ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1 | // Copyright 2011 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" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 38 | |
| 39 | namespace v8 { |
| 40 | namespace internal { |
| 41 | |
| 42 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 43 | |
| 44 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 45 | // The ToNumber stub takes one argument in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 46 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 47 | __ JumpIfNotSmi(eax, &check_heap_number, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 48 | __ ret(0); |
| 49 | |
| 50 | __ bind(&check_heap_number); |
| 51 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 52 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 53 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 54 | __ j(not_equal, &call_builtin, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 55 | __ ret(0); |
| 56 | |
| 57 | __ bind(&call_builtin); |
| 58 | __ pop(ecx); // Pop return address. |
| 59 | __ push(eax); |
| 60 | __ push(ecx); // Push return address. |
| 61 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
| 62 | } |
| 63 | |
| 64 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 65 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 66 | // Create a new closure from the given function info in new |
| 67 | // space. Set the context to the current context in esi. |
| 68 | Label gc; |
| 69 | __ AllocateInNewSpace(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
| 70 | |
| 71 | // Get the function info from the stack. |
| 72 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 73 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 74 | int map_index = strict_mode_ == kStrictMode |
| 75 | ? Context::STRICT_MODE_FUNCTION_MAP_INDEX |
| 76 | : Context::FUNCTION_MAP_INDEX; |
| 77 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 78 | // Compute the function map in the current global context and set that |
| 79 | // as the map of the allocated object. |
| 80 | __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 81 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalContextOffset)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 82 | __ mov(ecx, Operand(ecx, Context::SlotOffset(map_index))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 83 | __ mov(FieldOperand(eax, JSObject::kMapOffset), ecx); |
| 84 | |
| 85 | // Initialize the rest of the function. We don't have to update the |
| 86 | // write barrier because the allocated object is in new space. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 87 | Factory* factory = masm->isolate()->factory(); |
| 88 | __ mov(ebx, Immediate(factory->empty_fixed_array())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 89 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 90 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 91 | __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 92 | Immediate(factory->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 93 | __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 94 | __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 95 | __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 96 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 97 | Immediate(factory->undefined_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 98 | |
| 99 | // Initialize the code pointer in the function to be the one |
| 100 | // found in the shared function info object. |
| 101 | __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 102 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 103 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 104 | |
| 105 | // Return and remove the on-stack parameter. |
| 106 | __ ret(1 * kPointerSize); |
| 107 | |
| 108 | // Create a new closure through the slower runtime call. |
| 109 | __ bind(&gc); |
| 110 | __ pop(ecx); // Temporarily remove return address. |
| 111 | __ pop(edx); |
| 112 | __ push(esi); |
| 113 | __ push(edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 114 | __ push(Immediate(factory->false_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 115 | __ push(ecx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 116 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | |
| 120 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 121 | // Try to allocate the context in new space. |
| 122 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 123 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 124 | __ AllocateInNewSpace((length * kPointerSize) + FixedArray::kHeaderSize, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 125 | eax, ebx, ecx, &gc, TAG_OBJECT); |
| 126 | |
| 127 | // Get the function from the stack. |
| 128 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 129 | |
| 130 | // Setup the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 131 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 132 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 133 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 134 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 135 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 136 | |
| 137 | // Setup the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 138 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 139 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 140 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 141 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 142 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 143 | // Copy the global object from the previous context. |
| 144 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 145 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_INDEX)), ebx); |
| 146 | |
| 147 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 148 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 149 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 150 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 151 | } |
| 152 | |
| 153 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 154 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 155 | __ ret(1 * kPointerSize); |
| 156 | |
| 157 | // Need to collect. Call into runtime system. |
| 158 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 159 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 163 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 164 | // Stack layout on entry: |
| 165 | // |
| 166 | // [esp + (1 * kPointerSize)]: function |
| 167 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 168 | |
| 169 | // Try to allocate the context in new space. |
| 170 | Label gc; |
| 171 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 172 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
| 173 | eax, ebx, ecx, &gc, TAG_OBJECT); |
| 174 | |
| 175 | // Get the function or sentinel from the stack. |
| 176 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 177 | |
| 178 | // Get the serialized scope info from the stack. |
| 179 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 180 | |
| 181 | // Setup the object header. |
| 182 | Factory* factory = masm->isolate()->factory(); |
| 183 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 184 | factory->block_context_map()); |
| 185 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 186 | Immediate(Smi::FromInt(length))); |
| 187 | |
| 188 | // If this block context is nested in the global context we get a smi |
| 189 | // sentinel instead of a function. The block context should get the |
| 190 | // canonical empty function of the global context as its closure which |
| 191 | // we still have to look up. |
| 192 | Label after_sentinel; |
| 193 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 194 | if (FLAG_debug_code) { |
| 195 | const char* message = "Expected 0 as a Smi sentinel"; |
| 196 | __ cmp(ecx, 0); |
| 197 | __ Assert(equal, message); |
| 198 | } |
| 199 | __ mov(ecx, GlobalObjectOperand()); |
| 200 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalContextOffset)); |
| 201 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 202 | __ bind(&after_sentinel); |
| 203 | |
| 204 | // Setup the fixed slots. |
| 205 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 206 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 207 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 208 | |
| 209 | // Copy the global object from the previous context. |
| 210 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_INDEX)); |
| 211 | __ mov(ContextOperand(eax, Context::GLOBAL_INDEX), ebx); |
| 212 | |
| 213 | // Initialize the rest of the slots to the hole value. |
| 214 | if (slots_ == 1) { |
| 215 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 216 | factory->the_hole_value()); |
| 217 | } else { |
| 218 | __ mov(ebx, factory->the_hole_value()); |
| 219 | for (int i = 0; i < slots_; i++) { |
| 220 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | // Return and remove the on-stack parameters. |
| 225 | __ mov(esi, eax); |
| 226 | __ ret(2 * kPointerSize); |
| 227 | |
| 228 | // Need to collect. Call into runtime system. |
| 229 | __ bind(&gc); |
| 230 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 231 | } |
| 232 | |
| 233 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 234 | void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) { |
| 235 | // Stack layout on entry: |
| 236 | // |
| 237 | // [esp + kPointerSize]: constant elements. |
| 238 | // [esp + (2 * kPointerSize)]: literal index. |
| 239 | // [esp + (3 * kPointerSize)]: literals array. |
| 240 | |
| 241 | // All sizes here are multiples of kPointerSize. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 242 | int elements_size = 0; |
| 243 | if (length_ > 0) { |
| 244 | elements_size = mode_ == CLONE_DOUBLE_ELEMENTS |
| 245 | ? FixedDoubleArray::SizeFor(length_) |
| 246 | : FixedArray::SizeFor(length_); |
| 247 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 248 | int size = JSArray::kSize + elements_size; |
| 249 | |
| 250 | // Load boilerplate object into ecx and check if we need to create a |
| 251 | // boilerplate. |
| 252 | Label slow_case; |
| 253 | __ mov(ecx, Operand(esp, 3 * kPointerSize)); |
| 254 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 255 | STATIC_ASSERT(kPointerSize == 4); |
| 256 | STATIC_ASSERT(kSmiTagSize == 1); |
| 257 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 258 | __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size, |
| 259 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 260 | Factory* factory = masm->isolate()->factory(); |
| 261 | __ cmp(ecx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 262 | __ j(equal, &slow_case); |
| 263 | |
| 264 | if (FLAG_debug_code) { |
| 265 | const char* message; |
| 266 | Handle<Map> expected_map; |
| 267 | if (mode_ == CLONE_ELEMENTS) { |
| 268 | message = "Expected (writable) fixed array"; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 269 | expected_map = factory->fixed_array_map(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 270 | } else if (mode_ == CLONE_DOUBLE_ELEMENTS) { |
| 271 | message = "Expected (writable) fixed double array"; |
| 272 | expected_map = factory->fixed_double_array_map(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 273 | } else { |
| 274 | ASSERT(mode_ == COPY_ON_WRITE_ELEMENTS); |
| 275 | message = "Expected copy-on-write fixed array"; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 276 | expected_map = factory->fixed_cow_array_map(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 277 | } |
| 278 | __ push(ecx); |
| 279 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 280 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), expected_map); |
| 281 | __ Assert(equal, message); |
| 282 | __ pop(ecx); |
| 283 | } |
| 284 | |
| 285 | // Allocate both the JS array and the elements array in one big |
| 286 | // allocation. This avoids multiple limit checks. |
| 287 | __ AllocateInNewSpace(size, eax, ebx, edx, &slow_case, TAG_OBJECT); |
| 288 | |
| 289 | // Copy the JS array part. |
| 290 | for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
| 291 | if ((i != JSArray::kElementsOffset) || (length_ == 0)) { |
| 292 | __ mov(ebx, FieldOperand(ecx, i)); |
| 293 | __ mov(FieldOperand(eax, i), ebx); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | if (length_ > 0) { |
| 298 | // Get hold of the elements array of the boilerplate and setup the |
| 299 | // elements pointer in the resulting object. |
| 300 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 301 | __ lea(edx, Operand(eax, JSArray::kSize)); |
| 302 | __ mov(FieldOperand(eax, JSArray::kElementsOffset), edx); |
| 303 | |
| 304 | // Copy the elements array. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 305 | if (mode_ == CLONE_ELEMENTS) { |
| 306 | for (int i = 0; i < elements_size; i += kPointerSize) { |
| 307 | __ mov(ebx, FieldOperand(ecx, i)); |
| 308 | __ mov(FieldOperand(edx, i), ebx); |
| 309 | } |
| 310 | } else { |
| 311 | ASSERT(mode_ == CLONE_DOUBLE_ELEMENTS); |
| 312 | int i; |
| 313 | for (i = 0; i < FixedDoubleArray::kHeaderSize; i += kPointerSize) { |
| 314 | __ mov(ebx, FieldOperand(ecx, i)); |
| 315 | __ mov(FieldOperand(edx, i), ebx); |
| 316 | } |
| 317 | while (i < elements_size) { |
| 318 | __ fld_d(FieldOperand(ecx, i)); |
| 319 | __ fstp_d(FieldOperand(edx, i)); |
| 320 | i += kDoubleSize; |
| 321 | } |
| 322 | ASSERT(i == elements_size); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
| 326 | // Return and remove the on-stack parameters. |
| 327 | __ ret(3 * kPointerSize); |
| 328 | |
| 329 | __ bind(&slow_case); |
| 330 | __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
| 331 | } |
| 332 | |
| 333 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 334 | // The stub expects its argument on the stack and returns its result in tos_: |
| 335 | // zero for false, and a non-zero value for true. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 336 | void ToBooleanStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 337 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 338 | // 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] | 339 | Label patch; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 340 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 341 | const Register argument = eax; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 342 | const Register map = edx; |
| 343 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 344 | if (!types_.IsEmpty()) { |
| 345 | __ mov(argument, Operand(esp, 1 * kPointerSize)); |
| 346 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 347 | |
| 348 | // undefined -> false |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 349 | CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 350 | |
| 351 | // Boolean -> its value |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 352 | CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); |
| 353 | CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 354 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 355 | // 'null' -> false. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 356 | CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 357 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 358 | if (types_.Contains(SMI)) { |
| 359 | // Smis: 0 -> false, all other -> true |
| 360 | Label not_smi; |
| 361 | __ JumpIfNotSmi(argument, ¬_smi, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 362 | // argument contains the correct return value already. |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 363 | if (!tos_.is(argument)) { |
| 364 | __ mov(tos_, argument); |
| 365 | } |
| 366 | __ ret(1 * kPointerSize); |
| 367 | __ bind(¬_smi); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 368 | } else if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 369 | // If we need a map later and have a Smi -> patch. |
| 370 | __ JumpIfSmi(argument, &patch, Label::kNear); |
| 371 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 372 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 373 | if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 374 | __ mov(map, FieldOperand(argument, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 375 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 376 | if (types_.CanBeUndetectable()) { |
| 377 | __ test_b(FieldOperand(map, Map::kBitFieldOffset), |
| 378 | 1 << Map::kIsUndetectable); |
| 379 | // Undetectable -> false. |
| 380 | Label not_undetectable; |
| 381 | __ j(zero, ¬_undetectable, Label::kNear); |
| 382 | __ Set(tos_, Immediate(0)); |
| 383 | __ ret(1 * kPointerSize); |
| 384 | __ bind(¬_undetectable); |
| 385 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 386 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 387 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 388 | if (types_.Contains(SPEC_OBJECT)) { |
| 389 | // spec object -> true. |
| 390 | Label not_js_object; |
| 391 | __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
| 392 | __ j(below, ¬_js_object, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 393 | // argument contains the correct return value already. |
| 394 | if (!tos_.is(argument)) { |
| 395 | __ Set(tos_, Immediate(1)); |
| 396 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 397 | __ ret(1 * kPointerSize); |
| 398 | __ bind(¬_js_object); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 399 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 400 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 401 | if (types_.Contains(STRING)) { |
| 402 | // String value -> false iff empty. |
| 403 | Label not_string; |
| 404 | __ CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
| 405 | __ j(above_equal, ¬_string, Label::kNear); |
| 406 | __ mov(tos_, FieldOperand(argument, String::kLengthOffset)); |
| 407 | __ ret(1 * kPointerSize); // the string length is OK as the return value |
| 408 | __ bind(¬_string); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | if (types_.Contains(HEAP_NUMBER)) { |
| 412 | // heap number -> false iff +0, -0, or NaN. |
| 413 | Label not_heap_number, false_result; |
| 414 | __ cmp(map, factory->heap_number_map()); |
| 415 | __ j(not_equal, ¬_heap_number, Label::kNear); |
| 416 | __ fldz(); |
| 417 | __ fld_d(FieldOperand(argument, HeapNumber::kValueOffset)); |
| 418 | __ FCmp(); |
| 419 | __ j(zero, &false_result, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 420 | // argument contains the correct return value already. |
| 421 | if (!tos_.is(argument)) { |
| 422 | __ Set(tos_, Immediate(1)); |
| 423 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 424 | __ ret(1 * kPointerSize); |
| 425 | __ bind(&false_result); |
| 426 | __ Set(tos_, Immediate(0)); |
| 427 | __ ret(1 * kPointerSize); |
| 428 | __ bind(¬_heap_number); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 429 | } |
| 430 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 431 | __ bind(&patch); |
| 432 | GenerateTypeTransition(masm); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 436 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 437 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 438 | // store the registers in any particular way, but we do have to store and |
| 439 | // restore them. |
| 440 | __ pushad(); |
| 441 | if (save_doubles_ == kSaveFPRegs) { |
| 442 | CpuFeatures::Scope scope(SSE2); |
| 443 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 444 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 445 | XMMRegister reg = XMMRegister::from_code(i); |
| 446 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 447 | } |
| 448 | } |
| 449 | const int argument_count = 1; |
| 450 | |
| 451 | AllowExternalCallThatCantCauseGC scope(masm); |
| 452 | __ PrepareCallCFunction(argument_count, ecx); |
| 453 | __ mov(Operand(esp, 0 * kPointerSize), |
| 454 | Immediate(ExternalReference::isolate_address())); |
| 455 | __ CallCFunction( |
| 456 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 457 | argument_count); |
| 458 | if (save_doubles_ == kSaveFPRegs) { |
| 459 | CpuFeatures::Scope scope(SSE2); |
| 460 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 461 | XMMRegister reg = XMMRegister::from_code(i); |
| 462 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 463 | } |
| 464 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 465 | } |
| 466 | __ popad(); |
| 467 | __ ret(0); |
| 468 | } |
| 469 | |
| 470 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 471 | void ToBooleanStub::CheckOddball(MacroAssembler* masm, |
| 472 | Type type, |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 473 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 474 | bool result) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 475 | const Register argument = eax; |
| 476 | if (types_.Contains(type)) { |
| 477 | // If we see an expected oddball, return its ToBoolean value tos_. |
| 478 | Label different_value; |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 479 | __ CompareRoot(argument, value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 480 | __ j(not_equal, &different_value, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 481 | if (!result) { |
| 482 | // If we have to return zero, there is no way around clearing tos_. |
| 483 | __ Set(tos_, Immediate(0)); |
| 484 | } else if (!tos_.is(argument)) { |
| 485 | // If we have to return non-zero, we can re-use the argument if it is the |
| 486 | // same register as the result, because we never see Smi-zero here. |
| 487 | __ Set(tos_, Immediate(1)); |
| 488 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 489 | __ ret(1 * kPointerSize); |
| 490 | __ bind(&different_value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
| 494 | |
| 495 | void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 496 | __ pop(ecx); // Get return address, operand is now on top of stack. |
| 497 | __ push(Immediate(Smi::FromInt(tos_.code()))); |
| 498 | __ push(Immediate(Smi::FromInt(types_.ToByte()))); |
| 499 | __ push(ecx); // Push return address. |
| 500 | // Patch the caller to an appropriate specialized stub and return the |
| 501 | // operation result to the caller of the stub. |
| 502 | __ TailCallExternalReference( |
| 503 | ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), |
| 504 | 3, |
| 505 | 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 509 | class FloatingPointHelper : public AllStatic { |
| 510 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 511 | enum ArgLocation { |
| 512 | ARGS_ON_STACK, |
| 513 | ARGS_IN_REGISTERS |
| 514 | }; |
| 515 | |
| 516 | // Code pattern for loading a floating point value. Input value must |
| 517 | // be either a smi or a heap number object (fp value). Requirements: |
| 518 | // operand in register number. Returns operand as floating point number |
| 519 | // on FPU stack. |
| 520 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 521 | |
| 522 | // Code pattern for loading floating point values. Input values must |
| 523 | // be either smi or heap number objects (fp values). Requirements: |
| 524 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 525 | // Returns operands as floating point numbers on FPU stack. |
| 526 | static void LoadFloatOperands(MacroAssembler* masm, |
| 527 | Register scratch, |
| 528 | ArgLocation arg_location = ARGS_ON_STACK); |
| 529 | |
| 530 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 531 | // Expects operands in edx, eax. |
| 532 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 533 | |
| 534 | // Test if operands are smi or number objects (fp). Requirements: |
| 535 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 536 | // operands, jumps to the non_float label otherwise. |
| 537 | static void CheckFloatOperands(MacroAssembler* masm, |
| 538 | Label* non_float, |
| 539 | Register scratch); |
| 540 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 541 | // Checks that the two floating point numbers on top of the FPU stack |
| 542 | // have int32 values. |
| 543 | static void CheckFloatOperandsAreInt32(MacroAssembler* masm, |
| 544 | Label* non_int32); |
| 545 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 546 | // Takes the operands in edx and eax and loads them as integers in eax |
| 547 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 548 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 549 | bool use_sse3, |
| 550 | Label* operand_conversion_failure); |
| 551 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 552 | // Must only be called after LoadUnknownsAsIntegers. Assumes that the |
| 553 | // operands are pushed on the stack, and that their conversions to int32 |
| 554 | // are in eax and ecx. Checks that the original numbers were in the int32 |
| 555 | // range. |
| 556 | static void CheckLoadedIntegersWereInt32(MacroAssembler* masm, |
| 557 | bool use_sse3, |
| 558 | Label* not_int32); |
| 559 | |
| 560 | // Assumes that operands are smis or heap numbers and loads them |
| 561 | // into xmm0 and xmm1. Operands are in edx and eax. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 562 | // Leaves operands unchanged. |
| 563 | static void LoadSSE2Operands(MacroAssembler* masm); |
| 564 | |
| 565 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 566 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 567 | // either operand is not a number. Operands are in edx and eax. |
| 568 | // Leaves operands unchanged. |
| 569 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 570 | |
| 571 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 572 | // Expects operands in edx, eax. |
| 573 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 574 | |
| 575 | // Checks that the two floating point numbers loaded into xmm0 and xmm1 |
| 576 | // have int32 values. |
| 577 | static void CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 578 | Label* non_int32, |
| 579 | Register scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 580 | }; |
| 581 | |
| 582 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 583 | // Get the integer part of a heap number. Surprisingly, all this bit twiddling |
| 584 | // is faster than using the built-in instructions on floating point registers. |
| 585 | // Trashes edi and ebx. Dest is ecx. Source cannot be ecx or one of the |
| 586 | // trashed registers. |
| 587 | static void IntegerConvert(MacroAssembler* masm, |
| 588 | Register source, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 589 | bool use_sse3, |
| 590 | Label* conversion_failure) { |
| 591 | ASSERT(!source.is(ecx) && !source.is(edi) && !source.is(ebx)); |
| 592 | Label done, right_exponent, normal_exponent; |
| 593 | Register scratch = ebx; |
| 594 | Register scratch2 = edi; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 595 | // Get exponent word. |
| 596 | __ mov(scratch, FieldOperand(source, HeapNumber::kExponentOffset)); |
| 597 | // Get exponent alone in scratch2. |
| 598 | __ mov(scratch2, scratch); |
| 599 | __ and_(scratch2, HeapNumber::kExponentMask); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 600 | if (use_sse3) { |
| 601 | CpuFeatures::Scope scope(SSE3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 602 | // Check whether the exponent is too big for a 64 bit signed integer. |
| 603 | static const uint32_t kTooBigExponent = |
| 604 | (HeapNumber::kExponentBias + 63) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 605 | __ cmp(scratch2, Immediate(kTooBigExponent)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 606 | __ j(greater_equal, conversion_failure); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 607 | // Load x87 register with heap number. |
| 608 | __ fld_d(FieldOperand(source, HeapNumber::kValueOffset)); |
| 609 | // Reserve space for 64 bit answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 610 | __ sub(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 611 | // Do conversion, which cannot fail because we checked the exponent. |
| 612 | __ fisttp_d(Operand(esp, 0)); |
| 613 | __ 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] | 614 | __ add(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 615 | } else { |
| 616 | // Load ecx with zero. We use this either for the final shift or |
| 617 | // for the answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 618 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 619 | // Check whether the exponent matches a 32 bit signed int that cannot be |
| 620 | // represented by a Smi. A non-smi 32 bit integer is 1.xxx * 2^30 so the |
| 621 | // exponent is 30 (biased). This is the exponent that we are fastest at and |
| 622 | // also the highest exponent we can handle here. |
| 623 | const uint32_t non_smi_exponent = |
| 624 | (HeapNumber::kExponentBias + 30) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 625 | __ cmp(scratch2, Immediate(non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 626 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 627 | // logic. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 628 | __ j(equal, &right_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 629 | // If the exponent is higher than that then go to slow case. This catches |
| 630 | // 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] | 631 | __ j(less, &normal_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 632 | |
| 633 | { |
| 634 | // Handle a big exponent. The only reason we have this code is that the |
| 635 | // >>> operator has a tendency to generate numbers with an exponent of 31. |
| 636 | const uint32_t big_non_smi_exponent = |
| 637 | (HeapNumber::kExponentBias + 31) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 638 | __ cmp(scratch2, Immediate(big_non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 639 | __ j(not_equal, conversion_failure); |
| 640 | // We have the big exponent, typically from >>>. This means the number is |
| 641 | // in the range 2^31 to 2^32 - 1. Get the top bits of the mantissa. |
| 642 | __ mov(scratch2, scratch); |
| 643 | __ and_(scratch2, HeapNumber::kMantissaMask); |
| 644 | // Put back the implicit 1. |
| 645 | __ or_(scratch2, 1 << HeapNumber::kExponentShift); |
| 646 | // Shift up the mantissa bits to take up the space the exponent used to |
| 647 | // take. We just orred in the implicit bit so that took care of one and |
| 648 | // we want to use the full unsigned range so we subtract 1 bit from the |
| 649 | // shift distance. |
| 650 | const int big_shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 651 | __ shl(scratch2, big_shift_distance); |
| 652 | // Get the second half of the double. |
| 653 | __ mov(ecx, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 654 | // Shift down 21 bits to get the most significant 11 bits or the low |
| 655 | // mantissa word. |
| 656 | __ shr(ecx, 32 - big_shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 657 | __ or_(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 658 | // 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] | 659 | __ test(scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 660 | __ j(positive, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 661 | __ neg(ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 662 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | __ bind(&normal_exponent); |
| 666 | // Exponent word in scratch, exponent part of exponent word in scratch2. |
| 667 | // Zero in ecx. |
| 668 | // We know the exponent is smaller than 30 (biased). If it is less than |
| 669 | // 0 (biased) then the number is smaller in magnitude than 1.0 * 2^0, ie |
| 670 | // it rounds to zero. |
| 671 | const uint32_t zero_exponent = |
| 672 | (HeapNumber::kExponentBias + 0) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 673 | __ sub(scratch2, Immediate(zero_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 674 | // ecx already has a Smi zero. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 675 | __ j(less, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 676 | |
| 677 | // We have a shifted exponent between 0 and 30 in scratch2. |
| 678 | __ shr(scratch2, HeapNumber::kExponentShift); |
| 679 | __ mov(ecx, Immediate(30)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 680 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 681 | |
| 682 | __ bind(&right_exponent); |
| 683 | // Here ecx is the shift, scratch is the exponent word. |
| 684 | // Get the top bits of the mantissa. |
| 685 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 686 | // Put back the implicit 1. |
| 687 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 688 | // Shift up the mantissa bits to take up the space the exponent used to |
| 689 | // take. We have kExponentShift + 1 significant bits int he low end of the |
| 690 | // word. Shift them to the top bits. |
| 691 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 692 | __ shl(scratch, shift_distance); |
| 693 | // Get the second half of the double. For some exponents we don't |
| 694 | // actually need this because the bits get shifted out again, but |
| 695 | // it's probably slower to test than just to do it. |
| 696 | __ mov(scratch2, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 697 | // Shift down 22 bits to get the most significant 10 bits or the low |
| 698 | // mantissa word. |
| 699 | __ shr(scratch2, 32 - shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 700 | __ or_(scratch2, scratch); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 701 | // Move down according to the exponent. |
| 702 | __ shr_cl(scratch2); |
| 703 | // Now the unsigned answer is in scratch2. We need to move it to ecx and |
| 704 | // we may need to fix the sign. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 705 | Label negative; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 706 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 707 | __ cmp(ecx, FieldOperand(source, HeapNumber::kExponentOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 708 | __ j(greater, &negative, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 709 | __ mov(ecx, scratch2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 710 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 711 | __ bind(&negative); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 712 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 713 | __ bind(&done); |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 718 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 719 | const char* op_name = Token::Name(op_); |
| 720 | const char* overwrite_name = NULL; // Make g++ happy. |
| 721 | switch (mode_) { |
| 722 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 723 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 724 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 725 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 726 | op_name, |
| 727 | overwrite_name, |
| 728 | UnaryOpIC::GetName(operand_type_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | |
| 732 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 733 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 734 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 735 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 736 | GenerateTypeTransition(masm); |
| 737 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 738 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 739 | GenerateSmiStub(masm); |
| 740 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 741 | case UnaryOpIC::HEAP_NUMBER: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 742 | GenerateHeapNumberStub(masm); |
| 743 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 744 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 745 | GenerateGenericStub(masm); |
| 746 | break; |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 751 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 752 | __ pop(ecx); // Save return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 753 | |
| 754 | __ push(eax); // the operand |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 755 | __ push(Immediate(Smi::FromInt(op_))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 756 | __ push(Immediate(Smi::FromInt(mode_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 757 | __ push(Immediate(Smi::FromInt(operand_type_))); |
| 758 | |
| 759 | __ push(ecx); // Push return address. |
| 760 | |
| 761 | // Patch the caller to an appropriate specialized stub and return the |
| 762 | // operation result to the caller of the stub. |
| 763 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 764 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | |
| 768 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 769 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 770 | switch (op_) { |
| 771 | case Token::SUB: |
| 772 | GenerateSmiStubSub(masm); |
| 773 | break; |
| 774 | case Token::BIT_NOT: |
| 775 | GenerateSmiStubBitNot(masm); |
| 776 | break; |
| 777 | default: |
| 778 | UNREACHABLE(); |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 783 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 784 | Label non_smi, undo, slow; |
| 785 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, |
| 786 | Label::kNear, Label::kNear, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 787 | __ bind(&undo); |
| 788 | GenerateSmiCodeUndo(masm); |
| 789 | __ bind(&non_smi); |
| 790 | __ bind(&slow); |
| 791 | GenerateTypeTransition(masm); |
| 792 | } |
| 793 | |
| 794 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 795 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 796 | Label non_smi; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 797 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 798 | __ bind(&non_smi); |
| 799 | GenerateTypeTransition(masm); |
| 800 | } |
| 801 | |
| 802 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 803 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 804 | Label* non_smi, |
| 805 | Label* undo, |
| 806 | Label* slow, |
| 807 | Label::Distance non_smi_near, |
| 808 | Label::Distance undo_near, |
| 809 | Label::Distance slow_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 810 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 811 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 812 | |
| 813 | // 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] | 814 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 815 | __ j(zero, slow, slow_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 816 | |
| 817 | // 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] | 818 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 819 | __ Set(eax, Immediate(0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 820 | __ sub(eax, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 821 | __ j(overflow, undo, undo_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 822 | __ ret(0); |
| 823 | } |
| 824 | |
| 825 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 826 | void UnaryOpStub::GenerateSmiCodeBitNot( |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 827 | MacroAssembler* masm, |
| 828 | Label* non_smi, |
| 829 | Label::Distance non_smi_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 830 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 831 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 832 | |
| 833 | // Flip bits and revert inverted smi-tag. |
| 834 | __ not_(eax); |
| 835 | __ and_(eax, ~kSmiTagMask); |
| 836 | __ ret(0); |
| 837 | } |
| 838 | |
| 839 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 840 | void UnaryOpStub::GenerateSmiCodeUndo(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 841 | __ mov(eax, edx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | |
| 845 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 846 | void UnaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 847 | switch (op_) { |
| 848 | case Token::SUB: |
| 849 | GenerateHeapNumberStubSub(masm); |
| 850 | break; |
| 851 | case Token::BIT_NOT: |
| 852 | GenerateHeapNumberStubBitNot(masm); |
| 853 | break; |
| 854 | default: |
| 855 | UNREACHABLE(); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 860 | void UnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 861 | Label non_smi, undo, slow, call_builtin; |
| 862 | GenerateSmiCodeSub(masm, &non_smi, &undo, &call_builtin, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 863 | __ bind(&non_smi); |
| 864 | GenerateHeapNumberCodeSub(masm, &slow); |
| 865 | __ bind(&undo); |
| 866 | GenerateSmiCodeUndo(masm); |
| 867 | __ bind(&slow); |
| 868 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 869 | __ bind(&call_builtin); |
| 870 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 874 | void UnaryOpStub::GenerateHeapNumberStubBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 875 | MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 876 | Label non_smi, slow; |
| 877 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 878 | __ bind(&non_smi); |
| 879 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 880 | __ bind(&slow); |
| 881 | GenerateTypeTransition(masm); |
| 882 | } |
| 883 | |
| 884 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 885 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 886 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 887 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 888 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 889 | __ j(not_equal, slow); |
| 890 | |
| 891 | if (mode_ == UNARY_OVERWRITE) { |
| 892 | __ xor_(FieldOperand(eax, HeapNumber::kExponentOffset), |
| 893 | Immediate(HeapNumber::kSignMask)); // Flip sign. |
| 894 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 895 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 896 | // edx: operand |
| 897 | |
| 898 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 899 | __ AllocateHeapNumber(eax, ebx, ecx, &slow_allocate_heapnumber); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 900 | __ jmp(&heapnumber_allocated, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 901 | |
| 902 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 903 | { |
| 904 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 905 | __ push(edx); |
| 906 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 907 | __ pop(edx); |
| 908 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 909 | |
| 910 | __ bind(&heapnumber_allocated); |
| 911 | // eax: allocated 'empty' number |
| 912 | __ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 913 | __ xor_(ecx, HeapNumber::kSignMask); // Flip sign. |
| 914 | __ mov(FieldOperand(eax, HeapNumber::kExponentOffset), ecx); |
| 915 | __ mov(ecx, FieldOperand(edx, HeapNumber::kMantissaOffset)); |
| 916 | __ mov(FieldOperand(eax, HeapNumber::kMantissaOffset), ecx); |
| 917 | } |
| 918 | __ ret(0); |
| 919 | } |
| 920 | |
| 921 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 922 | void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm, |
| 923 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 924 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 925 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 926 | __ j(not_equal, slow); |
| 927 | |
| 928 | // 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] | 929 | IntegerConvert(masm, eax, CpuFeatures::IsSupported(SSE3), slow); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 930 | |
| 931 | // 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] | 932 | Label try_float; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 933 | __ not_(ecx); |
| 934 | __ cmp(ecx, 0xc0000000); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 935 | __ j(sign, &try_float, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 936 | |
| 937 | // Tag the result as a smi and we're done. |
| 938 | STATIC_ASSERT(kSmiTagSize == 1); |
| 939 | __ lea(eax, Operand(ecx, times_2, kSmiTag)); |
| 940 | __ ret(0); |
| 941 | |
| 942 | // Try to store the result in a heap number. |
| 943 | __ bind(&try_float); |
| 944 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 945 | Label slow_allocate_heapnumber, heapnumber_allocated; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 946 | __ mov(ebx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 947 | __ AllocateHeapNumber(eax, edx, edi, &slow_allocate_heapnumber); |
| 948 | __ jmp(&heapnumber_allocated); |
| 949 | |
| 950 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 951 | { |
| 952 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 953 | // Push the original HeapNumber on the stack. The integer value can't |
| 954 | // be stored since it's untagged and not in the smi range (so we can't |
| 955 | // smi-tag it). We'll recalculate the value after the GC instead. |
| 956 | __ push(ebx); |
| 957 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 958 | // New HeapNumber is in eax. |
| 959 | __ pop(edx); |
| 960 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 961 | // IntegerConvert uses ebx and edi as scratch registers. |
| 962 | // This conversion won't go slow-case. |
| 963 | IntegerConvert(masm, edx, CpuFeatures::IsSupported(SSE3), slow); |
| 964 | __ not_(ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 965 | |
| 966 | __ bind(&heapnumber_allocated); |
| 967 | } |
| 968 | if (CpuFeatures::IsSupported(SSE2)) { |
| 969 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 970 | __ cvtsi2sd(xmm0, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 971 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 972 | } else { |
| 973 | __ push(ecx); |
| 974 | __ fild_s(Operand(esp, 0)); |
| 975 | __ pop(ecx); |
| 976 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 977 | } |
| 978 | __ ret(0); |
| 979 | } |
| 980 | |
| 981 | |
| 982 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 983 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 984 | switch (op_) { |
| 985 | case Token::SUB: |
| 986 | GenerateGenericStubSub(masm); |
| 987 | break; |
| 988 | case Token::BIT_NOT: |
| 989 | GenerateGenericStubBitNot(masm); |
| 990 | break; |
| 991 | default: |
| 992 | UNREACHABLE(); |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 997 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 998 | Label non_smi, undo, slow; |
| 999 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1000 | __ bind(&non_smi); |
| 1001 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1002 | __ bind(&undo); |
| 1003 | GenerateSmiCodeUndo(masm); |
| 1004 | __ bind(&slow); |
| 1005 | GenerateGenericCodeFallback(masm); |
| 1006 | } |
| 1007 | |
| 1008 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1009 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1010 | Label non_smi, slow; |
| 1011 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1012 | __ bind(&non_smi); |
| 1013 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1014 | __ bind(&slow); |
| 1015 | GenerateGenericCodeFallback(masm); |
| 1016 | } |
| 1017 | |
| 1018 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1019 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1020 | // Handle the slow case by jumping to the corresponding JavaScript builtin. |
| 1021 | __ pop(ecx); // pop return address. |
| 1022 | __ push(eax); |
| 1023 | __ push(ecx); // push return address |
| 1024 | switch (op_) { |
| 1025 | case Token::SUB: |
| 1026 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 1027 | break; |
| 1028 | case Token::BIT_NOT: |
| 1029 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 1030 | break; |
| 1031 | default: |
| 1032 | UNREACHABLE(); |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1037 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1038 | __ pop(ecx); // Save return address. |
| 1039 | __ push(edx); |
| 1040 | __ push(eax); |
| 1041 | // Left and right arguments are now on top. |
| 1042 | // Push this stub's key. Although the operation and the type info are |
| 1043 | // encoded into the key, the encoding is opaque, so push them too. |
| 1044 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
| 1045 | __ push(Immediate(Smi::FromInt(op_))); |
| 1046 | __ push(Immediate(Smi::FromInt(operands_type_))); |
| 1047 | |
| 1048 | __ push(ecx); // Push return address. |
| 1049 | |
| 1050 | // Patch the caller to an appropriate specialized stub and return the |
| 1051 | // operation result to the caller of the stub. |
| 1052 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1053 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1054 | masm->isolate()), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1055 | 5, |
| 1056 | 1); |
| 1057 | } |
| 1058 | |
| 1059 | |
| 1060 | // Prepare for a type transition runtime call when the args are already on |
| 1061 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1062 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1063 | __ pop(ecx); // Save return address. |
| 1064 | // Left and right arguments are already on top of the stack. |
| 1065 | // Push this stub's key. Although the operation and the type info are |
| 1066 | // encoded into the key, the encoding is opaque, so push them too. |
| 1067 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
| 1068 | __ push(Immediate(Smi::FromInt(op_))); |
| 1069 | __ push(Immediate(Smi::FromInt(operands_type_))); |
| 1070 | |
| 1071 | __ push(ecx); // Push return address. |
| 1072 | |
| 1073 | // Patch the caller to an appropriate specialized stub and return the |
| 1074 | // operation result to the caller of the stub. |
| 1075 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1076 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1077 | masm->isolate()), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1078 | 5, |
| 1079 | 1); |
| 1080 | } |
| 1081 | |
| 1082 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1083 | void BinaryOpStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1084 | // Explicitly allow generation of nested stubs. It is safe here because |
| 1085 | // generation code does not use any raw pointers. |
| 1086 | AllowStubCallsScope allow_stub_calls(masm, true); |
| 1087 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1088 | switch (operands_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1089 | case BinaryOpIC::UNINITIALIZED: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1090 | GenerateTypeTransition(masm); |
| 1091 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1092 | case BinaryOpIC::SMI: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1093 | GenerateSmiStub(masm); |
| 1094 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1095 | case BinaryOpIC::INT32: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1096 | GenerateInt32Stub(masm); |
| 1097 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1098 | case BinaryOpIC::HEAP_NUMBER: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1099 | GenerateHeapNumberStub(masm); |
| 1100 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1101 | case BinaryOpIC::ODDBALL: |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1102 | GenerateOddballStub(masm); |
| 1103 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1104 | case BinaryOpIC::BOTH_STRING: |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1105 | GenerateBothStringStub(masm); |
| 1106 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1107 | case BinaryOpIC::STRING: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1108 | GenerateStringStub(masm); |
| 1109 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1110 | case BinaryOpIC::GENERIC: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1111 | GenerateGeneric(masm); |
| 1112 | break; |
| 1113 | default: |
| 1114 | UNREACHABLE(); |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1119 | void BinaryOpStub::PrintName(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1120 | const char* op_name = Token::Name(op_); |
| 1121 | const char* overwrite_name; |
| 1122 | switch (mode_) { |
| 1123 | case NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 1124 | case OVERWRITE_RIGHT: overwrite_name = "OverwriteRight"; break; |
| 1125 | case OVERWRITE_LEFT: overwrite_name = "OverwriteLeft"; break; |
| 1126 | default: overwrite_name = "UnknownOverwrite"; break; |
| 1127 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1128 | stream->Add("BinaryOpStub_%s_%s_%s", |
| 1129 | op_name, |
| 1130 | overwrite_name, |
| 1131 | BinaryOpIC::GetName(operands_type_)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1135 | void BinaryOpStub::GenerateSmiCode( |
| 1136 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1137 | Label* slow, |
| 1138 | SmiCodeGenerateHeapNumberResults allow_heapnumber_results) { |
| 1139 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 1140 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 1141 | Comment load_comment(masm, "-- Load arguments"); |
| 1142 | Register left = edx; |
| 1143 | Register right = eax; |
| 1144 | if (op_ == Token::DIV || op_ == Token::MOD) { |
| 1145 | left = eax; |
| 1146 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1147 | __ mov(ebx, eax); |
| 1148 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | |
| 1152 | // 2. Prepare the smi check of both operands by oring them together. |
| 1153 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 1154 | Label not_smis; |
| 1155 | Register combined = ecx; |
| 1156 | ASSERT(!left.is(combined) && !right.is(combined)); |
| 1157 | switch (op_) { |
| 1158 | case Token::BIT_OR: |
| 1159 | // Perform the operation into eax and smi check the result. Preserve |
| 1160 | // eax in case the result is not a smi. |
| 1161 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1162 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1163 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1164 | combined = right; |
| 1165 | break; |
| 1166 | |
| 1167 | case Token::BIT_XOR: |
| 1168 | case Token::BIT_AND: |
| 1169 | case Token::ADD: |
| 1170 | case Token::SUB: |
| 1171 | case Token::MUL: |
| 1172 | case Token::DIV: |
| 1173 | case Token::MOD: |
| 1174 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1175 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1176 | break; |
| 1177 | |
| 1178 | case Token::SHL: |
| 1179 | case Token::SAR: |
| 1180 | case Token::SHR: |
| 1181 | // Move the right operand into ecx for the shift operation, use eax |
| 1182 | // for the smi check register. |
| 1183 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1184 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1185 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1186 | combined = right; |
| 1187 | break; |
| 1188 | |
| 1189 | default: |
| 1190 | break; |
| 1191 | } |
| 1192 | |
| 1193 | // 3. Perform the smi check of the operands. |
| 1194 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1195 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1196 | |
| 1197 | // 4. Operands are both smis, perform the operation leaving the result in |
| 1198 | // eax and check the result if necessary. |
| 1199 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 1200 | Label use_fp_on_smis; |
| 1201 | switch (op_) { |
| 1202 | case Token::BIT_OR: |
| 1203 | // Nothing to do. |
| 1204 | break; |
| 1205 | |
| 1206 | case Token::BIT_XOR: |
| 1207 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1208 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1209 | break; |
| 1210 | |
| 1211 | case Token::BIT_AND: |
| 1212 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1213 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1214 | break; |
| 1215 | |
| 1216 | case Token::SHL: |
| 1217 | // Remove tags from operands (but keep sign). |
| 1218 | __ SmiUntag(left); |
| 1219 | __ SmiUntag(ecx); |
| 1220 | // Perform the operation. |
| 1221 | __ shl_cl(left); |
| 1222 | // Check that the *signed* result fits in a smi. |
| 1223 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1224 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1225 | // Tag the result and store it in register eax. |
| 1226 | __ SmiTag(left); |
| 1227 | __ mov(eax, left); |
| 1228 | break; |
| 1229 | |
| 1230 | case Token::SAR: |
| 1231 | // Remove tags from operands (but keep sign). |
| 1232 | __ SmiUntag(left); |
| 1233 | __ SmiUntag(ecx); |
| 1234 | // Perform the operation. |
| 1235 | __ sar_cl(left); |
| 1236 | // Tag the result and store it in register eax. |
| 1237 | __ SmiTag(left); |
| 1238 | __ mov(eax, left); |
| 1239 | break; |
| 1240 | |
| 1241 | case Token::SHR: |
| 1242 | // Remove tags from operands (but keep sign). |
| 1243 | __ SmiUntag(left); |
| 1244 | __ SmiUntag(ecx); |
| 1245 | // Perform the operation. |
| 1246 | __ shr_cl(left); |
| 1247 | // Check that the *unsigned* result fits in a smi. |
| 1248 | // Neither of the two high-order bits can be set: |
| 1249 | // - 0x80000000: high bit would be lost when smi tagging. |
| 1250 | // - 0x40000000: this number would convert to negative when |
| 1251 | // Smi tagging these two cases can only happen with shifts |
| 1252 | // by 0 or 1 when handed a valid smi. |
| 1253 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1254 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1255 | // Tag the result and store it in register eax. |
| 1256 | __ SmiTag(left); |
| 1257 | __ mov(eax, left); |
| 1258 | break; |
| 1259 | |
| 1260 | case Token::ADD: |
| 1261 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1262 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1263 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1264 | break; |
| 1265 | |
| 1266 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1267 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1268 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1269 | __ mov(eax, left); |
| 1270 | break; |
| 1271 | |
| 1272 | case Token::MUL: |
| 1273 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 1274 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 1275 | // We can't revert the multiplication if the result is not a smi |
| 1276 | // so save the right operand. |
| 1277 | __ mov(ebx, right); |
| 1278 | // Remove tag from one of the operands (but keep sign). |
| 1279 | __ SmiUntag(right); |
| 1280 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1281 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1282 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1283 | // Check for negative zero result. Use combined = left | right. |
| 1284 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 1285 | break; |
| 1286 | |
| 1287 | case Token::DIV: |
| 1288 | // We can't revert the division if the result is not a smi so |
| 1289 | // save the left operand. |
| 1290 | __ mov(edi, left); |
| 1291 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1292 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1293 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1294 | // Sign extend left into edx:eax. |
| 1295 | ASSERT(left.is(eax)); |
| 1296 | __ cdq(); |
| 1297 | // Divide edx:eax by right. |
| 1298 | __ idiv(right); |
| 1299 | // Check for the corner case of dividing the most negative smi by |
| 1300 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1301 | // instruction. |
| 1302 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1303 | __ cmp(eax, 0x40000000); |
| 1304 | __ j(equal, &use_fp_on_smis); |
| 1305 | // Check for negative zero result. Use combined = left | right. |
| 1306 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1307 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1308 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1309 | __ j(not_zero, &use_fp_on_smis); |
| 1310 | // Tag the result and store it in register eax. |
| 1311 | __ SmiTag(eax); |
| 1312 | break; |
| 1313 | |
| 1314 | case Token::MOD: |
| 1315 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1316 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1317 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1318 | |
| 1319 | // Sign extend left into edx:eax. |
| 1320 | ASSERT(left.is(eax)); |
| 1321 | __ cdq(); |
| 1322 | // Divide edx:eax by right. |
| 1323 | __ idiv(right); |
| 1324 | // Check for negative zero result. Use combined = left | right. |
| 1325 | __ NegativeZeroTest(edx, combined, slow); |
| 1326 | // Move remainder to register eax. |
| 1327 | __ mov(eax, edx); |
| 1328 | break; |
| 1329 | |
| 1330 | default: |
| 1331 | UNREACHABLE(); |
| 1332 | } |
| 1333 | |
| 1334 | // 5. Emit return of result in eax. Some operations have registers pushed. |
| 1335 | switch (op_) { |
| 1336 | case Token::ADD: |
| 1337 | case Token::SUB: |
| 1338 | case Token::MUL: |
| 1339 | case Token::DIV: |
| 1340 | __ ret(0); |
| 1341 | break; |
| 1342 | case Token::MOD: |
| 1343 | case Token::BIT_OR: |
| 1344 | case Token::BIT_AND: |
| 1345 | case Token::BIT_XOR: |
| 1346 | case Token::SAR: |
| 1347 | case Token::SHL: |
| 1348 | case Token::SHR: |
| 1349 | __ ret(2 * kPointerSize); |
| 1350 | break; |
| 1351 | default: |
| 1352 | UNREACHABLE(); |
| 1353 | } |
| 1354 | |
| 1355 | // 6. For some operations emit inline code to perform floating point |
| 1356 | // operations on known smis (e.g., if the result of the operation |
| 1357 | // overflowed the smi range). |
| 1358 | if (allow_heapnumber_results == NO_HEAPNUMBER_RESULTS) { |
| 1359 | __ bind(&use_fp_on_smis); |
| 1360 | switch (op_) { |
| 1361 | // Undo the effects of some operations, and some register moves. |
| 1362 | case Token::SHL: |
| 1363 | // The arguments are saved on the stack, and only used from there. |
| 1364 | break; |
| 1365 | case Token::ADD: |
| 1366 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1367 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1368 | break; |
| 1369 | case Token::SUB: |
| 1370 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1371 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1372 | break; |
| 1373 | case Token::MUL: |
| 1374 | // Right was clobbered but a copy is in ebx. |
| 1375 | __ mov(right, ebx); |
| 1376 | break; |
| 1377 | case Token::DIV: |
| 1378 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1379 | // division. They should be in eax, ebx for jump to not_smi. |
| 1380 | __ mov(eax, edi); |
| 1381 | break; |
| 1382 | default: |
| 1383 | // No other operators jump to use_fp_on_smis. |
| 1384 | break; |
| 1385 | } |
| 1386 | __ jmp(¬_smis); |
| 1387 | } else { |
| 1388 | ASSERT(allow_heapnumber_results == ALLOW_HEAPNUMBER_RESULTS); |
| 1389 | switch (op_) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1390 | case Token::SHL: |
| 1391 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1392 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1393 | __ bind(&use_fp_on_smis); |
| 1394 | // Result we want is in left == edx, so we can put the allocated heap |
| 1395 | // number in eax. |
| 1396 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1397 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1398 | // It's OK to overwrite the arguments on the stack because we |
| 1399 | // are about to return. |
| 1400 | if (op_ == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1401 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1402 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1403 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1404 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1405 | } else { |
| 1406 | ASSERT_EQ(Token::SHL, op_); |
| 1407 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1408 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1409 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1410 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1411 | } else { |
| 1412 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1413 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1414 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1415 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1416 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1417 | __ ret(2 * kPointerSize); |
| 1418 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | case Token::ADD: |
| 1422 | case Token::SUB: |
| 1423 | case Token::MUL: |
| 1424 | case Token::DIV: { |
| 1425 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1426 | __ bind(&use_fp_on_smis); |
| 1427 | // Restore arguments to edx, eax. |
| 1428 | switch (op_) { |
| 1429 | case Token::ADD: |
| 1430 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1431 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1432 | break; |
| 1433 | case Token::SUB: |
| 1434 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1435 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1436 | break; |
| 1437 | case Token::MUL: |
| 1438 | // Right was clobbered but a copy is in ebx. |
| 1439 | __ mov(right, ebx); |
| 1440 | break; |
| 1441 | case Token::DIV: |
| 1442 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1443 | // division. |
| 1444 | __ mov(edx, edi); |
| 1445 | __ mov(eax, right); |
| 1446 | break; |
| 1447 | default: UNREACHABLE(); |
| 1448 | break; |
| 1449 | } |
| 1450 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1451 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1452 | CpuFeatures::Scope use_sse2(SSE2); |
| 1453 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
| 1454 | switch (op_) { |
| 1455 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1456 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1457 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1458 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1459 | default: UNREACHABLE(); |
| 1460 | } |
| 1461 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1462 | } else { // SSE2 not available, use FPU. |
| 1463 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
| 1464 | switch (op_) { |
| 1465 | case Token::ADD: __ faddp(1); break; |
| 1466 | case Token::SUB: __ fsubp(1); break; |
| 1467 | case Token::MUL: __ fmulp(1); break; |
| 1468 | case Token::DIV: __ fdivp(1); break; |
| 1469 | default: UNREACHABLE(); |
| 1470 | } |
| 1471 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1472 | } |
| 1473 | __ mov(eax, ecx); |
| 1474 | __ ret(0); |
| 1475 | break; |
| 1476 | } |
| 1477 | |
| 1478 | default: |
| 1479 | break; |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1484 | // edx and eax. |
| 1485 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1486 | __ bind(¬_smis); |
| 1487 | switch (op_) { |
| 1488 | case Token::BIT_OR: |
| 1489 | case Token::SHL: |
| 1490 | case Token::SAR: |
| 1491 | case Token::SHR: |
| 1492 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1493 | // check. |
| 1494 | __ mov(eax, ecx); |
| 1495 | break; |
| 1496 | |
| 1497 | case Token::DIV: |
| 1498 | case Token::MOD: |
| 1499 | // Operands are in eax, ebx at this point. |
| 1500 | __ mov(edx, eax); |
| 1501 | __ mov(eax, ebx); |
| 1502 | break; |
| 1503 | |
| 1504 | default: |
| 1505 | break; |
| 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1510 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1511 | Label call_runtime; |
| 1512 | |
| 1513 | switch (op_) { |
| 1514 | case Token::ADD: |
| 1515 | case Token::SUB: |
| 1516 | case Token::MUL: |
| 1517 | case Token::DIV: |
| 1518 | break; |
| 1519 | case Token::MOD: |
| 1520 | case Token::BIT_OR: |
| 1521 | case Token::BIT_AND: |
| 1522 | case Token::BIT_XOR: |
| 1523 | case Token::SAR: |
| 1524 | case Token::SHL: |
| 1525 | case Token::SHR: |
| 1526 | GenerateRegisterArgsPush(masm); |
| 1527 | break; |
| 1528 | default: |
| 1529 | UNREACHABLE(); |
| 1530 | } |
| 1531 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1532 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1533 | result_type_ == BinaryOpIC::SMI) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1534 | GenerateSmiCode(masm, &call_runtime, NO_HEAPNUMBER_RESULTS); |
| 1535 | } else { |
| 1536 | GenerateSmiCode(masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS); |
| 1537 | } |
| 1538 | __ bind(&call_runtime); |
| 1539 | switch (op_) { |
| 1540 | case Token::ADD: |
| 1541 | case Token::SUB: |
| 1542 | case Token::MUL: |
| 1543 | case Token::DIV: |
| 1544 | GenerateTypeTransition(masm); |
| 1545 | break; |
| 1546 | case Token::MOD: |
| 1547 | case Token::BIT_OR: |
| 1548 | case Token::BIT_AND: |
| 1549 | case Token::BIT_XOR: |
| 1550 | case Token::SAR: |
| 1551 | case Token::SHL: |
| 1552 | case Token::SHR: |
| 1553 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1554 | break; |
| 1555 | default: |
| 1556 | UNREACHABLE(); |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1561 | void BinaryOpStub::GenerateStringStub(MacroAssembler* masm) { |
| 1562 | ASSERT(operands_type_ == BinaryOpIC::STRING); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1563 | ASSERT(op_ == Token::ADD); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1564 | // Try to add arguments as strings, otherwise, transition to the generic |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1565 | // BinaryOpIC type. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1566 | GenerateAddStrings(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1567 | GenerateTypeTransition(masm); |
| 1568 | } |
| 1569 | |
| 1570 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1571 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1572 | Label call_runtime; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1573 | ASSERT(operands_type_ == BinaryOpIC::BOTH_STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1574 | ASSERT(op_ == Token::ADD); |
| 1575 | // If both arguments are strings, call the string add stub. |
| 1576 | // Otherwise, do a transition. |
| 1577 | |
| 1578 | // Registers containing left and right operands respectively. |
| 1579 | Register left = edx; |
| 1580 | Register right = eax; |
| 1581 | |
| 1582 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1583 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1584 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1585 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1586 | |
| 1587 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1588 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1589 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1590 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1591 | |
| 1592 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 1593 | GenerateRegisterArgsPush(masm); |
| 1594 | __ TailCallStub(&string_add_stub); |
| 1595 | |
| 1596 | __ bind(&call_runtime); |
| 1597 | GenerateTypeTransition(masm); |
| 1598 | } |
| 1599 | |
| 1600 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1601 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1602 | Label call_runtime; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1603 | ASSERT(operands_type_ == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1604 | |
| 1605 | // Floating point case. |
| 1606 | switch (op_) { |
| 1607 | case Token::ADD: |
| 1608 | case Token::SUB: |
| 1609 | case Token::MUL: |
| 1610 | case Token::DIV: { |
| 1611 | Label not_floats; |
| 1612 | Label not_int32; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1613 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1614 | CpuFeatures::Scope use_sse2(SSE2); |
| 1615 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1616 | FloatingPointHelper::CheckSSE2OperandsAreInt32(masm, ¬_int32, ecx); |
| 1617 | switch (op_) { |
| 1618 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1619 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1620 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1621 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1622 | default: UNREACHABLE(); |
| 1623 | } |
| 1624 | // Check result type if it is currently Int32. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1625 | if (result_type_ <= BinaryOpIC::INT32) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1626 | __ cvttsd2si(ecx, Operand(xmm0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1627 | __ cvtsi2sd(xmm2, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1628 | __ ucomisd(xmm0, xmm2); |
| 1629 | __ j(not_zero, ¬_int32); |
| 1630 | __ j(carry, ¬_int32); |
| 1631 | } |
| 1632 | GenerateHeapResultAllocation(masm, &call_runtime); |
| 1633 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1634 | __ ret(0); |
| 1635 | } else { // SSE2 not available, use FPU. |
| 1636 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1637 | FloatingPointHelper::LoadFloatOperands( |
| 1638 | masm, |
| 1639 | ecx, |
| 1640 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1641 | FloatingPointHelper::CheckFloatOperandsAreInt32(masm, ¬_int32); |
| 1642 | switch (op_) { |
| 1643 | case Token::ADD: __ faddp(1); break; |
| 1644 | case Token::SUB: __ fsubp(1); break; |
| 1645 | case Token::MUL: __ fmulp(1); break; |
| 1646 | case Token::DIV: __ fdivp(1); break; |
| 1647 | default: UNREACHABLE(); |
| 1648 | } |
| 1649 | Label after_alloc_failure; |
| 1650 | GenerateHeapResultAllocation(masm, &after_alloc_failure); |
| 1651 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1652 | __ ret(0); |
| 1653 | __ bind(&after_alloc_failure); |
| 1654 | __ ffree(); |
| 1655 | __ jmp(&call_runtime); |
| 1656 | } |
| 1657 | |
| 1658 | __ bind(¬_floats); |
| 1659 | __ bind(¬_int32); |
| 1660 | GenerateTypeTransition(masm); |
| 1661 | break; |
| 1662 | } |
| 1663 | |
| 1664 | case Token::MOD: { |
| 1665 | // For MOD we go directly to runtime in the non-smi case. |
| 1666 | break; |
| 1667 | } |
| 1668 | case Token::BIT_OR: |
| 1669 | case Token::BIT_AND: |
| 1670 | case Token::BIT_XOR: |
| 1671 | case Token::SAR: |
| 1672 | case Token::SHL: |
| 1673 | case Token::SHR: { |
| 1674 | GenerateRegisterArgsPush(masm); |
| 1675 | Label not_floats; |
| 1676 | Label not_int32; |
| 1677 | Label non_smi_result; |
| 1678 | /* { |
| 1679 | CpuFeatures::Scope use_sse2(SSE2); |
| 1680 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1681 | FloatingPointHelper::CheckSSE2OperandsAreInt32(masm, ¬_int32, ecx); |
| 1682 | }*/ |
| 1683 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
| 1684 | use_sse3_, |
| 1685 | ¬_floats); |
| 1686 | FloatingPointHelper::CheckLoadedIntegersWereInt32(masm, use_sse3_, |
| 1687 | ¬_int32); |
| 1688 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1689 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1690 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1691 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1692 | case Token::SAR: __ sar_cl(eax); break; |
| 1693 | case Token::SHL: __ shl_cl(eax); break; |
| 1694 | case Token::SHR: __ shr_cl(eax); break; |
| 1695 | default: UNREACHABLE(); |
| 1696 | } |
| 1697 | if (op_ == Token::SHR) { |
| 1698 | // Check if result is non-negative and fits in a smi. |
| 1699 | __ test(eax, Immediate(0xc0000000)); |
| 1700 | __ j(not_zero, &call_runtime); |
| 1701 | } else { |
| 1702 | // Check if result fits in a smi. |
| 1703 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1704 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1705 | } |
| 1706 | // Tag smi result and return. |
| 1707 | __ SmiTag(eax); |
| 1708 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1709 | |
| 1710 | // All ops except SHR return a signed int32 that we load in |
| 1711 | // a HeapNumber. |
| 1712 | if (op_ != Token::SHR) { |
| 1713 | __ bind(&non_smi_result); |
| 1714 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1715 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1716 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1717 | switch (mode_) { |
| 1718 | case OVERWRITE_LEFT: |
| 1719 | case OVERWRITE_RIGHT: |
| 1720 | // If the operand was an object, we skip the |
| 1721 | // allocation of a heap number. |
| 1722 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1723 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1724 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1725 | // Fall through! |
| 1726 | case NO_OVERWRITE: |
| 1727 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1728 | __ bind(&skip_allocation); |
| 1729 | break; |
| 1730 | default: UNREACHABLE(); |
| 1731 | } |
| 1732 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1733 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1734 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1735 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1736 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1737 | } else { |
| 1738 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1739 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1740 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1741 | } |
| 1742 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1743 | } |
| 1744 | |
| 1745 | __ bind(¬_floats); |
| 1746 | __ bind(¬_int32); |
| 1747 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1748 | break; |
| 1749 | } |
| 1750 | default: UNREACHABLE(); break; |
| 1751 | } |
| 1752 | |
| 1753 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 1754 | // use the runtime system to get the correct result. |
| 1755 | __ bind(&call_runtime); |
| 1756 | |
| 1757 | switch (op_) { |
| 1758 | case Token::ADD: |
| 1759 | GenerateRegisterArgsPush(masm); |
| 1760 | __ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION); |
| 1761 | break; |
| 1762 | case Token::SUB: |
| 1763 | GenerateRegisterArgsPush(masm); |
| 1764 | __ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION); |
| 1765 | break; |
| 1766 | case Token::MUL: |
| 1767 | GenerateRegisterArgsPush(masm); |
| 1768 | __ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION); |
| 1769 | break; |
| 1770 | case Token::DIV: |
| 1771 | GenerateRegisterArgsPush(masm); |
| 1772 | __ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION); |
| 1773 | break; |
| 1774 | case Token::MOD: |
| 1775 | GenerateRegisterArgsPush(masm); |
| 1776 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1777 | break; |
| 1778 | case Token::BIT_OR: |
| 1779 | __ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION); |
| 1780 | break; |
| 1781 | case Token::BIT_AND: |
| 1782 | __ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION); |
| 1783 | break; |
| 1784 | case Token::BIT_XOR: |
| 1785 | __ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION); |
| 1786 | break; |
| 1787 | case Token::SAR: |
| 1788 | __ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION); |
| 1789 | break; |
| 1790 | case Token::SHL: |
| 1791 | __ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION); |
| 1792 | break; |
| 1793 | case Token::SHR: |
| 1794 | __ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION); |
| 1795 | break; |
| 1796 | default: |
| 1797 | UNREACHABLE(); |
| 1798 | } |
| 1799 | } |
| 1800 | |
| 1801 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1802 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1803 | if (op_ == Token::ADD) { |
| 1804 | // Handle string addition here, because it is the only operation |
| 1805 | // that does not do a ToNumber conversion on the operands. |
| 1806 | GenerateAddStrings(masm); |
| 1807 | } |
| 1808 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1809 | Factory* factory = masm->isolate()->factory(); |
| 1810 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1811 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1812 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1813 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1814 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1815 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1816 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1817 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1818 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1819 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1820 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1821 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1822 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1823 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1824 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1825 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1826 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1827 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1828 | } |
| 1829 | __ bind(&done); |
| 1830 | |
| 1831 | GenerateHeapNumberStub(masm); |
| 1832 | } |
| 1833 | |
| 1834 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1835 | void BinaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1836 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1837 | |
| 1838 | // Floating point case. |
| 1839 | switch (op_) { |
| 1840 | case Token::ADD: |
| 1841 | case Token::SUB: |
| 1842 | case Token::MUL: |
| 1843 | case Token::DIV: { |
| 1844 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1845 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1846 | CpuFeatures::Scope use_sse2(SSE2); |
| 1847 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1848 | |
| 1849 | switch (op_) { |
| 1850 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1851 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1852 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1853 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1854 | default: UNREACHABLE(); |
| 1855 | } |
| 1856 | GenerateHeapResultAllocation(masm, &call_runtime); |
| 1857 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1858 | __ ret(0); |
| 1859 | } else { // SSE2 not available, use FPU. |
| 1860 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1861 | FloatingPointHelper::LoadFloatOperands( |
| 1862 | masm, |
| 1863 | ecx, |
| 1864 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1865 | switch (op_) { |
| 1866 | case Token::ADD: __ faddp(1); break; |
| 1867 | case Token::SUB: __ fsubp(1); break; |
| 1868 | case Token::MUL: __ fmulp(1); break; |
| 1869 | case Token::DIV: __ fdivp(1); break; |
| 1870 | default: UNREACHABLE(); |
| 1871 | } |
| 1872 | Label after_alloc_failure; |
| 1873 | GenerateHeapResultAllocation(masm, &after_alloc_failure); |
| 1874 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1875 | __ ret(0); |
| 1876 | __ bind(&after_alloc_failure); |
| 1877 | __ ffree(); |
| 1878 | __ jmp(&call_runtime); |
| 1879 | } |
| 1880 | |
| 1881 | __ bind(¬_floats); |
| 1882 | GenerateTypeTransition(masm); |
| 1883 | break; |
| 1884 | } |
| 1885 | |
| 1886 | case Token::MOD: { |
| 1887 | // For MOD we go directly to runtime in the non-smi case. |
| 1888 | break; |
| 1889 | } |
| 1890 | case Token::BIT_OR: |
| 1891 | case Token::BIT_AND: |
| 1892 | case Token::BIT_XOR: |
| 1893 | case Token::SAR: |
| 1894 | case Token::SHL: |
| 1895 | case Token::SHR: { |
| 1896 | GenerateRegisterArgsPush(masm); |
| 1897 | Label not_floats; |
| 1898 | Label non_smi_result; |
| 1899 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
| 1900 | use_sse3_, |
| 1901 | ¬_floats); |
| 1902 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1903 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1904 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1905 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1906 | case Token::SAR: __ sar_cl(eax); break; |
| 1907 | case Token::SHL: __ shl_cl(eax); break; |
| 1908 | case Token::SHR: __ shr_cl(eax); break; |
| 1909 | default: UNREACHABLE(); |
| 1910 | } |
| 1911 | if (op_ == Token::SHR) { |
| 1912 | // Check if result is non-negative and fits in a smi. |
| 1913 | __ test(eax, Immediate(0xc0000000)); |
| 1914 | __ j(not_zero, &call_runtime); |
| 1915 | } else { |
| 1916 | // Check if result fits in a smi. |
| 1917 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1918 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1919 | } |
| 1920 | // Tag smi result and return. |
| 1921 | __ SmiTag(eax); |
| 1922 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1923 | |
| 1924 | // All ops except SHR return a signed int32 that we load in |
| 1925 | // a HeapNumber. |
| 1926 | if (op_ != Token::SHR) { |
| 1927 | __ bind(&non_smi_result); |
| 1928 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1929 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1930 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1931 | switch (mode_) { |
| 1932 | case OVERWRITE_LEFT: |
| 1933 | case OVERWRITE_RIGHT: |
| 1934 | // If the operand was an object, we skip the |
| 1935 | // allocation of a heap number. |
| 1936 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1937 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1938 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1939 | // Fall through! |
| 1940 | case NO_OVERWRITE: |
| 1941 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1942 | __ bind(&skip_allocation); |
| 1943 | break; |
| 1944 | default: UNREACHABLE(); |
| 1945 | } |
| 1946 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1947 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1948 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1949 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1950 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1951 | } else { |
| 1952 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1953 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1954 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1955 | } |
| 1956 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1957 | } |
| 1958 | |
| 1959 | __ bind(¬_floats); |
| 1960 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1961 | break; |
| 1962 | } |
| 1963 | default: UNREACHABLE(); break; |
| 1964 | } |
| 1965 | |
| 1966 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 1967 | // use the runtime system to get the correct result. |
| 1968 | __ bind(&call_runtime); |
| 1969 | |
| 1970 | switch (op_) { |
| 1971 | case Token::ADD: |
| 1972 | GenerateRegisterArgsPush(masm); |
| 1973 | __ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION); |
| 1974 | break; |
| 1975 | case Token::SUB: |
| 1976 | GenerateRegisterArgsPush(masm); |
| 1977 | __ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION); |
| 1978 | break; |
| 1979 | case Token::MUL: |
| 1980 | GenerateRegisterArgsPush(masm); |
| 1981 | __ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION); |
| 1982 | break; |
| 1983 | case Token::DIV: |
| 1984 | GenerateRegisterArgsPush(masm); |
| 1985 | __ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION); |
| 1986 | break; |
| 1987 | case Token::MOD: |
| 1988 | GenerateRegisterArgsPush(masm); |
| 1989 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1990 | break; |
| 1991 | case Token::BIT_OR: |
| 1992 | __ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION); |
| 1993 | break; |
| 1994 | case Token::BIT_AND: |
| 1995 | __ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION); |
| 1996 | break; |
| 1997 | case Token::BIT_XOR: |
| 1998 | __ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION); |
| 1999 | break; |
| 2000 | case Token::SAR: |
| 2001 | __ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION); |
| 2002 | break; |
| 2003 | case Token::SHL: |
| 2004 | __ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION); |
| 2005 | break; |
| 2006 | case Token::SHR: |
| 2007 | __ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION); |
| 2008 | break; |
| 2009 | default: |
| 2010 | UNREACHABLE(); |
| 2011 | } |
| 2012 | } |
| 2013 | |
| 2014 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2015 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2016 | Label call_runtime; |
| 2017 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2018 | Counters* counters = masm->isolate()->counters(); |
| 2019 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2020 | |
| 2021 | switch (op_) { |
| 2022 | case Token::ADD: |
| 2023 | case Token::SUB: |
| 2024 | case Token::MUL: |
| 2025 | case Token::DIV: |
| 2026 | break; |
| 2027 | case Token::MOD: |
| 2028 | case Token::BIT_OR: |
| 2029 | case Token::BIT_AND: |
| 2030 | case Token::BIT_XOR: |
| 2031 | case Token::SAR: |
| 2032 | case Token::SHL: |
| 2033 | case Token::SHR: |
| 2034 | GenerateRegisterArgsPush(masm); |
| 2035 | break; |
| 2036 | default: |
| 2037 | UNREACHABLE(); |
| 2038 | } |
| 2039 | |
| 2040 | GenerateSmiCode(masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS); |
| 2041 | |
| 2042 | // Floating point case. |
| 2043 | switch (op_) { |
| 2044 | case Token::ADD: |
| 2045 | case Token::SUB: |
| 2046 | case Token::MUL: |
| 2047 | case Token::DIV: { |
| 2048 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2049 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2050 | CpuFeatures::Scope use_sse2(SSE2); |
| 2051 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 2052 | |
| 2053 | switch (op_) { |
| 2054 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2055 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2056 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2057 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2058 | default: UNREACHABLE(); |
| 2059 | } |
| 2060 | GenerateHeapResultAllocation(masm, &call_runtime); |
| 2061 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2062 | __ ret(0); |
| 2063 | } else { // SSE2 not available, use FPU. |
| 2064 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2065 | FloatingPointHelper::LoadFloatOperands( |
| 2066 | masm, |
| 2067 | ecx, |
| 2068 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2069 | switch (op_) { |
| 2070 | case Token::ADD: __ faddp(1); break; |
| 2071 | case Token::SUB: __ fsubp(1); break; |
| 2072 | case Token::MUL: __ fmulp(1); break; |
| 2073 | case Token::DIV: __ fdivp(1); break; |
| 2074 | default: UNREACHABLE(); |
| 2075 | } |
| 2076 | Label after_alloc_failure; |
| 2077 | GenerateHeapResultAllocation(masm, &after_alloc_failure); |
| 2078 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2079 | __ ret(0); |
| 2080 | __ bind(&after_alloc_failure); |
| 2081 | __ ffree(); |
| 2082 | __ jmp(&call_runtime); |
| 2083 | } |
| 2084 | __ bind(¬_floats); |
| 2085 | break; |
| 2086 | } |
| 2087 | case Token::MOD: { |
| 2088 | // For MOD we go directly to runtime in the non-smi case. |
| 2089 | break; |
| 2090 | } |
| 2091 | case Token::BIT_OR: |
| 2092 | case Token::BIT_AND: |
| 2093 | case Token::BIT_XOR: |
| 2094 | case Token::SAR: |
| 2095 | case Token::SHL: |
| 2096 | case Token::SHR: { |
| 2097 | Label non_smi_result; |
| 2098 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
| 2099 | use_sse3_, |
| 2100 | &call_runtime); |
| 2101 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2102 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2103 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2104 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2105 | case Token::SAR: __ sar_cl(eax); break; |
| 2106 | case Token::SHL: __ shl_cl(eax); break; |
| 2107 | case Token::SHR: __ shr_cl(eax); break; |
| 2108 | default: UNREACHABLE(); |
| 2109 | } |
| 2110 | if (op_ == Token::SHR) { |
| 2111 | // Check if result is non-negative and fits in a smi. |
| 2112 | __ test(eax, Immediate(0xc0000000)); |
| 2113 | __ j(not_zero, &call_runtime); |
| 2114 | } else { |
| 2115 | // Check if result fits in a smi. |
| 2116 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2117 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2118 | } |
| 2119 | // Tag smi result and return. |
| 2120 | __ SmiTag(eax); |
| 2121 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 2122 | |
| 2123 | // All ops except SHR return a signed int32 that we load in |
| 2124 | // a HeapNumber. |
| 2125 | if (op_ != Token::SHR) { |
| 2126 | __ bind(&non_smi_result); |
| 2127 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2128 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2129 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2130 | switch (mode_) { |
| 2131 | case OVERWRITE_LEFT: |
| 2132 | case OVERWRITE_RIGHT: |
| 2133 | // If the operand was an object, we skip the |
| 2134 | // allocation of a heap number. |
| 2135 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2136 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2137 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2138 | // Fall through! |
| 2139 | case NO_OVERWRITE: |
| 2140 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2141 | __ bind(&skip_allocation); |
| 2142 | break; |
| 2143 | default: UNREACHABLE(); |
| 2144 | } |
| 2145 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2146 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2147 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2148 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2149 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2150 | } else { |
| 2151 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2152 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2153 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2154 | } |
| 2155 | __ ret(2 * kPointerSize); |
| 2156 | } |
| 2157 | break; |
| 2158 | } |
| 2159 | default: UNREACHABLE(); break; |
| 2160 | } |
| 2161 | |
| 2162 | // If all else fails, use the runtime system to get the correct |
| 2163 | // result. |
| 2164 | __ bind(&call_runtime); |
| 2165 | switch (op_) { |
| 2166 | case Token::ADD: { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2167 | GenerateAddStrings(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2168 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2169 | __ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION); |
| 2170 | break; |
| 2171 | } |
| 2172 | case Token::SUB: |
| 2173 | GenerateRegisterArgsPush(masm); |
| 2174 | __ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION); |
| 2175 | break; |
| 2176 | case Token::MUL: |
| 2177 | GenerateRegisterArgsPush(masm); |
| 2178 | __ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION); |
| 2179 | break; |
| 2180 | case Token::DIV: |
| 2181 | GenerateRegisterArgsPush(masm); |
| 2182 | __ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION); |
| 2183 | break; |
| 2184 | case Token::MOD: |
| 2185 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 2186 | break; |
| 2187 | case Token::BIT_OR: |
| 2188 | __ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION); |
| 2189 | break; |
| 2190 | case Token::BIT_AND: |
| 2191 | __ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION); |
| 2192 | break; |
| 2193 | case Token::BIT_XOR: |
| 2194 | __ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION); |
| 2195 | break; |
| 2196 | case Token::SAR: |
| 2197 | __ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION); |
| 2198 | break; |
| 2199 | case Token::SHL: |
| 2200 | __ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION); |
| 2201 | break; |
| 2202 | case Token::SHR: |
| 2203 | __ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION); |
| 2204 | break; |
| 2205 | default: |
| 2206 | UNREACHABLE(); |
| 2207 | } |
| 2208 | } |
| 2209 | |
| 2210 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2211 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2212 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2213 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2214 | |
| 2215 | // Registers containing left and right operands respectively. |
| 2216 | Register left = edx; |
| 2217 | Register right = eax; |
| 2218 | |
| 2219 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2220 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2221 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2222 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2223 | |
| 2224 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 2225 | GenerateRegisterArgsPush(masm); |
| 2226 | __ TailCallStub(&string_add_left_stub); |
| 2227 | |
| 2228 | // Left operand is not a string, test right. |
| 2229 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2230 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2231 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2232 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2233 | |
| 2234 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
| 2235 | GenerateRegisterArgsPush(masm); |
| 2236 | __ TailCallStub(&string_add_right_stub); |
| 2237 | |
| 2238 | // Neither argument is a string. |
| 2239 | __ bind(&call_runtime); |
| 2240 | } |
| 2241 | |
| 2242 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2243 | void BinaryOpStub::GenerateHeapResultAllocation( |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2244 | MacroAssembler* masm, |
| 2245 | Label* alloc_failure) { |
| 2246 | Label skip_allocation; |
| 2247 | OverwriteMode mode = mode_; |
| 2248 | switch (mode) { |
| 2249 | case OVERWRITE_LEFT: { |
| 2250 | // If the argument in edx is already an object, we skip the |
| 2251 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2252 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2253 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2254 | // for the possible runtime call. |
| 2255 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2256 | // Now edx can be overwritten losing one of the arguments as we are |
| 2257 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2258 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2259 | __ bind(&skip_allocation); |
| 2260 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2261 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2262 | break; |
| 2263 | } |
| 2264 | case OVERWRITE_RIGHT: |
| 2265 | // If the argument in eax is already an object, we skip the |
| 2266 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2267 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2268 | // Fall through! |
| 2269 | case NO_OVERWRITE: |
| 2270 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2271 | // for the possible runtime call. |
| 2272 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2273 | // Now eax can be overwritten losing one of the arguments as we are |
| 2274 | // now done and will not need it any more. |
| 2275 | __ mov(eax, ebx); |
| 2276 | __ bind(&skip_allocation); |
| 2277 | break; |
| 2278 | default: UNREACHABLE(); |
| 2279 | } |
| 2280 | } |
| 2281 | |
| 2282 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2283 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2284 | __ pop(ecx); |
| 2285 | __ push(edx); |
| 2286 | __ push(eax); |
| 2287 | __ push(ecx); |
| 2288 | } |
| 2289 | |
| 2290 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2291 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2292 | // TAGGED case: |
| 2293 | // Input: |
| 2294 | // esp[4]: tagged number input argument (should be number). |
| 2295 | // esp[0]: return address. |
| 2296 | // Output: |
| 2297 | // eax: tagged double result. |
| 2298 | // UNTAGGED case: |
| 2299 | // Input:: |
| 2300 | // esp[0]: return address. |
| 2301 | // xmm1: untagged double input argument |
| 2302 | // Output: |
| 2303 | // xmm1: untagged double result. |
| 2304 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2305 | Label runtime_call; |
| 2306 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2307 | Label skip_cache; |
| 2308 | const bool tagged = (argument_type_ == TAGGED); |
| 2309 | if (tagged) { |
| 2310 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2311 | Label input_not_smi; |
| 2312 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2313 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2314 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2315 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2316 | // Then load the low and high words of the double into ebx, edx. |
| 2317 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2318 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2319 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2320 | __ mov(Operand(esp, 0), eax); |
| 2321 | __ fild_s(Operand(esp, 0)); |
| 2322 | __ fst_d(Operand(esp, 0)); |
| 2323 | __ pop(edx); |
| 2324 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2325 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2326 | __ bind(&input_not_smi); |
| 2327 | // Check if input is a HeapNumber. |
| 2328 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2329 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2330 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2331 | __ j(not_equal, &runtime_call); |
| 2332 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2333 | // low and high words into ebx, edx. |
| 2334 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2335 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2336 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2337 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2338 | __ bind(&loaded); |
| 2339 | } else { // UNTAGGED. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2340 | if (CpuFeatures::IsSupported(SSE4_1)) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2341 | CpuFeatures::Scope sse4_scope(SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2342 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2343 | } else { |
| 2344 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2345 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2346 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2347 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2351 | // ebx = low 32 bits of double value |
| 2352 | // edx = high 32 bits of double value |
| 2353 | // Compute hash (the shifts are arithmetic): |
| 2354 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2355 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2356 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2357 | __ mov(eax, ecx); |
| 2358 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2359 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2360 | __ mov(eax, ecx); |
| 2361 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2362 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2363 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2364 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2365 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2366 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2367 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2368 | // ebx = low 32 bits of double value. |
| 2369 | // edx = high 32 bits of double value. |
| 2370 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2371 | ExternalReference cache_array = |
| 2372 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2373 | __ mov(eax, Immediate(cache_array)); |
| 2374 | int cache_array_index = |
| 2375 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2376 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2377 | // Eax points to the cache for the type type_. |
| 2378 | // 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] | 2379 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2380 | __ j(zero, &runtime_call_clear_stack); |
| 2381 | #ifdef DEBUG |
| 2382 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2383 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2384 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2385 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2386 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2387 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2388 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2389 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2390 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2391 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2392 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2393 | } |
| 2394 | #endif |
| 2395 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2396 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2397 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2398 | // 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] | 2399 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2400 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2401 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2402 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2403 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2404 | // Cache hit! |
| 2405 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2406 | if (tagged) { |
| 2407 | __ fstp(0); |
| 2408 | __ ret(kPointerSize); |
| 2409 | } else { // UNTAGGED. |
| 2410 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2411 | __ Ret(); |
| 2412 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2413 | |
| 2414 | __ bind(&cache_miss); |
| 2415 | // Update cache with new value. |
| 2416 | // We are short on registers, so use no_reg as scratch. |
| 2417 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2418 | if (tagged) { |
| 2419 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2420 | } else { // UNTAGGED. |
| 2421 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2422 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2423 | __ movdbl(Operand(esp, 0), xmm1); |
| 2424 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2425 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2426 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2427 | GenerateOperation(masm); |
| 2428 | __ mov(Operand(ecx, 0), ebx); |
| 2429 | __ mov(Operand(ecx, kIntSize), edx); |
| 2430 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2431 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2432 | if (tagged) { |
| 2433 | __ ret(kPointerSize); |
| 2434 | } else { // UNTAGGED. |
| 2435 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2436 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2437 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2438 | // Skip cache and return answer directly, only in untagged case. |
| 2439 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2440 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2441 | __ movdbl(Operand(esp, 0), xmm1); |
| 2442 | __ fld_d(Operand(esp, 0)); |
| 2443 | GenerateOperation(masm); |
| 2444 | __ fstp_d(Operand(esp, 0)); |
| 2445 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2446 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2447 | // We return the value in xmm1 without adding it to the cache, but |
| 2448 | // 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] | 2449 | { |
| 2450 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2451 | // Allocate an unused object bigger than a HeapNumber. |
| 2452 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2453 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2454 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2455 | __ Ret(); |
| 2456 | } |
| 2457 | |
| 2458 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2459 | if (tagged) { |
| 2460 | __ bind(&runtime_call_clear_stack); |
| 2461 | __ fstp(0); |
| 2462 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2463 | ExternalReference runtime = |
| 2464 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2465 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2466 | } else { // UNTAGGED. |
| 2467 | __ bind(&runtime_call_clear_stack); |
| 2468 | __ bind(&runtime_call); |
| 2469 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2470 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2471 | { |
| 2472 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2473 | __ push(eax); |
| 2474 | __ CallRuntime(RuntimeFunction(), 1); |
| 2475 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2476 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2477 | __ Ret(); |
| 2478 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | |
| 2482 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2483 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2484 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2485 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2486 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2487 | default: |
| 2488 | UNIMPLEMENTED(); |
| 2489 | return Runtime::kAbort; |
| 2490 | } |
| 2491 | } |
| 2492 | |
| 2493 | |
| 2494 | void TranscendentalCacheStub::GenerateOperation(MacroAssembler* masm) { |
| 2495 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2496 | // Input value is on FP stack, and also in ebx/edx. |
| 2497 | // Input value is possibly in xmm1. |
| 2498 | // Address of result (a newly allocated HeapNumber) may be in eax. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2499 | if (type_ == TranscendentalCache::SIN || type_ == TranscendentalCache::COS) { |
| 2500 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2501 | // return NaN for infinities and NaN. They can share all code except |
| 2502 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2503 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2504 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2505 | // work. We must reduce it to the appropriate range. |
| 2506 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2507 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2508 | int supported_exponent_limit = |
| 2509 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2510 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2511 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2512 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2513 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2514 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2515 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2516 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2517 | __ fstp(0); |
| 2518 | // NaN is represented by 0x7ff8000000000000. |
| 2519 | __ push(Immediate(0x7ff80000)); |
| 2520 | __ push(Immediate(0)); |
| 2521 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2522 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2523 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2524 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2525 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2526 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2527 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2528 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2529 | __ fldpi(); |
| 2530 | __ fadd(0); |
| 2531 | __ fld(1); |
| 2532 | // FPU Stack: input, 2*pi, input. |
| 2533 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2534 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2535 | __ fwait(); |
| 2536 | __ fnstsw_ax(); |
| 2537 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2538 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2539 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2540 | __ fnclex(); |
| 2541 | __ bind(&no_exceptions); |
| 2542 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2543 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2544 | // Compute st(0) % st(1) |
| 2545 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2546 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2547 | __ bind(&partial_remainder_loop); |
| 2548 | __ fprem1(); |
| 2549 | __ fwait(); |
| 2550 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2551 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2552 | // If C2 is set, computation only has partial result. Loop to |
| 2553 | // continue computation. |
| 2554 | __ j(not_zero, &partial_remainder_loop); |
| 2555 | } |
| 2556 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2557 | __ fstp(2); |
| 2558 | __ fstp(0); |
| 2559 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2560 | |
| 2561 | // FPU Stack: input % 2*pi |
| 2562 | __ bind(&in_range); |
| 2563 | switch (type_) { |
| 2564 | case TranscendentalCache::SIN: |
| 2565 | __ fsin(); |
| 2566 | break; |
| 2567 | case TranscendentalCache::COS: |
| 2568 | __ fcos(); |
| 2569 | break; |
| 2570 | default: |
| 2571 | UNREACHABLE(); |
| 2572 | } |
| 2573 | __ bind(&done); |
| 2574 | } else { |
| 2575 | ASSERT(type_ == TranscendentalCache::LOG); |
| 2576 | __ fldln2(); |
| 2577 | __ fxch(); |
| 2578 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2579 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2583 | // Input: edx, eax are the left and right objects of a bit op. |
| 2584 | // 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] | 2585 | void FloatingPointHelper::LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 2586 | bool use_sse3, |
| 2587 | Label* conversion_failure) { |
| 2588 | // Check float operands. |
| 2589 | Label arg1_is_object, check_undefined_arg1; |
| 2590 | Label arg2_is_object, check_undefined_arg2; |
| 2591 | Label load_arg2, done; |
| 2592 | |
| 2593 | // Test if arg1 is a Smi. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2594 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2595 | |
| 2596 | __ SmiUntag(edx); |
| 2597 | __ jmp(&load_arg2); |
| 2598 | |
| 2599 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2600 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2601 | Factory* factory = masm->isolate()->factory(); |
| 2602 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2603 | __ j(not_equal, conversion_failure); |
| 2604 | __ mov(edx, Immediate(0)); |
| 2605 | __ jmp(&load_arg2); |
| 2606 | |
| 2607 | __ bind(&arg1_is_object); |
| 2608 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2609 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2610 | __ j(not_equal, &check_undefined_arg1); |
| 2611 | |
| 2612 | // 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] | 2613 | IntegerConvert(masm, edx, use_sse3, conversion_failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2614 | __ mov(edx, ecx); |
| 2615 | |
| 2616 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2617 | __ bind(&load_arg2); |
| 2618 | |
| 2619 | // Test if arg2 is a Smi. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2620 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2621 | |
| 2622 | __ SmiUntag(eax); |
| 2623 | __ mov(ecx, eax); |
| 2624 | __ jmp(&done); |
| 2625 | |
| 2626 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2627 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2628 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2629 | __ j(not_equal, conversion_failure); |
| 2630 | __ mov(ecx, Immediate(0)); |
| 2631 | __ jmp(&done); |
| 2632 | |
| 2633 | __ bind(&arg2_is_object); |
| 2634 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2635 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2636 | __ j(not_equal, &check_undefined_arg2); |
| 2637 | |
| 2638 | // 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] | 2639 | IntegerConvert(masm, eax, use_sse3, conversion_failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2640 | __ bind(&done); |
| 2641 | __ mov(eax, edx); |
| 2642 | } |
| 2643 | |
| 2644 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2645 | void FloatingPointHelper::CheckLoadedIntegersWereInt32(MacroAssembler* masm, |
| 2646 | bool use_sse3, |
| 2647 | Label* not_int32) { |
| 2648 | return; |
| 2649 | } |
| 2650 | |
| 2651 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2652 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2653 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2654 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2655 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2656 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2657 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2658 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2659 | |
| 2660 | __ bind(&load_smi); |
| 2661 | __ SmiUntag(number); |
| 2662 | __ push(number); |
| 2663 | __ fild_s(Operand(esp, 0)); |
| 2664 | __ pop(number); |
| 2665 | |
| 2666 | __ bind(&done); |
| 2667 | } |
| 2668 | |
| 2669 | |
| 2670 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2671 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2672 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2673 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2674 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2675 | |
| 2676 | __ bind(&load_eax); |
| 2677 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2678 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2679 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2680 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2681 | |
| 2682 | __ bind(&load_smi_edx); |
| 2683 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2684 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2685 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2686 | __ jmp(&load_eax); |
| 2687 | |
| 2688 | __ bind(&load_smi_eax); |
| 2689 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2690 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2691 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2692 | |
| 2693 | __ bind(&done); |
| 2694 | } |
| 2695 | |
| 2696 | |
| 2697 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2698 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2699 | 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] | 2700 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2701 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2702 | Factory* factory = masm->isolate()->factory(); |
| 2703 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2704 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2705 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2706 | __ bind(&load_eax); |
| 2707 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2708 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2709 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2710 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2711 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2712 | __ bind(&load_smi_edx); |
| 2713 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2714 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2715 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2716 | __ jmp(&load_eax); |
| 2717 | __ bind(&load_smi_eax); |
| 2718 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2719 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2720 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2721 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2722 | __ bind(&load_float_eax); |
| 2723 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2724 | __ bind(&done); |
| 2725 | } |
| 2726 | |
| 2727 | |
| 2728 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2729 | Register scratch) { |
| 2730 | const Register left = edx; |
| 2731 | const Register right = eax; |
| 2732 | __ mov(scratch, left); |
| 2733 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2734 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2735 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2736 | |
| 2737 | __ mov(scratch, right); |
| 2738 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2739 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2740 | } |
| 2741 | |
| 2742 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2743 | void FloatingPointHelper::CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 2744 | Label* non_int32, |
| 2745 | Register scratch) { |
| 2746 | __ cvttsd2si(scratch, Operand(xmm0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2747 | __ cvtsi2sd(xmm2, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2748 | __ ucomisd(xmm0, xmm2); |
| 2749 | __ j(not_zero, non_int32); |
| 2750 | __ j(carry, non_int32); |
| 2751 | __ cvttsd2si(scratch, Operand(xmm1)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2752 | __ cvtsi2sd(xmm2, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2753 | __ ucomisd(xmm1, xmm2); |
| 2754 | __ j(not_zero, non_int32); |
| 2755 | __ j(carry, non_int32); |
| 2756 | } |
| 2757 | |
| 2758 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2759 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2760 | Register scratch, |
| 2761 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2762 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2763 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2764 | __ mov(scratch, edx); |
| 2765 | } else { |
| 2766 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2767 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2768 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2769 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2770 | __ bind(&done_load_1); |
| 2771 | |
| 2772 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2773 | __ mov(scratch, eax); |
| 2774 | } else { |
| 2775 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2776 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2777 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2778 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2779 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2780 | |
| 2781 | __ bind(&load_smi_1); |
| 2782 | __ SmiUntag(scratch); |
| 2783 | __ push(scratch); |
| 2784 | __ fild_s(Operand(esp, 0)); |
| 2785 | __ pop(scratch); |
| 2786 | __ jmp(&done_load_1); |
| 2787 | |
| 2788 | __ bind(&load_smi_2); |
| 2789 | __ SmiUntag(scratch); |
| 2790 | __ push(scratch); |
| 2791 | __ fild_s(Operand(esp, 0)); |
| 2792 | __ pop(scratch); |
| 2793 | |
| 2794 | __ bind(&done); |
| 2795 | } |
| 2796 | |
| 2797 | |
| 2798 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2799 | Register scratch) { |
| 2800 | const Register left = edx; |
| 2801 | const Register right = eax; |
| 2802 | __ mov(scratch, left); |
| 2803 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2804 | __ SmiUntag(scratch); |
| 2805 | __ push(scratch); |
| 2806 | __ fild_s(Operand(esp, 0)); |
| 2807 | |
| 2808 | __ mov(scratch, right); |
| 2809 | __ SmiUntag(scratch); |
| 2810 | __ mov(Operand(esp, 0), scratch); |
| 2811 | __ fild_s(Operand(esp, 0)); |
| 2812 | __ pop(scratch); |
| 2813 | } |
| 2814 | |
| 2815 | |
| 2816 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2817 | Label* non_float, |
| 2818 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2819 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2820 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 2821 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2822 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2823 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2824 | Factory* factory = masm->isolate()->factory(); |
| 2825 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2826 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 2827 | |
| 2828 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2829 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2830 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2831 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2832 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 2833 | |
| 2834 | // Fall-through: Both operands are numbers. |
| 2835 | __ bind(&done); |
| 2836 | } |
| 2837 | |
| 2838 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2839 | void FloatingPointHelper::CheckFloatOperandsAreInt32(MacroAssembler* masm, |
| 2840 | Label* non_int32) { |
| 2841 | return; |
| 2842 | } |
| 2843 | |
| 2844 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2845 | void MathPowStub::Generate(MacroAssembler* masm) { |
| 2846 | // Registers are used as follows: |
| 2847 | // edx = base |
| 2848 | // eax = exponent |
| 2849 | // ecx = temporary, result |
| 2850 | |
| 2851 | CpuFeatures::Scope use_sse2(SSE2); |
| 2852 | Label allocate_return, call_runtime; |
| 2853 | |
| 2854 | // Load input parameters. |
| 2855 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 2856 | __ mov(eax, Operand(esp, 1 * kPointerSize)); |
| 2857 | |
| 2858 | // Save 1 in xmm3 - we need this several times later on. |
| 2859 | __ mov(ecx, Immediate(1)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2860 | __ cvtsi2sd(xmm3, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2861 | |
| 2862 | Label exponent_nonsmi; |
| 2863 | Label base_nonsmi; |
| 2864 | // If the exponent is a heap number go to that specific case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2865 | __ JumpIfNotSmi(eax, &exponent_nonsmi); |
| 2866 | __ JumpIfNotSmi(edx, &base_nonsmi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2867 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2868 | // Optimized version when both exponent and base are smis. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2869 | Label powi; |
| 2870 | __ SmiUntag(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2871 | __ cvtsi2sd(xmm0, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2872 | __ jmp(&powi); |
| 2873 | // exponent is smi and base is a heapnumber. |
| 2874 | __ bind(&base_nonsmi); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2875 | Factory* factory = masm->isolate()->factory(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2876 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2877 | factory->heap_number_map()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2878 | __ j(not_equal, &call_runtime); |
| 2879 | |
| 2880 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2881 | |
| 2882 | // Optimized version of pow if exponent is a smi. |
| 2883 | // xmm0 contains the base. |
| 2884 | __ bind(&powi); |
| 2885 | __ SmiUntag(eax); |
| 2886 | |
| 2887 | // Save exponent in base as we need to check if exponent is negative later. |
| 2888 | // We know that base and exponent are in different registers. |
| 2889 | __ mov(edx, eax); |
| 2890 | |
| 2891 | // Get absolute value of exponent. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2892 | Label no_neg; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2893 | __ cmp(eax, 0); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2894 | __ j(greater_equal, &no_neg, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2895 | __ neg(eax); |
| 2896 | __ bind(&no_neg); |
| 2897 | |
| 2898 | // Load xmm1 with 1. |
| 2899 | __ movsd(xmm1, xmm3); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2900 | Label while_true; |
| 2901 | Label no_multiply; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2902 | |
| 2903 | __ bind(&while_true); |
| 2904 | __ shr(eax, 1); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2905 | __ j(not_carry, &no_multiply, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2906 | __ mulsd(xmm1, xmm0); |
| 2907 | __ bind(&no_multiply); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2908 | __ mulsd(xmm0, xmm0); |
| 2909 | __ j(not_zero, &while_true); |
| 2910 | |
| 2911 | // base has the original value of the exponent - if the exponent is |
| 2912 | // negative return 1/result. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2913 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2914 | __ j(positive, &allocate_return); |
| 2915 | // Special case if xmm1 has reached infinity. |
| 2916 | __ mov(ecx, Immediate(0x7FB00000)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2917 | __ movd(xmm0, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2918 | __ cvtss2sd(xmm0, xmm0); |
| 2919 | __ ucomisd(xmm0, xmm1); |
| 2920 | __ j(equal, &call_runtime); |
| 2921 | __ divsd(xmm3, xmm1); |
| 2922 | __ movsd(xmm1, xmm3); |
| 2923 | __ jmp(&allocate_return); |
| 2924 | |
| 2925 | // exponent (or both) is a heapnumber - no matter what we should now work |
| 2926 | // on doubles. |
| 2927 | __ bind(&exponent_nonsmi); |
| 2928 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2929 | factory->heap_number_map()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2930 | __ j(not_equal, &call_runtime); |
| 2931 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2932 | // Test if exponent is nan. |
| 2933 | __ ucomisd(xmm1, xmm1); |
| 2934 | __ j(parity_even, &call_runtime); |
| 2935 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2936 | Label base_not_smi; |
| 2937 | Label handle_special_cases; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2938 | __ JumpIfNotSmi(edx, &base_not_smi, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2939 | __ SmiUntag(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2940 | __ cvtsi2sd(xmm0, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2941 | __ jmp(&handle_special_cases, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2942 | |
| 2943 | __ bind(&base_not_smi); |
| 2944 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2945 | factory->heap_number_map()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2946 | __ j(not_equal, &call_runtime); |
| 2947 | __ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 2948 | __ and_(ecx, HeapNumber::kExponentMask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2949 | __ cmp(ecx, Immediate(HeapNumber::kExponentMask)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2950 | // base is NaN or +/-Infinity |
| 2951 | __ j(greater_equal, &call_runtime); |
| 2952 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2953 | |
| 2954 | // base is in xmm0 and exponent is in xmm1. |
| 2955 | __ bind(&handle_special_cases); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2956 | Label not_minus_half; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2957 | // Test for -0.5. |
| 2958 | // Load xmm2 with -0.5. |
| 2959 | __ mov(ecx, Immediate(0xBF000000)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2960 | __ movd(xmm2, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2961 | __ cvtss2sd(xmm2, xmm2); |
| 2962 | // xmm2 now has -0.5. |
| 2963 | __ ucomisd(xmm2, xmm1); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2964 | __ j(not_equal, ¬_minus_half, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2965 | |
| 2966 | // Calculates reciprocal of square root. |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2967 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2968 | __ xorps(xmm1, xmm1); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2969 | __ addsd(xmm1, xmm0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2970 | __ sqrtsd(xmm1, xmm1); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2971 | __ divsd(xmm3, xmm1); |
| 2972 | __ movsd(xmm1, xmm3); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2973 | __ jmp(&allocate_return); |
| 2974 | |
| 2975 | // Test for 0.5. |
| 2976 | __ bind(¬_minus_half); |
| 2977 | // Load xmm2 with 0.5. |
| 2978 | // Since xmm3 is 1 and xmm2 is -0.5 this is simply xmm2 + xmm3. |
| 2979 | __ addsd(xmm2, xmm3); |
| 2980 | // xmm2 now has 0.5. |
| 2981 | __ ucomisd(xmm2, xmm1); |
| 2982 | __ j(not_equal, &call_runtime); |
| 2983 | // Calculates square root. |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2984 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2985 | __ xorps(xmm1, xmm1); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2986 | __ addsd(xmm1, xmm0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2987 | __ sqrtsd(xmm1, xmm1); |
| 2988 | |
| 2989 | __ bind(&allocate_return); |
| 2990 | __ AllocateHeapNumber(ecx, eax, edx, &call_runtime); |
| 2991 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm1); |
| 2992 | __ mov(eax, ecx); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2993 | __ ret(2 * kPointerSize); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2994 | |
| 2995 | __ bind(&call_runtime); |
| 2996 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
| 2997 | } |
| 2998 | |
| 2999 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3000 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3001 | // The key is in edx and the parameter count is in eax. |
| 3002 | |
| 3003 | // The displacement is used for skipping the frame pointer on the |
| 3004 | // stack. It is the offset of the last parameter (if any) relative |
| 3005 | // to the frame pointer. |
| 3006 | static const int kDisplacement = 1 * kPointerSize; |
| 3007 | |
| 3008 | // Check that the key is a smi. |
| 3009 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3010 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3011 | |
| 3012 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3013 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3014 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3015 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3016 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3017 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3018 | |
| 3019 | // Check index against formal parameters count limit passed in |
| 3020 | // through register eax. Use unsigned comparison to get negative |
| 3021 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3022 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3023 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3024 | |
| 3025 | // Read the argument from the stack and return it. |
| 3026 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3027 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3028 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3029 | __ neg(edx); |
| 3030 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3031 | __ ret(0); |
| 3032 | |
| 3033 | // Arguments adaptor case: Check index against actual arguments |
| 3034 | // limit found in the arguments adaptor frame. Use unsigned |
| 3035 | // comparison to get negative check for free. |
| 3036 | __ bind(&adaptor); |
| 3037 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3038 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3039 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3040 | |
| 3041 | // Read the argument from the stack and return it. |
| 3042 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3043 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3044 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3045 | __ neg(edx); |
| 3046 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3047 | __ ret(0); |
| 3048 | |
| 3049 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3050 | // by calling the runtime system. |
| 3051 | __ bind(&slow); |
| 3052 | __ pop(ebx); // Return address. |
| 3053 | __ push(edx); |
| 3054 | __ push(ebx); |
| 3055 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3056 | } |
| 3057 | |
| 3058 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3059 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3060 | // esp[0] : return address |
| 3061 | // esp[4] : number of parameters |
| 3062 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3063 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3064 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3065 | // Check if the calling frame is an arguments adaptor frame. |
| 3066 | Label runtime; |
| 3067 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3068 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3069 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3070 | __ j(not_equal, &runtime, Label::kNear); |
| 3071 | |
| 3072 | // Patch the arguments.length and the parameters pointer. |
| 3073 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3074 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3075 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3076 | StandardFrameConstants::kCallerSPOffset)); |
| 3077 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3078 | |
| 3079 | __ bind(&runtime); |
| 3080 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3081 | } |
| 3082 | |
| 3083 | |
| 3084 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 3085 | // esp[0] : return address |
| 3086 | // esp[4] : number of parameters (tagged) |
| 3087 | // esp[8] : receiver displacement |
| 3088 | // esp[12] : function |
| 3089 | |
| 3090 | // ebx = parameter count (tagged) |
| 3091 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3092 | |
| 3093 | // Check if the calling frame is an arguments adaptor frame. |
| 3094 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3095 | // Generate* functions. |
| 3096 | Label runtime; |
| 3097 | Label adaptor_frame, try_allocate; |
| 3098 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3099 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3100 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3101 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3102 | |
| 3103 | // No adaptor, parameter count = argument count. |
| 3104 | __ mov(ecx, ebx); |
| 3105 | __ jmp(&try_allocate, Label::kNear); |
| 3106 | |
| 3107 | // We have an adaptor frame. Patch the parameters pointer. |
| 3108 | __ bind(&adaptor_frame); |
| 3109 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3110 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3111 | StandardFrameConstants::kCallerSPOffset)); |
| 3112 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3113 | |
| 3114 | // ebx = parameter count (tagged) |
| 3115 | // ecx = argument count (tagged) |
| 3116 | // esp[4] = parameter count (tagged) |
| 3117 | // esp[8] = address of receiver argument |
| 3118 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3119 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3120 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3121 | __ mov(ebx, ecx); |
| 3122 | |
| 3123 | __ bind(&try_allocate); |
| 3124 | |
| 3125 | // Save mapped parameter count. |
| 3126 | __ push(ebx); |
| 3127 | |
| 3128 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3129 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3130 | const int kParameterMapHeaderSize = |
| 3131 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3132 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3133 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3134 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3135 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3136 | __ bind(&no_parameter_map); |
| 3137 | |
| 3138 | // 2. Backing store. |
| 3139 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3140 | |
| 3141 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3142 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3143 | |
| 3144 | // Do the allocation of all three objects in one go. |
| 3145 | __ AllocateInNewSpace(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
| 3146 | |
| 3147 | // eax = address of new object(s) (tagged) |
| 3148 | // ecx = argument count (tagged) |
| 3149 | // esp[0] = mapped parameter count (tagged) |
| 3150 | // esp[8] = parameter count (tagged) |
| 3151 | // esp[12] = address of receiver argument |
| 3152 | // Get the arguments boilerplate from the current (global) context into edi. |
| 3153 | Label has_mapped_parameters, copy; |
| 3154 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 3155 | __ mov(edi, FieldOperand(edi, GlobalObject::kGlobalContextOffset)); |
| 3156 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3157 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3158 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3159 | __ mov(edi, Operand(edi, |
| 3160 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3161 | __ jmp(©, Label::kNear); |
| 3162 | |
| 3163 | __ bind(&has_mapped_parameters); |
| 3164 | __ mov(edi, Operand(edi, |
| 3165 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3166 | __ bind(©); |
| 3167 | |
| 3168 | // eax = address of new object (tagged) |
| 3169 | // ebx = mapped parameter count (tagged) |
| 3170 | // ecx = argument count (tagged) |
| 3171 | // edi = address of boilerplate object (tagged) |
| 3172 | // esp[0] = mapped parameter count (tagged) |
| 3173 | // esp[8] = parameter count (tagged) |
| 3174 | // esp[12] = address of receiver argument |
| 3175 | // Copy the JS object part. |
| 3176 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3177 | __ mov(edx, FieldOperand(edi, i)); |
| 3178 | __ mov(FieldOperand(eax, i), edx); |
| 3179 | } |
| 3180 | |
| 3181 | // Setup the callee in-object property. |
| 3182 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3183 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3184 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3185 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3186 | edx); |
| 3187 | |
| 3188 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3189 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3190 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3191 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3192 | ecx); |
| 3193 | |
| 3194 | // Setup the elements pointer in the allocated arguments object. |
| 3195 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3196 | // backing store. |
| 3197 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3198 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3199 | |
| 3200 | // eax = address of new object (tagged) |
| 3201 | // ebx = mapped parameter count (tagged) |
| 3202 | // ecx = argument count (tagged) |
| 3203 | // edi = address of parameter map or backing store (tagged) |
| 3204 | // esp[0] = mapped parameter count (tagged) |
| 3205 | // esp[8] = parameter count (tagged) |
| 3206 | // esp[12] = address of receiver argument |
| 3207 | // Free a register. |
| 3208 | __ push(eax); |
| 3209 | |
| 3210 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3211 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3212 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3213 | __ j(zero, &skip_parameter_map); |
| 3214 | |
| 3215 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3216 | Immediate(FACTORY->non_strict_arguments_elements_map())); |
| 3217 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3218 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3219 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3220 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3221 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3222 | |
| 3223 | // Copy the parameter slots and the holes in the arguments. |
| 3224 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3225 | // where parameters are stored in reverse order, at |
| 3226 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3227 | // The mapped parameter thus need to get indices |
| 3228 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3229 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3230 | // We loop from right to left. |
| 3231 | Label parameters_loop, parameters_test; |
| 3232 | __ push(ecx); |
| 3233 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3234 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3235 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3236 | __ sub(ebx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3237 | __ mov(ecx, FACTORY->the_hole_value()); |
| 3238 | __ mov(edx, edi); |
| 3239 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3240 | // eax = loop variable (tagged) |
| 3241 | // ebx = mapping index (tagged) |
| 3242 | // ecx = the hole value |
| 3243 | // edx = address of parameter map (tagged) |
| 3244 | // edi = address of backing store (tagged) |
| 3245 | // esp[0] = argument count (tagged) |
| 3246 | // esp[4] = address of new object (tagged) |
| 3247 | // esp[8] = mapped parameter count (tagged) |
| 3248 | // esp[16] = parameter count (tagged) |
| 3249 | // esp[20] = address of receiver argument |
| 3250 | __ jmp(¶meters_test, Label::kNear); |
| 3251 | |
| 3252 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3253 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3254 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3255 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3256 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3257 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3258 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3259 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3260 | __ pop(ecx); |
| 3261 | |
| 3262 | __ bind(&skip_parameter_map); |
| 3263 | |
| 3264 | // ecx = argument count (tagged) |
| 3265 | // edi = address of backing store (tagged) |
| 3266 | // esp[0] = address of new object (tagged) |
| 3267 | // esp[4] = mapped parameter count (tagged) |
| 3268 | // esp[12] = parameter count (tagged) |
| 3269 | // esp[16] = address of receiver argument |
| 3270 | // Copy arguments header and remaining slots (if there are any). |
| 3271 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3272 | Immediate(FACTORY->fixed_array_map())); |
| 3273 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3274 | |
| 3275 | Label arguments_loop, arguments_test; |
| 3276 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3277 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3278 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3279 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3280 | __ jmp(&arguments_test, Label::kNear); |
| 3281 | |
| 3282 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3283 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3284 | __ mov(eax, Operand(edx, 0)); |
| 3285 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3286 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3287 | |
| 3288 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3289 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3290 | __ j(less, &arguments_loop, Label::kNear); |
| 3291 | |
| 3292 | // Restore. |
| 3293 | __ pop(eax); // Address of arguments object. |
| 3294 | __ pop(ebx); // Parameter count. |
| 3295 | |
| 3296 | // Return and remove the on-stack parameters. |
| 3297 | __ ret(3 * kPointerSize); |
| 3298 | |
| 3299 | // Do the runtime call to allocate the arguments object. |
| 3300 | __ bind(&runtime); |
| 3301 | __ pop(eax); // Remove saved parameter count. |
| 3302 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
| 3303 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
| 3304 | } |
| 3305 | |
| 3306 | |
| 3307 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 3308 | // esp[0] : return address |
| 3309 | // esp[4] : number of parameters |
| 3310 | // esp[8] : receiver displacement |
| 3311 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3312 | |
| 3313 | // Check if the calling frame is an arguments adaptor frame. |
| 3314 | Label adaptor_frame, try_allocate, runtime; |
| 3315 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3316 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3317 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3318 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3319 | |
| 3320 | // Get the length from the frame. |
| 3321 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3322 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3323 | |
| 3324 | // Patch the arguments.length and the parameters pointer. |
| 3325 | __ bind(&adaptor_frame); |
| 3326 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3327 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3328 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3329 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3330 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3331 | |
| 3332 | // Try the new space allocation. Start out with computing the size of |
| 3333 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3334 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3335 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3336 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3337 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3338 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3339 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3340 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3341 | |
| 3342 | // Do the allocation of both objects in one go. |
| 3343 | __ AllocateInNewSpace(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
| 3344 | |
| 3345 | // Get the arguments boilerplate from the current (global) context. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3346 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 3347 | __ mov(edi, FieldOperand(edi, GlobalObject::kGlobalContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3348 | const int offset = |
| 3349 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3350 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3351 | |
| 3352 | // Copy the JS object part. |
| 3353 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3354 | __ mov(ebx, FieldOperand(edi, i)); |
| 3355 | __ mov(FieldOperand(eax, i), ebx); |
| 3356 | } |
| 3357 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3358 | // 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] | 3359 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3360 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3361 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3362 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3363 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3364 | |
| 3365 | // If there are no actual arguments, we're done. |
| 3366 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3367 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3368 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3369 | |
| 3370 | // Get the parameters pointer from the stack. |
| 3371 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3372 | |
| 3373 | // Setup the elements pointer in the allocated arguments object and |
| 3374 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3375 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3376 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3377 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3378 | Immediate(FACTORY->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3379 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3380 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3381 | // Untag the length for the loop below. |
| 3382 | __ SmiUntag(ecx); |
| 3383 | |
| 3384 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3385 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3386 | __ bind(&loop); |
| 3387 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3388 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3389 | __ add(edi, Immediate(kPointerSize)); |
| 3390 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3391 | __ dec(ecx); |
| 3392 | __ j(not_zero, &loop); |
| 3393 | |
| 3394 | // Return and remove the on-stack parameters. |
| 3395 | __ bind(&done); |
| 3396 | __ ret(3 * kPointerSize); |
| 3397 | |
| 3398 | // Do the runtime call to allocate the arguments object. |
| 3399 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3400 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | |
| 3404 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3405 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3406 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3407 | // at compilation. |
| 3408 | #ifdef V8_INTERPRETED_REGEXP |
| 3409 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3410 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3411 | |
| 3412 | // Stack frame on entry. |
| 3413 | // esp[0]: return address |
| 3414 | // esp[4]: last_match_info (expected JSArray) |
| 3415 | // esp[8]: previous index |
| 3416 | // esp[12]: subject string |
| 3417 | // esp[16]: JSRegExp object |
| 3418 | |
| 3419 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3420 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3421 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3422 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3423 | |
| 3424 | Label runtime, invoke_regexp; |
| 3425 | |
| 3426 | // Ensure that a RegExp stack is allocated. |
| 3427 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3428 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3429 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3430 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3431 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3432 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3433 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3434 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3435 | |
| 3436 | // Check that the first argument is a JSRegExp object. |
| 3437 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3438 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3439 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3440 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3441 | __ j(not_equal, &runtime); |
| 3442 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3443 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3444 | if (FLAG_debug_code) { |
| 3445 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3446 | __ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected"); |
| 3447 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 3448 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 3449 | } |
| 3450 | |
| 3451 | // ecx: RegExp data (FixedArray) |
| 3452 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3453 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3454 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3455 | __ j(not_equal, &runtime); |
| 3456 | |
| 3457 | // ecx: RegExp data (FixedArray) |
| 3458 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3459 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3460 | // Calculate number of capture registers (number_of_captures + 1) * 2. This |
| 3461 | // uses the asumption that smis are 2 * their untagged value. |
| 3462 | STATIC_ASSERT(kSmiTag == 0); |
| 3463 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3464 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3465 | // Check that the static offsets vector buffer is large enough. |
| 3466 | __ cmp(edx, OffsetsVector::kStaticOffsetsVectorSize); |
| 3467 | __ j(above, &runtime); |
| 3468 | |
| 3469 | // ecx: RegExp data (FixedArray) |
| 3470 | // edx: Number of capture registers |
| 3471 | // Check that the second argument is a string. |
| 3472 | __ mov(eax, Operand(esp, kSubjectOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3473 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3474 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 3475 | __ j(NegateCondition(is_string), &runtime); |
| 3476 | // Get the length of the string to ebx. |
| 3477 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 3478 | |
| 3479 | // ebx: Length of subject string as a smi |
| 3480 | // ecx: RegExp data (FixedArray) |
| 3481 | // edx: Number of capture registers |
| 3482 | // Check that the third argument is a positive smi less than the subject |
| 3483 | // string length. A negative value will be greater (unsigned comparison). |
| 3484 | __ mov(eax, Operand(esp, kPreviousIndexOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3485 | __ JumpIfNotSmi(eax, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3486 | __ cmp(eax, ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3487 | __ j(above_equal, &runtime); |
| 3488 | |
| 3489 | // ecx: RegExp data (FixedArray) |
| 3490 | // edx: Number of capture registers |
| 3491 | // Check that the fourth object is a JSArray object. |
| 3492 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3493 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3494 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 3495 | __ j(not_equal, &runtime); |
| 3496 | // Check that the JSArray is in fast case. |
| 3497 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
| 3498 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3499 | Factory* factory = masm->isolate()->factory(); |
| 3500 | __ cmp(eax, factory->fixed_array_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3501 | __ j(not_equal, &runtime); |
| 3502 | // Check that the last match info has space for the capture registers and the |
| 3503 | // additional information. |
| 3504 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 3505 | __ SmiUntag(eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3506 | __ add(edx, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 3507 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3508 | __ j(greater, &runtime); |
| 3509 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3510 | // Reset offset for possibly sliced string. |
| 3511 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3512 | // ecx: RegExp data (FixedArray) |
| 3513 | // Check the representation and encoding of the subject string. |
| 3514 | Label seq_ascii_string, seq_two_byte_string, check_code; |
| 3515 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 3516 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3517 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3518 | // First check for flat two byte string. |
| 3519 | __ and_(ebx, |
| 3520 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask); |
| 3521 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3522 | __ j(zero, &seq_two_byte_string, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3523 | // Any other flat string must be a flat ascii string. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3524 | __ and_(ebx, Immediate(kIsNotStringMask | kStringRepresentationMask)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3525 | __ j(zero, &seq_ascii_string, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3526 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3527 | // Check for flat cons string or sliced string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3528 | // A flat cons string is a cons string where the second part is the empty |
| 3529 | // string. In that case the subject string is just the first part of the cons |
| 3530 | // string. Also in this case the first part of the cons string is known to be |
| 3531 | // a sequential string or an external string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3532 | // In the case of a sliced string its offset has to be taken into account. |
| 3533 | Label cons_string, check_encoding; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3534 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3535 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3536 | __ cmp(ebx, Immediate(kExternalStringTag)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3537 | __ j(less, &cons_string); |
| 3538 | __ j(equal, &runtime); |
| 3539 | |
| 3540 | // String is sliced. |
| 3541 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 3542 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 3543 | // edi: offset of sliced string, smi-tagged. |
| 3544 | // eax: parent string. |
| 3545 | __ jmp(&check_encoding, Label::kNear); |
| 3546 | // String is a cons string, check whether it is flat. |
| 3547 | __ bind(&cons_string); |
| 3548 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3549 | __ j(not_equal, &runtime); |
| 3550 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3551 | __ bind(&check_encoding); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3552 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3553 | // eax: first part of cons string or parent of sliced string. |
| 3554 | // ebx: map of first part of cons string or map of parent of sliced string. |
| 3555 | // 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] | 3556 | __ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset), |
| 3557 | kStringRepresentationMask | kStringEncodingMask); |
| 3558 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3559 | __ j(zero, &seq_two_byte_string, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3560 | // Any other flat string must be ascii. |
| 3561 | __ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset), |
| 3562 | kStringRepresentationMask); |
| 3563 | __ j(not_zero, &runtime); |
| 3564 | |
| 3565 | __ bind(&seq_ascii_string); |
| 3566 | // eax: subject string (flat ascii) |
| 3567 | // ecx: RegExp data (FixedArray) |
| 3568 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3569 | __ Set(ecx, Immediate(1)); // Type is ascii. |
| 3570 | __ jmp(&check_code, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3571 | |
| 3572 | __ bind(&seq_two_byte_string); |
| 3573 | // eax: subject string (flat two byte) |
| 3574 | // ecx: RegExp data (FixedArray) |
| 3575 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3576 | __ Set(ecx, Immediate(0)); // Type is two byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3577 | |
| 3578 | __ bind(&check_code); |
| 3579 | // Check that the irregexp code has been generated for the actual string |
| 3580 | // 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] | 3581 | // a smi (code flushing support). |
| 3582 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3583 | |
| 3584 | // eax: subject string |
| 3585 | // edx: code |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3586 | // 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] | 3587 | // Load used arguments before starting to push arguments for call to native |
| 3588 | // RegExp code to avoid handling changing stack height. |
| 3589 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3590 | __ SmiUntag(ebx); // Previous index from smi. |
| 3591 | |
| 3592 | // eax: subject string |
| 3593 | // ebx: previous index |
| 3594 | // edx: code |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3595 | // 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] | 3596 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3597 | Counters* counters = masm->isolate()->counters(); |
| 3598 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3599 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3600 | // Isolates: note we add an additional parameter here (isolate pointer). |
| 3601 | static const int kRegExpExecuteArguments = 8; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3602 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3603 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3604 | // Argument 8: Pass current isolate address. |
| 3605 | __ mov(Operand(esp, 7 * kPointerSize), |
| 3606 | Immediate(ExternalReference::isolate_address())); |
| 3607 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3608 | // Argument 7: Indicate that this is a direct call from JavaScript. |
| 3609 | __ mov(Operand(esp, 6 * kPointerSize), Immediate(1)); |
| 3610 | |
| 3611 | // Argument 6: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3612 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 3613 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
| 3614 | __ mov(Operand(esp, 5 * kPointerSize), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3615 | |
| 3616 | // Argument 5: static offsets vector buffer. |
| 3617 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3618 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 3619 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3620 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3621 | // Argument 2: Previous index. |
| 3622 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 3623 | |
| 3624 | // Argument 1: Original subject string. |
| 3625 | // The original subject is in the previous stack frame. Therefore we have to |
| 3626 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 3627 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 3628 | // and thereby moves up esp by one kPointerSize.) |
| 3629 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 3630 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 3631 | |
| 3632 | // esi: original subject string |
| 3633 | // eax: underlying subject string |
| 3634 | // ebx: previous index |
| 3635 | // ecx: encoding of subject string (1 if ascii 0 if two_byte); |
| 3636 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3637 | // Argument 4: End of string data |
| 3638 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3639 | // Prepare start and end index of the input. |
| 3640 | // Load the length from the original sliced string if that is the case. |
| 3641 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3642 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3643 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3644 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3645 | |
| 3646 | // ebx: start index of the input string |
| 3647 | // esi: end index of the input string |
| 3648 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3649 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3650 | __ j(zero, &setup_two_byte, Label::kNear); |
| 3651 | __ SmiUntag(esi); |
| 3652 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqAsciiString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3653 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3654 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqAsciiString::kHeaderSize)); |
| 3655 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3656 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3657 | |
| 3658 | __ bind(&setup_two_byte); |
| 3659 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3660 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 3661 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3662 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3663 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 3664 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 3665 | |
| 3666 | __ bind(&setup_rest); |
| 3667 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3668 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3669 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 3670 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3671 | |
| 3672 | // Drop arguments and come back to JS mode. |
| 3673 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3674 | |
| 3675 | // Check the result. |
| 3676 | Label success; |
| 3677 | __ cmp(eax, NativeRegExpMacroAssembler::SUCCESS); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3678 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3679 | Label failure; |
| 3680 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3681 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3682 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 3683 | // If not exception it can only be retry. Handle that in the runtime system. |
| 3684 | __ j(not_equal, &runtime); |
| 3685 | // Result must now be exception. If there is no pending exception already a |
| 3686 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 3687 | // haven't created the exception yet. Handle that in the runtime system. |
| 3688 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3689 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3690 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3691 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3692 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3693 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3694 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3695 | // For exception, throw the exception again. |
| 3696 | |
| 3697 | // Clear the pending exception variable. |
| 3698 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 3699 | |
| 3700 | // Special handling of termination exceptions which are uncatchable |
| 3701 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3702 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3703 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3704 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3705 | |
| 3706 | // Handle normal exception by following handler chain. |
| 3707 | __ Throw(eax); |
| 3708 | |
| 3709 | __ bind(&throw_termination_exception); |
| 3710 | __ ThrowUncatchable(TERMINATION, eax); |
| 3711 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3712 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3713 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3714 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3715 | __ ret(4 * kPointerSize); |
| 3716 | |
| 3717 | // Load RegExp data. |
| 3718 | __ bind(&success); |
| 3719 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3720 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3721 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3722 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 3723 | STATIC_ASSERT(kSmiTag == 0); |
| 3724 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3725 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3726 | |
| 3727 | // edx: Number of capture registers |
| 3728 | // Load last_match_info which is still known to be a fast case JSArray. |
| 3729 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 3730 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
| 3731 | |
| 3732 | // ebx: last_match_info backing store (FixedArray) |
| 3733 | // edx: number of capture registers |
| 3734 | // Store the capture count. |
| 3735 | __ SmiTag(edx); // Number of capture registers to smi. |
| 3736 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 3737 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 3738 | // Store last subject and last input. |
| 3739 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 3740 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3741 | __ RecordWriteField(ebx, |
| 3742 | RegExpImpl::kLastSubjectOffset, |
| 3743 | eax, |
| 3744 | edi, |
| 3745 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3746 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 3747 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3748 | __ RecordWriteField(ebx, |
| 3749 | RegExpImpl::kLastInputOffset, |
| 3750 | eax, |
| 3751 | edi, |
| 3752 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3753 | |
| 3754 | // Get the static offsets vector filled by the native regexp code. |
| 3755 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3756 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3757 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 3758 | |
| 3759 | // ebx: last_match_info backing store (FixedArray) |
| 3760 | // ecx: offsets vector |
| 3761 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3762 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3763 | // Capture register counter starts from number of capture registers and |
| 3764 | // counts down until wraping after zero. |
| 3765 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3766 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3767 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3768 | // Read the value from the static offsets vector buffer. |
| 3769 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 3770 | __ SmiTag(edi); |
| 3771 | // Store the smi value in the last match info. |
| 3772 | __ mov(FieldOperand(ebx, |
| 3773 | edx, |
| 3774 | times_pointer_size, |
| 3775 | RegExpImpl::kFirstCaptureOffset), |
| 3776 | edi); |
| 3777 | __ jmp(&next_capture); |
| 3778 | __ bind(&done); |
| 3779 | |
| 3780 | // Return last match info. |
| 3781 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 3782 | __ ret(4 * kPointerSize); |
| 3783 | |
| 3784 | // Do the runtime call to execute the regexp. |
| 3785 | __ bind(&runtime); |
| 3786 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3787 | #endif // V8_INTERPRETED_REGEXP |
| 3788 | } |
| 3789 | |
| 3790 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3791 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 3792 | const int kMaxInlineLength = 100; |
| 3793 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3794 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3795 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3796 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3797 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3798 | __ j(above, &slowcase); |
| 3799 | // Smi-tagging is equivalent to multiplying by 2. |
| 3800 | STATIC_ASSERT(kSmiTag == 0); |
| 3801 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3802 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 3803 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 3804 | // Elements: [Map][Length][..elements..] |
| 3805 | __ AllocateInNewSpace(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 3806 | times_half_pointer_size, |
| 3807 | ebx, // In: Number of elements (times 2, being a smi) |
| 3808 | eax, // Out: Start of allocation (tagged). |
| 3809 | ecx, // Out: End of allocation. |
| 3810 | edx, // Scratch register |
| 3811 | &slowcase, |
| 3812 | TAG_OBJECT); |
| 3813 | // eax: Start of allocated area, object-tagged. |
| 3814 | |
| 3815 | // Set JSArray map to global.regexp_result_map(). |
| 3816 | // Set empty properties FixedArray. |
| 3817 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 3818 | // Interleave operations for better latency. |
| 3819 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3820 | Factory* factory = masm->isolate()->factory(); |
| 3821 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3822 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
| 3823 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalContextOffset)); |
| 3824 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 3825 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 3826 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 3827 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 3828 | |
| 3829 | // Set input, index and length fields from arguments. |
| 3830 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 3831 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 3832 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 3833 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 3834 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 3835 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 3836 | |
| 3837 | // Fill out the elements FixedArray. |
| 3838 | // eax: JSArray. |
| 3839 | // ebx: FixedArray. |
| 3840 | // ecx: Number of elements in array, as smi. |
| 3841 | |
| 3842 | // Set map. |
| 3843 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3844 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3845 | // Set length. |
| 3846 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
| 3847 | // Fill contents of fixed-array with the-hole. |
| 3848 | __ SmiUntag(ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3849 | __ mov(edx, Immediate(factory->the_hole_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3850 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
| 3851 | // Fill fixed array elements with hole. |
| 3852 | // eax: JSArray. |
| 3853 | // ecx: Number of elements to fill. |
| 3854 | // ebx: Start of elements in FixedArray. |
| 3855 | // edx: the hole. |
| 3856 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3857 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3858 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3859 | __ 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] | 3860 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3861 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 3862 | __ jmp(&loop); |
| 3863 | |
| 3864 | __ bind(&done); |
| 3865 | __ ret(3 * kPointerSize); |
| 3866 | |
| 3867 | __ bind(&slowcase); |
| 3868 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 3869 | } |
| 3870 | |
| 3871 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3872 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 3873 | Register object, |
| 3874 | Register result, |
| 3875 | Register scratch1, |
| 3876 | Register scratch2, |
| 3877 | bool object_is_smi, |
| 3878 | Label* not_found) { |
| 3879 | // Use of registers. Register result is used as a temporary. |
| 3880 | Register number_string_cache = result; |
| 3881 | Register mask = scratch1; |
| 3882 | Register scratch = scratch2; |
| 3883 | |
| 3884 | // Load the number string cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3885 | ExternalReference roots_array_start = |
| 3886 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3887 | __ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex)); |
| 3888 | __ mov(number_string_cache, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3889 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3890 | // Make the hash mask from the length of the number string cache. It |
| 3891 | // contains two elements (number and string) for each cache entry. |
| 3892 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 3893 | __ 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] | 3894 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3895 | |
| 3896 | // Calculate the entry in the number string cache. The hash value in the |
| 3897 | // number string cache for smis is just the smi value, and the hash for |
| 3898 | // doubles is the xor of the upper and lower words. See |
| 3899 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3900 | Label smi_hash_calculated; |
| 3901 | Label load_result_from_cache; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3902 | if (object_is_smi) { |
| 3903 | __ mov(scratch, object); |
| 3904 | __ SmiUntag(scratch); |
| 3905 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3906 | Label not_smi; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3907 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3908 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3909 | __ mov(scratch, object); |
| 3910 | __ SmiUntag(scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3911 | __ jmp(&smi_hash_calculated, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3912 | __ bind(¬_smi); |
| 3913 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3914 | masm->isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3915 | __ j(not_equal, not_found); |
| 3916 | STATIC_ASSERT(8 == kDoubleSize); |
| 3917 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 3918 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 3919 | // 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] | 3920 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3921 | Register index = scratch; |
| 3922 | Register probe = mask; |
| 3923 | __ mov(probe, |
| 3924 | FieldOperand(number_string_cache, |
| 3925 | index, |
| 3926 | times_twice_pointer_size, |
| 3927 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3928 | __ JumpIfSmi(probe, not_found); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3929 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3930 | CpuFeatures::Scope fscope(SSE2); |
| 3931 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 3932 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 3933 | __ ucomisd(xmm0, xmm1); |
| 3934 | } else { |
| 3935 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 3936 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 3937 | __ FCmp(); |
| 3938 | } |
| 3939 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 3940 | __ 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] | 3941 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3942 | } |
| 3943 | |
| 3944 | __ bind(&smi_hash_calculated); |
| 3945 | // 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] | 3946 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3947 | Register index = scratch; |
| 3948 | // Check if the entry is the smi we are looking for. |
| 3949 | __ cmp(object, |
| 3950 | FieldOperand(number_string_cache, |
| 3951 | index, |
| 3952 | times_twice_pointer_size, |
| 3953 | FixedArray::kHeaderSize)); |
| 3954 | __ j(not_equal, not_found); |
| 3955 | |
| 3956 | // Get the result from the cache. |
| 3957 | __ bind(&load_result_from_cache); |
| 3958 | __ mov(result, |
| 3959 | FieldOperand(number_string_cache, |
| 3960 | index, |
| 3961 | times_twice_pointer_size, |
| 3962 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3963 | Counters* counters = masm->isolate()->counters(); |
| 3964 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | |
| 3968 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 3969 | Label runtime; |
| 3970 | |
| 3971 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 3972 | |
| 3973 | // Generate code to lookup number in the number string cache. |
| 3974 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, false, &runtime); |
| 3975 | __ ret(1 * kPointerSize); |
| 3976 | |
| 3977 | __ bind(&runtime); |
| 3978 | // Handle number to string in the runtime system if not found in the cache. |
| 3979 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 3980 | } |
| 3981 | |
| 3982 | |
| 3983 | static int NegativeComparisonResult(Condition cc) { |
| 3984 | ASSERT(cc != equal); |
| 3985 | ASSERT((cc == less) || (cc == less_equal) |
| 3986 | || (cc == greater) || (cc == greater_equal)); |
| 3987 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 3988 | } |
| 3989 | |
| 3990 | void CompareStub::Generate(MacroAssembler* masm) { |
| 3991 | ASSERT(lhs_.is(no_reg) && rhs_.is(no_reg)); |
| 3992 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3993 | Label check_unequal_objects; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3994 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3995 | // Compare two smis if required. |
| 3996 | if (include_smi_compare_) { |
| 3997 | Label non_smi, smi_done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3998 | __ mov(ecx, edx); |
| 3999 | __ or_(ecx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4000 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4001 | __ sub(edx, eax); // Return on the result of the subtraction. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4002 | __ j(no_overflow, &smi_done, Label::kNear); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4003 | __ 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] | 4004 | __ bind(&smi_done); |
| 4005 | __ mov(eax, edx); |
| 4006 | __ ret(0); |
| 4007 | __ bind(&non_smi); |
| 4008 | } else if (FLAG_debug_code) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4009 | __ mov(ecx, edx); |
| 4010 | __ or_(ecx, eax); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4011 | __ test(ecx, Immediate(kSmiTagMask)); |
| 4012 | __ Assert(not_zero, "Unexpected smi operands."); |
| 4013 | } |
| 4014 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4015 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4016 | // it is certain that at least one operand isn't a smi. |
| 4017 | |
| 4018 | // Identical objects can be compared fast, but there are some tricky cases |
| 4019 | // for NaN and undefined. |
| 4020 | { |
| 4021 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4022 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4023 | __ j(not_equal, ¬_identical); |
| 4024 | |
| 4025 | if (cc_ != equal) { |
| 4026 | // Check for undefined. undefined OP undefined is false even though |
| 4027 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4028 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4029 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4030 | __ j(not_equal, &check_for_nan, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4031 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc_)))); |
| 4032 | __ ret(0); |
| 4033 | __ bind(&check_for_nan); |
| 4034 | } |
| 4035 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4036 | // 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] | 4037 | // so we do the second best thing - test it ourselves. |
| 4038 | // Note: if cc_ != equal, never_nan_nan_ is not used. |
| 4039 | if (never_nan_nan_ && (cc_ == equal)) { |
| 4040 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4041 | __ ret(0); |
| 4042 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4043 | Label heap_number; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4044 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4045 | Immediate(masm->isolate()->factory()->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4046 | __ j(equal, &heap_number, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4047 | if (cc_ != equal) { |
| 4048 | // Call runtime on identical JSObjects. Otherwise return equal. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4049 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4050 | __ j(above_equal, ¬_identical); |
| 4051 | } |
| 4052 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4053 | __ ret(0); |
| 4054 | |
| 4055 | __ bind(&heap_number); |
| 4056 | // It is a heap number, so return non-equal if it's NaN and equal if |
| 4057 | // it's not NaN. |
| 4058 | // The representation of NaN values has all exponent bits (52..62) set, |
| 4059 | // and not all mantissa bits (0..51) clear. |
| 4060 | // We only accept QNaNs, which have bit 51 set. |
| 4061 | // Read top bits of double representation (second word of value). |
| 4062 | |
| 4063 | // Value is a QNaN if value & kQuietNaNMask == kQuietNaNMask, i.e., |
| 4064 | // all bits in the mask are set. We only need to check the word |
| 4065 | // that contains the exponent and high bit of the mantissa. |
| 4066 | STATIC_ASSERT(((kQuietNaNHighBitsMask << 1) & 0x80000000u) != 0); |
| 4067 | __ mov(edx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4068 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4069 | // Shift value and mask so kQuietNaNHighBitsMask applies to topmost |
| 4070 | // bits. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4071 | __ add(edx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4072 | __ cmp(edx, kQuietNaNHighBitsMask << 1); |
| 4073 | if (cc_ == equal) { |
| 4074 | STATIC_ASSERT(EQUAL != 1); |
| 4075 | __ setcc(above_equal, eax); |
| 4076 | __ ret(0); |
| 4077 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4078 | Label nan; |
| 4079 | __ j(above_equal, &nan, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4080 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4081 | __ ret(0); |
| 4082 | __ bind(&nan); |
| 4083 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc_)))); |
| 4084 | __ ret(0); |
| 4085 | } |
| 4086 | } |
| 4087 | |
| 4088 | __ bind(¬_identical); |
| 4089 | } |
| 4090 | |
| 4091 | // Strict equality can quickly decide whether objects are equal. |
| 4092 | // Non-strict object equality is slower, so it is handled later in the stub. |
| 4093 | if (cc_ == equal && strict_) { |
| 4094 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4095 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4096 | // If we're doing a strict equality comparison, we don't have to do |
| 4097 | // type conversion, so we generate code to do fast comparison for objects |
| 4098 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4099 | // slow-case code. |
| 4100 | // If either is a Smi (we know that not both are), then they can only |
| 4101 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4102 | STATIC_ASSERT(kSmiTag == 0); |
| 4103 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4104 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4105 | __ and_(ecx, eax); |
| 4106 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4107 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4108 | // One operand is a smi. |
| 4109 | |
| 4110 | // Check whether the non-smi is a heap number. |
| 4111 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4112 | // 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] | 4113 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4114 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4115 | __ xor_(ebx, eax); |
| 4116 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4117 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4118 | // if eax was smi, ebx is now edx, else eax. |
| 4119 | |
| 4120 | // Check if the non-smi operand is a heap number. |
| 4121 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4122 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4123 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4124 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4125 | // Return non-equal (ebx is not zero) |
| 4126 | __ mov(eax, ebx); |
| 4127 | __ ret(0); |
| 4128 | |
| 4129 | __ bind(¬_smis); |
| 4130 | // If either operand is a JSObject or an oddball value, then they are not |
| 4131 | // equal since their pointers are different |
| 4132 | // There is no test for undetectability in strict equality. |
| 4133 | |
| 4134 | // Get the type of the first operand. |
| 4135 | // 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] | 4136 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4137 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4138 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4139 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4140 | |
| 4141 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4142 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4143 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4144 | __ bind(&return_not_equal); |
| 4145 | __ ret(0); |
| 4146 | |
| 4147 | __ bind(&first_non_object); |
| 4148 | // Check for oddballs: true, false, null, undefined. |
| 4149 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4150 | __ j(equal, &return_not_equal); |
| 4151 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4152 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4153 | __ j(above_equal, &return_not_equal); |
| 4154 | |
| 4155 | // Check for oddballs: true, false, null, undefined. |
| 4156 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4157 | __ j(equal, &return_not_equal); |
| 4158 | |
| 4159 | // Fall through to the general case. |
| 4160 | __ bind(&slow); |
| 4161 | } |
| 4162 | |
| 4163 | // Generate the number comparison code. |
| 4164 | if (include_number_compare_) { |
| 4165 | Label non_number_comparison; |
| 4166 | Label unordered; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4167 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4168 | CpuFeatures::Scope use_sse2(SSE2); |
| 4169 | CpuFeatures::Scope use_cmov(CMOV); |
| 4170 | |
| 4171 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4172 | __ ucomisd(xmm0, xmm1); |
| 4173 | |
| 4174 | // Don't base result on EFLAGS when a NaN is involved. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4175 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4176 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4177 | __ mov(eax, 0); // equal |
| 4178 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4179 | __ cmov(above, eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4180 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4181 | __ cmov(below, eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4182 | __ ret(0); |
| 4183 | } else { |
| 4184 | FloatingPointHelper::CheckFloatOperands( |
| 4185 | masm, &non_number_comparison, ebx); |
| 4186 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4187 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4188 | __ FCmp(); |
| 4189 | |
| 4190 | // Don't base result on EFLAGS when a NaN is involved. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4191 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4192 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4193 | Label below_label, above_label; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4194 | // Return a result of -1, 0, or 1, based on EFLAGS. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4195 | __ j(below, &below_label, Label::kNear); |
| 4196 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4197 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4198 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4199 | __ ret(0); |
| 4200 | |
| 4201 | __ bind(&below_label); |
| 4202 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4203 | __ ret(0); |
| 4204 | |
| 4205 | __ bind(&above_label); |
| 4206 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4207 | __ ret(0); |
| 4208 | } |
| 4209 | |
| 4210 | // If one of the numbers was NaN, then the result is always false. |
| 4211 | // The cc is never not-equal. |
| 4212 | __ bind(&unordered); |
| 4213 | ASSERT(cc_ != not_equal); |
| 4214 | if (cc_ == less || cc_ == less_equal) { |
| 4215 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4216 | } else { |
| 4217 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4218 | } |
| 4219 | __ ret(0); |
| 4220 | |
| 4221 | // The number comparison code did not provide a valid result. |
| 4222 | __ bind(&non_number_comparison); |
| 4223 | } |
| 4224 | |
| 4225 | // Fast negative check for symbol-to-symbol equality. |
| 4226 | Label check_for_strings; |
| 4227 | if (cc_ == equal) { |
| 4228 | BranchIfNonSymbol(masm, &check_for_strings, eax, ecx); |
| 4229 | BranchIfNonSymbol(masm, &check_for_strings, edx, ecx); |
| 4230 | |
| 4231 | // We've already checked for object identity, so if both operands |
| 4232 | // are symbols they aren't equal. Register eax already holds a |
| 4233 | // non-zero value, which indicates not equal, so just return. |
| 4234 | __ ret(0); |
| 4235 | } |
| 4236 | |
| 4237 | __ bind(&check_for_strings); |
| 4238 | |
| 4239 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4240 | &check_unequal_objects); |
| 4241 | |
| 4242 | // Inline comparison of ascii strings. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4243 | if (cc_ == equal) { |
| 4244 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4245 | edx, |
| 4246 | eax, |
| 4247 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4248 | ebx); |
| 4249 | } else { |
| 4250 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4251 | edx, |
| 4252 | eax, |
| 4253 | ecx, |
| 4254 | ebx, |
| 4255 | edi); |
| 4256 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4257 | #ifdef DEBUG |
| 4258 | __ Abort("Unexpected fall-through from string comparison"); |
| 4259 | #endif |
| 4260 | |
| 4261 | __ bind(&check_unequal_objects); |
| 4262 | if (cc_ == equal && !strict_) { |
| 4263 | // Non-strict equality. Objects are unequal if |
| 4264 | // they are both JSObjects and not undetectable, |
| 4265 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4266 | Label not_both_objects; |
| 4267 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4268 | // At most one is a smi, so we can test for smi by adding the two. |
| 4269 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4270 | // a heap object has the low bit clear. |
| 4271 | STATIC_ASSERT(kSmiTag == 0); |
| 4272 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4273 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4274 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4275 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4276 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4277 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4278 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4279 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4280 | // We do not bail out after this point. Both are JSObjects, and |
| 4281 | // they are equal if and only if both are undetectable. |
| 4282 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4283 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4284 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4285 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4286 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4287 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4288 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4289 | // The objects are both undetectable, so they both compare as the value |
| 4290 | // undefined, and are equal. |
| 4291 | __ Set(eax, Immediate(EQUAL)); |
| 4292 | __ bind(&return_unequal); |
| 4293 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4294 | // or return equal if we fell through to here. |
| 4295 | __ ret(0); // rax, rdx were pushed |
| 4296 | __ bind(¬_both_objects); |
| 4297 | } |
| 4298 | |
| 4299 | // Push arguments below the return address. |
| 4300 | __ pop(ecx); |
| 4301 | __ push(edx); |
| 4302 | __ push(eax); |
| 4303 | |
| 4304 | // Figure out which native to call and setup the arguments. |
| 4305 | Builtins::JavaScript builtin; |
| 4306 | if (cc_ == equal) { |
| 4307 | builtin = strict_ ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
| 4308 | } else { |
| 4309 | builtin = Builtins::COMPARE; |
| 4310 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc_)))); |
| 4311 | } |
| 4312 | |
| 4313 | // Restore return address on the stack. |
| 4314 | __ push(ecx); |
| 4315 | |
| 4316 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4317 | // tagged as a small integer. |
| 4318 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
| 4319 | } |
| 4320 | |
| 4321 | |
| 4322 | void CompareStub::BranchIfNonSymbol(MacroAssembler* masm, |
| 4323 | Label* label, |
| 4324 | Register object, |
| 4325 | Register scratch) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4326 | __ JumpIfSmi(object, label); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4327 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4328 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 4329 | __ and_(scratch, kIsSymbolMask | kIsNotStringMask); |
| 4330 | __ cmp(scratch, kSymbolTag | kStringTag); |
| 4331 | __ j(not_equal, label); |
| 4332 | } |
| 4333 | |
| 4334 | |
| 4335 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4336 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4337 | } |
| 4338 | |
| 4339 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4340 | void CallFunctionStub::FinishCode(Code* code) { |
| 4341 | code->set_has_function_cache(RecordCallTarget()); |
| 4342 | } |
| 4343 | |
| 4344 | |
| 4345 | void CallFunctionStub::Clear(Heap* heap, Address address) { |
| 4346 | ASSERT(Memory::uint8_at(address + kPointerSize) == Assembler::kTestEaxByte); |
| 4347 | // 1 ~ size of the test eax opcode. |
| 4348 | Object* cell = Memory::Object_at(address + kPointerSize + 1); |
| 4349 | // Low-level because clearing happens during GC. |
| 4350 | reinterpret_cast<JSGlobalPropertyCell*>(cell)->set_value( |
| 4351 | RawUninitializedSentinel(heap)); |
| 4352 | } |
| 4353 | |
| 4354 | |
| 4355 | Object* CallFunctionStub::GetCachedValue(Address address) { |
| 4356 | ASSERT(Memory::uint8_at(address + kPointerSize) == Assembler::kTestEaxByte); |
| 4357 | // 1 ~ size of the test eax opcode. |
| 4358 | Object* cell = Memory::Object_at(address + kPointerSize + 1); |
| 4359 | return JSGlobalPropertyCell::cast(cell)->value(); |
| 4360 | } |
| 4361 | |
| 4362 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4363 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4364 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4365 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4366 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4367 | // The receiver might implicitly be the global object. This is |
| 4368 | // indicated by passing the hole as the receiver to the call |
| 4369 | // function stub. |
| 4370 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4371 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4372 | // Get the receiver from the stack. |
| 4373 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4374 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4375 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4376 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4377 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4378 | // Patch the receiver on the stack with the global receiver object. |
| 4379 | __ mov(ebx, GlobalObjectOperand()); |
| 4380 | __ mov(ebx, FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset)); |
| 4381 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4382 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4383 | } |
| 4384 | |
| 4385 | // Get the function to call from the stack. |
| 4386 | // +2 ~ receiver, return address |
| 4387 | __ mov(edi, Operand(esp, (argc_ + 2) * kPointerSize)); |
| 4388 | |
| 4389 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4390 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4391 | // Goto slow case if we do not have a function. |
| 4392 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4393 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4394 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4395 | if (RecordCallTarget()) { |
| 4396 | // Cache the called function in a global property cell in the |
| 4397 | // instruction stream after the call. Cache states are uninitialized, |
| 4398 | // monomorphic (indicated by a JSFunction), and megamorphic. |
| 4399 | Label initialize, call; |
| 4400 | // Load the cache cell address into ebx and the cache state into ecx. |
| 4401 | __ mov(ebx, Operand(esp, 0)); // Return address. |
| 4402 | __ mov(ebx, Operand(ebx, 1)); // 1 ~ sizeof 'test eax' opcode in bytes. |
| 4403 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
| 4404 | |
| 4405 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4406 | // function without changing the state. |
| 4407 | __ cmp(ecx, edi); |
| 4408 | __ j(equal, &call, Label::kNear); |
| 4409 | __ cmp(ecx, Immediate(MegamorphicSentinel(isolate))); |
| 4410 | __ j(equal, &call, Label::kNear); |
| 4411 | |
| 4412 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4413 | // megamorphic. |
| 4414 | __ cmp(ecx, Immediate(UninitializedSentinel(isolate))); |
| 4415 | __ j(equal, &initialize, Label::kNear); |
| 4416 | // MegamorphicSentinel is a root so no write-barrier is needed. |
| 4417 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4418 | Immediate(MegamorphicSentinel(isolate))); |
| 4419 | __ jmp(&call, Label::kNear); |
| 4420 | |
| 4421 | // An uninitialized cache is patched with the function. |
| 4422 | __ bind(&initialize); |
| 4423 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4424 | __ mov(ecx, edi); |
| 4425 | __ RecordWriteField(ebx, |
| 4426 | JSGlobalPropertyCell::kValueOffset, |
| 4427 | ecx, |
| 4428 | edx, |
| 4429 | kDontSaveFPRegs, |
| 4430 | OMIT_REMEMBERED_SET, // Cells are rescanned. |
| 4431 | OMIT_SMI_CHECK); |
| 4432 | |
| 4433 | __ bind(&call); |
| 4434 | } |
| 4435 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4436 | // Fast-case: Just invoke the function. |
| 4437 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4438 | |
| 4439 | if (ReceiverMightBeImplicit()) { |
| 4440 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4441 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4442 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4443 | __ InvokeFunction(edi, |
| 4444 | actual, |
| 4445 | JUMP_FUNCTION, |
| 4446 | NullCallWrapper(), |
| 4447 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4448 | __ bind(&call_as_function); |
| 4449 | } |
| 4450 | __ InvokeFunction(edi, |
| 4451 | actual, |
| 4452 | JUMP_FUNCTION, |
| 4453 | NullCallWrapper(), |
| 4454 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4455 | |
| 4456 | // Slow-case: Non-function called. |
| 4457 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4458 | if (RecordCallTarget()) { |
| 4459 | // If there is a call target cache, mark it megamorphic in the |
| 4460 | // non-function case. |
| 4461 | __ mov(ebx, Operand(esp, 0)); |
| 4462 | __ mov(ebx, Operand(ebx, 1)); |
| 4463 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4464 | Immediate(MegamorphicSentinel(isolate))); |
| 4465 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4466 | // Check for function proxy. |
| 4467 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4468 | __ j(not_equal, &non_function); |
| 4469 | __ pop(ecx); |
| 4470 | __ push(edi); // put proxy as additional argument under return address |
| 4471 | __ push(ecx); |
| 4472 | __ Set(eax, Immediate(argc_ + 1)); |
| 4473 | __ Set(ebx, Immediate(0)); |
| 4474 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4475 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4476 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4477 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4478 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4479 | } |
| 4480 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4481 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4482 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4483 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4484 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4485 | __ Set(eax, Immediate(argc_)); |
| 4486 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4487 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4488 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4489 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4490 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4491 | } |
| 4492 | |
| 4493 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4494 | bool CEntryStub::NeedsImmovableCode() { |
| 4495 | return false; |
| 4496 | } |
| 4497 | |
| 4498 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4499 | bool CEntryStub::IsPregenerated() { |
| 4500 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 4501 | result_size_ == 1; |
| 4502 | } |
| 4503 | |
| 4504 | |
| 4505 | void CodeStub::GenerateStubsAheadOfTime() { |
| 4506 | CEntryStub::GenerateAheadOfTime(); |
| 4507 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(); |
| 4508 | // It is important that the store buffer overflow stubs are generated first. |
| 4509 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(); |
| 4510 | } |
| 4511 | |
| 4512 | |
| 4513 | void CodeStub::GenerateFPStubs() { |
| 4514 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4515 | Handle<Code> code = save_doubles.GetCode(); |
| 4516 | code->set_is_pregenerated(true); |
| 4517 | code->GetIsolate()->set_fp_stubs_generated(true); |
| 4518 | } |
| 4519 | |
| 4520 | |
| 4521 | void CEntryStub::GenerateAheadOfTime() { |
| 4522 | CEntryStub stub(1, kDontSaveFPRegs); |
| 4523 | Handle<Code> code = stub.GetCode(); |
| 4524 | code->set_is_pregenerated(true); |
| 4525 | } |
| 4526 | |
| 4527 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4528 | void CEntryStub::GenerateThrowTOS(MacroAssembler* masm) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4529 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4533 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 4534 | Label* throw_normal_exception, |
| 4535 | Label* throw_termination_exception, |
| 4536 | Label* throw_out_of_memory_exception, |
| 4537 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4538 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4539 | // eax: result parameter for PerformGC, if any |
| 4540 | // ebx: pointer to C function (C callee-saved) |
| 4541 | // ebp: frame pointer (restored after C call) |
| 4542 | // esp: stack pointer (restored after C call) |
| 4543 | // edi: number of arguments including receiver (C callee-saved) |
| 4544 | // esi: pointer to the first argument (C callee-saved) |
| 4545 | |
| 4546 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 4547 | |
| 4548 | // Check stack alignment. |
| 4549 | if (FLAG_debug_code) { |
| 4550 | __ CheckStackAlignment(); |
| 4551 | } |
| 4552 | |
| 4553 | if (do_gc) { |
| 4554 | // Pass failure code returned from last attempt as first argument to |
| 4555 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 4556 | // stack alignment is known to be correct. This function takes one argument |
| 4557 | // which is passed on the stack, and we know that the stack has been |
| 4558 | // prepared to pass at least one argument. |
| 4559 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 4560 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 4561 | } |
| 4562 | |
| 4563 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4564 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4565 | if (always_allocate_scope) { |
| 4566 | __ inc(Operand::StaticVariable(scope_depth)); |
| 4567 | } |
| 4568 | |
| 4569 | // Call C function. |
| 4570 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 4571 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4572 | __ mov(Operand(esp, 2 * kPointerSize), |
| 4573 | Immediate(ExternalReference::isolate_address())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4574 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4575 | // Result is in eax or edx:eax - do not destroy these registers! |
| 4576 | |
| 4577 | if (always_allocate_scope) { |
| 4578 | __ dec(Operand::StaticVariable(scope_depth)); |
| 4579 | } |
| 4580 | |
| 4581 | // Make sure we're not trying to return 'the hole' from the runtime |
| 4582 | // call as this may lead to crashes in the IC code later. |
| 4583 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4584 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4585 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4586 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4587 | __ int3(); |
| 4588 | __ bind(&okay); |
| 4589 | } |
| 4590 | |
| 4591 | // Check for failure result. |
| 4592 | Label failure_returned; |
| 4593 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 4594 | __ lea(ecx, Operand(eax, 1)); |
| 4595 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 4596 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4597 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4598 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4599 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4600 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4601 | |
| 4602 | // Check that there is no pending exception, otherwise we |
| 4603 | // should have returned some failure value. |
| 4604 | if (FLAG_debug_code) { |
| 4605 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4606 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4607 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4608 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 4609 | // 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] | 4610 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4611 | __ int3(); |
| 4612 | __ bind(&okay); |
| 4613 | __ pop(edx); |
| 4614 | } |
| 4615 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4616 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4617 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4618 | __ ret(0); |
| 4619 | |
| 4620 | // Handling of failure. |
| 4621 | __ bind(&failure_returned); |
| 4622 | |
| 4623 | Label retry; |
| 4624 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 4625 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 4626 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4627 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4628 | |
| 4629 | // Special handling of out of memory exceptions. |
| 4630 | __ cmp(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException())); |
| 4631 | __ j(equal, throw_out_of_memory_exception); |
| 4632 | |
| 4633 | // Retrieve the pending exception and clear the variable. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4634 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4635 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4636 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 4637 | |
| 4638 | // Special handling of termination exceptions which are uncatchable |
| 4639 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4640 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4641 | __ j(equal, throw_termination_exception); |
| 4642 | |
| 4643 | // Handle normal exception. |
| 4644 | __ jmp(throw_normal_exception); |
| 4645 | |
| 4646 | // Retry. |
| 4647 | __ bind(&retry); |
| 4648 | } |
| 4649 | |
| 4650 | |
| 4651 | void CEntryStub::GenerateThrowUncatchable(MacroAssembler* masm, |
| 4652 | UncatchableExceptionType type) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4653 | __ ThrowUncatchable(type, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4654 | } |
| 4655 | |
| 4656 | |
| 4657 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 4658 | // eax: number of arguments including receiver |
| 4659 | // ebx: pointer to C function (C callee-saved) |
| 4660 | // ebp: frame pointer (restored after C call) |
| 4661 | // esp: stack pointer (restored after C call) |
| 4662 | // esi: current context (C callee-saved) |
| 4663 | // edi: JS function of the caller (C callee-saved) |
| 4664 | |
| 4665 | // NOTE: Invocations of builtins may return failure objects instead |
| 4666 | // of a proper result. The builtin entry handles this by performing |
| 4667 | // a garbage collection and retrying the builtin (twice). |
| 4668 | |
| 4669 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4670 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4671 | |
| 4672 | // eax: result parameter for PerformGC, if any (setup below) |
| 4673 | // ebx: pointer to builtin function (C callee-saved) |
| 4674 | // ebp: frame pointer (restored after C call) |
| 4675 | // esp: stack pointer (restored after C call) |
| 4676 | // edi: number of arguments including receiver (C callee-saved) |
| 4677 | // esi: argv pointer (C callee-saved) |
| 4678 | |
| 4679 | Label throw_normal_exception; |
| 4680 | Label throw_termination_exception; |
| 4681 | Label throw_out_of_memory_exception; |
| 4682 | |
| 4683 | // Call into the runtime system. |
| 4684 | GenerateCore(masm, |
| 4685 | &throw_normal_exception, |
| 4686 | &throw_termination_exception, |
| 4687 | &throw_out_of_memory_exception, |
| 4688 | false, |
| 4689 | false); |
| 4690 | |
| 4691 | // Do space-specific GC and retry runtime call. |
| 4692 | GenerateCore(masm, |
| 4693 | &throw_normal_exception, |
| 4694 | &throw_termination_exception, |
| 4695 | &throw_out_of_memory_exception, |
| 4696 | true, |
| 4697 | false); |
| 4698 | |
| 4699 | // Do full GC and retry runtime call one final time. |
| 4700 | Failure* failure = Failure::InternalError(); |
| 4701 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 4702 | GenerateCore(masm, |
| 4703 | &throw_normal_exception, |
| 4704 | &throw_termination_exception, |
| 4705 | &throw_out_of_memory_exception, |
| 4706 | true, |
| 4707 | true); |
| 4708 | |
| 4709 | __ bind(&throw_out_of_memory_exception); |
| 4710 | GenerateThrowUncatchable(masm, OUT_OF_MEMORY); |
| 4711 | |
| 4712 | __ bind(&throw_termination_exception); |
| 4713 | GenerateThrowUncatchable(masm, TERMINATION); |
| 4714 | |
| 4715 | __ bind(&throw_normal_exception); |
| 4716 | GenerateThrowTOS(masm); |
| 4717 | } |
| 4718 | |
| 4719 | |
| 4720 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
| 4721 | Label invoke, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4722 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4723 | |
| 4724 | // Setup frame. |
| 4725 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4726 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4727 | |
| 4728 | // Push marker in two places. |
| 4729 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 4730 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 4731 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 4732 | // Save callee-saved registers (C calling conventions). |
| 4733 | __ push(edi); |
| 4734 | __ push(esi); |
| 4735 | __ push(ebx); |
| 4736 | |
| 4737 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4738 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4739 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 4740 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4741 | // 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] | 4742 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4743 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4744 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4745 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4746 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4747 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 4748 | Label cont; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4749 | __ jmp(&cont, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4750 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4751 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
| 4752 | __ bind(&cont); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4753 | |
| 4754 | // Call a faked try-block that does the invoke. |
| 4755 | __ call(&invoke); |
| 4756 | |
| 4757 | // Caught exception: Store result (exception) in the pending |
| 4758 | // exception field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4759 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4760 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4761 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 4762 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 4763 | __ jmp(&exit); |
| 4764 | |
| 4765 | // Invoke: Link this frame into the handler chain. |
| 4766 | __ bind(&invoke); |
| 4767 | __ PushTryHandler(IN_JS_ENTRY, JS_ENTRY_HANDLER); |
| 4768 | |
| 4769 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4770 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4771 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 4772 | |
| 4773 | // Fake a receiver (NULL). |
| 4774 | __ push(Immediate(0)); // receiver |
| 4775 | |
| 4776 | // Invoke the function by calling through JS entry trampoline |
| 4777 | // builtin and pop the faked function when we return. Notice that we |
| 4778 | // cannot store a reference to the trampoline code directly in this |
| 4779 | // stub, because the builtin stubs may not have been generated yet. |
| 4780 | if (is_construct) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4781 | ExternalReference construct_entry( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4782 | Builtins::kJSConstructEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4783 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4784 | __ mov(edx, Immediate(construct_entry)); |
| 4785 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4786 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4787 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4788 | __ mov(edx, Immediate(entry)); |
| 4789 | } |
| 4790 | __ mov(edx, Operand(edx, 0)); // deref address |
| 4791 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4792 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4793 | |
| 4794 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4795 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4796 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4797 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4798 | // Check if the current stack frame is marked as the outermost JS frame. |
| 4799 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4800 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4801 | __ j(not_equal, ¬_outermost_js_2); |
| 4802 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 4803 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4804 | |
| 4805 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4806 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4807 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4808 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4809 | |
| 4810 | // Restore callee-saved registers (C calling conventions). |
| 4811 | __ pop(ebx); |
| 4812 | __ pop(esi); |
| 4813 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4814 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4815 | |
| 4816 | // Restore frame pointer and return. |
| 4817 | __ pop(ebp); |
| 4818 | __ ret(0); |
| 4819 | } |
| 4820 | |
| 4821 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4822 | // Generate stub code for instanceof. |
| 4823 | // This code can patch a call site inlined cache of the instance of check, |
| 4824 | // which looks like this. |
| 4825 | // |
| 4826 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 4827 | // 75 0a jne <some near label> |
| 4828 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 4829 | // |
| 4830 | // If call site patching is requested the stack will have the delta from the |
| 4831 | // return address to the cmp instruction just below the return address. This |
| 4832 | // also means that call site patching can only take place with arguments in |
| 4833 | // registers. TOS looks like this when call site patching is requested |
| 4834 | // |
| 4835 | // esp[0] : return address |
| 4836 | // esp[4] : delta from return address to cmp instruction |
| 4837 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4838 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4839 | // Call site inlining and patching implies arguments in registers. |
| 4840 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 4841 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4842 | // Fixed register usage throughout the stub. |
| 4843 | Register object = eax; // Object (lhs). |
| 4844 | Register map = ebx; // Map of the object. |
| 4845 | Register function = edx; // Function (rhs). |
| 4846 | Register prototype = edi; // Prototype of the function. |
| 4847 | Register scratch = ecx; |
| 4848 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4849 | // Constants describing the call site code to patch. |
| 4850 | static const int kDeltaToCmpImmediate = 2; |
| 4851 | static const int kDeltaToMov = 8; |
| 4852 | static const int kDeltaToMovImmediate = 9; |
| 4853 | static const int8_t kCmpEdiImmediateByte1 = BitCast<int8_t, uint8_t>(0x81); |
| 4854 | static const int8_t kCmpEdiImmediateByte2 = BitCast<int8_t, uint8_t>(0xff); |
| 4855 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 4856 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4857 | ExternalReference roots_array_start = |
| 4858 | ExternalReference::roots_array_start(masm->isolate()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4859 | |
| 4860 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 4861 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 4862 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4863 | // Get the object and function - they are always both needed. |
| 4864 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4865 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4866 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 4867 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 4868 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4869 | |
| 4870 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4871 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4872 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4873 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4874 | // If there is a call site cache don't look in the global cache, but do the |
| 4875 | // real lookup and update the call site cache. |
| 4876 | if (!HasCallSiteInlineCheck()) { |
| 4877 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4878 | Label miss; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4879 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4880 | __ cmp(function, Operand::StaticArray(scratch, |
| 4881 | times_pointer_size, |
| 4882 | roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4883 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4884 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
| 4885 | __ cmp(map, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4886 | scratch, times_pointer_size, roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4887 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4888 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 4889 | __ mov(eax, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4890 | scratch, times_pointer_size, roots_array_start)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4891 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 4892 | __ bind(&miss); |
| 4893 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4894 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4895 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4896 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4897 | |
| 4898 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4899 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4900 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4901 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4902 | // Update the global instanceof or call site inlined cache with the current |
| 4903 | // map and function. The cached answer will be set when it is known below. |
| 4904 | if (!HasCallSiteInlineCheck()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4905 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4906 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 4907 | map); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4908 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4909 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4910 | function); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4911 | } else { |
| 4912 | // The constants for the code patching are based on no push instructions |
| 4913 | // at the call site. |
| 4914 | ASSERT(HasArgsInRegisters()); |
| 4915 | // Get return address and delta to inlined map check. |
| 4916 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 4917 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 4918 | if (FLAG_debug_code) { |
| 4919 | __ cmpb(Operand(scratch, 0), kCmpEdiImmediateByte1); |
| 4920 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)"); |
| 4921 | __ cmpb(Operand(scratch, 1), kCmpEdiImmediateByte2); |
| 4922 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)"); |
| 4923 | } |
| 4924 | __ mov(Operand(scratch, kDeltaToCmpImmediate), map); |
| 4925 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4926 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4927 | // Loop through the prototype chain of the object looking for the function |
| 4928 | // prototype. |
| 4929 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4930 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4931 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4932 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4933 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4934 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4935 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4936 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4937 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 4938 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4939 | __ jmp(&loop); |
| 4940 | |
| 4941 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4942 | if (!HasCallSiteInlineCheck()) { |
| 4943 | __ Set(eax, Immediate(0)); |
| 4944 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 4945 | __ mov(Operand::StaticArray(scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4946 | times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4947 | } else { |
| 4948 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4949 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4950 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 4951 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 4952 | if (FLAG_debug_code) { |
| 4953 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 4954 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 4955 | } |
| 4956 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 4957 | if (!ReturnTrueFalseObject()) { |
| 4958 | __ Set(eax, Immediate(0)); |
| 4959 | } |
| 4960 | } |
| 4961 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4962 | |
| 4963 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4964 | if (!HasCallSiteInlineCheck()) { |
| 4965 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 4966 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 4967 | __ mov(Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4968 | scratch, times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4969 | } else { |
| 4970 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4971 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4972 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 4973 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 4974 | if (FLAG_debug_code) { |
| 4975 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 4976 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 4977 | } |
| 4978 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 4979 | if (!ReturnTrueFalseObject()) { |
| 4980 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 4981 | } |
| 4982 | } |
| 4983 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4984 | |
| 4985 | Label object_not_null, object_not_null_or_smi; |
| 4986 | __ bind(¬_js_object); |
| 4987 | // Before null, smi and string value checks, check that the rhs is a function |
| 4988 | // 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] | 4989 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4990 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4991 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4992 | |
| 4993 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4994 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4995 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4996 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4997 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4998 | |
| 4999 | __ bind(&object_not_null); |
| 5000 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5001 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5002 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5003 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5004 | |
| 5005 | __ bind(&object_not_null_or_smi); |
| 5006 | // String values is not instance of anything. |
| 5007 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5008 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5009 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5010 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5011 | |
| 5012 | // Slow-case: Go through the JavaScript implementation. |
| 5013 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5014 | if (!ReturnTrueFalseObject()) { |
| 5015 | // Tail call the builtin which returns 0 or 1. |
| 5016 | if (HasArgsInRegisters()) { |
| 5017 | // Push arguments below return address. |
| 5018 | __ pop(scratch); |
| 5019 | __ push(object); |
| 5020 | __ push(function); |
| 5021 | __ push(scratch); |
| 5022 | } |
| 5023 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5024 | } else { |
| 5025 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5026 | { |
| 5027 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5028 | __ push(object); |
| 5029 | __ push(function); |
| 5030 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5031 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5032 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5033 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5034 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5035 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5036 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5037 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5038 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5039 | __ bind(&done); |
| 5040 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5041 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5042 | } |
| 5043 | |
| 5044 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5045 | Register InstanceofStub::left() { return eax; } |
| 5046 | |
| 5047 | |
| 5048 | Register InstanceofStub::right() { return edx; } |
| 5049 | |
| 5050 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5051 | int CompareStub::MinorKey() { |
| 5052 | // Encode the three parameters in a unique 16 bit value. To avoid duplicate |
| 5053 | // stubs the never NaN NaN condition is only taken into account if the |
| 5054 | // condition is equals. |
| 5055 | ASSERT(static_cast<unsigned>(cc_) < (1 << 12)); |
| 5056 | ASSERT(lhs_.is(no_reg) && rhs_.is(no_reg)); |
| 5057 | return ConditionField::encode(static_cast<unsigned>(cc_)) |
| 5058 | | RegisterField::encode(false) // lhs_ and rhs_ are not used |
| 5059 | | StrictField::encode(strict_) |
| 5060 | | NeverNanNanField::encode(cc_ == equal ? never_nan_nan_ : false) |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5061 | | IncludeNumberCompareField::encode(include_number_compare_) |
| 5062 | | IncludeSmiCompareField::encode(include_smi_compare_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5063 | } |
| 5064 | |
| 5065 | |
| 5066 | // Unfortunately you have to run without snapshots to see most of these |
| 5067 | // 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] | 5068 | void CompareStub::PrintName(StringStream* stream) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5069 | ASSERT(lhs_.is(no_reg) && rhs_.is(no_reg)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5070 | const char* cc_name; |
| 5071 | switch (cc_) { |
| 5072 | case less: cc_name = "LT"; break; |
| 5073 | case greater: cc_name = "GT"; break; |
| 5074 | case less_equal: cc_name = "LE"; break; |
| 5075 | case greater_equal: cc_name = "GE"; break; |
| 5076 | case equal: cc_name = "EQ"; break; |
| 5077 | case not_equal: cc_name = "NE"; break; |
| 5078 | default: cc_name = "UnknownCondition"; break; |
| 5079 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 5080 | bool is_equality = cc_ == equal || cc_ == not_equal; |
| 5081 | stream->Add("CompareStub_%s", cc_name); |
| 5082 | if (strict_ && is_equality) stream->Add("_STRICT"); |
| 5083 | if (never_nan_nan_ && is_equality) stream->Add("_NO_NAN"); |
| 5084 | if (!include_number_compare_) stream->Add("_NO_NUMBER"); |
| 5085 | if (!include_smi_compare_) stream->Add("_NO_SMI"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5086 | } |
| 5087 | |
| 5088 | |
| 5089 | // ------------------------------------------------------------------------- |
| 5090 | // StringCharCodeAtGenerator |
| 5091 | |
| 5092 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 5093 | Label flat_string; |
| 5094 | Label ascii_string; |
| 5095 | Label got_char_code; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5096 | Label sliced_string; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5097 | |
| 5098 | // If the receiver is a smi trigger the non-string case. |
| 5099 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5100 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5101 | |
| 5102 | // Fetch the instance type of the receiver into result register. |
| 5103 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5104 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5105 | // If the receiver is not a string trigger the non-string case. |
| 5106 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5107 | __ j(not_zero, receiver_not_string_); |
| 5108 | |
| 5109 | // If the index is non-smi trigger the non-smi case. |
| 5110 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5111 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5112 | |
| 5113 | // Put smi-tagged index into scratch register. |
| 5114 | __ mov(scratch_, index_); |
| 5115 | __ bind(&got_smi_index_); |
| 5116 | |
| 5117 | // Check for index out of range. |
| 5118 | __ cmp(scratch_, FieldOperand(object_, String::kLengthOffset)); |
| 5119 | __ j(above_equal, index_out_of_range_); |
| 5120 | |
| 5121 | // We need special handling for non-flat strings. |
| 5122 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5123 | __ test(result_, Immediate(kStringRepresentationMask)); |
| 5124 | __ j(zero, &flat_string); |
| 5125 | |
| 5126 | // Handle non-flat strings. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5127 | __ and_(result_, kStringRepresentationMask); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5128 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 5129 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5130 | __ cmp(result_, kExternalStringTag); |
| 5131 | __ j(greater, &sliced_string, Label::kNear); |
| 5132 | __ j(equal, &call_runtime_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5133 | |
| 5134 | // ConsString. |
| 5135 | // Check whether the right hand side is the empty string (i.e. if |
| 5136 | // this is really a flat string in a cons string). If that is not |
| 5137 | // the case we would rather go to the runtime system now to flatten |
| 5138 | // the string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5139 | Label assure_seq_string; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5140 | __ cmp(FieldOperand(object_, ConsString::kSecondOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5141 | Immediate(masm->isolate()->factory()->empty_string())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5142 | __ j(not_equal, &call_runtime_); |
| 5143 | // Get the first of the two strings and load its instance type. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5144 | __ mov(result_, FieldOperand(object_, ConsString::kFirstOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5145 | __ jmp(&assure_seq_string, Label::kNear); |
| 5146 | |
| 5147 | // SlicedString, unpack and add offset. |
| 5148 | __ bind(&sliced_string); |
| 5149 | __ add(scratch_, FieldOperand(object_, SlicedString::kOffsetOffset)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5150 | __ mov(result_, FieldOperand(object_, SlicedString::kParentOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5151 | |
| 5152 | // Assure that we are dealing with a sequential string. Go to runtime if not. |
| 5153 | __ bind(&assure_seq_string); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5154 | __ mov(result_, FieldOperand(result_, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5155 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5156 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5157 | __ test(result_, Immediate(kStringRepresentationMask)); |
| 5158 | __ j(not_zero, &call_runtime_); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5159 | // Actually fetch the parent string if it is confirmed to be sequential. |
| 5160 | STATIC_ASSERT(SlicedString::kParentOffset == ConsString::kFirstOffset); |
| 5161 | __ mov(object_, FieldOperand(object_, SlicedString::kParentOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5162 | |
| 5163 | // Check for 1-byte or 2-byte string. |
| 5164 | __ bind(&flat_string); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5165 | STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
| 5166 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5167 | __ test(result_, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5168 | __ j(not_zero, &ascii_string, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5169 | |
| 5170 | // 2-byte string. |
| 5171 | // Load the 2-byte character code into the result register. |
| 5172 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 5173 | __ movzx_w(result_, FieldOperand(object_, |
| 5174 | scratch_, times_1, // Scratch is smi-tagged. |
| 5175 | SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5176 | __ jmp(&got_char_code, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5177 | |
| 5178 | // ASCII string. |
| 5179 | // Load the byte into the result register. |
| 5180 | __ bind(&ascii_string); |
| 5181 | __ SmiUntag(scratch_); |
| 5182 | __ movzx_b(result_, FieldOperand(object_, |
| 5183 | scratch_, times_1, |
| 5184 | SeqAsciiString::kHeaderSize)); |
| 5185 | __ bind(&got_char_code); |
| 5186 | __ SmiTag(result_); |
| 5187 | __ bind(&exit_); |
| 5188 | } |
| 5189 | |
| 5190 | |
| 5191 | void StringCharCodeAtGenerator::GenerateSlow( |
| 5192 | MacroAssembler* masm, const RuntimeCallHelper& call_helper) { |
| 5193 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5194 | |
| 5195 | // Index is not a smi. |
| 5196 | __ bind(&index_not_smi_); |
| 5197 | // 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] | 5198 | __ CheckMap(index_, |
| 5199 | masm->isolate()->factory()->heap_number_map(), |
| 5200 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5201 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5202 | call_helper.BeforeCall(masm); |
| 5203 | __ push(object_); |
| 5204 | __ push(index_); |
| 5205 | __ push(index_); // Consumed by runtime conversion function. |
| 5206 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5207 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5208 | } else { |
| 5209 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5210 | // NumberToSmi discards numbers that are not exact integers. |
| 5211 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5212 | } |
| 5213 | if (!scratch_.is(eax)) { |
| 5214 | // Save the conversion result before the pop instructions below |
| 5215 | // have a chance to overwrite it. |
| 5216 | __ mov(scratch_, eax); |
| 5217 | } |
| 5218 | __ pop(index_); |
| 5219 | __ pop(object_); |
| 5220 | // Reload the instance type. |
| 5221 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5222 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5223 | call_helper.AfterCall(masm); |
| 5224 | // If index is still not a smi, it must be out of range. |
| 5225 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5226 | __ JumpIfNotSmi(scratch_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5227 | // Otherwise, return to the fast path. |
| 5228 | __ jmp(&got_smi_index_); |
| 5229 | |
| 5230 | // Call runtime. We get here when the receiver is a string and the |
| 5231 | // index is a number, but the code of getting the actual character |
| 5232 | // is too complex (e.g., when the string needs to be flattened). |
| 5233 | __ bind(&call_runtime_); |
| 5234 | call_helper.BeforeCall(masm); |
| 5235 | __ push(object_); |
| 5236 | __ push(index_); |
| 5237 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5238 | if (!result_.is(eax)) { |
| 5239 | __ mov(result_, eax); |
| 5240 | } |
| 5241 | call_helper.AfterCall(masm); |
| 5242 | __ jmp(&exit_); |
| 5243 | |
| 5244 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5245 | } |
| 5246 | |
| 5247 | |
| 5248 | // ------------------------------------------------------------------------- |
| 5249 | // StringCharFromCodeGenerator |
| 5250 | |
| 5251 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5252 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5253 | STATIC_ASSERT(kSmiTag == 0); |
| 5254 | STATIC_ASSERT(kSmiShiftSize == 0); |
| 5255 | ASSERT(IsPowerOf2(String::kMaxAsciiCharCode + 1)); |
| 5256 | __ test(code_, |
| 5257 | Immediate(kSmiTagMask | |
| 5258 | ((~String::kMaxAsciiCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5259 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5260 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5261 | Factory* factory = masm->isolate()->factory(); |
| 5262 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5263 | STATIC_ASSERT(kSmiTag == 0); |
| 5264 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5265 | STATIC_ASSERT(kSmiShiftSize == 0); |
| 5266 | // At this point code register contains smi tagged ascii char code. |
| 5267 | __ mov(result_, FieldOperand(result_, |
| 5268 | code_, times_half_pointer_size, |
| 5269 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5270 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5271 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5272 | __ bind(&exit_); |
| 5273 | } |
| 5274 | |
| 5275 | |
| 5276 | void StringCharFromCodeGenerator::GenerateSlow( |
| 5277 | MacroAssembler* masm, const RuntimeCallHelper& call_helper) { |
| 5278 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5279 | |
| 5280 | __ bind(&slow_case_); |
| 5281 | call_helper.BeforeCall(masm); |
| 5282 | __ push(code_); |
| 5283 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5284 | if (!result_.is(eax)) { |
| 5285 | __ mov(result_, eax); |
| 5286 | } |
| 5287 | call_helper.AfterCall(masm); |
| 5288 | __ jmp(&exit_); |
| 5289 | |
| 5290 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5291 | } |
| 5292 | |
| 5293 | |
| 5294 | // ------------------------------------------------------------------------- |
| 5295 | // StringCharAtGenerator |
| 5296 | |
| 5297 | void StringCharAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 5298 | char_code_at_generator_.GenerateFast(masm); |
| 5299 | char_from_code_generator_.GenerateFast(masm); |
| 5300 | } |
| 5301 | |
| 5302 | |
| 5303 | void StringCharAtGenerator::GenerateSlow( |
| 5304 | MacroAssembler* masm, const RuntimeCallHelper& call_helper) { |
| 5305 | char_code_at_generator_.GenerateSlow(masm, call_helper); |
| 5306 | char_from_code_generator_.GenerateSlow(masm, call_helper); |
| 5307 | } |
| 5308 | |
| 5309 | |
| 5310 | void StringAddStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5311 | Label string_add_runtime, call_builtin; |
| 5312 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5313 | |
| 5314 | // Load the two arguments. |
| 5315 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5316 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5317 | |
| 5318 | // 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] | 5319 | if (flags_ == NO_STRING_ADD_FLAGS) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5320 | __ JumpIfSmi(eax, &string_add_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5321 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
| 5322 | __ j(above_equal, &string_add_runtime); |
| 5323 | |
| 5324 | // First argument is a a string, test second. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5325 | __ JumpIfSmi(edx, &string_add_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5326 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
| 5327 | __ j(above_equal, &string_add_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5328 | } else { |
| 5329 | // Here at least one of the arguments is definitely a string. |
| 5330 | // We convert the one that is not known to be a string. |
| 5331 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 5332 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 5333 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5334 | &call_builtin); |
| 5335 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5336 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 5337 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 5338 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5339 | &call_builtin); |
| 5340 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 5341 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5342 | } |
| 5343 | |
| 5344 | // Both arguments are strings. |
| 5345 | // eax: first string |
| 5346 | // edx: second string |
| 5347 | // 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] | 5348 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5349 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5350 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5351 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5352 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5353 | // 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] | 5354 | Counters* counters = masm->isolate()->counters(); |
| 5355 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5356 | __ ret(2 * kPointerSize); |
| 5357 | __ bind(&second_not_zero_length); |
| 5358 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5359 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5360 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5361 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5362 | // First string is empty, result is second string which is in edx. |
| 5363 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5364 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5365 | __ ret(2 * kPointerSize); |
| 5366 | |
| 5367 | // Both strings are non-empty. |
| 5368 | // eax: first string |
| 5369 | // ebx: length of first string as a smi |
| 5370 | // ecx: length of second string as a smi |
| 5371 | // edx: second string |
| 5372 | // Look at the length of the result of adding the two strings. |
| 5373 | Label string_add_flat_result, longer_than_two; |
| 5374 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5375 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5376 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5377 | // Handle exceptionally long strings in the runtime system. |
| 5378 | __ j(overflow, &string_add_runtime); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5379 | // Use the symbol table when adding two one character strings, as it |
| 5380 | // helps later optimizations to return a symbol here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5381 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5382 | __ j(not_equal, &longer_than_two); |
| 5383 | |
| 5384 | // Check that both strings are non-external ascii strings. |
| 5385 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, |
| 5386 | &string_add_runtime); |
| 5387 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5388 | // Get the two characters forming the new string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5389 | __ movzx_b(ebx, FieldOperand(eax, SeqAsciiString::kHeaderSize)); |
| 5390 | __ movzx_b(ecx, FieldOperand(edx, SeqAsciiString::kHeaderSize)); |
| 5391 | |
| 5392 | // Try to lookup two character string in symbol table. If it is not found |
| 5393 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5394 | Label make_two_character_string, make_two_character_string_no_reload; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5395 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5396 | masm, ebx, ecx, eax, edx, edi, |
| 5397 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5398 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5399 | __ ret(2 * kPointerSize); |
| 5400 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5401 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5402 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5403 | // Reload the arguments. |
| 5404 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5405 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5406 | // Get the two characters forming the new string. |
| 5407 | __ movzx_b(ebx, FieldOperand(eax, SeqAsciiString::kHeaderSize)); |
| 5408 | __ movzx_b(ecx, FieldOperand(edx, SeqAsciiString::kHeaderSize)); |
| 5409 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5410 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5411 | __ AllocateAsciiString(eax, // Result. |
| 5412 | 2, // Length. |
| 5413 | edi, // Scratch 1. |
| 5414 | edx, // Scratch 2. |
| 5415 | &string_add_runtime); |
| 5416 | // Pack both characters in ebx. |
| 5417 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5418 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5419 | // Set the characters in the new string. |
| 5420 | __ mov_w(FieldOperand(eax, SeqAsciiString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5421 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5422 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5423 | |
| 5424 | __ bind(&longer_than_two); |
| 5425 | // Check if resulting string will be flat. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5426 | __ cmp(ebx, Immediate(Smi::FromInt(String::kMinNonFlatLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5427 | __ j(below, &string_add_flat_result); |
| 5428 | |
| 5429 | // If result is not supposed to be flat allocate a cons string object. If both |
| 5430 | // strings are ascii the result is an ascii cons string. |
| 5431 | Label non_ascii, allocated, ascii_data; |
| 5432 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5433 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5434 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5435 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5436 | __ and_(ecx, edi); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5437 | STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
| 5438 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5439 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5440 | __ j(zero, &non_ascii); |
| 5441 | __ bind(&ascii_data); |
| 5442 | // Allocate an acsii cons string. |
| 5443 | __ AllocateAsciiConsString(ecx, edi, no_reg, &string_add_runtime); |
| 5444 | __ bind(&allocated); |
| 5445 | // Fill the fields of the cons string. |
| 5446 | if (FLAG_debug_code) __ AbortIfNotSmi(ebx); |
| 5447 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5448 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5449 | Immediate(String::kEmptyHashField)); |
| 5450 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5451 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5452 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5453 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5454 | __ ret(2 * kPointerSize); |
| 5455 | __ bind(&non_ascii); |
| 5456 | // At least one of the strings is two-byte. Check whether it happens |
| 5457 | // to contain only ascii characters. |
| 5458 | // ecx: first instance type AND second instance type. |
| 5459 | // edi: second instance type. |
| 5460 | __ test(ecx, Immediate(kAsciiDataHintMask)); |
| 5461 | __ j(not_zero, &ascii_data); |
| 5462 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5463 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5464 | __ xor_(edi, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5465 | STATIC_ASSERT(kAsciiStringTag != 0 && kAsciiDataHintTag != 0); |
| 5466 | __ and_(edi, kAsciiStringTag | kAsciiDataHintTag); |
| 5467 | __ cmp(edi, kAsciiStringTag | kAsciiDataHintTag); |
| 5468 | __ j(equal, &ascii_data); |
| 5469 | // Allocate a two byte cons string. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5470 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &string_add_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5471 | __ jmp(&allocated); |
| 5472 | |
| 5473 | // Handle creating a flat result. First check that both strings are not |
| 5474 | // external strings. |
| 5475 | // eax: first string |
| 5476 | // ebx: length of resulting flat string as a smi |
| 5477 | // edx: second string |
| 5478 | __ bind(&string_add_flat_result); |
| 5479 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5480 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5481 | __ and_(ecx, kStringRepresentationMask); |
| 5482 | __ cmp(ecx, kExternalStringTag); |
| 5483 | __ j(equal, &string_add_runtime); |
| 5484 | __ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5485 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5486 | __ and_(ecx, kStringRepresentationMask); |
| 5487 | __ cmp(ecx, kExternalStringTag); |
| 5488 | __ j(equal, &string_add_runtime); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5489 | // We cannot encounter sliced strings here since: |
| 5490 | STATIC_ASSERT(SlicedString::kMinLength >= String::kMinNonFlatLength); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5491 | // Now check if both strings are ascii strings. |
| 5492 | // eax: first string |
| 5493 | // ebx: length of resulting flat string as a smi |
| 5494 | // edx: second string |
| 5495 | Label non_ascii_string_add_flat_result; |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5496 | STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
| 5497 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5498 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5499 | __ test_b(FieldOperand(ecx, Map::kInstanceTypeOffset), kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5500 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5501 | __ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5502 | __ test_b(FieldOperand(ecx, Map::kInstanceTypeOffset), kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5503 | __ j(zero, &string_add_runtime); |
| 5504 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5505 | // Both strings are ascii strings. As they are short they are both flat. |
| 5506 | // ebx: length of resulting flat string as a smi |
| 5507 | __ SmiUntag(ebx); |
| 5508 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &string_add_runtime); |
| 5509 | // eax: result string |
| 5510 | __ mov(ecx, eax); |
| 5511 | // Locate first character of result. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5512 | __ add(ecx, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5513 | // Load first argument and locate first character. |
| 5514 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 5515 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5516 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5517 | __ add(edx, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5518 | // eax: result string |
| 5519 | // ecx: first character of result |
| 5520 | // edx: first char of first argument |
| 5521 | // edi: length of first argument |
| 5522 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
| 5523 | // Load second argument and locate first character. |
| 5524 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 5525 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5526 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5527 | __ add(edx, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5528 | // eax: result string |
| 5529 | // ecx: next character of result |
| 5530 | // edx: first char of second argument |
| 5531 | // edi: length of second argument |
| 5532 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5533 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5534 | __ ret(2 * kPointerSize); |
| 5535 | |
| 5536 | // Handle creating a flat two byte result. |
| 5537 | // eax: first string - known to be two byte |
| 5538 | // ebx: length of resulting flat string as a smi |
| 5539 | // edx: second string |
| 5540 | __ bind(&non_ascii_string_add_flat_result); |
| 5541 | __ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5542 | __ test_b(FieldOperand(ecx, Map::kInstanceTypeOffset), kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5543 | __ j(not_zero, &string_add_runtime); |
| 5544 | // Both strings are two byte strings. As they are short they are both |
| 5545 | // flat. |
| 5546 | __ SmiUntag(ebx); |
| 5547 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &string_add_runtime); |
| 5548 | // eax: result string |
| 5549 | __ mov(ecx, eax); |
| 5550 | // Locate first character of result. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5551 | __ add(ecx, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5552 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5553 | // Load first argument and locate first character. |
| 5554 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 5555 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5556 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5557 | __ add(edx, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5558 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5559 | // eax: result string |
| 5560 | // ecx: first character of result |
| 5561 | // edx: first char of first argument |
| 5562 | // edi: length of first argument |
| 5563 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
| 5564 | // Load second argument and locate first character. |
| 5565 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 5566 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5567 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5568 | __ add(edx, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5569 | // eax: result string |
| 5570 | // ecx: next character of result |
| 5571 | // edx: first char of second argument |
| 5572 | // edi: length of second argument |
| 5573 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5574 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5575 | __ ret(2 * kPointerSize); |
| 5576 | |
| 5577 | // Just jump to runtime to add the two strings. |
| 5578 | __ bind(&string_add_runtime); |
| 5579 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5580 | |
| 5581 | if (call_builtin.is_linked()) { |
| 5582 | __ bind(&call_builtin); |
| 5583 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 5584 | } |
| 5585 | } |
| 5586 | |
| 5587 | |
| 5588 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 5589 | int stack_offset, |
| 5590 | Register arg, |
| 5591 | Register scratch1, |
| 5592 | Register scratch2, |
| 5593 | Register scratch3, |
| 5594 | Label* slow) { |
| 5595 | // First check if the argument is already a string. |
| 5596 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5597 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5598 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 5599 | __ j(below, &done); |
| 5600 | |
| 5601 | // Check the number to string cache. |
| 5602 | Label not_cached; |
| 5603 | __ bind(¬_string); |
| 5604 | // Puts the cached result into scratch1. |
| 5605 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 5606 | arg, |
| 5607 | scratch1, |
| 5608 | scratch2, |
| 5609 | scratch3, |
| 5610 | false, |
| 5611 | ¬_cached); |
| 5612 | __ mov(arg, scratch1); |
| 5613 | __ mov(Operand(esp, stack_offset), arg); |
| 5614 | __ jmp(&done); |
| 5615 | |
| 5616 | // Check if the argument is a safe string wrapper. |
| 5617 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5618 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5619 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 5620 | __ j(not_equal, slow); |
| 5621 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 5622 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 5623 | __ j(zero, slow); |
| 5624 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 5625 | __ mov(Operand(esp, stack_offset), arg); |
| 5626 | |
| 5627 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5628 | } |
| 5629 | |
| 5630 | |
| 5631 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5632 | Register dest, |
| 5633 | Register src, |
| 5634 | Register count, |
| 5635 | Register scratch, |
| 5636 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5637 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5638 | __ bind(&loop); |
| 5639 | // This loop just copies one character at a time, as it is only used for very |
| 5640 | // short strings. |
| 5641 | if (ascii) { |
| 5642 | __ mov_b(scratch, Operand(src, 0)); |
| 5643 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5644 | __ add(src, Immediate(1)); |
| 5645 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5646 | } else { |
| 5647 | __ mov_w(scratch, Operand(src, 0)); |
| 5648 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5649 | __ add(src, Immediate(2)); |
| 5650 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5651 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5652 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5653 | __ j(not_zero, &loop); |
| 5654 | } |
| 5655 | |
| 5656 | |
| 5657 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 5658 | Register dest, |
| 5659 | Register src, |
| 5660 | Register count, |
| 5661 | Register scratch, |
| 5662 | bool ascii) { |
| 5663 | // Copy characters using rep movs of doublewords. |
| 5664 | // The destination is aligned on a 4 byte boundary because we are |
| 5665 | // copying to the beginning of a newly allocated string. |
| 5666 | ASSERT(dest.is(edi)); // rep movs destination |
| 5667 | ASSERT(src.is(esi)); // rep movs source |
| 5668 | ASSERT(count.is(ecx)); // rep movs count |
| 5669 | ASSERT(!scratch.is(dest)); |
| 5670 | ASSERT(!scratch.is(src)); |
| 5671 | ASSERT(!scratch.is(count)); |
| 5672 | |
| 5673 | // Nothing to do for zero characters. |
| 5674 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5675 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5676 | __ j(zero, &done); |
| 5677 | |
| 5678 | // Make count the number of bytes to copy. |
| 5679 | if (!ascii) { |
| 5680 | __ shl(count, 1); |
| 5681 | } |
| 5682 | |
| 5683 | // 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] | 5684 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5685 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5686 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5687 | |
| 5688 | // Copy from edi to esi using rep movs instruction. |
| 5689 | __ mov(scratch, count); |
| 5690 | __ sar(count, 2); // Number of doublewords to copy. |
| 5691 | __ cld(); |
| 5692 | __ rep_movs(); |
| 5693 | |
| 5694 | // Find number of bytes left. |
| 5695 | __ mov(count, scratch); |
| 5696 | __ and_(count, 3); |
| 5697 | |
| 5698 | // Check if there are more bytes to copy. |
| 5699 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5700 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5701 | __ j(zero, &done); |
| 5702 | |
| 5703 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5704 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5705 | __ bind(&loop); |
| 5706 | __ mov_b(scratch, Operand(src, 0)); |
| 5707 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5708 | __ add(src, Immediate(1)); |
| 5709 | __ add(dest, Immediate(1)); |
| 5710 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5711 | __ j(not_zero, &loop); |
| 5712 | |
| 5713 | __ bind(&done); |
| 5714 | } |
| 5715 | |
| 5716 | |
| 5717 | void StringHelper::GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 5718 | Register c1, |
| 5719 | Register c2, |
| 5720 | Register scratch1, |
| 5721 | Register scratch2, |
| 5722 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5723 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5724 | Label* not_found) { |
| 5725 | // Register scratch3 is the general scratch register in this function. |
| 5726 | Register scratch = scratch3; |
| 5727 | |
| 5728 | // Make sure that both characters are not digits as such strings has a |
| 5729 | // 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] | 5730 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5731 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5732 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5733 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5734 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5735 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5736 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5737 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5738 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5739 | |
| 5740 | __ bind(¬_array_index); |
| 5741 | // Calculate the two character string hash. |
| 5742 | Register hash = scratch1; |
| 5743 | GenerateHashInit(masm, hash, c1, scratch); |
| 5744 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 5745 | GenerateHashGetHash(masm, hash, scratch); |
| 5746 | |
| 5747 | // Collect the two characters in a register. |
| 5748 | Register chars = c1; |
| 5749 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5750 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5751 | |
| 5752 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5753 | // hash: hash of two character string. |
| 5754 | |
| 5755 | // Load the symbol table. |
| 5756 | Register symbol_table = c2; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5757 | ExternalReference roots_array_start = |
| 5758 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5759 | __ mov(scratch, Immediate(Heap::kSymbolTableRootIndex)); |
| 5760 | __ mov(symbol_table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5761 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5762 | |
| 5763 | // Calculate capacity mask from the symbol table capacity. |
| 5764 | Register mask = scratch2; |
| 5765 | __ mov(mask, FieldOperand(symbol_table, SymbolTable::kCapacityOffset)); |
| 5766 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5767 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5768 | |
| 5769 | // Registers |
| 5770 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5771 | // hash: hash of two character string |
| 5772 | // symbol_table: symbol table |
| 5773 | // mask: capacity mask |
| 5774 | // scratch: - |
| 5775 | |
| 5776 | // Perform a number of probes in the symbol table. |
| 5777 | static const int kProbes = 4; |
| 5778 | Label found_in_symbol_table; |
| 5779 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
| 5780 | for (int i = 0; i < kProbes; i++) { |
| 5781 | // Calculate entry in symbol table. |
| 5782 | __ mov(scratch, hash); |
| 5783 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5784 | __ add(scratch, Immediate(SymbolTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5785 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5786 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5787 | |
| 5788 | // Load the entry from the symbol table. |
| 5789 | Register candidate = scratch; // Scratch register contains candidate. |
| 5790 | STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
| 5791 | __ mov(candidate, |
| 5792 | FieldOperand(symbol_table, |
| 5793 | scratch, |
| 5794 | times_pointer_size, |
| 5795 | SymbolTable::kElementsStartOffset)); |
| 5796 | |
| 5797 | // 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] | 5798 | Factory* factory = masm->isolate()->factory(); |
| 5799 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5800 | __ j(equal, not_found); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5801 | __ cmp(candidate, factory->null_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5802 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5803 | |
| 5804 | // If length is not 2 the string is not a candidate. |
| 5805 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 5806 | Immediate(Smi::FromInt(2))); |
| 5807 | __ j(not_equal, &next_probe[i]); |
| 5808 | |
| 5809 | // As we are out of registers save the mask on the stack and use that |
| 5810 | // register as a temporary. |
| 5811 | __ push(mask); |
| 5812 | Register temp = mask; |
| 5813 | |
| 5814 | // Check that the candidate is a non-external ascii string. |
| 5815 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 5816 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 5817 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 5818 | temp, temp, &next_probe_pop_mask[i]); |
| 5819 | |
| 5820 | // Check if the two characters match. |
| 5821 | __ mov(temp, FieldOperand(candidate, SeqAsciiString::kHeaderSize)); |
| 5822 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5823 | __ cmp(chars, temp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5824 | __ j(equal, &found_in_symbol_table); |
| 5825 | __ bind(&next_probe_pop_mask[i]); |
| 5826 | __ pop(mask); |
| 5827 | __ bind(&next_probe[i]); |
| 5828 | } |
| 5829 | |
| 5830 | // No matching 2 character string found by probing. |
| 5831 | __ jmp(not_found); |
| 5832 | |
| 5833 | // Scratch register contains result when we fall through to here. |
| 5834 | Register result = scratch; |
| 5835 | __ bind(&found_in_symbol_table); |
| 5836 | __ pop(mask); // Pop saved mask from the stack. |
| 5837 | if (!result.is(eax)) { |
| 5838 | __ mov(eax, result); |
| 5839 | } |
| 5840 | } |
| 5841 | |
| 5842 | |
| 5843 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 5844 | Register hash, |
| 5845 | Register character, |
| 5846 | Register scratch) { |
| 5847 | // hash = character + (character << 10); |
| 5848 | __ mov(hash, character); |
| 5849 | __ shl(hash, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5850 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5851 | // hash ^= hash >> 6; |
| 5852 | __ mov(scratch, hash); |
| 5853 | __ sar(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5854 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5855 | } |
| 5856 | |
| 5857 | |
| 5858 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 5859 | Register hash, |
| 5860 | Register character, |
| 5861 | Register scratch) { |
| 5862 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5863 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5864 | // hash += hash << 10; |
| 5865 | __ mov(scratch, hash); |
| 5866 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5867 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5868 | // hash ^= hash >> 6; |
| 5869 | __ mov(scratch, hash); |
| 5870 | __ sar(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5871 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | |
| 5875 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 5876 | Register hash, |
| 5877 | Register scratch) { |
| 5878 | // hash += hash << 3; |
| 5879 | __ mov(scratch, hash); |
| 5880 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5881 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5882 | // hash ^= hash >> 11; |
| 5883 | __ mov(scratch, hash); |
| 5884 | __ sar(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5885 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5886 | // hash += hash << 15; |
| 5887 | __ mov(scratch, hash); |
| 5888 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5889 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5890 | |
| 5891 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5892 | Label hash_not_zero; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5893 | __ test(hash, hash); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5894 | __ j(not_zero, &hash_not_zero, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5895 | __ mov(hash, Immediate(27)); |
| 5896 | __ bind(&hash_not_zero); |
| 5897 | } |
| 5898 | |
| 5899 | |
| 5900 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 5901 | Label runtime; |
| 5902 | |
| 5903 | // Stack frame on entry. |
| 5904 | // esp[0]: return address |
| 5905 | // esp[4]: to |
| 5906 | // esp[8]: from |
| 5907 | // esp[12]: string |
| 5908 | |
| 5909 | // Make sure first argument is a string. |
| 5910 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 5911 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5912 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5913 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 5914 | __ j(NegateCondition(is_string), &runtime); |
| 5915 | |
| 5916 | // eax: string |
| 5917 | // ebx: instance type |
| 5918 | |
| 5919 | // Calculate length of sub string using the smi values. |
| 5920 | Label result_longer_than_two; |
| 5921 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5922 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5923 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5924 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5925 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5926 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
| 5927 | Label return_eax; |
| 5928 | __ j(equal, &return_eax); |
| 5929 | // Special handling of sub-strings of length 1 and 2. One character strings |
| 5930 | // are handled in the runtime system (looked up in the single character |
| 5931 | // cache). Two character strings are looked for in the symbol cache. |
| 5932 | __ SmiUntag(ecx); // Result length is no longer smi. |
| 5933 | __ cmp(ecx, 2); |
| 5934 | __ j(greater, &result_longer_than_two); |
| 5935 | __ j(less, &runtime); |
| 5936 | |
| 5937 | // Sub string of length 2 requested. |
| 5938 | // eax: string |
| 5939 | // ebx: instance type |
| 5940 | // ecx: sub string length (value is 2) |
| 5941 | // edx: from index (smi) |
| 5942 | __ JumpIfInstanceTypeIsNotSequentialAscii(ebx, ebx, &runtime); |
| 5943 | |
| 5944 | // Get the two characters forming the sub string. |
| 5945 | __ SmiUntag(edx); // From index is no longer smi. |
| 5946 | __ movzx_b(ebx, FieldOperand(eax, edx, times_1, SeqAsciiString::kHeaderSize)); |
| 5947 | __ movzx_b(ecx, |
| 5948 | FieldOperand(eax, edx, times_1, SeqAsciiString::kHeaderSize + 1)); |
| 5949 | |
| 5950 | // Try to lookup two character string in symbol table. |
| 5951 | Label make_two_character_string; |
| 5952 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5953 | masm, ebx, ecx, eax, edx, edi, |
| 5954 | &make_two_character_string, &make_two_character_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5955 | __ ret(3 * kPointerSize); |
| 5956 | |
| 5957 | __ bind(&make_two_character_string); |
| 5958 | // Setup registers for allocating the two character string. |
| 5959 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 5960 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5961 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 5962 | __ Set(ecx, Immediate(2)); |
| 5963 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5964 | if (FLAG_string_slices) { |
| 5965 | Label copy_routine; |
| 5966 | // If coming from the make_two_character_string path, the string |
| 5967 | // is too short to be sliced anyways. |
| 5968 | STATIC_ASSERT(2 < SlicedString::kMinLength); |
| 5969 | __ jmp(©_routine); |
| 5970 | __ bind(&result_longer_than_two); |
| 5971 | |
| 5972 | // eax: string |
| 5973 | // ebx: instance type |
| 5974 | // ecx: sub string length |
| 5975 | // edx: from index (smi) |
| 5976 | Label allocate_slice, sliced_string, seq_string; |
| 5977 | __ cmp(ecx, SlicedString::kMinLength); |
| 5978 | // Short slice. Copy instead of slicing. |
| 5979 | __ j(less, ©_routine); |
| 5980 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5981 | __ test(ebx, Immediate(kStringRepresentationMask)); |
| 5982 | __ j(zero, &seq_string, Label::kNear); |
| 5983 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 5984 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 5985 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 5986 | // External string. Jump to runtime. |
| 5987 | __ j(zero, &runtime); |
| 5988 | |
| 5989 | Factory* factory = masm->isolate()->factory(); |
| 5990 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 5991 | __ j(not_zero, &sliced_string, Label::kNear); |
| 5992 | // Cons string. Check whether it is flat, then fetch first part. |
| 5993 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 5994 | factory->empty_string()); |
| 5995 | __ j(not_equal, &runtime); |
| 5996 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 5997 | __ jmp(&allocate_slice, Label::kNear); |
| 5998 | |
| 5999 | __ bind(&sliced_string); |
| 6000 | // Sliced string. Fetch parent and correct start index by offset. |
| 6001 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6002 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6003 | __ jmp(&allocate_slice, Label::kNear); |
| 6004 | |
| 6005 | __ bind(&seq_string); |
| 6006 | // Sequential string. Just move string to the right register. |
| 6007 | __ mov(edi, eax); |
| 6008 | |
| 6009 | __ bind(&allocate_slice); |
| 6010 | // edi: underlying subject string |
| 6011 | // ebx: instance type of original subject string |
| 6012 | // edx: offset |
| 6013 | // ecx: length |
| 6014 | // Allocate new sliced string. At this point we do not reload the instance |
| 6015 | // type including the string encoding because we simply rely on the info |
| 6016 | // provided by the original string. It does not matter if the original |
| 6017 | // string's encoding is wrong because we always have to recheck encoding of |
| 6018 | // the newly created string's parent anyways due to externalized strings. |
| 6019 | Label two_byte_slice, set_slice_header; |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6020 | STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
| 6021 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6022 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6023 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6024 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6025 | __ jmp(&set_slice_header, Label::kNear); |
| 6026 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6027 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6028 | __ bind(&set_slice_header); |
| 6029 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
| 6030 | __ SmiTag(ecx); |
| 6031 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
| 6032 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6033 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6034 | Immediate(String::kEmptyHashField)); |
| 6035 | __ jmp(&return_eax); |
| 6036 | |
| 6037 | __ bind(©_routine); |
| 6038 | } else { |
| 6039 | __ bind(&result_longer_than_two); |
| 6040 | } |
| 6041 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6042 | // eax: string |
| 6043 | // ebx: instance type |
| 6044 | // ecx: result string length |
| 6045 | // Check for flat ascii string |
| 6046 | Label non_ascii_flat; |
| 6047 | __ JumpIfInstanceTypeIsNotSequentialAscii(ebx, ebx, &non_ascii_flat); |
| 6048 | |
| 6049 | // Allocate the result. |
| 6050 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime); |
| 6051 | |
| 6052 | // eax: result string |
| 6053 | // ecx: result string length |
| 6054 | __ mov(edx, esi); // esi used by following code. |
| 6055 | // Locate first character of result. |
| 6056 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6057 | __ add(edi, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6058 | // Load string argument and locate character of sub string start. |
| 6059 | __ mov(esi, Operand(esp, 3 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6060 | __ add(esi, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6061 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); // from |
| 6062 | __ SmiUntag(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6063 | __ add(esi, ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6064 | |
| 6065 | // eax: result string |
| 6066 | // ecx: result length |
| 6067 | // edx: original value of esi |
| 6068 | // edi: first character of result |
| 6069 | // esi: character of sub string start |
| 6070 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6071 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6072 | Counters* counters = masm->isolate()->counters(); |
| 6073 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6074 | __ ret(3 * kPointerSize); |
| 6075 | |
| 6076 | __ bind(&non_ascii_flat); |
| 6077 | // eax: string |
| 6078 | // ebx: instance type & kStringRepresentationMask | kStringEncodingMask |
| 6079 | // ecx: result string length |
| 6080 | // Check for flat two byte string |
| 6081 | __ cmp(ebx, kSeqStringTag | kTwoByteStringTag); |
| 6082 | __ j(not_equal, &runtime); |
| 6083 | |
| 6084 | // Allocate the result. |
| 6085 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime); |
| 6086 | |
| 6087 | // eax: result string |
| 6088 | // ecx: result string length |
| 6089 | __ mov(edx, esi); // esi used by following code. |
| 6090 | // Locate first character of result. |
| 6091 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6092 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6093 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6094 | // Load string argument and locate character of sub string start. |
| 6095 | __ mov(esi, Operand(esp, 3 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6096 | __ add(esi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6097 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); // from |
| 6098 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6099 | // byte character. |
| 6100 | STATIC_ASSERT(kSmiTag == 0); |
| 6101 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6102 | __ add(esi, ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6103 | |
| 6104 | // eax: result string |
| 6105 | // ecx: result length |
| 6106 | // edx: original value of esi |
| 6107 | // edi: first character of result |
| 6108 | // esi: character of sub string start |
| 6109 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6110 | __ mov(esi, edx); // Restore esi. |
| 6111 | |
| 6112 | __ bind(&return_eax); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6113 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6114 | __ ret(3 * kPointerSize); |
| 6115 | |
| 6116 | // Just jump to runtime to create the sub string. |
| 6117 | __ bind(&runtime); |
| 6118 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
| 6119 | } |
| 6120 | |
| 6121 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6122 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6123 | Register left, |
| 6124 | Register right, |
| 6125 | Register scratch1, |
| 6126 | Register scratch2) { |
| 6127 | Register length = scratch1; |
| 6128 | |
| 6129 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6130 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6131 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6132 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6133 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6134 | __ bind(&strings_not_equal); |
| 6135 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6136 | __ ret(0); |
| 6137 | |
| 6138 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6139 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6140 | __ bind(&check_zero_length); |
| 6141 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6142 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6143 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6144 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6145 | __ ret(0); |
| 6146 | |
| 6147 | // Compare characters. |
| 6148 | __ bind(&compare_chars); |
| 6149 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6150 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6151 | |
| 6152 | // Characters are equal. |
| 6153 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6154 | __ ret(0); |
| 6155 | } |
| 6156 | |
| 6157 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6158 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6159 | Register left, |
| 6160 | Register right, |
| 6161 | Register scratch1, |
| 6162 | Register scratch2, |
| 6163 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6164 | Counters* counters = masm->isolate()->counters(); |
| 6165 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6166 | |
| 6167 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6168 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6169 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6170 | __ mov(scratch3, scratch1); |
| 6171 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6172 | |
| 6173 | Register length_delta = scratch3; |
| 6174 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6175 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6176 | // 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] | 6177 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6178 | __ bind(&left_shorter); |
| 6179 | |
| 6180 | Register min_length = scratch1; |
| 6181 | |
| 6182 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6183 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6184 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6185 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6186 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6187 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6188 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6189 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6190 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6191 | |
| 6192 | // Compare lengths - strings up to min-length are equal. |
| 6193 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6194 | __ test(length_delta, length_delta); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6195 | __ j(not_zero, &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6196 | |
| 6197 | // Result is EQUAL. |
| 6198 | STATIC_ASSERT(EQUAL == 0); |
| 6199 | STATIC_ASSERT(kSmiTag == 0); |
| 6200 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6201 | __ ret(0); |
| 6202 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6203 | Label result_greater; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6204 | __ bind(&result_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6205 | __ j(greater, &result_greater, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6206 | |
| 6207 | // Result is LESS. |
| 6208 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6209 | __ ret(0); |
| 6210 | |
| 6211 | // Result is GREATER. |
| 6212 | __ bind(&result_greater); |
| 6213 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6214 | __ ret(0); |
| 6215 | } |
| 6216 | |
| 6217 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6218 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6219 | MacroAssembler* masm, |
| 6220 | Register left, |
| 6221 | Register right, |
| 6222 | Register length, |
| 6223 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6224 | Label* chars_not_equal, |
| 6225 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6226 | // Change index to run from -length to -1 by adding length to string |
| 6227 | // start. This means that loop ends when index reaches zero, which |
| 6228 | // doesn't need an additional compare. |
| 6229 | __ SmiUntag(length); |
| 6230 | __ lea(left, |
| 6231 | FieldOperand(left, length, times_1, SeqAsciiString::kHeaderSize)); |
| 6232 | __ lea(right, |
| 6233 | FieldOperand(right, length, times_1, SeqAsciiString::kHeaderSize)); |
| 6234 | __ neg(length); |
| 6235 | Register index = length; // index = -length; |
| 6236 | |
| 6237 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6238 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6239 | __ bind(&loop); |
| 6240 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6241 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6242 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6243 | __ add(index, Immediate(1)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6244 | __ j(not_zero, &loop); |
| 6245 | } |
| 6246 | |
| 6247 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6248 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6249 | Label runtime; |
| 6250 | |
| 6251 | // Stack frame on entry. |
| 6252 | // esp[0]: return address |
| 6253 | // esp[4]: right string |
| 6254 | // esp[8]: left string |
| 6255 | |
| 6256 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6257 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6258 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6259 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6260 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6261 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6262 | STATIC_ASSERT(EQUAL == 0); |
| 6263 | STATIC_ASSERT(kSmiTag == 0); |
| 6264 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6265 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6266 | __ ret(2 * kPointerSize); |
| 6267 | |
| 6268 | __ bind(¬_same); |
| 6269 | |
| 6270 | // Check that both objects are sequential ascii strings. |
| 6271 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6272 | |
| 6273 | // Compare flat ascii strings. |
| 6274 | // Drop arguments from the stack. |
| 6275 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6276 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6277 | __ push(ecx); |
| 6278 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6279 | |
| 6280 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6281 | // tagged as a small integer. |
| 6282 | __ bind(&runtime); |
| 6283 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6284 | } |
| 6285 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6286 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6287 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
| 6288 | ASSERT(state_ == CompareIC::SMIS); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6289 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6290 | __ mov(ecx, edx); |
| 6291 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6292 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6293 | |
| 6294 | if (GetCondition() == equal) { |
| 6295 | // 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] | 6296 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6297 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6298 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6299 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6300 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6301 | // Correct sign of result in case of overflow. |
| 6302 | __ not_(edx); |
| 6303 | __ bind(&done); |
| 6304 | __ mov(eax, edx); |
| 6305 | } |
| 6306 | __ ret(0); |
| 6307 | |
| 6308 | __ bind(&miss); |
| 6309 | GenerateMiss(masm); |
| 6310 | } |
| 6311 | |
| 6312 | |
| 6313 | void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) { |
| 6314 | ASSERT(state_ == CompareIC::HEAP_NUMBERS); |
| 6315 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6316 | Label generic_stub; |
| 6317 | Label unordered; |
| 6318 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6319 | __ mov(ecx, edx); |
| 6320 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6321 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6322 | |
| 6323 | __ CmpObjectType(eax, HEAP_NUMBER_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6324 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6325 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6326 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6327 | |
| 6328 | // Inlining the double comparison and falling back to the general compare |
| 6329 | // stub if NaN is involved or SS2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6330 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6331 | CpuFeatures::Scope scope1(SSE2); |
| 6332 | CpuFeatures::Scope scope2(CMOV); |
| 6333 | |
| 6334 | // Load left and right operand |
| 6335 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6336 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 6337 | |
| 6338 | // Compare operands |
| 6339 | __ ucomisd(xmm0, xmm1); |
| 6340 | |
| 6341 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6342 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6343 | |
| 6344 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6345 | // Performing mov, because xor would destroy the flag register. |
| 6346 | __ mov(eax, 0); // equal |
| 6347 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6348 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6349 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6350 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6351 | __ ret(0); |
| 6352 | |
| 6353 | __ bind(&unordered); |
| 6354 | } |
| 6355 | |
| 6356 | CompareStub stub(GetCondition(), strict(), NO_COMPARE_FLAGS); |
| 6357 | __ bind(&generic_stub); |
| 6358 | __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 6359 | |
| 6360 | __ bind(&miss); |
| 6361 | GenerateMiss(masm); |
| 6362 | } |
| 6363 | |
| 6364 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6365 | void ICCompareStub::GenerateSymbols(MacroAssembler* masm) { |
| 6366 | ASSERT(state_ == CompareIC::SYMBOLS); |
| 6367 | ASSERT(GetCondition() == equal); |
| 6368 | |
| 6369 | // Registers containing left and right operands respectively. |
| 6370 | Register left = edx; |
| 6371 | Register right = eax; |
| 6372 | Register tmp1 = ecx; |
| 6373 | Register tmp2 = ebx; |
| 6374 | |
| 6375 | // Check that both operands are heap objects. |
| 6376 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6377 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6378 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6379 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6380 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6381 | |
| 6382 | // Check that both operands are symbols. |
| 6383 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6384 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6385 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6386 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6387 | STATIC_ASSERT(kSymbolTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6388 | __ and_(tmp1, tmp2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6389 | __ test(tmp1, Immediate(kIsSymbolMask)); |
| 6390 | __ j(zero, &miss, Label::kNear); |
| 6391 | |
| 6392 | // Symbols are compared by identity. |
| 6393 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6394 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6395 | // Make sure eax is non-zero. At this point input operands are |
| 6396 | // guaranteed to be non-zero. |
| 6397 | ASSERT(right.is(eax)); |
| 6398 | __ j(not_equal, &done, Label::kNear); |
| 6399 | STATIC_ASSERT(EQUAL == 0); |
| 6400 | STATIC_ASSERT(kSmiTag == 0); |
| 6401 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6402 | __ bind(&done); |
| 6403 | __ ret(0); |
| 6404 | |
| 6405 | __ bind(&miss); |
| 6406 | GenerateMiss(masm); |
| 6407 | } |
| 6408 | |
| 6409 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6410 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
| 6411 | ASSERT(state_ == CompareIC::STRINGS); |
| 6412 | ASSERT(GetCondition() == equal); |
| 6413 | Label miss; |
| 6414 | |
| 6415 | // Registers containing left and right operands respectively. |
| 6416 | Register left = edx; |
| 6417 | Register right = eax; |
| 6418 | Register tmp1 = ecx; |
| 6419 | Register tmp2 = ebx; |
| 6420 | Register tmp3 = edi; |
| 6421 | |
| 6422 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6423 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6424 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6425 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6426 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6427 | |
| 6428 | // Check that both operands are strings. This leaves the instance |
| 6429 | // types loaded in tmp1 and tmp2. |
| 6430 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6431 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6432 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6433 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6434 | __ mov(tmp3, tmp1); |
| 6435 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6436 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6437 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 6438 | __ j(not_zero, &miss); |
| 6439 | |
| 6440 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6441 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6442 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6443 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6444 | STATIC_ASSERT(EQUAL == 0); |
| 6445 | STATIC_ASSERT(kSmiTag == 0); |
| 6446 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6447 | __ ret(0); |
| 6448 | |
| 6449 | // Handle not identical strings. |
| 6450 | __ bind(¬_same); |
| 6451 | |
| 6452 | // Check that both strings are symbols. If they are, we're done |
| 6453 | // because we already know they are not identical. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6454 | Label do_compare; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6455 | STATIC_ASSERT(kSymbolTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6456 | __ and_(tmp1, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6457 | __ test(tmp1, Immediate(kIsSymbolMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6458 | __ j(zero, &do_compare, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6459 | // Make sure eax is non-zero. At this point input operands are |
| 6460 | // guaranteed to be non-zero. |
| 6461 | ASSERT(right.is(eax)); |
| 6462 | __ ret(0); |
| 6463 | |
| 6464 | // Check that both strings are sequential ASCII. |
| 6465 | Label runtime; |
| 6466 | __ bind(&do_compare); |
| 6467 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 6468 | |
| 6469 | // Compare flat ASCII strings. Returns when done. |
| 6470 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6471 | masm, left, right, tmp1, tmp2); |
| 6472 | |
| 6473 | // Handle more complex cases in runtime. |
| 6474 | __ bind(&runtime); |
| 6475 | __ pop(tmp1); // Return address. |
| 6476 | __ push(left); |
| 6477 | __ push(right); |
| 6478 | __ push(tmp1); |
| 6479 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6480 | |
| 6481 | __ bind(&miss); |
| 6482 | GenerateMiss(masm); |
| 6483 | } |
| 6484 | |
| 6485 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6486 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
| 6487 | ASSERT(state_ == CompareIC::OBJECTS); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6488 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6489 | __ mov(ecx, edx); |
| 6490 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6491 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6492 | |
| 6493 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6494 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6495 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6496 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6497 | |
| 6498 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6499 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6500 | __ ret(0); |
| 6501 | |
| 6502 | __ bind(&miss); |
| 6503 | GenerateMiss(masm); |
| 6504 | } |
| 6505 | |
| 6506 | |
| 6507 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
| 6508 | // Save the registers. |
| 6509 | __ pop(ecx); |
| 6510 | __ push(edx); |
| 6511 | __ push(eax); |
| 6512 | __ push(ecx); |
| 6513 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6514 | { |
| 6515 | // Call the runtime system in a fresh internal frame. |
| 6516 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 6517 | masm->isolate()); |
| 6518 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 6519 | __ push(edx); |
| 6520 | __ push(eax); |
| 6521 | __ push(Immediate(Smi::FromInt(op_))); |
| 6522 | __ CallExternalReference(miss, 3); |
| 6523 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6524 | |
| 6525 | // Compute the entry point of the rewritten stub. |
| 6526 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 6527 | |
| 6528 | // Restore registers. |
| 6529 | __ pop(ecx); |
| 6530 | __ pop(eax); |
| 6531 | __ pop(edx); |
| 6532 | __ push(ecx); |
| 6533 | |
| 6534 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6535 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6536 | } |
| 6537 | |
| 6538 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6539 | // Helper function used to check that the dictionary doesn't contain |
| 6540 | // the property. This function may return false negatives, so miss_label |
| 6541 | // must always call a backup property check that is complete. |
| 6542 | // This function is safe to call if the receiver has fast properties. |
| 6543 | // 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] | 6544 | void StringDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 6545 | Label* miss, |
| 6546 | Label* done, |
| 6547 | Register properties, |
| 6548 | Handle<String> name, |
| 6549 | Register r0) { |
| 6550 | ASSERT(name->IsSymbol()); |
| 6551 | |
| 6552 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6553 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6554 | // undefined value), it guarantees the hash table doesn't contain the |
| 6555 | // property. It's true even if some slots represent deleted properties |
| 6556 | // (their names are the null value). |
| 6557 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6558 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6559 | Register index = r0; |
| 6560 | // Capacity is smi 2^n. |
| 6561 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 6562 | __ dec(index); |
| 6563 | __ and_(index, |
| 6564 | Immediate(Smi::FromInt(name->Hash() + |
| 6565 | StringDictionary::GetProbeOffset(i)))); |
| 6566 | |
| 6567 | // Scale the index by multiplying by the entry size. |
| 6568 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6569 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 6570 | Register entity_name = r0; |
| 6571 | // Having undefined at this place means the name is not contained. |
| 6572 | ASSERT_EQ(kSmiTagSize, 1); |
| 6573 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 6574 | kElementsStartOffset - kHeapObjectTag)); |
| 6575 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 6576 | __ j(equal, done); |
| 6577 | |
| 6578 | // Stop if found the property. |
| 6579 | __ cmp(entity_name, Handle<String>(name)); |
| 6580 | __ j(equal, miss); |
| 6581 | |
| 6582 | // Check if the entry name is not a symbol. |
| 6583 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 6584 | __ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 6585 | kIsSymbolMask); |
| 6586 | __ j(zero, miss); |
| 6587 | } |
| 6588 | |
| 6589 | StringDictionaryLookupStub stub(properties, |
| 6590 | r0, |
| 6591 | r0, |
| 6592 | StringDictionaryLookupStub::NEGATIVE_LOOKUP); |
| 6593 | __ push(Immediate(Handle<Object>(name))); |
| 6594 | __ push(Immediate(name->Hash())); |
| 6595 | __ CallStub(&stub); |
| 6596 | __ test(r0, r0); |
| 6597 | __ j(not_zero, miss); |
| 6598 | __ jmp(done); |
| 6599 | } |
| 6600 | |
| 6601 | |
| 6602 | // TODO(kmillikin): Eliminate this function when the stub cache is fully |
| 6603 | // handlified. |
| 6604 | MaybeObject* StringDictionaryLookupStub::TryGenerateNegativeLookup( |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6605 | MacroAssembler* masm, |
| 6606 | Label* miss, |
| 6607 | Label* done, |
| 6608 | Register properties, |
| 6609 | String* name, |
| 6610 | Register r0) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6611 | ASSERT(name->IsSymbol()); |
| 6612 | |
| 6613 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6614 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6615 | // undefined value), it guarantees the hash table doesn't contain the |
| 6616 | // property. It's true even if some slots represent deleted properties |
| 6617 | // (their names are the null value). |
| 6618 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6619 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6620 | Register index = r0; |
| 6621 | // Capacity is smi 2^n. |
| 6622 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 6623 | __ dec(index); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6624 | __ and_(index, |
| 6625 | Immediate(Smi::FromInt(name->Hash() + |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6626 | StringDictionary::GetProbeOffset(i)))); |
| 6627 | |
| 6628 | // Scale the index by multiplying by the entry size. |
| 6629 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6630 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 6631 | Register entity_name = r0; |
| 6632 | // Having undefined at this place means the name is not contained. |
| 6633 | ASSERT_EQ(kSmiTagSize, 1); |
| 6634 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 6635 | kElementsStartOffset - kHeapObjectTag)); |
| 6636 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6637 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6638 | |
| 6639 | // Stop if found the property. |
| 6640 | __ cmp(entity_name, Handle<String>(name)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6641 | __ j(equal, miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6642 | |
| 6643 | // Check if the entry name is not a symbol. |
| 6644 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 6645 | __ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 6646 | kIsSymbolMask); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6647 | __ j(zero, miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6648 | } |
| 6649 | |
| 6650 | StringDictionaryLookupStub stub(properties, |
| 6651 | r0, |
| 6652 | r0, |
| 6653 | StringDictionaryLookupStub::NEGATIVE_LOOKUP); |
| 6654 | __ push(Immediate(Handle<Object>(name))); |
| 6655 | __ push(Immediate(name->Hash())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6656 | MaybeObject* result = masm->TryCallStub(&stub); |
| 6657 | if (result->IsFailure()) return result; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6658 | __ test(r0, r0); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6659 | __ j(not_zero, miss); |
| 6660 | __ jmp(done); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6661 | return result; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6662 | } |
| 6663 | |
| 6664 | |
| 6665 | // Probe the string dictionary in the |elements| register. Jump to the |
| 6666 | // |done| label if a property with the given name is found leaving the |
| 6667 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 6668 | // otherwise. |
| 6669 | void StringDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 6670 | Label* miss, |
| 6671 | Label* done, |
| 6672 | Register elements, |
| 6673 | Register name, |
| 6674 | Register r0, |
| 6675 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame^] | 6676 | ASSERT(!elements.is(r0)); |
| 6677 | ASSERT(!elements.is(r1)); |
| 6678 | ASSERT(!name.is(r0)); |
| 6679 | ASSERT(!name.is(r1)); |
| 6680 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6681 | // Assert that name contains a string. |
| 6682 | if (FLAG_debug_code) __ AbortIfNotString(name); |
| 6683 | |
| 6684 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 6685 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 6686 | __ dec(r1); |
| 6687 | |
| 6688 | // Generate an unrolled loop that performs a few probes before |
| 6689 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 6690 | // cover ~93% of loads from dictionaries. |
| 6691 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6692 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6693 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 6694 | __ shr(r0, String::kHashShift); |
| 6695 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6696 | __ add(r0, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6697 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6698 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6699 | |
| 6700 | // Scale the index by multiplying by the entry size. |
| 6701 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6702 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 6703 | |
| 6704 | // Check if the key is identical to the name. |
| 6705 | __ cmp(name, Operand(elements, |
| 6706 | r0, |
| 6707 | times_4, |
| 6708 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6709 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6710 | } |
| 6711 | |
| 6712 | StringDictionaryLookupStub stub(elements, |
| 6713 | r1, |
| 6714 | r0, |
| 6715 | POSITIVE_LOOKUP); |
| 6716 | __ push(name); |
| 6717 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 6718 | __ shr(r0, String::kHashShift); |
| 6719 | __ push(r0); |
| 6720 | __ CallStub(&stub); |
| 6721 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6722 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6723 | __ j(zero, miss); |
| 6724 | __ jmp(done); |
| 6725 | } |
| 6726 | |
| 6727 | |
| 6728 | void StringDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6729 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 6730 | // 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] | 6731 | // Stack frame on entry: |
| 6732 | // esp[0 * kPointerSize]: return address. |
| 6733 | // esp[1 * kPointerSize]: key's hash. |
| 6734 | // esp[2 * kPointerSize]: key. |
| 6735 | // Registers: |
| 6736 | // dictionary_: StringDictionary to probe. |
| 6737 | // result_: used as scratch. |
| 6738 | // index_: will hold an index of entry if lookup is successful. |
| 6739 | // might alias with result_. |
| 6740 | // Returns: |
| 6741 | // result_ is zero if lookup failed, non zero otherwise. |
| 6742 | |
| 6743 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 6744 | |
| 6745 | Register scratch = result_; |
| 6746 | |
| 6747 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 6748 | __ dec(scratch); |
| 6749 | __ SmiUntag(scratch); |
| 6750 | __ push(scratch); |
| 6751 | |
| 6752 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6753 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6754 | // undefined value), it guarantees the hash table doesn't contain the |
| 6755 | // property. It's true even if some slots represent deleted properties |
| 6756 | // (their names are the null value). |
| 6757 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 6758 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6759 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 6760 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6761 | __ add(scratch, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6762 | } |
| 6763 | __ and_(scratch, Operand(esp, 0)); |
| 6764 | |
| 6765 | // Scale the index by multiplying by the entry size. |
| 6766 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6767 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 6768 | |
| 6769 | // Having undefined at this place means the name is not contained. |
| 6770 | ASSERT_EQ(kSmiTagSize, 1); |
| 6771 | __ mov(scratch, Operand(dictionary_, |
| 6772 | index_, |
| 6773 | times_pointer_size, |
| 6774 | kElementsStartOffset - kHeapObjectTag)); |
| 6775 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 6776 | __ j(equal, ¬_in_dictionary); |
| 6777 | |
| 6778 | // Stop if found the property. |
| 6779 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 6780 | __ j(equal, &in_dictionary); |
| 6781 | |
| 6782 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
| 6783 | // If we hit a non symbol key during negative lookup |
| 6784 | // we have to bailout as this key might be equal to the |
| 6785 | // key we are looking for. |
| 6786 | |
| 6787 | // Check if the entry name is not a symbol. |
| 6788 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 6789 | __ test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 6790 | kIsSymbolMask); |
| 6791 | __ j(zero, &maybe_in_dictionary); |
| 6792 | } |
| 6793 | } |
| 6794 | |
| 6795 | __ bind(&maybe_in_dictionary); |
| 6796 | // If we are doing negative lookup then probing failure should be |
| 6797 | // treated as a lookup success. For positive lookup probing failure |
| 6798 | // should be treated as lookup failure. |
| 6799 | if (mode_ == POSITIVE_LOOKUP) { |
| 6800 | __ mov(result_, Immediate(0)); |
| 6801 | __ Drop(1); |
| 6802 | __ ret(2 * kPointerSize); |
| 6803 | } |
| 6804 | |
| 6805 | __ bind(&in_dictionary); |
| 6806 | __ mov(result_, Immediate(1)); |
| 6807 | __ Drop(1); |
| 6808 | __ ret(2 * kPointerSize); |
| 6809 | |
| 6810 | __ bind(¬_in_dictionary); |
| 6811 | __ mov(result_, Immediate(0)); |
| 6812 | __ Drop(1); |
| 6813 | __ ret(2 * kPointerSize); |
| 6814 | } |
| 6815 | |
| 6816 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6817 | struct AheadOfTimeWriteBarrierStubList { |
| 6818 | Register object, value, address; |
| 6819 | RememberedSetAction action; |
| 6820 | }; |
| 6821 | |
| 6822 | |
| 6823 | struct AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
| 6824 | // Used in RegExpExecStub. |
| 6825 | { ebx, eax, edi, EMIT_REMEMBERED_SET }, |
| 6826 | // Used in CompileArrayPushCall. |
| 6827 | { ebx, ecx, edx, EMIT_REMEMBERED_SET }, |
| 6828 | { ebx, edi, edx, OMIT_REMEMBERED_SET }, |
| 6829 | // Used in CompileStoreGlobal and CallFunctionStub. |
| 6830 | { ebx, ecx, edx, OMIT_REMEMBERED_SET }, |
| 6831 | // Used in StoreStubCompiler::CompileStoreField and |
| 6832 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
| 6833 | { edx, ecx, ebx, EMIT_REMEMBERED_SET }, |
| 6834 | // GenerateStoreField calls the stub with two different permutations of |
| 6835 | // registers. This is the second. |
| 6836 | { ebx, ecx, edx, EMIT_REMEMBERED_SET }, |
| 6837 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
| 6838 | { ebx, edi, edx, EMIT_REMEMBERED_SET }, |
| 6839 | // KeyedStoreIC::GenerateGeneric. |
| 6840 | { ebx, edx, ecx, EMIT_REMEMBERED_SET}, |
| 6841 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
| 6842 | { edi, edx, ecx, EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6843 | // ElementsTransitionGenerator::GenerateSmiOnlyToObject |
| 6844 | // and ElementsTransitionGenerator::GenerateSmiOnlyToDouble |
| 6845 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
| 6846 | { edx, ebx, edi, EMIT_REMEMBERED_SET}, |
| 6847 | // ElementsTransitionGenerator::GenerateDoubleToObject |
| 6848 | { eax, edx, esi, EMIT_REMEMBERED_SET}, |
| 6849 | { edx, eax, edi, EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6850 | // Null termination. |
| 6851 | { no_reg, no_reg, no_reg, EMIT_REMEMBERED_SET} |
| 6852 | }; |
| 6853 | |
| 6854 | |
| 6855 | bool RecordWriteStub::IsPregenerated() { |
| 6856 | for (AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
| 6857 | !entry->object.is(no_reg); |
| 6858 | entry++) { |
| 6859 | if (object_.is(entry->object) && |
| 6860 | value_.is(entry->value) && |
| 6861 | address_.is(entry->address) && |
| 6862 | remembered_set_action_ == entry->action && |
| 6863 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 6864 | return true; |
| 6865 | } |
| 6866 | } |
| 6867 | return false; |
| 6868 | } |
| 6869 | |
| 6870 | |
| 6871 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime() { |
| 6872 | StoreBufferOverflowStub stub1(kDontSaveFPRegs); |
| 6873 | stub1.GetCode()->set_is_pregenerated(true); |
| 6874 | |
| 6875 | CpuFeatures::TryForceFeatureScope scope(SSE2); |
| 6876 | if (CpuFeatures::IsSupported(SSE2)) { |
| 6877 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
| 6878 | stub2.GetCode()->set_is_pregenerated(true); |
| 6879 | } |
| 6880 | } |
| 6881 | |
| 6882 | |
| 6883 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime() { |
| 6884 | for (AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
| 6885 | !entry->object.is(no_reg); |
| 6886 | entry++) { |
| 6887 | RecordWriteStub stub(entry->object, |
| 6888 | entry->value, |
| 6889 | entry->address, |
| 6890 | entry->action, |
| 6891 | kDontSaveFPRegs); |
| 6892 | stub.GetCode()->set_is_pregenerated(true); |
| 6893 | } |
| 6894 | } |
| 6895 | |
| 6896 | |
| 6897 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 6898 | // the value has just been written into the object, now this stub makes sure |
| 6899 | // we keep the GC informed. The word in the object where the value has been |
| 6900 | // written is in the address register. |
| 6901 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 6902 | Label skip_to_incremental_noncompacting; |
| 6903 | Label skip_to_incremental_compacting; |
| 6904 | |
| 6905 | // The first two instructions are generated with labels so as to get the |
| 6906 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 6907 | // forth between a compare instructions (a nop in this position) and the |
| 6908 | // real branch when we start and stop incremental heap marking. |
| 6909 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 6910 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 6911 | |
| 6912 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 6913 | __ RememberedSetHelper(object_, |
| 6914 | address_, |
| 6915 | value_, |
| 6916 | save_fp_regs_mode_, |
| 6917 | MacroAssembler::kReturnAtEnd); |
| 6918 | } else { |
| 6919 | __ ret(0); |
| 6920 | } |
| 6921 | |
| 6922 | __ bind(&skip_to_incremental_noncompacting); |
| 6923 | GenerateIncremental(masm, INCREMENTAL); |
| 6924 | |
| 6925 | __ bind(&skip_to_incremental_compacting); |
| 6926 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 6927 | |
| 6928 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 6929 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 6930 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 6931 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 6932 | } |
| 6933 | |
| 6934 | |
| 6935 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 6936 | regs_.Save(masm); |
| 6937 | |
| 6938 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 6939 | Label dont_need_remembered_set; |
| 6940 | |
| 6941 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 6942 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 6943 | regs_.scratch0(), |
| 6944 | &dont_need_remembered_set); |
| 6945 | |
| 6946 | __ CheckPageFlag(regs_.object(), |
| 6947 | regs_.scratch0(), |
| 6948 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 6949 | not_zero, |
| 6950 | &dont_need_remembered_set); |
| 6951 | |
| 6952 | // First notify the incremental marker if necessary, then update the |
| 6953 | // remembered set. |
| 6954 | CheckNeedsToInformIncrementalMarker( |
| 6955 | masm, |
| 6956 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 6957 | mode); |
| 6958 | InformIncrementalMarker(masm, mode); |
| 6959 | regs_.Restore(masm); |
| 6960 | __ RememberedSetHelper(object_, |
| 6961 | address_, |
| 6962 | value_, |
| 6963 | save_fp_regs_mode_, |
| 6964 | MacroAssembler::kReturnAtEnd); |
| 6965 | |
| 6966 | __ bind(&dont_need_remembered_set); |
| 6967 | } |
| 6968 | |
| 6969 | CheckNeedsToInformIncrementalMarker( |
| 6970 | masm, |
| 6971 | kReturnOnNoNeedToInformIncrementalMarker, |
| 6972 | mode); |
| 6973 | InformIncrementalMarker(masm, mode); |
| 6974 | regs_.Restore(masm); |
| 6975 | __ ret(0); |
| 6976 | } |
| 6977 | |
| 6978 | |
| 6979 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 6980 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 6981 | int argument_count = 3; |
| 6982 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 6983 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
| 6984 | if (mode == INCREMENTAL_COMPACTION) { |
| 6985 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
| 6986 | } else { |
| 6987 | ASSERT(mode == INCREMENTAL); |
| 6988 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 6989 | __ mov(Operand(esp, 1 * kPointerSize), regs_.scratch0()); // Value. |
| 6990 | } |
| 6991 | __ mov(Operand(esp, 2 * kPointerSize), |
| 6992 | Immediate(ExternalReference::isolate_address())); |
| 6993 | |
| 6994 | AllowExternalCallThatCantCauseGC scope(masm); |
| 6995 | if (mode == INCREMENTAL_COMPACTION) { |
| 6996 | __ CallCFunction( |
| 6997 | ExternalReference::incremental_evacuation_record_write_function( |
| 6998 | masm->isolate()), |
| 6999 | argument_count); |
| 7000 | } else { |
| 7001 | ASSERT(mode == INCREMENTAL); |
| 7002 | __ CallCFunction( |
| 7003 | ExternalReference::incremental_marking_record_write_function( |
| 7004 | masm->isolate()), |
| 7005 | argument_count); |
| 7006 | } |
| 7007 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7008 | } |
| 7009 | |
| 7010 | |
| 7011 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7012 | MacroAssembler* masm, |
| 7013 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7014 | Mode mode) { |
| 7015 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7016 | |
| 7017 | // Let's look at the color of the object: If it is not black we don't have |
| 7018 | // to inform the incremental marker. |
| 7019 | __ JumpIfBlack(regs_.object(), |
| 7020 | regs_.scratch0(), |
| 7021 | regs_.scratch1(), |
| 7022 | &object_is_black, |
| 7023 | Label::kNear); |
| 7024 | |
| 7025 | regs_.Restore(masm); |
| 7026 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7027 | __ RememberedSetHelper(object_, |
| 7028 | address_, |
| 7029 | value_, |
| 7030 | save_fp_regs_mode_, |
| 7031 | MacroAssembler::kReturnAtEnd); |
| 7032 | } else { |
| 7033 | __ ret(0); |
| 7034 | } |
| 7035 | |
| 7036 | __ bind(&object_is_black); |
| 7037 | |
| 7038 | // Get the value from the slot. |
| 7039 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7040 | |
| 7041 | if (mode == INCREMENTAL_COMPACTION) { |
| 7042 | Label ensure_not_white; |
| 7043 | |
| 7044 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7045 | regs_.scratch1(), // Scratch. |
| 7046 | MemoryChunk::kEvacuationCandidateMask, |
| 7047 | zero, |
| 7048 | &ensure_not_white, |
| 7049 | Label::kNear); |
| 7050 | |
| 7051 | __ CheckPageFlag(regs_.object(), |
| 7052 | regs_.scratch1(), // Scratch. |
| 7053 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7054 | not_zero, |
| 7055 | &ensure_not_white, |
| 7056 | Label::kNear); |
| 7057 | |
| 7058 | __ jmp(&need_incremental); |
| 7059 | |
| 7060 | __ bind(&ensure_not_white); |
| 7061 | } |
| 7062 | |
| 7063 | // We need an extra register for this, so we push the object register |
| 7064 | // temporarily. |
| 7065 | __ push(regs_.object()); |
| 7066 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7067 | regs_.scratch1(), // Scratch. |
| 7068 | regs_.object(), // Scratch. |
| 7069 | &need_incremental_pop_object, |
| 7070 | Label::kNear); |
| 7071 | __ pop(regs_.object()); |
| 7072 | |
| 7073 | regs_.Restore(masm); |
| 7074 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7075 | __ RememberedSetHelper(object_, |
| 7076 | address_, |
| 7077 | value_, |
| 7078 | save_fp_regs_mode_, |
| 7079 | MacroAssembler::kReturnAtEnd); |
| 7080 | } else { |
| 7081 | __ ret(0); |
| 7082 | } |
| 7083 | |
| 7084 | __ bind(&need_incremental_pop_object); |
| 7085 | __ pop(regs_.object()); |
| 7086 | |
| 7087 | __ bind(&need_incremental); |
| 7088 | |
| 7089 | // Fall through when we need to inform the incremental marker. |
| 7090 | } |
| 7091 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7092 | #undef __ |
| 7093 | |
| 7094 | } } // namespace v8::internal |
| 7095 | |
| 7096 | #endif // V8_TARGET_ARCH_IA32 |