yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #if defined(V8_TARGET_ARCH_IA32) |
| 31 | |
| 32 | #include "bootstrapper.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 33 | #include "code-stubs.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 34 | #include "isolate.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 35 | #include "jsregexp.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 36 | #include "regexp-macro-assembler.h" |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 37 | #include "stub-cache.h" |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 38 | #include "codegen.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 39 | |
| 40 | namespace v8 { |
| 41 | namespace internal { |
| 42 | |
| 43 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 44 | |
| 45 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 46 | // The ToNumber stub takes one argument in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 47 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 48 | __ JumpIfNotSmi(eax, &check_heap_number, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 49 | __ ret(0); |
| 50 | |
| 51 | __ bind(&check_heap_number); |
| 52 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 53 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 54 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 55 | __ j(not_equal, &call_builtin, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 56 | __ ret(0); |
| 57 | |
| 58 | __ bind(&call_builtin); |
| 59 | __ pop(ecx); // Pop return address. |
| 60 | __ push(eax); |
| 61 | __ push(ecx); // Push return address. |
| 62 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
| 63 | } |
| 64 | |
| 65 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 66 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 67 | // Create a new closure from the given function info in new |
| 68 | // space. Set the context to the current context in esi. |
| 69 | Label gc; |
| 70 | __ AllocateInNewSpace(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
| 71 | |
| 72 | // Get the function info from the stack. |
| 73 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 74 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 75 | int map_index = (language_mode_ == CLASSIC_MODE) |
| 76 | ? Context::FUNCTION_MAP_INDEX |
| 77 | : Context::STRICT_MODE_FUNCTION_MAP_INDEX; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 78 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 79 | // Compute the function map in the current global context and set that |
| 80 | // as the map of the allocated object. |
| 81 | __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 82 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalContextOffset)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 83 | __ mov(ecx, Operand(ecx, Context::SlotOffset(map_index))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 84 | __ mov(FieldOperand(eax, JSObject::kMapOffset), ecx); |
| 85 | |
| 86 | // Initialize the rest of the function. We don't have to update the |
| 87 | // write barrier because the allocated object is in new space. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 88 | Factory* factory = masm->isolate()->factory(); |
| 89 | __ mov(ebx, Immediate(factory->empty_fixed_array())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 90 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 91 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 92 | __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 93 | Immediate(factory->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 94 | __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 95 | __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 96 | __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 97 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 98 | Immediate(factory->undefined_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 99 | |
| 100 | // Initialize the code pointer in the function to be the one |
| 101 | // found in the shared function info object. |
| 102 | __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 103 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 104 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 105 | |
| 106 | // Return and remove the on-stack parameter. |
| 107 | __ ret(1 * kPointerSize); |
| 108 | |
| 109 | // Create a new closure through the slower runtime call. |
| 110 | __ bind(&gc); |
| 111 | __ pop(ecx); // Temporarily remove return address. |
| 112 | __ pop(edx); |
| 113 | __ push(esi); |
| 114 | __ push(edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 115 | __ push(Immediate(factory->false_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 116 | __ push(ecx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 117 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | |
| 121 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 122 | // Try to allocate the context in new space. |
| 123 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 124 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 125 | __ AllocateInNewSpace((length * kPointerSize) + FixedArray::kHeaderSize, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 126 | eax, ebx, ecx, &gc, TAG_OBJECT); |
| 127 | |
| 128 | // Get the function from the stack. |
| 129 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 130 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 131 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 132 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 133 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 134 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 135 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 136 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 137 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 138 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 139 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 140 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 141 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 142 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 143 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 144 | // Copy the global object from the previous context. |
| 145 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 146 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_INDEX)), ebx); |
| 147 | |
| 148 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 149 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 150 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 151 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 152 | } |
| 153 | |
| 154 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 155 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 156 | __ ret(1 * kPointerSize); |
| 157 | |
| 158 | // Need to collect. Call into runtime system. |
| 159 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 160 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 164 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 165 | // Stack layout on entry: |
| 166 | // |
| 167 | // [esp + (1 * kPointerSize)]: function |
| 168 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 169 | |
| 170 | // Try to allocate the context in new space. |
| 171 | Label gc; |
| 172 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 173 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
| 174 | eax, ebx, ecx, &gc, TAG_OBJECT); |
| 175 | |
| 176 | // Get the function or sentinel from the stack. |
| 177 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 178 | |
| 179 | // Get the serialized scope info from the stack. |
| 180 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 181 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 182 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 183 | Factory* factory = masm->isolate()->factory(); |
| 184 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 185 | factory->block_context_map()); |
| 186 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 187 | Immediate(Smi::FromInt(length))); |
| 188 | |
| 189 | // If this block context is nested in the global context we get a smi |
| 190 | // sentinel instead of a function. The block context should get the |
| 191 | // canonical empty function of the global context as its closure which |
| 192 | // we still have to look up. |
| 193 | Label after_sentinel; |
| 194 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 195 | if (FLAG_debug_code) { |
| 196 | const char* message = "Expected 0 as a Smi sentinel"; |
| 197 | __ cmp(ecx, 0); |
| 198 | __ Assert(equal, message); |
| 199 | } |
| 200 | __ mov(ecx, GlobalObjectOperand()); |
| 201 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalContextOffset)); |
| 202 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 203 | __ bind(&after_sentinel); |
| 204 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 205 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 206 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 207 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 208 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 209 | |
| 210 | // Copy the global object from the previous context. |
| 211 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_INDEX)); |
| 212 | __ mov(ContextOperand(eax, Context::GLOBAL_INDEX), ebx); |
| 213 | |
| 214 | // Initialize the rest of the slots to the hole value. |
| 215 | if (slots_ == 1) { |
| 216 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 217 | factory->the_hole_value()); |
| 218 | } else { |
| 219 | __ mov(ebx, factory->the_hole_value()); |
| 220 | for (int i = 0; i < slots_; i++) { |
| 221 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | // Return and remove the on-stack parameters. |
| 226 | __ mov(esi, eax); |
| 227 | __ ret(2 * kPointerSize); |
| 228 | |
| 229 | // Need to collect. Call into runtime system. |
| 230 | __ bind(&gc); |
| 231 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 232 | } |
| 233 | |
| 234 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 235 | static void GenerateFastCloneShallowArrayCommon( |
| 236 | MacroAssembler* masm, |
| 237 | int length, |
| 238 | FastCloneShallowArrayStub::Mode mode, |
| 239 | Label* fail) { |
| 240 | // Registers on entry: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 241 | // |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 242 | // ecx: boilerplate literal array. |
| 243 | ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 244 | |
| 245 | // All sizes here are multiples of kPointerSize. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 246 | int elements_size = 0; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 247 | if (length > 0) { |
| 248 | elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 249 | ? FixedDoubleArray::SizeFor(length) |
| 250 | : FixedArray::SizeFor(length); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 251 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 252 | int size = JSArray::kSize + elements_size; |
| 253 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 254 | // Allocate both the JS array and the elements array in one big |
| 255 | // allocation. This avoids multiple limit checks. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 256 | __ AllocateInNewSpace(size, eax, ebx, edx, fail, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 257 | |
| 258 | // Copy the JS array part. |
| 259 | for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 260 | if ((i != JSArray::kElementsOffset) || (length == 0)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 261 | __ mov(ebx, FieldOperand(ecx, i)); |
| 262 | __ mov(FieldOperand(eax, i), ebx); |
| 263 | } |
| 264 | } |
| 265 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 266 | if (length > 0) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 267 | // Get hold of the elements array of the boilerplate and setup the |
| 268 | // elements pointer in the resulting object. |
| 269 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 270 | __ lea(edx, Operand(eax, JSArray::kSize)); |
| 271 | __ mov(FieldOperand(eax, JSArray::kElementsOffset), edx); |
| 272 | |
| 273 | // Copy the elements array. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 274 | if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 275 | for (int i = 0; i < elements_size; i += kPointerSize) { |
| 276 | __ mov(ebx, FieldOperand(ecx, i)); |
| 277 | __ mov(FieldOperand(edx, i), ebx); |
| 278 | } |
| 279 | } else { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 280 | ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 281 | int i; |
| 282 | for (i = 0; i < FixedDoubleArray::kHeaderSize; i += kPointerSize) { |
| 283 | __ mov(ebx, FieldOperand(ecx, i)); |
| 284 | __ mov(FieldOperand(edx, i), ebx); |
| 285 | } |
| 286 | while (i < elements_size) { |
| 287 | __ fld_d(FieldOperand(ecx, i)); |
| 288 | __ fstp_d(FieldOperand(edx, i)); |
| 289 | i += kDoubleSize; |
| 290 | } |
| 291 | ASSERT(i == elements_size); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 292 | } |
| 293 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 294 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 295 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 296 | |
| 297 | void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) { |
| 298 | // Stack layout on entry: |
| 299 | // |
| 300 | // [esp + kPointerSize]: constant elements. |
| 301 | // [esp + (2 * kPointerSize)]: literal index. |
| 302 | // [esp + (3 * kPointerSize)]: literals array. |
| 303 | |
| 304 | // Load boilerplate object into ecx and check if we need to create a |
| 305 | // boilerplate. |
| 306 | __ mov(ecx, Operand(esp, 3 * kPointerSize)); |
| 307 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 308 | STATIC_ASSERT(kPointerSize == 4); |
| 309 | STATIC_ASSERT(kSmiTagSize == 1); |
| 310 | STATIC_ASSERT(kSmiTag == 0); |
| 311 | __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size, |
| 312 | FixedArray::kHeaderSize)); |
| 313 | Factory* factory = masm->isolate()->factory(); |
| 314 | __ cmp(ecx, factory->undefined_value()); |
| 315 | Label slow_case; |
| 316 | __ j(equal, &slow_case); |
| 317 | |
| 318 | FastCloneShallowArrayStub::Mode mode = mode_; |
| 319 | // ecx is boilerplate object. |
| 320 | if (mode == CLONE_ANY_ELEMENTS) { |
| 321 | Label double_elements, check_fast_elements; |
| 322 | __ mov(ebx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 323 | __ CheckMap(ebx, factory->fixed_cow_array_map(), |
| 324 | &check_fast_elements, DONT_DO_SMI_CHECK); |
| 325 | GenerateFastCloneShallowArrayCommon(masm, 0, |
| 326 | COPY_ON_WRITE_ELEMENTS, &slow_case); |
| 327 | __ ret(3 * kPointerSize); |
| 328 | |
| 329 | __ bind(&check_fast_elements); |
| 330 | __ CheckMap(ebx, factory->fixed_array_map(), |
| 331 | &double_elements, DONT_DO_SMI_CHECK); |
| 332 | GenerateFastCloneShallowArrayCommon(masm, length_, |
| 333 | CLONE_ELEMENTS, &slow_case); |
| 334 | __ ret(3 * kPointerSize); |
| 335 | |
| 336 | __ bind(&double_elements); |
| 337 | mode = CLONE_DOUBLE_ELEMENTS; |
| 338 | // Fall through to generate the code to handle double elements. |
| 339 | } |
| 340 | |
| 341 | if (FLAG_debug_code) { |
| 342 | const char* message; |
| 343 | Handle<Map> expected_map; |
| 344 | if (mode == CLONE_ELEMENTS) { |
| 345 | message = "Expected (writable) fixed array"; |
| 346 | expected_map = factory->fixed_array_map(); |
| 347 | } else if (mode == CLONE_DOUBLE_ELEMENTS) { |
| 348 | message = "Expected (writable) fixed double array"; |
| 349 | expected_map = factory->fixed_double_array_map(); |
| 350 | } else { |
| 351 | ASSERT(mode == COPY_ON_WRITE_ELEMENTS); |
| 352 | message = "Expected copy-on-write fixed array"; |
| 353 | expected_map = factory->fixed_cow_array_map(); |
| 354 | } |
| 355 | __ push(ecx); |
| 356 | __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |
| 357 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), expected_map); |
| 358 | __ Assert(equal, message); |
| 359 | __ pop(ecx); |
| 360 | } |
| 361 | |
| 362 | GenerateFastCloneShallowArrayCommon(masm, length_, mode, &slow_case); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 363 | // Return and remove the on-stack parameters. |
| 364 | __ ret(3 * kPointerSize); |
| 365 | |
| 366 | __ bind(&slow_case); |
| 367 | __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
| 368 | } |
| 369 | |
| 370 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 371 | void FastCloneShallowObjectStub::Generate(MacroAssembler* masm) { |
| 372 | // Stack layout on entry: |
| 373 | // |
| 374 | // [esp + kPointerSize]: object literal flags. |
| 375 | // [esp + (2 * kPointerSize)]: constant properties. |
| 376 | // [esp + (3 * kPointerSize)]: literal index. |
| 377 | // [esp + (4 * kPointerSize)]: literals array. |
| 378 | |
| 379 | // Load boilerplate object into ecx and check if we need to create a |
| 380 | // boilerplate. |
| 381 | Label slow_case; |
| 382 | __ mov(ecx, Operand(esp, 4 * kPointerSize)); |
| 383 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 384 | STATIC_ASSERT(kPointerSize == 4); |
| 385 | STATIC_ASSERT(kSmiTagSize == 1); |
| 386 | STATIC_ASSERT(kSmiTag == 0); |
| 387 | __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size, |
| 388 | FixedArray::kHeaderSize)); |
| 389 | Factory* factory = masm->isolate()->factory(); |
| 390 | __ cmp(ecx, factory->undefined_value()); |
| 391 | __ j(equal, &slow_case); |
| 392 | |
| 393 | // Check that the boilerplate contains only fast properties and we can |
| 394 | // statically determine the instance size. |
| 395 | int size = JSObject::kHeaderSize + length_ * kPointerSize; |
| 396 | __ mov(eax, FieldOperand(ecx, HeapObject::kMapOffset)); |
| 397 | __ movzx_b(eax, FieldOperand(eax, Map::kInstanceSizeOffset)); |
| 398 | __ cmp(eax, Immediate(size >> kPointerSizeLog2)); |
| 399 | __ j(not_equal, &slow_case); |
| 400 | |
| 401 | // Allocate the JS object and copy header together with all in-object |
| 402 | // properties from the boilerplate. |
| 403 | __ AllocateInNewSpace(size, eax, ebx, edx, &slow_case, TAG_OBJECT); |
| 404 | for (int i = 0; i < size; i += kPointerSize) { |
| 405 | __ mov(ebx, FieldOperand(ecx, i)); |
| 406 | __ mov(FieldOperand(eax, i), ebx); |
| 407 | } |
| 408 | |
| 409 | // Return and remove the on-stack parameters. |
| 410 | __ ret(4 * kPointerSize); |
| 411 | |
| 412 | __ bind(&slow_case); |
| 413 | __ TailCallRuntime(Runtime::kCreateObjectLiteralShallow, 4, 1); |
| 414 | } |
| 415 | |
| 416 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 417 | // The stub expects its argument on the stack and returns its result in tos_: |
| 418 | // zero for false, and a non-zero value for true. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 419 | void ToBooleanStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 420 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 421 | // 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] | 422 | Label patch; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 423 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 424 | const Register argument = eax; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 425 | const Register map = edx; |
| 426 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 427 | if (!types_.IsEmpty()) { |
| 428 | __ mov(argument, Operand(esp, 1 * kPointerSize)); |
| 429 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 430 | |
| 431 | // undefined -> false |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 432 | CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 433 | |
| 434 | // Boolean -> its value |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 435 | CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); |
| 436 | CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 437 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 438 | // 'null' -> false. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 439 | CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 440 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 441 | if (types_.Contains(SMI)) { |
| 442 | // Smis: 0 -> false, all other -> true |
| 443 | Label not_smi; |
| 444 | __ JumpIfNotSmi(argument, ¬_smi, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 445 | // argument contains the correct return value already. |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 446 | if (!tos_.is(argument)) { |
| 447 | __ mov(tos_, argument); |
| 448 | } |
| 449 | __ ret(1 * kPointerSize); |
| 450 | __ bind(¬_smi); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 451 | } else if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 452 | // If we need a map later and have a Smi -> patch. |
| 453 | __ JumpIfSmi(argument, &patch, Label::kNear); |
| 454 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 455 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 456 | if (types_.NeedsMap()) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 457 | __ mov(map, FieldOperand(argument, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 458 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 459 | if (types_.CanBeUndetectable()) { |
| 460 | __ test_b(FieldOperand(map, Map::kBitFieldOffset), |
| 461 | 1 << Map::kIsUndetectable); |
| 462 | // Undetectable -> false. |
| 463 | Label not_undetectable; |
| 464 | __ j(zero, ¬_undetectable, Label::kNear); |
| 465 | __ Set(tos_, Immediate(0)); |
| 466 | __ ret(1 * kPointerSize); |
| 467 | __ bind(¬_undetectable); |
| 468 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 469 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 470 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 471 | if (types_.Contains(SPEC_OBJECT)) { |
| 472 | // spec object -> true. |
| 473 | Label not_js_object; |
| 474 | __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
| 475 | __ j(below, ¬_js_object, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 476 | // argument contains the correct return value already. |
| 477 | if (!tos_.is(argument)) { |
| 478 | __ Set(tos_, Immediate(1)); |
| 479 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 480 | __ ret(1 * kPointerSize); |
| 481 | __ bind(¬_js_object); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 482 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 483 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 484 | if (types_.Contains(STRING)) { |
| 485 | // String value -> false iff empty. |
| 486 | Label not_string; |
| 487 | __ CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
| 488 | __ j(above_equal, ¬_string, Label::kNear); |
| 489 | __ mov(tos_, FieldOperand(argument, String::kLengthOffset)); |
| 490 | __ ret(1 * kPointerSize); // the string length is OK as the return value |
| 491 | __ bind(¬_string); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | if (types_.Contains(HEAP_NUMBER)) { |
| 495 | // heap number -> false iff +0, -0, or NaN. |
| 496 | Label not_heap_number, false_result; |
| 497 | __ cmp(map, factory->heap_number_map()); |
| 498 | __ j(not_equal, ¬_heap_number, Label::kNear); |
| 499 | __ fldz(); |
| 500 | __ fld_d(FieldOperand(argument, HeapNumber::kValueOffset)); |
| 501 | __ FCmp(); |
| 502 | __ j(zero, &false_result, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 503 | // argument contains the correct return value already. |
| 504 | if (!tos_.is(argument)) { |
| 505 | __ Set(tos_, Immediate(1)); |
| 506 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 507 | __ ret(1 * kPointerSize); |
| 508 | __ bind(&false_result); |
| 509 | __ Set(tos_, Immediate(0)); |
| 510 | __ ret(1 * kPointerSize); |
| 511 | __ bind(¬_heap_number); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 512 | } |
| 513 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 514 | __ bind(&patch); |
| 515 | GenerateTypeTransition(masm); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 519 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 520 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 521 | // store the registers in any particular way, but we do have to store and |
| 522 | // restore them. |
| 523 | __ pushad(); |
| 524 | if (save_doubles_ == kSaveFPRegs) { |
| 525 | CpuFeatures::Scope scope(SSE2); |
| 526 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 527 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 528 | XMMRegister reg = XMMRegister::from_code(i); |
| 529 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 530 | } |
| 531 | } |
| 532 | const int argument_count = 1; |
| 533 | |
| 534 | AllowExternalCallThatCantCauseGC scope(masm); |
| 535 | __ PrepareCallCFunction(argument_count, ecx); |
| 536 | __ mov(Operand(esp, 0 * kPointerSize), |
| 537 | Immediate(ExternalReference::isolate_address())); |
| 538 | __ CallCFunction( |
| 539 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 540 | argument_count); |
| 541 | if (save_doubles_ == kSaveFPRegs) { |
| 542 | CpuFeatures::Scope scope(SSE2); |
| 543 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 544 | XMMRegister reg = XMMRegister::from_code(i); |
| 545 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 546 | } |
| 547 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 548 | } |
| 549 | __ popad(); |
| 550 | __ ret(0); |
| 551 | } |
| 552 | |
| 553 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 554 | void ToBooleanStub::CheckOddball(MacroAssembler* masm, |
| 555 | Type type, |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 556 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 557 | bool result) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 558 | const Register argument = eax; |
| 559 | if (types_.Contains(type)) { |
| 560 | // If we see an expected oddball, return its ToBoolean value tos_. |
| 561 | Label different_value; |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 562 | __ CompareRoot(argument, value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 563 | __ j(not_equal, &different_value, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 564 | if (!result) { |
| 565 | // If we have to return zero, there is no way around clearing tos_. |
| 566 | __ Set(tos_, Immediate(0)); |
| 567 | } else if (!tos_.is(argument)) { |
| 568 | // If we have to return non-zero, we can re-use the argument if it is the |
| 569 | // same register as the result, because we never see Smi-zero here. |
| 570 | __ Set(tos_, Immediate(1)); |
| 571 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 572 | __ ret(1 * kPointerSize); |
| 573 | __ bind(&different_value); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | |
| 577 | |
| 578 | void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 579 | __ pop(ecx); // Get return address, operand is now on top of stack. |
| 580 | __ push(Immediate(Smi::FromInt(tos_.code()))); |
| 581 | __ push(Immediate(Smi::FromInt(types_.ToByte()))); |
| 582 | __ push(ecx); // Push return address. |
| 583 | // Patch the caller to an appropriate specialized stub and return the |
| 584 | // operation result to the caller of the stub. |
| 585 | __ TailCallExternalReference( |
| 586 | ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), |
| 587 | 3, |
| 588 | 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 592 | class FloatingPointHelper : public AllStatic { |
| 593 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 594 | enum ArgLocation { |
| 595 | ARGS_ON_STACK, |
| 596 | ARGS_IN_REGISTERS |
| 597 | }; |
| 598 | |
| 599 | // Code pattern for loading a floating point value. Input value must |
| 600 | // be either a smi or a heap number object (fp value). Requirements: |
| 601 | // operand in register number. Returns operand as floating point number |
| 602 | // on FPU stack. |
| 603 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 604 | |
| 605 | // Code pattern for loading floating point values. Input values must |
| 606 | // be either smi or heap number objects (fp values). Requirements: |
| 607 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 608 | // Returns operands as floating point numbers on FPU stack. |
| 609 | static void LoadFloatOperands(MacroAssembler* masm, |
| 610 | Register scratch, |
| 611 | ArgLocation arg_location = ARGS_ON_STACK); |
| 612 | |
| 613 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 614 | // Expects operands in edx, eax. |
| 615 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 616 | |
| 617 | // Test if operands are smi or number objects (fp). Requirements: |
| 618 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 619 | // operands, jumps to the non_float label otherwise. |
| 620 | static void CheckFloatOperands(MacroAssembler* masm, |
| 621 | Label* non_float, |
| 622 | Register scratch); |
| 623 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 624 | // Checks that the two floating point numbers on top of the FPU stack |
| 625 | // have int32 values. |
| 626 | static void CheckFloatOperandsAreInt32(MacroAssembler* masm, |
| 627 | Label* non_int32); |
| 628 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 629 | // Takes the operands in edx and eax and loads them as integers in eax |
| 630 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 631 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 632 | bool use_sse3, |
| 633 | Label* operand_conversion_failure); |
| 634 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 635 | // Must only be called after LoadUnknownsAsIntegers. Assumes that the |
| 636 | // operands are pushed on the stack, and that their conversions to int32 |
| 637 | // are in eax and ecx. Checks that the original numbers were in the int32 |
| 638 | // range. |
| 639 | static void CheckLoadedIntegersWereInt32(MacroAssembler* masm, |
| 640 | bool use_sse3, |
| 641 | Label* not_int32); |
| 642 | |
| 643 | // Assumes that operands are smis or heap numbers and loads them |
| 644 | // into xmm0 and xmm1. Operands are in edx and eax. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 645 | // Leaves operands unchanged. |
| 646 | static void LoadSSE2Operands(MacroAssembler* masm); |
| 647 | |
| 648 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 649 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 650 | // either operand is not a number. Operands are in edx and eax. |
| 651 | // Leaves operands unchanged. |
| 652 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 653 | |
| 654 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 655 | // Expects operands in edx, eax. |
| 656 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 657 | |
| 658 | // Checks that the two floating point numbers loaded into xmm0 and xmm1 |
| 659 | // have int32 values. |
| 660 | static void CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 661 | Label* non_int32, |
| 662 | Register scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 663 | }; |
| 664 | |
| 665 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 666 | // Get the integer part of a heap number. Surprisingly, all this bit twiddling |
| 667 | // is faster than using the built-in instructions on floating point registers. |
| 668 | // Trashes edi and ebx. Dest is ecx. Source cannot be ecx or one of the |
| 669 | // trashed registers. |
| 670 | static void IntegerConvert(MacroAssembler* masm, |
| 671 | Register source, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 672 | bool use_sse3, |
| 673 | Label* conversion_failure) { |
| 674 | ASSERT(!source.is(ecx) && !source.is(edi) && !source.is(ebx)); |
| 675 | Label done, right_exponent, normal_exponent; |
| 676 | Register scratch = ebx; |
| 677 | Register scratch2 = edi; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 678 | // Get exponent word. |
| 679 | __ mov(scratch, FieldOperand(source, HeapNumber::kExponentOffset)); |
| 680 | // Get exponent alone in scratch2. |
| 681 | __ mov(scratch2, scratch); |
| 682 | __ and_(scratch2, HeapNumber::kExponentMask); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 683 | if (use_sse3) { |
| 684 | CpuFeatures::Scope scope(SSE3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 685 | // Check whether the exponent is too big for a 64 bit signed integer. |
| 686 | static const uint32_t kTooBigExponent = |
| 687 | (HeapNumber::kExponentBias + 63) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 688 | __ cmp(scratch2, Immediate(kTooBigExponent)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 689 | __ j(greater_equal, conversion_failure); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 690 | // Load x87 register with heap number. |
| 691 | __ fld_d(FieldOperand(source, HeapNumber::kValueOffset)); |
| 692 | // Reserve space for 64 bit answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 693 | __ sub(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 694 | // Do conversion, which cannot fail because we checked the exponent. |
| 695 | __ fisttp_d(Operand(esp, 0)); |
| 696 | __ 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] | 697 | __ add(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 698 | } else { |
| 699 | // Load ecx with zero. We use this either for the final shift or |
| 700 | // for the answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 701 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 702 | // Check whether the exponent matches a 32 bit signed int that cannot be |
| 703 | // represented by a Smi. A non-smi 32 bit integer is 1.xxx * 2^30 so the |
| 704 | // exponent is 30 (biased). This is the exponent that we are fastest at and |
| 705 | // also the highest exponent we can handle here. |
| 706 | const uint32_t non_smi_exponent = |
| 707 | (HeapNumber::kExponentBias + 30) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 708 | __ cmp(scratch2, Immediate(non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 709 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 710 | // logic. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 711 | __ j(equal, &right_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 712 | // If the exponent is higher than that then go to slow case. This catches |
| 713 | // 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] | 714 | __ j(less, &normal_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 715 | |
| 716 | { |
| 717 | // Handle a big exponent. The only reason we have this code is that the |
| 718 | // >>> operator has a tendency to generate numbers with an exponent of 31. |
| 719 | const uint32_t big_non_smi_exponent = |
| 720 | (HeapNumber::kExponentBias + 31) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 721 | __ cmp(scratch2, Immediate(big_non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 722 | __ j(not_equal, conversion_failure); |
| 723 | // We have the big exponent, typically from >>>. This means the number is |
| 724 | // in the range 2^31 to 2^32 - 1. Get the top bits of the mantissa. |
| 725 | __ mov(scratch2, scratch); |
| 726 | __ and_(scratch2, HeapNumber::kMantissaMask); |
| 727 | // Put back the implicit 1. |
| 728 | __ or_(scratch2, 1 << HeapNumber::kExponentShift); |
| 729 | // Shift up the mantissa bits to take up the space the exponent used to |
| 730 | // take. We just orred in the implicit bit so that took care of one and |
| 731 | // we want to use the full unsigned range so we subtract 1 bit from the |
| 732 | // shift distance. |
| 733 | const int big_shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 734 | __ shl(scratch2, big_shift_distance); |
| 735 | // Get the second half of the double. |
| 736 | __ mov(ecx, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 737 | // Shift down 21 bits to get the most significant 11 bits or the low |
| 738 | // mantissa word. |
| 739 | __ shr(ecx, 32 - big_shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 740 | __ or_(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 741 | // 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] | 742 | __ test(scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 743 | __ j(positive, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 744 | __ neg(ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 745 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | __ bind(&normal_exponent); |
| 749 | // Exponent word in scratch, exponent part of exponent word in scratch2. |
| 750 | // Zero in ecx. |
| 751 | // We know the exponent is smaller than 30 (biased). If it is less than |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 752 | // 0 (biased) then the number is smaller in magnitude than 1.0 * 2^0, i.e. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 753 | // it rounds to zero. |
| 754 | const uint32_t zero_exponent = |
| 755 | (HeapNumber::kExponentBias + 0) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 756 | __ sub(scratch2, Immediate(zero_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 757 | // ecx already has a Smi zero. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 758 | __ j(less, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 759 | |
| 760 | // We have a shifted exponent between 0 and 30 in scratch2. |
| 761 | __ shr(scratch2, HeapNumber::kExponentShift); |
| 762 | __ mov(ecx, Immediate(30)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 763 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 764 | |
| 765 | __ bind(&right_exponent); |
| 766 | // Here ecx is the shift, scratch is the exponent word. |
| 767 | // Get the top bits of the mantissa. |
| 768 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 769 | // Put back the implicit 1. |
| 770 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 771 | // Shift up the mantissa bits to take up the space the exponent used to |
| 772 | // take. We have kExponentShift + 1 significant bits int he low end of the |
| 773 | // word. Shift them to the top bits. |
| 774 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 775 | __ shl(scratch, shift_distance); |
| 776 | // Get the second half of the double. For some exponents we don't |
| 777 | // actually need this because the bits get shifted out again, but |
| 778 | // it's probably slower to test than just to do it. |
| 779 | __ mov(scratch2, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 780 | // Shift down 22 bits to get the most significant 10 bits or the low |
| 781 | // mantissa word. |
| 782 | __ shr(scratch2, 32 - shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 783 | __ or_(scratch2, scratch); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 784 | // Move down according to the exponent. |
| 785 | __ shr_cl(scratch2); |
| 786 | // Now the unsigned answer is in scratch2. We need to move it to ecx and |
| 787 | // we may need to fix the sign. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 788 | Label negative; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 789 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 790 | __ cmp(ecx, FieldOperand(source, HeapNumber::kExponentOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 791 | __ j(greater, &negative, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 792 | __ mov(ecx, scratch2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 793 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 794 | __ bind(&negative); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 795 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 796 | __ bind(&done); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 801 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 802 | const char* op_name = Token::Name(op_); |
| 803 | const char* overwrite_name = NULL; // Make g++ happy. |
| 804 | switch (mode_) { |
| 805 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 806 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 807 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 808 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 809 | op_name, |
| 810 | overwrite_name, |
| 811 | UnaryOpIC::GetName(operand_type_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | |
| 815 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 816 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 817 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 818 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 819 | GenerateTypeTransition(masm); |
| 820 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 821 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 822 | GenerateSmiStub(masm); |
| 823 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 824 | case UnaryOpIC::HEAP_NUMBER: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 825 | GenerateHeapNumberStub(masm); |
| 826 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 827 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 828 | GenerateGenericStub(masm); |
| 829 | break; |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 834 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 835 | __ pop(ecx); // Save return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 836 | |
| 837 | __ push(eax); // the operand |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 838 | __ push(Immediate(Smi::FromInt(op_))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 839 | __ push(Immediate(Smi::FromInt(mode_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 840 | __ push(Immediate(Smi::FromInt(operand_type_))); |
| 841 | |
| 842 | __ push(ecx); // Push return address. |
| 843 | |
| 844 | // Patch the caller to an appropriate specialized stub and return the |
| 845 | // operation result to the caller of the stub. |
| 846 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 847 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | |
| 851 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 852 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 853 | switch (op_) { |
| 854 | case Token::SUB: |
| 855 | GenerateSmiStubSub(masm); |
| 856 | break; |
| 857 | case Token::BIT_NOT: |
| 858 | GenerateSmiStubBitNot(masm); |
| 859 | break; |
| 860 | default: |
| 861 | UNREACHABLE(); |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 866 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 867 | Label non_smi, undo, slow; |
| 868 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, |
| 869 | Label::kNear, Label::kNear, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 870 | __ bind(&undo); |
| 871 | GenerateSmiCodeUndo(masm); |
| 872 | __ bind(&non_smi); |
| 873 | __ bind(&slow); |
| 874 | GenerateTypeTransition(masm); |
| 875 | } |
| 876 | |
| 877 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 878 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 879 | Label non_smi; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 880 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 881 | __ bind(&non_smi); |
| 882 | GenerateTypeTransition(masm); |
| 883 | } |
| 884 | |
| 885 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 886 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 887 | Label* non_smi, |
| 888 | Label* undo, |
| 889 | Label* slow, |
| 890 | Label::Distance non_smi_near, |
| 891 | Label::Distance undo_near, |
| 892 | Label::Distance slow_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 893 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 894 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 895 | |
| 896 | // 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] | 897 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 898 | __ j(zero, slow, slow_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 899 | |
| 900 | // 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] | 901 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 902 | __ Set(eax, Immediate(0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 903 | __ sub(eax, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 904 | __ j(overflow, undo, undo_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 905 | __ ret(0); |
| 906 | } |
| 907 | |
| 908 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 909 | void UnaryOpStub::GenerateSmiCodeBitNot( |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 910 | MacroAssembler* masm, |
| 911 | Label* non_smi, |
| 912 | Label::Distance non_smi_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 913 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 914 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 915 | |
| 916 | // Flip bits and revert inverted smi-tag. |
| 917 | __ not_(eax); |
| 918 | __ and_(eax, ~kSmiTagMask); |
| 919 | __ ret(0); |
| 920 | } |
| 921 | |
| 922 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 923 | void UnaryOpStub::GenerateSmiCodeUndo(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 924 | __ mov(eax, edx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | |
| 928 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 929 | void UnaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 930 | switch (op_) { |
| 931 | case Token::SUB: |
| 932 | GenerateHeapNumberStubSub(masm); |
| 933 | break; |
| 934 | case Token::BIT_NOT: |
| 935 | GenerateHeapNumberStubBitNot(masm); |
| 936 | break; |
| 937 | default: |
| 938 | UNREACHABLE(); |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 943 | void UnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 944 | Label non_smi, undo, slow, call_builtin; |
| 945 | GenerateSmiCodeSub(masm, &non_smi, &undo, &call_builtin, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 946 | __ bind(&non_smi); |
| 947 | GenerateHeapNumberCodeSub(masm, &slow); |
| 948 | __ bind(&undo); |
| 949 | GenerateSmiCodeUndo(masm); |
| 950 | __ bind(&slow); |
| 951 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 952 | __ bind(&call_builtin); |
| 953 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 957 | void UnaryOpStub::GenerateHeapNumberStubBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 958 | MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 959 | Label non_smi, slow; |
| 960 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 961 | __ bind(&non_smi); |
| 962 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 963 | __ bind(&slow); |
| 964 | GenerateTypeTransition(masm); |
| 965 | } |
| 966 | |
| 967 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 968 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 969 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 970 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 971 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 972 | __ j(not_equal, slow); |
| 973 | |
| 974 | if (mode_ == UNARY_OVERWRITE) { |
| 975 | __ xor_(FieldOperand(eax, HeapNumber::kExponentOffset), |
| 976 | Immediate(HeapNumber::kSignMask)); // Flip sign. |
| 977 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 978 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 979 | // edx: operand |
| 980 | |
| 981 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 982 | __ AllocateHeapNumber(eax, ebx, ecx, &slow_allocate_heapnumber); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 983 | __ jmp(&heapnumber_allocated, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 984 | |
| 985 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 986 | { |
| 987 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 988 | __ push(edx); |
| 989 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 990 | __ pop(edx); |
| 991 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 992 | |
| 993 | __ bind(&heapnumber_allocated); |
| 994 | // eax: allocated 'empty' number |
| 995 | __ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 996 | __ xor_(ecx, HeapNumber::kSignMask); // Flip sign. |
| 997 | __ mov(FieldOperand(eax, HeapNumber::kExponentOffset), ecx); |
| 998 | __ mov(ecx, FieldOperand(edx, HeapNumber::kMantissaOffset)); |
| 999 | __ mov(FieldOperand(eax, HeapNumber::kMantissaOffset), ecx); |
| 1000 | } |
| 1001 | __ ret(0); |
| 1002 | } |
| 1003 | |
| 1004 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1005 | void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm, |
| 1006 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1007 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1008 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 1009 | __ j(not_equal, slow); |
| 1010 | |
| 1011 | // 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] | 1012 | IntegerConvert(masm, eax, CpuFeatures::IsSupported(SSE3), slow); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1013 | |
| 1014 | // 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] | 1015 | Label try_float; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1016 | __ not_(ecx); |
| 1017 | __ cmp(ecx, 0xc0000000); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1018 | __ j(sign, &try_float, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1019 | |
| 1020 | // Tag the result as a smi and we're done. |
| 1021 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1022 | __ lea(eax, Operand(ecx, times_2, kSmiTag)); |
| 1023 | __ ret(0); |
| 1024 | |
| 1025 | // Try to store the result in a heap number. |
| 1026 | __ bind(&try_float); |
| 1027 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 1028 | Label slow_allocate_heapnumber, heapnumber_allocated; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1029 | __ mov(ebx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1030 | __ AllocateHeapNumber(eax, edx, edi, &slow_allocate_heapnumber); |
| 1031 | __ jmp(&heapnumber_allocated); |
| 1032 | |
| 1033 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1034 | { |
| 1035 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1036 | // Push the original HeapNumber on the stack. The integer value can't |
| 1037 | // be stored since it's untagged and not in the smi range (so we can't |
| 1038 | // smi-tag it). We'll recalculate the value after the GC instead. |
| 1039 | __ push(ebx); |
| 1040 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1041 | // New HeapNumber is in eax. |
| 1042 | __ pop(edx); |
| 1043 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1044 | // IntegerConvert uses ebx and edi as scratch registers. |
| 1045 | // This conversion won't go slow-case. |
| 1046 | IntegerConvert(masm, edx, CpuFeatures::IsSupported(SSE3), slow); |
| 1047 | __ not_(ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1048 | |
| 1049 | __ bind(&heapnumber_allocated); |
| 1050 | } |
| 1051 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1052 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1053 | __ cvtsi2sd(xmm0, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1054 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1055 | } else { |
| 1056 | __ push(ecx); |
| 1057 | __ fild_s(Operand(esp, 0)); |
| 1058 | __ pop(ecx); |
| 1059 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1060 | } |
| 1061 | __ ret(0); |
| 1062 | } |
| 1063 | |
| 1064 | |
| 1065 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1066 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1067 | switch (op_) { |
| 1068 | case Token::SUB: |
| 1069 | GenerateGenericStubSub(masm); |
| 1070 | break; |
| 1071 | case Token::BIT_NOT: |
| 1072 | GenerateGenericStubBitNot(masm); |
| 1073 | break; |
| 1074 | default: |
| 1075 | UNREACHABLE(); |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1080 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1081 | Label non_smi, undo, slow; |
| 1082 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1083 | __ bind(&non_smi); |
| 1084 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1085 | __ bind(&undo); |
| 1086 | GenerateSmiCodeUndo(masm); |
| 1087 | __ bind(&slow); |
| 1088 | GenerateGenericCodeFallback(masm); |
| 1089 | } |
| 1090 | |
| 1091 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1092 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1093 | Label non_smi, slow; |
| 1094 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1095 | __ bind(&non_smi); |
| 1096 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1097 | __ bind(&slow); |
| 1098 | GenerateGenericCodeFallback(masm); |
| 1099 | } |
| 1100 | |
| 1101 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1102 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1103 | // Handle the slow case by jumping to the corresponding JavaScript builtin. |
| 1104 | __ pop(ecx); // pop return address. |
| 1105 | __ push(eax); |
| 1106 | __ push(ecx); // push return address |
| 1107 | switch (op_) { |
| 1108 | case Token::SUB: |
| 1109 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 1110 | break; |
| 1111 | case Token::BIT_NOT: |
| 1112 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 1113 | break; |
| 1114 | default: |
| 1115 | UNREACHABLE(); |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1120 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1121 | __ pop(ecx); // Save return address. |
| 1122 | __ push(edx); |
| 1123 | __ push(eax); |
| 1124 | // Left and right arguments are now on top. |
| 1125 | // Push this stub's key. Although the operation and the type info are |
| 1126 | // encoded into the key, the encoding is opaque, so push them too. |
| 1127 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
| 1128 | __ push(Immediate(Smi::FromInt(op_))); |
| 1129 | __ push(Immediate(Smi::FromInt(operands_type_))); |
| 1130 | |
| 1131 | __ push(ecx); // Push return address. |
| 1132 | |
| 1133 | // Patch the caller to an appropriate specialized stub and return the |
| 1134 | // operation result to the caller of the stub. |
| 1135 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1136 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1137 | masm->isolate()), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1138 | 5, |
| 1139 | 1); |
| 1140 | } |
| 1141 | |
| 1142 | |
| 1143 | // Prepare for a type transition runtime call when the args are already on |
| 1144 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1145 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1146 | __ pop(ecx); // Save return address. |
| 1147 | // Left and right arguments are already on top of the stack. |
| 1148 | // Push this stub's key. Although the operation and the type info are |
| 1149 | // encoded into the key, the encoding is opaque, so push them too. |
| 1150 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
| 1151 | __ push(Immediate(Smi::FromInt(op_))); |
| 1152 | __ push(Immediate(Smi::FromInt(operands_type_))); |
| 1153 | |
| 1154 | __ push(ecx); // Push return address. |
| 1155 | |
| 1156 | // Patch the caller to an appropriate specialized stub and return the |
| 1157 | // operation result to the caller of the stub. |
| 1158 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1159 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1160 | masm->isolate()), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1161 | 5, |
| 1162 | 1); |
| 1163 | } |
| 1164 | |
| 1165 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1166 | void BinaryOpStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1167 | // Explicitly allow generation of nested stubs. It is safe here because |
| 1168 | // generation code does not use any raw pointers. |
| 1169 | AllowStubCallsScope allow_stub_calls(masm, true); |
| 1170 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1171 | switch (operands_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1172 | case BinaryOpIC::UNINITIALIZED: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1173 | GenerateTypeTransition(masm); |
| 1174 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1175 | case BinaryOpIC::SMI: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1176 | GenerateSmiStub(masm); |
| 1177 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1178 | case BinaryOpIC::INT32: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1179 | GenerateInt32Stub(masm); |
| 1180 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1181 | case BinaryOpIC::HEAP_NUMBER: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1182 | GenerateHeapNumberStub(masm); |
| 1183 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1184 | case BinaryOpIC::ODDBALL: |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1185 | GenerateOddballStub(masm); |
| 1186 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1187 | case BinaryOpIC::BOTH_STRING: |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1188 | GenerateBothStringStub(masm); |
| 1189 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1190 | case BinaryOpIC::STRING: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1191 | GenerateStringStub(masm); |
| 1192 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1193 | case BinaryOpIC::GENERIC: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1194 | GenerateGeneric(masm); |
| 1195 | break; |
| 1196 | default: |
| 1197 | UNREACHABLE(); |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1202 | void BinaryOpStub::PrintName(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1203 | const char* op_name = Token::Name(op_); |
| 1204 | const char* overwrite_name; |
| 1205 | switch (mode_) { |
| 1206 | case NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 1207 | case OVERWRITE_RIGHT: overwrite_name = "OverwriteRight"; break; |
| 1208 | case OVERWRITE_LEFT: overwrite_name = "OverwriteLeft"; break; |
| 1209 | default: overwrite_name = "UnknownOverwrite"; break; |
| 1210 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1211 | stream->Add("BinaryOpStub_%s_%s_%s", |
| 1212 | op_name, |
| 1213 | overwrite_name, |
| 1214 | BinaryOpIC::GetName(operands_type_)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1218 | void BinaryOpStub::GenerateSmiCode( |
| 1219 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1220 | Label* slow, |
| 1221 | SmiCodeGenerateHeapNumberResults allow_heapnumber_results) { |
| 1222 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 1223 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 1224 | Comment load_comment(masm, "-- Load arguments"); |
| 1225 | Register left = edx; |
| 1226 | Register right = eax; |
| 1227 | if (op_ == Token::DIV || op_ == Token::MOD) { |
| 1228 | left = eax; |
| 1229 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1230 | __ mov(ebx, eax); |
| 1231 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | |
| 1235 | // 2. Prepare the smi check of both operands by oring them together. |
| 1236 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 1237 | Label not_smis; |
| 1238 | Register combined = ecx; |
| 1239 | ASSERT(!left.is(combined) && !right.is(combined)); |
| 1240 | switch (op_) { |
| 1241 | case Token::BIT_OR: |
| 1242 | // Perform the operation into eax and smi check the result. Preserve |
| 1243 | // eax in case the result is not a smi. |
| 1244 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1245 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1246 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1247 | combined = right; |
| 1248 | break; |
| 1249 | |
| 1250 | case Token::BIT_XOR: |
| 1251 | case Token::BIT_AND: |
| 1252 | case Token::ADD: |
| 1253 | case Token::SUB: |
| 1254 | case Token::MUL: |
| 1255 | case Token::DIV: |
| 1256 | case Token::MOD: |
| 1257 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1258 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1259 | break; |
| 1260 | |
| 1261 | case Token::SHL: |
| 1262 | case Token::SAR: |
| 1263 | case Token::SHR: |
| 1264 | // Move the right operand into ecx for the shift operation, use eax |
| 1265 | // for the smi check register. |
| 1266 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1267 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1268 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1269 | combined = right; |
| 1270 | break; |
| 1271 | |
| 1272 | default: |
| 1273 | break; |
| 1274 | } |
| 1275 | |
| 1276 | // 3. Perform the smi check of the operands. |
| 1277 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1278 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1279 | |
| 1280 | // 4. Operands are both smis, perform the operation leaving the result in |
| 1281 | // eax and check the result if necessary. |
| 1282 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 1283 | Label use_fp_on_smis; |
| 1284 | switch (op_) { |
| 1285 | case Token::BIT_OR: |
| 1286 | // Nothing to do. |
| 1287 | break; |
| 1288 | |
| 1289 | case Token::BIT_XOR: |
| 1290 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1291 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1292 | break; |
| 1293 | |
| 1294 | case Token::BIT_AND: |
| 1295 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1296 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1297 | break; |
| 1298 | |
| 1299 | case Token::SHL: |
| 1300 | // Remove tags from operands (but keep sign). |
| 1301 | __ SmiUntag(left); |
| 1302 | __ SmiUntag(ecx); |
| 1303 | // Perform the operation. |
| 1304 | __ shl_cl(left); |
| 1305 | // Check that the *signed* result fits in a smi. |
| 1306 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1307 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1308 | // Tag the result and store it in register eax. |
| 1309 | __ SmiTag(left); |
| 1310 | __ mov(eax, left); |
| 1311 | break; |
| 1312 | |
| 1313 | case Token::SAR: |
| 1314 | // Remove tags from operands (but keep sign). |
| 1315 | __ SmiUntag(left); |
| 1316 | __ SmiUntag(ecx); |
| 1317 | // Perform the operation. |
| 1318 | __ sar_cl(left); |
| 1319 | // Tag the result and store it in register eax. |
| 1320 | __ SmiTag(left); |
| 1321 | __ mov(eax, left); |
| 1322 | break; |
| 1323 | |
| 1324 | case Token::SHR: |
| 1325 | // Remove tags from operands (but keep sign). |
| 1326 | __ SmiUntag(left); |
| 1327 | __ SmiUntag(ecx); |
| 1328 | // Perform the operation. |
| 1329 | __ shr_cl(left); |
| 1330 | // Check that the *unsigned* result fits in a smi. |
| 1331 | // Neither of the two high-order bits can be set: |
| 1332 | // - 0x80000000: high bit would be lost when smi tagging. |
| 1333 | // - 0x40000000: this number would convert to negative when |
| 1334 | // Smi tagging these two cases can only happen with shifts |
| 1335 | // by 0 or 1 when handed a valid smi. |
| 1336 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1337 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1338 | // Tag the result and store it in register eax. |
| 1339 | __ SmiTag(left); |
| 1340 | __ mov(eax, left); |
| 1341 | break; |
| 1342 | |
| 1343 | case Token::ADD: |
| 1344 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1345 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1346 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1347 | break; |
| 1348 | |
| 1349 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1350 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1351 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1352 | __ mov(eax, left); |
| 1353 | break; |
| 1354 | |
| 1355 | case Token::MUL: |
| 1356 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 1357 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 1358 | // We can't revert the multiplication if the result is not a smi |
| 1359 | // so save the right operand. |
| 1360 | __ mov(ebx, right); |
| 1361 | // Remove tag from one of the operands (but keep sign). |
| 1362 | __ SmiUntag(right); |
| 1363 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1364 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1365 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1366 | // Check for negative zero result. Use combined = left | right. |
| 1367 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 1368 | break; |
| 1369 | |
| 1370 | case Token::DIV: |
| 1371 | // We can't revert the division if the result is not a smi so |
| 1372 | // save the left operand. |
| 1373 | __ mov(edi, left); |
| 1374 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1375 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1376 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1377 | // Sign extend left into edx:eax. |
| 1378 | ASSERT(left.is(eax)); |
| 1379 | __ cdq(); |
| 1380 | // Divide edx:eax by right. |
| 1381 | __ idiv(right); |
| 1382 | // Check for the corner case of dividing the most negative smi by |
| 1383 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1384 | // instruction. |
| 1385 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1386 | __ cmp(eax, 0x40000000); |
| 1387 | __ j(equal, &use_fp_on_smis); |
| 1388 | // Check for negative zero result. Use combined = left | right. |
| 1389 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1390 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1391 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1392 | __ j(not_zero, &use_fp_on_smis); |
| 1393 | // Tag the result and store it in register eax. |
| 1394 | __ SmiTag(eax); |
| 1395 | break; |
| 1396 | |
| 1397 | case Token::MOD: |
| 1398 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1399 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1400 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1401 | |
| 1402 | // Sign extend left into edx:eax. |
| 1403 | ASSERT(left.is(eax)); |
| 1404 | __ cdq(); |
| 1405 | // Divide edx:eax by right. |
| 1406 | __ idiv(right); |
| 1407 | // Check for negative zero result. Use combined = left | right. |
| 1408 | __ NegativeZeroTest(edx, combined, slow); |
| 1409 | // Move remainder to register eax. |
| 1410 | __ mov(eax, edx); |
| 1411 | break; |
| 1412 | |
| 1413 | default: |
| 1414 | UNREACHABLE(); |
| 1415 | } |
| 1416 | |
| 1417 | // 5. Emit return of result in eax. Some operations have registers pushed. |
| 1418 | switch (op_) { |
| 1419 | case Token::ADD: |
| 1420 | case Token::SUB: |
| 1421 | case Token::MUL: |
| 1422 | case Token::DIV: |
| 1423 | __ ret(0); |
| 1424 | break; |
| 1425 | case Token::MOD: |
| 1426 | case Token::BIT_OR: |
| 1427 | case Token::BIT_AND: |
| 1428 | case Token::BIT_XOR: |
| 1429 | case Token::SAR: |
| 1430 | case Token::SHL: |
| 1431 | case Token::SHR: |
| 1432 | __ ret(2 * kPointerSize); |
| 1433 | break; |
| 1434 | default: |
| 1435 | UNREACHABLE(); |
| 1436 | } |
| 1437 | |
| 1438 | // 6. For some operations emit inline code to perform floating point |
| 1439 | // operations on known smis (e.g., if the result of the operation |
| 1440 | // overflowed the smi range). |
| 1441 | if (allow_heapnumber_results == NO_HEAPNUMBER_RESULTS) { |
| 1442 | __ bind(&use_fp_on_smis); |
| 1443 | switch (op_) { |
| 1444 | // Undo the effects of some operations, and some register moves. |
| 1445 | case Token::SHL: |
| 1446 | // The arguments are saved on the stack, and only used from there. |
| 1447 | break; |
| 1448 | case Token::ADD: |
| 1449 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1450 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1451 | break; |
| 1452 | case Token::SUB: |
| 1453 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1454 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1455 | break; |
| 1456 | case Token::MUL: |
| 1457 | // Right was clobbered but a copy is in ebx. |
| 1458 | __ mov(right, ebx); |
| 1459 | break; |
| 1460 | case Token::DIV: |
| 1461 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1462 | // division. They should be in eax, ebx for jump to not_smi. |
| 1463 | __ mov(eax, edi); |
| 1464 | break; |
| 1465 | default: |
| 1466 | // No other operators jump to use_fp_on_smis. |
| 1467 | break; |
| 1468 | } |
| 1469 | __ jmp(¬_smis); |
| 1470 | } else { |
| 1471 | ASSERT(allow_heapnumber_results == ALLOW_HEAPNUMBER_RESULTS); |
| 1472 | switch (op_) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1473 | case Token::SHL: |
| 1474 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1475 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1476 | __ bind(&use_fp_on_smis); |
| 1477 | // Result we want is in left == edx, so we can put the allocated heap |
| 1478 | // number in eax. |
| 1479 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1480 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1481 | // It's OK to overwrite the arguments on the stack because we |
| 1482 | // are about to return. |
| 1483 | if (op_ == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1484 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1485 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1486 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1487 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1488 | } else { |
| 1489 | ASSERT_EQ(Token::SHL, op_); |
| 1490 | if (CpuFeatures::IsSupported(SSE2)) { |
| 1491 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1492 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1493 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1494 | } else { |
| 1495 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1496 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1497 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1498 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1499 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1500 | __ ret(2 * kPointerSize); |
| 1501 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | case Token::ADD: |
| 1505 | case Token::SUB: |
| 1506 | case Token::MUL: |
| 1507 | case Token::DIV: { |
| 1508 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1509 | __ bind(&use_fp_on_smis); |
| 1510 | // Restore arguments to edx, eax. |
| 1511 | switch (op_) { |
| 1512 | case Token::ADD: |
| 1513 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1514 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1515 | break; |
| 1516 | case Token::SUB: |
| 1517 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1518 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1519 | break; |
| 1520 | case Token::MUL: |
| 1521 | // Right was clobbered but a copy is in ebx. |
| 1522 | __ mov(right, ebx); |
| 1523 | break; |
| 1524 | case Token::DIV: |
| 1525 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1526 | // division. |
| 1527 | __ mov(edx, edi); |
| 1528 | __ mov(eax, right); |
| 1529 | break; |
| 1530 | default: UNREACHABLE(); |
| 1531 | break; |
| 1532 | } |
| 1533 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1534 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1535 | CpuFeatures::Scope use_sse2(SSE2); |
| 1536 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
| 1537 | switch (op_) { |
| 1538 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1539 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1540 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1541 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1542 | default: UNREACHABLE(); |
| 1543 | } |
| 1544 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1545 | } else { // SSE2 not available, use FPU. |
| 1546 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
| 1547 | switch (op_) { |
| 1548 | case Token::ADD: __ faddp(1); break; |
| 1549 | case Token::SUB: __ fsubp(1); break; |
| 1550 | case Token::MUL: __ fmulp(1); break; |
| 1551 | case Token::DIV: __ fdivp(1); break; |
| 1552 | default: UNREACHABLE(); |
| 1553 | } |
| 1554 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1555 | } |
| 1556 | __ mov(eax, ecx); |
| 1557 | __ ret(0); |
| 1558 | break; |
| 1559 | } |
| 1560 | |
| 1561 | default: |
| 1562 | break; |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1567 | // edx and eax. |
| 1568 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1569 | __ bind(¬_smis); |
| 1570 | switch (op_) { |
| 1571 | case Token::BIT_OR: |
| 1572 | case Token::SHL: |
| 1573 | case Token::SAR: |
| 1574 | case Token::SHR: |
| 1575 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1576 | // check. |
| 1577 | __ mov(eax, ecx); |
| 1578 | break; |
| 1579 | |
| 1580 | case Token::DIV: |
| 1581 | case Token::MOD: |
| 1582 | // Operands are in eax, ebx at this point. |
| 1583 | __ mov(edx, eax); |
| 1584 | __ mov(eax, ebx); |
| 1585 | break; |
| 1586 | |
| 1587 | default: |
| 1588 | break; |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1593 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1594 | Label call_runtime; |
| 1595 | |
| 1596 | switch (op_) { |
| 1597 | case Token::ADD: |
| 1598 | case Token::SUB: |
| 1599 | case Token::MUL: |
| 1600 | case Token::DIV: |
| 1601 | break; |
| 1602 | case Token::MOD: |
| 1603 | case Token::BIT_OR: |
| 1604 | case Token::BIT_AND: |
| 1605 | case Token::BIT_XOR: |
| 1606 | case Token::SAR: |
| 1607 | case Token::SHL: |
| 1608 | case Token::SHR: |
| 1609 | GenerateRegisterArgsPush(masm); |
| 1610 | break; |
| 1611 | default: |
| 1612 | UNREACHABLE(); |
| 1613 | } |
| 1614 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1615 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1616 | result_type_ == BinaryOpIC::SMI) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1617 | GenerateSmiCode(masm, &call_runtime, NO_HEAPNUMBER_RESULTS); |
| 1618 | } else { |
| 1619 | GenerateSmiCode(masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS); |
| 1620 | } |
| 1621 | __ bind(&call_runtime); |
| 1622 | switch (op_) { |
| 1623 | case Token::ADD: |
| 1624 | case Token::SUB: |
| 1625 | case Token::MUL: |
| 1626 | case Token::DIV: |
| 1627 | GenerateTypeTransition(masm); |
| 1628 | break; |
| 1629 | case Token::MOD: |
| 1630 | case Token::BIT_OR: |
| 1631 | case Token::BIT_AND: |
| 1632 | case Token::BIT_XOR: |
| 1633 | case Token::SAR: |
| 1634 | case Token::SHL: |
| 1635 | case Token::SHR: |
| 1636 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1637 | break; |
| 1638 | default: |
| 1639 | UNREACHABLE(); |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1644 | void BinaryOpStub::GenerateStringStub(MacroAssembler* masm) { |
| 1645 | ASSERT(operands_type_ == BinaryOpIC::STRING); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1646 | ASSERT(op_ == Token::ADD); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1647 | // Try to add arguments as strings, otherwise, transition to the generic |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1648 | // BinaryOpIC type. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1649 | GenerateAddStrings(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1650 | GenerateTypeTransition(masm); |
| 1651 | } |
| 1652 | |
| 1653 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1654 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1655 | Label call_runtime; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1656 | ASSERT(operands_type_ == BinaryOpIC::BOTH_STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1657 | ASSERT(op_ == Token::ADD); |
| 1658 | // If both arguments are strings, call the string add stub. |
| 1659 | // Otherwise, do a transition. |
| 1660 | |
| 1661 | // Registers containing left and right operands respectively. |
| 1662 | Register left = edx; |
| 1663 | Register right = eax; |
| 1664 | |
| 1665 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1666 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1667 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1668 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1669 | |
| 1670 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1671 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1672 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1673 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1674 | |
| 1675 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 1676 | GenerateRegisterArgsPush(masm); |
| 1677 | __ TailCallStub(&string_add_stub); |
| 1678 | |
| 1679 | __ bind(&call_runtime); |
| 1680 | GenerateTypeTransition(masm); |
| 1681 | } |
| 1682 | |
| 1683 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1684 | // Input: |
| 1685 | // edx: left operand (tagged) |
| 1686 | // eax: right operand (tagged) |
| 1687 | // Output: |
| 1688 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1689 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1690 | Label call_runtime; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1691 | ASSERT(operands_type_ == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1692 | |
| 1693 | // Floating point case. |
| 1694 | switch (op_) { |
| 1695 | case Token::ADD: |
| 1696 | case Token::SUB: |
| 1697 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1698 | case Token::DIV: |
| 1699 | case Token::MOD: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1700 | Label not_floats; |
| 1701 | Label not_int32; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1702 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1703 | CpuFeatures::Scope use_sse2(SSE2); |
| 1704 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1705 | FloatingPointHelper::CheckSSE2OperandsAreInt32(masm, ¬_int32, ecx); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1706 | if (op_ == Token::MOD) { |
| 1707 | GenerateRegisterArgsPush(masm); |
| 1708 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1709 | } else { |
| 1710 | switch (op_) { |
| 1711 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1712 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1713 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1714 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1715 | default: UNREACHABLE(); |
| 1716 | } |
| 1717 | // Check result type if it is currently Int32. |
| 1718 | if (result_type_ <= BinaryOpIC::INT32) { |
| 1719 | __ cvttsd2si(ecx, Operand(xmm0)); |
| 1720 | __ cvtsi2sd(xmm2, ecx); |
| 1721 | __ ucomisd(xmm0, xmm2); |
| 1722 | __ j(not_zero, ¬_int32); |
| 1723 | __ j(carry, ¬_int32); |
| 1724 | } |
| 1725 | GenerateHeapResultAllocation(masm, &call_runtime); |
| 1726 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1727 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1728 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1729 | } else { // SSE2 not available, use FPU. |
| 1730 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1731 | FloatingPointHelper::LoadFloatOperands( |
| 1732 | masm, |
| 1733 | ecx, |
| 1734 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1735 | FloatingPointHelper::CheckFloatOperandsAreInt32(masm, ¬_int32); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1736 | if (op_ == Token::MOD) { |
| 1737 | // The operands are now on the FPU stack, but we don't need them. |
| 1738 | __ fstp(0); |
| 1739 | __ fstp(0); |
| 1740 | GenerateRegisterArgsPush(masm); |
| 1741 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1742 | } else { |
| 1743 | switch (op_) { |
| 1744 | case Token::ADD: __ faddp(1); break; |
| 1745 | case Token::SUB: __ fsubp(1); break; |
| 1746 | case Token::MUL: __ fmulp(1); break; |
| 1747 | case Token::DIV: __ fdivp(1); break; |
| 1748 | default: UNREACHABLE(); |
| 1749 | } |
| 1750 | Label after_alloc_failure; |
| 1751 | GenerateHeapResultAllocation(masm, &after_alloc_failure); |
| 1752 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1753 | __ ret(0); |
| 1754 | __ bind(&after_alloc_failure); |
| 1755 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1756 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1757 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | __ bind(¬_floats); |
| 1761 | __ bind(¬_int32); |
| 1762 | GenerateTypeTransition(masm); |
| 1763 | break; |
| 1764 | } |
| 1765 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1766 | case Token::BIT_OR: |
| 1767 | case Token::BIT_AND: |
| 1768 | case Token::BIT_XOR: |
| 1769 | case Token::SAR: |
| 1770 | case Token::SHL: |
| 1771 | case Token::SHR: { |
| 1772 | GenerateRegisterArgsPush(masm); |
| 1773 | Label not_floats; |
| 1774 | Label not_int32; |
| 1775 | Label non_smi_result; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1776 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
| 1777 | use_sse3_, |
| 1778 | ¬_floats); |
| 1779 | FloatingPointHelper::CheckLoadedIntegersWereInt32(masm, use_sse3_, |
| 1780 | ¬_int32); |
| 1781 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1782 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1783 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1784 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1785 | case Token::SAR: __ sar_cl(eax); break; |
| 1786 | case Token::SHL: __ shl_cl(eax); break; |
| 1787 | case Token::SHR: __ shr_cl(eax); break; |
| 1788 | default: UNREACHABLE(); |
| 1789 | } |
| 1790 | if (op_ == Token::SHR) { |
| 1791 | // Check if result is non-negative and fits in a smi. |
| 1792 | __ test(eax, Immediate(0xc0000000)); |
| 1793 | __ j(not_zero, &call_runtime); |
| 1794 | } else { |
| 1795 | // Check if result fits in a smi. |
| 1796 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1797 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1798 | } |
| 1799 | // Tag smi result and return. |
| 1800 | __ SmiTag(eax); |
| 1801 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1802 | |
| 1803 | // All ops except SHR return a signed int32 that we load in |
| 1804 | // a HeapNumber. |
| 1805 | if (op_ != Token::SHR) { |
| 1806 | __ bind(&non_smi_result); |
| 1807 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1808 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1809 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1810 | switch (mode_) { |
| 1811 | case OVERWRITE_LEFT: |
| 1812 | case OVERWRITE_RIGHT: |
| 1813 | // If the operand was an object, we skip the |
| 1814 | // allocation of a heap number. |
| 1815 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1816 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1817 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1818 | // Fall through! |
| 1819 | case NO_OVERWRITE: |
| 1820 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1821 | __ bind(&skip_allocation); |
| 1822 | break; |
| 1823 | default: UNREACHABLE(); |
| 1824 | } |
| 1825 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1826 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1827 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1828 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1829 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1830 | } else { |
| 1831 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1832 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1833 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1834 | } |
| 1835 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1836 | } |
| 1837 | |
| 1838 | __ bind(¬_floats); |
| 1839 | __ bind(¬_int32); |
| 1840 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1841 | break; |
| 1842 | } |
| 1843 | default: UNREACHABLE(); break; |
| 1844 | } |
| 1845 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1846 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1847 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1848 | __ bind(&call_runtime); |
| 1849 | |
| 1850 | switch (op_) { |
| 1851 | case Token::ADD: |
| 1852 | GenerateRegisterArgsPush(masm); |
| 1853 | __ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION); |
| 1854 | break; |
| 1855 | case Token::SUB: |
| 1856 | GenerateRegisterArgsPush(masm); |
| 1857 | __ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION); |
| 1858 | break; |
| 1859 | case Token::MUL: |
| 1860 | GenerateRegisterArgsPush(masm); |
| 1861 | __ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION); |
| 1862 | break; |
| 1863 | case Token::DIV: |
| 1864 | GenerateRegisterArgsPush(masm); |
| 1865 | __ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION); |
| 1866 | break; |
| 1867 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1868 | break; |
| 1869 | case Token::BIT_OR: |
| 1870 | __ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION); |
| 1871 | break; |
| 1872 | case Token::BIT_AND: |
| 1873 | __ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION); |
| 1874 | break; |
| 1875 | case Token::BIT_XOR: |
| 1876 | __ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION); |
| 1877 | break; |
| 1878 | case Token::SAR: |
| 1879 | __ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION); |
| 1880 | break; |
| 1881 | case Token::SHL: |
| 1882 | __ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION); |
| 1883 | break; |
| 1884 | case Token::SHR: |
| 1885 | __ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION); |
| 1886 | break; |
| 1887 | default: |
| 1888 | UNREACHABLE(); |
| 1889 | } |
| 1890 | } |
| 1891 | |
| 1892 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1893 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1894 | if (op_ == Token::ADD) { |
| 1895 | // Handle string addition here, because it is the only operation |
| 1896 | // that does not do a ToNumber conversion on the operands. |
| 1897 | GenerateAddStrings(masm); |
| 1898 | } |
| 1899 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1900 | Factory* factory = masm->isolate()->factory(); |
| 1901 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1902 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1903 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1904 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1905 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1906 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1907 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1908 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1909 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1910 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1911 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1912 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1913 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1914 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1915 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1916 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1917 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1918 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1919 | } |
| 1920 | __ bind(&done); |
| 1921 | |
| 1922 | GenerateHeapNumberStub(masm); |
| 1923 | } |
| 1924 | |
| 1925 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1926 | void BinaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1927 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1928 | |
| 1929 | // Floating point case. |
| 1930 | switch (op_) { |
| 1931 | case Token::ADD: |
| 1932 | case Token::SUB: |
| 1933 | case Token::MUL: |
| 1934 | case Token::DIV: { |
| 1935 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1936 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1937 | CpuFeatures::Scope use_sse2(SSE2); |
| 1938 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1939 | |
| 1940 | switch (op_) { |
| 1941 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1942 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1943 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1944 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1945 | default: UNREACHABLE(); |
| 1946 | } |
| 1947 | GenerateHeapResultAllocation(masm, &call_runtime); |
| 1948 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1949 | __ ret(0); |
| 1950 | } else { // SSE2 not available, use FPU. |
| 1951 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1952 | FloatingPointHelper::LoadFloatOperands( |
| 1953 | masm, |
| 1954 | ecx, |
| 1955 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1956 | switch (op_) { |
| 1957 | case Token::ADD: __ faddp(1); break; |
| 1958 | case Token::SUB: __ fsubp(1); break; |
| 1959 | case Token::MUL: __ fmulp(1); break; |
| 1960 | case Token::DIV: __ fdivp(1); break; |
| 1961 | default: UNREACHABLE(); |
| 1962 | } |
| 1963 | Label after_alloc_failure; |
| 1964 | GenerateHeapResultAllocation(masm, &after_alloc_failure); |
| 1965 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1966 | __ ret(0); |
| 1967 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1968 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1969 | __ jmp(&call_runtime); |
| 1970 | } |
| 1971 | |
| 1972 | __ bind(¬_floats); |
| 1973 | GenerateTypeTransition(masm); |
| 1974 | break; |
| 1975 | } |
| 1976 | |
| 1977 | case Token::MOD: { |
| 1978 | // For MOD we go directly to runtime in the non-smi case. |
| 1979 | break; |
| 1980 | } |
| 1981 | case Token::BIT_OR: |
| 1982 | case Token::BIT_AND: |
| 1983 | case Token::BIT_XOR: |
| 1984 | case Token::SAR: |
| 1985 | case Token::SHL: |
| 1986 | case Token::SHR: { |
| 1987 | GenerateRegisterArgsPush(masm); |
| 1988 | Label not_floats; |
| 1989 | Label non_smi_result; |
| 1990 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
| 1991 | use_sse3_, |
| 1992 | ¬_floats); |
| 1993 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1994 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1995 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1996 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1997 | case Token::SAR: __ sar_cl(eax); break; |
| 1998 | case Token::SHL: __ shl_cl(eax); break; |
| 1999 | case Token::SHR: __ shr_cl(eax); break; |
| 2000 | default: UNREACHABLE(); |
| 2001 | } |
| 2002 | if (op_ == Token::SHR) { |
| 2003 | // Check if result is non-negative and fits in a smi. |
| 2004 | __ test(eax, Immediate(0xc0000000)); |
| 2005 | __ j(not_zero, &call_runtime); |
| 2006 | } else { |
| 2007 | // Check if result fits in a smi. |
| 2008 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2009 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2010 | } |
| 2011 | // Tag smi result and return. |
| 2012 | __ SmiTag(eax); |
| 2013 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2014 | |
| 2015 | // All ops except SHR return a signed int32 that we load in |
| 2016 | // a HeapNumber. |
| 2017 | if (op_ != Token::SHR) { |
| 2018 | __ bind(&non_smi_result); |
| 2019 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2020 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2021 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2022 | switch (mode_) { |
| 2023 | case OVERWRITE_LEFT: |
| 2024 | case OVERWRITE_RIGHT: |
| 2025 | // If the operand was an object, we skip the |
| 2026 | // allocation of a heap number. |
| 2027 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2028 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2029 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2030 | // Fall through! |
| 2031 | case NO_OVERWRITE: |
| 2032 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2033 | __ bind(&skip_allocation); |
| 2034 | break; |
| 2035 | default: UNREACHABLE(); |
| 2036 | } |
| 2037 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2038 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2039 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2040 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2041 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2042 | } else { |
| 2043 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2044 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2045 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2046 | } |
| 2047 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2048 | } |
| 2049 | |
| 2050 | __ bind(¬_floats); |
| 2051 | GenerateTypeTransitionWithSavedArgs(masm); |
| 2052 | break; |
| 2053 | } |
| 2054 | default: UNREACHABLE(); break; |
| 2055 | } |
| 2056 | |
| 2057 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 2058 | // use the runtime system to get the correct result. |
| 2059 | __ bind(&call_runtime); |
| 2060 | |
| 2061 | switch (op_) { |
| 2062 | case Token::ADD: |
| 2063 | GenerateRegisterArgsPush(masm); |
| 2064 | __ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION); |
| 2065 | break; |
| 2066 | case Token::SUB: |
| 2067 | GenerateRegisterArgsPush(masm); |
| 2068 | __ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION); |
| 2069 | break; |
| 2070 | case Token::MUL: |
| 2071 | GenerateRegisterArgsPush(masm); |
| 2072 | __ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION); |
| 2073 | break; |
| 2074 | case Token::DIV: |
| 2075 | GenerateRegisterArgsPush(masm); |
| 2076 | __ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION); |
| 2077 | break; |
| 2078 | case Token::MOD: |
| 2079 | GenerateRegisterArgsPush(masm); |
| 2080 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 2081 | break; |
| 2082 | case Token::BIT_OR: |
| 2083 | __ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION); |
| 2084 | break; |
| 2085 | case Token::BIT_AND: |
| 2086 | __ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION); |
| 2087 | break; |
| 2088 | case Token::BIT_XOR: |
| 2089 | __ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION); |
| 2090 | break; |
| 2091 | case Token::SAR: |
| 2092 | __ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION); |
| 2093 | break; |
| 2094 | case Token::SHL: |
| 2095 | __ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION); |
| 2096 | break; |
| 2097 | case Token::SHR: |
| 2098 | __ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION); |
| 2099 | break; |
| 2100 | default: |
| 2101 | UNREACHABLE(); |
| 2102 | } |
| 2103 | } |
| 2104 | |
| 2105 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2106 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2107 | Label call_runtime; |
| 2108 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2109 | Counters* counters = masm->isolate()->counters(); |
| 2110 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2111 | |
| 2112 | switch (op_) { |
| 2113 | case Token::ADD: |
| 2114 | case Token::SUB: |
| 2115 | case Token::MUL: |
| 2116 | case Token::DIV: |
| 2117 | break; |
| 2118 | case Token::MOD: |
| 2119 | case Token::BIT_OR: |
| 2120 | case Token::BIT_AND: |
| 2121 | case Token::BIT_XOR: |
| 2122 | case Token::SAR: |
| 2123 | case Token::SHL: |
| 2124 | case Token::SHR: |
| 2125 | GenerateRegisterArgsPush(masm); |
| 2126 | break; |
| 2127 | default: |
| 2128 | UNREACHABLE(); |
| 2129 | } |
| 2130 | |
| 2131 | GenerateSmiCode(masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS); |
| 2132 | |
| 2133 | // Floating point case. |
| 2134 | switch (op_) { |
| 2135 | case Token::ADD: |
| 2136 | case Token::SUB: |
| 2137 | case Token::MUL: |
| 2138 | case Token::DIV: { |
| 2139 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2140 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2141 | CpuFeatures::Scope use_sse2(SSE2); |
| 2142 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 2143 | |
| 2144 | switch (op_) { |
| 2145 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2146 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2147 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2148 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2149 | default: UNREACHABLE(); |
| 2150 | } |
| 2151 | GenerateHeapResultAllocation(masm, &call_runtime); |
| 2152 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2153 | __ ret(0); |
| 2154 | } else { // SSE2 not available, use FPU. |
| 2155 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2156 | FloatingPointHelper::LoadFloatOperands( |
| 2157 | masm, |
| 2158 | ecx, |
| 2159 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2160 | switch (op_) { |
| 2161 | case Token::ADD: __ faddp(1); break; |
| 2162 | case Token::SUB: __ fsubp(1); break; |
| 2163 | case Token::MUL: __ fmulp(1); break; |
| 2164 | case Token::DIV: __ fdivp(1); break; |
| 2165 | default: UNREACHABLE(); |
| 2166 | } |
| 2167 | Label after_alloc_failure; |
| 2168 | GenerateHeapResultAllocation(masm, &after_alloc_failure); |
| 2169 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2170 | __ ret(0); |
| 2171 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2172 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 2173 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2174 | } |
| 2175 | __ bind(¬_floats); |
| 2176 | break; |
| 2177 | } |
| 2178 | case Token::MOD: { |
| 2179 | // For MOD we go directly to runtime in the non-smi case. |
| 2180 | break; |
| 2181 | } |
| 2182 | case Token::BIT_OR: |
| 2183 | case Token::BIT_AND: |
| 2184 | case Token::BIT_XOR: |
| 2185 | case Token::SAR: |
| 2186 | case Token::SHL: |
| 2187 | case Token::SHR: { |
| 2188 | Label non_smi_result; |
| 2189 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
| 2190 | use_sse3_, |
| 2191 | &call_runtime); |
| 2192 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2193 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2194 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2195 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2196 | case Token::SAR: __ sar_cl(eax); break; |
| 2197 | case Token::SHL: __ shl_cl(eax); break; |
| 2198 | case Token::SHR: __ shr_cl(eax); break; |
| 2199 | default: UNREACHABLE(); |
| 2200 | } |
| 2201 | if (op_ == Token::SHR) { |
| 2202 | // Check if result is non-negative and fits in a smi. |
| 2203 | __ test(eax, Immediate(0xc0000000)); |
| 2204 | __ j(not_zero, &call_runtime); |
| 2205 | } else { |
| 2206 | // Check if result fits in a smi. |
| 2207 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2208 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2209 | } |
| 2210 | // Tag smi result and return. |
| 2211 | __ SmiTag(eax); |
| 2212 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 2213 | |
| 2214 | // All ops except SHR return a signed int32 that we load in |
| 2215 | // a HeapNumber. |
| 2216 | if (op_ != Token::SHR) { |
| 2217 | __ bind(&non_smi_result); |
| 2218 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2219 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2220 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2221 | switch (mode_) { |
| 2222 | case OVERWRITE_LEFT: |
| 2223 | case OVERWRITE_RIGHT: |
| 2224 | // If the operand was an object, we skip the |
| 2225 | // allocation of a heap number. |
| 2226 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2227 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2228 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2229 | // Fall through! |
| 2230 | case NO_OVERWRITE: |
| 2231 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2232 | __ bind(&skip_allocation); |
| 2233 | break; |
| 2234 | default: UNREACHABLE(); |
| 2235 | } |
| 2236 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2237 | if (CpuFeatures::IsSupported(SSE2)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2238 | CpuFeatures::Scope use_sse2(SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2239 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2240 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2241 | } else { |
| 2242 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2243 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2244 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2245 | } |
| 2246 | __ ret(2 * kPointerSize); |
| 2247 | } |
| 2248 | break; |
| 2249 | } |
| 2250 | default: UNREACHABLE(); break; |
| 2251 | } |
| 2252 | |
| 2253 | // If all else fails, use the runtime system to get the correct |
| 2254 | // result. |
| 2255 | __ bind(&call_runtime); |
| 2256 | switch (op_) { |
| 2257 | case Token::ADD: { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2258 | GenerateAddStrings(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2259 | GenerateRegisterArgsPush(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2260 | __ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION); |
| 2261 | break; |
| 2262 | } |
| 2263 | case Token::SUB: |
| 2264 | GenerateRegisterArgsPush(masm); |
| 2265 | __ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION); |
| 2266 | break; |
| 2267 | case Token::MUL: |
| 2268 | GenerateRegisterArgsPush(masm); |
| 2269 | __ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION); |
| 2270 | break; |
| 2271 | case Token::DIV: |
| 2272 | GenerateRegisterArgsPush(masm); |
| 2273 | __ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION); |
| 2274 | break; |
| 2275 | case Token::MOD: |
| 2276 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 2277 | break; |
| 2278 | case Token::BIT_OR: |
| 2279 | __ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION); |
| 2280 | break; |
| 2281 | case Token::BIT_AND: |
| 2282 | __ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION); |
| 2283 | break; |
| 2284 | case Token::BIT_XOR: |
| 2285 | __ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION); |
| 2286 | break; |
| 2287 | case Token::SAR: |
| 2288 | __ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION); |
| 2289 | break; |
| 2290 | case Token::SHL: |
| 2291 | __ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION); |
| 2292 | break; |
| 2293 | case Token::SHR: |
| 2294 | __ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION); |
| 2295 | break; |
| 2296 | default: |
| 2297 | UNREACHABLE(); |
| 2298 | } |
| 2299 | } |
| 2300 | |
| 2301 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2302 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2303 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2304 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2305 | |
| 2306 | // Registers containing left and right operands respectively. |
| 2307 | Register left = edx; |
| 2308 | Register right = eax; |
| 2309 | |
| 2310 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2311 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2312 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2313 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2314 | |
| 2315 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 2316 | GenerateRegisterArgsPush(masm); |
| 2317 | __ TailCallStub(&string_add_left_stub); |
| 2318 | |
| 2319 | // Left operand is not a string, test right. |
| 2320 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2321 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2322 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2323 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2324 | |
| 2325 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
| 2326 | GenerateRegisterArgsPush(masm); |
| 2327 | __ TailCallStub(&string_add_right_stub); |
| 2328 | |
| 2329 | // Neither argument is a string. |
| 2330 | __ bind(&call_runtime); |
| 2331 | } |
| 2332 | |
| 2333 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2334 | void BinaryOpStub::GenerateHeapResultAllocation( |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2335 | MacroAssembler* masm, |
| 2336 | Label* alloc_failure) { |
| 2337 | Label skip_allocation; |
| 2338 | OverwriteMode mode = mode_; |
| 2339 | switch (mode) { |
| 2340 | case OVERWRITE_LEFT: { |
| 2341 | // If the argument in edx is already an object, we skip the |
| 2342 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2343 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2344 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2345 | // for the possible runtime call. |
| 2346 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2347 | // Now edx can be overwritten losing one of the arguments as we are |
| 2348 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2349 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2350 | __ bind(&skip_allocation); |
| 2351 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2352 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2353 | break; |
| 2354 | } |
| 2355 | case OVERWRITE_RIGHT: |
| 2356 | // If the argument in eax is already an object, we skip the |
| 2357 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2358 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2359 | // Fall through! |
| 2360 | case NO_OVERWRITE: |
| 2361 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2362 | // for the possible runtime call. |
| 2363 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2364 | // Now eax can be overwritten losing one of the arguments as we are |
| 2365 | // now done and will not need it any more. |
| 2366 | __ mov(eax, ebx); |
| 2367 | __ bind(&skip_allocation); |
| 2368 | break; |
| 2369 | default: UNREACHABLE(); |
| 2370 | } |
| 2371 | } |
| 2372 | |
| 2373 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2374 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2375 | __ pop(ecx); |
| 2376 | __ push(edx); |
| 2377 | __ push(eax); |
| 2378 | __ push(ecx); |
| 2379 | } |
| 2380 | |
| 2381 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2382 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2383 | // TAGGED case: |
| 2384 | // Input: |
| 2385 | // esp[4]: tagged number input argument (should be number). |
| 2386 | // esp[0]: return address. |
| 2387 | // Output: |
| 2388 | // eax: tagged double result. |
| 2389 | // UNTAGGED case: |
| 2390 | // Input:: |
| 2391 | // esp[0]: return address. |
| 2392 | // xmm1: untagged double input argument |
| 2393 | // Output: |
| 2394 | // xmm1: untagged double result. |
| 2395 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2396 | Label runtime_call; |
| 2397 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2398 | Label skip_cache; |
| 2399 | const bool tagged = (argument_type_ == TAGGED); |
| 2400 | if (tagged) { |
| 2401 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2402 | Label input_not_smi; |
| 2403 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2404 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2405 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2406 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2407 | // Then load the low and high words of the double into ebx, edx. |
| 2408 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2409 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2410 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2411 | __ mov(Operand(esp, 0), eax); |
| 2412 | __ fild_s(Operand(esp, 0)); |
| 2413 | __ fst_d(Operand(esp, 0)); |
| 2414 | __ pop(edx); |
| 2415 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2416 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2417 | __ bind(&input_not_smi); |
| 2418 | // Check if input is a HeapNumber. |
| 2419 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2420 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2421 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2422 | __ j(not_equal, &runtime_call); |
| 2423 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2424 | // low and high words into ebx, edx. |
| 2425 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2426 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2427 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2428 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2429 | __ bind(&loaded); |
| 2430 | } else { // UNTAGGED. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2431 | if (CpuFeatures::IsSupported(SSE4_1)) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2432 | CpuFeatures::Scope sse4_scope(SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2433 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2434 | } else { |
| 2435 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2436 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2437 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2438 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2442 | // ebx = low 32 bits of double value |
| 2443 | // edx = high 32 bits of double value |
| 2444 | // Compute hash (the shifts are arithmetic): |
| 2445 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2446 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2447 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2448 | __ mov(eax, ecx); |
| 2449 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2450 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2451 | __ mov(eax, ecx); |
| 2452 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2453 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2454 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2455 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2456 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2457 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2458 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2459 | // ebx = low 32 bits of double value. |
| 2460 | // edx = high 32 bits of double value. |
| 2461 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2462 | ExternalReference cache_array = |
| 2463 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2464 | __ mov(eax, Immediate(cache_array)); |
| 2465 | int cache_array_index = |
| 2466 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2467 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2468 | // Eax points to the cache for the type type_. |
| 2469 | // 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] | 2470 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2471 | __ j(zero, &runtime_call_clear_stack); |
| 2472 | #ifdef DEBUG |
| 2473 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2474 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2475 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2476 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2477 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2478 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2479 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2480 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2481 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2482 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2483 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2484 | } |
| 2485 | #endif |
| 2486 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2487 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2488 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2489 | // 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] | 2490 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2491 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2492 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2493 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2494 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2495 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2496 | Counters* counters = masm->isolate()->counters(); |
| 2497 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2498 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2499 | if (tagged) { |
| 2500 | __ fstp(0); |
| 2501 | __ ret(kPointerSize); |
| 2502 | } else { // UNTAGGED. |
| 2503 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2504 | __ Ret(); |
| 2505 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2506 | |
| 2507 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2508 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2509 | // Update cache with new value. |
| 2510 | // We are short on registers, so use no_reg as scratch. |
| 2511 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2512 | if (tagged) { |
| 2513 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2514 | } else { // UNTAGGED. |
| 2515 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2516 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2517 | __ movdbl(Operand(esp, 0), xmm1); |
| 2518 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2519 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2520 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2521 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2522 | __ mov(Operand(ecx, 0), ebx); |
| 2523 | __ mov(Operand(ecx, kIntSize), edx); |
| 2524 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2525 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2526 | if (tagged) { |
| 2527 | __ ret(kPointerSize); |
| 2528 | } else { // UNTAGGED. |
| 2529 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2530 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2531 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2532 | // Skip cache and return answer directly, only in untagged case. |
| 2533 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2534 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2535 | __ movdbl(Operand(esp, 0), xmm1); |
| 2536 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2537 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2538 | __ fstp_d(Operand(esp, 0)); |
| 2539 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2540 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2541 | // We return the value in xmm1 without adding it to the cache, but |
| 2542 | // 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] | 2543 | { |
| 2544 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2545 | // Allocate an unused object bigger than a HeapNumber. |
| 2546 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2547 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2548 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2549 | __ Ret(); |
| 2550 | } |
| 2551 | |
| 2552 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2553 | if (tagged) { |
| 2554 | __ bind(&runtime_call_clear_stack); |
| 2555 | __ fstp(0); |
| 2556 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2557 | ExternalReference runtime = |
| 2558 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2559 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2560 | } else { // UNTAGGED. |
| 2561 | __ bind(&runtime_call_clear_stack); |
| 2562 | __ bind(&runtime_call); |
| 2563 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2564 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2565 | { |
| 2566 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2567 | __ push(eax); |
| 2568 | __ CallRuntime(RuntimeFunction(), 1); |
| 2569 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2570 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2571 | __ Ret(); |
| 2572 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | |
| 2576 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2577 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2578 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2579 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2580 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2581 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2582 | default: |
| 2583 | UNIMPLEMENTED(); |
| 2584 | return Runtime::kAbort; |
| 2585 | } |
| 2586 | } |
| 2587 | |
| 2588 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2589 | void TranscendentalCacheStub::GenerateOperation( |
| 2590 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2591 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2592 | // Input value is on FP stack, and also in ebx/edx. |
| 2593 | // Input value is possibly in xmm1. |
| 2594 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2595 | if (type == TranscendentalCache::SIN || |
| 2596 | type == TranscendentalCache::COS || |
| 2597 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2598 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2599 | // return NaN for infinities and NaN. They can share all code except |
| 2600 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2601 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2602 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2603 | // work. We must reduce it to the appropriate range. |
| 2604 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2605 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2606 | int supported_exponent_limit = |
| 2607 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2608 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2609 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2610 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2611 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2612 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2613 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2614 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2615 | __ fstp(0); |
| 2616 | // NaN is represented by 0x7ff8000000000000. |
| 2617 | __ push(Immediate(0x7ff80000)); |
| 2618 | __ push(Immediate(0)); |
| 2619 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2620 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2621 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2622 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2623 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2624 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2625 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2626 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2627 | __ fldpi(); |
| 2628 | __ fadd(0); |
| 2629 | __ fld(1); |
| 2630 | // FPU Stack: input, 2*pi, input. |
| 2631 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2632 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2633 | __ fwait(); |
| 2634 | __ fnstsw_ax(); |
| 2635 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2636 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2637 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2638 | __ fnclex(); |
| 2639 | __ bind(&no_exceptions); |
| 2640 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2641 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2642 | // Compute st(0) % st(1) |
| 2643 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2644 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2645 | __ bind(&partial_remainder_loop); |
| 2646 | __ fprem1(); |
| 2647 | __ fwait(); |
| 2648 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2649 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2650 | // If C2 is set, computation only has partial result. Loop to |
| 2651 | // continue computation. |
| 2652 | __ j(not_zero, &partial_remainder_loop); |
| 2653 | } |
| 2654 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2655 | __ fstp(2); |
| 2656 | __ fstp(0); |
| 2657 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2658 | |
| 2659 | // FPU Stack: input % 2*pi |
| 2660 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2661 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2662 | case TranscendentalCache::SIN: |
| 2663 | __ fsin(); |
| 2664 | break; |
| 2665 | case TranscendentalCache::COS: |
| 2666 | __ fcos(); |
| 2667 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2668 | case TranscendentalCache::TAN: |
| 2669 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2670 | // FP register stack. |
| 2671 | __ fptan(); |
| 2672 | __ fstp(0); // Pop FP register stack. |
| 2673 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2674 | default: |
| 2675 | UNREACHABLE(); |
| 2676 | } |
| 2677 | __ bind(&done); |
| 2678 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2679 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2680 | __ fldln2(); |
| 2681 | __ fxch(); |
| 2682 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2683 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2687 | // Input: edx, eax are the left and right objects of a bit op. |
| 2688 | // 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] | 2689 | void FloatingPointHelper::LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 2690 | bool use_sse3, |
| 2691 | Label* conversion_failure) { |
| 2692 | // Check float operands. |
| 2693 | Label arg1_is_object, check_undefined_arg1; |
| 2694 | Label arg2_is_object, check_undefined_arg2; |
| 2695 | Label load_arg2, done; |
| 2696 | |
| 2697 | // Test if arg1 is a Smi. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2698 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2699 | |
| 2700 | __ SmiUntag(edx); |
| 2701 | __ jmp(&load_arg2); |
| 2702 | |
| 2703 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2704 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2705 | Factory* factory = masm->isolate()->factory(); |
| 2706 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2707 | __ j(not_equal, conversion_failure); |
| 2708 | __ mov(edx, Immediate(0)); |
| 2709 | __ jmp(&load_arg2); |
| 2710 | |
| 2711 | __ bind(&arg1_is_object); |
| 2712 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2713 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2714 | __ j(not_equal, &check_undefined_arg1); |
| 2715 | |
| 2716 | // 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] | 2717 | IntegerConvert(masm, edx, use_sse3, conversion_failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2718 | __ mov(edx, ecx); |
| 2719 | |
| 2720 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2721 | __ bind(&load_arg2); |
| 2722 | |
| 2723 | // Test if arg2 is a Smi. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2724 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2725 | |
| 2726 | __ SmiUntag(eax); |
| 2727 | __ mov(ecx, eax); |
| 2728 | __ jmp(&done); |
| 2729 | |
| 2730 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2731 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2732 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2733 | __ j(not_equal, conversion_failure); |
| 2734 | __ mov(ecx, Immediate(0)); |
| 2735 | __ jmp(&done); |
| 2736 | |
| 2737 | __ bind(&arg2_is_object); |
| 2738 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2739 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2740 | __ j(not_equal, &check_undefined_arg2); |
| 2741 | |
| 2742 | // 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] | 2743 | IntegerConvert(masm, eax, use_sse3, conversion_failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2744 | __ bind(&done); |
| 2745 | __ mov(eax, edx); |
| 2746 | } |
| 2747 | |
| 2748 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2749 | void FloatingPointHelper::CheckLoadedIntegersWereInt32(MacroAssembler* masm, |
| 2750 | bool use_sse3, |
| 2751 | Label* not_int32) { |
| 2752 | return; |
| 2753 | } |
| 2754 | |
| 2755 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2756 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2757 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2758 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2759 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2760 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2761 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2762 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2763 | |
| 2764 | __ bind(&load_smi); |
| 2765 | __ SmiUntag(number); |
| 2766 | __ push(number); |
| 2767 | __ fild_s(Operand(esp, 0)); |
| 2768 | __ pop(number); |
| 2769 | |
| 2770 | __ bind(&done); |
| 2771 | } |
| 2772 | |
| 2773 | |
| 2774 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2775 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2776 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2777 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2778 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2779 | |
| 2780 | __ bind(&load_eax); |
| 2781 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2782 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2783 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2784 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2785 | |
| 2786 | __ bind(&load_smi_edx); |
| 2787 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2788 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2789 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2790 | __ jmp(&load_eax); |
| 2791 | |
| 2792 | __ bind(&load_smi_eax); |
| 2793 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2794 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2795 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2796 | |
| 2797 | __ bind(&done); |
| 2798 | } |
| 2799 | |
| 2800 | |
| 2801 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2802 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2803 | 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] | 2804 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2805 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2806 | Factory* factory = masm->isolate()->factory(); |
| 2807 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2808 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2809 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2810 | __ bind(&load_eax); |
| 2811 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2812 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2813 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2814 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2815 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2816 | __ bind(&load_smi_edx); |
| 2817 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2818 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2819 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2820 | __ jmp(&load_eax); |
| 2821 | __ bind(&load_smi_eax); |
| 2822 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2823 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2824 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2825 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2826 | __ bind(&load_float_eax); |
| 2827 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2828 | __ bind(&done); |
| 2829 | } |
| 2830 | |
| 2831 | |
| 2832 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2833 | Register scratch) { |
| 2834 | const Register left = edx; |
| 2835 | const Register right = eax; |
| 2836 | __ mov(scratch, left); |
| 2837 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2838 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2839 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2840 | |
| 2841 | __ mov(scratch, right); |
| 2842 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2843 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2847 | void FloatingPointHelper::CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 2848 | Label* non_int32, |
| 2849 | Register scratch) { |
| 2850 | __ cvttsd2si(scratch, Operand(xmm0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2851 | __ cvtsi2sd(xmm2, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2852 | __ ucomisd(xmm0, xmm2); |
| 2853 | __ j(not_zero, non_int32); |
| 2854 | __ j(carry, non_int32); |
| 2855 | __ cvttsd2si(scratch, Operand(xmm1)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2856 | __ cvtsi2sd(xmm2, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2857 | __ ucomisd(xmm1, xmm2); |
| 2858 | __ j(not_zero, non_int32); |
| 2859 | __ j(carry, non_int32); |
| 2860 | } |
| 2861 | |
| 2862 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2863 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2864 | Register scratch, |
| 2865 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2866 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2867 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2868 | __ mov(scratch, edx); |
| 2869 | } else { |
| 2870 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2871 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2872 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2873 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2874 | __ bind(&done_load_1); |
| 2875 | |
| 2876 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2877 | __ mov(scratch, eax); |
| 2878 | } else { |
| 2879 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2880 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2881 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2882 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2883 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2884 | |
| 2885 | __ bind(&load_smi_1); |
| 2886 | __ SmiUntag(scratch); |
| 2887 | __ push(scratch); |
| 2888 | __ fild_s(Operand(esp, 0)); |
| 2889 | __ pop(scratch); |
| 2890 | __ jmp(&done_load_1); |
| 2891 | |
| 2892 | __ bind(&load_smi_2); |
| 2893 | __ SmiUntag(scratch); |
| 2894 | __ push(scratch); |
| 2895 | __ fild_s(Operand(esp, 0)); |
| 2896 | __ pop(scratch); |
| 2897 | |
| 2898 | __ bind(&done); |
| 2899 | } |
| 2900 | |
| 2901 | |
| 2902 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2903 | Register scratch) { |
| 2904 | const Register left = edx; |
| 2905 | const Register right = eax; |
| 2906 | __ mov(scratch, left); |
| 2907 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2908 | __ SmiUntag(scratch); |
| 2909 | __ push(scratch); |
| 2910 | __ fild_s(Operand(esp, 0)); |
| 2911 | |
| 2912 | __ mov(scratch, right); |
| 2913 | __ SmiUntag(scratch); |
| 2914 | __ mov(Operand(esp, 0), scratch); |
| 2915 | __ fild_s(Operand(esp, 0)); |
| 2916 | __ pop(scratch); |
| 2917 | } |
| 2918 | |
| 2919 | |
| 2920 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2921 | Label* non_float, |
| 2922 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2923 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2924 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 2925 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2926 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2927 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2928 | Factory* factory = masm->isolate()->factory(); |
| 2929 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2930 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 2931 | |
| 2932 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2933 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2934 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2935 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2936 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 2937 | |
| 2938 | // Fall-through: Both operands are numbers. |
| 2939 | __ bind(&done); |
| 2940 | } |
| 2941 | |
| 2942 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2943 | void FloatingPointHelper::CheckFloatOperandsAreInt32(MacroAssembler* masm, |
| 2944 | Label* non_int32) { |
| 2945 | return; |
| 2946 | } |
| 2947 | |
| 2948 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2949 | void MathPowStub::Generate(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2950 | CpuFeatures::Scope use_sse2(SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2951 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2952 | const Register exponent = eax; |
| 2953 | const Register base = edx; |
| 2954 | const Register scratch = ecx; |
| 2955 | const XMMRegister double_result = xmm3; |
| 2956 | const XMMRegister double_base = xmm2; |
| 2957 | const XMMRegister double_exponent = xmm1; |
| 2958 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2959 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2960 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2961 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2962 | // Save 1 in double_result - we need this several times later on. |
| 2963 | __ mov(scratch, Immediate(1)); |
| 2964 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2965 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2966 | if (exponent_type_ == ON_STACK) { |
| 2967 | Label base_is_smi, unpack_exponent; |
| 2968 | // The exponent and base are supplied as arguments on the stack. |
| 2969 | // This can only happen if the stub is called from non-optimized code. |
| 2970 | // Load input parameters from stack. |
| 2971 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 2972 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 2973 | |
| 2974 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 2975 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 2976 | factory->heap_number_map()); |
| 2977 | __ j(not_equal, &call_runtime); |
| 2978 | |
| 2979 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 2980 | __ jmp(&unpack_exponent, Label::kNear); |
| 2981 | |
| 2982 | __ bind(&base_is_smi); |
| 2983 | __ SmiUntag(base); |
| 2984 | __ cvtsi2sd(double_base, base); |
| 2985 | |
| 2986 | __ bind(&unpack_exponent); |
| 2987 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2988 | __ SmiUntag(exponent); |
| 2989 | __ jmp(&int_exponent); |
| 2990 | |
| 2991 | __ bind(&exponent_not_smi); |
| 2992 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 2993 | factory->heap_number_map()); |
| 2994 | __ j(not_equal, &call_runtime); |
| 2995 | __ movdbl(double_exponent, |
| 2996 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2997 | } else if (exponent_type_ == TAGGED) { |
| 2998 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2999 | __ SmiUntag(exponent); |
| 3000 | __ jmp(&int_exponent); |
| 3001 | |
| 3002 | __ bind(&exponent_not_smi); |
| 3003 | __ movdbl(double_exponent, |
| 3004 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 3005 | } |
| 3006 | |
| 3007 | if (exponent_type_ != INTEGER) { |
| 3008 | Label fast_power; |
| 3009 | // Detect integer exponents stored as double. |
| 3010 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 3011 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 3012 | __ cmp(exponent, Immediate(0x80000000u)); |
| 3013 | __ j(equal, &call_runtime); |
| 3014 | __ cvtsi2sd(double_scratch, exponent); |
| 3015 | // Already ruled out NaNs for exponent. |
| 3016 | __ ucomisd(double_exponent, double_scratch); |
| 3017 | __ j(equal, &int_exponent); |
| 3018 | |
| 3019 | if (exponent_type_ == ON_STACK) { |
| 3020 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 3021 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 3022 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 3023 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 3024 | // Test for 0.5. |
| 3025 | // Load double_scratch with 0.5. |
| 3026 | __ mov(scratch, Immediate(0x3F000000u)); |
| 3027 | __ movd(double_scratch, scratch); |
| 3028 | __ cvtss2sd(double_scratch, double_scratch); |
| 3029 | // Already ruled out NaNs for exponent. |
| 3030 | __ ucomisd(double_scratch, double_exponent); |
| 3031 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 3032 | |
| 3033 | // Calculates square root of base. Check for the special case of |
| 3034 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 3035 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3036 | // 9 bits set and the lowest 23 bits cleared. |
| 3037 | __ mov(scratch, 0xFF800000u); |
| 3038 | __ movd(double_scratch, scratch); |
| 3039 | __ cvtss2sd(double_scratch, double_scratch); |
| 3040 | __ ucomisd(double_base, double_scratch); |
| 3041 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3042 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3043 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 3044 | __ j(carry, &continue_sqrt, Label::kNear); |
| 3045 | |
| 3046 | // Set result to Infinity in the special case. |
| 3047 | __ xorps(double_result, double_result); |
| 3048 | __ subsd(double_result, double_scratch); |
| 3049 | __ jmp(&done); |
| 3050 | |
| 3051 | __ bind(&continue_sqrt); |
| 3052 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3053 | __ xorps(double_scratch, double_scratch); |
| 3054 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 3055 | __ sqrtsd(double_result, double_scratch); |
| 3056 | __ jmp(&done); |
| 3057 | |
| 3058 | // Test for -0.5. |
| 3059 | __ bind(¬_plus_half); |
| 3060 | // Load double_exponent with -0.5 by substracting 1. |
| 3061 | __ subsd(double_scratch, double_result); |
| 3062 | // Already ruled out NaNs for exponent. |
| 3063 | __ ucomisd(double_scratch, double_exponent); |
| 3064 | __ j(not_equal, &fast_power, Label::kNear); |
| 3065 | |
| 3066 | // Calculates reciprocal of square root of base. Check for the special |
| 3067 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 3068 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3069 | // 9 bits set and the lowest 23 bits cleared. |
| 3070 | __ mov(scratch, 0xFF800000u); |
| 3071 | __ movd(double_scratch, scratch); |
| 3072 | __ cvtss2sd(double_scratch, double_scratch); |
| 3073 | __ ucomisd(double_base, double_scratch); |
| 3074 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3075 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3076 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 3077 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 3078 | |
| 3079 | // Set result to 0 in the special case. |
| 3080 | __ xorps(double_result, double_result); |
| 3081 | __ jmp(&done); |
| 3082 | |
| 3083 | __ bind(&continue_rsqrt); |
| 3084 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3085 | __ xorps(double_exponent, double_exponent); |
| 3086 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 3087 | __ sqrtsd(double_exponent, double_exponent); |
| 3088 | __ divsd(double_result, double_exponent); |
| 3089 | __ jmp(&done); |
| 3090 | } |
| 3091 | |
| 3092 | // Using FPU instructions to calculate power. |
| 3093 | Label fast_power_failed; |
| 3094 | __ bind(&fast_power); |
| 3095 | __ fnclex(); // Clear flags to catch exceptions later. |
| 3096 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 3097 | __ sub(esp, Immediate(kDoubleSize)); |
| 3098 | __ movdbl(Operand(esp, 0), double_exponent); |
| 3099 | __ fld_d(Operand(esp, 0)); // E |
| 3100 | __ movdbl(Operand(esp, 0), double_base); |
| 3101 | __ fld_d(Operand(esp, 0)); // B, E |
| 3102 | |
| 3103 | // Exponent is in st(1) and base is in st(0) |
| 3104 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 3105 | // FYL2X calculates st(1) * log2(st(0)) |
| 3106 | __ fyl2x(); // X |
| 3107 | __ fld(0); // X, X |
| 3108 | __ frndint(); // rnd(X), X |
| 3109 | __ fsub(1); // rnd(X), X-rnd(X) |
| 3110 | __ fxch(1); // X - rnd(X), rnd(X) |
| 3111 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 3112 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 3113 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
| 3114 | __ faddp(1); // 1, 2^(X-rnd(X)), rnd(X) |
| 3115 | // FSCALE calculates st(0) * 2^st(1) |
| 3116 | __ fscale(); // 2^X, rnd(X) |
| 3117 | __ fstp(1); |
| 3118 | // Bail out to runtime in case of exceptions in the status word. |
| 3119 | __ fnstsw_ax(); |
| 3120 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 3121 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 3122 | __ fstp_d(Operand(esp, 0)); |
| 3123 | __ movdbl(double_result, Operand(esp, 0)); |
| 3124 | __ add(esp, Immediate(kDoubleSize)); |
| 3125 | __ jmp(&done); |
| 3126 | |
| 3127 | __ bind(&fast_power_failed); |
| 3128 | __ fninit(); |
| 3129 | __ add(esp, Immediate(kDoubleSize)); |
| 3130 | __ jmp(&call_runtime); |
| 3131 | } |
| 3132 | |
| 3133 | // Calculate power with integer exponent. |
| 3134 | __ bind(&int_exponent); |
| 3135 | const XMMRegister double_scratch2 = double_exponent; |
| 3136 | __ mov(scratch, exponent); // Back up exponent. |
| 3137 | __ movsd(double_scratch, double_base); // Back up base. |
| 3138 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3139 | |
| 3140 | // Get absolute value of exponent. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3141 | Label no_neg, while_true, no_multiply; |
| 3142 | __ test(scratch, scratch); |
| 3143 | __ j(positive, &no_neg, Label::kNear); |
| 3144 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3145 | __ bind(&no_neg); |
| 3146 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3147 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3148 | __ shr(scratch, 1); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3149 | __ j(not_carry, &no_multiply, Label::kNear); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3150 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3151 | __ bind(&no_multiply); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3152 | |
| 3153 | __ mulsd(double_scratch, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3154 | __ j(not_zero, &while_true); |
| 3155 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3156 | // scratch has the original value of the exponent - if the exponent is |
| 3157 | // negative, return 1/result. |
| 3158 | __ test(exponent, exponent); |
| 3159 | __ j(positive, &done); |
| 3160 | __ divsd(double_scratch2, double_result); |
| 3161 | __ movsd(double_result, double_scratch2); |
| 3162 | // Test whether result is zero. Bail out to check for subnormal result. |
| 3163 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 3164 | __ xorps(double_scratch2, double_scratch2); |
| 3165 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 3166 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 3167 | // and may not have contained the exponent value in the first place when the |
| 3168 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 3169 | __ j(not_equal, &done); |
| 3170 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3171 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3172 | // Returning or bailing out. |
| 3173 | Counters* counters = masm->isolate()->counters(); |
| 3174 | if (exponent_type_ == ON_STACK) { |
| 3175 | // The arguments are still on the stack. |
| 3176 | __ bind(&call_runtime); |
| 3177 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3178 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3179 | // The stub is called from non-optimized code, which expects the result |
| 3180 | // as heap number in exponent. |
| 3181 | __ bind(&done); |
| 3182 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 3183 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 3184 | __ IncrementCounter(counters->math_pow(), 1); |
| 3185 | __ ret(2 * kPointerSize); |
| 3186 | } else { |
| 3187 | __ bind(&call_runtime); |
| 3188 | { |
| 3189 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3190 | __ PrepareCallCFunction(4, scratch); |
| 3191 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 3192 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 3193 | __ CallCFunction( |
| 3194 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 3195 | } |
| 3196 | // Return value is in st(0) on ia32. |
| 3197 | // Store it into the (fixed) result register. |
| 3198 | __ sub(esp, Immediate(kDoubleSize)); |
| 3199 | __ fstp_d(Operand(esp, 0)); |
| 3200 | __ movdbl(double_result, Operand(esp, 0)); |
| 3201 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3202 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3203 | __ bind(&done); |
| 3204 | __ IncrementCounter(counters->math_pow(), 1); |
| 3205 | __ ret(0); |
| 3206 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3207 | } |
| 3208 | |
| 3209 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3210 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3211 | // The key is in edx and the parameter count is in eax. |
| 3212 | |
| 3213 | // The displacement is used for skipping the frame pointer on the |
| 3214 | // stack. It is the offset of the last parameter (if any) relative |
| 3215 | // to the frame pointer. |
| 3216 | static const int kDisplacement = 1 * kPointerSize; |
| 3217 | |
| 3218 | // Check that the key is a smi. |
| 3219 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3220 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3221 | |
| 3222 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3223 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3224 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3225 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3226 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3227 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3228 | |
| 3229 | // Check index against formal parameters count limit passed in |
| 3230 | // through register eax. Use unsigned comparison to get negative |
| 3231 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3232 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3233 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3234 | |
| 3235 | // Read the argument from the stack and return it. |
| 3236 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3237 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3238 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3239 | __ neg(edx); |
| 3240 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3241 | __ ret(0); |
| 3242 | |
| 3243 | // Arguments adaptor case: Check index against actual arguments |
| 3244 | // limit found in the arguments adaptor frame. Use unsigned |
| 3245 | // comparison to get negative check for free. |
| 3246 | __ bind(&adaptor); |
| 3247 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3248 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3249 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3250 | |
| 3251 | // Read the argument from the stack and return it. |
| 3252 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3253 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3254 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3255 | __ neg(edx); |
| 3256 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3257 | __ ret(0); |
| 3258 | |
| 3259 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3260 | // by calling the runtime system. |
| 3261 | __ bind(&slow); |
| 3262 | __ pop(ebx); // Return address. |
| 3263 | __ push(edx); |
| 3264 | __ push(ebx); |
| 3265 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3266 | } |
| 3267 | |
| 3268 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3269 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3270 | // esp[0] : return address |
| 3271 | // esp[4] : number of parameters |
| 3272 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3273 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3274 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3275 | // Check if the calling frame is an arguments adaptor frame. |
| 3276 | Label runtime; |
| 3277 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3278 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3279 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3280 | __ j(not_equal, &runtime, Label::kNear); |
| 3281 | |
| 3282 | // Patch the arguments.length and the parameters pointer. |
| 3283 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3284 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3285 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3286 | StandardFrameConstants::kCallerSPOffset)); |
| 3287 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3288 | |
| 3289 | __ bind(&runtime); |
| 3290 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3291 | } |
| 3292 | |
| 3293 | |
| 3294 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 3295 | // esp[0] : return address |
| 3296 | // esp[4] : number of parameters (tagged) |
| 3297 | // esp[8] : receiver displacement |
| 3298 | // esp[12] : function |
| 3299 | |
| 3300 | // ebx = parameter count (tagged) |
| 3301 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3302 | |
| 3303 | // Check if the calling frame is an arguments adaptor frame. |
| 3304 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3305 | // Generate* functions. |
| 3306 | Label runtime; |
| 3307 | Label adaptor_frame, try_allocate; |
| 3308 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3309 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3310 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3311 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3312 | |
| 3313 | // No adaptor, parameter count = argument count. |
| 3314 | __ mov(ecx, ebx); |
| 3315 | __ jmp(&try_allocate, Label::kNear); |
| 3316 | |
| 3317 | // We have an adaptor frame. Patch the parameters pointer. |
| 3318 | __ bind(&adaptor_frame); |
| 3319 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3320 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3321 | StandardFrameConstants::kCallerSPOffset)); |
| 3322 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3323 | |
| 3324 | // ebx = parameter count (tagged) |
| 3325 | // ecx = argument count (tagged) |
| 3326 | // esp[4] = parameter count (tagged) |
| 3327 | // esp[8] = address of receiver argument |
| 3328 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3329 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3330 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3331 | __ mov(ebx, ecx); |
| 3332 | |
| 3333 | __ bind(&try_allocate); |
| 3334 | |
| 3335 | // Save mapped parameter count. |
| 3336 | __ push(ebx); |
| 3337 | |
| 3338 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3339 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3340 | const int kParameterMapHeaderSize = |
| 3341 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3342 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3343 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3344 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3345 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3346 | __ bind(&no_parameter_map); |
| 3347 | |
| 3348 | // 2. Backing store. |
| 3349 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3350 | |
| 3351 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3352 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3353 | |
| 3354 | // Do the allocation of all three objects in one go. |
| 3355 | __ AllocateInNewSpace(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
| 3356 | |
| 3357 | // eax = address of new object(s) (tagged) |
| 3358 | // ecx = argument count (tagged) |
| 3359 | // esp[0] = mapped parameter count (tagged) |
| 3360 | // esp[8] = parameter count (tagged) |
| 3361 | // esp[12] = address of receiver argument |
| 3362 | // Get the arguments boilerplate from the current (global) context into edi. |
| 3363 | Label has_mapped_parameters, copy; |
| 3364 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 3365 | __ mov(edi, FieldOperand(edi, GlobalObject::kGlobalContextOffset)); |
| 3366 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3367 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3368 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3369 | __ mov(edi, Operand(edi, |
| 3370 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3371 | __ jmp(©, Label::kNear); |
| 3372 | |
| 3373 | __ bind(&has_mapped_parameters); |
| 3374 | __ mov(edi, Operand(edi, |
| 3375 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3376 | __ bind(©); |
| 3377 | |
| 3378 | // eax = address of new object (tagged) |
| 3379 | // ebx = mapped parameter count (tagged) |
| 3380 | // ecx = argument count (tagged) |
| 3381 | // edi = address of boilerplate object (tagged) |
| 3382 | // esp[0] = mapped parameter count (tagged) |
| 3383 | // esp[8] = parameter count (tagged) |
| 3384 | // esp[12] = address of receiver argument |
| 3385 | // Copy the JS object part. |
| 3386 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3387 | __ mov(edx, FieldOperand(edi, i)); |
| 3388 | __ mov(FieldOperand(eax, i), edx); |
| 3389 | } |
| 3390 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3391 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3392 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3393 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3394 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3395 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3396 | edx); |
| 3397 | |
| 3398 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3399 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3400 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3401 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3402 | ecx); |
| 3403 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3404 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3405 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3406 | // backing store. |
| 3407 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3408 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3409 | |
| 3410 | // eax = address of new object (tagged) |
| 3411 | // ebx = mapped parameter count (tagged) |
| 3412 | // ecx = argument count (tagged) |
| 3413 | // edi = address of parameter map or backing store (tagged) |
| 3414 | // esp[0] = mapped parameter count (tagged) |
| 3415 | // esp[8] = parameter count (tagged) |
| 3416 | // esp[12] = address of receiver argument |
| 3417 | // Free a register. |
| 3418 | __ push(eax); |
| 3419 | |
| 3420 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3421 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3422 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3423 | __ j(zero, &skip_parameter_map); |
| 3424 | |
| 3425 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3426 | Immediate(FACTORY->non_strict_arguments_elements_map())); |
| 3427 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3428 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3429 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3430 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3431 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3432 | |
| 3433 | // Copy the parameter slots and the holes in the arguments. |
| 3434 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3435 | // where parameters are stored in reverse order, at |
| 3436 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3437 | // The mapped parameter thus need to get indices |
| 3438 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3439 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3440 | // We loop from right to left. |
| 3441 | Label parameters_loop, parameters_test; |
| 3442 | __ push(ecx); |
| 3443 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3444 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3445 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3446 | __ sub(ebx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3447 | __ mov(ecx, FACTORY->the_hole_value()); |
| 3448 | __ mov(edx, edi); |
| 3449 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3450 | // eax = loop variable (tagged) |
| 3451 | // ebx = mapping index (tagged) |
| 3452 | // ecx = the hole value |
| 3453 | // edx = address of parameter map (tagged) |
| 3454 | // edi = address of backing store (tagged) |
| 3455 | // esp[0] = argument count (tagged) |
| 3456 | // esp[4] = address of new object (tagged) |
| 3457 | // esp[8] = mapped parameter count (tagged) |
| 3458 | // esp[16] = parameter count (tagged) |
| 3459 | // esp[20] = address of receiver argument |
| 3460 | __ jmp(¶meters_test, Label::kNear); |
| 3461 | |
| 3462 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3463 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3464 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3465 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3466 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3467 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3468 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3469 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3470 | __ pop(ecx); |
| 3471 | |
| 3472 | __ bind(&skip_parameter_map); |
| 3473 | |
| 3474 | // ecx = argument count (tagged) |
| 3475 | // edi = address of backing store (tagged) |
| 3476 | // esp[0] = address of new object (tagged) |
| 3477 | // esp[4] = mapped parameter count (tagged) |
| 3478 | // esp[12] = parameter count (tagged) |
| 3479 | // esp[16] = address of receiver argument |
| 3480 | // Copy arguments header and remaining slots (if there are any). |
| 3481 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3482 | Immediate(FACTORY->fixed_array_map())); |
| 3483 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3484 | |
| 3485 | Label arguments_loop, arguments_test; |
| 3486 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3487 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3488 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3489 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3490 | __ jmp(&arguments_test, Label::kNear); |
| 3491 | |
| 3492 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3493 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3494 | __ mov(eax, Operand(edx, 0)); |
| 3495 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3496 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3497 | |
| 3498 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3499 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3500 | __ j(less, &arguments_loop, Label::kNear); |
| 3501 | |
| 3502 | // Restore. |
| 3503 | __ pop(eax); // Address of arguments object. |
| 3504 | __ pop(ebx); // Parameter count. |
| 3505 | |
| 3506 | // Return and remove the on-stack parameters. |
| 3507 | __ ret(3 * kPointerSize); |
| 3508 | |
| 3509 | // Do the runtime call to allocate the arguments object. |
| 3510 | __ bind(&runtime); |
| 3511 | __ pop(eax); // Remove saved parameter count. |
| 3512 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
| 3513 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
| 3514 | } |
| 3515 | |
| 3516 | |
| 3517 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 3518 | // esp[0] : return address |
| 3519 | // esp[4] : number of parameters |
| 3520 | // esp[8] : receiver displacement |
| 3521 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3522 | |
| 3523 | // Check if the calling frame is an arguments adaptor frame. |
| 3524 | Label adaptor_frame, try_allocate, runtime; |
| 3525 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3526 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3527 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3528 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3529 | |
| 3530 | // Get the length from the frame. |
| 3531 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3532 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3533 | |
| 3534 | // Patch the arguments.length and the parameters pointer. |
| 3535 | __ bind(&adaptor_frame); |
| 3536 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3537 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3538 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3539 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3540 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3541 | |
| 3542 | // Try the new space allocation. Start out with computing the size of |
| 3543 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3544 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3545 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3546 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3547 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3548 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3549 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3550 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3551 | |
| 3552 | // Do the allocation of both objects in one go. |
| 3553 | __ AllocateInNewSpace(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
| 3554 | |
| 3555 | // Get the arguments boilerplate from the current (global) context. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3556 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 3557 | __ mov(edi, FieldOperand(edi, GlobalObject::kGlobalContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3558 | const int offset = |
| 3559 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3560 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3561 | |
| 3562 | // Copy the JS object part. |
| 3563 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3564 | __ mov(ebx, FieldOperand(edi, i)); |
| 3565 | __ mov(FieldOperand(eax, i), ebx); |
| 3566 | } |
| 3567 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3568 | // 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] | 3569 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3570 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3571 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3572 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3573 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3574 | |
| 3575 | // If there are no actual arguments, we're done. |
| 3576 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3577 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3578 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3579 | |
| 3580 | // Get the parameters pointer from the stack. |
| 3581 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3582 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3583 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3584 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3585 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3586 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3587 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3588 | Immediate(FACTORY->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3589 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3590 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3591 | // Untag the length for the loop below. |
| 3592 | __ SmiUntag(ecx); |
| 3593 | |
| 3594 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3595 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3596 | __ bind(&loop); |
| 3597 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3598 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3599 | __ add(edi, Immediate(kPointerSize)); |
| 3600 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3601 | __ dec(ecx); |
| 3602 | __ j(not_zero, &loop); |
| 3603 | |
| 3604 | // Return and remove the on-stack parameters. |
| 3605 | __ bind(&done); |
| 3606 | __ ret(3 * kPointerSize); |
| 3607 | |
| 3608 | // Do the runtime call to allocate the arguments object. |
| 3609 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3610 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | |
| 3614 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3615 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3616 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3617 | // at compilation. |
| 3618 | #ifdef V8_INTERPRETED_REGEXP |
| 3619 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3620 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3621 | |
| 3622 | // Stack frame on entry. |
| 3623 | // esp[0]: return address |
| 3624 | // esp[4]: last_match_info (expected JSArray) |
| 3625 | // esp[8]: previous index |
| 3626 | // esp[12]: subject string |
| 3627 | // esp[16]: JSRegExp object |
| 3628 | |
| 3629 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3630 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3631 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3632 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3633 | |
| 3634 | Label runtime, invoke_regexp; |
| 3635 | |
| 3636 | // Ensure that a RegExp stack is allocated. |
| 3637 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3638 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3639 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3640 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3641 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3642 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3643 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3644 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3645 | |
| 3646 | // Check that the first argument is a JSRegExp object. |
| 3647 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3648 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3649 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3650 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3651 | __ j(not_equal, &runtime); |
| 3652 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3653 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3654 | if (FLAG_debug_code) { |
| 3655 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3656 | __ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected"); |
| 3657 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 3658 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 3659 | } |
| 3660 | |
| 3661 | // ecx: RegExp data (FixedArray) |
| 3662 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3663 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3664 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3665 | __ j(not_equal, &runtime); |
| 3666 | |
| 3667 | // ecx: RegExp data (FixedArray) |
| 3668 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3669 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3670 | // Calculate number of capture registers (number_of_captures + 1) * 2. This |
| 3671 | // uses the asumption that smis are 2 * their untagged value. |
| 3672 | STATIC_ASSERT(kSmiTag == 0); |
| 3673 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3674 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3675 | // Check that the static offsets vector buffer is large enough. |
| 3676 | __ cmp(edx, OffsetsVector::kStaticOffsetsVectorSize); |
| 3677 | __ j(above, &runtime); |
| 3678 | |
| 3679 | // ecx: RegExp data (FixedArray) |
| 3680 | // edx: Number of capture registers |
| 3681 | // Check that the second argument is a string. |
| 3682 | __ mov(eax, Operand(esp, kSubjectOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3683 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3684 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 3685 | __ j(NegateCondition(is_string), &runtime); |
| 3686 | // Get the length of the string to ebx. |
| 3687 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 3688 | |
| 3689 | // ebx: Length of subject string as a smi |
| 3690 | // ecx: RegExp data (FixedArray) |
| 3691 | // edx: Number of capture registers |
| 3692 | // Check that the third argument is a positive smi less than the subject |
| 3693 | // string length. A negative value will be greater (unsigned comparison). |
| 3694 | __ mov(eax, Operand(esp, kPreviousIndexOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3695 | __ JumpIfNotSmi(eax, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3696 | __ cmp(eax, ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3697 | __ j(above_equal, &runtime); |
| 3698 | |
| 3699 | // ecx: RegExp data (FixedArray) |
| 3700 | // edx: Number of capture registers |
| 3701 | // Check that the fourth object is a JSArray object. |
| 3702 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3703 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3704 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 3705 | __ j(not_equal, &runtime); |
| 3706 | // Check that the JSArray is in fast case. |
| 3707 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
| 3708 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3709 | Factory* factory = masm->isolate()->factory(); |
| 3710 | __ cmp(eax, factory->fixed_array_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3711 | __ j(not_equal, &runtime); |
| 3712 | // Check that the last match info has space for the capture registers and the |
| 3713 | // additional information. |
| 3714 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 3715 | __ SmiUntag(eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3716 | __ add(edx, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 3717 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3718 | __ j(greater, &runtime); |
| 3719 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3720 | // Reset offset for possibly sliced string. |
| 3721 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3722 | // ecx: RegExp data (FixedArray) |
| 3723 | // Check the representation and encoding of the subject string. |
| 3724 | Label seq_ascii_string, seq_two_byte_string, check_code; |
| 3725 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 3726 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3727 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3728 | // First check for flat two byte string. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3729 | __ and_(ebx, kIsNotStringMask | |
| 3730 | kStringRepresentationMask | |
| 3731 | kStringEncodingMask | |
| 3732 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3733 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3734 | __ j(zero, &seq_two_byte_string, Label::kNear); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3735 | // Any other flat string must be a flat ASCII string. None of the following |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3736 | // string type tests will succeed if subject is not a string or a short |
| 3737 | // external string. |
| 3738 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3739 | kStringRepresentationMask | |
| 3740 | kShortExternalStringMask)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3741 | __ j(zero, &seq_ascii_string, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3742 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3743 | // ebx: whether subject is a string and if yes, its string representation |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3744 | // Check for flat cons string or sliced string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3745 | // A flat cons string is a cons string where the second part is the empty |
| 3746 | // string. In that case the subject string is just the first part of the cons |
| 3747 | // string. Also in this case the first part of the cons string is known to be |
| 3748 | // a sequential string or an external string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3749 | // In the case of a sliced string its offset has to be taken into account. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3750 | Label cons_string, external_string, check_encoding; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3751 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3752 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3753 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3754 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3755 | __ cmp(ebx, Immediate(kExternalStringTag)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3756 | __ j(less, &cons_string); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3757 | __ j(equal, &external_string); |
| 3758 | |
| 3759 | // Catch non-string subject or short external string. |
| 3760 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 3761 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 3762 | __ j(not_zero, &runtime); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3763 | |
| 3764 | // String is sliced. |
| 3765 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 3766 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 3767 | // edi: offset of sliced string, smi-tagged. |
| 3768 | // eax: parent string. |
| 3769 | __ jmp(&check_encoding, Label::kNear); |
| 3770 | // String is a cons string, check whether it is flat. |
| 3771 | __ bind(&cons_string); |
| 3772 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3773 | __ j(not_equal, &runtime); |
| 3774 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3775 | __ bind(&check_encoding); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3776 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3777 | // eax: first part of cons string or parent of sliced string. |
| 3778 | // ebx: map of first part of cons string or map of parent of sliced string. |
| 3779 | // 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] | 3780 | __ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset), |
| 3781 | kStringRepresentationMask | kStringEncodingMask); |
| 3782 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3783 | __ j(zero, &seq_two_byte_string, Label::kNear); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3784 | // Any other flat string must be sequential ASCII or external. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3785 | __ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset), |
| 3786 | kStringRepresentationMask); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3787 | __ j(not_zero, &external_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3788 | |
| 3789 | __ bind(&seq_ascii_string); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3790 | // eax: subject string (flat ASCII) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3791 | // ecx: RegExp data (FixedArray) |
| 3792 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3793 | __ Set(ecx, Immediate(1)); // Type is ASCII. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3794 | __ jmp(&check_code, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3795 | |
| 3796 | __ bind(&seq_two_byte_string); |
| 3797 | // eax: subject string (flat two byte) |
| 3798 | // ecx: RegExp data (FixedArray) |
| 3799 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3800 | __ Set(ecx, Immediate(0)); // Type is two byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3801 | |
| 3802 | __ bind(&check_code); |
| 3803 | // Check that the irregexp code has been generated for the actual string |
| 3804 | // 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] | 3805 | // a smi (code flushing support). |
| 3806 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3807 | |
| 3808 | // eax: subject string |
| 3809 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3810 | // 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] | 3811 | // Load used arguments before starting to push arguments for call to native |
| 3812 | // RegExp code to avoid handling changing stack height. |
| 3813 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3814 | __ SmiUntag(ebx); // Previous index from smi. |
| 3815 | |
| 3816 | // eax: subject string |
| 3817 | // ebx: previous index |
| 3818 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3819 | // 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] | 3820 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3821 | Counters* counters = masm->isolate()->counters(); |
| 3822 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3823 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3824 | // Isolates: note we add an additional parameter here (isolate pointer). |
| 3825 | static const int kRegExpExecuteArguments = 8; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3826 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3827 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3828 | // Argument 8: Pass current isolate address. |
| 3829 | __ mov(Operand(esp, 7 * kPointerSize), |
| 3830 | Immediate(ExternalReference::isolate_address())); |
| 3831 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3832 | // Argument 7: Indicate that this is a direct call from JavaScript. |
| 3833 | __ mov(Operand(esp, 6 * kPointerSize), Immediate(1)); |
| 3834 | |
| 3835 | // Argument 6: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3836 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 3837 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
| 3838 | __ mov(Operand(esp, 5 * kPointerSize), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3839 | |
| 3840 | // Argument 5: static offsets vector buffer. |
| 3841 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3842 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 3843 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3844 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3845 | // Argument 2: Previous index. |
| 3846 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 3847 | |
| 3848 | // Argument 1: Original subject string. |
| 3849 | // The original subject is in the previous stack frame. Therefore we have to |
| 3850 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 3851 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 3852 | // and thereby moves up esp by one kPointerSize.) |
| 3853 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 3854 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 3855 | |
| 3856 | // esi: original subject string |
| 3857 | // eax: underlying subject string |
| 3858 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3859 | // ecx: encoding of subject string (1 if ASCII 0 if two_byte); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3860 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3861 | // Argument 4: End of string data |
| 3862 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3863 | // Prepare start and end index of the input. |
| 3864 | // Load the length from the original sliced string if that is the case. |
| 3865 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3866 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3867 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3868 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3869 | |
| 3870 | // ebx: start index of the input string |
| 3871 | // esi: end index of the input string |
| 3872 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3873 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3874 | __ j(zero, &setup_two_byte, Label::kNear); |
| 3875 | __ SmiUntag(esi); |
| 3876 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqAsciiString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3877 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3878 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqAsciiString::kHeaderSize)); |
| 3879 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3880 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3881 | |
| 3882 | __ bind(&setup_two_byte); |
| 3883 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3884 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 3885 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3886 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3887 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 3888 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 3889 | |
| 3890 | __ bind(&setup_rest); |
| 3891 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3892 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3893 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 3894 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3895 | |
| 3896 | // Drop arguments and come back to JS mode. |
| 3897 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3898 | |
| 3899 | // Check the result. |
| 3900 | Label success; |
| 3901 | __ cmp(eax, NativeRegExpMacroAssembler::SUCCESS); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3902 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3903 | Label failure; |
| 3904 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3905 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3906 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 3907 | // If not exception it can only be retry. Handle that in the runtime system. |
| 3908 | __ j(not_equal, &runtime); |
| 3909 | // Result must now be exception. If there is no pending exception already a |
| 3910 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 3911 | // haven't created the exception yet. Handle that in the runtime system. |
| 3912 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3913 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3914 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3915 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3916 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3917 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3918 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3919 | // For exception, throw the exception again. |
| 3920 | |
| 3921 | // Clear the pending exception variable. |
| 3922 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 3923 | |
| 3924 | // Special handling of termination exceptions which are uncatchable |
| 3925 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3926 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3927 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3928 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3929 | |
| 3930 | // Handle normal exception by following handler chain. |
| 3931 | __ Throw(eax); |
| 3932 | |
| 3933 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 3934 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3935 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3936 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3937 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3938 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3939 | __ ret(4 * kPointerSize); |
| 3940 | |
| 3941 | // Load RegExp data. |
| 3942 | __ bind(&success); |
| 3943 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3944 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3945 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3946 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 3947 | STATIC_ASSERT(kSmiTag == 0); |
| 3948 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3949 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3950 | |
| 3951 | // edx: Number of capture registers |
| 3952 | // Load last_match_info which is still known to be a fast case JSArray. |
| 3953 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 3954 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
| 3955 | |
| 3956 | // ebx: last_match_info backing store (FixedArray) |
| 3957 | // edx: number of capture registers |
| 3958 | // Store the capture count. |
| 3959 | __ SmiTag(edx); // Number of capture registers to smi. |
| 3960 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 3961 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 3962 | // Store last subject and last input. |
| 3963 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 3964 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3965 | __ RecordWriteField(ebx, |
| 3966 | RegExpImpl::kLastSubjectOffset, |
| 3967 | eax, |
| 3968 | edi, |
| 3969 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3970 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 3971 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3972 | __ RecordWriteField(ebx, |
| 3973 | RegExpImpl::kLastInputOffset, |
| 3974 | eax, |
| 3975 | edi, |
| 3976 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3977 | |
| 3978 | // Get the static offsets vector filled by the native regexp code. |
| 3979 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3980 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3981 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 3982 | |
| 3983 | // ebx: last_match_info backing store (FixedArray) |
| 3984 | // ecx: offsets vector |
| 3985 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3986 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3987 | // Capture register counter starts from number of capture registers and |
| 3988 | // counts down until wraping after zero. |
| 3989 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3990 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3991 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3992 | // Read the value from the static offsets vector buffer. |
| 3993 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 3994 | __ SmiTag(edi); |
| 3995 | // Store the smi value in the last match info. |
| 3996 | __ mov(FieldOperand(ebx, |
| 3997 | edx, |
| 3998 | times_pointer_size, |
| 3999 | RegExpImpl::kFirstCaptureOffset), |
| 4000 | edi); |
| 4001 | __ jmp(&next_capture); |
| 4002 | __ bind(&done); |
| 4003 | |
| 4004 | // Return last match info. |
| 4005 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 4006 | __ ret(4 * kPointerSize); |
| 4007 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4008 | // External string. Short external strings have already been ruled out. |
| 4009 | // eax: subject string (expected to be external) |
| 4010 | // ebx: scratch |
| 4011 | __ bind(&external_string); |
| 4012 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4013 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4014 | if (FLAG_debug_code) { |
| 4015 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 4016 | // Sequential strings have already been ruled out. |
| 4017 | __ test_b(ebx, kIsIndirectStringMask); |
| 4018 | __ Assert(zero, "external string expected, but not found"); |
| 4019 | } |
| 4020 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 4021 | // Move the pointer so that offset-wise, it looks like a sequential string. |
| 4022 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); |
| 4023 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4024 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 4025 | __ test_b(ebx, kStringEncodingMask); |
| 4026 | __ j(not_zero, &seq_ascii_string); |
| 4027 | __ jmp(&seq_two_byte_string); |
| 4028 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4029 | // Do the runtime call to execute the regexp. |
| 4030 | __ bind(&runtime); |
| 4031 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4032 | #endif // V8_INTERPRETED_REGEXP |
| 4033 | } |
| 4034 | |
| 4035 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4036 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 4037 | const int kMaxInlineLength = 100; |
| 4038 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4039 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4040 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4041 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4042 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4043 | __ j(above, &slowcase); |
| 4044 | // Smi-tagging is equivalent to multiplying by 2. |
| 4045 | STATIC_ASSERT(kSmiTag == 0); |
| 4046 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4047 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 4048 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 4049 | // Elements: [Map][Length][..elements..] |
| 4050 | __ AllocateInNewSpace(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 4051 | times_half_pointer_size, |
| 4052 | ebx, // In: Number of elements (times 2, being a smi) |
| 4053 | eax, // Out: Start of allocation (tagged). |
| 4054 | ecx, // Out: End of allocation. |
| 4055 | edx, // Scratch register |
| 4056 | &slowcase, |
| 4057 | TAG_OBJECT); |
| 4058 | // eax: Start of allocated area, object-tagged. |
| 4059 | |
| 4060 | // Set JSArray map to global.regexp_result_map(). |
| 4061 | // Set empty properties FixedArray. |
| 4062 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 4063 | // Interleave operations for better latency. |
| 4064 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4065 | Factory* factory = masm->isolate()->factory(); |
| 4066 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4067 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
| 4068 | __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalContextOffset)); |
| 4069 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 4070 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 4071 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 4072 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 4073 | |
| 4074 | // Set input, index and length fields from arguments. |
| 4075 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 4076 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 4077 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 4078 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 4079 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 4080 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 4081 | |
| 4082 | // Fill out the elements FixedArray. |
| 4083 | // eax: JSArray. |
| 4084 | // ebx: FixedArray. |
| 4085 | // ecx: Number of elements in array, as smi. |
| 4086 | |
| 4087 | // Set map. |
| 4088 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4089 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4090 | // Set length. |
| 4091 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
| 4092 | // Fill contents of fixed-array with the-hole. |
| 4093 | __ SmiUntag(ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4094 | __ mov(edx, Immediate(factory->the_hole_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4095 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
| 4096 | // Fill fixed array elements with hole. |
| 4097 | // eax: JSArray. |
| 4098 | // ecx: Number of elements to fill. |
| 4099 | // ebx: Start of elements in FixedArray. |
| 4100 | // edx: the hole. |
| 4101 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4102 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4103 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4104 | __ 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] | 4105 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4106 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 4107 | __ jmp(&loop); |
| 4108 | |
| 4109 | __ bind(&done); |
| 4110 | __ ret(3 * kPointerSize); |
| 4111 | |
| 4112 | __ bind(&slowcase); |
| 4113 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 4114 | } |
| 4115 | |
| 4116 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4117 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 4118 | Register object, |
| 4119 | Register result, |
| 4120 | Register scratch1, |
| 4121 | Register scratch2, |
| 4122 | bool object_is_smi, |
| 4123 | Label* not_found) { |
| 4124 | // Use of registers. Register result is used as a temporary. |
| 4125 | Register number_string_cache = result; |
| 4126 | Register mask = scratch1; |
| 4127 | Register scratch = scratch2; |
| 4128 | |
| 4129 | // Load the number string cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4130 | ExternalReference roots_array_start = |
| 4131 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4132 | __ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex)); |
| 4133 | __ mov(number_string_cache, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4134 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4135 | // Make the hash mask from the length of the number string cache. It |
| 4136 | // contains two elements (number and string) for each cache entry. |
| 4137 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 4138 | __ 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] | 4139 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4140 | |
| 4141 | // Calculate the entry in the number string cache. The hash value in the |
| 4142 | // number string cache for smis is just the smi value, and the hash for |
| 4143 | // doubles is the xor of the upper and lower words. See |
| 4144 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4145 | Label smi_hash_calculated; |
| 4146 | Label load_result_from_cache; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4147 | if (object_is_smi) { |
| 4148 | __ mov(scratch, object); |
| 4149 | __ SmiUntag(scratch); |
| 4150 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4151 | Label not_smi; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4152 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4153 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4154 | __ mov(scratch, object); |
| 4155 | __ SmiUntag(scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4156 | __ jmp(&smi_hash_calculated, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4157 | __ bind(¬_smi); |
| 4158 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4159 | masm->isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4160 | __ j(not_equal, not_found); |
| 4161 | STATIC_ASSERT(8 == kDoubleSize); |
| 4162 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4163 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 4164 | // 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] | 4165 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4166 | Register index = scratch; |
| 4167 | Register probe = mask; |
| 4168 | __ mov(probe, |
| 4169 | FieldOperand(number_string_cache, |
| 4170 | index, |
| 4171 | times_twice_pointer_size, |
| 4172 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4173 | __ JumpIfSmi(probe, not_found); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4174 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4175 | CpuFeatures::Scope fscope(SSE2); |
| 4176 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4177 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4178 | __ ucomisd(xmm0, xmm1); |
| 4179 | } else { |
| 4180 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 4181 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4182 | __ FCmp(); |
| 4183 | } |
| 4184 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 4185 | __ 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] | 4186 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4187 | } |
| 4188 | |
| 4189 | __ bind(&smi_hash_calculated); |
| 4190 | // 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] | 4191 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4192 | Register index = scratch; |
| 4193 | // Check if the entry is the smi we are looking for. |
| 4194 | __ cmp(object, |
| 4195 | FieldOperand(number_string_cache, |
| 4196 | index, |
| 4197 | times_twice_pointer_size, |
| 4198 | FixedArray::kHeaderSize)); |
| 4199 | __ j(not_equal, not_found); |
| 4200 | |
| 4201 | // Get the result from the cache. |
| 4202 | __ bind(&load_result_from_cache); |
| 4203 | __ mov(result, |
| 4204 | FieldOperand(number_string_cache, |
| 4205 | index, |
| 4206 | times_twice_pointer_size, |
| 4207 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4208 | Counters* counters = masm->isolate()->counters(); |
| 4209 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4210 | } |
| 4211 | |
| 4212 | |
| 4213 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 4214 | Label runtime; |
| 4215 | |
| 4216 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 4217 | |
| 4218 | // Generate code to lookup number in the number string cache. |
| 4219 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, false, &runtime); |
| 4220 | __ ret(1 * kPointerSize); |
| 4221 | |
| 4222 | __ bind(&runtime); |
| 4223 | // Handle number to string in the runtime system if not found in the cache. |
| 4224 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 4225 | } |
| 4226 | |
| 4227 | |
| 4228 | static int NegativeComparisonResult(Condition cc) { |
| 4229 | ASSERT(cc != equal); |
| 4230 | ASSERT((cc == less) || (cc == less_equal) |
| 4231 | || (cc == greater) || (cc == greater_equal)); |
| 4232 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 4233 | } |
| 4234 | |
| 4235 | void CompareStub::Generate(MacroAssembler* masm) { |
| 4236 | ASSERT(lhs_.is(no_reg) && rhs_.is(no_reg)); |
| 4237 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4238 | Label check_unequal_objects; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4239 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4240 | // Compare two smis if required. |
| 4241 | if (include_smi_compare_) { |
| 4242 | Label non_smi, smi_done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4243 | __ mov(ecx, edx); |
| 4244 | __ or_(ecx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4245 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4246 | __ sub(edx, eax); // Return on the result of the subtraction. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4247 | __ j(no_overflow, &smi_done, Label::kNear); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4248 | __ 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] | 4249 | __ bind(&smi_done); |
| 4250 | __ mov(eax, edx); |
| 4251 | __ ret(0); |
| 4252 | __ bind(&non_smi); |
| 4253 | } else if (FLAG_debug_code) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4254 | __ mov(ecx, edx); |
| 4255 | __ or_(ecx, eax); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4256 | __ test(ecx, Immediate(kSmiTagMask)); |
| 4257 | __ Assert(not_zero, "Unexpected smi operands."); |
| 4258 | } |
| 4259 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4260 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4261 | // it is certain that at least one operand isn't a smi. |
| 4262 | |
| 4263 | // Identical objects can be compared fast, but there are some tricky cases |
| 4264 | // for NaN and undefined. |
| 4265 | { |
| 4266 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4267 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4268 | __ j(not_equal, ¬_identical); |
| 4269 | |
| 4270 | if (cc_ != equal) { |
| 4271 | // Check for undefined. undefined OP undefined is false even though |
| 4272 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4273 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4274 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4275 | __ j(not_equal, &check_for_nan, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4276 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc_)))); |
| 4277 | __ ret(0); |
| 4278 | __ bind(&check_for_nan); |
| 4279 | } |
| 4280 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4281 | // 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] | 4282 | // so we do the second best thing - test it ourselves. |
| 4283 | // Note: if cc_ != equal, never_nan_nan_ is not used. |
| 4284 | if (never_nan_nan_ && (cc_ == equal)) { |
| 4285 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4286 | __ ret(0); |
| 4287 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4288 | Label heap_number; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4289 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4290 | Immediate(masm->isolate()->factory()->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4291 | __ j(equal, &heap_number, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4292 | if (cc_ != equal) { |
| 4293 | // Call runtime on identical JSObjects. Otherwise return equal. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4294 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4295 | __ j(above_equal, ¬_identical); |
| 4296 | } |
| 4297 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4298 | __ ret(0); |
| 4299 | |
| 4300 | __ bind(&heap_number); |
| 4301 | // It is a heap number, so return non-equal if it's NaN and equal if |
| 4302 | // it's not NaN. |
| 4303 | // The representation of NaN values has all exponent bits (52..62) set, |
| 4304 | // and not all mantissa bits (0..51) clear. |
| 4305 | // We only accept QNaNs, which have bit 51 set. |
| 4306 | // Read top bits of double representation (second word of value). |
| 4307 | |
| 4308 | // Value is a QNaN if value & kQuietNaNMask == kQuietNaNMask, i.e., |
| 4309 | // all bits in the mask are set. We only need to check the word |
| 4310 | // that contains the exponent and high bit of the mantissa. |
| 4311 | STATIC_ASSERT(((kQuietNaNHighBitsMask << 1) & 0x80000000u) != 0); |
| 4312 | __ mov(edx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4313 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4314 | // Shift value and mask so kQuietNaNHighBitsMask applies to topmost |
| 4315 | // bits. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4316 | __ add(edx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4317 | __ cmp(edx, kQuietNaNHighBitsMask << 1); |
| 4318 | if (cc_ == equal) { |
| 4319 | STATIC_ASSERT(EQUAL != 1); |
| 4320 | __ setcc(above_equal, eax); |
| 4321 | __ ret(0); |
| 4322 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4323 | Label nan; |
| 4324 | __ j(above_equal, &nan, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4325 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4326 | __ ret(0); |
| 4327 | __ bind(&nan); |
| 4328 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc_)))); |
| 4329 | __ ret(0); |
| 4330 | } |
| 4331 | } |
| 4332 | |
| 4333 | __ bind(¬_identical); |
| 4334 | } |
| 4335 | |
| 4336 | // Strict equality can quickly decide whether objects are equal. |
| 4337 | // Non-strict object equality is slower, so it is handled later in the stub. |
| 4338 | if (cc_ == equal && strict_) { |
| 4339 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4340 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4341 | // If we're doing a strict equality comparison, we don't have to do |
| 4342 | // type conversion, so we generate code to do fast comparison for objects |
| 4343 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4344 | // slow-case code. |
| 4345 | // If either is a Smi (we know that not both are), then they can only |
| 4346 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4347 | STATIC_ASSERT(kSmiTag == 0); |
| 4348 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4349 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4350 | __ and_(ecx, eax); |
| 4351 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4352 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4353 | // One operand is a smi. |
| 4354 | |
| 4355 | // Check whether the non-smi is a heap number. |
| 4356 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4357 | // 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] | 4358 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4359 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4360 | __ xor_(ebx, eax); |
| 4361 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4362 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4363 | // if eax was smi, ebx is now edx, else eax. |
| 4364 | |
| 4365 | // Check if the non-smi operand is a heap number. |
| 4366 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4367 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4368 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4369 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4370 | // Return non-equal (ebx is not zero) |
| 4371 | __ mov(eax, ebx); |
| 4372 | __ ret(0); |
| 4373 | |
| 4374 | __ bind(¬_smis); |
| 4375 | // If either operand is a JSObject or an oddball value, then they are not |
| 4376 | // equal since their pointers are different |
| 4377 | // There is no test for undetectability in strict equality. |
| 4378 | |
| 4379 | // Get the type of the first operand. |
| 4380 | // 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] | 4381 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4382 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4383 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4384 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4385 | |
| 4386 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4387 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4388 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4389 | __ bind(&return_not_equal); |
| 4390 | __ ret(0); |
| 4391 | |
| 4392 | __ bind(&first_non_object); |
| 4393 | // Check for oddballs: true, false, null, undefined. |
| 4394 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4395 | __ j(equal, &return_not_equal); |
| 4396 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4397 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4398 | __ j(above_equal, &return_not_equal); |
| 4399 | |
| 4400 | // Check for oddballs: true, false, null, undefined. |
| 4401 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4402 | __ j(equal, &return_not_equal); |
| 4403 | |
| 4404 | // Fall through to the general case. |
| 4405 | __ bind(&slow); |
| 4406 | } |
| 4407 | |
| 4408 | // Generate the number comparison code. |
| 4409 | if (include_number_compare_) { |
| 4410 | Label non_number_comparison; |
| 4411 | Label unordered; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4412 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4413 | CpuFeatures::Scope use_sse2(SSE2); |
| 4414 | CpuFeatures::Scope use_cmov(CMOV); |
| 4415 | |
| 4416 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4417 | __ ucomisd(xmm0, xmm1); |
| 4418 | |
| 4419 | // Don't base result on EFLAGS when a NaN is involved. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4420 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4421 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4422 | __ mov(eax, 0); // equal |
| 4423 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4424 | __ cmov(above, eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4425 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4426 | __ cmov(below, eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4427 | __ ret(0); |
| 4428 | } else { |
| 4429 | FloatingPointHelper::CheckFloatOperands( |
| 4430 | masm, &non_number_comparison, ebx); |
| 4431 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4432 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4433 | __ FCmp(); |
| 4434 | |
| 4435 | // Don't base result on EFLAGS when a NaN is involved. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4436 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4437 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4438 | Label below_label, above_label; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4439 | // Return a result of -1, 0, or 1, based on EFLAGS. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4440 | __ j(below, &below_label, Label::kNear); |
| 4441 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4442 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 4443 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4444 | __ ret(0); |
| 4445 | |
| 4446 | __ bind(&below_label); |
| 4447 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4448 | __ ret(0); |
| 4449 | |
| 4450 | __ bind(&above_label); |
| 4451 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4452 | __ ret(0); |
| 4453 | } |
| 4454 | |
| 4455 | // If one of the numbers was NaN, then the result is always false. |
| 4456 | // The cc is never not-equal. |
| 4457 | __ bind(&unordered); |
| 4458 | ASSERT(cc_ != not_equal); |
| 4459 | if (cc_ == less || cc_ == less_equal) { |
| 4460 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4461 | } else { |
| 4462 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4463 | } |
| 4464 | __ ret(0); |
| 4465 | |
| 4466 | // The number comparison code did not provide a valid result. |
| 4467 | __ bind(&non_number_comparison); |
| 4468 | } |
| 4469 | |
| 4470 | // Fast negative check for symbol-to-symbol equality. |
| 4471 | Label check_for_strings; |
| 4472 | if (cc_ == equal) { |
| 4473 | BranchIfNonSymbol(masm, &check_for_strings, eax, ecx); |
| 4474 | BranchIfNonSymbol(masm, &check_for_strings, edx, ecx); |
| 4475 | |
| 4476 | // We've already checked for object identity, so if both operands |
| 4477 | // are symbols they aren't equal. Register eax already holds a |
| 4478 | // non-zero value, which indicates not equal, so just return. |
| 4479 | __ ret(0); |
| 4480 | } |
| 4481 | |
| 4482 | __ bind(&check_for_strings); |
| 4483 | |
| 4484 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4485 | &check_unequal_objects); |
| 4486 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4487 | // Inline comparison of ASCII strings. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4488 | if (cc_ == equal) { |
| 4489 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4490 | edx, |
| 4491 | eax, |
| 4492 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4493 | ebx); |
| 4494 | } else { |
| 4495 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4496 | edx, |
| 4497 | eax, |
| 4498 | ecx, |
| 4499 | ebx, |
| 4500 | edi); |
| 4501 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4502 | #ifdef DEBUG |
| 4503 | __ Abort("Unexpected fall-through from string comparison"); |
| 4504 | #endif |
| 4505 | |
| 4506 | __ bind(&check_unequal_objects); |
| 4507 | if (cc_ == equal && !strict_) { |
| 4508 | // Non-strict equality. Objects are unequal if |
| 4509 | // they are both JSObjects and not undetectable, |
| 4510 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4511 | Label not_both_objects; |
| 4512 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4513 | // At most one is a smi, so we can test for smi by adding the two. |
| 4514 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4515 | // a heap object has the low bit clear. |
| 4516 | STATIC_ASSERT(kSmiTag == 0); |
| 4517 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4518 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4519 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4520 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4521 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4522 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4523 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4524 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4525 | // We do not bail out after this point. Both are JSObjects, and |
| 4526 | // they are equal if and only if both are undetectable. |
| 4527 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4528 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4529 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4530 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4531 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4532 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4533 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4534 | // The objects are both undetectable, so they both compare as the value |
| 4535 | // undefined, and are equal. |
| 4536 | __ Set(eax, Immediate(EQUAL)); |
| 4537 | __ bind(&return_unequal); |
| 4538 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4539 | // or return equal if we fell through to here. |
| 4540 | __ ret(0); // rax, rdx were pushed |
| 4541 | __ bind(¬_both_objects); |
| 4542 | } |
| 4543 | |
| 4544 | // Push arguments below the return address. |
| 4545 | __ pop(ecx); |
| 4546 | __ push(edx); |
| 4547 | __ push(eax); |
| 4548 | |
| 4549 | // Figure out which native to call and setup the arguments. |
| 4550 | Builtins::JavaScript builtin; |
| 4551 | if (cc_ == equal) { |
| 4552 | builtin = strict_ ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
| 4553 | } else { |
| 4554 | builtin = Builtins::COMPARE; |
| 4555 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc_)))); |
| 4556 | } |
| 4557 | |
| 4558 | // Restore return address on the stack. |
| 4559 | __ push(ecx); |
| 4560 | |
| 4561 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4562 | // tagged as a small integer. |
| 4563 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
| 4564 | } |
| 4565 | |
| 4566 | |
| 4567 | void CompareStub::BranchIfNonSymbol(MacroAssembler* masm, |
| 4568 | Label* label, |
| 4569 | Register object, |
| 4570 | Register scratch) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4571 | __ JumpIfSmi(object, label); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4572 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4573 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 4574 | __ and_(scratch, kIsSymbolMask | kIsNotStringMask); |
| 4575 | __ cmp(scratch, kSymbolTag | kStringTag); |
| 4576 | __ j(not_equal, label); |
| 4577 | } |
| 4578 | |
| 4579 | |
| 4580 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4581 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4582 | } |
| 4583 | |
| 4584 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4585 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 4586 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 4587 | } |
| 4588 | |
| 4589 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4590 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4591 | // Cache the called function in a global property cell. Cache states |
| 4592 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4593 | // megamorphic. |
| 4594 | // ebx : cache cell for call target |
| 4595 | // edi : the function to call |
| 4596 | Isolate* isolate = masm->isolate(); |
| 4597 | Label initialize, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4598 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4599 | // Load the cache state into ecx. |
| 4600 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4601 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4602 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4603 | // function without changing the state. |
| 4604 | __ cmp(ecx, edi); |
| 4605 | __ j(equal, &done, Label::kNear); |
| 4606 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4607 | __ j(equal, &done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4608 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4609 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4610 | // megamorphic. |
| 4611 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4612 | __ j(equal, &initialize, Label::kNear); |
| 4613 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4614 | // write-barrier is needed. |
| 4615 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4616 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4617 | __ jmp(&done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4618 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4619 | // An uninitialized cache is patched with the function. |
| 4620 | __ bind(&initialize); |
| 4621 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4622 | // No need for a write barrier here - cells are rescanned. |
| 4623 | |
| 4624 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4628 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4629 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4630 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4631 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4632 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4633 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4634 | // The receiver might implicitly be the global object. This is |
| 4635 | // indicated by passing the hole as the receiver to the call |
| 4636 | // function stub. |
| 4637 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4638 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4639 | // Get the receiver from the stack. |
| 4640 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4641 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4642 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4643 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4644 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4645 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4646 | __ mov(ecx, GlobalObjectOperand()); |
| 4647 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4648 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4649 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4650 | } |
| 4651 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4652 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4653 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4654 | // Goto slow case if we do not have a function. |
| 4655 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4656 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4657 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4658 | if (RecordCallTarget()) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4659 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4660 | } |
| 4661 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4662 | // Fast-case: Just invoke the function. |
| 4663 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4664 | |
| 4665 | if (ReceiverMightBeImplicit()) { |
| 4666 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4667 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4668 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4669 | __ InvokeFunction(edi, |
| 4670 | actual, |
| 4671 | JUMP_FUNCTION, |
| 4672 | NullCallWrapper(), |
| 4673 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4674 | __ bind(&call_as_function); |
| 4675 | } |
| 4676 | __ InvokeFunction(edi, |
| 4677 | actual, |
| 4678 | JUMP_FUNCTION, |
| 4679 | NullCallWrapper(), |
| 4680 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4681 | |
| 4682 | // Slow-case: Non-function called. |
| 4683 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4684 | if (RecordCallTarget()) { |
| 4685 | // If there is a call target cache, mark it megamorphic in the |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4686 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4687 | // object (undefined) so no write barrier is needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4688 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4689 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4690 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4691 | // Check for function proxy. |
| 4692 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4693 | __ j(not_equal, &non_function); |
| 4694 | __ pop(ecx); |
| 4695 | __ push(edi); // put proxy as additional argument under return address |
| 4696 | __ push(ecx); |
| 4697 | __ Set(eax, Immediate(argc_ + 1)); |
| 4698 | __ Set(ebx, Immediate(0)); |
| 4699 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4700 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4701 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4702 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4703 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4704 | } |
| 4705 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4706 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4707 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4708 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4709 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4710 | __ Set(eax, Immediate(argc_)); |
| 4711 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4712 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4713 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4714 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4715 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4716 | } |
| 4717 | |
| 4718 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4719 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 4720 | // eax : number of arguments |
| 4721 | // ebx : cache cell for call target |
| 4722 | // edi : constructor function |
| 4723 | Label slow, non_function_call; |
| 4724 | |
| 4725 | // Check that function is not a smi. |
| 4726 | __ JumpIfSmi(edi, &non_function_call); |
| 4727 | // Check that function is a JSFunction. |
| 4728 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 4729 | __ j(not_equal, &slow); |
| 4730 | |
| 4731 | if (RecordCallTarget()) { |
| 4732 | GenerateRecordCallTarget(masm); |
| 4733 | } |
| 4734 | |
| 4735 | // Jump to the function-specific construct stub. |
| 4736 | __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4737 | __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kConstructStubOffset)); |
| 4738 | __ lea(ebx, FieldOperand(ebx, Code::kHeaderSize)); |
| 4739 | __ jmp(ebx); |
| 4740 | |
| 4741 | // edi: called object |
| 4742 | // eax: number of arguments |
| 4743 | // ecx: object map |
| 4744 | Label do_call; |
| 4745 | __ bind(&slow); |
| 4746 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4747 | __ j(not_equal, &non_function_call); |
| 4748 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4749 | __ jmp(&do_call); |
| 4750 | |
| 4751 | __ bind(&non_function_call); |
| 4752 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4753 | __ bind(&do_call); |
| 4754 | // Set expected number of arguments to zero (not changing eax). |
| 4755 | __ Set(ebx, Immediate(0)); |
| 4756 | Handle<Code> arguments_adaptor = |
| 4757 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 4758 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 4759 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 4760 | } |
| 4761 | |
| 4762 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4763 | bool CEntryStub::NeedsImmovableCode() { |
| 4764 | return false; |
| 4765 | } |
| 4766 | |
| 4767 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4768 | bool CEntryStub::IsPregenerated() { |
| 4769 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 4770 | result_size_ == 1; |
| 4771 | } |
| 4772 | |
| 4773 | |
| 4774 | void CodeStub::GenerateStubsAheadOfTime() { |
| 4775 | CEntryStub::GenerateAheadOfTime(); |
| 4776 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(); |
| 4777 | // It is important that the store buffer overflow stubs are generated first. |
| 4778 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(); |
| 4779 | } |
| 4780 | |
| 4781 | |
| 4782 | void CodeStub::GenerateFPStubs() { |
| 4783 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4784 | Handle<Code> code = save_doubles.GetCode(); |
| 4785 | code->set_is_pregenerated(true); |
| 4786 | code->GetIsolate()->set_fp_stubs_generated(true); |
| 4787 | } |
| 4788 | |
| 4789 | |
| 4790 | void CEntryStub::GenerateAheadOfTime() { |
| 4791 | CEntryStub stub(1, kDontSaveFPRegs); |
| 4792 | Handle<Code> code = stub.GetCode(); |
| 4793 | code->set_is_pregenerated(true); |
| 4794 | } |
| 4795 | |
| 4796 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4797 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 4798 | Label* throw_normal_exception, |
| 4799 | Label* throw_termination_exception, |
| 4800 | Label* throw_out_of_memory_exception, |
| 4801 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4802 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4803 | // eax: result parameter for PerformGC, if any |
| 4804 | // ebx: pointer to C function (C callee-saved) |
| 4805 | // ebp: frame pointer (restored after C call) |
| 4806 | // esp: stack pointer (restored after C call) |
| 4807 | // edi: number of arguments including receiver (C callee-saved) |
| 4808 | // esi: pointer to the first argument (C callee-saved) |
| 4809 | |
| 4810 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 4811 | |
| 4812 | // Check stack alignment. |
| 4813 | if (FLAG_debug_code) { |
| 4814 | __ CheckStackAlignment(); |
| 4815 | } |
| 4816 | |
| 4817 | if (do_gc) { |
| 4818 | // Pass failure code returned from last attempt as first argument to |
| 4819 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 4820 | // stack alignment is known to be correct. This function takes one argument |
| 4821 | // which is passed on the stack, and we know that the stack has been |
| 4822 | // prepared to pass at least one argument. |
| 4823 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 4824 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 4825 | } |
| 4826 | |
| 4827 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4828 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4829 | if (always_allocate_scope) { |
| 4830 | __ inc(Operand::StaticVariable(scope_depth)); |
| 4831 | } |
| 4832 | |
| 4833 | // Call C function. |
| 4834 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 4835 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4836 | __ mov(Operand(esp, 2 * kPointerSize), |
| 4837 | Immediate(ExternalReference::isolate_address())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4838 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4839 | // Result is in eax or edx:eax - do not destroy these registers! |
| 4840 | |
| 4841 | if (always_allocate_scope) { |
| 4842 | __ dec(Operand::StaticVariable(scope_depth)); |
| 4843 | } |
| 4844 | |
| 4845 | // Make sure we're not trying to return 'the hole' from the runtime |
| 4846 | // call as this may lead to crashes in the IC code later. |
| 4847 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4848 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4849 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4850 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4851 | __ int3(); |
| 4852 | __ bind(&okay); |
| 4853 | } |
| 4854 | |
| 4855 | // Check for failure result. |
| 4856 | Label failure_returned; |
| 4857 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 4858 | __ lea(ecx, Operand(eax, 1)); |
| 4859 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 4860 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4861 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4862 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4863 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4864 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4865 | |
| 4866 | // Check that there is no pending exception, otherwise we |
| 4867 | // should have returned some failure value. |
| 4868 | if (FLAG_debug_code) { |
| 4869 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4870 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4871 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4872 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 4873 | // 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] | 4874 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4875 | __ int3(); |
| 4876 | __ bind(&okay); |
| 4877 | __ pop(edx); |
| 4878 | } |
| 4879 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4880 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4881 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4882 | __ ret(0); |
| 4883 | |
| 4884 | // Handling of failure. |
| 4885 | __ bind(&failure_returned); |
| 4886 | |
| 4887 | Label retry; |
| 4888 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 4889 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 4890 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4891 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4892 | |
| 4893 | // Special handling of out of memory exceptions. |
| 4894 | __ cmp(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException())); |
| 4895 | __ j(equal, throw_out_of_memory_exception); |
| 4896 | |
| 4897 | // Retrieve the pending exception and clear the variable. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4898 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4899 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4900 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 4901 | |
| 4902 | // Special handling of termination exceptions which are uncatchable |
| 4903 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4904 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4905 | __ j(equal, throw_termination_exception); |
| 4906 | |
| 4907 | // Handle normal exception. |
| 4908 | __ jmp(throw_normal_exception); |
| 4909 | |
| 4910 | // Retry. |
| 4911 | __ bind(&retry); |
| 4912 | } |
| 4913 | |
| 4914 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4915 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 4916 | // eax: number of arguments including receiver |
| 4917 | // ebx: pointer to C function (C callee-saved) |
| 4918 | // ebp: frame pointer (restored after C call) |
| 4919 | // esp: stack pointer (restored after C call) |
| 4920 | // esi: current context (C callee-saved) |
| 4921 | // edi: JS function of the caller (C callee-saved) |
| 4922 | |
| 4923 | // NOTE: Invocations of builtins may return failure objects instead |
| 4924 | // of a proper result. The builtin entry handles this by performing |
| 4925 | // a garbage collection and retrying the builtin (twice). |
| 4926 | |
| 4927 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4928 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4929 | |
| 4930 | // eax: result parameter for PerformGC, if any (setup below) |
| 4931 | // ebx: pointer to builtin function (C callee-saved) |
| 4932 | // ebp: frame pointer (restored after C call) |
| 4933 | // esp: stack pointer (restored after C call) |
| 4934 | // edi: number of arguments including receiver (C callee-saved) |
| 4935 | // esi: argv pointer (C callee-saved) |
| 4936 | |
| 4937 | Label throw_normal_exception; |
| 4938 | Label throw_termination_exception; |
| 4939 | Label throw_out_of_memory_exception; |
| 4940 | |
| 4941 | // Call into the runtime system. |
| 4942 | GenerateCore(masm, |
| 4943 | &throw_normal_exception, |
| 4944 | &throw_termination_exception, |
| 4945 | &throw_out_of_memory_exception, |
| 4946 | false, |
| 4947 | false); |
| 4948 | |
| 4949 | // Do space-specific GC and retry runtime call. |
| 4950 | GenerateCore(masm, |
| 4951 | &throw_normal_exception, |
| 4952 | &throw_termination_exception, |
| 4953 | &throw_out_of_memory_exception, |
| 4954 | true, |
| 4955 | false); |
| 4956 | |
| 4957 | // Do full GC and retry runtime call one final time. |
| 4958 | Failure* failure = Failure::InternalError(); |
| 4959 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 4960 | GenerateCore(masm, |
| 4961 | &throw_normal_exception, |
| 4962 | &throw_termination_exception, |
| 4963 | &throw_out_of_memory_exception, |
| 4964 | true, |
| 4965 | true); |
| 4966 | |
| 4967 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4968 | // Set external caught exception to false. |
| 4969 | Isolate* isolate = masm->isolate(); |
| 4970 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 4971 | isolate); |
| 4972 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 4973 | |
| 4974 | // Set pending exception and eax to out of memory exception. |
| 4975 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 4976 | isolate); |
| 4977 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException())); |
| 4978 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 4979 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4980 | |
| 4981 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4982 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4983 | |
| 4984 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4985 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | |
| 4989 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4990 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4991 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4992 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4993 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4994 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4995 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4996 | |
| 4997 | // Push marker in two places. |
| 4998 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 4999 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 5000 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 5001 | // Save callee-saved registers (C calling conventions). |
| 5002 | __ push(edi); |
| 5003 | __ push(esi); |
| 5004 | __ push(ebx); |
| 5005 | |
| 5006 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5007 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5008 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 5009 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5010 | // 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] | 5011 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5012 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5013 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5014 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5015 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5016 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame^] | 5017 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5018 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5019 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5020 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5021 | // Jump to a faked try block that does the invoke, with a faked catch |
| 5022 | // block that sets the pending exception. |
| 5023 | __ jmp(&invoke); |
| 5024 | __ bind(&handler_entry); |
| 5025 | handler_offset_ = handler_entry.pos(); |
| 5026 | // Caught exception: Store result (exception) in the pending exception |
| 5027 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5028 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5029 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5030 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5031 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 5032 | __ jmp(&exit); |
| 5033 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5034 | // Invoke: Link this frame into the handler chain. There's only one |
| 5035 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5036 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 5037 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5038 | |
| 5039 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5040 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5041 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 5042 | |
| 5043 | // Fake a receiver (NULL). |
| 5044 | __ push(Immediate(0)); // receiver |
| 5045 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5046 | // Invoke the function by calling through JS entry trampoline builtin and |
| 5047 | // pop the faked function when we return. Notice that we cannot store a |
| 5048 | // reference to the trampoline code directly in this stub, because the |
| 5049 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5050 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5051 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 5052 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5053 | __ mov(edx, Immediate(construct_entry)); |
| 5054 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5055 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5056 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5057 | __ mov(edx, Immediate(entry)); |
| 5058 | } |
| 5059 | __ mov(edx, Operand(edx, 0)); // deref address |
| 5060 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5061 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5062 | |
| 5063 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5064 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5065 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5066 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5067 | // Check if the current stack frame is marked as the outermost JS frame. |
| 5068 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5069 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5070 | __ j(not_equal, ¬_outermost_js_2); |
| 5071 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 5072 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5073 | |
| 5074 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5075 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5076 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5077 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5078 | |
| 5079 | // Restore callee-saved registers (C calling conventions). |
| 5080 | __ pop(ebx); |
| 5081 | __ pop(esi); |
| 5082 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5083 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5084 | |
| 5085 | // Restore frame pointer and return. |
| 5086 | __ pop(ebp); |
| 5087 | __ ret(0); |
| 5088 | } |
| 5089 | |
| 5090 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5091 | // Generate stub code for instanceof. |
| 5092 | // This code can patch a call site inlined cache of the instance of check, |
| 5093 | // which looks like this. |
| 5094 | // |
| 5095 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 5096 | // 75 0a jne <some near label> |
| 5097 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 5098 | // |
| 5099 | // If call site patching is requested the stack will have the delta from the |
| 5100 | // return address to the cmp instruction just below the return address. This |
| 5101 | // also means that call site patching can only take place with arguments in |
| 5102 | // registers. TOS looks like this when call site patching is requested |
| 5103 | // |
| 5104 | // esp[0] : return address |
| 5105 | // esp[4] : delta from return address to cmp instruction |
| 5106 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5107 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5108 | // Call site inlining and patching implies arguments in registers. |
| 5109 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 5110 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5111 | // Fixed register usage throughout the stub. |
| 5112 | Register object = eax; // Object (lhs). |
| 5113 | Register map = ebx; // Map of the object. |
| 5114 | Register function = edx; // Function (rhs). |
| 5115 | Register prototype = edi; // Prototype of the function. |
| 5116 | Register scratch = ecx; |
| 5117 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5118 | // Constants describing the call site code to patch. |
| 5119 | static const int kDeltaToCmpImmediate = 2; |
| 5120 | static const int kDeltaToMov = 8; |
| 5121 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5122 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 5123 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5124 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 5125 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5126 | ExternalReference roots_array_start = |
| 5127 | ExternalReference::roots_array_start(masm->isolate()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5128 | |
| 5129 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 5130 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 5131 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5132 | // Get the object and function - they are always both needed. |
| 5133 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5134 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5135 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 5136 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 5137 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5138 | |
| 5139 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5140 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5141 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5142 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5143 | // If there is a call site cache don't look in the global cache, but do the |
| 5144 | // real lookup and update the call site cache. |
| 5145 | if (!HasCallSiteInlineCheck()) { |
| 5146 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5147 | Label miss; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5148 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5149 | __ cmp(function, Operand::StaticArray(scratch, |
| 5150 | times_pointer_size, |
| 5151 | roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5152 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5153 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
| 5154 | __ cmp(map, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5155 | scratch, times_pointer_size, roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5156 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5157 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5158 | __ mov(eax, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5159 | scratch, times_pointer_size, roots_array_start)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5160 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 5161 | __ bind(&miss); |
| 5162 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5163 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5164 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5165 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5166 | |
| 5167 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5168 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5169 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5170 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5171 | // Update the global instanceof or call site inlined cache with the current |
| 5172 | // map and function. The cached answer will be set when it is known below. |
| 5173 | if (!HasCallSiteInlineCheck()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5174 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5175 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 5176 | map); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5177 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5178 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5179 | function); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5180 | } else { |
| 5181 | // The constants for the code patching are based on no push instructions |
| 5182 | // at the call site. |
| 5183 | ASSERT(HasArgsInRegisters()); |
| 5184 | // Get return address and delta to inlined map check. |
| 5185 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5186 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5187 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5188 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5189 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)"); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5190 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5191 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)"); |
| 5192 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5193 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 5194 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5195 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5196 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5197 | // Loop through the prototype chain of the object looking for the function |
| 5198 | // prototype. |
| 5199 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5200 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5201 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5202 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5203 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5204 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5205 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5206 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5207 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 5208 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5209 | __ jmp(&loop); |
| 5210 | |
| 5211 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5212 | if (!HasCallSiteInlineCheck()) { |
| 5213 | __ Set(eax, Immediate(0)); |
| 5214 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5215 | __ mov(Operand::StaticArray(scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5216 | times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5217 | } else { |
| 5218 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5219 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5220 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5221 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5222 | if (FLAG_debug_code) { |
| 5223 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5224 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5225 | } |
| 5226 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5227 | if (!ReturnTrueFalseObject()) { |
| 5228 | __ Set(eax, Immediate(0)); |
| 5229 | } |
| 5230 | } |
| 5231 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5232 | |
| 5233 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5234 | if (!HasCallSiteInlineCheck()) { |
| 5235 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5236 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5237 | __ mov(Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5238 | scratch, times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5239 | } else { |
| 5240 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5241 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5242 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5243 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5244 | if (FLAG_debug_code) { |
| 5245 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5246 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5247 | } |
| 5248 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5249 | if (!ReturnTrueFalseObject()) { |
| 5250 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5251 | } |
| 5252 | } |
| 5253 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5254 | |
| 5255 | Label object_not_null, object_not_null_or_smi; |
| 5256 | __ bind(¬_js_object); |
| 5257 | // Before null, smi and string value checks, check that the rhs is a function |
| 5258 | // 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] | 5259 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5260 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5261 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5262 | |
| 5263 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5264 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5265 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5266 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5267 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5268 | |
| 5269 | __ bind(&object_not_null); |
| 5270 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5271 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5272 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5273 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5274 | |
| 5275 | __ bind(&object_not_null_or_smi); |
| 5276 | // String values is not instance of anything. |
| 5277 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5278 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5279 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5280 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5281 | |
| 5282 | // Slow-case: Go through the JavaScript implementation. |
| 5283 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5284 | if (!ReturnTrueFalseObject()) { |
| 5285 | // Tail call the builtin which returns 0 or 1. |
| 5286 | if (HasArgsInRegisters()) { |
| 5287 | // Push arguments below return address. |
| 5288 | __ pop(scratch); |
| 5289 | __ push(object); |
| 5290 | __ push(function); |
| 5291 | __ push(scratch); |
| 5292 | } |
| 5293 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5294 | } else { |
| 5295 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5296 | { |
| 5297 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5298 | __ push(object); |
| 5299 | __ push(function); |
| 5300 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5301 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5302 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5303 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5304 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5305 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5306 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5307 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5308 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5309 | __ bind(&done); |
| 5310 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5311 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5315 | Register InstanceofStub::left() { return eax; } |
| 5316 | |
| 5317 | |
| 5318 | Register InstanceofStub::right() { return edx; } |
| 5319 | |
| 5320 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5321 | int CompareStub::MinorKey() { |
| 5322 | // Encode the three parameters in a unique 16 bit value. To avoid duplicate |
| 5323 | // stubs the never NaN NaN condition is only taken into account if the |
| 5324 | // condition is equals. |
| 5325 | ASSERT(static_cast<unsigned>(cc_) < (1 << 12)); |
| 5326 | ASSERT(lhs_.is(no_reg) && rhs_.is(no_reg)); |
| 5327 | return ConditionField::encode(static_cast<unsigned>(cc_)) |
| 5328 | | RegisterField::encode(false) // lhs_ and rhs_ are not used |
| 5329 | | StrictField::encode(strict_) |
| 5330 | | NeverNanNanField::encode(cc_ == equal ? never_nan_nan_ : false) |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5331 | | IncludeNumberCompareField::encode(include_number_compare_) |
| 5332 | | IncludeSmiCompareField::encode(include_smi_compare_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5333 | } |
| 5334 | |
| 5335 | |
| 5336 | // Unfortunately you have to run without snapshots to see most of these |
| 5337 | // 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] | 5338 | void CompareStub::PrintName(StringStream* stream) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5339 | ASSERT(lhs_.is(no_reg) && rhs_.is(no_reg)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5340 | const char* cc_name; |
| 5341 | switch (cc_) { |
| 5342 | case less: cc_name = "LT"; break; |
| 5343 | case greater: cc_name = "GT"; break; |
| 5344 | case less_equal: cc_name = "LE"; break; |
| 5345 | case greater_equal: cc_name = "GE"; break; |
| 5346 | case equal: cc_name = "EQ"; break; |
| 5347 | case not_equal: cc_name = "NE"; break; |
| 5348 | default: cc_name = "UnknownCondition"; break; |
| 5349 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 5350 | bool is_equality = cc_ == equal || cc_ == not_equal; |
| 5351 | stream->Add("CompareStub_%s", cc_name); |
| 5352 | if (strict_ && is_equality) stream->Add("_STRICT"); |
| 5353 | if (never_nan_nan_ && is_equality) stream->Add("_NO_NAN"); |
| 5354 | if (!include_number_compare_) stream->Add("_NO_NUMBER"); |
| 5355 | if (!include_smi_compare_) stream->Add("_NO_SMI"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5356 | } |
| 5357 | |
| 5358 | |
| 5359 | // ------------------------------------------------------------------------- |
| 5360 | // StringCharCodeAtGenerator |
| 5361 | |
| 5362 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5363 | // If the receiver is a smi trigger the non-string case. |
| 5364 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5365 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5366 | |
| 5367 | // Fetch the instance type of the receiver into result register. |
| 5368 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5369 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5370 | // If the receiver is not a string trigger the non-string case. |
| 5371 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5372 | __ j(not_zero, receiver_not_string_); |
| 5373 | |
| 5374 | // If the index is non-smi trigger the non-smi case. |
| 5375 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5376 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5377 | __ bind(&got_smi_index_); |
| 5378 | |
| 5379 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5380 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5381 | __ j(above_equal, index_out_of_range_); |
| 5382 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5383 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5384 | |
| 5385 | Factory* factory = masm->isolate()->factory(); |
| 5386 | StringCharLoadGenerator::Generate( |
| 5387 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5388 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5389 | __ SmiTag(result_); |
| 5390 | __ bind(&exit_); |
| 5391 | } |
| 5392 | |
| 5393 | |
| 5394 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5395 | MacroAssembler* masm, |
| 5396 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5397 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5398 | |
| 5399 | // Index is not a smi. |
| 5400 | __ bind(&index_not_smi_); |
| 5401 | // 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] | 5402 | __ CheckMap(index_, |
| 5403 | masm->isolate()->factory()->heap_number_map(), |
| 5404 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5405 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5406 | call_helper.BeforeCall(masm); |
| 5407 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5408 | __ push(index_); // Consumed by runtime conversion function. |
| 5409 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5410 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5411 | } else { |
| 5412 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5413 | // NumberToSmi discards numbers that are not exact integers. |
| 5414 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5415 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5416 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5417 | // Save the conversion result before the pop instructions below |
| 5418 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5419 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5420 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5421 | __ pop(object_); |
| 5422 | // Reload the instance type. |
| 5423 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5424 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5425 | call_helper.AfterCall(masm); |
| 5426 | // If index is still not a smi, it must be out of range. |
| 5427 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5428 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5429 | // Otherwise, return to the fast path. |
| 5430 | __ jmp(&got_smi_index_); |
| 5431 | |
| 5432 | // Call runtime. We get here when the receiver is a string and the |
| 5433 | // index is a number, but the code of getting the actual character |
| 5434 | // is too complex (e.g., when the string needs to be flattened). |
| 5435 | __ bind(&call_runtime_); |
| 5436 | call_helper.BeforeCall(masm); |
| 5437 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5438 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5439 | __ push(index_); |
| 5440 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5441 | if (!result_.is(eax)) { |
| 5442 | __ mov(result_, eax); |
| 5443 | } |
| 5444 | call_helper.AfterCall(masm); |
| 5445 | __ jmp(&exit_); |
| 5446 | |
| 5447 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5448 | } |
| 5449 | |
| 5450 | |
| 5451 | // ------------------------------------------------------------------------- |
| 5452 | // StringCharFromCodeGenerator |
| 5453 | |
| 5454 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5455 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5456 | STATIC_ASSERT(kSmiTag == 0); |
| 5457 | STATIC_ASSERT(kSmiShiftSize == 0); |
| 5458 | ASSERT(IsPowerOf2(String::kMaxAsciiCharCode + 1)); |
| 5459 | __ test(code_, |
| 5460 | Immediate(kSmiTagMask | |
| 5461 | ((~String::kMaxAsciiCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5462 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5463 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5464 | Factory* factory = masm->isolate()->factory(); |
| 5465 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5466 | STATIC_ASSERT(kSmiTag == 0); |
| 5467 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5468 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5469 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5470 | __ mov(result_, FieldOperand(result_, |
| 5471 | code_, times_half_pointer_size, |
| 5472 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5473 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5474 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5475 | __ bind(&exit_); |
| 5476 | } |
| 5477 | |
| 5478 | |
| 5479 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5480 | MacroAssembler* masm, |
| 5481 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5482 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5483 | |
| 5484 | __ bind(&slow_case_); |
| 5485 | call_helper.BeforeCall(masm); |
| 5486 | __ push(code_); |
| 5487 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5488 | if (!result_.is(eax)) { |
| 5489 | __ mov(result_, eax); |
| 5490 | } |
| 5491 | call_helper.AfterCall(masm); |
| 5492 | __ jmp(&exit_); |
| 5493 | |
| 5494 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5495 | } |
| 5496 | |
| 5497 | |
| 5498 | // ------------------------------------------------------------------------- |
| 5499 | // StringCharAtGenerator |
| 5500 | |
| 5501 | void StringCharAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 5502 | char_code_at_generator_.GenerateFast(masm); |
| 5503 | char_from_code_generator_.GenerateFast(masm); |
| 5504 | } |
| 5505 | |
| 5506 | |
| 5507 | void StringCharAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5508 | MacroAssembler* masm, |
| 5509 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5510 | char_code_at_generator_.GenerateSlow(masm, call_helper); |
| 5511 | char_from_code_generator_.GenerateSlow(masm, call_helper); |
| 5512 | } |
| 5513 | |
| 5514 | |
| 5515 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5516 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5517 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5518 | |
| 5519 | // Load the two arguments. |
| 5520 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5521 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5522 | |
| 5523 | // 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] | 5524 | if (flags_ == NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5525 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5526 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5527 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5528 | |
| 5529 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5530 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5531 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5532 | __ j(above_equal, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5533 | } else { |
| 5534 | // Here at least one of the arguments is definitely a string. |
| 5535 | // We convert the one that is not known to be a string. |
| 5536 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 5537 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 5538 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5539 | &call_builtin); |
| 5540 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5541 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 5542 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 5543 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5544 | &call_builtin); |
| 5545 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 5546 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5547 | } |
| 5548 | |
| 5549 | // Both arguments are strings. |
| 5550 | // eax: first string |
| 5551 | // edx: second string |
| 5552 | // 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] | 5553 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5554 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5555 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5556 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5557 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5558 | // 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] | 5559 | Counters* counters = masm->isolate()->counters(); |
| 5560 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5561 | __ ret(2 * kPointerSize); |
| 5562 | __ bind(&second_not_zero_length); |
| 5563 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5564 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5565 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5566 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5567 | // First string is empty, result is second string which is in edx. |
| 5568 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5569 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5570 | __ ret(2 * kPointerSize); |
| 5571 | |
| 5572 | // Both strings are non-empty. |
| 5573 | // eax: first string |
| 5574 | // ebx: length of first string as a smi |
| 5575 | // ecx: length of second string as a smi |
| 5576 | // edx: second string |
| 5577 | // Look at the length of the result of adding the two strings. |
| 5578 | Label string_add_flat_result, longer_than_two; |
| 5579 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5580 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5581 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5582 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5583 | __ j(overflow, &call_runtime); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5584 | // Use the symbol table when adding two one character strings, as it |
| 5585 | // helps later optimizations to return a symbol here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5586 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5587 | __ j(not_equal, &longer_than_two); |
| 5588 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5589 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5590 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5591 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5592 | // Get the two characters forming the new string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5593 | __ movzx_b(ebx, FieldOperand(eax, SeqAsciiString::kHeaderSize)); |
| 5594 | __ movzx_b(ecx, FieldOperand(edx, SeqAsciiString::kHeaderSize)); |
| 5595 | |
| 5596 | // Try to lookup two character string in symbol table. If it is not found |
| 5597 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5598 | Label make_two_character_string, make_two_character_string_no_reload; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5599 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5600 | masm, ebx, ecx, eax, edx, edi, |
| 5601 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5602 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5603 | __ ret(2 * kPointerSize); |
| 5604 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5605 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5606 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5607 | // Reload the arguments. |
| 5608 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5609 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5610 | // Get the two characters forming the new string. |
| 5611 | __ movzx_b(ebx, FieldOperand(eax, SeqAsciiString::kHeaderSize)); |
| 5612 | __ movzx_b(ecx, FieldOperand(edx, SeqAsciiString::kHeaderSize)); |
| 5613 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5614 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5615 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5616 | // Pack both characters in ebx. |
| 5617 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5618 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5619 | // Set the characters in the new string. |
| 5620 | __ mov_w(FieldOperand(eax, SeqAsciiString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5621 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5622 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5623 | |
| 5624 | __ bind(&longer_than_two); |
| 5625 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5626 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5627 | __ j(below, &string_add_flat_result); |
| 5628 | |
| 5629 | // If result is not supposed to be flat allocate a cons string object. If both |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5630 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5631 | Label non_ascii, allocated, ascii_data; |
| 5632 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5633 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5634 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5635 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5636 | __ and_(ecx, edi); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5637 | STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
| 5638 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5639 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5640 | __ j(zero, &non_ascii); |
| 5641 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5642 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5643 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5644 | __ bind(&allocated); |
| 5645 | // Fill the fields of the cons string. |
| 5646 | if (FLAG_debug_code) __ AbortIfNotSmi(ebx); |
| 5647 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5648 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5649 | Immediate(String::kEmptyHashField)); |
| 5650 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5651 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5652 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5653 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5654 | __ ret(2 * kPointerSize); |
| 5655 | __ bind(&non_ascii); |
| 5656 | // At least one of the strings is two-byte. Check whether it happens |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5657 | // to contain only ASCII characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5658 | // ecx: first instance type AND second instance type. |
| 5659 | // edi: second instance type. |
| 5660 | __ test(ecx, Immediate(kAsciiDataHintMask)); |
| 5661 | __ j(not_zero, &ascii_data); |
| 5662 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5663 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5664 | __ xor_(edi, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5665 | STATIC_ASSERT(kAsciiStringTag != 0 && kAsciiDataHintTag != 0); |
| 5666 | __ and_(edi, kAsciiStringTag | kAsciiDataHintTag); |
| 5667 | __ cmp(edi, kAsciiStringTag | kAsciiDataHintTag); |
| 5668 | __ j(equal, &ascii_data); |
| 5669 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5670 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5671 | __ jmp(&allocated); |
| 5672 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5673 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5674 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5675 | // Handle creating a flat result from either external or sequential strings. |
| 5676 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5677 | // eax: first string |
| 5678 | // ebx: length of resulting flat string as a smi |
| 5679 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5680 | Label first_prepared, second_prepared; |
| 5681 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5682 | __ bind(&string_add_flat_result); |
| 5683 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5684 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5685 | // ecx: instance type of first string |
| 5686 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5687 | __ test_b(ecx, kStringRepresentationMask); |
| 5688 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5689 | // Rule out short external string and load string resource. |
| 5690 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5691 | __ test_b(ecx, kShortExternalStringMask); |
| 5692 | __ j(not_zero, &call_runtime); |
| 5693 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 5694 | STATIC_ASSERT(SeqAsciiString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
| 5695 | __ jmp(&first_prepared, Label::kNear); |
| 5696 | __ bind(&first_is_sequential); |
| 5697 | __ add(eax, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 5698 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5699 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5700 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5701 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5702 | // Check whether both strings have same encoding. |
| 5703 | // edi: instance type of second string |
| 5704 | __ xor_(ecx, edi); |
| 5705 | __ test_b(ecx, kStringEncodingMask); |
| 5706 | __ j(not_zero, &call_runtime); |
| 5707 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5708 | __ test_b(edi, kStringRepresentationMask); |
| 5709 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5710 | // Rule out short external string and load string resource. |
| 5711 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5712 | __ test_b(edi, kShortExternalStringMask); |
| 5713 | __ j(not_zero, &call_runtime); |
| 5714 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
| 5715 | STATIC_ASSERT(SeqAsciiString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
| 5716 | __ jmp(&second_prepared, Label::kNear); |
| 5717 | __ bind(&second_is_sequential); |
| 5718 | __ add(edx, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 5719 | __ bind(&second_prepared); |
| 5720 | |
| 5721 | // Push the addresses of both strings' first characters onto the stack. |
| 5722 | __ push(edx); |
| 5723 | __ push(eax); |
| 5724 | |
| 5725 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5726 | // edi: instance type of second string |
| 5727 | // First string and second string have the same encoding. |
| 5728 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5729 | __ test_b(edi, kStringEncodingMask); |
| 5730 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5731 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5732 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5733 | // ebx: length of resulting flat string as a smi |
| 5734 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5735 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5736 | // eax: result string |
| 5737 | __ mov(ecx, eax); |
| 5738 | // Locate first character of result. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5739 | __ add(ecx, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5740 | // Load first argument's length and first character location. Account for |
| 5741 | // values currently on the stack when fetching arguments from it. |
| 5742 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5743 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5744 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5745 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5746 | // eax: result string |
| 5747 | // ecx: first character of result |
| 5748 | // edx: first char of first argument |
| 5749 | // edi: length of first argument |
| 5750 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5751 | // Load second argument's length and first character location. Account for |
| 5752 | // values currently on the stack when fetching arguments from it. |
| 5753 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5754 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5755 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5756 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5757 | // eax: result string |
| 5758 | // ecx: next character of result |
| 5759 | // edx: first char of second argument |
| 5760 | // edi: length of second argument |
| 5761 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5762 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5763 | __ ret(2 * kPointerSize); |
| 5764 | |
| 5765 | // Handle creating a flat two byte result. |
| 5766 | // eax: first string - known to be two byte |
| 5767 | // ebx: length of resulting flat string as a smi |
| 5768 | // edx: second string |
| 5769 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5770 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5771 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5772 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5773 | // eax: result string |
| 5774 | __ mov(ecx, eax); |
| 5775 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5776 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5777 | // Load second argument's length and first character location. Account for |
| 5778 | // values currently on the stack when fetching arguments from it. |
| 5779 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5780 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5781 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5782 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5783 | // eax: result string |
| 5784 | // ecx: first character of result |
| 5785 | // edx: first char of first argument |
| 5786 | // edi: length of first argument |
| 5787 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5788 | // Load second argument's length and first character location. Account for |
| 5789 | // values currently on the stack when fetching arguments from it. |
| 5790 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5791 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5792 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5793 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5794 | // eax: result string |
| 5795 | // ecx: next character of result |
| 5796 | // edx: first char of second argument |
| 5797 | // edi: length of second argument |
| 5798 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5799 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5800 | __ ret(2 * kPointerSize); |
| 5801 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5802 | // Recover stack pointer before jumping to runtime. |
| 5803 | __ bind(&call_runtime_drop_two); |
| 5804 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5805 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5806 | __ bind(&call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5807 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5808 | |
| 5809 | if (call_builtin.is_linked()) { |
| 5810 | __ bind(&call_builtin); |
| 5811 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 5812 | } |
| 5813 | } |
| 5814 | |
| 5815 | |
| 5816 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 5817 | int stack_offset, |
| 5818 | Register arg, |
| 5819 | Register scratch1, |
| 5820 | Register scratch2, |
| 5821 | Register scratch3, |
| 5822 | Label* slow) { |
| 5823 | // First check if the argument is already a string. |
| 5824 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5825 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5826 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 5827 | __ j(below, &done); |
| 5828 | |
| 5829 | // Check the number to string cache. |
| 5830 | Label not_cached; |
| 5831 | __ bind(¬_string); |
| 5832 | // Puts the cached result into scratch1. |
| 5833 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 5834 | arg, |
| 5835 | scratch1, |
| 5836 | scratch2, |
| 5837 | scratch3, |
| 5838 | false, |
| 5839 | ¬_cached); |
| 5840 | __ mov(arg, scratch1); |
| 5841 | __ mov(Operand(esp, stack_offset), arg); |
| 5842 | __ jmp(&done); |
| 5843 | |
| 5844 | // Check if the argument is a safe string wrapper. |
| 5845 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5846 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5847 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 5848 | __ j(not_equal, slow); |
| 5849 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 5850 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 5851 | __ j(zero, slow); |
| 5852 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 5853 | __ mov(Operand(esp, stack_offset), arg); |
| 5854 | |
| 5855 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5856 | } |
| 5857 | |
| 5858 | |
| 5859 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5860 | Register dest, |
| 5861 | Register src, |
| 5862 | Register count, |
| 5863 | Register scratch, |
| 5864 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5865 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5866 | __ bind(&loop); |
| 5867 | // This loop just copies one character at a time, as it is only used for very |
| 5868 | // short strings. |
| 5869 | if (ascii) { |
| 5870 | __ mov_b(scratch, Operand(src, 0)); |
| 5871 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5872 | __ add(src, Immediate(1)); |
| 5873 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5874 | } else { |
| 5875 | __ mov_w(scratch, Operand(src, 0)); |
| 5876 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5877 | __ add(src, Immediate(2)); |
| 5878 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5879 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5880 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5881 | __ j(not_zero, &loop); |
| 5882 | } |
| 5883 | |
| 5884 | |
| 5885 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 5886 | Register dest, |
| 5887 | Register src, |
| 5888 | Register count, |
| 5889 | Register scratch, |
| 5890 | bool ascii) { |
| 5891 | // Copy characters using rep movs of doublewords. |
| 5892 | // The destination is aligned on a 4 byte boundary because we are |
| 5893 | // copying to the beginning of a newly allocated string. |
| 5894 | ASSERT(dest.is(edi)); // rep movs destination |
| 5895 | ASSERT(src.is(esi)); // rep movs source |
| 5896 | ASSERT(count.is(ecx)); // rep movs count |
| 5897 | ASSERT(!scratch.is(dest)); |
| 5898 | ASSERT(!scratch.is(src)); |
| 5899 | ASSERT(!scratch.is(count)); |
| 5900 | |
| 5901 | // Nothing to do for zero characters. |
| 5902 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5903 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5904 | __ j(zero, &done); |
| 5905 | |
| 5906 | // Make count the number of bytes to copy. |
| 5907 | if (!ascii) { |
| 5908 | __ shl(count, 1); |
| 5909 | } |
| 5910 | |
| 5911 | // 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] | 5912 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5913 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5914 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5915 | |
| 5916 | // Copy from edi to esi using rep movs instruction. |
| 5917 | __ mov(scratch, count); |
| 5918 | __ sar(count, 2); // Number of doublewords to copy. |
| 5919 | __ cld(); |
| 5920 | __ rep_movs(); |
| 5921 | |
| 5922 | // Find number of bytes left. |
| 5923 | __ mov(count, scratch); |
| 5924 | __ and_(count, 3); |
| 5925 | |
| 5926 | // Check if there are more bytes to copy. |
| 5927 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5928 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5929 | __ j(zero, &done); |
| 5930 | |
| 5931 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5932 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5933 | __ bind(&loop); |
| 5934 | __ mov_b(scratch, Operand(src, 0)); |
| 5935 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5936 | __ add(src, Immediate(1)); |
| 5937 | __ add(dest, Immediate(1)); |
| 5938 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5939 | __ j(not_zero, &loop); |
| 5940 | |
| 5941 | __ bind(&done); |
| 5942 | } |
| 5943 | |
| 5944 | |
| 5945 | void StringHelper::GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 5946 | Register c1, |
| 5947 | Register c2, |
| 5948 | Register scratch1, |
| 5949 | Register scratch2, |
| 5950 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5951 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5952 | Label* not_found) { |
| 5953 | // Register scratch3 is the general scratch register in this function. |
| 5954 | Register scratch = scratch3; |
| 5955 | |
| 5956 | // Make sure that both characters are not digits as such strings has a |
| 5957 | // 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] | 5958 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5959 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5960 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5961 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5962 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5963 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5964 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5965 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5966 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5967 | |
| 5968 | __ bind(¬_array_index); |
| 5969 | // Calculate the two character string hash. |
| 5970 | Register hash = scratch1; |
| 5971 | GenerateHashInit(masm, hash, c1, scratch); |
| 5972 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 5973 | GenerateHashGetHash(masm, hash, scratch); |
| 5974 | |
| 5975 | // Collect the two characters in a register. |
| 5976 | Register chars = c1; |
| 5977 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5978 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5979 | |
| 5980 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5981 | // hash: hash of two character string. |
| 5982 | |
| 5983 | // Load the symbol table. |
| 5984 | Register symbol_table = c2; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5985 | ExternalReference roots_array_start = |
| 5986 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5987 | __ mov(scratch, Immediate(Heap::kSymbolTableRootIndex)); |
| 5988 | __ mov(symbol_table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5989 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5990 | |
| 5991 | // Calculate capacity mask from the symbol table capacity. |
| 5992 | Register mask = scratch2; |
| 5993 | __ mov(mask, FieldOperand(symbol_table, SymbolTable::kCapacityOffset)); |
| 5994 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5995 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5996 | |
| 5997 | // Registers |
| 5998 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5999 | // hash: hash of two character string |
| 6000 | // symbol_table: symbol table |
| 6001 | // mask: capacity mask |
| 6002 | // scratch: - |
| 6003 | |
| 6004 | // Perform a number of probes in the symbol table. |
| 6005 | static const int kProbes = 4; |
| 6006 | Label found_in_symbol_table; |
| 6007 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6008 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6009 | for (int i = 0; i < kProbes; i++) { |
| 6010 | // Calculate entry in symbol table. |
| 6011 | __ mov(scratch, hash); |
| 6012 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6013 | __ add(scratch, Immediate(SymbolTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6014 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6015 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6016 | |
| 6017 | // Load the entry from the symbol table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6018 | STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
| 6019 | __ mov(candidate, |
| 6020 | FieldOperand(symbol_table, |
| 6021 | scratch, |
| 6022 | times_pointer_size, |
| 6023 | SymbolTable::kElementsStartOffset)); |
| 6024 | |
| 6025 | // 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] | 6026 | Factory* factory = masm->isolate()->factory(); |
| 6027 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6028 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6029 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6030 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6031 | |
| 6032 | // If length is not 2 the string is not a candidate. |
| 6033 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 6034 | Immediate(Smi::FromInt(2))); |
| 6035 | __ j(not_equal, &next_probe[i]); |
| 6036 | |
| 6037 | // As we are out of registers save the mask on the stack and use that |
| 6038 | // register as a temporary. |
| 6039 | __ push(mask); |
| 6040 | Register temp = mask; |
| 6041 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6042 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6043 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 6044 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 6045 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 6046 | temp, temp, &next_probe_pop_mask[i]); |
| 6047 | |
| 6048 | // Check if the two characters match. |
| 6049 | __ mov(temp, FieldOperand(candidate, SeqAsciiString::kHeaderSize)); |
| 6050 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6051 | __ cmp(chars, temp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6052 | __ j(equal, &found_in_symbol_table); |
| 6053 | __ bind(&next_probe_pop_mask[i]); |
| 6054 | __ pop(mask); |
| 6055 | __ bind(&next_probe[i]); |
| 6056 | } |
| 6057 | |
| 6058 | // No matching 2 character string found by probing. |
| 6059 | __ jmp(not_found); |
| 6060 | |
| 6061 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6062 | Register result = candidate; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6063 | __ bind(&found_in_symbol_table); |
| 6064 | __ pop(mask); // Pop saved mask from the stack. |
| 6065 | if (!result.is(eax)) { |
| 6066 | __ mov(eax, result); |
| 6067 | } |
| 6068 | } |
| 6069 | |
| 6070 | |
| 6071 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 6072 | Register hash, |
| 6073 | Register character, |
| 6074 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6075 | // hash = (seed + character) + ((seed + character) << 10); |
| 6076 | if (Serializer::enabled()) { |
| 6077 | ExternalReference roots_array_start = |
| 6078 | ExternalReference::roots_array_start(masm->isolate()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6079 | __ mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6080 | __ mov(scratch, Operand::StaticArray(scratch, |
| 6081 | times_pointer_size, |
| 6082 | roots_array_start)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6083 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6084 | __ add(scratch, character); |
| 6085 | __ mov(hash, scratch); |
| 6086 | __ shl(scratch, 10); |
| 6087 | __ add(hash, scratch); |
| 6088 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6089 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6090 | __ lea(scratch, Operand(character, seed)); |
| 6091 | __ shl(scratch, 10); |
| 6092 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 6093 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6094 | // hash ^= hash >> 6; |
| 6095 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6096 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6097 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6098 | } |
| 6099 | |
| 6100 | |
| 6101 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 6102 | Register hash, |
| 6103 | Register character, |
| 6104 | Register scratch) { |
| 6105 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6106 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6107 | // hash += hash << 10; |
| 6108 | __ mov(scratch, hash); |
| 6109 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6110 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6111 | // hash ^= hash >> 6; |
| 6112 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6113 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6114 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6115 | } |
| 6116 | |
| 6117 | |
| 6118 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 6119 | Register hash, |
| 6120 | Register scratch) { |
| 6121 | // hash += hash << 3; |
| 6122 | __ mov(scratch, hash); |
| 6123 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6124 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6125 | // hash ^= hash >> 11; |
| 6126 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6127 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6128 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6129 | // hash += hash << 15; |
| 6130 | __ mov(scratch, hash); |
| 6131 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6132 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6133 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6134 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6135 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6136 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6137 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6138 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6139 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6140 | __ bind(&hash_not_zero); |
| 6141 | } |
| 6142 | |
| 6143 | |
| 6144 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6145 | Label runtime; |
| 6146 | |
| 6147 | // Stack frame on entry. |
| 6148 | // esp[0]: return address |
| 6149 | // esp[4]: to |
| 6150 | // esp[8]: from |
| 6151 | // esp[12]: string |
| 6152 | |
| 6153 | // Make sure first argument is a string. |
| 6154 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 6155 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6156 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6157 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 6158 | __ j(NegateCondition(is_string), &runtime); |
| 6159 | |
| 6160 | // eax: string |
| 6161 | // ebx: instance type |
| 6162 | |
| 6163 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6164 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6165 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6166 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6167 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6168 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6169 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6170 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6171 | // Shorter than original string's length: an actual substring. |
| 6172 | __ j(below, ¬_original_string, Label::kNear); |
| 6173 | // Longer than original string's length or negative: unsafe arguments. |
| 6174 | __ j(above, &runtime); |
| 6175 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6176 | Counters* counters = masm->isolate()->counters(); |
| 6177 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6178 | __ ret(3 * kPointerSize); |
| 6179 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6180 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6181 | // eax: string |
| 6182 | // ebx: instance type |
| 6183 | // ecx: sub string length (smi) |
| 6184 | // edx: from index (smi) |
| 6185 | // Deal with different string types: update the index if necessary |
| 6186 | // and put the underlying string into edi. |
| 6187 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6188 | // If the string is not indirect, it can only be sequential or external. |
| 6189 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6190 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6191 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 6192 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 6193 | |
| 6194 | Factory* factory = masm->isolate()->factory(); |
| 6195 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 6196 | __ j(not_zero, &sliced_string, Label::kNear); |
| 6197 | // Cons string. Check whether it is flat, then fetch first part. |
| 6198 | // Flat cons strings have an empty second part. |
| 6199 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 6200 | factory->empty_string()); |
| 6201 | __ j(not_equal, &runtime); |
| 6202 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 6203 | // Update instance type. |
| 6204 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6205 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6206 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6207 | |
| 6208 | __ bind(&sliced_string); |
| 6209 | // Sliced string. Fetch parent and adjust start index by offset. |
| 6210 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6211 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6212 | // Update instance type. |
| 6213 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6214 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6215 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6216 | |
| 6217 | __ bind(&seq_or_external_string); |
| 6218 | // Sequential or external string. Just move string to the expected register. |
| 6219 | __ mov(edi, eax); |
| 6220 | |
| 6221 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6222 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6223 | if (FLAG_string_slices) { |
| 6224 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6225 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6226 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6227 | // edx: adjusted start index (smi) |
| 6228 | // ecx: length (smi) |
| 6229 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 6230 | // Short slice. Copy instead of slicing. |
| 6231 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6232 | // Allocate new sliced string. At this point we do not reload the instance |
| 6233 | // type including the string encoding because we simply rely on the info |
| 6234 | // provided by the original string. It does not matter if the original |
| 6235 | // string's encoding is wrong because we always have to recheck encoding of |
| 6236 | // the newly created string's parent anyways due to externalized strings. |
| 6237 | Label two_byte_slice, set_slice_header; |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6238 | STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
| 6239 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6240 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6241 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6242 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6243 | __ jmp(&set_slice_header, Label::kNear); |
| 6244 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6245 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6246 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6247 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6248 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6249 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6250 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6251 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6252 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6253 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6254 | |
| 6255 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6256 | } |
| 6257 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6258 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6259 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6260 | // edx: adjusted start index (smi) |
| 6261 | // ecx: length (smi) |
| 6262 | // The subject string can only be external or sequential string of either |
| 6263 | // encoding at this point. |
| 6264 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 6265 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6266 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6267 | __ test_b(ebx, kExternalStringTag); |
| 6268 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6269 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6270 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6271 | // Rule out short external strings. |
| 6272 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6273 | __ test_b(ebx, kShortExternalStringMask); |
| 6274 | __ j(not_zero, &runtime); |
| 6275 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 6276 | // Move the pointer so that offset-wise, it looks like a sequential string. |
| 6277 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); |
| 6278 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6279 | |
| 6280 | __ bind(&sequential_string); |
| 6281 | // Stash away (adjusted) index and (underlying) string. |
| 6282 | __ push(edx); |
| 6283 | __ push(edi); |
| 6284 | __ SmiUntag(ecx); |
| 6285 | STATIC_ASSERT((kAsciiStringTag & kStringEncodingMask) != 0); |
| 6286 | __ test_b(ebx, kStringEncodingMask); |
| 6287 | __ j(zero, &two_byte_sequential); |
| 6288 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6289 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6290 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6291 | |
| 6292 | // eax: result string |
| 6293 | // ecx: result string length |
| 6294 | __ mov(edx, esi); // esi used by following code. |
| 6295 | // Locate first character of result. |
| 6296 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6297 | __ add(edi, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6298 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6299 | __ pop(esi); |
| 6300 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6301 | __ SmiUntag(ebx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6302 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqAsciiString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6303 | |
| 6304 | // eax: result string |
| 6305 | // ecx: result length |
| 6306 | // edx: original value of esi |
| 6307 | // edi: first character of result |
| 6308 | // esi: character of sub string start |
| 6309 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6310 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6311 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6312 | __ ret(3 * kPointerSize); |
| 6313 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6314 | __ bind(&two_byte_sequential); |
| 6315 | // Sequential two-byte string. Allocate the result. |
| 6316 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6317 | |
| 6318 | // eax: result string |
| 6319 | // ecx: result string length |
| 6320 | __ mov(edx, esi); // esi used by following code. |
| 6321 | // Locate first character of result. |
| 6322 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6323 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6324 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6325 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6326 | __ pop(esi); |
| 6327 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6328 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6329 | // byte character. |
| 6330 | STATIC_ASSERT(kSmiTag == 0); |
| 6331 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6332 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6333 | |
| 6334 | // eax: result string |
| 6335 | // ecx: result length |
| 6336 | // edx: original value of esi |
| 6337 | // edi: first character of result |
| 6338 | // esi: character of sub string start |
| 6339 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6340 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6341 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6342 | __ ret(3 * kPointerSize); |
| 6343 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6344 | // Drop pushed values on the stack before tail call. |
| 6345 | __ bind(&runtime_drop_two); |
| 6346 | __ Drop(2); |
| 6347 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6348 | // Just jump to runtime to create the sub string. |
| 6349 | __ bind(&runtime); |
| 6350 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
| 6351 | } |
| 6352 | |
| 6353 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6354 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6355 | Register left, |
| 6356 | Register right, |
| 6357 | Register scratch1, |
| 6358 | Register scratch2) { |
| 6359 | Register length = scratch1; |
| 6360 | |
| 6361 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6362 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6363 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6364 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6365 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6366 | __ bind(&strings_not_equal); |
| 6367 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6368 | __ ret(0); |
| 6369 | |
| 6370 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6371 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6372 | __ bind(&check_zero_length); |
| 6373 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6374 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6375 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6376 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6377 | __ ret(0); |
| 6378 | |
| 6379 | // Compare characters. |
| 6380 | __ bind(&compare_chars); |
| 6381 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6382 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6383 | |
| 6384 | // Characters are equal. |
| 6385 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6386 | __ ret(0); |
| 6387 | } |
| 6388 | |
| 6389 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6390 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6391 | Register left, |
| 6392 | Register right, |
| 6393 | Register scratch1, |
| 6394 | Register scratch2, |
| 6395 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6396 | Counters* counters = masm->isolate()->counters(); |
| 6397 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6398 | |
| 6399 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6400 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6401 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6402 | __ mov(scratch3, scratch1); |
| 6403 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6404 | |
| 6405 | Register length_delta = scratch3; |
| 6406 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6407 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6408 | // 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] | 6409 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6410 | __ bind(&left_shorter); |
| 6411 | |
| 6412 | Register min_length = scratch1; |
| 6413 | |
| 6414 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6415 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6416 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6417 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6418 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6419 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6420 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6421 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6422 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6423 | |
| 6424 | // Compare lengths - strings up to min-length are equal. |
| 6425 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6426 | __ test(length_delta, length_delta); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6427 | __ j(not_zero, &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6428 | |
| 6429 | // Result is EQUAL. |
| 6430 | STATIC_ASSERT(EQUAL == 0); |
| 6431 | STATIC_ASSERT(kSmiTag == 0); |
| 6432 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6433 | __ ret(0); |
| 6434 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6435 | Label result_greater; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6436 | __ bind(&result_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6437 | __ j(greater, &result_greater, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6438 | |
| 6439 | // Result is LESS. |
| 6440 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6441 | __ ret(0); |
| 6442 | |
| 6443 | // Result is GREATER. |
| 6444 | __ bind(&result_greater); |
| 6445 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6446 | __ ret(0); |
| 6447 | } |
| 6448 | |
| 6449 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6450 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6451 | MacroAssembler* masm, |
| 6452 | Register left, |
| 6453 | Register right, |
| 6454 | Register length, |
| 6455 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6456 | Label* chars_not_equal, |
| 6457 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6458 | // Change index to run from -length to -1 by adding length to string |
| 6459 | // start. This means that loop ends when index reaches zero, which |
| 6460 | // doesn't need an additional compare. |
| 6461 | __ SmiUntag(length); |
| 6462 | __ lea(left, |
| 6463 | FieldOperand(left, length, times_1, SeqAsciiString::kHeaderSize)); |
| 6464 | __ lea(right, |
| 6465 | FieldOperand(right, length, times_1, SeqAsciiString::kHeaderSize)); |
| 6466 | __ neg(length); |
| 6467 | Register index = length; // index = -length; |
| 6468 | |
| 6469 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6470 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6471 | __ bind(&loop); |
| 6472 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6473 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6474 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6475 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6476 | __ j(not_zero, &loop); |
| 6477 | } |
| 6478 | |
| 6479 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6480 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6481 | Label runtime; |
| 6482 | |
| 6483 | // Stack frame on entry. |
| 6484 | // esp[0]: return address |
| 6485 | // esp[4]: right string |
| 6486 | // esp[8]: left string |
| 6487 | |
| 6488 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6489 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6490 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6491 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6492 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6493 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6494 | STATIC_ASSERT(EQUAL == 0); |
| 6495 | STATIC_ASSERT(kSmiTag == 0); |
| 6496 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6497 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6498 | __ ret(2 * kPointerSize); |
| 6499 | |
| 6500 | __ bind(¬_same); |
| 6501 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6502 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6503 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6504 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6505 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6506 | // Drop arguments from the stack. |
| 6507 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6508 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6509 | __ push(ecx); |
| 6510 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6511 | |
| 6512 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6513 | // tagged as a small integer. |
| 6514 | __ bind(&runtime); |
| 6515 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6516 | } |
| 6517 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6518 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6519 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
| 6520 | ASSERT(state_ == CompareIC::SMIS); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6521 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6522 | __ mov(ecx, edx); |
| 6523 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6524 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6525 | |
| 6526 | if (GetCondition() == equal) { |
| 6527 | // 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] | 6528 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6529 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6530 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6531 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6532 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6533 | // Correct sign of result in case of overflow. |
| 6534 | __ not_(edx); |
| 6535 | __ bind(&done); |
| 6536 | __ mov(eax, edx); |
| 6537 | } |
| 6538 | __ ret(0); |
| 6539 | |
| 6540 | __ bind(&miss); |
| 6541 | GenerateMiss(masm); |
| 6542 | } |
| 6543 | |
| 6544 | |
| 6545 | void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) { |
| 6546 | ASSERT(state_ == CompareIC::HEAP_NUMBERS); |
| 6547 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6548 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6549 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6550 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6551 | __ mov(ecx, edx); |
| 6552 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6553 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6554 | |
| 6555 | __ CmpObjectType(eax, HEAP_NUMBER_TYPE, ecx); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6556 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6557 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6558 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6559 | |
| 6560 | // Inlining the double comparison and falling back to the general compare |
| 6561 | // stub if NaN is involved or SS2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6562 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6563 | CpuFeatures::Scope scope1(SSE2); |
| 6564 | CpuFeatures::Scope scope2(CMOV); |
| 6565 | |
| 6566 | // Load left and right operand |
| 6567 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6568 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 6569 | |
| 6570 | // Compare operands |
| 6571 | __ ucomisd(xmm0, xmm1); |
| 6572 | |
| 6573 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6574 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6575 | |
| 6576 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6577 | // Performing mov, because xor would destroy the flag register. |
| 6578 | __ mov(eax, 0); // equal |
| 6579 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6580 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6581 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6582 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6583 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6584 | } |
| 6585 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6586 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6587 | CompareStub stub(GetCondition(), strict(), NO_COMPARE_FLAGS); |
| 6588 | __ bind(&generic_stub); |
| 6589 | __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 6590 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6591 | __ bind(&maybe_undefined1); |
| 6592 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6593 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6594 | __ j(not_equal, &miss); |
| 6595 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6596 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6597 | __ jmp(&unordered); |
| 6598 | } |
| 6599 | |
| 6600 | __ bind(&maybe_undefined2); |
| 6601 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6602 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6603 | __ j(equal, &unordered); |
| 6604 | } |
| 6605 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6606 | __ bind(&miss); |
| 6607 | GenerateMiss(masm); |
| 6608 | } |
| 6609 | |
| 6610 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6611 | void ICCompareStub::GenerateSymbols(MacroAssembler* masm) { |
| 6612 | ASSERT(state_ == CompareIC::SYMBOLS); |
| 6613 | ASSERT(GetCondition() == equal); |
| 6614 | |
| 6615 | // Registers containing left and right operands respectively. |
| 6616 | Register left = edx; |
| 6617 | Register right = eax; |
| 6618 | Register tmp1 = ecx; |
| 6619 | Register tmp2 = ebx; |
| 6620 | |
| 6621 | // Check that both operands are heap objects. |
| 6622 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6623 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6624 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6625 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6626 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6627 | |
| 6628 | // Check that both operands are symbols. |
| 6629 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6630 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6631 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6632 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6633 | STATIC_ASSERT(kSymbolTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6634 | __ and_(tmp1, tmp2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6635 | __ test(tmp1, Immediate(kIsSymbolMask)); |
| 6636 | __ j(zero, &miss, Label::kNear); |
| 6637 | |
| 6638 | // Symbols are compared by identity. |
| 6639 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6640 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6641 | // Make sure eax is non-zero. At this point input operands are |
| 6642 | // guaranteed to be non-zero. |
| 6643 | ASSERT(right.is(eax)); |
| 6644 | __ j(not_equal, &done, Label::kNear); |
| 6645 | STATIC_ASSERT(EQUAL == 0); |
| 6646 | STATIC_ASSERT(kSmiTag == 0); |
| 6647 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6648 | __ bind(&done); |
| 6649 | __ ret(0); |
| 6650 | |
| 6651 | __ bind(&miss); |
| 6652 | GenerateMiss(masm); |
| 6653 | } |
| 6654 | |
| 6655 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6656 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
| 6657 | ASSERT(state_ == CompareIC::STRINGS); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6658 | Label miss; |
| 6659 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6660 | bool equality = Token::IsEqualityOp(op_); |
| 6661 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6662 | // Registers containing left and right operands respectively. |
| 6663 | Register left = edx; |
| 6664 | Register right = eax; |
| 6665 | Register tmp1 = ecx; |
| 6666 | Register tmp2 = ebx; |
| 6667 | Register tmp3 = edi; |
| 6668 | |
| 6669 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6670 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6671 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6672 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6673 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6674 | |
| 6675 | // Check that both operands are strings. This leaves the instance |
| 6676 | // types loaded in tmp1 and tmp2. |
| 6677 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6678 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6679 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6680 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6681 | __ mov(tmp3, tmp1); |
| 6682 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6683 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6684 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 6685 | __ j(not_zero, &miss); |
| 6686 | |
| 6687 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6688 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6689 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6690 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6691 | STATIC_ASSERT(EQUAL == 0); |
| 6692 | STATIC_ASSERT(kSmiTag == 0); |
| 6693 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6694 | __ ret(0); |
| 6695 | |
| 6696 | // Handle not identical strings. |
| 6697 | __ bind(¬_same); |
| 6698 | |
| 6699 | // Check that both strings are symbols. If they are, we're done |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6700 | // because we already know they are not identical. But in the case of |
| 6701 | // non-equality compare, we still need to determine the order. |
| 6702 | if (equality) { |
| 6703 | Label do_compare; |
| 6704 | STATIC_ASSERT(kSymbolTag != 0); |
| 6705 | __ and_(tmp1, tmp2); |
| 6706 | __ test(tmp1, Immediate(kIsSymbolMask)); |
| 6707 | __ j(zero, &do_compare, Label::kNear); |
| 6708 | // Make sure eax is non-zero. At this point input operands are |
| 6709 | // guaranteed to be non-zero. |
| 6710 | ASSERT(right.is(eax)); |
| 6711 | __ ret(0); |
| 6712 | __ bind(&do_compare); |
| 6713 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6714 | |
| 6715 | // Check that both strings are sequential ASCII. |
| 6716 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6717 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 6718 | |
| 6719 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6720 | if (equality) { |
| 6721 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6722 | masm, left, right, tmp1, tmp2); |
| 6723 | } else { |
| 6724 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 6725 | masm, left, right, tmp1, tmp2, tmp3); |
| 6726 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6727 | |
| 6728 | // Handle more complex cases in runtime. |
| 6729 | __ bind(&runtime); |
| 6730 | __ pop(tmp1); // Return address. |
| 6731 | __ push(left); |
| 6732 | __ push(right); |
| 6733 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6734 | if (equality) { |
| 6735 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6736 | } else { |
| 6737 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6738 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6739 | |
| 6740 | __ bind(&miss); |
| 6741 | GenerateMiss(masm); |
| 6742 | } |
| 6743 | |
| 6744 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6745 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
| 6746 | ASSERT(state_ == CompareIC::OBJECTS); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6747 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6748 | __ mov(ecx, edx); |
| 6749 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6750 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6751 | |
| 6752 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6753 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6754 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6755 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6756 | |
| 6757 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6758 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6759 | __ ret(0); |
| 6760 | |
| 6761 | __ bind(&miss); |
| 6762 | GenerateMiss(masm); |
| 6763 | } |
| 6764 | |
| 6765 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6766 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 6767 | Label miss; |
| 6768 | __ mov(ecx, edx); |
| 6769 | __ and_(ecx, eax); |
| 6770 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6771 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6772 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 6773 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 6774 | __ cmp(ecx, known_map_); |
| 6775 | __ j(not_equal, &miss, Label::kNear); |
| 6776 | __ cmp(ebx, known_map_); |
| 6777 | __ j(not_equal, &miss, Label::kNear); |
| 6778 | |
| 6779 | __ sub(eax, edx); |
| 6780 | __ ret(0); |
| 6781 | |
| 6782 | __ bind(&miss); |
| 6783 | GenerateMiss(masm); |
| 6784 | } |
| 6785 | |
| 6786 | |
| 6787 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6788 | { |
| 6789 | // Call the runtime system in a fresh internal frame. |
| 6790 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 6791 | masm->isolate()); |
| 6792 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6793 | __ push(edx); // Preserve edx and eax. |
| 6794 | __ push(eax); |
| 6795 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6796 | __ push(eax); |
| 6797 | __ push(Immediate(Smi::FromInt(op_))); |
| 6798 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6799 | // Compute the entry point of the rewritten stub. |
| 6800 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 6801 | __ pop(eax); |
| 6802 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6803 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6804 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6805 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6806 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6807 | } |
| 6808 | |
| 6809 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6810 | // Helper function used to check that the dictionary doesn't contain |
| 6811 | // the property. This function may return false negatives, so miss_label |
| 6812 | // must always call a backup property check that is complete. |
| 6813 | // This function is safe to call if the receiver has fast properties. |
| 6814 | // 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] | 6815 | void StringDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 6816 | Label* miss, |
| 6817 | Label* done, |
| 6818 | Register properties, |
| 6819 | Handle<String> name, |
| 6820 | Register r0) { |
| 6821 | ASSERT(name->IsSymbol()); |
| 6822 | |
| 6823 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6824 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6825 | // undefined value), it guarantees the hash table doesn't contain the |
| 6826 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6827 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6828 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6829 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6830 | Register index = r0; |
| 6831 | // Capacity is smi 2^n. |
| 6832 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 6833 | __ dec(index); |
| 6834 | __ and_(index, |
| 6835 | Immediate(Smi::FromInt(name->Hash() + |
| 6836 | StringDictionary::GetProbeOffset(i)))); |
| 6837 | |
| 6838 | // Scale the index by multiplying by the entry size. |
| 6839 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6840 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 6841 | Register entity_name = r0; |
| 6842 | // Having undefined at this place means the name is not contained. |
| 6843 | ASSERT_EQ(kSmiTagSize, 1); |
| 6844 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 6845 | kElementsStartOffset - kHeapObjectTag)); |
| 6846 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 6847 | __ j(equal, done); |
| 6848 | |
| 6849 | // Stop if found the property. |
| 6850 | __ cmp(entity_name, Handle<String>(name)); |
| 6851 | __ j(equal, miss); |
| 6852 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6853 | Label the_hole; |
| 6854 | // Check for the hole and skip. |
| 6855 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
| 6856 | __ j(equal, &the_hole, Label::kNear); |
| 6857 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6858 | // Check if the entry name is not a symbol. |
| 6859 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 6860 | __ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 6861 | kIsSymbolMask); |
| 6862 | __ j(zero, miss); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6863 | __ bind(&the_hole); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6864 | } |
| 6865 | |
| 6866 | StringDictionaryLookupStub stub(properties, |
| 6867 | r0, |
| 6868 | r0, |
| 6869 | StringDictionaryLookupStub::NEGATIVE_LOOKUP); |
| 6870 | __ push(Immediate(Handle<Object>(name))); |
| 6871 | __ push(Immediate(name->Hash())); |
| 6872 | __ CallStub(&stub); |
| 6873 | __ test(r0, r0); |
| 6874 | __ j(not_zero, miss); |
| 6875 | __ jmp(done); |
| 6876 | } |
| 6877 | |
| 6878 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6879 | // Probe the string dictionary in the |elements| register. Jump to the |
| 6880 | // |done| label if a property with the given name is found leaving the |
| 6881 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 6882 | // otherwise. |
| 6883 | void StringDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 6884 | Label* miss, |
| 6885 | Label* done, |
| 6886 | Register elements, |
| 6887 | Register name, |
| 6888 | Register r0, |
| 6889 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 6890 | ASSERT(!elements.is(r0)); |
| 6891 | ASSERT(!elements.is(r1)); |
| 6892 | ASSERT(!name.is(r0)); |
| 6893 | ASSERT(!name.is(r1)); |
| 6894 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6895 | // Assert that name contains a string. |
| 6896 | if (FLAG_debug_code) __ AbortIfNotString(name); |
| 6897 | |
| 6898 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 6899 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 6900 | __ dec(r1); |
| 6901 | |
| 6902 | // Generate an unrolled loop that performs a few probes before |
| 6903 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 6904 | // cover ~93% of loads from dictionaries. |
| 6905 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6906 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6907 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 6908 | __ shr(r0, String::kHashShift); |
| 6909 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6910 | __ add(r0, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6911 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6912 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6913 | |
| 6914 | // Scale the index by multiplying by the entry size. |
| 6915 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6916 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 6917 | |
| 6918 | // Check if the key is identical to the name. |
| 6919 | __ cmp(name, Operand(elements, |
| 6920 | r0, |
| 6921 | times_4, |
| 6922 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6923 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6924 | } |
| 6925 | |
| 6926 | StringDictionaryLookupStub stub(elements, |
| 6927 | r1, |
| 6928 | r0, |
| 6929 | POSITIVE_LOOKUP); |
| 6930 | __ push(name); |
| 6931 | __ mov(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 6932 | __ shr(r0, String::kHashShift); |
| 6933 | __ push(r0); |
| 6934 | __ CallStub(&stub); |
| 6935 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6936 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6937 | __ j(zero, miss); |
| 6938 | __ jmp(done); |
| 6939 | } |
| 6940 | |
| 6941 | |
| 6942 | void StringDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6943 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 6944 | // 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] | 6945 | // Stack frame on entry: |
| 6946 | // esp[0 * kPointerSize]: return address. |
| 6947 | // esp[1 * kPointerSize]: key's hash. |
| 6948 | // esp[2 * kPointerSize]: key. |
| 6949 | // Registers: |
| 6950 | // dictionary_: StringDictionary to probe. |
| 6951 | // result_: used as scratch. |
| 6952 | // index_: will hold an index of entry if lookup is successful. |
| 6953 | // might alias with result_. |
| 6954 | // Returns: |
| 6955 | // result_ is zero if lookup failed, non zero otherwise. |
| 6956 | |
| 6957 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 6958 | |
| 6959 | Register scratch = result_; |
| 6960 | |
| 6961 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 6962 | __ dec(scratch); |
| 6963 | __ SmiUntag(scratch); |
| 6964 | __ push(scratch); |
| 6965 | |
| 6966 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6967 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6968 | // undefined value), it guarantees the hash table doesn't contain the |
| 6969 | // property. It's true even if some slots represent deleted properties |
| 6970 | // (their names are the null value). |
| 6971 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 6972 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6973 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 6974 | if (i > 0) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6975 | __ add(scratch, Immediate(StringDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6976 | } |
| 6977 | __ and_(scratch, Operand(esp, 0)); |
| 6978 | |
| 6979 | // Scale the index by multiplying by the entry size. |
| 6980 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6981 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 6982 | |
| 6983 | // Having undefined at this place means the name is not contained. |
| 6984 | ASSERT_EQ(kSmiTagSize, 1); |
| 6985 | __ mov(scratch, Operand(dictionary_, |
| 6986 | index_, |
| 6987 | times_pointer_size, |
| 6988 | kElementsStartOffset - kHeapObjectTag)); |
| 6989 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 6990 | __ j(equal, ¬_in_dictionary); |
| 6991 | |
| 6992 | // Stop if found the property. |
| 6993 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 6994 | __ j(equal, &in_dictionary); |
| 6995 | |
| 6996 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
| 6997 | // If we hit a non symbol key during negative lookup |
| 6998 | // we have to bailout as this key might be equal to the |
| 6999 | // key we are looking for. |
| 7000 | |
| 7001 | // Check if the entry name is not a symbol. |
| 7002 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 7003 | __ test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 7004 | kIsSymbolMask); |
| 7005 | __ j(zero, &maybe_in_dictionary); |
| 7006 | } |
| 7007 | } |
| 7008 | |
| 7009 | __ bind(&maybe_in_dictionary); |
| 7010 | // If we are doing negative lookup then probing failure should be |
| 7011 | // treated as a lookup success. For positive lookup probing failure |
| 7012 | // should be treated as lookup failure. |
| 7013 | if (mode_ == POSITIVE_LOOKUP) { |
| 7014 | __ mov(result_, Immediate(0)); |
| 7015 | __ Drop(1); |
| 7016 | __ ret(2 * kPointerSize); |
| 7017 | } |
| 7018 | |
| 7019 | __ bind(&in_dictionary); |
| 7020 | __ mov(result_, Immediate(1)); |
| 7021 | __ Drop(1); |
| 7022 | __ ret(2 * kPointerSize); |
| 7023 | |
| 7024 | __ bind(¬_in_dictionary); |
| 7025 | __ mov(result_, Immediate(0)); |
| 7026 | __ Drop(1); |
| 7027 | __ ret(2 * kPointerSize); |
| 7028 | } |
| 7029 | |
| 7030 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7031 | struct AheadOfTimeWriteBarrierStubList { |
| 7032 | Register object, value, address; |
| 7033 | RememberedSetAction action; |
| 7034 | }; |
| 7035 | |
| 7036 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7037 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 7038 | |
| 7039 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7040 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7041 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7042 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7043 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 7044 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7045 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7046 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7047 | // Used in StoreStubCompiler::CompileStoreField and |
| 7048 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7049 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7050 | // GenerateStoreField calls the stub with two different permutations of |
| 7051 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7052 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7053 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7054 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7055 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7056 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7057 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7058 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 7059 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7060 | // ElementsTransitionGenerator::GenerateSmiOnlyToObject |
| 7061 | // and ElementsTransitionGenerator::GenerateSmiOnlyToDouble |
| 7062 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7063 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 7064 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7065 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7066 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 7067 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7068 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7069 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7070 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7071 | { REG(no_reg), REG(no_reg), REG(no_reg), EMIT_REMEMBERED_SET} |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7072 | }; |
| 7073 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7074 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7075 | |
| 7076 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7077 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7078 | !entry->object.is(no_reg); |
| 7079 | entry++) { |
| 7080 | if (object_.is(entry->object) && |
| 7081 | value_.is(entry->value) && |
| 7082 | address_.is(entry->address) && |
| 7083 | remembered_set_action_ == entry->action && |
| 7084 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7085 | return true; |
| 7086 | } |
| 7087 | } |
| 7088 | return false; |
| 7089 | } |
| 7090 | |
| 7091 | |
| 7092 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime() { |
| 7093 | StoreBufferOverflowStub stub1(kDontSaveFPRegs); |
| 7094 | stub1.GetCode()->set_is_pregenerated(true); |
| 7095 | |
| 7096 | CpuFeatures::TryForceFeatureScope scope(SSE2); |
| 7097 | if (CpuFeatures::IsSupported(SSE2)) { |
| 7098 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
| 7099 | stub2.GetCode()->set_is_pregenerated(true); |
| 7100 | } |
| 7101 | } |
| 7102 | |
| 7103 | |
| 7104 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7105 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7106 | !entry->object.is(no_reg); |
| 7107 | entry++) { |
| 7108 | RecordWriteStub stub(entry->object, |
| 7109 | entry->value, |
| 7110 | entry->address, |
| 7111 | entry->action, |
| 7112 | kDontSaveFPRegs); |
| 7113 | stub.GetCode()->set_is_pregenerated(true); |
| 7114 | } |
| 7115 | } |
| 7116 | |
| 7117 | |
| 7118 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7119 | // the value has just been written into the object, now this stub makes sure |
| 7120 | // we keep the GC informed. The word in the object where the value has been |
| 7121 | // written is in the address register. |
| 7122 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7123 | Label skip_to_incremental_noncompacting; |
| 7124 | Label skip_to_incremental_compacting; |
| 7125 | |
| 7126 | // The first two instructions are generated with labels so as to get the |
| 7127 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7128 | // forth between a compare instructions (a nop in this position) and the |
| 7129 | // real branch when we start and stop incremental heap marking. |
| 7130 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 7131 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 7132 | |
| 7133 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7134 | __ RememberedSetHelper(object_, |
| 7135 | address_, |
| 7136 | value_, |
| 7137 | save_fp_regs_mode_, |
| 7138 | MacroAssembler::kReturnAtEnd); |
| 7139 | } else { |
| 7140 | __ ret(0); |
| 7141 | } |
| 7142 | |
| 7143 | __ bind(&skip_to_incremental_noncompacting); |
| 7144 | GenerateIncremental(masm, INCREMENTAL); |
| 7145 | |
| 7146 | __ bind(&skip_to_incremental_compacting); |
| 7147 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7148 | |
| 7149 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7150 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7151 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 7152 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 7153 | } |
| 7154 | |
| 7155 | |
| 7156 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7157 | regs_.Save(masm); |
| 7158 | |
| 7159 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7160 | Label dont_need_remembered_set; |
| 7161 | |
| 7162 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7163 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7164 | regs_.scratch0(), |
| 7165 | &dont_need_remembered_set); |
| 7166 | |
| 7167 | __ CheckPageFlag(regs_.object(), |
| 7168 | regs_.scratch0(), |
| 7169 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7170 | not_zero, |
| 7171 | &dont_need_remembered_set); |
| 7172 | |
| 7173 | // First notify the incremental marker if necessary, then update the |
| 7174 | // remembered set. |
| 7175 | CheckNeedsToInformIncrementalMarker( |
| 7176 | masm, |
| 7177 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 7178 | mode); |
| 7179 | InformIncrementalMarker(masm, mode); |
| 7180 | regs_.Restore(masm); |
| 7181 | __ RememberedSetHelper(object_, |
| 7182 | address_, |
| 7183 | value_, |
| 7184 | save_fp_regs_mode_, |
| 7185 | MacroAssembler::kReturnAtEnd); |
| 7186 | |
| 7187 | __ bind(&dont_need_remembered_set); |
| 7188 | } |
| 7189 | |
| 7190 | CheckNeedsToInformIncrementalMarker( |
| 7191 | masm, |
| 7192 | kReturnOnNoNeedToInformIncrementalMarker, |
| 7193 | mode); |
| 7194 | InformIncrementalMarker(masm, mode); |
| 7195 | regs_.Restore(masm); |
| 7196 | __ ret(0); |
| 7197 | } |
| 7198 | |
| 7199 | |
| 7200 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7201 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7202 | int argument_count = 3; |
| 7203 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7204 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
| 7205 | if (mode == INCREMENTAL_COMPACTION) { |
| 7206 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
| 7207 | } else { |
| 7208 | ASSERT(mode == INCREMENTAL); |
| 7209 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7210 | __ mov(Operand(esp, 1 * kPointerSize), regs_.scratch0()); // Value. |
| 7211 | } |
| 7212 | __ mov(Operand(esp, 2 * kPointerSize), |
| 7213 | Immediate(ExternalReference::isolate_address())); |
| 7214 | |
| 7215 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7216 | if (mode == INCREMENTAL_COMPACTION) { |
| 7217 | __ CallCFunction( |
| 7218 | ExternalReference::incremental_evacuation_record_write_function( |
| 7219 | masm->isolate()), |
| 7220 | argument_count); |
| 7221 | } else { |
| 7222 | ASSERT(mode == INCREMENTAL); |
| 7223 | __ CallCFunction( |
| 7224 | ExternalReference::incremental_marking_record_write_function( |
| 7225 | masm->isolate()), |
| 7226 | argument_count); |
| 7227 | } |
| 7228 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7229 | } |
| 7230 | |
| 7231 | |
| 7232 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7233 | MacroAssembler* masm, |
| 7234 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7235 | Mode mode) { |
| 7236 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7237 | |
| 7238 | // Let's look at the color of the object: If it is not black we don't have |
| 7239 | // to inform the incremental marker. |
| 7240 | __ JumpIfBlack(regs_.object(), |
| 7241 | regs_.scratch0(), |
| 7242 | regs_.scratch1(), |
| 7243 | &object_is_black, |
| 7244 | Label::kNear); |
| 7245 | |
| 7246 | regs_.Restore(masm); |
| 7247 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7248 | __ RememberedSetHelper(object_, |
| 7249 | address_, |
| 7250 | value_, |
| 7251 | save_fp_regs_mode_, |
| 7252 | MacroAssembler::kReturnAtEnd); |
| 7253 | } else { |
| 7254 | __ ret(0); |
| 7255 | } |
| 7256 | |
| 7257 | __ bind(&object_is_black); |
| 7258 | |
| 7259 | // Get the value from the slot. |
| 7260 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7261 | |
| 7262 | if (mode == INCREMENTAL_COMPACTION) { |
| 7263 | Label ensure_not_white; |
| 7264 | |
| 7265 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7266 | regs_.scratch1(), // Scratch. |
| 7267 | MemoryChunk::kEvacuationCandidateMask, |
| 7268 | zero, |
| 7269 | &ensure_not_white, |
| 7270 | Label::kNear); |
| 7271 | |
| 7272 | __ CheckPageFlag(regs_.object(), |
| 7273 | regs_.scratch1(), // Scratch. |
| 7274 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7275 | not_zero, |
| 7276 | &ensure_not_white, |
| 7277 | Label::kNear); |
| 7278 | |
| 7279 | __ jmp(&need_incremental); |
| 7280 | |
| 7281 | __ bind(&ensure_not_white); |
| 7282 | } |
| 7283 | |
| 7284 | // We need an extra register for this, so we push the object register |
| 7285 | // temporarily. |
| 7286 | __ push(regs_.object()); |
| 7287 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7288 | regs_.scratch1(), // Scratch. |
| 7289 | regs_.object(), // Scratch. |
| 7290 | &need_incremental_pop_object, |
| 7291 | Label::kNear); |
| 7292 | __ pop(regs_.object()); |
| 7293 | |
| 7294 | regs_.Restore(masm); |
| 7295 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7296 | __ RememberedSetHelper(object_, |
| 7297 | address_, |
| 7298 | value_, |
| 7299 | save_fp_regs_mode_, |
| 7300 | MacroAssembler::kReturnAtEnd); |
| 7301 | } else { |
| 7302 | __ ret(0); |
| 7303 | } |
| 7304 | |
| 7305 | __ bind(&need_incremental_pop_object); |
| 7306 | __ pop(regs_.object()); |
| 7307 | |
| 7308 | __ bind(&need_incremental); |
| 7309 | |
| 7310 | // Fall through when we need to inform the incremental marker. |
| 7311 | } |
| 7312 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7313 | |
| 7314 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7315 | // ----------- S t a t e ------------- |
| 7316 | // -- eax : element value to store |
| 7317 | // -- ebx : array literal |
| 7318 | // -- edi : map of array literal |
| 7319 | // -- ecx : element index as smi |
| 7320 | // -- edx : array literal index in function |
| 7321 | // -- esp[0] : return address |
| 7322 | // ----------------------------------- |
| 7323 | |
| 7324 | Label element_done; |
| 7325 | Label double_elements; |
| 7326 | Label smi_element; |
| 7327 | Label slow_elements; |
| 7328 | Label slow_elements_from_double; |
| 7329 | Label fast_elements; |
| 7330 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7331 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7332 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7333 | // FAST_SMI_ONLY_ELEMENTS or FAST_ELEMENTS |
| 7334 | __ JumpIfSmi(eax, &smi_element); |
| 7335 | __ CheckFastSmiOnlyElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7336 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7337 | // Store into the array literal requires a elements transition. Call into |
| 7338 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7339 | |
| 7340 | __ bind(&slow_elements); |
| 7341 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7342 | // call. |
| 7343 | __ push(ebx); |
| 7344 | __ push(ecx); |
| 7345 | __ push(eax); |
| 7346 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7347 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7348 | __ push(edx); |
| 7349 | __ push(edi); // Return return address so that tail call returns to right |
| 7350 | // place. |
| 7351 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7352 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7353 | __ bind(&slow_elements_from_double); |
| 7354 | __ pop(edx); |
| 7355 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7356 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7357 | // Array literal has ElementsKind of FAST_ELEMENTS and value is an object. |
| 7358 | __ bind(&fast_elements); |
| 7359 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7360 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7361 | FixedArrayBase::kHeaderSize)); |
| 7362 | __ mov(Operand(ecx, 0), eax); |
| 7363 | // Update the write barrier for the array store. |
| 7364 | __ RecordWrite(ebx, ecx, eax, |
| 7365 | kDontSaveFPRegs, |
| 7366 | EMIT_REMEMBERED_SET, |
| 7367 | OMIT_SMI_CHECK); |
| 7368 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7369 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7370 | // Array literal has ElementsKind of FAST_SMI_ONLY_ELEMENTS or |
| 7371 | // FAST_ELEMENTS, and value is Smi. |
| 7372 | __ bind(&smi_element); |
| 7373 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7374 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7375 | FixedArrayBase::kHeaderSize), eax); |
| 7376 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7377 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7378 | // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS. |
| 7379 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7380 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7381 | __ push(edx); |
| 7382 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7383 | __ StoreNumberToDoubleElements(eax, |
| 7384 | edx, |
| 7385 | ecx, |
| 7386 | edi, |
| 7387 | xmm0, |
| 7388 | &slow_elements_from_double, |
| 7389 | false); |
| 7390 | __ pop(edx); |
| 7391 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7392 | } |
| 7393 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7394 | #undef __ |
| 7395 | |
| 7396 | } } // namespace v8::internal |
| 7397 | |
| 7398 | #endif // V8_TARGET_ARCH_IA32 |