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); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 738 | }; |
| 739 | |
| 740 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 741 | // Get the integer part of a heap number. Surprisingly, all this bit twiddling |
| 742 | // is faster than using the built-in instructions on floating point registers. |
| 743 | // Trashes edi and ebx. Dest is ecx. Source cannot be ecx or one of the |
| 744 | // trashed registers. |
| 745 | static void IntegerConvert(MacroAssembler* masm, |
| 746 | Register source, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 747 | bool use_sse3, |
| 748 | Label* conversion_failure) { |
| 749 | ASSERT(!source.is(ecx) && !source.is(edi) && !source.is(ebx)); |
| 750 | Label done, right_exponent, normal_exponent; |
| 751 | Register scratch = ebx; |
| 752 | Register scratch2 = edi; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 753 | // Get exponent word. |
| 754 | __ mov(scratch, FieldOperand(source, HeapNumber::kExponentOffset)); |
| 755 | // Get exponent alone in scratch2. |
| 756 | __ mov(scratch2, scratch); |
| 757 | __ and_(scratch2, HeapNumber::kExponentMask); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 758 | if (use_sse3) { |
| 759 | CpuFeatures::Scope scope(SSE3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 760 | // Check whether the exponent is too big for a 64 bit signed integer. |
| 761 | static const uint32_t kTooBigExponent = |
| 762 | (HeapNumber::kExponentBias + 63) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 763 | __ cmp(scratch2, Immediate(kTooBigExponent)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 764 | __ j(greater_equal, conversion_failure); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 765 | // Load x87 register with heap number. |
| 766 | __ fld_d(FieldOperand(source, HeapNumber::kValueOffset)); |
| 767 | // Reserve space for 64 bit answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 768 | __ sub(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 769 | // Do conversion, which cannot fail because we checked the exponent. |
| 770 | __ fisttp_d(Operand(esp, 0)); |
| 771 | __ 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] | 772 | __ add(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 773 | } else { |
| 774 | // Load ecx with zero. We use this either for the final shift or |
| 775 | // for the answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 776 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 777 | // Check whether the exponent matches a 32 bit signed int that cannot be |
| 778 | // represented by a Smi. A non-smi 32 bit integer is 1.xxx * 2^30 so the |
| 779 | // exponent is 30 (biased). This is the exponent that we are fastest at and |
| 780 | // also the highest exponent we can handle here. |
| 781 | const uint32_t non_smi_exponent = |
| 782 | (HeapNumber::kExponentBias + 30) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 783 | __ cmp(scratch2, Immediate(non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 784 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 785 | // logic. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 786 | __ j(equal, &right_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 787 | // If the exponent is higher than that then go to slow case. This catches |
| 788 | // 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] | 789 | __ j(less, &normal_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 790 | |
| 791 | { |
| 792 | // Handle a big exponent. The only reason we have this code is that the |
| 793 | // >>> operator has a tendency to generate numbers with an exponent of 31. |
| 794 | const uint32_t big_non_smi_exponent = |
| 795 | (HeapNumber::kExponentBias + 31) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 796 | __ cmp(scratch2, Immediate(big_non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 797 | __ j(not_equal, conversion_failure); |
| 798 | // We have the big exponent, typically from >>>. This means the number is |
| 799 | // in the range 2^31 to 2^32 - 1. Get the top bits of the mantissa. |
| 800 | __ mov(scratch2, scratch); |
| 801 | __ and_(scratch2, HeapNumber::kMantissaMask); |
| 802 | // Put back the implicit 1. |
| 803 | __ or_(scratch2, 1 << HeapNumber::kExponentShift); |
| 804 | // Shift up the mantissa bits to take up the space the exponent used to |
| 805 | // take. We just orred in the implicit bit so that took care of one and |
| 806 | // we want to use the full unsigned range so we subtract 1 bit from the |
| 807 | // shift distance. |
| 808 | const int big_shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 809 | __ shl(scratch2, big_shift_distance); |
| 810 | // Get the second half of the double. |
| 811 | __ mov(ecx, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 812 | // Shift down 21 bits to get the most significant 11 bits or the low |
| 813 | // mantissa word. |
| 814 | __ shr(ecx, 32 - big_shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 815 | __ or_(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 816 | // 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] | 817 | __ test(scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 818 | __ j(positive, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 819 | __ neg(ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 820 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | __ bind(&normal_exponent); |
| 824 | // Exponent word in scratch, exponent part of exponent word in scratch2. |
| 825 | // Zero in ecx. |
| 826 | // We know the exponent is smaller than 30 (biased). If it is less than |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 827 | // 0 (biased) then the number is smaller in magnitude than 1.0 * 2^0, i.e. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 828 | // it rounds to zero. |
| 829 | const uint32_t zero_exponent = |
| 830 | (HeapNumber::kExponentBias + 0) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 831 | __ sub(scratch2, Immediate(zero_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 832 | // ecx already has a Smi zero. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 833 | __ j(less, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 834 | |
| 835 | // We have a shifted exponent between 0 and 30 in scratch2. |
| 836 | __ shr(scratch2, HeapNumber::kExponentShift); |
| 837 | __ mov(ecx, Immediate(30)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 838 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 839 | |
| 840 | __ bind(&right_exponent); |
| 841 | // Here ecx is the shift, scratch is the exponent word. |
| 842 | // Get the top bits of the mantissa. |
| 843 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 844 | // Put back the implicit 1. |
| 845 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 846 | // Shift up the mantissa bits to take up the space the exponent used to |
| 847 | // take. We have kExponentShift + 1 significant bits int he low end of the |
| 848 | // word. Shift them to the top bits. |
| 849 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 850 | __ shl(scratch, shift_distance); |
| 851 | // Get the second half of the double. For some exponents we don't |
| 852 | // actually need this because the bits get shifted out again, but |
| 853 | // it's probably slower to test than just to do it. |
| 854 | __ mov(scratch2, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 855 | // Shift down 22 bits to get the most significant 10 bits or the low |
| 856 | // mantissa word. |
| 857 | __ shr(scratch2, 32 - shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 858 | __ or_(scratch2, scratch); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 859 | // Move down according to the exponent. |
| 860 | __ shr_cl(scratch2); |
| 861 | // Now the unsigned answer is in scratch2. We need to move it to ecx and |
| 862 | // we may need to fix the sign. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 863 | Label negative; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 864 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 865 | __ cmp(ecx, FieldOperand(source, HeapNumber::kExponentOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 866 | __ j(greater, &negative, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 867 | __ mov(ecx, scratch2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 868 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 869 | __ bind(&negative); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 870 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 871 | __ bind(&done); |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 876 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 877 | const char* op_name = Token::Name(op_); |
| 878 | const char* overwrite_name = NULL; // Make g++ happy. |
| 879 | switch (mode_) { |
| 880 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 881 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 882 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 883 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 884 | op_name, |
| 885 | overwrite_name, |
| 886 | UnaryOpIC::GetName(operand_type_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | |
| 890 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 891 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 892 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 893 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 894 | GenerateTypeTransition(masm); |
| 895 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 896 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 897 | GenerateSmiStub(masm); |
| 898 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 899 | case UnaryOpIC::HEAP_NUMBER: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 900 | GenerateHeapNumberStub(masm); |
| 901 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 902 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 903 | GenerateGenericStub(masm); |
| 904 | break; |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 909 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 910 | __ pop(ecx); // Save return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 911 | |
| 912 | __ push(eax); // the operand |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 913 | __ push(Immediate(Smi::FromInt(op_))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 914 | __ push(Immediate(Smi::FromInt(mode_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 915 | __ push(Immediate(Smi::FromInt(operand_type_))); |
| 916 | |
| 917 | __ push(ecx); // Push return address. |
| 918 | |
| 919 | // Patch the caller to an appropriate specialized stub and return the |
| 920 | // operation result to the caller of the stub. |
| 921 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 922 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | |
| 926 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 927 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 928 | switch (op_) { |
| 929 | case Token::SUB: |
| 930 | GenerateSmiStubSub(masm); |
| 931 | break; |
| 932 | case Token::BIT_NOT: |
| 933 | GenerateSmiStubBitNot(masm); |
| 934 | break; |
| 935 | default: |
| 936 | UNREACHABLE(); |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 941 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 942 | Label non_smi, undo, slow; |
| 943 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, |
| 944 | Label::kNear, Label::kNear, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 945 | __ bind(&undo); |
| 946 | GenerateSmiCodeUndo(masm); |
| 947 | __ bind(&non_smi); |
| 948 | __ bind(&slow); |
| 949 | GenerateTypeTransition(masm); |
| 950 | } |
| 951 | |
| 952 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 953 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 954 | Label non_smi; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 955 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 956 | __ bind(&non_smi); |
| 957 | GenerateTypeTransition(masm); |
| 958 | } |
| 959 | |
| 960 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 961 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 962 | Label* non_smi, |
| 963 | Label* undo, |
| 964 | Label* slow, |
| 965 | Label::Distance non_smi_near, |
| 966 | Label::Distance undo_near, |
| 967 | Label::Distance slow_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 968 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 969 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 970 | |
| 971 | // 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] | 972 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 973 | __ j(zero, slow, slow_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 974 | |
| 975 | // 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] | 976 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 977 | __ Set(eax, Immediate(0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 978 | __ sub(eax, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 979 | __ j(overflow, undo, undo_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 980 | __ ret(0); |
| 981 | } |
| 982 | |
| 983 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 984 | void UnaryOpStub::GenerateSmiCodeBitNot( |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 985 | MacroAssembler* masm, |
| 986 | Label* non_smi, |
| 987 | Label::Distance non_smi_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 988 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 989 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 990 | |
| 991 | // Flip bits and revert inverted smi-tag. |
| 992 | __ not_(eax); |
| 993 | __ and_(eax, ~kSmiTagMask); |
| 994 | __ ret(0); |
| 995 | } |
| 996 | |
| 997 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 998 | void UnaryOpStub::GenerateSmiCodeUndo(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 999 | __ mov(eax, edx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | |
| 1003 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1004 | void UnaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1005 | switch (op_) { |
| 1006 | case Token::SUB: |
| 1007 | GenerateHeapNumberStubSub(masm); |
| 1008 | break; |
| 1009 | case Token::BIT_NOT: |
| 1010 | GenerateHeapNumberStubBitNot(masm); |
| 1011 | break; |
| 1012 | default: |
| 1013 | UNREACHABLE(); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1018 | void UnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1019 | Label non_smi, undo, slow, call_builtin; |
| 1020 | GenerateSmiCodeSub(masm, &non_smi, &undo, &call_builtin, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1021 | __ bind(&non_smi); |
| 1022 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1023 | __ bind(&undo); |
| 1024 | GenerateSmiCodeUndo(masm); |
| 1025 | __ bind(&slow); |
| 1026 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1027 | __ bind(&call_builtin); |
| 1028 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1032 | void UnaryOpStub::GenerateHeapNumberStubBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1033 | MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1034 | Label non_smi, slow; |
| 1035 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1036 | __ bind(&non_smi); |
| 1037 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1038 | __ bind(&slow); |
| 1039 | GenerateTypeTransition(masm); |
| 1040 | } |
| 1041 | |
| 1042 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1043 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 1044 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1045 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1046 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1047 | __ j(not_equal, slow); |
| 1048 | |
| 1049 | if (mode_ == UNARY_OVERWRITE) { |
| 1050 | __ xor_(FieldOperand(eax, HeapNumber::kExponentOffset), |
| 1051 | Immediate(HeapNumber::kSignMask)); // Flip sign. |
| 1052 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1053 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1054 | // edx: operand |
| 1055 | |
| 1056 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 1057 | __ AllocateHeapNumber(eax, ebx, ecx, &slow_allocate_heapnumber); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1058 | __ jmp(&heapnumber_allocated, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1059 | |
| 1060 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1061 | { |
| 1062 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1063 | __ push(edx); |
| 1064 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1065 | __ pop(edx); |
| 1066 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1067 | |
| 1068 | __ bind(&heapnumber_allocated); |
| 1069 | // eax: allocated 'empty' number |
| 1070 | __ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 1071 | __ xor_(ecx, HeapNumber::kSignMask); // Flip sign. |
| 1072 | __ mov(FieldOperand(eax, HeapNumber::kExponentOffset), ecx); |
| 1073 | __ mov(ecx, FieldOperand(edx, HeapNumber::kMantissaOffset)); |
| 1074 | __ mov(FieldOperand(eax, HeapNumber::kMantissaOffset), ecx); |
| 1075 | } |
| 1076 | __ ret(0); |
| 1077 | } |
| 1078 | |
| 1079 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1080 | void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm, |
| 1081 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1082 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1083 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1084 | __ j(not_equal, slow); |
| 1085 | |
| 1086 | // 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] | 1087 | IntegerConvert(masm, eax, CpuFeatures::IsSupported(SSE3), slow); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1088 | |
| 1089 | // 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] | 1090 | Label try_float; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1091 | __ not_(ecx); |
| 1092 | __ cmp(ecx, 0xc0000000); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1093 | __ j(sign, &try_float, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1094 | |
| 1095 | // Tag the result as a smi and we're done. |
| 1096 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1097 | __ lea(eax, Operand(ecx, times_2, kSmiTag)); |
| 1098 | __ ret(0); |
| 1099 | |
| 1100 | // Try to store the result in a heap number. |
| 1101 | __ bind(&try_float); |
| 1102 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 1103 | Label slow_allocate_heapnumber, heapnumber_allocated; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1104 | __ mov(ebx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1105 | __ AllocateHeapNumber(eax, edx, edi, &slow_allocate_heapnumber); |
| 1106 | __ jmp(&heapnumber_allocated); |
| 1107 | |
| 1108 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1109 | { |
| 1110 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1111 | // Push the original HeapNumber on the stack. The integer value can't |
| 1112 | // be stored since it's untagged and not in the smi range (so we can't |
| 1113 | // smi-tag it). We'll recalculate the value after the GC instead. |
| 1114 | __ push(ebx); |
| 1115 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1116 | // New HeapNumber is in eax. |
| 1117 | __ pop(edx); |
| 1118 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1119 | // IntegerConvert uses ebx and edi as scratch registers. |
| 1120 | // This conversion won't go slow-case. |
| 1121 | IntegerConvert(masm, edx, CpuFeatures::IsSupported(SSE3), slow); |
| 1122 | __ not_(ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1123 | |
| 1124 | __ bind(&heapnumber_allocated); |
| 1125 | } |
| 1126 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1127 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1128 | __ cvtsi2sd(xmm0, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1129 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1130 | } else { |
| 1131 | __ push(ecx); |
| 1132 | __ fild_s(Operand(esp, 0)); |
| 1133 | __ pop(ecx); |
| 1134 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1135 | } |
| 1136 | __ ret(0); |
| 1137 | } |
| 1138 | |
| 1139 | |
| 1140 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1141 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1142 | switch (op_) { |
| 1143 | case Token::SUB: |
| 1144 | GenerateGenericStubSub(masm); |
| 1145 | break; |
| 1146 | case Token::BIT_NOT: |
| 1147 | GenerateGenericStubBitNot(masm); |
| 1148 | break; |
| 1149 | default: |
| 1150 | UNREACHABLE(); |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1155 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1156 | Label non_smi, undo, slow; |
| 1157 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1158 | __ bind(&non_smi); |
| 1159 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1160 | __ bind(&undo); |
| 1161 | GenerateSmiCodeUndo(masm); |
| 1162 | __ bind(&slow); |
| 1163 | GenerateGenericCodeFallback(masm); |
| 1164 | } |
| 1165 | |
| 1166 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1167 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1168 | Label non_smi, slow; |
| 1169 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1170 | __ bind(&non_smi); |
| 1171 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1172 | __ bind(&slow); |
| 1173 | GenerateGenericCodeFallback(masm); |
| 1174 | } |
| 1175 | |
| 1176 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1177 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1178 | // Handle the slow case by jumping to the corresponding JavaScript builtin. |
| 1179 | __ pop(ecx); // pop return address. |
| 1180 | __ push(eax); |
| 1181 | __ push(ecx); // push return address |
| 1182 | switch (op_) { |
| 1183 | case Token::SUB: |
| 1184 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 1185 | break; |
| 1186 | case Token::BIT_NOT: |
| 1187 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 1188 | break; |
| 1189 | default: |
| 1190 | UNREACHABLE(); |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1195 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1196 | __ pop(ecx); // Save return address. |
| 1197 | __ push(edx); |
| 1198 | __ push(eax); |
| 1199 | // Left and right arguments are now on top. |
| 1200 | // Push this stub's key. Although the operation and the type info are |
| 1201 | // encoded into the key, the encoding is opaque, so push them too. |
| 1202 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
| 1203 | __ push(Immediate(Smi::FromInt(op_))); |
| 1204 | __ push(Immediate(Smi::FromInt(operands_type_))); |
| 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()), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1213 | 5, |
| 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. |
| 1223 | // Push this stub's key. Although the operation and the type info are |
| 1224 | // encoded into the key, the encoding is opaque, so push them too. |
| 1225 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
| 1226 | __ push(Immediate(Smi::FromInt(op_))); |
| 1227 | __ push(Immediate(Smi::FromInt(operands_type_))); |
| 1228 | |
| 1229 | __ push(ecx); // Push return address. |
| 1230 | |
| 1231 | // Patch the caller to an appropriate specialized stub and return the |
| 1232 | // operation result to the caller of the stub. |
| 1233 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1234 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1235 | masm->isolate()), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1236 | 5, |
| 1237 | 1); |
| 1238 | } |
| 1239 | |
| 1240 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1241 | void BinaryOpStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1242 | // Explicitly allow generation of nested stubs. It is safe here because |
| 1243 | // generation code does not use any raw pointers. |
| 1244 | AllowStubCallsScope allow_stub_calls(masm, true); |
| 1245 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1246 | switch (operands_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1247 | case BinaryOpIC::UNINITIALIZED: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1248 | GenerateTypeTransition(masm); |
| 1249 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1250 | case BinaryOpIC::SMI: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1251 | GenerateSmiStub(masm); |
| 1252 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1253 | case BinaryOpIC::INT32: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1254 | GenerateInt32Stub(masm); |
| 1255 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1256 | case BinaryOpIC::HEAP_NUMBER: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1257 | GenerateHeapNumberStub(masm); |
| 1258 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1259 | case BinaryOpIC::ODDBALL: |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1260 | GenerateOddballStub(masm); |
| 1261 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1262 | case BinaryOpIC::BOTH_STRING: |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1263 | GenerateBothStringStub(masm); |
| 1264 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1265 | case BinaryOpIC::STRING: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1266 | GenerateStringStub(masm); |
| 1267 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1268 | case BinaryOpIC::GENERIC: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1269 | GenerateGeneric(masm); |
| 1270 | break; |
| 1271 | default: |
| 1272 | UNREACHABLE(); |
| 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1277 | void BinaryOpStub::PrintName(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1278 | const char* op_name = Token::Name(op_); |
| 1279 | const char* overwrite_name; |
| 1280 | switch (mode_) { |
| 1281 | case NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 1282 | case OVERWRITE_RIGHT: overwrite_name = "OverwriteRight"; break; |
| 1283 | case OVERWRITE_LEFT: overwrite_name = "OverwriteLeft"; break; |
| 1284 | default: overwrite_name = "UnknownOverwrite"; break; |
| 1285 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1286 | stream->Add("BinaryOpStub_%s_%s_%s", |
| 1287 | op_name, |
| 1288 | overwrite_name, |
| 1289 | BinaryOpIC::GetName(operands_type_)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1293 | void BinaryOpStub::GenerateSmiCode( |
| 1294 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1295 | Label* slow, |
| 1296 | SmiCodeGenerateHeapNumberResults allow_heapnumber_results) { |
| 1297 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 1298 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 1299 | Comment load_comment(masm, "-- Load arguments"); |
| 1300 | Register left = edx; |
| 1301 | Register right = eax; |
| 1302 | if (op_ == Token::DIV || op_ == Token::MOD) { |
| 1303 | left = eax; |
| 1304 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1305 | __ mov(ebx, eax); |
| 1306 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | |
| 1310 | // 2. Prepare the smi check of both operands by oring them together. |
| 1311 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 1312 | Label not_smis; |
| 1313 | Register combined = ecx; |
| 1314 | ASSERT(!left.is(combined) && !right.is(combined)); |
| 1315 | switch (op_) { |
| 1316 | case Token::BIT_OR: |
| 1317 | // Perform the operation into eax and smi check the result. Preserve |
| 1318 | // eax in case the result is not a smi. |
| 1319 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1320 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1321 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1322 | combined = right; |
| 1323 | break; |
| 1324 | |
| 1325 | case Token::BIT_XOR: |
| 1326 | case Token::BIT_AND: |
| 1327 | case Token::ADD: |
| 1328 | case Token::SUB: |
| 1329 | case Token::MUL: |
| 1330 | case Token::DIV: |
| 1331 | case Token::MOD: |
| 1332 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1333 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1334 | break; |
| 1335 | |
| 1336 | case Token::SHL: |
| 1337 | case Token::SAR: |
| 1338 | case Token::SHR: |
| 1339 | // Move the right operand into ecx for the shift operation, use eax |
| 1340 | // for the smi check register. |
| 1341 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1342 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1343 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1344 | combined = right; |
| 1345 | break; |
| 1346 | |
| 1347 | default: |
| 1348 | break; |
| 1349 | } |
| 1350 | |
| 1351 | // 3. Perform the smi check of the operands. |
| 1352 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1353 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1354 | |
| 1355 | // 4. Operands are both smis, perform the operation leaving the result in |
| 1356 | // eax and check the result if necessary. |
| 1357 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 1358 | Label use_fp_on_smis; |
| 1359 | switch (op_) { |
| 1360 | case Token::BIT_OR: |
| 1361 | // Nothing to do. |
| 1362 | break; |
| 1363 | |
| 1364 | case Token::BIT_XOR: |
| 1365 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1366 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1367 | break; |
| 1368 | |
| 1369 | case Token::BIT_AND: |
| 1370 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1371 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1372 | break; |
| 1373 | |
| 1374 | case Token::SHL: |
| 1375 | // Remove tags from operands (but keep sign). |
| 1376 | __ SmiUntag(left); |
| 1377 | __ SmiUntag(ecx); |
| 1378 | // Perform the operation. |
| 1379 | __ shl_cl(left); |
| 1380 | // Check that the *signed* result fits in a smi. |
| 1381 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1382 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1383 | // Tag the result and store it in register eax. |
| 1384 | __ SmiTag(left); |
| 1385 | __ mov(eax, left); |
| 1386 | break; |
| 1387 | |
| 1388 | case Token::SAR: |
| 1389 | // Remove tags from operands (but keep sign). |
| 1390 | __ SmiUntag(left); |
| 1391 | __ SmiUntag(ecx); |
| 1392 | // Perform the operation. |
| 1393 | __ sar_cl(left); |
| 1394 | // Tag the result and store it in register eax. |
| 1395 | __ SmiTag(left); |
| 1396 | __ mov(eax, left); |
| 1397 | break; |
| 1398 | |
| 1399 | case Token::SHR: |
| 1400 | // Remove tags from operands (but keep sign). |
| 1401 | __ SmiUntag(left); |
| 1402 | __ SmiUntag(ecx); |
| 1403 | // Perform the operation. |
| 1404 | __ shr_cl(left); |
| 1405 | // Check that the *unsigned* result fits in a smi. |
| 1406 | // Neither of the two high-order bits can be set: |
| 1407 | // - 0x80000000: high bit would be lost when smi tagging. |
| 1408 | // - 0x40000000: this number would convert to negative when |
| 1409 | // Smi tagging these two cases can only happen with shifts |
| 1410 | // by 0 or 1 when handed a valid smi. |
| 1411 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1412 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1413 | // Tag the result and store it in register eax. |
| 1414 | __ SmiTag(left); |
| 1415 | __ mov(eax, left); |
| 1416 | break; |
| 1417 | |
| 1418 | case Token::ADD: |
| 1419 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1420 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1421 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1422 | break; |
| 1423 | |
| 1424 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1425 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1426 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1427 | __ mov(eax, left); |
| 1428 | break; |
| 1429 | |
| 1430 | case Token::MUL: |
| 1431 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 1432 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 1433 | // We can't revert the multiplication if the result is not a smi |
| 1434 | // so save the right operand. |
| 1435 | __ mov(ebx, right); |
| 1436 | // Remove tag from one of the operands (but keep sign). |
| 1437 | __ SmiUntag(right); |
| 1438 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1439 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1440 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1441 | // Check for negative zero result. Use combined = left | right. |
| 1442 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 1443 | break; |
| 1444 | |
| 1445 | case Token::DIV: |
| 1446 | // We can't revert the division if the result is not a smi so |
| 1447 | // save the left operand. |
| 1448 | __ mov(edi, left); |
| 1449 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1450 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1451 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1452 | // Sign extend left into edx:eax. |
| 1453 | ASSERT(left.is(eax)); |
| 1454 | __ cdq(); |
| 1455 | // Divide edx:eax by right. |
| 1456 | __ idiv(right); |
| 1457 | // Check for the corner case of dividing the most negative smi by |
| 1458 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1459 | // instruction. |
| 1460 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1461 | __ cmp(eax, 0x40000000); |
| 1462 | __ j(equal, &use_fp_on_smis); |
| 1463 | // Check for negative zero result. Use combined = left | right. |
| 1464 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1465 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1466 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1467 | __ j(not_zero, &use_fp_on_smis); |
| 1468 | // Tag the result and store it in register eax. |
| 1469 | __ SmiTag(eax); |
| 1470 | break; |
| 1471 | |
| 1472 | case Token::MOD: |
| 1473 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1474 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1475 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1476 | |
| 1477 | // Sign extend left into edx:eax. |
| 1478 | ASSERT(left.is(eax)); |
| 1479 | __ cdq(); |
| 1480 | // Divide edx:eax by right. |
| 1481 | __ idiv(right); |
| 1482 | // Check for negative zero result. Use combined = left | right. |
| 1483 | __ NegativeZeroTest(edx, combined, slow); |
| 1484 | // Move remainder to register eax. |
| 1485 | __ mov(eax, edx); |
| 1486 | break; |
| 1487 | |
| 1488 | default: |
| 1489 | UNREACHABLE(); |
| 1490 | } |
| 1491 | |
| 1492 | // 5. Emit return of result in eax. Some operations have registers pushed. |
| 1493 | switch (op_) { |
| 1494 | case Token::ADD: |
| 1495 | case Token::SUB: |
| 1496 | case Token::MUL: |
| 1497 | case Token::DIV: |
| 1498 | __ ret(0); |
| 1499 | break; |
| 1500 | case Token::MOD: |
| 1501 | case Token::BIT_OR: |
| 1502 | case Token::BIT_AND: |
| 1503 | case Token::BIT_XOR: |
| 1504 | case Token::SAR: |
| 1505 | case Token::SHL: |
| 1506 | case Token::SHR: |
| 1507 | __ ret(2 * kPointerSize); |
| 1508 | break; |
| 1509 | default: |
| 1510 | UNREACHABLE(); |
| 1511 | } |
| 1512 | |
| 1513 | // 6. For some operations emit inline code to perform floating point |
| 1514 | // operations on known smis (e.g., if the result of the operation |
| 1515 | // overflowed the smi range). |
| 1516 | if (allow_heapnumber_results == NO_HEAPNUMBER_RESULTS) { |
| 1517 | __ bind(&use_fp_on_smis); |
| 1518 | switch (op_) { |
| 1519 | // Undo the effects of some operations, and some register moves. |
| 1520 | case Token::SHL: |
| 1521 | // The arguments are saved on the stack, and only used from there. |
| 1522 | break; |
| 1523 | case Token::ADD: |
| 1524 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1525 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1526 | break; |
| 1527 | case Token::SUB: |
| 1528 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1529 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1530 | break; |
| 1531 | case Token::MUL: |
| 1532 | // Right was clobbered but a copy is in ebx. |
| 1533 | __ mov(right, ebx); |
| 1534 | break; |
| 1535 | case Token::DIV: |
| 1536 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1537 | // division. They should be in eax, ebx for jump to not_smi. |
| 1538 | __ mov(eax, edi); |
| 1539 | break; |
| 1540 | default: |
| 1541 | // No other operators jump to use_fp_on_smis. |
| 1542 | break; |
| 1543 | } |
| 1544 | __ jmp(¬_smis); |
| 1545 | } else { |
| 1546 | ASSERT(allow_heapnumber_results == ALLOW_HEAPNUMBER_RESULTS); |
| 1547 | switch (op_) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1548 | case Token::SHL: |
| 1549 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1550 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1551 | __ bind(&use_fp_on_smis); |
| 1552 | // Result we want is in left == edx, so we can put the allocated heap |
| 1553 | // number in eax. |
| 1554 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1555 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1556 | // It's OK to overwrite the arguments on the stack because we |
| 1557 | // are about to return. |
| 1558 | if (op_ == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1559 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1560 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1561 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1562 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1563 | } else { |
| 1564 | ASSERT_EQ(Token::SHL, op_); |
| 1565 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1566 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1567 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1568 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1569 | } else { |
| 1570 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1571 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1572 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1573 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1574 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1575 | __ ret(2 * kPointerSize); |
| 1576 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | case Token::ADD: |
| 1580 | case Token::SUB: |
| 1581 | case Token::MUL: |
| 1582 | case Token::DIV: { |
| 1583 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1584 | __ bind(&use_fp_on_smis); |
| 1585 | // Restore arguments to edx, eax. |
| 1586 | switch (op_) { |
| 1587 | case Token::ADD: |
| 1588 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1589 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1590 | break; |
| 1591 | case Token::SUB: |
| 1592 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1593 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1594 | break; |
| 1595 | case Token::MUL: |
| 1596 | // Right was clobbered but a copy is in ebx. |
| 1597 | __ mov(right, ebx); |
| 1598 | break; |
| 1599 | case Token::DIV: |
| 1600 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1601 | // division. |
| 1602 | __ mov(edx, edi); |
| 1603 | __ mov(eax, right); |
| 1604 | break; |
| 1605 | default: UNREACHABLE(); |
| 1606 | break; |
| 1607 | } |
| 1608 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1609 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1610 | CpuFeatures::Scope use_sse2(SSE2); |
| 1611 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
| 1612 | switch (op_) { |
| 1613 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1614 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1615 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1616 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1617 | default: UNREACHABLE(); |
| 1618 | } |
| 1619 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1620 | } else { // SSE2 not available, use FPU. |
| 1621 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
| 1622 | switch (op_) { |
| 1623 | case Token::ADD: __ faddp(1); break; |
| 1624 | case Token::SUB: __ fsubp(1); break; |
| 1625 | case Token::MUL: __ fmulp(1); break; |
| 1626 | case Token::DIV: __ fdivp(1); break; |
| 1627 | default: UNREACHABLE(); |
| 1628 | } |
| 1629 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1630 | } |
| 1631 | __ mov(eax, ecx); |
| 1632 | __ ret(0); |
| 1633 | break; |
| 1634 | } |
| 1635 | |
| 1636 | default: |
| 1637 | break; |
| 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1642 | // edx and eax. |
| 1643 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1644 | __ bind(¬_smis); |
| 1645 | switch (op_) { |
| 1646 | case Token::BIT_OR: |
| 1647 | case Token::SHL: |
| 1648 | case Token::SAR: |
| 1649 | case Token::SHR: |
| 1650 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1651 | // check. |
| 1652 | __ mov(eax, ecx); |
| 1653 | break; |
| 1654 | |
| 1655 | case Token::DIV: |
| 1656 | case Token::MOD: |
| 1657 | // Operands are in eax, ebx at this point. |
| 1658 | __ mov(edx, eax); |
| 1659 | __ mov(eax, ebx); |
| 1660 | break; |
| 1661 | |
| 1662 | default: |
| 1663 | break; |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1668 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1669 | Label call_runtime; |
| 1670 | |
| 1671 | switch (op_) { |
| 1672 | case Token::ADD: |
| 1673 | case Token::SUB: |
| 1674 | case Token::MUL: |
| 1675 | case Token::DIV: |
| 1676 | break; |
| 1677 | case Token::MOD: |
| 1678 | case Token::BIT_OR: |
| 1679 | case Token::BIT_AND: |
| 1680 | case Token::BIT_XOR: |
| 1681 | case Token::SAR: |
| 1682 | case Token::SHL: |
| 1683 | case Token::SHR: |
| 1684 | GenerateRegisterArgsPush(masm); |
| 1685 | break; |
| 1686 | default: |
| 1687 | UNREACHABLE(); |
| 1688 | } |
| 1689 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1690 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1691 | result_type_ == BinaryOpIC::SMI) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1692 | GenerateSmiCode(masm, &call_runtime, NO_HEAPNUMBER_RESULTS); |
| 1693 | } else { |
| 1694 | GenerateSmiCode(masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS); |
| 1695 | } |
| 1696 | __ bind(&call_runtime); |
| 1697 | switch (op_) { |
| 1698 | case Token::ADD: |
| 1699 | case Token::SUB: |
| 1700 | case Token::MUL: |
| 1701 | case Token::DIV: |
| 1702 | GenerateTypeTransition(masm); |
| 1703 | break; |
| 1704 | case Token::MOD: |
| 1705 | case Token::BIT_OR: |
| 1706 | case Token::BIT_AND: |
| 1707 | case Token::BIT_XOR: |
| 1708 | case Token::SAR: |
| 1709 | case Token::SHL: |
| 1710 | case Token::SHR: |
| 1711 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1712 | break; |
| 1713 | default: |
| 1714 | UNREACHABLE(); |
| 1715 | } |
| 1716 | } |
| 1717 | |
| 1718 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1719 | void BinaryOpStub::GenerateStringStub(MacroAssembler* masm) { |
| 1720 | ASSERT(operands_type_ == BinaryOpIC::STRING); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1721 | ASSERT(op_ == Token::ADD); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1722 | // Try to add arguments as strings, otherwise, transition to the generic |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1723 | // BinaryOpIC type. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1724 | GenerateAddStrings(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1725 | GenerateTypeTransition(masm); |
| 1726 | } |
| 1727 | |
| 1728 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1729 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1730 | Label call_runtime; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1731 | ASSERT(operands_type_ == BinaryOpIC::BOTH_STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1732 | ASSERT(op_ == Token::ADD); |
| 1733 | // If both arguments are strings, call the string add stub. |
| 1734 | // Otherwise, do a transition. |
| 1735 | |
| 1736 | // Registers containing left and right operands respectively. |
| 1737 | Register left = edx; |
| 1738 | Register right = eax; |
| 1739 | |
| 1740 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1741 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1742 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1743 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1744 | |
| 1745 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1746 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1747 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1748 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1749 | |
| 1750 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 1751 | GenerateRegisterArgsPush(masm); |
| 1752 | __ TailCallStub(&string_add_stub); |
| 1753 | |
| 1754 | __ bind(&call_runtime); |
| 1755 | GenerateTypeTransition(masm); |
| 1756 | } |
| 1757 | |
| 1758 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1759 | // Input: |
| 1760 | // edx: left operand (tagged) |
| 1761 | // eax: right operand (tagged) |
| 1762 | // Output: |
| 1763 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1764 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1765 | Label call_runtime; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1766 | ASSERT(operands_type_ == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1767 | |
| 1768 | // Floating point case. |
| 1769 | switch (op_) { |
| 1770 | case Token::ADD: |
| 1771 | case Token::SUB: |
| 1772 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1773 | case Token::DIV: |
| 1774 | case Token::MOD: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1775 | Label not_floats; |
| 1776 | Label not_int32; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1777 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1778 | CpuFeatures::Scope use_sse2(SSE2); |
| 1779 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1780 | FloatingPointHelper::CheckSSE2OperandsAreInt32(masm, ¬_int32, ecx); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1781 | if (op_ == Token::MOD) { |
| 1782 | GenerateRegisterArgsPush(masm); |
| 1783 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1784 | } else { |
| 1785 | switch (op_) { |
| 1786 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1787 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1788 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1789 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1790 | default: UNREACHABLE(); |
| 1791 | } |
| 1792 | // Check result type if it is currently Int32. |
| 1793 | if (result_type_ <= BinaryOpIC::INT32) { |
| 1794 | __ cvttsd2si(ecx, Operand(xmm0)); |
| 1795 | __ cvtsi2sd(xmm2, ecx); |
| 1796 | __ ucomisd(xmm0, xmm2); |
| 1797 | __ j(not_zero, ¬_int32); |
| 1798 | __ j(carry, ¬_int32); |
| 1799 | } |
| 1800 | GenerateHeapResultAllocation(masm, &call_runtime); |
| 1801 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1802 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1803 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1804 | } else { // SSE2 not available, use FPU. |
| 1805 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1806 | FloatingPointHelper::LoadFloatOperands( |
| 1807 | masm, |
| 1808 | ecx, |
| 1809 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1810 | FloatingPointHelper::CheckFloatOperandsAreInt32(masm, ¬_int32); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1811 | if (op_ == Token::MOD) { |
| 1812 | // The operands are now on the FPU stack, but we don't need them. |
| 1813 | __ fstp(0); |
| 1814 | __ fstp(0); |
| 1815 | GenerateRegisterArgsPush(masm); |
| 1816 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1817 | } else { |
| 1818 | switch (op_) { |
| 1819 | case Token::ADD: __ faddp(1); break; |
| 1820 | case Token::SUB: __ fsubp(1); break; |
| 1821 | case Token::MUL: __ fmulp(1); break; |
| 1822 | case Token::DIV: __ fdivp(1); break; |
| 1823 | default: UNREACHABLE(); |
| 1824 | } |
| 1825 | Label after_alloc_failure; |
| 1826 | GenerateHeapResultAllocation(masm, &after_alloc_failure); |
| 1827 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1828 | __ ret(0); |
| 1829 | __ bind(&after_alloc_failure); |
| 1830 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1831 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1832 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | __ bind(¬_floats); |
| 1836 | __ bind(¬_int32); |
| 1837 | GenerateTypeTransition(masm); |
| 1838 | break; |
| 1839 | } |
| 1840 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1841 | case Token::BIT_OR: |
| 1842 | case Token::BIT_AND: |
| 1843 | case Token::BIT_XOR: |
| 1844 | case Token::SAR: |
| 1845 | case Token::SHL: |
| 1846 | case Token::SHR: { |
| 1847 | GenerateRegisterArgsPush(masm); |
| 1848 | Label not_floats; |
| 1849 | Label not_int32; |
| 1850 | Label non_smi_result; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1851 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
| 1852 | use_sse3_, |
| 1853 | ¬_floats); |
| 1854 | FloatingPointHelper::CheckLoadedIntegersWereInt32(masm, use_sse3_, |
| 1855 | ¬_int32); |
| 1856 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1857 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1858 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1859 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1860 | case Token::SAR: __ sar_cl(eax); break; |
| 1861 | case Token::SHL: __ shl_cl(eax); break; |
| 1862 | case Token::SHR: __ shr_cl(eax); break; |
| 1863 | default: UNREACHABLE(); |
| 1864 | } |
| 1865 | if (op_ == Token::SHR) { |
| 1866 | // Check if result is non-negative and fits in a smi. |
| 1867 | __ test(eax, Immediate(0xc0000000)); |
| 1868 | __ j(not_zero, &call_runtime); |
| 1869 | } else { |
| 1870 | // Check if result fits in a smi. |
| 1871 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1872 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1873 | } |
| 1874 | // Tag smi result and return. |
| 1875 | __ SmiTag(eax); |
| 1876 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1877 | |
| 1878 | // All ops except SHR return a signed int32 that we load in |
| 1879 | // a HeapNumber. |
| 1880 | if (op_ != Token::SHR) { |
| 1881 | __ bind(&non_smi_result); |
| 1882 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1883 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1884 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1885 | switch (mode_) { |
| 1886 | case OVERWRITE_LEFT: |
| 1887 | case OVERWRITE_RIGHT: |
| 1888 | // If the operand was an object, we skip the |
| 1889 | // allocation of a heap number. |
| 1890 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1891 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1892 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1893 | // Fall through! |
| 1894 | case NO_OVERWRITE: |
| 1895 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1896 | __ bind(&skip_allocation); |
| 1897 | break; |
| 1898 | default: UNREACHABLE(); |
| 1899 | } |
| 1900 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1901 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1902 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1903 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1904 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1905 | } else { |
| 1906 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1907 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1908 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1909 | } |
| 1910 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1911 | } |
| 1912 | |
| 1913 | __ bind(¬_floats); |
| 1914 | __ bind(¬_int32); |
| 1915 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1916 | break; |
| 1917 | } |
| 1918 | default: UNREACHABLE(); break; |
| 1919 | } |
| 1920 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1921 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1922 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1923 | __ bind(&call_runtime); |
| 1924 | |
| 1925 | switch (op_) { |
| 1926 | case Token::ADD: |
| 1927 | GenerateRegisterArgsPush(masm); |
| 1928 | __ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION); |
| 1929 | break; |
| 1930 | case Token::SUB: |
| 1931 | GenerateRegisterArgsPush(masm); |
| 1932 | __ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION); |
| 1933 | break; |
| 1934 | case Token::MUL: |
| 1935 | GenerateRegisterArgsPush(masm); |
| 1936 | __ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION); |
| 1937 | break; |
| 1938 | case Token::DIV: |
| 1939 | GenerateRegisterArgsPush(masm); |
| 1940 | __ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION); |
| 1941 | break; |
| 1942 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1943 | break; |
| 1944 | case Token::BIT_OR: |
| 1945 | __ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION); |
| 1946 | break; |
| 1947 | case Token::BIT_AND: |
| 1948 | __ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION); |
| 1949 | break; |
| 1950 | case Token::BIT_XOR: |
| 1951 | __ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION); |
| 1952 | break; |
| 1953 | case Token::SAR: |
| 1954 | __ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION); |
| 1955 | break; |
| 1956 | case Token::SHL: |
| 1957 | __ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION); |
| 1958 | break; |
| 1959 | case Token::SHR: |
| 1960 | __ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION); |
| 1961 | break; |
| 1962 | default: |
| 1963 | UNREACHABLE(); |
| 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1968 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1969 | if (op_ == Token::ADD) { |
| 1970 | // Handle string addition here, because it is the only operation |
| 1971 | // that does not do a ToNumber conversion on the operands. |
| 1972 | GenerateAddStrings(masm); |
| 1973 | } |
| 1974 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1975 | Factory* factory = masm->isolate()->factory(); |
| 1976 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1977 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1978 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1979 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1980 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1981 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1982 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1983 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1984 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1985 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1986 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1987 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1988 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1989 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1990 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1991 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1992 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1993 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1994 | } |
| 1995 | __ bind(&done); |
| 1996 | |
| 1997 | GenerateHeapNumberStub(masm); |
| 1998 | } |
| 1999 | |
| 2000 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2001 | void BinaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2002 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2003 | |
| 2004 | // Floating point case. |
| 2005 | switch (op_) { |
| 2006 | case Token::ADD: |
| 2007 | case Token::SUB: |
| 2008 | case Token::MUL: |
| 2009 | case Token::DIV: { |
| 2010 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2011 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2012 | CpuFeatures::Scope use_sse2(SSE2); |
| 2013 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 2014 | |
| 2015 | switch (op_) { |
| 2016 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2017 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2018 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2019 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2020 | default: UNREACHABLE(); |
| 2021 | } |
| 2022 | GenerateHeapResultAllocation(masm, &call_runtime); |
| 2023 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2024 | __ ret(0); |
| 2025 | } else { // SSE2 not available, use FPU. |
| 2026 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2027 | FloatingPointHelper::LoadFloatOperands( |
| 2028 | masm, |
| 2029 | ecx, |
| 2030 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2031 | switch (op_) { |
| 2032 | case Token::ADD: __ faddp(1); break; |
| 2033 | case Token::SUB: __ fsubp(1); break; |
| 2034 | case Token::MUL: __ fmulp(1); break; |
| 2035 | case Token::DIV: __ fdivp(1); break; |
| 2036 | default: UNREACHABLE(); |
| 2037 | } |
| 2038 | Label after_alloc_failure; |
| 2039 | GenerateHeapResultAllocation(masm, &after_alloc_failure); |
| 2040 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2041 | __ ret(0); |
| 2042 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2043 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2044 | __ jmp(&call_runtime); |
| 2045 | } |
| 2046 | |
| 2047 | __ bind(¬_floats); |
| 2048 | GenerateTypeTransition(masm); |
| 2049 | break; |
| 2050 | } |
| 2051 | |
| 2052 | case Token::MOD: { |
| 2053 | // For MOD we go directly to runtime in the non-smi case. |
| 2054 | break; |
| 2055 | } |
| 2056 | case Token::BIT_OR: |
| 2057 | case Token::BIT_AND: |
| 2058 | case Token::BIT_XOR: |
| 2059 | case Token::SAR: |
| 2060 | case Token::SHL: |
| 2061 | case Token::SHR: { |
| 2062 | GenerateRegisterArgsPush(masm); |
| 2063 | Label not_floats; |
| 2064 | Label non_smi_result; |
| 2065 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
| 2066 | use_sse3_, |
| 2067 | ¬_floats); |
| 2068 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2069 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2070 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2071 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2072 | case Token::SAR: __ sar_cl(eax); break; |
| 2073 | case Token::SHL: __ shl_cl(eax); break; |
| 2074 | case Token::SHR: __ shr_cl(eax); break; |
| 2075 | default: UNREACHABLE(); |
| 2076 | } |
| 2077 | if (op_ == Token::SHR) { |
| 2078 | // Check if result is non-negative and fits in a smi. |
| 2079 | __ test(eax, Immediate(0xc0000000)); |
| 2080 | __ j(not_zero, &call_runtime); |
| 2081 | } else { |
| 2082 | // Check if result fits in a smi. |
| 2083 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2084 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2085 | } |
| 2086 | // Tag smi result and return. |
| 2087 | __ SmiTag(eax); |
| 2088 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2089 | |
| 2090 | // All ops except SHR return a signed int32 that we load in |
| 2091 | // a HeapNumber. |
| 2092 | if (op_ != Token::SHR) { |
| 2093 | __ bind(&non_smi_result); |
| 2094 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2095 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2096 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2097 | switch (mode_) { |
| 2098 | case OVERWRITE_LEFT: |
| 2099 | case OVERWRITE_RIGHT: |
| 2100 | // If the operand was an object, we skip the |
| 2101 | // allocation of a heap number. |
| 2102 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2103 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2104 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2105 | // Fall through! |
| 2106 | case NO_OVERWRITE: |
| 2107 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2108 | __ bind(&skip_allocation); |
| 2109 | break; |
| 2110 | default: UNREACHABLE(); |
| 2111 | } |
| 2112 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2113 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2114 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2115 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2116 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2117 | } else { |
| 2118 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2119 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2120 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2121 | } |
| 2122 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2123 | } |
| 2124 | |
| 2125 | __ bind(¬_floats); |
| 2126 | GenerateTypeTransitionWithSavedArgs(masm); |
| 2127 | break; |
| 2128 | } |
| 2129 | default: UNREACHABLE(); break; |
| 2130 | } |
| 2131 | |
| 2132 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 2133 | // use the runtime system to get the correct result. |
| 2134 | __ bind(&call_runtime); |
| 2135 | |
| 2136 | switch (op_) { |
| 2137 | case Token::ADD: |
| 2138 | GenerateRegisterArgsPush(masm); |
| 2139 | __ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION); |
| 2140 | break; |
| 2141 | case Token::SUB: |
| 2142 | GenerateRegisterArgsPush(masm); |
| 2143 | __ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION); |
| 2144 | break; |
| 2145 | case Token::MUL: |
| 2146 | GenerateRegisterArgsPush(masm); |
| 2147 | __ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION); |
| 2148 | break; |
| 2149 | case Token::DIV: |
| 2150 | GenerateRegisterArgsPush(masm); |
| 2151 | __ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION); |
| 2152 | break; |
| 2153 | case Token::MOD: |
| 2154 | GenerateRegisterArgsPush(masm); |
| 2155 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 2156 | break; |
| 2157 | case Token::BIT_OR: |
| 2158 | __ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION); |
| 2159 | break; |
| 2160 | case Token::BIT_AND: |
| 2161 | __ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION); |
| 2162 | break; |
| 2163 | case Token::BIT_XOR: |
| 2164 | __ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION); |
| 2165 | break; |
| 2166 | case Token::SAR: |
| 2167 | __ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION); |
| 2168 | break; |
| 2169 | case Token::SHL: |
| 2170 | __ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION); |
| 2171 | break; |
| 2172 | case Token::SHR: |
| 2173 | __ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION); |
| 2174 | break; |
| 2175 | default: |
| 2176 | UNREACHABLE(); |
| 2177 | } |
| 2178 | } |
| 2179 | |
| 2180 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2181 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2182 | Label call_runtime; |
| 2183 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2184 | Counters* counters = masm->isolate()->counters(); |
| 2185 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2186 | |
| 2187 | switch (op_) { |
| 2188 | case Token::ADD: |
| 2189 | case Token::SUB: |
| 2190 | case Token::MUL: |
| 2191 | case Token::DIV: |
| 2192 | break; |
| 2193 | case Token::MOD: |
| 2194 | case Token::BIT_OR: |
| 2195 | case Token::BIT_AND: |
| 2196 | case Token::BIT_XOR: |
| 2197 | case Token::SAR: |
| 2198 | case Token::SHL: |
| 2199 | case Token::SHR: |
| 2200 | GenerateRegisterArgsPush(masm); |
| 2201 | break; |
| 2202 | default: |
| 2203 | UNREACHABLE(); |
| 2204 | } |
| 2205 | |
| 2206 | GenerateSmiCode(masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS); |
| 2207 | |
| 2208 | // Floating point case. |
| 2209 | switch (op_) { |
| 2210 | case Token::ADD: |
| 2211 | case Token::SUB: |
| 2212 | case Token::MUL: |
| 2213 | case Token::DIV: { |
| 2214 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2215 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2216 | CpuFeatures::Scope use_sse2(SSE2); |
| 2217 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 2218 | |
| 2219 | switch (op_) { |
| 2220 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2221 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2222 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2223 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2224 | default: UNREACHABLE(); |
| 2225 | } |
| 2226 | GenerateHeapResultAllocation(masm, &call_runtime); |
| 2227 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2228 | __ ret(0); |
| 2229 | } else { // SSE2 not available, use FPU. |
| 2230 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2231 | FloatingPointHelper::LoadFloatOperands( |
| 2232 | masm, |
| 2233 | ecx, |
| 2234 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2235 | switch (op_) { |
| 2236 | case Token::ADD: __ faddp(1); break; |
| 2237 | case Token::SUB: __ fsubp(1); break; |
| 2238 | case Token::MUL: __ fmulp(1); break; |
| 2239 | case Token::DIV: __ fdivp(1); break; |
| 2240 | default: UNREACHABLE(); |
| 2241 | } |
| 2242 | Label after_alloc_failure; |
| 2243 | GenerateHeapResultAllocation(masm, &after_alloc_failure); |
| 2244 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2245 | __ ret(0); |
| 2246 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2247 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 2248 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2249 | } |
| 2250 | __ bind(¬_floats); |
| 2251 | break; |
| 2252 | } |
| 2253 | case Token::MOD: { |
| 2254 | // For MOD we go directly to runtime in the non-smi case. |
| 2255 | break; |
| 2256 | } |
| 2257 | case Token::BIT_OR: |
| 2258 | case Token::BIT_AND: |
| 2259 | case Token::BIT_XOR: |
| 2260 | case Token::SAR: |
| 2261 | case Token::SHL: |
| 2262 | case Token::SHR: { |
| 2263 | Label non_smi_result; |
| 2264 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
| 2265 | use_sse3_, |
| 2266 | &call_runtime); |
| 2267 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2268 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2269 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2270 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2271 | case Token::SAR: __ sar_cl(eax); break; |
| 2272 | case Token::SHL: __ shl_cl(eax); break; |
| 2273 | case Token::SHR: __ shr_cl(eax); break; |
| 2274 | default: UNREACHABLE(); |
| 2275 | } |
| 2276 | if (op_ == Token::SHR) { |
| 2277 | // Check if result is non-negative and fits in a smi. |
| 2278 | __ test(eax, Immediate(0xc0000000)); |
| 2279 | __ j(not_zero, &call_runtime); |
| 2280 | } else { |
| 2281 | // Check if result fits in a smi. |
| 2282 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2283 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2284 | } |
| 2285 | // Tag smi result and return. |
| 2286 | __ SmiTag(eax); |
| 2287 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 2288 | |
| 2289 | // All ops except SHR return a signed int32 that we load in |
| 2290 | // a HeapNumber. |
| 2291 | if (op_ != Token::SHR) { |
| 2292 | __ bind(&non_smi_result); |
| 2293 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2294 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2295 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2296 | switch (mode_) { |
| 2297 | case OVERWRITE_LEFT: |
| 2298 | case OVERWRITE_RIGHT: |
| 2299 | // If the operand was an object, we skip the |
| 2300 | // allocation of a heap number. |
| 2301 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2302 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2303 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2304 | // Fall through! |
| 2305 | case NO_OVERWRITE: |
| 2306 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2307 | __ bind(&skip_allocation); |
| 2308 | break; |
| 2309 | default: UNREACHABLE(); |
| 2310 | } |
| 2311 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2312 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2313 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2314 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2315 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2316 | } else { |
| 2317 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2318 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2319 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2320 | } |
| 2321 | __ ret(2 * kPointerSize); |
| 2322 | } |
| 2323 | break; |
| 2324 | } |
| 2325 | default: UNREACHABLE(); break; |
| 2326 | } |
| 2327 | |
| 2328 | // If all else fails, use the runtime system to get the correct |
| 2329 | // result. |
| 2330 | __ bind(&call_runtime); |
| 2331 | switch (op_) { |
| 2332 | case Token::ADD: { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2333 | GenerateAddStrings(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2334 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2335 | __ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION); |
| 2336 | break; |
| 2337 | } |
| 2338 | case Token::SUB: |
| 2339 | GenerateRegisterArgsPush(masm); |
| 2340 | __ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION); |
| 2341 | break; |
| 2342 | case Token::MUL: |
| 2343 | GenerateRegisterArgsPush(masm); |
| 2344 | __ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION); |
| 2345 | break; |
| 2346 | case Token::DIV: |
| 2347 | GenerateRegisterArgsPush(masm); |
| 2348 | __ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION); |
| 2349 | break; |
| 2350 | case Token::MOD: |
| 2351 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 2352 | break; |
| 2353 | case Token::BIT_OR: |
| 2354 | __ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION); |
| 2355 | break; |
| 2356 | case Token::BIT_AND: |
| 2357 | __ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION); |
| 2358 | break; |
| 2359 | case Token::BIT_XOR: |
| 2360 | __ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION); |
| 2361 | break; |
| 2362 | case Token::SAR: |
| 2363 | __ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION); |
| 2364 | break; |
| 2365 | case Token::SHL: |
| 2366 | __ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION); |
| 2367 | break; |
| 2368 | case Token::SHR: |
| 2369 | __ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION); |
| 2370 | break; |
| 2371 | default: |
| 2372 | UNREACHABLE(); |
| 2373 | } |
| 2374 | } |
| 2375 | |
| 2376 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2377 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2378 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2379 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2380 | |
| 2381 | // Registers containing left and right operands respectively. |
| 2382 | Register left = edx; |
| 2383 | Register right = eax; |
| 2384 | |
| 2385 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2386 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2387 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2388 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2389 | |
| 2390 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 2391 | GenerateRegisterArgsPush(masm); |
| 2392 | __ TailCallStub(&string_add_left_stub); |
| 2393 | |
| 2394 | // Left operand is not a string, test right. |
| 2395 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2396 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2397 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2398 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2399 | |
| 2400 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
| 2401 | GenerateRegisterArgsPush(masm); |
| 2402 | __ TailCallStub(&string_add_right_stub); |
| 2403 | |
| 2404 | // Neither argument is a string. |
| 2405 | __ bind(&call_runtime); |
| 2406 | } |
| 2407 | |
| 2408 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2409 | void BinaryOpStub::GenerateHeapResultAllocation( |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2410 | MacroAssembler* masm, |
| 2411 | Label* alloc_failure) { |
| 2412 | Label skip_allocation; |
| 2413 | OverwriteMode mode = mode_; |
| 2414 | switch (mode) { |
| 2415 | case OVERWRITE_LEFT: { |
| 2416 | // If the argument in edx is already an object, we skip the |
| 2417 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2418 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2419 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2420 | // for the possible runtime call. |
| 2421 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2422 | // Now edx can be overwritten losing one of the arguments as we are |
| 2423 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2424 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2425 | __ bind(&skip_allocation); |
| 2426 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2427 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2428 | break; |
| 2429 | } |
| 2430 | case OVERWRITE_RIGHT: |
| 2431 | // If the argument in eax is already an object, we skip the |
| 2432 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2433 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2434 | // Fall through! |
| 2435 | case NO_OVERWRITE: |
| 2436 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2437 | // for the possible runtime call. |
| 2438 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2439 | // Now eax can be overwritten losing one of the arguments as we are |
| 2440 | // now done and will not need it any more. |
| 2441 | __ mov(eax, ebx); |
| 2442 | __ bind(&skip_allocation); |
| 2443 | break; |
| 2444 | default: UNREACHABLE(); |
| 2445 | } |
| 2446 | } |
| 2447 | |
| 2448 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2449 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2450 | __ pop(ecx); |
| 2451 | __ push(edx); |
| 2452 | __ push(eax); |
| 2453 | __ push(ecx); |
| 2454 | } |
| 2455 | |
| 2456 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2457 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2458 | // TAGGED case: |
| 2459 | // Input: |
| 2460 | // esp[4]: tagged number input argument (should be number). |
| 2461 | // esp[0]: return address. |
| 2462 | // Output: |
| 2463 | // eax: tagged double result. |
| 2464 | // UNTAGGED case: |
| 2465 | // Input:: |
| 2466 | // esp[0]: return address. |
| 2467 | // xmm1: untagged double input argument |
| 2468 | // Output: |
| 2469 | // xmm1: untagged double result. |
| 2470 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2471 | Label runtime_call; |
| 2472 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2473 | Label skip_cache; |
| 2474 | const bool tagged = (argument_type_ == TAGGED); |
| 2475 | if (tagged) { |
| 2476 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2477 | Label input_not_smi; |
| 2478 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2479 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2480 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2481 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2482 | // Then load the low and high words of the double into ebx, edx. |
| 2483 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2484 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2485 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2486 | __ mov(Operand(esp, 0), eax); |
| 2487 | __ fild_s(Operand(esp, 0)); |
| 2488 | __ fst_d(Operand(esp, 0)); |
| 2489 | __ pop(edx); |
| 2490 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2491 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2492 | __ bind(&input_not_smi); |
| 2493 | // Check if input is a HeapNumber. |
| 2494 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2495 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2496 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2497 | __ j(not_equal, &runtime_call); |
| 2498 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2499 | // low and high words into ebx, edx. |
| 2500 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2501 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2502 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2503 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2504 | __ bind(&loaded); |
| 2505 | } else { // UNTAGGED. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2506 | if (CpuFeatures::IsSupported(SSE4_1)) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2507 | CpuFeatures::Scope sse4_scope(SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2508 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2509 | } else { |
| 2510 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2511 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2512 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2513 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2517 | // ebx = low 32 bits of double value |
| 2518 | // edx = high 32 bits of double value |
| 2519 | // Compute hash (the shifts are arithmetic): |
| 2520 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2521 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2522 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2523 | __ mov(eax, ecx); |
| 2524 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2525 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2526 | __ mov(eax, ecx); |
| 2527 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2528 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2529 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2530 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2531 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2532 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2533 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2534 | // ebx = low 32 bits of double value. |
| 2535 | // edx = high 32 bits of double value. |
| 2536 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2537 | ExternalReference cache_array = |
| 2538 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2539 | __ mov(eax, Immediate(cache_array)); |
| 2540 | int cache_array_index = |
| 2541 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2542 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2543 | // Eax points to the cache for the type type_. |
| 2544 | // 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] | 2545 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2546 | __ j(zero, &runtime_call_clear_stack); |
| 2547 | #ifdef DEBUG |
| 2548 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2549 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2550 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2551 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2552 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2553 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2554 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2555 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2556 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2557 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2558 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2559 | } |
| 2560 | #endif |
| 2561 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2562 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2563 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2564 | // 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] | 2565 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2566 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2567 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2568 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2569 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2570 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2571 | Counters* counters = masm->isolate()->counters(); |
| 2572 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2573 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2574 | if (tagged) { |
| 2575 | __ fstp(0); |
| 2576 | __ ret(kPointerSize); |
| 2577 | } else { // UNTAGGED. |
| 2578 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2579 | __ Ret(); |
| 2580 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2581 | |
| 2582 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2583 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2584 | // Update cache with new value. |
| 2585 | // We are short on registers, so use no_reg as scratch. |
| 2586 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2587 | if (tagged) { |
| 2588 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2589 | } else { // UNTAGGED. |
| 2590 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2591 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2592 | __ movdbl(Operand(esp, 0), xmm1); |
| 2593 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2594 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2595 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2596 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2597 | __ mov(Operand(ecx, 0), ebx); |
| 2598 | __ mov(Operand(ecx, kIntSize), edx); |
| 2599 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2600 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2601 | if (tagged) { |
| 2602 | __ ret(kPointerSize); |
| 2603 | } else { // UNTAGGED. |
| 2604 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2605 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2606 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2607 | // Skip cache and return answer directly, only in untagged case. |
| 2608 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2609 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2610 | __ movdbl(Operand(esp, 0), xmm1); |
| 2611 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2612 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2613 | __ fstp_d(Operand(esp, 0)); |
| 2614 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2615 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2616 | // We return the value in xmm1 without adding it to the cache, but |
| 2617 | // 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] | 2618 | { |
| 2619 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2620 | // Allocate an unused object bigger than a HeapNumber. |
| 2621 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2622 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2623 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2624 | __ Ret(); |
| 2625 | } |
| 2626 | |
| 2627 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2628 | if (tagged) { |
| 2629 | __ bind(&runtime_call_clear_stack); |
| 2630 | __ fstp(0); |
| 2631 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2632 | ExternalReference runtime = |
| 2633 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2634 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2635 | } else { // UNTAGGED. |
| 2636 | __ bind(&runtime_call_clear_stack); |
| 2637 | __ bind(&runtime_call); |
| 2638 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2639 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2640 | { |
| 2641 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2642 | __ push(eax); |
| 2643 | __ CallRuntime(RuntimeFunction(), 1); |
| 2644 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2645 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2646 | __ Ret(); |
| 2647 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | |
| 2651 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2652 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2653 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2654 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2655 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2656 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2657 | default: |
| 2658 | UNIMPLEMENTED(); |
| 2659 | return Runtime::kAbort; |
| 2660 | } |
| 2661 | } |
| 2662 | |
| 2663 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2664 | void TranscendentalCacheStub::GenerateOperation( |
| 2665 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2666 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2667 | // Input value is on FP stack, and also in ebx/edx. |
| 2668 | // Input value is possibly in xmm1. |
| 2669 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2670 | if (type == TranscendentalCache::SIN || |
| 2671 | type == TranscendentalCache::COS || |
| 2672 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2673 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2674 | // return NaN for infinities and NaN. They can share all code except |
| 2675 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2676 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2677 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2678 | // work. We must reduce it to the appropriate range. |
| 2679 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2680 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2681 | int supported_exponent_limit = |
| 2682 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2683 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2684 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2685 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2686 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2687 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2688 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2689 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2690 | __ fstp(0); |
| 2691 | // NaN is represented by 0x7ff8000000000000. |
| 2692 | __ push(Immediate(0x7ff80000)); |
| 2693 | __ push(Immediate(0)); |
| 2694 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2695 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2696 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2697 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2698 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2699 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2700 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2701 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2702 | __ fldpi(); |
| 2703 | __ fadd(0); |
| 2704 | __ fld(1); |
| 2705 | // FPU Stack: input, 2*pi, input. |
| 2706 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2707 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2708 | __ fwait(); |
| 2709 | __ fnstsw_ax(); |
| 2710 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2711 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2712 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2713 | __ fnclex(); |
| 2714 | __ bind(&no_exceptions); |
| 2715 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2716 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2717 | // Compute st(0) % st(1) |
| 2718 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2719 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2720 | __ bind(&partial_remainder_loop); |
| 2721 | __ fprem1(); |
| 2722 | __ fwait(); |
| 2723 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2724 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2725 | // If C2 is set, computation only has partial result. Loop to |
| 2726 | // continue computation. |
| 2727 | __ j(not_zero, &partial_remainder_loop); |
| 2728 | } |
| 2729 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2730 | __ fstp(2); |
| 2731 | __ fstp(0); |
| 2732 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2733 | |
| 2734 | // FPU Stack: input % 2*pi |
| 2735 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2736 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2737 | case TranscendentalCache::SIN: |
| 2738 | __ fsin(); |
| 2739 | break; |
| 2740 | case TranscendentalCache::COS: |
| 2741 | __ fcos(); |
| 2742 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2743 | case TranscendentalCache::TAN: |
| 2744 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2745 | // FP register stack. |
| 2746 | __ fptan(); |
| 2747 | __ fstp(0); // Pop FP register stack. |
| 2748 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2749 | default: |
| 2750 | UNREACHABLE(); |
| 2751 | } |
| 2752 | __ bind(&done); |
| 2753 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2754 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2755 | __ fldln2(); |
| 2756 | __ fxch(); |
| 2757 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2758 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2762 | // Input: edx, eax are the left and right objects of a bit op. |
| 2763 | // 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] | 2764 | void FloatingPointHelper::LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 2765 | bool use_sse3, |
| 2766 | Label* conversion_failure) { |
| 2767 | // Check float operands. |
| 2768 | Label arg1_is_object, check_undefined_arg1; |
| 2769 | Label arg2_is_object, check_undefined_arg2; |
| 2770 | Label load_arg2, done; |
| 2771 | |
| 2772 | // Test if arg1 is a Smi. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2773 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2774 | |
| 2775 | __ SmiUntag(edx); |
| 2776 | __ jmp(&load_arg2); |
| 2777 | |
| 2778 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2779 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2780 | Factory* factory = masm->isolate()->factory(); |
| 2781 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2782 | __ j(not_equal, conversion_failure); |
| 2783 | __ mov(edx, Immediate(0)); |
| 2784 | __ jmp(&load_arg2); |
| 2785 | |
| 2786 | __ bind(&arg1_is_object); |
| 2787 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2788 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2789 | __ j(not_equal, &check_undefined_arg1); |
| 2790 | |
| 2791 | // 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] | 2792 | IntegerConvert(masm, edx, use_sse3, conversion_failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2793 | __ mov(edx, ecx); |
| 2794 | |
| 2795 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2796 | __ bind(&load_arg2); |
| 2797 | |
| 2798 | // Test if arg2 is a Smi. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2799 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2800 | |
| 2801 | __ SmiUntag(eax); |
| 2802 | __ mov(ecx, eax); |
| 2803 | __ jmp(&done); |
| 2804 | |
| 2805 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2806 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2807 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2808 | __ j(not_equal, conversion_failure); |
| 2809 | __ mov(ecx, Immediate(0)); |
| 2810 | __ jmp(&done); |
| 2811 | |
| 2812 | __ bind(&arg2_is_object); |
| 2813 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2814 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2815 | __ j(not_equal, &check_undefined_arg2); |
| 2816 | |
| 2817 | // 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] | 2818 | IntegerConvert(masm, eax, use_sse3, conversion_failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2819 | __ bind(&done); |
| 2820 | __ mov(eax, edx); |
| 2821 | } |
| 2822 | |
| 2823 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2824 | void FloatingPointHelper::CheckLoadedIntegersWereInt32(MacroAssembler* masm, |
| 2825 | bool use_sse3, |
| 2826 | Label* not_int32) { |
| 2827 | return; |
| 2828 | } |
| 2829 | |
| 2830 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2831 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2832 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2833 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2834 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2835 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2836 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2837 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2838 | |
| 2839 | __ bind(&load_smi); |
| 2840 | __ SmiUntag(number); |
| 2841 | __ push(number); |
| 2842 | __ fild_s(Operand(esp, 0)); |
| 2843 | __ pop(number); |
| 2844 | |
| 2845 | __ bind(&done); |
| 2846 | } |
| 2847 | |
| 2848 | |
| 2849 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2850 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2851 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2852 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2853 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2854 | |
| 2855 | __ bind(&load_eax); |
| 2856 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2857 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2858 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2859 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2860 | |
| 2861 | __ bind(&load_smi_edx); |
| 2862 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2863 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2864 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2865 | __ jmp(&load_eax); |
| 2866 | |
| 2867 | __ bind(&load_smi_eax); |
| 2868 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2869 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2870 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2871 | |
| 2872 | __ bind(&done); |
| 2873 | } |
| 2874 | |
| 2875 | |
| 2876 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2877 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2878 | 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] | 2879 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2880 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2881 | Factory* factory = masm->isolate()->factory(); |
| 2882 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2883 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2884 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2885 | __ bind(&load_eax); |
| 2886 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2887 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2888 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2889 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2890 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2891 | __ bind(&load_smi_edx); |
| 2892 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2893 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2894 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2895 | __ jmp(&load_eax); |
| 2896 | __ bind(&load_smi_eax); |
| 2897 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2898 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2899 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2900 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2901 | __ bind(&load_float_eax); |
| 2902 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2903 | __ bind(&done); |
| 2904 | } |
| 2905 | |
| 2906 | |
| 2907 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2908 | Register scratch) { |
| 2909 | const Register left = edx; |
| 2910 | const Register right = eax; |
| 2911 | __ mov(scratch, left); |
| 2912 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2913 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2914 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2915 | |
| 2916 | __ mov(scratch, right); |
| 2917 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2918 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2922 | void FloatingPointHelper::CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 2923 | Label* non_int32, |
| 2924 | Register scratch) { |
| 2925 | __ cvttsd2si(scratch, Operand(xmm0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2926 | __ cvtsi2sd(xmm2, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2927 | __ ucomisd(xmm0, xmm2); |
| 2928 | __ j(not_zero, non_int32); |
| 2929 | __ j(carry, non_int32); |
| 2930 | __ cvttsd2si(scratch, Operand(xmm1)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2931 | __ cvtsi2sd(xmm2, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2932 | __ ucomisd(xmm1, xmm2); |
| 2933 | __ j(not_zero, non_int32); |
| 2934 | __ j(carry, non_int32); |
| 2935 | } |
| 2936 | |
| 2937 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2938 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2939 | Register scratch, |
| 2940 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2941 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2942 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2943 | __ mov(scratch, edx); |
| 2944 | } else { |
| 2945 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2946 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2947 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2948 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2949 | __ bind(&done_load_1); |
| 2950 | |
| 2951 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2952 | __ mov(scratch, eax); |
| 2953 | } else { |
| 2954 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2955 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2956 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2957 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2958 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2959 | |
| 2960 | __ bind(&load_smi_1); |
| 2961 | __ SmiUntag(scratch); |
| 2962 | __ push(scratch); |
| 2963 | __ fild_s(Operand(esp, 0)); |
| 2964 | __ pop(scratch); |
| 2965 | __ jmp(&done_load_1); |
| 2966 | |
| 2967 | __ bind(&load_smi_2); |
| 2968 | __ SmiUntag(scratch); |
| 2969 | __ push(scratch); |
| 2970 | __ fild_s(Operand(esp, 0)); |
| 2971 | __ pop(scratch); |
| 2972 | |
| 2973 | __ bind(&done); |
| 2974 | } |
| 2975 | |
| 2976 | |
| 2977 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2978 | Register scratch) { |
| 2979 | const Register left = edx; |
| 2980 | const Register right = eax; |
| 2981 | __ mov(scratch, left); |
| 2982 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2983 | __ SmiUntag(scratch); |
| 2984 | __ push(scratch); |
| 2985 | __ fild_s(Operand(esp, 0)); |
| 2986 | |
| 2987 | __ mov(scratch, right); |
| 2988 | __ SmiUntag(scratch); |
| 2989 | __ mov(Operand(esp, 0), scratch); |
| 2990 | __ fild_s(Operand(esp, 0)); |
| 2991 | __ pop(scratch); |
| 2992 | } |
| 2993 | |
| 2994 | |
| 2995 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2996 | Label* non_float, |
| 2997 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2998 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2999 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 3000 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3001 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3002 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3003 | Factory* factory = masm->isolate()->factory(); |
| 3004 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3005 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 3006 | |
| 3007 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3008 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3009 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3010 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3011 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 3012 | |
| 3013 | // Fall-through: Both operands are numbers. |
| 3014 | __ bind(&done); |
| 3015 | } |
| 3016 | |
| 3017 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3018 | void FloatingPointHelper::CheckFloatOperandsAreInt32(MacroAssembler* masm, |
| 3019 | Label* non_int32) { |
| 3020 | return; |
| 3021 | } |
| 3022 | |
| 3023 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3024 | void MathPowStub::Generate(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3025 | CpuFeatures::Scope use_sse2(SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3026 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3027 | const Register exponent = eax; |
| 3028 | const Register base = edx; |
| 3029 | const Register scratch = ecx; |
| 3030 | const XMMRegister double_result = xmm3; |
| 3031 | const XMMRegister double_base = xmm2; |
| 3032 | const XMMRegister double_exponent = xmm1; |
| 3033 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3034 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3035 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3036 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3037 | // Save 1 in double_result - we need this several times later on. |
| 3038 | __ mov(scratch, Immediate(1)); |
| 3039 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3040 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3041 | if (exponent_type_ == ON_STACK) { |
| 3042 | Label base_is_smi, unpack_exponent; |
| 3043 | // The exponent and base are supplied as arguments on the stack. |
| 3044 | // This can only happen if the stub is called from non-optimized code. |
| 3045 | // Load input parameters from stack. |
| 3046 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 3047 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 3048 | |
| 3049 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 3050 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 3051 | factory->heap_number_map()); |
| 3052 | __ j(not_equal, &call_runtime); |
| 3053 | |
| 3054 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 3055 | __ jmp(&unpack_exponent, Label::kNear); |
| 3056 | |
| 3057 | __ bind(&base_is_smi); |
| 3058 | __ SmiUntag(base); |
| 3059 | __ cvtsi2sd(double_base, base); |
| 3060 | |
| 3061 | __ bind(&unpack_exponent); |
| 3062 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 3063 | __ SmiUntag(exponent); |
| 3064 | __ jmp(&int_exponent); |
| 3065 | |
| 3066 | __ bind(&exponent_not_smi); |
| 3067 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 3068 | factory->heap_number_map()); |
| 3069 | __ j(not_equal, &call_runtime); |
| 3070 | __ movdbl(double_exponent, |
| 3071 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3072 | } else if (exponent_type_ == TAGGED) { |
| 3073 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 3074 | __ SmiUntag(exponent); |
| 3075 | __ jmp(&int_exponent); |
| 3076 | |
| 3077 | __ bind(&exponent_not_smi); |
| 3078 | __ movdbl(double_exponent, |
| 3079 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3080 | } |
| 3081 | |
| 3082 | if (exponent_type_ != INTEGER) { |
| 3083 | Label fast_power; |
| 3084 | // Detect integer exponents stored as double. |
| 3085 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 3086 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 3087 | __ cmp(exponent, Immediate(0x80000000u)); |
| 3088 | __ j(equal, &call_runtime); |
| 3089 | __ cvtsi2sd(double_scratch, exponent); |
| 3090 | // Already ruled out NaNs for exponent. |
| 3091 | __ ucomisd(double_exponent, double_scratch); |
| 3092 | __ j(equal, &int_exponent); |
| 3093 | |
| 3094 | if (exponent_type_ == ON_STACK) { |
| 3095 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 3096 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 3097 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 3098 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 3099 | // Test for 0.5. |
| 3100 | // Load double_scratch with 0.5. |
| 3101 | __ mov(scratch, Immediate(0x3F000000u)); |
| 3102 | __ movd(double_scratch, scratch); |
| 3103 | __ cvtss2sd(double_scratch, double_scratch); |
| 3104 | // Already ruled out NaNs for exponent. |
| 3105 | __ ucomisd(double_scratch, double_exponent); |
| 3106 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 3107 | |
| 3108 | // Calculates square root of base. Check for the special case of |
| 3109 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 3110 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3111 | // 9 bits set and the lowest 23 bits cleared. |
| 3112 | __ mov(scratch, 0xFF800000u); |
| 3113 | __ movd(double_scratch, scratch); |
| 3114 | __ cvtss2sd(double_scratch, double_scratch); |
| 3115 | __ ucomisd(double_base, double_scratch); |
| 3116 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3117 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3118 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 3119 | __ j(carry, &continue_sqrt, Label::kNear); |
| 3120 | |
| 3121 | // Set result to Infinity in the special case. |
| 3122 | __ xorps(double_result, double_result); |
| 3123 | __ subsd(double_result, double_scratch); |
| 3124 | __ jmp(&done); |
| 3125 | |
| 3126 | __ bind(&continue_sqrt); |
| 3127 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3128 | __ xorps(double_scratch, double_scratch); |
| 3129 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 3130 | __ sqrtsd(double_result, double_scratch); |
| 3131 | __ jmp(&done); |
| 3132 | |
| 3133 | // Test for -0.5. |
| 3134 | __ bind(¬_plus_half); |
| 3135 | // Load double_exponent with -0.5 by substracting 1. |
| 3136 | __ subsd(double_scratch, double_result); |
| 3137 | // Already ruled out NaNs for exponent. |
| 3138 | __ ucomisd(double_scratch, double_exponent); |
| 3139 | __ j(not_equal, &fast_power, Label::kNear); |
| 3140 | |
| 3141 | // Calculates reciprocal of square root of base. Check for the special |
| 3142 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 3143 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3144 | // 9 bits set and the lowest 23 bits cleared. |
| 3145 | __ mov(scratch, 0xFF800000u); |
| 3146 | __ movd(double_scratch, scratch); |
| 3147 | __ cvtss2sd(double_scratch, double_scratch); |
| 3148 | __ ucomisd(double_base, double_scratch); |
| 3149 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3150 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3151 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 3152 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 3153 | |
| 3154 | // Set result to 0 in the special case. |
| 3155 | __ xorps(double_result, double_result); |
| 3156 | __ jmp(&done); |
| 3157 | |
| 3158 | __ bind(&continue_rsqrt); |
| 3159 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3160 | __ xorps(double_exponent, double_exponent); |
| 3161 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 3162 | __ sqrtsd(double_exponent, double_exponent); |
| 3163 | __ divsd(double_result, double_exponent); |
| 3164 | __ jmp(&done); |
| 3165 | } |
| 3166 | |
| 3167 | // Using FPU instructions to calculate power. |
| 3168 | Label fast_power_failed; |
| 3169 | __ bind(&fast_power); |
| 3170 | __ fnclex(); // Clear flags to catch exceptions later. |
| 3171 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 3172 | __ sub(esp, Immediate(kDoubleSize)); |
| 3173 | __ movdbl(Operand(esp, 0), double_exponent); |
| 3174 | __ fld_d(Operand(esp, 0)); // E |
| 3175 | __ movdbl(Operand(esp, 0), double_base); |
| 3176 | __ fld_d(Operand(esp, 0)); // B, E |
| 3177 | |
| 3178 | // Exponent is in st(1) and base is in st(0) |
| 3179 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 3180 | // FYL2X calculates st(1) * log2(st(0)) |
| 3181 | __ fyl2x(); // X |
| 3182 | __ fld(0); // X, X |
| 3183 | __ frndint(); // rnd(X), X |
| 3184 | __ fsub(1); // rnd(X), X-rnd(X) |
| 3185 | __ fxch(1); // X - rnd(X), rnd(X) |
| 3186 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 3187 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 3188 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
| 3189 | __ faddp(1); // 1, 2^(X-rnd(X)), rnd(X) |
| 3190 | // FSCALE calculates st(0) * 2^st(1) |
| 3191 | __ fscale(); // 2^X, rnd(X) |
| 3192 | __ fstp(1); |
| 3193 | // Bail out to runtime in case of exceptions in the status word. |
| 3194 | __ fnstsw_ax(); |
| 3195 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 3196 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 3197 | __ fstp_d(Operand(esp, 0)); |
| 3198 | __ movdbl(double_result, Operand(esp, 0)); |
| 3199 | __ add(esp, Immediate(kDoubleSize)); |
| 3200 | __ jmp(&done); |
| 3201 | |
| 3202 | __ bind(&fast_power_failed); |
| 3203 | __ fninit(); |
| 3204 | __ add(esp, Immediate(kDoubleSize)); |
| 3205 | __ jmp(&call_runtime); |
| 3206 | } |
| 3207 | |
| 3208 | // Calculate power with integer exponent. |
| 3209 | __ bind(&int_exponent); |
| 3210 | const XMMRegister double_scratch2 = double_exponent; |
| 3211 | __ mov(scratch, exponent); // Back up exponent. |
| 3212 | __ movsd(double_scratch, double_base); // Back up base. |
| 3213 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3214 | |
| 3215 | // Get absolute value of exponent. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3216 | Label no_neg, while_true, no_multiply; |
| 3217 | __ test(scratch, scratch); |
| 3218 | __ j(positive, &no_neg, Label::kNear); |
| 3219 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3220 | __ bind(&no_neg); |
| 3221 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3222 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3223 | __ shr(scratch, 1); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3224 | __ j(not_carry, &no_multiply, Label::kNear); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3225 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3226 | __ bind(&no_multiply); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3227 | |
| 3228 | __ mulsd(double_scratch, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3229 | __ j(not_zero, &while_true); |
| 3230 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3231 | // scratch has the original value of the exponent - if the exponent is |
| 3232 | // negative, return 1/result. |
| 3233 | __ test(exponent, exponent); |
| 3234 | __ j(positive, &done); |
| 3235 | __ divsd(double_scratch2, double_result); |
| 3236 | __ movsd(double_result, double_scratch2); |
| 3237 | // Test whether result is zero. Bail out to check for subnormal result. |
| 3238 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 3239 | __ xorps(double_scratch2, double_scratch2); |
| 3240 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 3241 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 3242 | // and may not have contained the exponent value in the first place when the |
| 3243 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 3244 | __ j(not_equal, &done); |
| 3245 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3246 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3247 | // Returning or bailing out. |
| 3248 | Counters* counters = masm->isolate()->counters(); |
| 3249 | if (exponent_type_ == ON_STACK) { |
| 3250 | // The arguments are still on the stack. |
| 3251 | __ bind(&call_runtime); |
| 3252 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3253 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3254 | // The stub is called from non-optimized code, which expects the result |
| 3255 | // as heap number in exponent. |
| 3256 | __ bind(&done); |
| 3257 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 3258 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 3259 | __ IncrementCounter(counters->math_pow(), 1); |
| 3260 | __ ret(2 * kPointerSize); |
| 3261 | } else { |
| 3262 | __ bind(&call_runtime); |
| 3263 | { |
| 3264 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3265 | __ PrepareCallCFunction(4, scratch); |
| 3266 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 3267 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 3268 | __ CallCFunction( |
| 3269 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 3270 | } |
| 3271 | // Return value is in st(0) on ia32. |
| 3272 | // Store it into the (fixed) result register. |
| 3273 | __ sub(esp, Immediate(kDoubleSize)); |
| 3274 | __ fstp_d(Operand(esp, 0)); |
| 3275 | __ movdbl(double_result, Operand(esp, 0)); |
| 3276 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3277 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3278 | __ bind(&done); |
| 3279 | __ IncrementCounter(counters->math_pow(), 1); |
| 3280 | __ ret(0); |
| 3281 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3285 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3286 | // The key is in edx and the parameter count is in eax. |
| 3287 | |
| 3288 | // The displacement is used for skipping the frame pointer on the |
| 3289 | // stack. It is the offset of the last parameter (if any) relative |
| 3290 | // to the frame pointer. |
| 3291 | static const int kDisplacement = 1 * kPointerSize; |
| 3292 | |
| 3293 | // Check that the key is a smi. |
| 3294 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3295 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3296 | |
| 3297 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3298 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3299 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3300 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3301 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3302 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3303 | |
| 3304 | // Check index against formal parameters count limit passed in |
| 3305 | // through register eax. Use unsigned comparison to get negative |
| 3306 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3307 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3308 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3309 | |
| 3310 | // Read the argument from the stack and return it. |
| 3311 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3312 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3313 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3314 | __ neg(edx); |
| 3315 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3316 | __ ret(0); |
| 3317 | |
| 3318 | // Arguments adaptor case: Check index against actual arguments |
| 3319 | // limit found in the arguments adaptor frame. Use unsigned |
| 3320 | // comparison to get negative check for free. |
| 3321 | __ bind(&adaptor); |
| 3322 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3323 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3324 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3325 | |
| 3326 | // Read the argument from the stack and return it. |
| 3327 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3328 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3329 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3330 | __ neg(edx); |
| 3331 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3332 | __ ret(0); |
| 3333 | |
| 3334 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3335 | // by calling the runtime system. |
| 3336 | __ bind(&slow); |
| 3337 | __ pop(ebx); // Return address. |
| 3338 | __ push(edx); |
| 3339 | __ push(ebx); |
| 3340 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3341 | } |
| 3342 | |
| 3343 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3344 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3345 | // esp[0] : return address |
| 3346 | // esp[4] : number of parameters |
| 3347 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3348 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3349 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3350 | // Check if the calling frame is an arguments adaptor frame. |
| 3351 | Label runtime; |
| 3352 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3353 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3354 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3355 | __ j(not_equal, &runtime, Label::kNear); |
| 3356 | |
| 3357 | // Patch the arguments.length and the parameters pointer. |
| 3358 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3359 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3360 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3361 | StandardFrameConstants::kCallerSPOffset)); |
| 3362 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3363 | |
| 3364 | __ bind(&runtime); |
| 3365 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3366 | } |
| 3367 | |
| 3368 | |
| 3369 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 3370 | // esp[0] : return address |
| 3371 | // esp[4] : number of parameters (tagged) |
| 3372 | // esp[8] : receiver displacement |
| 3373 | // esp[12] : function |
| 3374 | |
| 3375 | // ebx = parameter count (tagged) |
| 3376 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3377 | |
| 3378 | // Check if the calling frame is an arguments adaptor frame. |
| 3379 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3380 | // Generate* functions. |
| 3381 | Label runtime; |
| 3382 | Label adaptor_frame, try_allocate; |
| 3383 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3384 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3385 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3386 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3387 | |
| 3388 | // No adaptor, parameter count = argument count. |
| 3389 | __ mov(ecx, ebx); |
| 3390 | __ jmp(&try_allocate, Label::kNear); |
| 3391 | |
| 3392 | // We have an adaptor frame. Patch the parameters pointer. |
| 3393 | __ bind(&adaptor_frame); |
| 3394 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3395 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3396 | StandardFrameConstants::kCallerSPOffset)); |
| 3397 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3398 | |
| 3399 | // ebx = parameter count (tagged) |
| 3400 | // ecx = argument count (tagged) |
| 3401 | // esp[4] = parameter count (tagged) |
| 3402 | // esp[8] = address of receiver argument |
| 3403 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3404 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3405 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3406 | __ mov(ebx, ecx); |
| 3407 | |
| 3408 | __ bind(&try_allocate); |
| 3409 | |
| 3410 | // Save mapped parameter count. |
| 3411 | __ push(ebx); |
| 3412 | |
| 3413 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3414 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3415 | const int kParameterMapHeaderSize = |
| 3416 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3417 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3418 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3419 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3420 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3421 | __ bind(&no_parameter_map); |
| 3422 | |
| 3423 | // 2. Backing store. |
| 3424 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3425 | |
| 3426 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3427 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3428 | |
| 3429 | // Do the allocation of all three objects in one go. |
| 3430 | __ AllocateInNewSpace(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
| 3431 | |
| 3432 | // eax = address of new object(s) (tagged) |
| 3433 | // ecx = argument count (tagged) |
| 3434 | // esp[0] = mapped parameter count (tagged) |
| 3435 | // esp[8] = parameter count (tagged) |
| 3436 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame^] | 3437 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3438 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame^] | 3439 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3440 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3441 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3442 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3443 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3444 | __ mov(edi, Operand(edi, |
| 3445 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3446 | __ jmp(©, Label::kNear); |
| 3447 | |
| 3448 | __ bind(&has_mapped_parameters); |
| 3449 | __ mov(edi, Operand(edi, |
| 3450 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3451 | __ bind(©); |
| 3452 | |
| 3453 | // eax = address of new object (tagged) |
| 3454 | // ebx = mapped parameter count (tagged) |
| 3455 | // ecx = argument count (tagged) |
| 3456 | // edi = address of boilerplate object (tagged) |
| 3457 | // esp[0] = mapped parameter count (tagged) |
| 3458 | // esp[8] = parameter count (tagged) |
| 3459 | // esp[12] = address of receiver argument |
| 3460 | // Copy the JS object part. |
| 3461 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3462 | __ mov(edx, FieldOperand(edi, i)); |
| 3463 | __ mov(FieldOperand(eax, i), edx); |
| 3464 | } |
| 3465 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3466 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3467 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3468 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3469 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3470 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3471 | edx); |
| 3472 | |
| 3473 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3474 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3475 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3476 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3477 | ecx); |
| 3478 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3479 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3480 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3481 | // backing store. |
| 3482 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3483 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3484 | |
| 3485 | // eax = address of new object (tagged) |
| 3486 | // ebx = mapped parameter count (tagged) |
| 3487 | // ecx = argument count (tagged) |
| 3488 | // edi = address of parameter map or backing store (tagged) |
| 3489 | // esp[0] = mapped parameter count (tagged) |
| 3490 | // esp[8] = parameter count (tagged) |
| 3491 | // esp[12] = address of receiver argument |
| 3492 | // Free a register. |
| 3493 | __ push(eax); |
| 3494 | |
| 3495 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3496 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3497 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3498 | __ j(zero, &skip_parameter_map); |
| 3499 | |
| 3500 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3501 | Immediate(FACTORY->non_strict_arguments_elements_map())); |
| 3502 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3503 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3504 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3505 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3506 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3507 | |
| 3508 | // Copy the parameter slots and the holes in the arguments. |
| 3509 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3510 | // where parameters are stored in reverse order, at |
| 3511 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3512 | // The mapped parameter thus need to get indices |
| 3513 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3514 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3515 | // We loop from right to left. |
| 3516 | Label parameters_loop, parameters_test; |
| 3517 | __ push(ecx); |
| 3518 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3519 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3520 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3521 | __ sub(ebx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3522 | __ mov(ecx, FACTORY->the_hole_value()); |
| 3523 | __ mov(edx, edi); |
| 3524 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3525 | // eax = loop variable (tagged) |
| 3526 | // ebx = mapping index (tagged) |
| 3527 | // ecx = the hole value |
| 3528 | // edx = address of parameter map (tagged) |
| 3529 | // edi = address of backing store (tagged) |
| 3530 | // esp[0] = argument count (tagged) |
| 3531 | // esp[4] = address of new object (tagged) |
| 3532 | // esp[8] = mapped parameter count (tagged) |
| 3533 | // esp[16] = parameter count (tagged) |
| 3534 | // esp[20] = address of receiver argument |
| 3535 | __ jmp(¶meters_test, Label::kNear); |
| 3536 | |
| 3537 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3538 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3539 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3540 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3541 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3542 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3543 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3544 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3545 | __ pop(ecx); |
| 3546 | |
| 3547 | __ bind(&skip_parameter_map); |
| 3548 | |
| 3549 | // ecx = argument count (tagged) |
| 3550 | // edi = address of backing store (tagged) |
| 3551 | // esp[0] = address of new object (tagged) |
| 3552 | // esp[4] = mapped parameter count (tagged) |
| 3553 | // esp[12] = parameter count (tagged) |
| 3554 | // esp[16] = address of receiver argument |
| 3555 | // Copy arguments header and remaining slots (if there are any). |
| 3556 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3557 | Immediate(FACTORY->fixed_array_map())); |
| 3558 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3559 | |
| 3560 | Label arguments_loop, arguments_test; |
| 3561 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3562 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3563 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3564 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3565 | __ jmp(&arguments_test, Label::kNear); |
| 3566 | |
| 3567 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3568 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3569 | __ mov(eax, Operand(edx, 0)); |
| 3570 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3571 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3572 | |
| 3573 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3574 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3575 | __ j(less, &arguments_loop, Label::kNear); |
| 3576 | |
| 3577 | // Restore. |
| 3578 | __ pop(eax); // Address of arguments object. |
| 3579 | __ pop(ebx); // Parameter count. |
| 3580 | |
| 3581 | // Return and remove the on-stack parameters. |
| 3582 | __ ret(3 * kPointerSize); |
| 3583 | |
| 3584 | // Do the runtime call to allocate the arguments object. |
| 3585 | __ bind(&runtime); |
| 3586 | __ pop(eax); // Remove saved parameter count. |
| 3587 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
| 3588 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
| 3589 | } |
| 3590 | |
| 3591 | |
| 3592 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 3593 | // esp[0] : return address |
| 3594 | // esp[4] : number of parameters |
| 3595 | // esp[8] : receiver displacement |
| 3596 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3597 | |
| 3598 | // Check if the calling frame is an arguments adaptor frame. |
| 3599 | Label adaptor_frame, try_allocate, runtime; |
| 3600 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3601 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3602 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3603 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3604 | |
| 3605 | // Get the length from the frame. |
| 3606 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3607 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3608 | |
| 3609 | // Patch the arguments.length and the parameters pointer. |
| 3610 | __ bind(&adaptor_frame); |
| 3611 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3612 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3613 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3614 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3615 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3616 | |
| 3617 | // Try the new space allocation. Start out with computing the size of |
| 3618 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3619 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3620 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3621 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3622 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3623 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3624 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3625 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3626 | |
| 3627 | // Do the allocation of both objects in one go. |
| 3628 | __ AllocateInNewSpace(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
| 3629 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame^] | 3630 | // Get the arguments boilerplate from the current native context. |
| 3631 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3632 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3633 | const int offset = |
| 3634 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3635 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3636 | |
| 3637 | // Copy the JS object part. |
| 3638 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3639 | __ mov(ebx, FieldOperand(edi, i)); |
| 3640 | __ mov(FieldOperand(eax, i), ebx); |
| 3641 | } |
| 3642 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3643 | // 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] | 3644 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3645 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3646 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3647 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3648 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3649 | |
| 3650 | // If there are no actual arguments, we're done. |
| 3651 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3652 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3653 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3654 | |
| 3655 | // Get the parameters pointer from the stack. |
| 3656 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3657 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3658 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3659 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3660 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3661 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3662 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3663 | Immediate(FACTORY->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3664 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3665 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3666 | // Untag the length for the loop below. |
| 3667 | __ SmiUntag(ecx); |
| 3668 | |
| 3669 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3670 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3671 | __ bind(&loop); |
| 3672 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3673 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3674 | __ add(edi, Immediate(kPointerSize)); |
| 3675 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3676 | __ dec(ecx); |
| 3677 | __ j(not_zero, &loop); |
| 3678 | |
| 3679 | // Return and remove the on-stack parameters. |
| 3680 | __ bind(&done); |
| 3681 | __ ret(3 * kPointerSize); |
| 3682 | |
| 3683 | // Do the runtime call to allocate the arguments object. |
| 3684 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3685 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3686 | } |
| 3687 | |
| 3688 | |
| 3689 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3690 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3691 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3692 | // at compilation. |
| 3693 | #ifdef V8_INTERPRETED_REGEXP |
| 3694 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3695 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3696 | |
| 3697 | // Stack frame on entry. |
| 3698 | // esp[0]: return address |
| 3699 | // esp[4]: last_match_info (expected JSArray) |
| 3700 | // esp[8]: previous index |
| 3701 | // esp[12]: subject string |
| 3702 | // esp[16]: JSRegExp object |
| 3703 | |
| 3704 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3705 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3706 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3707 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3708 | |
| 3709 | Label runtime, invoke_regexp; |
| 3710 | |
| 3711 | // Ensure that a RegExp stack is allocated. |
| 3712 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3713 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3714 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3715 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3716 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3717 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3718 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3719 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3720 | |
| 3721 | // Check that the first argument is a JSRegExp object. |
| 3722 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3723 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3724 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3725 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3726 | __ j(not_equal, &runtime); |
| 3727 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3728 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3729 | if (FLAG_debug_code) { |
| 3730 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3731 | __ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected"); |
| 3732 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 3733 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 3734 | } |
| 3735 | |
| 3736 | // ecx: RegExp data (FixedArray) |
| 3737 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3738 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3739 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3740 | __ j(not_equal, &runtime); |
| 3741 | |
| 3742 | // ecx: RegExp data (FixedArray) |
| 3743 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3744 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3745 | // Calculate number of capture registers (number_of_captures + 1) * 2. This |
| 3746 | // uses the asumption that smis are 2 * their untagged value. |
| 3747 | STATIC_ASSERT(kSmiTag == 0); |
| 3748 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3749 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3750 | // Check that the static offsets vector buffer is large enough. |
yangguo@chromium.org | 08eb196 | 2012-08-21 11:19:20 +0000 | [diff] [blame] | 3751 | __ cmp(edx, OffsetsVector::kStaticOffsetsVectorSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3752 | __ j(above, &runtime); |
| 3753 | |
| 3754 | // ecx: RegExp data (FixedArray) |
| 3755 | // edx: Number of capture registers |
| 3756 | // Check that the second argument is a string. |
| 3757 | __ mov(eax, Operand(esp, kSubjectOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3758 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3759 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 3760 | __ j(NegateCondition(is_string), &runtime); |
| 3761 | // Get the length of the string to ebx. |
| 3762 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 3763 | |
| 3764 | // ebx: Length of subject string as a smi |
| 3765 | // ecx: RegExp data (FixedArray) |
| 3766 | // edx: Number of capture registers |
| 3767 | // Check that the third argument is a positive smi less than the subject |
| 3768 | // string length. A negative value will be greater (unsigned comparison). |
| 3769 | __ mov(eax, Operand(esp, kPreviousIndexOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3770 | __ JumpIfNotSmi(eax, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3771 | __ cmp(eax, ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3772 | __ j(above_equal, &runtime); |
| 3773 | |
| 3774 | // ecx: RegExp data (FixedArray) |
| 3775 | // edx: Number of capture registers |
| 3776 | // Check that the fourth object is a JSArray object. |
| 3777 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3778 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3779 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 3780 | __ j(not_equal, &runtime); |
| 3781 | // Check that the JSArray is in fast case. |
| 3782 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
| 3783 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3784 | Factory* factory = masm->isolate()->factory(); |
| 3785 | __ cmp(eax, factory->fixed_array_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3786 | __ j(not_equal, &runtime); |
| 3787 | // Check that the last match info has space for the capture registers and the |
| 3788 | // additional information. |
| 3789 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 3790 | __ SmiUntag(eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3791 | __ add(edx, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 3792 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3793 | __ j(greater, &runtime); |
| 3794 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3795 | // Reset offset for possibly sliced string. |
| 3796 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3797 | // ecx: RegExp data (FixedArray) |
| 3798 | // Check the representation and encoding of the subject string. |
| 3799 | Label seq_ascii_string, seq_two_byte_string, check_code; |
| 3800 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 3801 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3802 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3803 | // First check for flat two byte string. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3804 | __ and_(ebx, kIsNotStringMask | |
| 3805 | kStringRepresentationMask | |
| 3806 | kStringEncodingMask | |
| 3807 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3808 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3809 | __ j(zero, &seq_two_byte_string, Label::kNear); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3810 | // 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] | 3811 | // string type tests will succeed if subject is not a string or a short |
| 3812 | // external string. |
| 3813 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3814 | kStringRepresentationMask | |
| 3815 | kShortExternalStringMask)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3816 | __ j(zero, &seq_ascii_string, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3817 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3818 | // 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] | 3819 | // Check for flat cons string or sliced string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3820 | // A flat cons string is a cons string where the second part is the empty |
| 3821 | // string. In that case the subject string is just the first part of the cons |
| 3822 | // string. Also in this case the first part of the cons string is known to be |
| 3823 | // a sequential string or an external string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3824 | // 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] | 3825 | Label cons_string, external_string, check_encoding; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3826 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3827 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3828 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3829 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3830 | __ cmp(ebx, Immediate(kExternalStringTag)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3831 | __ j(less, &cons_string); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3832 | __ j(equal, &external_string); |
| 3833 | |
| 3834 | // Catch non-string subject or short external string. |
| 3835 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 3836 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 3837 | __ j(not_zero, &runtime); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3838 | |
| 3839 | // String is sliced. |
| 3840 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 3841 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 3842 | // edi: offset of sliced string, smi-tagged. |
| 3843 | // eax: parent string. |
| 3844 | __ jmp(&check_encoding, Label::kNear); |
| 3845 | // String is a cons string, check whether it is flat. |
| 3846 | __ bind(&cons_string); |
| 3847 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3848 | __ j(not_equal, &runtime); |
| 3849 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3850 | __ bind(&check_encoding); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3851 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3852 | // eax: first part of cons string or parent of sliced string. |
| 3853 | // ebx: map of first part of cons string or map of parent of sliced string. |
| 3854 | // 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] | 3855 | __ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset), |
| 3856 | kStringRepresentationMask | kStringEncodingMask); |
| 3857 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3858 | __ j(zero, &seq_two_byte_string, Label::kNear); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3859 | // Any other flat string must be sequential ASCII or external. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3860 | __ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset), |
| 3861 | kStringRepresentationMask); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3862 | __ j(not_zero, &external_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3863 | |
| 3864 | __ bind(&seq_ascii_string); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3865 | // eax: subject string (flat ASCII) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3866 | // ecx: RegExp data (FixedArray) |
| 3867 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3868 | __ Set(ecx, Immediate(1)); // Type is ASCII. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3869 | __ jmp(&check_code, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3870 | |
| 3871 | __ bind(&seq_two_byte_string); |
| 3872 | // eax: subject string (flat two byte) |
| 3873 | // ecx: RegExp data (FixedArray) |
| 3874 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3875 | __ Set(ecx, Immediate(0)); // Type is two byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3876 | |
| 3877 | __ bind(&check_code); |
| 3878 | // Check that the irregexp code has been generated for the actual string |
| 3879 | // 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] | 3880 | // a smi (code flushing support). |
| 3881 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3882 | |
| 3883 | // eax: subject string |
| 3884 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3885 | // 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] | 3886 | // Load used arguments before starting to push arguments for call to native |
| 3887 | // RegExp code to avoid handling changing stack height. |
| 3888 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3889 | __ SmiUntag(ebx); // Previous index from smi. |
| 3890 | |
| 3891 | // eax: subject string |
| 3892 | // ebx: previous index |
| 3893 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3894 | // 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] | 3895 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3896 | Counters* counters = masm->isolate()->counters(); |
| 3897 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3898 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3899 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3900 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3901 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3902 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3903 | // Argument 9: Pass current isolate address. |
| 3904 | __ mov(Operand(esp, 8 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3905 | Immediate(ExternalReference::isolate_address())); |
| 3906 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3907 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 3908 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3909 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3910 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3911 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 3912 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3913 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 3914 | |
| 3915 | // Argument 6: Set the number of capture registers to zero to force global |
| 3916 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 3917 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3918 | |
| 3919 | // Argument 5: static offsets vector buffer. |
| 3920 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3921 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 3922 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3923 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3924 | // Argument 2: Previous index. |
| 3925 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 3926 | |
| 3927 | // Argument 1: Original subject string. |
| 3928 | // The original subject is in the previous stack frame. Therefore we have to |
| 3929 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 3930 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 3931 | // and thereby moves up esp by one kPointerSize.) |
| 3932 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 3933 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 3934 | |
| 3935 | // esi: original subject string |
| 3936 | // eax: underlying subject string |
| 3937 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3938 | // 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] | 3939 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3940 | // Argument 4: End of string data |
| 3941 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3942 | // Prepare start and end index of the input. |
| 3943 | // Load the length from the original sliced string if that is the case. |
| 3944 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3945 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3946 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3947 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3948 | |
| 3949 | // ebx: start index of the input string |
| 3950 | // esi: end index of the input string |
| 3951 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3952 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3953 | __ j(zero, &setup_two_byte, Label::kNear); |
| 3954 | __ SmiUntag(esi); |
| 3955 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqAsciiString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3956 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3957 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqAsciiString::kHeaderSize)); |
| 3958 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3959 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3960 | |
| 3961 | __ bind(&setup_two_byte); |
| 3962 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3963 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 3964 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3965 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3966 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 3967 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 3968 | |
| 3969 | __ bind(&setup_rest); |
| 3970 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3971 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3972 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 3973 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3974 | |
| 3975 | // Drop arguments and come back to JS mode. |
| 3976 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3977 | |
| 3978 | // Check the result. |
| 3979 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3980 | __ cmp(eax, 1); |
| 3981 | // We expect exactly one result since we force the called regexp to behave |
| 3982 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3983 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3984 | Label failure; |
| 3985 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3986 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3987 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 3988 | // If not exception it can only be retry. Handle that in the runtime system. |
| 3989 | __ j(not_equal, &runtime); |
| 3990 | // Result must now be exception. If there is no pending exception already a |
| 3991 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 3992 | // haven't created the exception yet. Handle that in the runtime system. |
| 3993 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3994 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3995 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3996 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3997 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3998 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3999 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4000 | // For exception, throw the exception again. |
| 4001 | |
| 4002 | // Clear the pending exception variable. |
| 4003 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 4004 | |
| 4005 | // Special handling of termination exceptions which are uncatchable |
| 4006 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4007 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4008 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4009 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4010 | |
| 4011 | // Handle normal exception by following handler chain. |
| 4012 | __ Throw(eax); |
| 4013 | |
| 4014 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4015 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4016 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4017 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4018 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4019 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4020 | __ ret(4 * kPointerSize); |
| 4021 | |
| 4022 | // Load RegExp data. |
| 4023 | __ bind(&success); |
| 4024 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 4025 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 4026 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 4027 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 4028 | STATIC_ASSERT(kSmiTag == 0); |
| 4029 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4030 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4031 | |
| 4032 | // edx: Number of capture registers |
| 4033 | // Load last_match_info which is still known to be a fast case JSArray. |
| 4034 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 4035 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
| 4036 | |
| 4037 | // ebx: last_match_info backing store (FixedArray) |
| 4038 | // edx: number of capture registers |
| 4039 | // Store the capture count. |
| 4040 | __ SmiTag(edx); // Number of capture registers to smi. |
| 4041 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 4042 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 4043 | // Store last subject and last input. |
| 4044 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 4045 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4046 | __ RecordWriteField(ebx, |
| 4047 | RegExpImpl::kLastSubjectOffset, |
| 4048 | eax, |
| 4049 | edi, |
| 4050 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4051 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 4052 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4053 | __ RecordWriteField(ebx, |
| 4054 | RegExpImpl::kLastInputOffset, |
| 4055 | eax, |
| 4056 | edi, |
| 4057 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4058 | |
| 4059 | // Get the static offsets vector filled by the native regexp code. |
| 4060 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4061 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4062 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 4063 | |
| 4064 | // ebx: last_match_info backing store (FixedArray) |
| 4065 | // ecx: offsets vector |
| 4066 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4067 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4068 | // Capture register counter starts from number of capture registers and |
| 4069 | // counts down until wraping after zero. |
| 4070 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4071 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4072 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4073 | // Read the value from the static offsets vector buffer. |
| 4074 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 4075 | __ SmiTag(edi); |
| 4076 | // Store the smi value in the last match info. |
| 4077 | __ mov(FieldOperand(ebx, |
| 4078 | edx, |
| 4079 | times_pointer_size, |
| 4080 | RegExpImpl::kFirstCaptureOffset), |
| 4081 | edi); |
| 4082 | __ jmp(&next_capture); |
| 4083 | __ bind(&done); |
| 4084 | |
| 4085 | // Return last match info. |
| 4086 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 4087 | __ ret(4 * kPointerSize); |
| 4088 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4089 | // External string. Short external strings have already been ruled out. |
| 4090 | // eax: subject string (expected to be external) |
| 4091 | // ebx: scratch |
| 4092 | __ bind(&external_string); |
| 4093 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4094 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4095 | if (FLAG_debug_code) { |
| 4096 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 4097 | // Sequential strings have already been ruled out. |
| 4098 | __ test_b(ebx, kIsIndirectStringMask); |
| 4099 | __ Assert(zero, "external string expected, but not found"); |
| 4100 | } |
| 4101 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 4102 | // Move the pointer so that offset-wise, it looks like a sequential string. |
| 4103 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); |
| 4104 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4105 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 4106 | __ test_b(ebx, kStringEncodingMask); |
| 4107 | __ j(not_zero, &seq_ascii_string); |
| 4108 | __ jmp(&seq_two_byte_string); |
| 4109 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4110 | // Do the runtime call to execute the regexp. |
| 4111 | __ bind(&runtime); |
| 4112 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4113 | #endif // V8_INTERPRETED_REGEXP |
| 4114 | } |
| 4115 | |
| 4116 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4117 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 4118 | const int kMaxInlineLength = 100; |
| 4119 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4120 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4121 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4122 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4123 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4124 | __ j(above, &slowcase); |
| 4125 | // Smi-tagging is equivalent to multiplying by 2. |
| 4126 | STATIC_ASSERT(kSmiTag == 0); |
| 4127 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4128 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 4129 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 4130 | // Elements: [Map][Length][..elements..] |
| 4131 | __ AllocateInNewSpace(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 4132 | times_half_pointer_size, |
| 4133 | ebx, // In: Number of elements (times 2, being a smi) |
| 4134 | eax, // Out: Start of allocation (tagged). |
| 4135 | ecx, // Out: End of allocation. |
| 4136 | edx, // Scratch register |
| 4137 | &slowcase, |
| 4138 | TAG_OBJECT); |
| 4139 | // eax: Start of allocated area, object-tagged. |
| 4140 | |
| 4141 | // Set JSArray map to global.regexp_result_map(). |
| 4142 | // Set empty properties FixedArray. |
| 4143 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 4144 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame^] | 4145 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4146 | Factory* factory = masm->isolate()->factory(); |
| 4147 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4148 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame^] | 4149 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4150 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 4151 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 4152 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 4153 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 4154 | |
| 4155 | // Set input, index and length fields from arguments. |
| 4156 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 4157 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 4158 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 4159 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 4160 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 4161 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 4162 | |
| 4163 | // Fill out the elements FixedArray. |
| 4164 | // eax: JSArray. |
| 4165 | // ebx: FixedArray. |
| 4166 | // ecx: Number of elements in array, as smi. |
| 4167 | |
| 4168 | // Set map. |
| 4169 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4170 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4171 | // Set length. |
| 4172 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
| 4173 | // Fill contents of fixed-array with the-hole. |
| 4174 | __ SmiUntag(ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4175 | __ mov(edx, Immediate(factory->the_hole_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4176 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
| 4177 | // Fill fixed array elements with hole. |
| 4178 | // eax: JSArray. |
| 4179 | // ecx: Number of elements to fill. |
| 4180 | // ebx: Start of elements in FixedArray. |
| 4181 | // edx: the hole. |
| 4182 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4183 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4184 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4185 | __ 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] | 4186 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4187 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 4188 | __ jmp(&loop); |
| 4189 | |
| 4190 | __ bind(&done); |
| 4191 | __ ret(3 * kPointerSize); |
| 4192 | |
| 4193 | __ bind(&slowcase); |
| 4194 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 4195 | } |
| 4196 | |
| 4197 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4198 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 4199 | Register object, |
| 4200 | Register result, |
| 4201 | Register scratch1, |
| 4202 | Register scratch2, |
| 4203 | bool object_is_smi, |
| 4204 | Label* not_found) { |
| 4205 | // Use of registers. Register result is used as a temporary. |
| 4206 | Register number_string_cache = result; |
| 4207 | Register mask = scratch1; |
| 4208 | Register scratch = scratch2; |
| 4209 | |
| 4210 | // Load the number string cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4211 | ExternalReference roots_array_start = |
| 4212 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4213 | __ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex)); |
| 4214 | __ mov(number_string_cache, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4215 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4216 | // Make the hash mask from the length of the number string cache. It |
| 4217 | // contains two elements (number and string) for each cache entry. |
| 4218 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 4219 | __ 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] | 4220 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4221 | |
| 4222 | // Calculate the entry in the number string cache. The hash value in the |
| 4223 | // number string cache for smis is just the smi value, and the hash for |
| 4224 | // doubles is the xor of the upper and lower words. See |
| 4225 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4226 | Label smi_hash_calculated; |
| 4227 | Label load_result_from_cache; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4228 | if (object_is_smi) { |
| 4229 | __ mov(scratch, object); |
| 4230 | __ SmiUntag(scratch); |
| 4231 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4232 | Label not_smi; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4233 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4234 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4235 | __ mov(scratch, object); |
| 4236 | __ SmiUntag(scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4237 | __ jmp(&smi_hash_calculated, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4238 | __ bind(¬_smi); |
| 4239 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4240 | masm->isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4241 | __ j(not_equal, not_found); |
| 4242 | STATIC_ASSERT(8 == kDoubleSize); |
| 4243 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4244 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 4245 | // 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] | 4246 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4247 | Register index = scratch; |
| 4248 | Register probe = mask; |
| 4249 | __ mov(probe, |
| 4250 | FieldOperand(number_string_cache, |
| 4251 | index, |
| 4252 | times_twice_pointer_size, |
| 4253 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4254 | __ JumpIfSmi(probe, not_found); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4255 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4256 | CpuFeatures::Scope fscope(SSE2); |
| 4257 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4258 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4259 | __ ucomisd(xmm0, xmm1); |
| 4260 | } else { |
| 4261 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 4262 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4263 | __ FCmp(); |
| 4264 | } |
| 4265 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 4266 | __ 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] | 4267 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4268 | } |
| 4269 | |
| 4270 | __ bind(&smi_hash_calculated); |
| 4271 | // 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] | 4272 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4273 | Register index = scratch; |
| 4274 | // Check if the entry is the smi we are looking for. |
| 4275 | __ cmp(object, |
| 4276 | FieldOperand(number_string_cache, |
| 4277 | index, |
| 4278 | times_twice_pointer_size, |
| 4279 | FixedArray::kHeaderSize)); |
| 4280 | __ j(not_equal, not_found); |
| 4281 | |
| 4282 | // Get the result from the cache. |
| 4283 | __ bind(&load_result_from_cache); |
| 4284 | __ mov(result, |
| 4285 | FieldOperand(number_string_cache, |
| 4286 | index, |
| 4287 | times_twice_pointer_size, |
| 4288 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4289 | Counters* counters = masm->isolate()->counters(); |
| 4290 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4291 | } |
| 4292 | |
| 4293 | |
| 4294 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 4295 | Label runtime; |
| 4296 | |
| 4297 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 4298 | |
| 4299 | // Generate code to lookup number in the number string cache. |
| 4300 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, false, &runtime); |
| 4301 | __ ret(1 * kPointerSize); |
| 4302 | |
| 4303 | __ bind(&runtime); |
| 4304 | // Handle number to string in the runtime system if not found in the cache. |
| 4305 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 4306 | } |
| 4307 | |
| 4308 | |
| 4309 | static int NegativeComparisonResult(Condition cc) { |
| 4310 | ASSERT(cc != equal); |
| 4311 | ASSERT((cc == less) || (cc == less_equal) |
| 4312 | || (cc == greater) || (cc == greater_equal)); |
| 4313 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 4314 | } |
| 4315 | |
| 4316 | void CompareStub::Generate(MacroAssembler* masm) { |
| 4317 | ASSERT(lhs_.is(no_reg) && rhs_.is(no_reg)); |
| 4318 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4319 | Label check_unequal_objects; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4320 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4321 | // Compare two smis if required. |
| 4322 | if (include_smi_compare_) { |
| 4323 | Label non_smi, smi_done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4324 | __ mov(ecx, edx); |
| 4325 | __ or_(ecx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4326 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4327 | __ sub(edx, eax); // Return on the result of the subtraction. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4328 | __ j(no_overflow, &smi_done, Label::kNear); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4329 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4330 | __ bind(&smi_done); |
| 4331 | __ mov(eax, edx); |
| 4332 | __ ret(0); |
| 4333 | __ bind(&non_smi); |
| 4334 | } else if (FLAG_debug_code) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4335 | __ mov(ecx, edx); |
| 4336 | __ or_(ecx, eax); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4337 | __ test(ecx, Immediate(kSmiTagMask)); |
| 4338 | __ Assert(not_zero, "Unexpected smi operands."); |
| 4339 | } |
| 4340 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4341 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4342 | // it is certain that at least one operand isn't a smi. |
| 4343 | |
| 4344 | // Identical objects can be compared fast, but there are some tricky cases |
| 4345 | // for NaN and undefined. |
| 4346 | { |
| 4347 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4348 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4349 | __ j(not_equal, ¬_identical); |
| 4350 | |
| 4351 | if (cc_ != equal) { |
| 4352 | // Check for undefined. undefined OP undefined is false even though |
| 4353 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4354 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4355 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4356 | __ j(not_equal, &check_for_nan, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4357 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc_)))); |
| 4358 | __ ret(0); |
| 4359 | __ bind(&check_for_nan); |
| 4360 | } |
| 4361 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4362 | // 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] | 4363 | // so we do the second best thing - test it ourselves. |
| 4364 | // Note: if cc_ != equal, never_nan_nan_ is not used. |
| 4365 | if (never_nan_nan_ && (cc_ == equal)) { |
| 4366 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4367 | __ ret(0); |
| 4368 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4369 | Label heap_number; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4370 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4371 | Immediate(masm->isolate()->factory()->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4372 | __ j(equal, &heap_number, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4373 | if (cc_ != equal) { |
| 4374 | // Call runtime on identical JSObjects. Otherwise return equal. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4375 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4376 | __ j(above_equal, ¬_identical); |
| 4377 | } |
| 4378 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4379 | __ ret(0); |
| 4380 | |
| 4381 | __ bind(&heap_number); |
| 4382 | // It is a heap number, so return non-equal if it's NaN and equal if |
| 4383 | // it's not NaN. |
| 4384 | // The representation of NaN values has all exponent bits (52..62) set, |
| 4385 | // and not all mantissa bits (0..51) clear. |
| 4386 | // We only accept QNaNs, which have bit 51 set. |
| 4387 | // Read top bits of double representation (second word of value). |
| 4388 | |
| 4389 | // Value is a QNaN if value & kQuietNaNMask == kQuietNaNMask, i.e., |
| 4390 | // all bits in the mask are set. We only need to check the word |
| 4391 | // that contains the exponent and high bit of the mantissa. |
| 4392 | STATIC_ASSERT(((kQuietNaNHighBitsMask << 1) & 0x80000000u) != 0); |
| 4393 | __ mov(edx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4394 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4395 | // Shift value and mask so kQuietNaNHighBitsMask applies to topmost |
| 4396 | // bits. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4397 | __ add(edx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4398 | __ cmp(edx, kQuietNaNHighBitsMask << 1); |
| 4399 | if (cc_ == equal) { |
| 4400 | STATIC_ASSERT(EQUAL != 1); |
| 4401 | __ setcc(above_equal, eax); |
| 4402 | __ ret(0); |
| 4403 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4404 | Label nan; |
| 4405 | __ j(above_equal, &nan, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4406 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4407 | __ ret(0); |
| 4408 | __ bind(&nan); |
| 4409 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc_)))); |
| 4410 | __ ret(0); |
| 4411 | } |
| 4412 | } |
| 4413 | |
| 4414 | __ bind(¬_identical); |
| 4415 | } |
| 4416 | |
| 4417 | // Strict equality can quickly decide whether objects are equal. |
| 4418 | // Non-strict object equality is slower, so it is handled later in the stub. |
| 4419 | if (cc_ == equal && strict_) { |
| 4420 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4421 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4422 | // If we're doing a strict equality comparison, we don't have to do |
| 4423 | // type conversion, so we generate code to do fast comparison for objects |
| 4424 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4425 | // slow-case code. |
| 4426 | // If either is a Smi (we know that not both are), then they can only |
| 4427 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4428 | STATIC_ASSERT(kSmiTag == 0); |
| 4429 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4430 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4431 | __ and_(ecx, eax); |
| 4432 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4433 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4434 | // One operand is a smi. |
| 4435 | |
| 4436 | // Check whether the non-smi is a heap number. |
| 4437 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4438 | // 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] | 4439 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4440 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4441 | __ xor_(ebx, eax); |
| 4442 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4443 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4444 | // if eax was smi, ebx is now edx, else eax. |
| 4445 | |
| 4446 | // Check if the non-smi operand is a heap number. |
| 4447 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4448 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4449 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4450 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4451 | // Return non-equal (ebx is not zero) |
| 4452 | __ mov(eax, ebx); |
| 4453 | __ ret(0); |
| 4454 | |
| 4455 | __ bind(¬_smis); |
| 4456 | // If either operand is a JSObject or an oddball value, then they are not |
| 4457 | // equal since their pointers are different |
| 4458 | // There is no test for undetectability in strict equality. |
| 4459 | |
| 4460 | // Get the type of the first operand. |
| 4461 | // 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] | 4462 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4463 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4464 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4465 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4466 | |
| 4467 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4468 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4469 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4470 | __ bind(&return_not_equal); |
| 4471 | __ ret(0); |
| 4472 | |
| 4473 | __ bind(&first_non_object); |
| 4474 | // Check for oddballs: true, false, null, undefined. |
| 4475 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4476 | __ j(equal, &return_not_equal); |
| 4477 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4478 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4479 | __ j(above_equal, &return_not_equal); |
| 4480 | |
| 4481 | // Check for oddballs: true, false, null, undefined. |
| 4482 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4483 | __ j(equal, &return_not_equal); |
| 4484 | |
| 4485 | // Fall through to the general case. |
| 4486 | __ bind(&slow); |
| 4487 | } |
| 4488 | |
| 4489 | // Generate the number comparison code. |
| 4490 | if (include_number_compare_) { |
| 4491 | Label non_number_comparison; |
| 4492 | Label unordered; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4493 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4494 | CpuFeatures::Scope use_sse2(SSE2); |
| 4495 | CpuFeatures::Scope use_cmov(CMOV); |
| 4496 | |
| 4497 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4498 | __ ucomisd(xmm0, xmm1); |
| 4499 | |
| 4500 | // Don't base result on EFLAGS when a NaN is involved. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4501 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4502 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4503 | __ mov(eax, 0); // equal |
| 4504 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4505 | __ cmov(above, eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4506 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4507 | __ cmov(below, eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4508 | __ ret(0); |
| 4509 | } else { |
| 4510 | FloatingPointHelper::CheckFloatOperands( |
| 4511 | masm, &non_number_comparison, ebx); |
| 4512 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4513 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4514 | __ FCmp(); |
| 4515 | |
| 4516 | // Don't base result on EFLAGS when a NaN is involved. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4517 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4518 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4519 | Label below_label, above_label; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4520 | // Return a result of -1, 0, or 1, based on EFLAGS. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4521 | __ j(below, &below_label, Label::kNear); |
| 4522 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4523 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4524 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4525 | __ ret(0); |
| 4526 | |
| 4527 | __ bind(&below_label); |
| 4528 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4529 | __ ret(0); |
| 4530 | |
| 4531 | __ bind(&above_label); |
| 4532 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4533 | __ ret(0); |
| 4534 | } |
| 4535 | |
| 4536 | // If one of the numbers was NaN, then the result is always false. |
| 4537 | // The cc is never not-equal. |
| 4538 | __ bind(&unordered); |
| 4539 | ASSERT(cc_ != not_equal); |
| 4540 | if (cc_ == less || cc_ == less_equal) { |
| 4541 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4542 | } else { |
| 4543 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4544 | } |
| 4545 | __ ret(0); |
| 4546 | |
| 4547 | // The number comparison code did not provide a valid result. |
| 4548 | __ bind(&non_number_comparison); |
| 4549 | } |
| 4550 | |
| 4551 | // Fast negative check for symbol-to-symbol equality. |
| 4552 | Label check_for_strings; |
| 4553 | if (cc_ == equal) { |
| 4554 | BranchIfNonSymbol(masm, &check_for_strings, eax, ecx); |
| 4555 | BranchIfNonSymbol(masm, &check_for_strings, edx, ecx); |
| 4556 | |
| 4557 | // We've already checked for object identity, so if both operands |
| 4558 | // are symbols they aren't equal. Register eax already holds a |
| 4559 | // non-zero value, which indicates not equal, so just return. |
| 4560 | __ ret(0); |
| 4561 | } |
| 4562 | |
| 4563 | __ bind(&check_for_strings); |
| 4564 | |
| 4565 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4566 | &check_unequal_objects); |
| 4567 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4568 | // Inline comparison of ASCII strings. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4569 | if (cc_ == equal) { |
| 4570 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4571 | edx, |
| 4572 | eax, |
| 4573 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4574 | ebx); |
| 4575 | } else { |
| 4576 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4577 | edx, |
| 4578 | eax, |
| 4579 | ecx, |
| 4580 | ebx, |
| 4581 | edi); |
| 4582 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4583 | #ifdef DEBUG |
| 4584 | __ Abort("Unexpected fall-through from string comparison"); |
| 4585 | #endif |
| 4586 | |
| 4587 | __ bind(&check_unequal_objects); |
| 4588 | if (cc_ == equal && !strict_) { |
| 4589 | // Non-strict equality. Objects are unequal if |
| 4590 | // they are both JSObjects and not undetectable, |
| 4591 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4592 | Label not_both_objects; |
| 4593 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4594 | // At most one is a smi, so we can test for smi by adding the two. |
| 4595 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4596 | // a heap object has the low bit clear. |
| 4597 | STATIC_ASSERT(kSmiTag == 0); |
| 4598 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4599 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4600 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4601 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4602 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4603 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4604 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4605 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4606 | // We do not bail out after this point. Both are JSObjects, and |
| 4607 | // they are equal if and only if both are undetectable. |
| 4608 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4609 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4610 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4611 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4612 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4613 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4614 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4615 | // The objects are both undetectable, so they both compare as the value |
| 4616 | // undefined, and are equal. |
| 4617 | __ Set(eax, Immediate(EQUAL)); |
| 4618 | __ bind(&return_unequal); |
| 4619 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4620 | // or return equal if we fell through to here. |
| 4621 | __ ret(0); // rax, rdx were pushed |
| 4622 | __ bind(¬_both_objects); |
| 4623 | } |
| 4624 | |
| 4625 | // Push arguments below the return address. |
| 4626 | __ pop(ecx); |
| 4627 | __ push(edx); |
| 4628 | __ push(eax); |
| 4629 | |
| 4630 | // Figure out which native to call and setup the arguments. |
| 4631 | Builtins::JavaScript builtin; |
| 4632 | if (cc_ == equal) { |
| 4633 | builtin = strict_ ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
| 4634 | } else { |
| 4635 | builtin = Builtins::COMPARE; |
| 4636 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc_)))); |
| 4637 | } |
| 4638 | |
| 4639 | // Restore return address on the stack. |
| 4640 | __ push(ecx); |
| 4641 | |
| 4642 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4643 | // tagged as a small integer. |
| 4644 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
| 4645 | } |
| 4646 | |
| 4647 | |
| 4648 | void CompareStub::BranchIfNonSymbol(MacroAssembler* masm, |
| 4649 | Label* label, |
| 4650 | Register object, |
| 4651 | Register scratch) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4652 | __ JumpIfSmi(object, label); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4653 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4654 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 4655 | __ and_(scratch, kIsSymbolMask | kIsNotStringMask); |
| 4656 | __ cmp(scratch, kSymbolTag | kStringTag); |
| 4657 | __ j(not_equal, label); |
| 4658 | } |
| 4659 | |
| 4660 | |
| 4661 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4662 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4663 | } |
| 4664 | |
| 4665 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4666 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 4667 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 4668 | } |
| 4669 | |
| 4670 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4671 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4672 | // Cache the called function in a global property cell. Cache states |
| 4673 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4674 | // megamorphic. |
| 4675 | // ebx : cache cell for call target |
| 4676 | // edi : the function to call |
| 4677 | Isolate* isolate = masm->isolate(); |
| 4678 | Label initialize, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4679 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4680 | // Load the cache state into ecx. |
| 4681 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4682 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4683 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4684 | // function without changing the state. |
| 4685 | __ cmp(ecx, edi); |
| 4686 | __ j(equal, &done, Label::kNear); |
| 4687 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4688 | __ j(equal, &done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4689 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4690 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4691 | // megamorphic. |
| 4692 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4693 | __ j(equal, &initialize, Label::kNear); |
| 4694 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4695 | // write-barrier is needed. |
| 4696 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4697 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4698 | __ jmp(&done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4699 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4700 | // An uninitialized cache is patched with the function. |
| 4701 | __ bind(&initialize); |
| 4702 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4703 | // No need for a write barrier here - cells are rescanned. |
| 4704 | |
| 4705 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4706 | } |
| 4707 | |
| 4708 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4709 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4710 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4711 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4712 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4713 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4714 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4715 | // The receiver might implicitly be the global object. This is |
| 4716 | // indicated by passing the hole as the receiver to the call |
| 4717 | // function stub. |
| 4718 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4719 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4720 | // Get the receiver from the stack. |
| 4721 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4722 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4723 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4724 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4725 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4726 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4727 | __ mov(ecx, GlobalObjectOperand()); |
| 4728 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4729 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4730 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4731 | } |
| 4732 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4733 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4734 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4735 | // Goto slow case if we do not have a function. |
| 4736 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4737 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4738 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4739 | if (RecordCallTarget()) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4740 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4741 | } |
| 4742 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4743 | // Fast-case: Just invoke the function. |
| 4744 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4745 | |
| 4746 | if (ReceiverMightBeImplicit()) { |
| 4747 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4748 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4749 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4750 | __ InvokeFunction(edi, |
| 4751 | actual, |
| 4752 | JUMP_FUNCTION, |
| 4753 | NullCallWrapper(), |
| 4754 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4755 | __ bind(&call_as_function); |
| 4756 | } |
| 4757 | __ InvokeFunction(edi, |
| 4758 | actual, |
| 4759 | JUMP_FUNCTION, |
| 4760 | NullCallWrapper(), |
| 4761 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4762 | |
| 4763 | // Slow-case: Non-function called. |
| 4764 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4765 | if (RecordCallTarget()) { |
| 4766 | // 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] | 4767 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4768 | // object (undefined) so no write barrier is needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4769 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4770 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4771 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4772 | // Check for function proxy. |
| 4773 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4774 | __ j(not_equal, &non_function); |
| 4775 | __ pop(ecx); |
| 4776 | __ push(edi); // put proxy as additional argument under return address |
| 4777 | __ push(ecx); |
| 4778 | __ Set(eax, Immediate(argc_ + 1)); |
| 4779 | __ Set(ebx, Immediate(0)); |
| 4780 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4781 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4782 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4783 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4784 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4785 | } |
| 4786 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4787 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4788 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4789 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4790 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4791 | __ Set(eax, Immediate(argc_)); |
| 4792 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4793 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4794 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4795 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4796 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4797 | } |
| 4798 | |
| 4799 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4800 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 4801 | // eax : number of arguments |
| 4802 | // ebx : cache cell for call target |
| 4803 | // edi : constructor function |
| 4804 | Label slow, non_function_call; |
| 4805 | |
| 4806 | // Check that function is not a smi. |
| 4807 | __ JumpIfSmi(edi, &non_function_call); |
| 4808 | // Check that function is a JSFunction. |
| 4809 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 4810 | __ j(not_equal, &slow); |
| 4811 | |
| 4812 | if (RecordCallTarget()) { |
| 4813 | GenerateRecordCallTarget(masm); |
| 4814 | } |
| 4815 | |
| 4816 | // Jump to the function-specific construct stub. |
| 4817 | __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4818 | __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kConstructStubOffset)); |
| 4819 | __ lea(ebx, FieldOperand(ebx, Code::kHeaderSize)); |
| 4820 | __ jmp(ebx); |
| 4821 | |
| 4822 | // edi: called object |
| 4823 | // eax: number of arguments |
| 4824 | // ecx: object map |
| 4825 | Label do_call; |
| 4826 | __ bind(&slow); |
| 4827 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4828 | __ j(not_equal, &non_function_call); |
| 4829 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4830 | __ jmp(&do_call); |
| 4831 | |
| 4832 | __ bind(&non_function_call); |
| 4833 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4834 | __ bind(&do_call); |
| 4835 | // Set expected number of arguments to zero (not changing eax). |
| 4836 | __ Set(ebx, Immediate(0)); |
| 4837 | Handle<Code> arguments_adaptor = |
| 4838 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 4839 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 4840 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 4841 | } |
| 4842 | |
| 4843 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4844 | bool CEntryStub::NeedsImmovableCode() { |
| 4845 | return false; |
| 4846 | } |
| 4847 | |
| 4848 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4849 | bool CEntryStub::IsPregenerated() { |
| 4850 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 4851 | result_size_ == 1; |
| 4852 | } |
| 4853 | |
| 4854 | |
| 4855 | void CodeStub::GenerateStubsAheadOfTime() { |
| 4856 | CEntryStub::GenerateAheadOfTime(); |
| 4857 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(); |
| 4858 | // It is important that the store buffer overflow stubs are generated first. |
| 4859 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(); |
| 4860 | } |
| 4861 | |
| 4862 | |
| 4863 | void CodeStub::GenerateFPStubs() { |
| 4864 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4865 | Handle<Code> code = save_doubles.GetCode(); |
| 4866 | code->set_is_pregenerated(true); |
| 4867 | code->GetIsolate()->set_fp_stubs_generated(true); |
| 4868 | } |
| 4869 | |
| 4870 | |
| 4871 | void CEntryStub::GenerateAheadOfTime() { |
| 4872 | CEntryStub stub(1, kDontSaveFPRegs); |
| 4873 | Handle<Code> code = stub.GetCode(); |
| 4874 | code->set_is_pregenerated(true); |
| 4875 | } |
| 4876 | |
| 4877 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4878 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 4879 | Label* throw_normal_exception, |
| 4880 | Label* throw_termination_exception, |
| 4881 | Label* throw_out_of_memory_exception, |
| 4882 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4883 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4884 | // eax: result parameter for PerformGC, if any |
| 4885 | // ebx: pointer to C function (C callee-saved) |
| 4886 | // ebp: frame pointer (restored after C call) |
| 4887 | // esp: stack pointer (restored after C call) |
| 4888 | // edi: number of arguments including receiver (C callee-saved) |
| 4889 | // esi: pointer to the first argument (C callee-saved) |
| 4890 | |
| 4891 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 4892 | |
| 4893 | // Check stack alignment. |
| 4894 | if (FLAG_debug_code) { |
| 4895 | __ CheckStackAlignment(); |
| 4896 | } |
| 4897 | |
| 4898 | if (do_gc) { |
| 4899 | // Pass failure code returned from last attempt as first argument to |
| 4900 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 4901 | // stack alignment is known to be correct. This function takes one argument |
| 4902 | // which is passed on the stack, and we know that the stack has been |
| 4903 | // prepared to pass at least one argument. |
| 4904 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 4905 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 4906 | } |
| 4907 | |
| 4908 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4909 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4910 | if (always_allocate_scope) { |
| 4911 | __ inc(Operand::StaticVariable(scope_depth)); |
| 4912 | } |
| 4913 | |
| 4914 | // Call C function. |
| 4915 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 4916 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4917 | __ mov(Operand(esp, 2 * kPointerSize), |
| 4918 | Immediate(ExternalReference::isolate_address())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4919 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4920 | // Result is in eax or edx:eax - do not destroy these registers! |
| 4921 | |
| 4922 | if (always_allocate_scope) { |
| 4923 | __ dec(Operand::StaticVariable(scope_depth)); |
| 4924 | } |
| 4925 | |
| 4926 | // Make sure we're not trying to return 'the hole' from the runtime |
| 4927 | // call as this may lead to crashes in the IC code later. |
| 4928 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4929 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4930 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4931 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4932 | __ int3(); |
| 4933 | __ bind(&okay); |
| 4934 | } |
| 4935 | |
| 4936 | // Check for failure result. |
| 4937 | Label failure_returned; |
| 4938 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 4939 | __ lea(ecx, Operand(eax, 1)); |
| 4940 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 4941 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4942 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4943 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4944 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4945 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4946 | |
| 4947 | // Check that there is no pending exception, otherwise we |
| 4948 | // should have returned some failure value. |
| 4949 | if (FLAG_debug_code) { |
| 4950 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4951 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4952 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4953 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 4954 | // 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] | 4955 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4956 | __ int3(); |
| 4957 | __ bind(&okay); |
| 4958 | __ pop(edx); |
| 4959 | } |
| 4960 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4961 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4962 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4963 | __ ret(0); |
| 4964 | |
| 4965 | // Handling of failure. |
| 4966 | __ bind(&failure_returned); |
| 4967 | |
| 4968 | Label retry; |
| 4969 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 4970 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 4971 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4972 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4973 | |
| 4974 | // Special handling of out of memory exceptions. |
| 4975 | __ cmp(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException())); |
| 4976 | __ j(equal, throw_out_of_memory_exception); |
| 4977 | |
| 4978 | // Retrieve the pending exception and clear the variable. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4979 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4980 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4981 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 4982 | |
| 4983 | // Special handling of termination exceptions which are uncatchable |
| 4984 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4985 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4986 | __ j(equal, throw_termination_exception); |
| 4987 | |
| 4988 | // Handle normal exception. |
| 4989 | __ jmp(throw_normal_exception); |
| 4990 | |
| 4991 | // Retry. |
| 4992 | __ bind(&retry); |
| 4993 | } |
| 4994 | |
| 4995 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4996 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 4997 | // eax: number of arguments including receiver |
| 4998 | // ebx: pointer to C function (C callee-saved) |
| 4999 | // ebp: frame pointer (restored after C call) |
| 5000 | // esp: stack pointer (restored after C call) |
| 5001 | // esi: current context (C callee-saved) |
| 5002 | // edi: JS function of the caller (C callee-saved) |
| 5003 | |
| 5004 | // NOTE: Invocations of builtins may return failure objects instead |
| 5005 | // of a proper result. The builtin entry handles this by performing |
| 5006 | // a garbage collection and retrying the builtin (twice). |
| 5007 | |
| 5008 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5009 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5010 | |
| 5011 | // eax: result parameter for PerformGC, if any (setup below) |
| 5012 | // ebx: pointer to builtin function (C callee-saved) |
| 5013 | // ebp: frame pointer (restored after C call) |
| 5014 | // esp: stack pointer (restored after C call) |
| 5015 | // edi: number of arguments including receiver (C callee-saved) |
| 5016 | // esi: argv pointer (C callee-saved) |
| 5017 | |
| 5018 | Label throw_normal_exception; |
| 5019 | Label throw_termination_exception; |
| 5020 | Label throw_out_of_memory_exception; |
| 5021 | |
| 5022 | // Call into the runtime system. |
| 5023 | GenerateCore(masm, |
| 5024 | &throw_normal_exception, |
| 5025 | &throw_termination_exception, |
| 5026 | &throw_out_of_memory_exception, |
| 5027 | false, |
| 5028 | false); |
| 5029 | |
| 5030 | // Do space-specific GC and retry runtime call. |
| 5031 | GenerateCore(masm, |
| 5032 | &throw_normal_exception, |
| 5033 | &throw_termination_exception, |
| 5034 | &throw_out_of_memory_exception, |
| 5035 | true, |
| 5036 | false); |
| 5037 | |
| 5038 | // Do full GC and retry runtime call one final time. |
| 5039 | Failure* failure = Failure::InternalError(); |
| 5040 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 5041 | GenerateCore(masm, |
| 5042 | &throw_normal_exception, |
| 5043 | &throw_termination_exception, |
| 5044 | &throw_out_of_memory_exception, |
| 5045 | true, |
| 5046 | true); |
| 5047 | |
| 5048 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5049 | // Set external caught exception to false. |
| 5050 | Isolate* isolate = masm->isolate(); |
| 5051 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 5052 | isolate); |
| 5053 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 5054 | |
| 5055 | // Set pending exception and eax to out of memory exception. |
| 5056 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 5057 | isolate); |
| 5058 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException())); |
| 5059 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5060 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5061 | |
| 5062 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5063 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5064 | |
| 5065 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5066 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5067 | } |
| 5068 | |
| 5069 | |
| 5070 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5071 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5072 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5073 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5074 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5075 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5076 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5077 | |
| 5078 | // Push marker in two places. |
| 5079 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 5080 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 5081 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 5082 | // Save callee-saved registers (C calling conventions). |
| 5083 | __ push(edi); |
| 5084 | __ push(esi); |
| 5085 | __ push(ebx); |
| 5086 | |
| 5087 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5088 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5089 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 5090 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5091 | // 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] | 5092 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5093 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5094 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5095 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5096 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5097 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 5098 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5099 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5100 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5101 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5102 | // Jump to a faked try block that does the invoke, with a faked catch |
| 5103 | // block that sets the pending exception. |
| 5104 | __ jmp(&invoke); |
| 5105 | __ bind(&handler_entry); |
| 5106 | handler_offset_ = handler_entry.pos(); |
| 5107 | // Caught exception: Store result (exception) in the pending exception |
| 5108 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5109 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5110 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5111 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5112 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 5113 | __ jmp(&exit); |
| 5114 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5115 | // Invoke: Link this frame into the handler chain. There's only one |
| 5116 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5117 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 5118 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5119 | |
| 5120 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5121 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5122 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 5123 | |
| 5124 | // Fake a receiver (NULL). |
| 5125 | __ push(Immediate(0)); // receiver |
| 5126 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5127 | // Invoke the function by calling through JS entry trampoline builtin and |
| 5128 | // pop the faked function when we return. Notice that we cannot store a |
| 5129 | // reference to the trampoline code directly in this stub, because the |
| 5130 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5131 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5132 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 5133 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5134 | __ mov(edx, Immediate(construct_entry)); |
| 5135 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5136 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5137 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5138 | __ mov(edx, Immediate(entry)); |
| 5139 | } |
| 5140 | __ mov(edx, Operand(edx, 0)); // deref address |
| 5141 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5142 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5143 | |
| 5144 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5145 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5146 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5147 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5148 | // Check if the current stack frame is marked as the outermost JS frame. |
| 5149 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5150 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5151 | __ j(not_equal, ¬_outermost_js_2); |
| 5152 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 5153 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5154 | |
| 5155 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5156 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5157 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5158 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5159 | |
| 5160 | // Restore callee-saved registers (C calling conventions). |
| 5161 | __ pop(ebx); |
| 5162 | __ pop(esi); |
| 5163 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5164 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5165 | |
| 5166 | // Restore frame pointer and return. |
| 5167 | __ pop(ebp); |
| 5168 | __ ret(0); |
| 5169 | } |
| 5170 | |
| 5171 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5172 | // Generate stub code for instanceof. |
| 5173 | // This code can patch a call site inlined cache of the instance of check, |
| 5174 | // which looks like this. |
| 5175 | // |
| 5176 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 5177 | // 75 0a jne <some near label> |
| 5178 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 5179 | // |
| 5180 | // If call site patching is requested the stack will have the delta from the |
| 5181 | // return address to the cmp instruction just below the return address. This |
| 5182 | // also means that call site patching can only take place with arguments in |
| 5183 | // registers. TOS looks like this when call site patching is requested |
| 5184 | // |
| 5185 | // esp[0] : return address |
| 5186 | // esp[4] : delta from return address to cmp instruction |
| 5187 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5188 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5189 | // Call site inlining and patching implies arguments in registers. |
| 5190 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 5191 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5192 | // Fixed register usage throughout the stub. |
| 5193 | Register object = eax; // Object (lhs). |
| 5194 | Register map = ebx; // Map of the object. |
| 5195 | Register function = edx; // Function (rhs). |
| 5196 | Register prototype = edi; // Prototype of the function. |
| 5197 | Register scratch = ecx; |
| 5198 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5199 | // Constants describing the call site code to patch. |
| 5200 | static const int kDeltaToCmpImmediate = 2; |
| 5201 | static const int kDeltaToMov = 8; |
| 5202 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5203 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 5204 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5205 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 5206 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5207 | ExternalReference roots_array_start = |
| 5208 | ExternalReference::roots_array_start(masm->isolate()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5209 | |
| 5210 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 5211 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 5212 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5213 | // Get the object and function - they are always both needed. |
| 5214 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5215 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5216 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 5217 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 5218 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5219 | |
| 5220 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5221 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5222 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5223 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5224 | // If there is a call site cache don't look in the global cache, but do the |
| 5225 | // real lookup and update the call site cache. |
| 5226 | if (!HasCallSiteInlineCheck()) { |
| 5227 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5228 | Label miss; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5229 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5230 | __ cmp(function, Operand::StaticArray(scratch, |
| 5231 | times_pointer_size, |
| 5232 | roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5233 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5234 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
| 5235 | __ cmp(map, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5236 | scratch, times_pointer_size, roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5237 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5238 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5239 | __ mov(eax, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5240 | scratch, times_pointer_size, roots_array_start)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5241 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 5242 | __ bind(&miss); |
| 5243 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5244 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5245 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5246 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5247 | |
| 5248 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5249 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5250 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5251 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5252 | // Update the global instanceof or call site inlined cache with the current |
| 5253 | // map and function. The cached answer will be set when it is known below. |
| 5254 | if (!HasCallSiteInlineCheck()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5255 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5256 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 5257 | map); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5258 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5259 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5260 | function); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5261 | } else { |
| 5262 | // The constants for the code patching are based on no push instructions |
| 5263 | // at the call site. |
| 5264 | ASSERT(HasArgsInRegisters()); |
| 5265 | // Get return address and delta to inlined map check. |
| 5266 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5267 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5268 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5269 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5270 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)"); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5271 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5272 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)"); |
| 5273 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5274 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 5275 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5276 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5277 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5278 | // Loop through the prototype chain of the object looking for the function |
| 5279 | // prototype. |
| 5280 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5281 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5282 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5283 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5284 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5285 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5286 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5287 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5288 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 5289 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5290 | __ jmp(&loop); |
| 5291 | |
| 5292 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5293 | if (!HasCallSiteInlineCheck()) { |
| 5294 | __ Set(eax, Immediate(0)); |
| 5295 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5296 | __ mov(Operand::StaticArray(scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5297 | times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5298 | } else { |
| 5299 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5300 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5301 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5302 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5303 | if (FLAG_debug_code) { |
| 5304 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5305 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5306 | } |
| 5307 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5308 | if (!ReturnTrueFalseObject()) { |
| 5309 | __ Set(eax, Immediate(0)); |
| 5310 | } |
| 5311 | } |
| 5312 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5313 | |
| 5314 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5315 | if (!HasCallSiteInlineCheck()) { |
| 5316 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5317 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5318 | __ mov(Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5319 | scratch, times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5320 | } else { |
| 5321 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5322 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5323 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5324 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5325 | if (FLAG_debug_code) { |
| 5326 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5327 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5328 | } |
| 5329 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5330 | if (!ReturnTrueFalseObject()) { |
| 5331 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5332 | } |
| 5333 | } |
| 5334 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5335 | |
| 5336 | Label object_not_null, object_not_null_or_smi; |
| 5337 | __ bind(¬_js_object); |
| 5338 | // Before null, smi and string value checks, check that the rhs is a function |
| 5339 | // 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] | 5340 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5341 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5342 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5343 | |
| 5344 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5345 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5346 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5347 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5348 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5349 | |
| 5350 | __ bind(&object_not_null); |
| 5351 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5352 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5353 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5354 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5355 | |
| 5356 | __ bind(&object_not_null_or_smi); |
| 5357 | // String values is not instance of anything. |
| 5358 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5359 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5360 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5361 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5362 | |
| 5363 | // Slow-case: Go through the JavaScript implementation. |
| 5364 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5365 | if (!ReturnTrueFalseObject()) { |
| 5366 | // Tail call the builtin which returns 0 or 1. |
| 5367 | if (HasArgsInRegisters()) { |
| 5368 | // Push arguments below return address. |
| 5369 | __ pop(scratch); |
| 5370 | __ push(object); |
| 5371 | __ push(function); |
| 5372 | __ push(scratch); |
| 5373 | } |
| 5374 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5375 | } else { |
| 5376 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5377 | { |
| 5378 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5379 | __ push(object); |
| 5380 | __ push(function); |
| 5381 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5382 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5383 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5384 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5385 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5386 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5387 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5388 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5389 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5390 | __ bind(&done); |
| 5391 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5392 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5393 | } |
| 5394 | |
| 5395 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5396 | Register InstanceofStub::left() { return eax; } |
| 5397 | |
| 5398 | |
| 5399 | Register InstanceofStub::right() { return edx; } |
| 5400 | |
| 5401 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5402 | int CompareStub::MinorKey() { |
| 5403 | // Encode the three parameters in a unique 16 bit value. To avoid duplicate |
| 5404 | // stubs the never NaN NaN condition is only taken into account if the |
| 5405 | // condition is equals. |
| 5406 | ASSERT(static_cast<unsigned>(cc_) < (1 << 12)); |
| 5407 | ASSERT(lhs_.is(no_reg) && rhs_.is(no_reg)); |
| 5408 | return ConditionField::encode(static_cast<unsigned>(cc_)) |
| 5409 | | RegisterField::encode(false) // lhs_ and rhs_ are not used |
| 5410 | | StrictField::encode(strict_) |
| 5411 | | NeverNanNanField::encode(cc_ == equal ? never_nan_nan_ : false) |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5412 | | IncludeNumberCompareField::encode(include_number_compare_) |
| 5413 | | IncludeSmiCompareField::encode(include_smi_compare_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | |
| 5417 | // Unfortunately you have to run without snapshots to see most of these |
| 5418 | // names in the profile since most compare stubs end up in the snapshot. |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 5419 | void CompareStub::PrintName(StringStream* stream) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5420 | ASSERT(lhs_.is(no_reg) && rhs_.is(no_reg)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5421 | const char* cc_name; |
| 5422 | switch (cc_) { |
| 5423 | case less: cc_name = "LT"; break; |
| 5424 | case greater: cc_name = "GT"; break; |
| 5425 | case less_equal: cc_name = "LE"; break; |
| 5426 | case greater_equal: cc_name = "GE"; break; |
| 5427 | case equal: cc_name = "EQ"; break; |
| 5428 | case not_equal: cc_name = "NE"; break; |
| 5429 | default: cc_name = "UnknownCondition"; break; |
| 5430 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 5431 | bool is_equality = cc_ == equal || cc_ == not_equal; |
| 5432 | stream->Add("CompareStub_%s", cc_name); |
| 5433 | if (strict_ && is_equality) stream->Add("_STRICT"); |
| 5434 | if (never_nan_nan_ && is_equality) stream->Add("_NO_NAN"); |
| 5435 | if (!include_number_compare_) stream->Add("_NO_NUMBER"); |
| 5436 | if (!include_smi_compare_) stream->Add("_NO_SMI"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5437 | } |
| 5438 | |
| 5439 | |
| 5440 | // ------------------------------------------------------------------------- |
| 5441 | // StringCharCodeAtGenerator |
| 5442 | |
| 5443 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5444 | // If the receiver is a smi trigger the non-string case. |
| 5445 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5446 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5447 | |
| 5448 | // Fetch the instance type of the receiver into result register. |
| 5449 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5450 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5451 | // If the receiver is not a string trigger the non-string case. |
| 5452 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5453 | __ j(not_zero, receiver_not_string_); |
| 5454 | |
| 5455 | // If the index is non-smi trigger the non-smi case. |
| 5456 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5457 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5458 | __ bind(&got_smi_index_); |
| 5459 | |
| 5460 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5461 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5462 | __ j(above_equal, index_out_of_range_); |
| 5463 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5464 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5465 | |
| 5466 | Factory* factory = masm->isolate()->factory(); |
| 5467 | StringCharLoadGenerator::Generate( |
| 5468 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5469 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5470 | __ SmiTag(result_); |
| 5471 | __ bind(&exit_); |
| 5472 | } |
| 5473 | |
| 5474 | |
| 5475 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5476 | MacroAssembler* masm, |
| 5477 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5478 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5479 | |
| 5480 | // Index is not a smi. |
| 5481 | __ bind(&index_not_smi_); |
| 5482 | // 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] | 5483 | __ CheckMap(index_, |
| 5484 | masm->isolate()->factory()->heap_number_map(), |
| 5485 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5486 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5487 | call_helper.BeforeCall(masm); |
| 5488 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5489 | __ push(index_); // Consumed by runtime conversion function. |
| 5490 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5491 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5492 | } else { |
| 5493 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5494 | // NumberToSmi discards numbers that are not exact integers. |
| 5495 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5496 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5497 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5498 | // Save the conversion result before the pop instructions below |
| 5499 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5500 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5501 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5502 | __ pop(object_); |
| 5503 | // Reload the instance type. |
| 5504 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5505 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5506 | call_helper.AfterCall(masm); |
| 5507 | // If index is still not a smi, it must be out of range. |
| 5508 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5509 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5510 | // Otherwise, return to the fast path. |
| 5511 | __ jmp(&got_smi_index_); |
| 5512 | |
| 5513 | // Call runtime. We get here when the receiver is a string and the |
| 5514 | // index is a number, but the code of getting the actual character |
| 5515 | // is too complex (e.g., when the string needs to be flattened). |
| 5516 | __ bind(&call_runtime_); |
| 5517 | call_helper.BeforeCall(masm); |
| 5518 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5519 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5520 | __ push(index_); |
| 5521 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5522 | if (!result_.is(eax)) { |
| 5523 | __ mov(result_, eax); |
| 5524 | } |
| 5525 | call_helper.AfterCall(masm); |
| 5526 | __ jmp(&exit_); |
| 5527 | |
| 5528 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5529 | } |
| 5530 | |
| 5531 | |
| 5532 | // ------------------------------------------------------------------------- |
| 5533 | // StringCharFromCodeGenerator |
| 5534 | |
| 5535 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5536 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5537 | STATIC_ASSERT(kSmiTag == 0); |
| 5538 | STATIC_ASSERT(kSmiShiftSize == 0); |
| 5539 | ASSERT(IsPowerOf2(String::kMaxAsciiCharCode + 1)); |
| 5540 | __ test(code_, |
| 5541 | Immediate(kSmiTagMask | |
| 5542 | ((~String::kMaxAsciiCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5543 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5544 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5545 | Factory* factory = masm->isolate()->factory(); |
| 5546 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5547 | STATIC_ASSERT(kSmiTag == 0); |
| 5548 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5549 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5550 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5551 | __ mov(result_, FieldOperand(result_, |
| 5552 | code_, times_half_pointer_size, |
| 5553 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5554 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5555 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5556 | __ bind(&exit_); |
| 5557 | } |
| 5558 | |
| 5559 | |
| 5560 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5561 | MacroAssembler* masm, |
| 5562 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5563 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5564 | |
| 5565 | __ bind(&slow_case_); |
| 5566 | call_helper.BeforeCall(masm); |
| 5567 | __ push(code_); |
| 5568 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5569 | if (!result_.is(eax)) { |
| 5570 | __ mov(result_, eax); |
| 5571 | } |
| 5572 | call_helper.AfterCall(masm); |
| 5573 | __ jmp(&exit_); |
| 5574 | |
| 5575 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5576 | } |
| 5577 | |
| 5578 | |
| 5579 | // ------------------------------------------------------------------------- |
| 5580 | // StringCharAtGenerator |
| 5581 | |
| 5582 | void StringCharAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 5583 | char_code_at_generator_.GenerateFast(masm); |
| 5584 | char_from_code_generator_.GenerateFast(masm); |
| 5585 | } |
| 5586 | |
| 5587 | |
| 5588 | void StringCharAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5589 | MacroAssembler* masm, |
| 5590 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5591 | char_code_at_generator_.GenerateSlow(masm, call_helper); |
| 5592 | char_from_code_generator_.GenerateSlow(masm, call_helper); |
| 5593 | } |
| 5594 | |
| 5595 | |
| 5596 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5597 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5598 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5599 | |
| 5600 | // Load the two arguments. |
| 5601 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5602 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5603 | |
| 5604 | // 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] | 5605 | if (flags_ == NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5606 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5607 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5608 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5609 | |
| 5610 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5611 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5612 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5613 | __ j(above_equal, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5614 | } else { |
| 5615 | // Here at least one of the arguments is definitely a string. |
| 5616 | // We convert the one that is not known to be a string. |
| 5617 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 5618 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 5619 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5620 | &call_builtin); |
| 5621 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5622 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 5623 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 5624 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5625 | &call_builtin); |
| 5626 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 5627 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5628 | } |
| 5629 | |
| 5630 | // Both arguments are strings. |
| 5631 | // eax: first string |
| 5632 | // edx: second string |
| 5633 | // 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] | 5634 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5635 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5636 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5637 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5638 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5639 | // 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] | 5640 | Counters* counters = masm->isolate()->counters(); |
| 5641 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5642 | __ ret(2 * kPointerSize); |
| 5643 | __ bind(&second_not_zero_length); |
| 5644 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5645 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5646 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5647 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5648 | // First string is empty, result is second string which is in edx. |
| 5649 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5650 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5651 | __ ret(2 * kPointerSize); |
| 5652 | |
| 5653 | // Both strings are non-empty. |
| 5654 | // eax: first string |
| 5655 | // ebx: length of first string as a smi |
| 5656 | // ecx: length of second string as a smi |
| 5657 | // edx: second string |
| 5658 | // Look at the length of the result of adding the two strings. |
| 5659 | Label string_add_flat_result, longer_than_two; |
| 5660 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5661 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5662 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5663 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5664 | __ j(overflow, &call_runtime); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5665 | // Use the symbol table when adding two one character strings, as it |
| 5666 | // helps later optimizations to return a symbol here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5667 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5668 | __ j(not_equal, &longer_than_two); |
| 5669 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5670 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5671 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5672 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5673 | // Get the two characters forming the new string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5674 | __ movzx_b(ebx, FieldOperand(eax, SeqAsciiString::kHeaderSize)); |
| 5675 | __ movzx_b(ecx, FieldOperand(edx, SeqAsciiString::kHeaderSize)); |
| 5676 | |
| 5677 | // Try to lookup two character string in symbol table. If it is not found |
| 5678 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5679 | Label make_two_character_string, make_two_character_string_no_reload; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5680 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5681 | masm, ebx, ecx, eax, edx, edi, |
| 5682 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5683 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5684 | __ ret(2 * kPointerSize); |
| 5685 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5686 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5687 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5688 | // Reload the arguments. |
| 5689 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5690 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5691 | // Get the two characters forming the new string. |
| 5692 | __ movzx_b(ebx, FieldOperand(eax, SeqAsciiString::kHeaderSize)); |
| 5693 | __ movzx_b(ecx, FieldOperand(edx, SeqAsciiString::kHeaderSize)); |
| 5694 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5695 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5696 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5697 | // Pack both characters in ebx. |
| 5698 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5699 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5700 | // Set the characters in the new string. |
| 5701 | __ mov_w(FieldOperand(eax, SeqAsciiString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5702 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5703 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5704 | |
| 5705 | __ bind(&longer_than_two); |
| 5706 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5707 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5708 | __ j(below, &string_add_flat_result); |
| 5709 | |
| 5710 | // 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] | 5711 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5712 | Label non_ascii, allocated, ascii_data; |
| 5713 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5714 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5715 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5716 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5717 | __ and_(ecx, edi); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5718 | STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
| 5719 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5720 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5721 | __ j(zero, &non_ascii); |
| 5722 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5723 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5724 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5725 | __ bind(&allocated); |
| 5726 | // Fill the fields of the cons string. |
| 5727 | if (FLAG_debug_code) __ AbortIfNotSmi(ebx); |
| 5728 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5729 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5730 | Immediate(String::kEmptyHashField)); |
| 5731 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5732 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5733 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5734 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5735 | __ ret(2 * kPointerSize); |
| 5736 | __ bind(&non_ascii); |
| 5737 | // 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] | 5738 | // to contain only ASCII characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5739 | // ecx: first instance type AND second instance type. |
| 5740 | // edi: second instance type. |
| 5741 | __ test(ecx, Immediate(kAsciiDataHintMask)); |
| 5742 | __ j(not_zero, &ascii_data); |
| 5743 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5744 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5745 | __ xor_(edi, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5746 | STATIC_ASSERT(kAsciiStringTag != 0 && kAsciiDataHintTag != 0); |
| 5747 | __ and_(edi, kAsciiStringTag | kAsciiDataHintTag); |
| 5748 | __ cmp(edi, kAsciiStringTag | kAsciiDataHintTag); |
| 5749 | __ j(equal, &ascii_data); |
| 5750 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5751 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5752 | __ jmp(&allocated); |
| 5753 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5754 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5755 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5756 | // Handle creating a flat result from either external or sequential strings. |
| 5757 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5758 | // eax: first string |
| 5759 | // ebx: length of resulting flat string as a smi |
| 5760 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5761 | Label first_prepared, second_prepared; |
| 5762 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5763 | __ bind(&string_add_flat_result); |
| 5764 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5765 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5766 | // ecx: instance type of first string |
| 5767 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5768 | __ test_b(ecx, kStringRepresentationMask); |
| 5769 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5770 | // Rule out short external string and load string resource. |
| 5771 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5772 | __ test_b(ecx, kShortExternalStringMask); |
| 5773 | __ j(not_zero, &call_runtime); |
| 5774 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 5775 | STATIC_ASSERT(SeqAsciiString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
| 5776 | __ jmp(&first_prepared, Label::kNear); |
| 5777 | __ bind(&first_is_sequential); |
| 5778 | __ add(eax, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 5779 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5780 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5781 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5782 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5783 | // Check whether both strings have same encoding. |
| 5784 | // edi: instance type of second string |
| 5785 | __ xor_(ecx, edi); |
| 5786 | __ test_b(ecx, kStringEncodingMask); |
| 5787 | __ j(not_zero, &call_runtime); |
| 5788 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5789 | __ test_b(edi, kStringRepresentationMask); |
| 5790 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5791 | // Rule out short external string and load string resource. |
| 5792 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5793 | __ test_b(edi, kShortExternalStringMask); |
| 5794 | __ j(not_zero, &call_runtime); |
| 5795 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
| 5796 | STATIC_ASSERT(SeqAsciiString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
| 5797 | __ jmp(&second_prepared, Label::kNear); |
| 5798 | __ bind(&second_is_sequential); |
| 5799 | __ add(edx, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 5800 | __ bind(&second_prepared); |
| 5801 | |
| 5802 | // Push the addresses of both strings' first characters onto the stack. |
| 5803 | __ push(edx); |
| 5804 | __ push(eax); |
| 5805 | |
| 5806 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5807 | // edi: instance type of second string |
| 5808 | // First string and second string have the same encoding. |
| 5809 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5810 | __ test_b(edi, kStringEncodingMask); |
| 5811 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5812 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5813 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5814 | // ebx: length of resulting flat string as a smi |
| 5815 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5816 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5817 | // eax: result string |
| 5818 | __ mov(ecx, eax); |
| 5819 | // Locate first character of result. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5820 | __ add(ecx, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5821 | // Load first argument's length and first character location. Account for |
| 5822 | // values currently on the stack when fetching arguments from it. |
| 5823 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5824 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5825 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5826 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5827 | // eax: result string |
| 5828 | // ecx: first character of result |
| 5829 | // edx: first char of first argument |
| 5830 | // edi: length of first argument |
| 5831 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5832 | // Load second argument's length and first character location. Account for |
| 5833 | // values currently on the stack when fetching arguments from it. |
| 5834 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5835 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5836 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5837 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5838 | // eax: result string |
| 5839 | // ecx: next character of result |
| 5840 | // edx: first char of second argument |
| 5841 | // edi: length of second argument |
| 5842 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5843 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5844 | __ ret(2 * kPointerSize); |
| 5845 | |
| 5846 | // Handle creating a flat two byte result. |
| 5847 | // eax: first string - known to be two byte |
| 5848 | // ebx: length of resulting flat string as a smi |
| 5849 | // edx: second string |
| 5850 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5851 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5852 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5853 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5854 | // eax: result string |
| 5855 | __ mov(ecx, eax); |
| 5856 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5857 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5858 | // Load second argument's length and first character location. Account for |
| 5859 | // values currently on the stack when fetching arguments from it. |
| 5860 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5861 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5862 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5863 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5864 | // eax: result string |
| 5865 | // ecx: first character of result |
| 5866 | // edx: first char of first argument |
| 5867 | // edi: length of first argument |
| 5868 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5869 | // Load second argument's length and first character location. Account for |
| 5870 | // values currently on the stack when fetching arguments from it. |
| 5871 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5872 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5873 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5874 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5875 | // eax: result string |
| 5876 | // ecx: next character of result |
| 5877 | // edx: first char of second argument |
| 5878 | // edi: length of second argument |
| 5879 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5880 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5881 | __ ret(2 * kPointerSize); |
| 5882 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5883 | // Recover stack pointer before jumping to runtime. |
| 5884 | __ bind(&call_runtime_drop_two); |
| 5885 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5886 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5887 | __ bind(&call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5888 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5889 | |
| 5890 | if (call_builtin.is_linked()) { |
| 5891 | __ bind(&call_builtin); |
| 5892 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 5893 | } |
| 5894 | } |
| 5895 | |
| 5896 | |
| 5897 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 5898 | int stack_offset, |
| 5899 | Register arg, |
| 5900 | Register scratch1, |
| 5901 | Register scratch2, |
| 5902 | Register scratch3, |
| 5903 | Label* slow) { |
| 5904 | // First check if the argument is already a string. |
| 5905 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5906 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5907 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 5908 | __ j(below, &done); |
| 5909 | |
| 5910 | // Check the number to string cache. |
| 5911 | Label not_cached; |
| 5912 | __ bind(¬_string); |
| 5913 | // Puts the cached result into scratch1. |
| 5914 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 5915 | arg, |
| 5916 | scratch1, |
| 5917 | scratch2, |
| 5918 | scratch3, |
| 5919 | false, |
| 5920 | ¬_cached); |
| 5921 | __ mov(arg, scratch1); |
| 5922 | __ mov(Operand(esp, stack_offset), arg); |
| 5923 | __ jmp(&done); |
| 5924 | |
| 5925 | // Check if the argument is a safe string wrapper. |
| 5926 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5927 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5928 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 5929 | __ j(not_equal, slow); |
| 5930 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 5931 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 5932 | __ j(zero, slow); |
| 5933 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 5934 | __ mov(Operand(esp, stack_offset), arg); |
| 5935 | |
| 5936 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5937 | } |
| 5938 | |
| 5939 | |
| 5940 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5941 | Register dest, |
| 5942 | Register src, |
| 5943 | Register count, |
| 5944 | Register scratch, |
| 5945 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5946 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5947 | __ bind(&loop); |
| 5948 | // This loop just copies one character at a time, as it is only used for very |
| 5949 | // short strings. |
| 5950 | if (ascii) { |
| 5951 | __ mov_b(scratch, Operand(src, 0)); |
| 5952 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5953 | __ add(src, Immediate(1)); |
| 5954 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5955 | } else { |
| 5956 | __ mov_w(scratch, Operand(src, 0)); |
| 5957 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5958 | __ add(src, Immediate(2)); |
| 5959 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5960 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5961 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5962 | __ j(not_zero, &loop); |
| 5963 | } |
| 5964 | |
| 5965 | |
| 5966 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 5967 | Register dest, |
| 5968 | Register src, |
| 5969 | Register count, |
| 5970 | Register scratch, |
| 5971 | bool ascii) { |
| 5972 | // Copy characters using rep movs of doublewords. |
| 5973 | // The destination is aligned on a 4 byte boundary because we are |
| 5974 | // copying to the beginning of a newly allocated string. |
| 5975 | ASSERT(dest.is(edi)); // rep movs destination |
| 5976 | ASSERT(src.is(esi)); // rep movs source |
| 5977 | ASSERT(count.is(ecx)); // rep movs count |
| 5978 | ASSERT(!scratch.is(dest)); |
| 5979 | ASSERT(!scratch.is(src)); |
| 5980 | ASSERT(!scratch.is(count)); |
| 5981 | |
| 5982 | // Nothing to do for zero characters. |
| 5983 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5984 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5985 | __ j(zero, &done); |
| 5986 | |
| 5987 | // Make count the number of bytes to copy. |
| 5988 | if (!ascii) { |
| 5989 | __ shl(count, 1); |
| 5990 | } |
| 5991 | |
| 5992 | // 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] | 5993 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5994 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5995 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5996 | |
| 5997 | // Copy from edi to esi using rep movs instruction. |
| 5998 | __ mov(scratch, count); |
| 5999 | __ sar(count, 2); // Number of doublewords to copy. |
| 6000 | __ cld(); |
| 6001 | __ rep_movs(); |
| 6002 | |
| 6003 | // Find number of bytes left. |
| 6004 | __ mov(count, scratch); |
| 6005 | __ and_(count, 3); |
| 6006 | |
| 6007 | // Check if there are more bytes to copy. |
| 6008 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6009 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6010 | __ j(zero, &done); |
| 6011 | |
| 6012 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6013 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6014 | __ bind(&loop); |
| 6015 | __ mov_b(scratch, Operand(src, 0)); |
| 6016 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6017 | __ add(src, Immediate(1)); |
| 6018 | __ add(dest, Immediate(1)); |
| 6019 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6020 | __ j(not_zero, &loop); |
| 6021 | |
| 6022 | __ bind(&done); |
| 6023 | } |
| 6024 | |
| 6025 | |
| 6026 | void StringHelper::GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 6027 | Register c1, |
| 6028 | Register c2, |
| 6029 | Register scratch1, |
| 6030 | Register scratch2, |
| 6031 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6032 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6033 | Label* not_found) { |
| 6034 | // Register scratch3 is the general scratch register in this function. |
| 6035 | Register scratch = scratch3; |
| 6036 | |
| 6037 | // Make sure that both characters are not digits as such strings has a |
| 6038 | // 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] | 6039 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6040 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6041 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6042 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6043 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6044 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6045 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6046 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6047 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6048 | |
| 6049 | __ bind(¬_array_index); |
| 6050 | // Calculate the two character string hash. |
| 6051 | Register hash = scratch1; |
| 6052 | GenerateHashInit(masm, hash, c1, scratch); |
| 6053 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 6054 | GenerateHashGetHash(masm, hash, scratch); |
| 6055 | |
| 6056 | // Collect the two characters in a register. |
| 6057 | Register chars = c1; |
| 6058 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6059 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6060 | |
| 6061 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6062 | // hash: hash of two character string. |
| 6063 | |
| 6064 | // Load the symbol table. |
| 6065 | Register symbol_table = c2; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6066 | ExternalReference roots_array_start = |
| 6067 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6068 | __ mov(scratch, Immediate(Heap::kSymbolTableRootIndex)); |
| 6069 | __ mov(symbol_table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6070 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6071 | |
| 6072 | // Calculate capacity mask from the symbol table capacity. |
| 6073 | Register mask = scratch2; |
| 6074 | __ mov(mask, FieldOperand(symbol_table, SymbolTable::kCapacityOffset)); |
| 6075 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6076 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6077 | |
| 6078 | // Registers |
| 6079 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6080 | // hash: hash of two character string |
| 6081 | // symbol_table: symbol table |
| 6082 | // mask: capacity mask |
| 6083 | // scratch: - |
| 6084 | |
| 6085 | // Perform a number of probes in the symbol table. |
| 6086 | static const int kProbes = 4; |
| 6087 | Label found_in_symbol_table; |
| 6088 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6089 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6090 | for (int i = 0; i < kProbes; i++) { |
| 6091 | // Calculate entry in symbol table. |
| 6092 | __ mov(scratch, hash); |
| 6093 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6094 | __ add(scratch, Immediate(SymbolTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6095 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6096 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6097 | |
| 6098 | // Load the entry from the symbol table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6099 | STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
| 6100 | __ mov(candidate, |
| 6101 | FieldOperand(symbol_table, |
| 6102 | scratch, |
| 6103 | times_pointer_size, |
| 6104 | SymbolTable::kElementsStartOffset)); |
| 6105 | |
| 6106 | // 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] | 6107 | Factory* factory = masm->isolate()->factory(); |
| 6108 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6109 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6110 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6111 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6112 | |
| 6113 | // If length is not 2 the string is not a candidate. |
| 6114 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 6115 | Immediate(Smi::FromInt(2))); |
| 6116 | __ j(not_equal, &next_probe[i]); |
| 6117 | |
| 6118 | // As we are out of registers save the mask on the stack and use that |
| 6119 | // register as a temporary. |
| 6120 | __ push(mask); |
| 6121 | Register temp = mask; |
| 6122 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6123 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6124 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 6125 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 6126 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 6127 | temp, temp, &next_probe_pop_mask[i]); |
| 6128 | |
| 6129 | // Check if the two characters match. |
| 6130 | __ mov(temp, FieldOperand(candidate, SeqAsciiString::kHeaderSize)); |
| 6131 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6132 | __ cmp(chars, temp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6133 | __ j(equal, &found_in_symbol_table); |
| 6134 | __ bind(&next_probe_pop_mask[i]); |
| 6135 | __ pop(mask); |
| 6136 | __ bind(&next_probe[i]); |
| 6137 | } |
| 6138 | |
| 6139 | // No matching 2 character string found by probing. |
| 6140 | __ jmp(not_found); |
| 6141 | |
| 6142 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6143 | Register result = candidate; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6144 | __ bind(&found_in_symbol_table); |
| 6145 | __ pop(mask); // Pop saved mask from the stack. |
| 6146 | if (!result.is(eax)) { |
| 6147 | __ mov(eax, result); |
| 6148 | } |
| 6149 | } |
| 6150 | |
| 6151 | |
| 6152 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 6153 | Register hash, |
| 6154 | Register character, |
| 6155 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6156 | // hash = (seed + character) + ((seed + character) << 10); |
| 6157 | if (Serializer::enabled()) { |
| 6158 | ExternalReference roots_array_start = |
| 6159 | ExternalReference::roots_array_start(masm->isolate()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6160 | __ mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6161 | __ mov(scratch, Operand::StaticArray(scratch, |
| 6162 | times_pointer_size, |
| 6163 | roots_array_start)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6164 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6165 | __ add(scratch, character); |
| 6166 | __ mov(hash, scratch); |
| 6167 | __ shl(scratch, 10); |
| 6168 | __ add(hash, scratch); |
| 6169 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6170 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6171 | __ lea(scratch, Operand(character, seed)); |
| 6172 | __ shl(scratch, 10); |
| 6173 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 6174 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6175 | // hash ^= hash >> 6; |
| 6176 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6177 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6178 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | |
| 6182 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 6183 | Register hash, |
| 6184 | Register character, |
| 6185 | Register scratch) { |
| 6186 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6187 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6188 | // hash += hash << 10; |
| 6189 | __ mov(scratch, hash); |
| 6190 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6191 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6192 | // hash ^= hash >> 6; |
| 6193 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6194 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6195 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6196 | } |
| 6197 | |
| 6198 | |
| 6199 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 6200 | Register hash, |
| 6201 | Register scratch) { |
| 6202 | // hash += hash << 3; |
| 6203 | __ mov(scratch, hash); |
| 6204 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6205 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6206 | // hash ^= hash >> 11; |
| 6207 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6208 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6209 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6210 | // hash += hash << 15; |
| 6211 | __ mov(scratch, hash); |
| 6212 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6213 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6214 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6215 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6216 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6217 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6218 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6219 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6220 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6221 | __ bind(&hash_not_zero); |
| 6222 | } |
| 6223 | |
| 6224 | |
| 6225 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6226 | Label runtime; |
| 6227 | |
| 6228 | // Stack frame on entry. |
| 6229 | // esp[0]: return address |
| 6230 | // esp[4]: to |
| 6231 | // esp[8]: from |
| 6232 | // esp[12]: string |
| 6233 | |
| 6234 | // Make sure first argument is a string. |
| 6235 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 6236 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6237 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6238 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 6239 | __ j(NegateCondition(is_string), &runtime); |
| 6240 | |
| 6241 | // eax: string |
| 6242 | // ebx: instance type |
| 6243 | |
| 6244 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6245 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6246 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6247 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6248 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6249 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6250 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6251 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6252 | // Shorter than original string's length: an actual substring. |
| 6253 | __ j(below, ¬_original_string, Label::kNear); |
| 6254 | // Longer than original string's length or negative: unsafe arguments. |
| 6255 | __ j(above, &runtime); |
| 6256 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6257 | Counters* counters = masm->isolate()->counters(); |
| 6258 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6259 | __ ret(3 * kPointerSize); |
| 6260 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6261 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6262 | // eax: string |
| 6263 | // ebx: instance type |
| 6264 | // ecx: sub string length (smi) |
| 6265 | // edx: from index (smi) |
| 6266 | // Deal with different string types: update the index if necessary |
| 6267 | // and put the underlying string into edi. |
| 6268 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6269 | // If the string is not indirect, it can only be sequential or external. |
| 6270 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6271 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6272 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 6273 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 6274 | |
| 6275 | Factory* factory = masm->isolate()->factory(); |
| 6276 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 6277 | __ j(not_zero, &sliced_string, Label::kNear); |
| 6278 | // Cons string. Check whether it is flat, then fetch first part. |
| 6279 | // Flat cons strings have an empty second part. |
| 6280 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 6281 | factory->empty_string()); |
| 6282 | __ j(not_equal, &runtime); |
| 6283 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 6284 | // Update instance type. |
| 6285 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6286 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6287 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6288 | |
| 6289 | __ bind(&sliced_string); |
| 6290 | // Sliced string. Fetch parent and adjust start index by offset. |
| 6291 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6292 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6293 | // Update instance type. |
| 6294 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6295 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6296 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6297 | |
| 6298 | __ bind(&seq_or_external_string); |
| 6299 | // Sequential or external string. Just move string to the expected register. |
| 6300 | __ mov(edi, eax); |
| 6301 | |
| 6302 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6303 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6304 | if (FLAG_string_slices) { |
| 6305 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6306 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6307 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6308 | // edx: adjusted start index (smi) |
| 6309 | // ecx: length (smi) |
| 6310 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 6311 | // Short slice. Copy instead of slicing. |
| 6312 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6313 | // Allocate new sliced string. At this point we do not reload the instance |
| 6314 | // type including the string encoding because we simply rely on the info |
| 6315 | // provided by the original string. It does not matter if the original |
| 6316 | // string's encoding is wrong because we always have to recheck encoding of |
| 6317 | // the newly created string's parent anyways due to externalized strings. |
| 6318 | Label two_byte_slice, set_slice_header; |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6319 | STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
| 6320 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6321 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6322 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6323 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6324 | __ jmp(&set_slice_header, Label::kNear); |
| 6325 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6326 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6327 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6328 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6329 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6330 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6331 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6332 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6333 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6334 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6335 | |
| 6336 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6337 | } |
| 6338 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6339 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6340 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6341 | // edx: adjusted start index (smi) |
| 6342 | // ecx: length (smi) |
| 6343 | // The subject string can only be external or sequential string of either |
| 6344 | // encoding at this point. |
| 6345 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 6346 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6347 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6348 | __ test_b(ebx, kExternalStringTag); |
| 6349 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6350 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6351 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6352 | // Rule out short external strings. |
| 6353 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6354 | __ test_b(ebx, kShortExternalStringMask); |
| 6355 | __ j(not_zero, &runtime); |
| 6356 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 6357 | // Move the pointer so that offset-wise, it looks like a sequential string. |
| 6358 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); |
| 6359 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6360 | |
| 6361 | __ bind(&sequential_string); |
| 6362 | // Stash away (adjusted) index and (underlying) string. |
| 6363 | __ push(edx); |
| 6364 | __ push(edi); |
| 6365 | __ SmiUntag(ecx); |
| 6366 | STATIC_ASSERT((kAsciiStringTag & kStringEncodingMask) != 0); |
| 6367 | __ test_b(ebx, kStringEncodingMask); |
| 6368 | __ j(zero, &two_byte_sequential); |
| 6369 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6370 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6371 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6372 | |
| 6373 | // eax: result string |
| 6374 | // ecx: result string length |
| 6375 | __ mov(edx, esi); // esi used by following code. |
| 6376 | // Locate first character of result. |
| 6377 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6378 | __ add(edi, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6379 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6380 | __ pop(esi); |
| 6381 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6382 | __ SmiUntag(ebx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6383 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqAsciiString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6384 | |
| 6385 | // eax: result string |
| 6386 | // ecx: result length |
| 6387 | // edx: original value of esi |
| 6388 | // edi: first character of result |
| 6389 | // esi: character of sub string start |
| 6390 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6391 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6392 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6393 | __ ret(3 * kPointerSize); |
| 6394 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6395 | __ bind(&two_byte_sequential); |
| 6396 | // Sequential two-byte string. Allocate the result. |
| 6397 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6398 | |
| 6399 | // eax: result string |
| 6400 | // ecx: result string length |
| 6401 | __ mov(edx, esi); // esi used by following code. |
| 6402 | // Locate first character of result. |
| 6403 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6404 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6405 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6406 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6407 | __ pop(esi); |
| 6408 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6409 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6410 | // byte character. |
| 6411 | STATIC_ASSERT(kSmiTag == 0); |
| 6412 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6413 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6414 | |
| 6415 | // eax: result string |
| 6416 | // ecx: result length |
| 6417 | // edx: original value of esi |
| 6418 | // edi: first character of result |
| 6419 | // esi: character of sub string start |
| 6420 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6421 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6422 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6423 | __ ret(3 * kPointerSize); |
| 6424 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6425 | // Drop pushed values on the stack before tail call. |
| 6426 | __ bind(&runtime_drop_two); |
| 6427 | __ Drop(2); |
| 6428 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6429 | // Just jump to runtime to create the sub string. |
| 6430 | __ bind(&runtime); |
| 6431 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
| 6432 | } |
| 6433 | |
| 6434 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6435 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6436 | Register left, |
| 6437 | Register right, |
| 6438 | Register scratch1, |
| 6439 | Register scratch2) { |
| 6440 | Register length = scratch1; |
| 6441 | |
| 6442 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6443 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6444 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6445 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6446 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6447 | __ bind(&strings_not_equal); |
| 6448 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6449 | __ ret(0); |
| 6450 | |
| 6451 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6452 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6453 | __ bind(&check_zero_length); |
| 6454 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6455 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6456 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6457 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6458 | __ ret(0); |
| 6459 | |
| 6460 | // Compare characters. |
| 6461 | __ bind(&compare_chars); |
| 6462 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6463 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6464 | |
| 6465 | // Characters are equal. |
| 6466 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6467 | __ ret(0); |
| 6468 | } |
| 6469 | |
| 6470 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6471 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6472 | Register left, |
| 6473 | Register right, |
| 6474 | Register scratch1, |
| 6475 | Register scratch2, |
| 6476 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6477 | Counters* counters = masm->isolate()->counters(); |
| 6478 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6479 | |
| 6480 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6481 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6482 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6483 | __ mov(scratch3, scratch1); |
| 6484 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6485 | |
| 6486 | Register length_delta = scratch3; |
| 6487 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6488 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6489 | // 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] | 6490 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6491 | __ bind(&left_shorter); |
| 6492 | |
| 6493 | Register min_length = scratch1; |
| 6494 | |
| 6495 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6496 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6497 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6498 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6499 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6500 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6501 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6502 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6503 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6504 | |
| 6505 | // Compare lengths - strings up to min-length are equal. |
| 6506 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6507 | __ test(length_delta, length_delta); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6508 | __ j(not_zero, &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6509 | |
| 6510 | // Result is EQUAL. |
| 6511 | STATIC_ASSERT(EQUAL == 0); |
| 6512 | STATIC_ASSERT(kSmiTag == 0); |
| 6513 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6514 | __ ret(0); |
| 6515 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6516 | Label result_greater; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6517 | __ bind(&result_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6518 | __ j(greater, &result_greater, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6519 | |
| 6520 | // Result is LESS. |
| 6521 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6522 | __ ret(0); |
| 6523 | |
| 6524 | // Result is GREATER. |
| 6525 | __ bind(&result_greater); |
| 6526 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6527 | __ ret(0); |
| 6528 | } |
| 6529 | |
| 6530 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6531 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6532 | MacroAssembler* masm, |
| 6533 | Register left, |
| 6534 | Register right, |
| 6535 | Register length, |
| 6536 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6537 | Label* chars_not_equal, |
| 6538 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6539 | // Change index to run from -length to -1 by adding length to string |
| 6540 | // start. This means that loop ends when index reaches zero, which |
| 6541 | // doesn't need an additional compare. |
| 6542 | __ SmiUntag(length); |
| 6543 | __ lea(left, |
| 6544 | FieldOperand(left, length, times_1, SeqAsciiString::kHeaderSize)); |
| 6545 | __ lea(right, |
| 6546 | FieldOperand(right, length, times_1, SeqAsciiString::kHeaderSize)); |
| 6547 | __ neg(length); |
| 6548 | Register index = length; // index = -length; |
| 6549 | |
| 6550 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6551 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6552 | __ bind(&loop); |
| 6553 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6554 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6555 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6556 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6557 | __ j(not_zero, &loop); |
| 6558 | } |
| 6559 | |
| 6560 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6561 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6562 | Label runtime; |
| 6563 | |
| 6564 | // Stack frame on entry. |
| 6565 | // esp[0]: return address |
| 6566 | // esp[4]: right string |
| 6567 | // esp[8]: left string |
| 6568 | |
| 6569 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6570 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6571 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6572 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6573 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6574 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6575 | STATIC_ASSERT(EQUAL == 0); |
| 6576 | STATIC_ASSERT(kSmiTag == 0); |
| 6577 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6578 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6579 | __ ret(2 * kPointerSize); |
| 6580 | |
| 6581 | __ bind(¬_same); |
| 6582 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6583 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6584 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6585 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6586 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6587 | // Drop arguments from the stack. |
| 6588 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6589 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6590 | __ push(ecx); |
| 6591 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6592 | |
| 6593 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6594 | // tagged as a small integer. |
| 6595 | __ bind(&runtime); |
| 6596 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6597 | } |
| 6598 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6599 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6600 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
| 6601 | ASSERT(state_ == CompareIC::SMIS); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6602 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6603 | __ mov(ecx, edx); |
| 6604 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6605 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6606 | |
| 6607 | if (GetCondition() == equal) { |
| 6608 | // 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] | 6609 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6610 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6611 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6612 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6613 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6614 | // Correct sign of result in case of overflow. |
| 6615 | __ not_(edx); |
| 6616 | __ bind(&done); |
| 6617 | __ mov(eax, edx); |
| 6618 | } |
| 6619 | __ ret(0); |
| 6620 | |
| 6621 | __ bind(&miss); |
| 6622 | GenerateMiss(masm); |
| 6623 | } |
| 6624 | |
| 6625 | |
| 6626 | void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) { |
| 6627 | ASSERT(state_ == CompareIC::HEAP_NUMBERS); |
| 6628 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6629 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6630 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6631 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6632 | __ mov(ecx, edx); |
| 6633 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6634 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6635 | |
| 6636 | __ CmpObjectType(eax, HEAP_NUMBER_TYPE, ecx); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6637 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6638 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6639 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6640 | |
| 6641 | // Inlining the double comparison and falling back to the general compare |
| 6642 | // stub if NaN is involved or SS2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6643 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6644 | CpuFeatures::Scope scope1(SSE2); |
| 6645 | CpuFeatures::Scope scope2(CMOV); |
| 6646 | |
| 6647 | // Load left and right operand |
| 6648 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6649 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 6650 | |
| 6651 | // Compare operands |
| 6652 | __ ucomisd(xmm0, xmm1); |
| 6653 | |
| 6654 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6655 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6656 | |
| 6657 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6658 | // Performing mov, because xor would destroy the flag register. |
| 6659 | __ mov(eax, 0); // equal |
| 6660 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6661 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6662 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6663 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6664 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6665 | } |
| 6666 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6667 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6668 | CompareStub stub(GetCondition(), strict(), NO_COMPARE_FLAGS); |
| 6669 | __ bind(&generic_stub); |
| 6670 | __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 6671 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6672 | __ bind(&maybe_undefined1); |
| 6673 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6674 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6675 | __ j(not_equal, &miss); |
| 6676 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6677 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6678 | __ jmp(&unordered); |
| 6679 | } |
| 6680 | |
| 6681 | __ bind(&maybe_undefined2); |
| 6682 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6683 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6684 | __ j(equal, &unordered); |
| 6685 | } |
| 6686 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6687 | __ bind(&miss); |
| 6688 | GenerateMiss(masm); |
| 6689 | } |
| 6690 | |
| 6691 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6692 | void ICCompareStub::GenerateSymbols(MacroAssembler* masm) { |
| 6693 | ASSERT(state_ == CompareIC::SYMBOLS); |
| 6694 | ASSERT(GetCondition() == equal); |
| 6695 | |
| 6696 | // Registers containing left and right operands respectively. |
| 6697 | Register left = edx; |
| 6698 | Register right = eax; |
| 6699 | Register tmp1 = ecx; |
| 6700 | Register tmp2 = ebx; |
| 6701 | |
| 6702 | // Check that both operands are heap objects. |
| 6703 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6704 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6705 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6706 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6707 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6708 | |
| 6709 | // Check that both operands are symbols. |
| 6710 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6711 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6712 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6713 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6714 | STATIC_ASSERT(kSymbolTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6715 | __ and_(tmp1, tmp2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6716 | __ test(tmp1, Immediate(kIsSymbolMask)); |
| 6717 | __ j(zero, &miss, Label::kNear); |
| 6718 | |
| 6719 | // Symbols are compared by identity. |
| 6720 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6721 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6722 | // Make sure eax is non-zero. At this point input operands are |
| 6723 | // guaranteed to be non-zero. |
| 6724 | ASSERT(right.is(eax)); |
| 6725 | __ j(not_equal, &done, Label::kNear); |
| 6726 | STATIC_ASSERT(EQUAL == 0); |
| 6727 | STATIC_ASSERT(kSmiTag == 0); |
| 6728 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6729 | __ bind(&done); |
| 6730 | __ ret(0); |
| 6731 | |
| 6732 | __ bind(&miss); |
| 6733 | GenerateMiss(masm); |
| 6734 | } |
| 6735 | |
| 6736 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6737 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
| 6738 | ASSERT(state_ == CompareIC::STRINGS); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6739 | Label miss; |
| 6740 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6741 | bool equality = Token::IsEqualityOp(op_); |
| 6742 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6743 | // Registers containing left and right operands respectively. |
| 6744 | Register left = edx; |
| 6745 | Register right = eax; |
| 6746 | Register tmp1 = ecx; |
| 6747 | Register tmp2 = ebx; |
| 6748 | Register tmp3 = edi; |
| 6749 | |
| 6750 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6751 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6752 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6753 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6754 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6755 | |
| 6756 | // Check that both operands are strings. This leaves the instance |
| 6757 | // types loaded in tmp1 and tmp2. |
| 6758 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6759 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6760 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6761 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6762 | __ mov(tmp3, tmp1); |
| 6763 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6764 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6765 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 6766 | __ j(not_zero, &miss); |
| 6767 | |
| 6768 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6769 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6770 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6771 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6772 | STATIC_ASSERT(EQUAL == 0); |
| 6773 | STATIC_ASSERT(kSmiTag == 0); |
| 6774 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6775 | __ ret(0); |
| 6776 | |
| 6777 | // Handle not identical strings. |
| 6778 | __ bind(¬_same); |
| 6779 | |
| 6780 | // 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] | 6781 | // because we already know they are not identical. But in the case of |
| 6782 | // non-equality compare, we still need to determine the order. |
| 6783 | if (equality) { |
| 6784 | Label do_compare; |
| 6785 | STATIC_ASSERT(kSymbolTag != 0); |
| 6786 | __ and_(tmp1, tmp2); |
| 6787 | __ test(tmp1, Immediate(kIsSymbolMask)); |
| 6788 | __ j(zero, &do_compare, Label::kNear); |
| 6789 | // Make sure eax is non-zero. At this point input operands are |
| 6790 | // guaranteed to be non-zero. |
| 6791 | ASSERT(right.is(eax)); |
| 6792 | __ ret(0); |
| 6793 | __ bind(&do_compare); |
| 6794 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6795 | |
| 6796 | // Check that both strings are sequential ASCII. |
| 6797 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6798 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 6799 | |
| 6800 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6801 | if (equality) { |
| 6802 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6803 | masm, left, right, tmp1, tmp2); |
| 6804 | } else { |
| 6805 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 6806 | masm, left, right, tmp1, tmp2, tmp3); |
| 6807 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6808 | |
| 6809 | // Handle more complex cases in runtime. |
| 6810 | __ bind(&runtime); |
| 6811 | __ pop(tmp1); // Return address. |
| 6812 | __ push(left); |
| 6813 | __ push(right); |
| 6814 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6815 | if (equality) { |
| 6816 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6817 | } else { |
| 6818 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6819 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6820 | |
| 6821 | __ bind(&miss); |
| 6822 | GenerateMiss(masm); |
| 6823 | } |
| 6824 | |
| 6825 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6826 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
| 6827 | ASSERT(state_ == CompareIC::OBJECTS); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6828 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6829 | __ mov(ecx, edx); |
| 6830 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6831 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6832 | |
| 6833 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6834 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6835 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6836 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6837 | |
| 6838 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6839 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6840 | __ ret(0); |
| 6841 | |
| 6842 | __ bind(&miss); |
| 6843 | GenerateMiss(masm); |
| 6844 | } |
| 6845 | |
| 6846 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6847 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 6848 | Label miss; |
| 6849 | __ mov(ecx, edx); |
| 6850 | __ and_(ecx, eax); |
| 6851 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6852 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6853 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 6854 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 6855 | __ cmp(ecx, known_map_); |
| 6856 | __ j(not_equal, &miss, Label::kNear); |
| 6857 | __ cmp(ebx, known_map_); |
| 6858 | __ j(not_equal, &miss, Label::kNear); |
| 6859 | |
| 6860 | __ sub(eax, edx); |
| 6861 | __ ret(0); |
| 6862 | |
| 6863 | __ bind(&miss); |
| 6864 | GenerateMiss(masm); |
| 6865 | } |
| 6866 | |
| 6867 | |
| 6868 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6869 | { |
| 6870 | // Call the runtime system in a fresh internal frame. |
| 6871 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 6872 | masm->isolate()); |
| 6873 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6874 | __ push(edx); // Preserve edx and eax. |
| 6875 | __ push(eax); |
| 6876 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6877 | __ push(eax); |
| 6878 | __ push(Immediate(Smi::FromInt(op_))); |
| 6879 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6880 | // Compute the entry point of the rewritten stub. |
| 6881 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 6882 | __ pop(eax); |
| 6883 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6884 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6885 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6886 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6887 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6888 | } |
| 6889 | |
| 6890 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6891 | // Helper function used to check that the dictionary doesn't contain |
| 6892 | // the property. This function may return false negatives, so miss_label |
| 6893 | // must always call a backup property check that is complete. |
| 6894 | // This function is safe to call if the receiver has fast properties. |
| 6895 | // 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] | 6896 | void StringDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 6897 | Label* miss, |
| 6898 | Label* done, |
| 6899 | Register properties, |
| 6900 | Handle<String> name, |
| 6901 | Register r0) { |
| 6902 | ASSERT(name->IsSymbol()); |
| 6903 | |
| 6904 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6905 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6906 | // undefined value), it guarantees the hash table doesn't contain the |
| 6907 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6908 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6909 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6910 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6911 | Register index = r0; |
| 6912 | // Capacity is smi 2^n. |
| 6913 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 6914 | __ dec(index); |
| 6915 | __ and_(index, |
| 6916 | Immediate(Smi::FromInt(name->Hash() + |
| 6917 | StringDictionary::GetProbeOffset(i)))); |
| 6918 | |
| 6919 | // Scale the index by multiplying by the entry size. |
| 6920 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6921 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 6922 | Register entity_name = r0; |
| 6923 | // Having undefined at this place means the name is not contained. |
| 6924 | ASSERT_EQ(kSmiTagSize, 1); |
| 6925 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 6926 | kElementsStartOffset - kHeapObjectTag)); |
| 6927 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 6928 | __ j(equal, done); |
| 6929 | |
| 6930 | // Stop if found the property. |
| 6931 | __ cmp(entity_name, Handle<String>(name)); |
| 6932 | __ j(equal, miss); |
| 6933 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6934 | Label the_hole; |
| 6935 | // Check for the hole and skip. |
| 6936 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
| 6937 | __ j(equal, &the_hole, Label::kNear); |
| 6938 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6939 | // Check if the entry name is not a symbol. |
| 6940 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 6941 | __ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 6942 | kIsSymbolMask); |
| 6943 | __ j(zero, miss); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6944 | __ bind(&the_hole); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6945 | } |
| 6946 | |
| 6947 | StringDictionaryLookupStub stub(properties, |
| 6948 | r0, |
| 6949 | r0, |
| 6950 | StringDictionaryLookupStub::NEGATIVE_LOOKUP); |
| 6951 | __ push(Immediate(Handle<Object>(name))); |
| 6952 | __ push(Immediate(name->Hash())); |
| 6953 | __ CallStub(&stub); |
| 6954 | __ test(r0, r0); |
| 6955 | __ j(not_zero, miss); |
| 6956 | __ jmp(done); |
| 6957 | } |
| 6958 | |
| 6959 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6960 | // Probe the string dictionary in the |elements| register. Jump to the |
| 6961 | // |done| label if a property with the given name is found leaving the |
| 6962 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 6963 | // otherwise. |
| 6964 | void StringDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 6965 | Label* miss, |
| 6966 | Label* done, |
| 6967 | Register elements, |
| 6968 | Register name, |
| 6969 | Register r0, |
| 6970 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 6971 | ASSERT(!elements.is(r0)); |
| 6972 | ASSERT(!elements.is(r1)); |
| 6973 | ASSERT(!name.is(r0)); |
| 6974 | ASSERT(!name.is(r1)); |
| 6975 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6976 | // Assert that name contains a string. |
| 6977 | if (FLAG_debug_code) __ AbortIfNotString(name); |
| 6978 | |
| 6979 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 6980 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 6981 | __ dec(r1); |
| 6982 | |
| 6983 | // Generate an unrolled loop that performs a few probes before |
| 6984 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 6985 | // cover ~93% of loads from dictionaries. |
| 6986 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6987 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6988 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 6989 | __ shr(r0, String::kHashShift); |
| 6990 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6991 | __ add(r0, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6992 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6993 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6994 | |
| 6995 | // Scale the index by multiplying by the entry size. |
| 6996 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6997 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 6998 | |
| 6999 | // Check if the key is identical to the name. |
| 7000 | __ cmp(name, Operand(elements, |
| 7001 | r0, |
| 7002 | times_4, |
| 7003 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7004 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7005 | } |
| 7006 | |
| 7007 | StringDictionaryLookupStub stub(elements, |
| 7008 | r1, |
| 7009 | r0, |
| 7010 | POSITIVE_LOOKUP); |
| 7011 | __ push(name); |
| 7012 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 7013 | __ shr(r0, String::kHashShift); |
| 7014 | __ push(r0); |
| 7015 | __ CallStub(&stub); |
| 7016 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7017 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7018 | __ j(zero, miss); |
| 7019 | __ jmp(done); |
| 7020 | } |
| 7021 | |
| 7022 | |
| 7023 | void StringDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7024 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 7025 | // 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] | 7026 | // Stack frame on entry: |
| 7027 | // esp[0 * kPointerSize]: return address. |
| 7028 | // esp[1 * kPointerSize]: key's hash. |
| 7029 | // esp[2 * kPointerSize]: key. |
| 7030 | // Registers: |
| 7031 | // dictionary_: StringDictionary to probe. |
| 7032 | // result_: used as scratch. |
| 7033 | // index_: will hold an index of entry if lookup is successful. |
| 7034 | // might alias with result_. |
| 7035 | // Returns: |
| 7036 | // result_ is zero if lookup failed, non zero otherwise. |
| 7037 | |
| 7038 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 7039 | |
| 7040 | Register scratch = result_; |
| 7041 | |
| 7042 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 7043 | __ dec(scratch); |
| 7044 | __ SmiUntag(scratch); |
| 7045 | __ push(scratch); |
| 7046 | |
| 7047 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7048 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7049 | // undefined value), it guarantees the hash table doesn't contain the |
| 7050 | // property. It's true even if some slots represent deleted properties |
| 7051 | // (their names are the null value). |
| 7052 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 7053 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7054 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 7055 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7056 | __ add(scratch, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7057 | } |
| 7058 | __ and_(scratch, Operand(esp, 0)); |
| 7059 | |
| 7060 | // Scale the index by multiplying by the entry size. |
| 7061 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7062 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 7063 | |
| 7064 | // Having undefined at this place means the name is not contained. |
| 7065 | ASSERT_EQ(kSmiTagSize, 1); |
| 7066 | __ mov(scratch, Operand(dictionary_, |
| 7067 | index_, |
| 7068 | times_pointer_size, |
| 7069 | kElementsStartOffset - kHeapObjectTag)); |
| 7070 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 7071 | __ j(equal, ¬_in_dictionary); |
| 7072 | |
| 7073 | // Stop if found the property. |
| 7074 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 7075 | __ j(equal, &in_dictionary); |
| 7076 | |
| 7077 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
| 7078 | // If we hit a non symbol key during negative lookup |
| 7079 | // we have to bailout as this key might be equal to the |
| 7080 | // key we are looking for. |
| 7081 | |
| 7082 | // Check if the entry name is not a symbol. |
| 7083 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 7084 | __ test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 7085 | kIsSymbolMask); |
| 7086 | __ j(zero, &maybe_in_dictionary); |
| 7087 | } |
| 7088 | } |
| 7089 | |
| 7090 | __ bind(&maybe_in_dictionary); |
| 7091 | // If we are doing negative lookup then probing failure should be |
| 7092 | // treated as a lookup success. For positive lookup probing failure |
| 7093 | // should be treated as lookup failure. |
| 7094 | if (mode_ == POSITIVE_LOOKUP) { |
| 7095 | __ mov(result_, Immediate(0)); |
| 7096 | __ Drop(1); |
| 7097 | __ ret(2 * kPointerSize); |
| 7098 | } |
| 7099 | |
| 7100 | __ bind(&in_dictionary); |
| 7101 | __ mov(result_, Immediate(1)); |
| 7102 | __ Drop(1); |
| 7103 | __ ret(2 * kPointerSize); |
| 7104 | |
| 7105 | __ bind(¬_in_dictionary); |
| 7106 | __ mov(result_, Immediate(0)); |
| 7107 | __ Drop(1); |
| 7108 | __ ret(2 * kPointerSize); |
| 7109 | } |
| 7110 | |
| 7111 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7112 | struct AheadOfTimeWriteBarrierStubList { |
| 7113 | Register object, value, address; |
| 7114 | RememberedSetAction action; |
| 7115 | }; |
| 7116 | |
| 7117 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7118 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 7119 | |
| 7120 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7121 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7122 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7123 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7124 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 7125 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7126 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7127 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7128 | // Used in StoreStubCompiler::CompileStoreField and |
| 7129 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7130 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7131 | // GenerateStoreField calls the stub with two different permutations of |
| 7132 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7133 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7134 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7135 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7136 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7137 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7138 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7139 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 7140 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7141 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7142 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7143 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7144 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 7145 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7146 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7147 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 7148 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7149 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7150 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7151 | // FastNewClosureStub |
| 7152 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7153 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7154 | { 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] | 7155 | }; |
| 7156 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7157 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7158 | |
| 7159 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7160 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7161 | !entry->object.is(no_reg); |
| 7162 | entry++) { |
| 7163 | if (object_.is(entry->object) && |
| 7164 | value_.is(entry->value) && |
| 7165 | address_.is(entry->address) && |
| 7166 | remembered_set_action_ == entry->action && |
| 7167 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7168 | return true; |
| 7169 | } |
| 7170 | } |
| 7171 | return false; |
| 7172 | } |
| 7173 | |
| 7174 | |
| 7175 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime() { |
| 7176 | StoreBufferOverflowStub stub1(kDontSaveFPRegs); |
| 7177 | stub1.GetCode()->set_is_pregenerated(true); |
| 7178 | |
| 7179 | CpuFeatures::TryForceFeatureScope scope(SSE2); |
| 7180 | if (CpuFeatures::IsSupported(SSE2)) { |
| 7181 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
| 7182 | stub2.GetCode()->set_is_pregenerated(true); |
| 7183 | } |
| 7184 | } |
| 7185 | |
| 7186 | |
| 7187 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7188 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7189 | !entry->object.is(no_reg); |
| 7190 | entry++) { |
| 7191 | RecordWriteStub stub(entry->object, |
| 7192 | entry->value, |
| 7193 | entry->address, |
| 7194 | entry->action, |
| 7195 | kDontSaveFPRegs); |
| 7196 | stub.GetCode()->set_is_pregenerated(true); |
| 7197 | } |
| 7198 | } |
| 7199 | |
| 7200 | |
| 7201 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7202 | // the value has just been written into the object, now this stub makes sure |
| 7203 | // we keep the GC informed. The word in the object where the value has been |
| 7204 | // written is in the address register. |
| 7205 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7206 | Label skip_to_incremental_noncompacting; |
| 7207 | Label skip_to_incremental_compacting; |
| 7208 | |
| 7209 | // The first two instructions are generated with labels so as to get the |
| 7210 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7211 | // forth between a compare instructions (a nop in this position) and the |
| 7212 | // real branch when we start and stop incremental heap marking. |
| 7213 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 7214 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 7215 | |
| 7216 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7217 | __ RememberedSetHelper(object_, |
| 7218 | address_, |
| 7219 | value_, |
| 7220 | save_fp_regs_mode_, |
| 7221 | MacroAssembler::kReturnAtEnd); |
| 7222 | } else { |
| 7223 | __ ret(0); |
| 7224 | } |
| 7225 | |
| 7226 | __ bind(&skip_to_incremental_noncompacting); |
| 7227 | GenerateIncremental(masm, INCREMENTAL); |
| 7228 | |
| 7229 | __ bind(&skip_to_incremental_compacting); |
| 7230 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7231 | |
| 7232 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7233 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7234 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 7235 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 7236 | } |
| 7237 | |
| 7238 | |
| 7239 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7240 | regs_.Save(masm); |
| 7241 | |
| 7242 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7243 | Label dont_need_remembered_set; |
| 7244 | |
| 7245 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7246 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7247 | regs_.scratch0(), |
| 7248 | &dont_need_remembered_set); |
| 7249 | |
| 7250 | __ CheckPageFlag(regs_.object(), |
| 7251 | regs_.scratch0(), |
| 7252 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7253 | not_zero, |
| 7254 | &dont_need_remembered_set); |
| 7255 | |
| 7256 | // First notify the incremental marker if necessary, then update the |
| 7257 | // remembered set. |
| 7258 | CheckNeedsToInformIncrementalMarker( |
| 7259 | masm, |
| 7260 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 7261 | mode); |
| 7262 | InformIncrementalMarker(masm, mode); |
| 7263 | regs_.Restore(masm); |
| 7264 | __ RememberedSetHelper(object_, |
| 7265 | address_, |
| 7266 | value_, |
| 7267 | save_fp_regs_mode_, |
| 7268 | MacroAssembler::kReturnAtEnd); |
| 7269 | |
| 7270 | __ bind(&dont_need_remembered_set); |
| 7271 | } |
| 7272 | |
| 7273 | CheckNeedsToInformIncrementalMarker( |
| 7274 | masm, |
| 7275 | kReturnOnNoNeedToInformIncrementalMarker, |
| 7276 | mode); |
| 7277 | InformIncrementalMarker(masm, mode); |
| 7278 | regs_.Restore(masm); |
| 7279 | __ ret(0); |
| 7280 | } |
| 7281 | |
| 7282 | |
| 7283 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7284 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7285 | int argument_count = 3; |
| 7286 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7287 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
| 7288 | if (mode == INCREMENTAL_COMPACTION) { |
| 7289 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
| 7290 | } else { |
| 7291 | ASSERT(mode == INCREMENTAL); |
| 7292 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7293 | __ mov(Operand(esp, 1 * kPointerSize), regs_.scratch0()); // Value. |
| 7294 | } |
| 7295 | __ mov(Operand(esp, 2 * kPointerSize), |
| 7296 | Immediate(ExternalReference::isolate_address())); |
| 7297 | |
| 7298 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7299 | if (mode == INCREMENTAL_COMPACTION) { |
| 7300 | __ CallCFunction( |
| 7301 | ExternalReference::incremental_evacuation_record_write_function( |
| 7302 | masm->isolate()), |
| 7303 | argument_count); |
| 7304 | } else { |
| 7305 | ASSERT(mode == INCREMENTAL); |
| 7306 | __ CallCFunction( |
| 7307 | ExternalReference::incremental_marking_record_write_function( |
| 7308 | masm->isolate()), |
| 7309 | argument_count); |
| 7310 | } |
| 7311 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7312 | } |
| 7313 | |
| 7314 | |
| 7315 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7316 | MacroAssembler* masm, |
| 7317 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7318 | Mode mode) { |
| 7319 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7320 | |
| 7321 | // Let's look at the color of the object: If it is not black we don't have |
| 7322 | // to inform the incremental marker. |
| 7323 | __ JumpIfBlack(regs_.object(), |
| 7324 | regs_.scratch0(), |
| 7325 | regs_.scratch1(), |
| 7326 | &object_is_black, |
| 7327 | Label::kNear); |
| 7328 | |
| 7329 | regs_.Restore(masm); |
| 7330 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7331 | __ RememberedSetHelper(object_, |
| 7332 | address_, |
| 7333 | value_, |
| 7334 | save_fp_regs_mode_, |
| 7335 | MacroAssembler::kReturnAtEnd); |
| 7336 | } else { |
| 7337 | __ ret(0); |
| 7338 | } |
| 7339 | |
| 7340 | __ bind(&object_is_black); |
| 7341 | |
| 7342 | // Get the value from the slot. |
| 7343 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7344 | |
| 7345 | if (mode == INCREMENTAL_COMPACTION) { |
| 7346 | Label ensure_not_white; |
| 7347 | |
| 7348 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7349 | regs_.scratch1(), // Scratch. |
| 7350 | MemoryChunk::kEvacuationCandidateMask, |
| 7351 | zero, |
| 7352 | &ensure_not_white, |
| 7353 | Label::kNear); |
| 7354 | |
| 7355 | __ CheckPageFlag(regs_.object(), |
| 7356 | regs_.scratch1(), // Scratch. |
| 7357 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7358 | not_zero, |
| 7359 | &ensure_not_white, |
| 7360 | Label::kNear); |
| 7361 | |
| 7362 | __ jmp(&need_incremental); |
| 7363 | |
| 7364 | __ bind(&ensure_not_white); |
| 7365 | } |
| 7366 | |
| 7367 | // We need an extra register for this, so we push the object register |
| 7368 | // temporarily. |
| 7369 | __ push(regs_.object()); |
| 7370 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7371 | regs_.scratch1(), // Scratch. |
| 7372 | regs_.object(), // Scratch. |
| 7373 | &need_incremental_pop_object, |
| 7374 | Label::kNear); |
| 7375 | __ pop(regs_.object()); |
| 7376 | |
| 7377 | regs_.Restore(masm); |
| 7378 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7379 | __ RememberedSetHelper(object_, |
| 7380 | address_, |
| 7381 | value_, |
| 7382 | save_fp_regs_mode_, |
| 7383 | MacroAssembler::kReturnAtEnd); |
| 7384 | } else { |
| 7385 | __ ret(0); |
| 7386 | } |
| 7387 | |
| 7388 | __ bind(&need_incremental_pop_object); |
| 7389 | __ pop(regs_.object()); |
| 7390 | |
| 7391 | __ bind(&need_incremental); |
| 7392 | |
| 7393 | // Fall through when we need to inform the incremental marker. |
| 7394 | } |
| 7395 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7396 | |
| 7397 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7398 | // ----------- S t a t e ------------- |
| 7399 | // -- eax : element value to store |
| 7400 | // -- ebx : array literal |
| 7401 | // -- edi : map of array literal |
| 7402 | // -- ecx : element index as smi |
| 7403 | // -- edx : array literal index in function |
| 7404 | // -- esp[0] : return address |
| 7405 | // ----------------------------------- |
| 7406 | |
| 7407 | Label element_done; |
| 7408 | Label double_elements; |
| 7409 | Label smi_element; |
| 7410 | Label slow_elements; |
| 7411 | Label slow_elements_from_double; |
| 7412 | Label fast_elements; |
| 7413 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7414 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7415 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7416 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7417 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7418 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7419 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7420 | // Store into the array literal requires a elements transition. Call into |
| 7421 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7422 | |
| 7423 | __ bind(&slow_elements); |
| 7424 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7425 | // call. |
| 7426 | __ push(ebx); |
| 7427 | __ push(ecx); |
| 7428 | __ push(eax); |
| 7429 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7430 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7431 | __ push(edx); |
| 7432 | __ push(edi); // Return return address so that tail call returns to right |
| 7433 | // place. |
| 7434 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7435 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7436 | __ bind(&slow_elements_from_double); |
| 7437 | __ pop(edx); |
| 7438 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7439 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7440 | // 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] | 7441 | __ bind(&fast_elements); |
| 7442 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7443 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7444 | FixedArrayBase::kHeaderSize)); |
| 7445 | __ mov(Operand(ecx, 0), eax); |
| 7446 | // Update the write barrier for the array store. |
| 7447 | __ RecordWrite(ebx, ecx, eax, |
| 7448 | kDontSaveFPRegs, |
| 7449 | EMIT_REMEMBERED_SET, |
| 7450 | OMIT_SMI_CHECK); |
| 7451 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7452 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7453 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7454 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7455 | __ bind(&smi_element); |
| 7456 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7457 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7458 | FixedArrayBase::kHeaderSize), eax); |
| 7459 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7460 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7461 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7462 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7463 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7464 | __ push(edx); |
| 7465 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7466 | __ StoreNumberToDoubleElements(eax, |
| 7467 | edx, |
| 7468 | ecx, |
| 7469 | edi, |
| 7470 | xmm0, |
| 7471 | &slow_elements_from_double, |
| 7472 | false); |
| 7473 | __ pop(edx); |
| 7474 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7475 | } |
| 7476 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7477 | |
| 7478 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 7479 | if (entry_hook_ != NULL) { |
| 7480 | ProfileEntryHookStub stub; |
| 7481 | masm->CallStub(&stub); |
| 7482 | } |
| 7483 | } |
| 7484 | |
| 7485 | |
| 7486 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 7487 | // Ecx is the only volatile register we must save. |
| 7488 | __ push(ecx); |
| 7489 | |
| 7490 | // Calculate and push the original stack pointer. |
| 7491 | __ lea(eax, Operand(esp, kPointerSize)); |
| 7492 | __ push(eax); |
| 7493 | |
| 7494 | // Calculate and push the function address. |
| 7495 | __ mov(eax, Operand(eax, 0)); |
| 7496 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7497 | __ push(eax); |
| 7498 | |
| 7499 | // Call the entry hook. |
| 7500 | int32_t hook_location = reinterpret_cast<int32_t>(&entry_hook_); |
| 7501 | __ call(Operand(hook_location, RelocInfo::NONE)); |
| 7502 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7503 | |
| 7504 | // Restore ecx. |
| 7505 | __ pop(ecx); |
| 7506 | __ ret(0); |
| 7507 | } |
| 7508 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7509 | #undef __ |
| 7510 | |
| 7511 | } } // namespace v8::internal |
| 7512 | |
| 7513 | #endif // V8_TARGET_ARCH_IA32 |