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_X64) |
| 31 | |
| 32 | #include "bootstrapper.h" |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 33 | #include "code-stubs.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 34 | #include "regexp-macro-assembler.h" |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 35 | #include "stub-cache.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 36 | |
| 37 | namespace v8 { |
| 38 | namespace internal { |
| 39 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 40 | |
| 41 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 42 | Isolate* isolate, |
| 43 | CodeStubInterfaceDescriptor* descriptor) { |
| 44 | static Register registers[] = { rdx, rax }; |
| 45 | descriptor->register_param_count_ = 2; |
| 46 | descriptor->register_params_ = registers; |
| 47 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame^] | 48 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 52 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 53 | |
| 54 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 55 | // The ToNumber stub takes one argument in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 56 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 57 | __ SmiTest(rax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 58 | __ j(not_zero, &check_heap_number, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 59 | __ Ret(); |
| 60 | |
| 61 | __ bind(&check_heap_number); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 62 | __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset), |
| 63 | Heap::kHeapNumberMapRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 64 | __ j(not_equal, &call_builtin, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 65 | __ Ret(); |
| 66 | |
| 67 | __ bind(&call_builtin); |
| 68 | __ pop(rcx); // Pop return address. |
| 69 | __ push(rax); |
| 70 | __ push(rcx); // Push return address. |
| 71 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
| 72 | } |
| 73 | |
| 74 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 75 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 76 | // Create a new closure from the given function info in new |
| 77 | // space. Set the context to the current context in rsi. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 78 | Counters* counters = masm->isolate()->counters(); |
| 79 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 80 | Label gc; |
| 81 | __ AllocateInNewSpace(JSFunction::kSize, rax, rbx, rcx, &gc, TAG_OBJECT); |
| 82 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 83 | __ IncrementCounter(counters->fast_new_closure_total(), 1); |
| 84 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 85 | // Get the function info from the stack. |
| 86 | __ movq(rdx, Operand(rsp, 1 * kPointerSize)); |
| 87 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 88 | int map_index = (language_mode_ == CLASSIC_MODE) |
| 89 | ? Context::FUNCTION_MAP_INDEX |
| 90 | : Context::STRICT_MODE_FUNCTION_MAP_INDEX; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 91 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 92 | // Compute the function map in the current native context and set that |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 93 | // as the map of the allocated object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 94 | __ movq(rcx, Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 95 | __ movq(rcx, FieldOperand(rcx, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 96 | __ movq(rbx, Operand(rcx, Context::SlotOffset(map_index))); |
| 97 | __ movq(FieldOperand(rax, JSObject::kMapOffset), rbx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 98 | |
| 99 | // Initialize the rest of the function. We don't have to update the |
| 100 | // write barrier because the allocated object is in new space. |
| 101 | __ LoadRoot(rbx, Heap::kEmptyFixedArrayRootIndex); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 102 | __ LoadRoot(r8, Heap::kTheHoleValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 103 | __ LoadRoot(rdi, Heap::kUndefinedValueRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 104 | __ movq(FieldOperand(rax, JSObject::kPropertiesOffset), rbx); |
| 105 | __ movq(FieldOperand(rax, JSObject::kElementsOffset), rbx); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 106 | __ movq(FieldOperand(rax, JSFunction::kPrototypeOrInitialMapOffset), r8); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 107 | __ movq(FieldOperand(rax, JSFunction::kSharedFunctionInfoOffset), rdx); |
| 108 | __ movq(FieldOperand(rax, JSFunction::kContextOffset), rsi); |
| 109 | __ movq(FieldOperand(rax, JSFunction::kLiteralsOffset), rbx); |
| 110 | |
| 111 | // Initialize the code pointer in the function to be the one |
| 112 | // found in the shared function info object. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 113 | // But first check if there is an optimized version for our context. |
| 114 | Label check_optimized; |
| 115 | Label install_unoptimized; |
| 116 | if (FLAG_cache_optimized_code) { |
| 117 | __ movq(rbx, |
| 118 | FieldOperand(rdx, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 119 | __ testq(rbx, rbx); |
| 120 | __ j(not_zero, &check_optimized, Label::kNear); |
| 121 | } |
| 122 | __ bind(&install_unoptimized); |
| 123 | __ movq(FieldOperand(rax, JSFunction::kNextFunctionLinkOffset), |
| 124 | rdi); // Initialize with undefined. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 125 | __ movq(rdx, FieldOperand(rdx, SharedFunctionInfo::kCodeOffset)); |
| 126 | __ lea(rdx, FieldOperand(rdx, Code::kHeaderSize)); |
| 127 | __ movq(FieldOperand(rax, JSFunction::kCodeEntryOffset), rdx); |
| 128 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 129 | // Return and remove the on-stack parameter. |
| 130 | __ ret(1 * kPointerSize); |
| 131 | |
| 132 | __ bind(&check_optimized); |
| 133 | |
| 134 | __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); |
| 135 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 136 | // rcx holds native context, ebx points to fixed array of 3-element entries |
| 137 | // (native context, optimized code, literals). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 138 | // The optimized code map must never be empty, so check the first elements. |
| 139 | Label install_optimized; |
| 140 | // Speculatively move code object into edx. |
| 141 | __ movq(rdx, FieldOperand(rbx, FixedArray::kHeaderSize + kPointerSize)); |
| 142 | __ cmpq(rcx, FieldOperand(rbx, FixedArray::kHeaderSize)); |
| 143 | __ j(equal, &install_optimized); |
| 144 | |
| 145 | // Iterate through the rest of map backwards. rdx holds an index. |
| 146 | Label loop; |
| 147 | Label restore; |
| 148 | __ movq(rdx, FieldOperand(rbx, FixedArray::kLengthOffset)); |
| 149 | __ SmiToInteger32(rdx, rdx); |
| 150 | __ bind(&loop); |
| 151 | // Do not double check first entry. |
| 152 | __ cmpq(rdx, Immediate(SharedFunctionInfo::kEntryLength)); |
| 153 | __ j(equal, &restore); |
| 154 | __ subq(rdx, Immediate(SharedFunctionInfo::kEntryLength)); // Skip an entry. |
| 155 | __ cmpq(rcx, FieldOperand(rbx, |
| 156 | rdx, |
| 157 | times_pointer_size, |
| 158 | FixedArray::kHeaderSize)); |
| 159 | __ j(not_equal, &loop, Label::kNear); |
| 160 | // Hit: fetch the optimized code. |
| 161 | __ movq(rdx, FieldOperand(rbx, |
| 162 | rdx, |
| 163 | times_pointer_size, |
| 164 | FixedArray::kHeaderSize + 1 * kPointerSize)); |
| 165 | |
| 166 | __ bind(&install_optimized); |
| 167 | __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); |
| 168 | |
| 169 | // TODO(fschneider): Idea: store proper code pointers in the map and either |
| 170 | // unmangle them on marking or do nothing as the whole map is discarded on |
| 171 | // major GC anyway. |
| 172 | __ lea(rdx, FieldOperand(rdx, Code::kHeaderSize)); |
| 173 | __ movq(FieldOperand(rax, JSFunction::kCodeEntryOffset), rdx); |
| 174 | |
| 175 | // Now link a function into a list of optimized functions. |
| 176 | __ movq(rdx, ContextOperand(rcx, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 177 | |
| 178 | __ movq(FieldOperand(rax, JSFunction::kNextFunctionLinkOffset), rdx); |
| 179 | // No need for write barrier as JSFunction (rax) is in the new space. |
| 180 | |
| 181 | __ movq(ContextOperand(rcx, Context::OPTIMIZED_FUNCTIONS_LIST), rax); |
| 182 | // Store JSFunction (rax) into rdx before issuing write barrier as |
| 183 | // it clobbers all the registers passed. |
| 184 | __ movq(rdx, rax); |
| 185 | __ RecordWriteContextSlot( |
| 186 | rcx, |
| 187 | Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), |
| 188 | rdx, |
| 189 | rbx, |
| 190 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 191 | |
| 192 | // Return and remove the on-stack parameter. |
| 193 | __ ret(1 * kPointerSize); |
| 194 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 195 | __ bind(&restore); |
| 196 | __ movq(rdx, Operand(rsp, 1 * kPointerSize)); |
| 197 | __ jmp(&install_unoptimized); |
| 198 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 199 | // Create a new closure through the slower runtime call. |
| 200 | __ bind(&gc); |
| 201 | __ pop(rcx); // Temporarily remove return address. |
| 202 | __ pop(rdx); |
| 203 | __ push(rsi); |
| 204 | __ push(rdx); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 205 | __ PushRoot(Heap::kFalseValueRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 206 | __ push(rcx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 207 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | |
| 211 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 212 | // Try to allocate the context in new space. |
| 213 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 214 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 215 | __ AllocateInNewSpace((length * kPointerSize) + FixedArray::kHeaderSize, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 216 | rax, rbx, rcx, &gc, TAG_OBJECT); |
| 217 | |
| 218 | // Get the function from the stack. |
| 219 | __ movq(rcx, Operand(rsp, 1 * kPointerSize)); |
| 220 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 221 | // Set up the object header. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 222 | __ LoadRoot(kScratchRegister, Heap::kFunctionContextMapRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 223 | __ movq(FieldOperand(rax, HeapObject::kMapOffset), kScratchRegister); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 224 | __ Move(FieldOperand(rax, FixedArray::kLengthOffset), Smi::FromInt(length)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 225 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 226 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 227 | __ Set(rbx, 0); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 228 | __ movq(Operand(rax, Context::SlotOffset(Context::CLOSURE_INDEX)), rcx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 229 | __ movq(Operand(rax, Context::SlotOffset(Context::PREVIOUS_INDEX)), rsi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 230 | __ movq(Operand(rax, Context::SlotOffset(Context::EXTENSION_INDEX)), rbx); |
| 231 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 232 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 233 | __ movq(rbx, Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 234 | __ movq(Operand(rax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), rbx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 235 | |
| 236 | // Initialize the rest of the slots to undefined. |
| 237 | __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 238 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 239 | __ movq(Operand(rax, Context::SlotOffset(i)), rbx); |
| 240 | } |
| 241 | |
| 242 | // Return and remove the on-stack parameter. |
| 243 | __ movq(rsi, rax); |
| 244 | __ ret(1 * kPointerSize); |
| 245 | |
| 246 | // Need to collect. Call into runtime system. |
| 247 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 248 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 252 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 253 | // Stack layout on entry: |
| 254 | // |
| 255 | // [rsp + (1 * kPointerSize)]: function |
| 256 | // [rsp + (2 * kPointerSize)]: serialized scope info |
| 257 | |
| 258 | // Try to allocate the context in new space. |
| 259 | Label gc; |
| 260 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 261 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
| 262 | rax, rbx, rcx, &gc, TAG_OBJECT); |
| 263 | |
| 264 | // Get the function from the stack. |
| 265 | __ movq(rcx, Operand(rsp, 1 * kPointerSize)); |
| 266 | |
| 267 | // Get the serialized scope info from the stack. |
| 268 | __ movq(rbx, Operand(rsp, 2 * kPointerSize)); |
| 269 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 270 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 271 | __ LoadRoot(kScratchRegister, Heap::kBlockContextMapRootIndex); |
| 272 | __ movq(FieldOperand(rax, HeapObject::kMapOffset), kScratchRegister); |
| 273 | __ Move(FieldOperand(rax, FixedArray::kLengthOffset), Smi::FromInt(length)); |
| 274 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 275 | // If this block context is nested in the native context we get a smi |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 276 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 277 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 278 | // we still have to look up. |
| 279 | Label after_sentinel; |
| 280 | __ JumpIfNotSmi(rcx, &after_sentinel, Label::kNear); |
| 281 | if (FLAG_debug_code) { |
| 282 | const char* message = "Expected 0 as a Smi sentinel"; |
| 283 | __ cmpq(rcx, Immediate(0)); |
| 284 | __ Assert(equal, message); |
| 285 | } |
| 286 | __ movq(rcx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 287 | __ movq(rcx, FieldOperand(rcx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 288 | __ movq(rcx, ContextOperand(rcx, Context::CLOSURE_INDEX)); |
| 289 | __ bind(&after_sentinel); |
| 290 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 291 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 292 | __ movq(ContextOperand(rax, Context::CLOSURE_INDEX), rcx); |
| 293 | __ movq(ContextOperand(rax, Context::PREVIOUS_INDEX), rsi); |
| 294 | __ movq(ContextOperand(rax, Context::EXTENSION_INDEX), rbx); |
| 295 | |
| 296 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 297 | __ movq(rbx, ContextOperand(rsi, Context::GLOBAL_OBJECT_INDEX)); |
| 298 | __ movq(ContextOperand(rax, Context::GLOBAL_OBJECT_INDEX), rbx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 299 | |
| 300 | // Initialize the rest of the slots to the hole value. |
| 301 | __ LoadRoot(rbx, Heap::kTheHoleValueRootIndex); |
| 302 | for (int i = 0; i < slots_; i++) { |
| 303 | __ movq(ContextOperand(rax, i + Context::MIN_CONTEXT_SLOTS), rbx); |
| 304 | } |
| 305 | |
| 306 | // Return and remove the on-stack parameter. |
| 307 | __ movq(rsi, rax); |
| 308 | __ ret(2 * kPointerSize); |
| 309 | |
| 310 | // Need to collect. Call into runtime system. |
| 311 | __ bind(&gc); |
| 312 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 313 | } |
| 314 | |
| 315 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 316 | static void GenerateFastCloneShallowArrayCommon( |
| 317 | MacroAssembler* masm, |
| 318 | int length, |
| 319 | FastCloneShallowArrayStub::Mode mode, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 320 | AllocationSiteMode allocation_site_mode, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 321 | Label* fail) { |
| 322 | // Registers on entry: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 323 | // |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 324 | // rcx: boilerplate literal array. |
| 325 | ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 326 | |
| 327 | // All sizes here are multiples of kPointerSize. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 328 | int elements_size = 0; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 329 | if (length > 0) { |
| 330 | elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 331 | ? FixedDoubleArray::SizeFor(length) |
| 332 | : FixedArray::SizeFor(length); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 333 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 334 | int size = JSArray::kSize; |
| 335 | int allocation_info_start = size; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 336 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 337 | size += AllocationSiteInfo::kSize; |
| 338 | } |
| 339 | size += elements_size; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 340 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 341 | // Allocate both the JS array and the elements array in one big |
| 342 | // allocation. This avoids multiple limit checks. |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 343 | AllocationFlags flags = TAG_OBJECT; |
| 344 | if (mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS) { |
| 345 | flags = static_cast<AllocationFlags>(DOUBLE_ALIGNMENT | flags); |
| 346 | } |
| 347 | __ AllocateInNewSpace(size, rax, rbx, rdx, fail, flags); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 348 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 349 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 350 | __ LoadRoot(kScratchRegister, Heap::kAllocationSiteInfoMapRootIndex); |
| 351 | __ movq(FieldOperand(rax, allocation_info_start), kScratchRegister); |
| 352 | __ movq(FieldOperand(rax, allocation_info_start + kPointerSize), rcx); |
| 353 | } |
| 354 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 355 | // Copy the JS array part. |
| 356 | for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 357 | if ((i != JSArray::kElementsOffset) || (length == 0)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 358 | __ movq(rbx, FieldOperand(rcx, i)); |
| 359 | __ movq(FieldOperand(rax, i), rbx); |
| 360 | } |
| 361 | } |
| 362 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 363 | if (length > 0) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 364 | // Get hold of the elements array of the boilerplate and setup the |
| 365 | // elements pointer in the resulting object. |
| 366 | __ movq(rcx, FieldOperand(rcx, JSArray::kElementsOffset)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 367 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 368 | __ lea(rdx, Operand(rax, JSArray::kSize + AllocationSiteInfo::kSize)); |
| 369 | } else { |
| 370 | __ lea(rdx, Operand(rax, JSArray::kSize)); |
| 371 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 372 | __ movq(FieldOperand(rax, JSArray::kElementsOffset), rdx); |
| 373 | |
| 374 | // Copy the elements array. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 375 | if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 376 | for (int i = 0; i < elements_size; i += kPointerSize) { |
| 377 | __ movq(rbx, FieldOperand(rcx, i)); |
| 378 | __ movq(FieldOperand(rdx, i), rbx); |
| 379 | } |
| 380 | } else { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 381 | ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 382 | int i; |
| 383 | for (i = 0; i < FixedDoubleArray::kHeaderSize; i += kPointerSize) { |
| 384 | __ movq(rbx, FieldOperand(rcx, i)); |
| 385 | __ movq(FieldOperand(rdx, i), rbx); |
| 386 | } |
| 387 | while (i < elements_size) { |
| 388 | __ movsd(xmm0, FieldOperand(rcx, i)); |
| 389 | __ movsd(FieldOperand(rdx, i), xmm0); |
| 390 | i += kDoubleSize; |
| 391 | } |
| 392 | ASSERT(i == elements_size); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 393 | } |
| 394 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 395 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 396 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 397 | void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) { |
| 398 | // Stack layout on entry: |
| 399 | // |
| 400 | // [rsp + kPointerSize]: constant elements. |
| 401 | // [rsp + (2 * kPointerSize)]: literal index. |
| 402 | // [rsp + (3 * kPointerSize)]: literals array. |
| 403 | |
| 404 | // Load boilerplate object into rcx and check if we need to create a |
| 405 | // boilerplate. |
| 406 | __ movq(rcx, Operand(rsp, 3 * kPointerSize)); |
| 407 | __ movq(rax, Operand(rsp, 2 * kPointerSize)); |
| 408 | SmiIndex index = masm->SmiToIndex(rax, rax, kPointerSizeLog2); |
| 409 | __ movq(rcx, |
| 410 | FieldOperand(rcx, index.reg, index.scale, FixedArray::kHeaderSize)); |
| 411 | __ CompareRoot(rcx, Heap::kUndefinedValueRootIndex); |
| 412 | Label slow_case; |
| 413 | __ j(equal, &slow_case); |
| 414 | |
| 415 | FastCloneShallowArrayStub::Mode mode = mode_; |
| 416 | // rcx is boilerplate object. |
| 417 | Factory* factory = masm->isolate()->factory(); |
| 418 | if (mode == CLONE_ANY_ELEMENTS) { |
| 419 | Label double_elements, check_fast_elements; |
| 420 | __ movq(rbx, FieldOperand(rcx, JSArray::kElementsOffset)); |
| 421 | __ Cmp(FieldOperand(rbx, HeapObject::kMapOffset), |
| 422 | factory->fixed_cow_array_map()); |
| 423 | __ j(not_equal, &check_fast_elements); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 424 | GenerateFastCloneShallowArrayCommon(masm, 0, COPY_ON_WRITE_ELEMENTS, |
| 425 | allocation_site_mode_, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 426 | &slow_case); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 427 | __ ret(3 * kPointerSize); |
| 428 | |
| 429 | __ bind(&check_fast_elements); |
| 430 | __ Cmp(FieldOperand(rbx, HeapObject::kMapOffset), |
| 431 | factory->fixed_array_map()); |
| 432 | __ j(not_equal, &double_elements); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 433 | GenerateFastCloneShallowArrayCommon(masm, length_, CLONE_ELEMENTS, |
| 434 | allocation_site_mode_, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 435 | &slow_case); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 436 | __ ret(3 * kPointerSize); |
| 437 | |
| 438 | __ bind(&double_elements); |
| 439 | mode = CLONE_DOUBLE_ELEMENTS; |
| 440 | // Fall through to generate the code to handle double elements. |
| 441 | } |
| 442 | |
| 443 | if (FLAG_debug_code) { |
| 444 | const char* message; |
| 445 | Heap::RootListIndex expected_map_index; |
| 446 | if (mode == CLONE_ELEMENTS) { |
| 447 | message = "Expected (writable) fixed array"; |
| 448 | expected_map_index = Heap::kFixedArrayMapRootIndex; |
| 449 | } else if (mode == CLONE_DOUBLE_ELEMENTS) { |
| 450 | message = "Expected (writable) fixed double array"; |
| 451 | expected_map_index = Heap::kFixedDoubleArrayMapRootIndex; |
| 452 | } else { |
| 453 | ASSERT(mode == COPY_ON_WRITE_ELEMENTS); |
| 454 | message = "Expected copy-on-write fixed array"; |
| 455 | expected_map_index = Heap::kFixedCOWArrayMapRootIndex; |
| 456 | } |
| 457 | __ push(rcx); |
| 458 | __ movq(rcx, FieldOperand(rcx, JSArray::kElementsOffset)); |
| 459 | __ CompareRoot(FieldOperand(rcx, HeapObject::kMapOffset), |
| 460 | expected_map_index); |
| 461 | __ Assert(equal, message); |
| 462 | __ pop(rcx); |
| 463 | } |
| 464 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 465 | GenerateFastCloneShallowArrayCommon(masm, length_, mode, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 466 | allocation_site_mode_, |
| 467 | &slow_case); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 468 | __ ret(3 * kPointerSize); |
| 469 | |
| 470 | __ bind(&slow_case); |
| 471 | __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
| 472 | } |
| 473 | |
| 474 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 475 | void FastCloneShallowObjectStub::Generate(MacroAssembler* masm) { |
| 476 | // Stack layout on entry: |
| 477 | // |
| 478 | // [rsp + kPointerSize]: object literal flags. |
| 479 | // [rsp + (2 * kPointerSize)]: constant properties. |
| 480 | // [rsp + (3 * kPointerSize)]: literal index. |
| 481 | // [rsp + (4 * kPointerSize)]: literals array. |
| 482 | |
| 483 | // Load boilerplate object into ecx and check if we need to create a |
| 484 | // boilerplate. |
| 485 | Label slow_case; |
| 486 | __ movq(rcx, Operand(rsp, 4 * kPointerSize)); |
| 487 | __ movq(rax, Operand(rsp, 3 * kPointerSize)); |
| 488 | SmiIndex index = masm->SmiToIndex(rax, rax, kPointerSizeLog2); |
| 489 | __ movq(rcx, |
| 490 | FieldOperand(rcx, index.reg, index.scale, FixedArray::kHeaderSize)); |
| 491 | __ CompareRoot(rcx, Heap::kUndefinedValueRootIndex); |
| 492 | __ j(equal, &slow_case); |
| 493 | |
| 494 | // Check that the boilerplate contains only fast properties and we can |
| 495 | // statically determine the instance size. |
| 496 | int size = JSObject::kHeaderSize + length_ * kPointerSize; |
| 497 | __ movq(rax, FieldOperand(rcx, HeapObject::kMapOffset)); |
| 498 | __ movzxbq(rax, FieldOperand(rax, Map::kInstanceSizeOffset)); |
| 499 | __ cmpq(rax, Immediate(size >> kPointerSizeLog2)); |
| 500 | __ j(not_equal, &slow_case); |
| 501 | |
| 502 | // Allocate the JS object and copy header together with all in-object |
| 503 | // properties from the boilerplate. |
| 504 | __ AllocateInNewSpace(size, rax, rbx, rdx, &slow_case, TAG_OBJECT); |
| 505 | for (int i = 0; i < size; i += kPointerSize) { |
| 506 | __ movq(rbx, FieldOperand(rcx, i)); |
| 507 | __ movq(FieldOperand(rax, i), rbx); |
| 508 | } |
| 509 | |
| 510 | // Return and remove the on-stack parameters. |
| 511 | __ ret(4 * kPointerSize); |
| 512 | |
| 513 | __ bind(&slow_case); |
| 514 | __ TailCallRuntime(Runtime::kCreateObjectLiteralShallow, 4, 1); |
| 515 | } |
| 516 | |
| 517 | |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 518 | // The stub expects its argument on the stack and returns its result in tos_: |
| 519 | // zero for false, and a non-zero value for true. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 520 | void ToBooleanStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 521 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 522 | // we cannot call anything that could cause a GC from this stub. |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 523 | Label patch; |
| 524 | const Register argument = rax; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 525 | const Register map = rdx; |
| 526 | |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 527 | if (!types_.IsEmpty()) { |
| 528 | __ movq(argument, Operand(rsp, 1 * kPointerSize)); |
| 529 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 530 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 531 | // undefined -> false |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 532 | CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 533 | |
| 534 | // Boolean -> its value |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 535 | CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); |
| 536 | CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 537 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 538 | // 'null' -> false. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 539 | CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 540 | |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 541 | if (types_.Contains(SMI)) { |
| 542 | // Smis: 0 -> false, all other -> true |
| 543 | Label not_smi; |
| 544 | __ JumpIfNotSmi(argument, ¬_smi, Label::kNear); |
| 545 | // argument contains the correct return value already |
| 546 | if (!tos_.is(argument)) { |
| 547 | __ movq(tos_, argument); |
| 548 | } |
| 549 | __ ret(1 * kPointerSize); |
| 550 | __ bind(¬_smi); |
| 551 | } else if (types_.NeedsMap()) { |
| 552 | // If we need a map later and have a Smi -> patch. |
| 553 | __ JumpIfSmi(argument, &patch, Label::kNear); |
| 554 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 555 | |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 556 | if (types_.NeedsMap()) { |
| 557 | __ movq(map, FieldOperand(argument, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 558 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 559 | if (types_.CanBeUndetectable()) { |
| 560 | __ testb(FieldOperand(map, Map::kBitFieldOffset), |
| 561 | Immediate(1 << Map::kIsUndetectable)); |
| 562 | // Undetectable -> false. |
| 563 | Label not_undetectable; |
| 564 | __ j(zero, ¬_undetectable, Label::kNear); |
| 565 | __ Set(tos_, 0); |
| 566 | __ ret(1 * kPointerSize); |
| 567 | __ bind(¬_undetectable); |
| 568 | } |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 569 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 570 | |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 571 | if (types_.Contains(SPEC_OBJECT)) { |
| 572 | // spec object -> true. |
| 573 | Label not_js_object; |
| 574 | __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
| 575 | __ j(below, ¬_js_object, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 576 | // argument contains the correct return value already. |
| 577 | if (!tos_.is(argument)) { |
| 578 | __ Set(tos_, 1); |
| 579 | } |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 580 | __ ret(1 * kPointerSize); |
| 581 | __ bind(¬_js_object); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 582 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 583 | |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 584 | if (types_.Contains(STRING)) { |
| 585 | // String value -> false iff empty. |
| 586 | Label not_string; |
| 587 | __ CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
| 588 | __ j(above_equal, ¬_string, Label::kNear); |
| 589 | __ movq(tos_, FieldOperand(argument, String::kLengthOffset)); |
| 590 | __ ret(1 * kPointerSize); // the string length is OK as the return value |
| 591 | __ bind(¬_string); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 592 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 593 | |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 594 | if (types_.Contains(HEAP_NUMBER)) { |
| 595 | // heap number -> false iff +0, -0, or NaN. |
| 596 | Label not_heap_number, false_result; |
| 597 | __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 598 | __ j(not_equal, ¬_heap_number, Label::kNear); |
| 599 | __ xorps(xmm0, xmm0); |
| 600 | __ ucomisd(xmm0, FieldOperand(argument, HeapNumber::kValueOffset)); |
| 601 | __ j(zero, &false_result, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 602 | // argument contains the correct return value already. |
| 603 | if (!tos_.is(argument)) { |
| 604 | __ Set(tos_, 1); |
| 605 | } |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 606 | __ ret(1 * kPointerSize); |
| 607 | __ bind(&false_result); |
| 608 | __ Set(tos_, 0); |
| 609 | __ ret(1 * kPointerSize); |
| 610 | __ bind(¬_heap_number); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 611 | } |
| 612 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 613 | __ bind(&patch); |
| 614 | GenerateTypeTransition(masm); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 618 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 619 | __ PushCallerSaved(save_doubles_); |
| 620 | const int argument_count = 1; |
| 621 | __ PrepareCallCFunction(argument_count); |
| 622 | #ifdef _WIN64 |
| 623 | __ LoadAddress(rcx, ExternalReference::isolate_address()); |
| 624 | #else |
| 625 | __ LoadAddress(rdi, ExternalReference::isolate_address()); |
| 626 | #endif |
| 627 | |
| 628 | AllowExternalCallThatCantCauseGC scope(masm); |
| 629 | __ CallCFunction( |
| 630 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 631 | argument_count); |
| 632 | __ PopCallerSaved(save_doubles_); |
| 633 | __ ret(0); |
| 634 | } |
| 635 | |
| 636 | |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 637 | void ToBooleanStub::CheckOddball(MacroAssembler* masm, |
| 638 | Type type, |
| 639 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 640 | bool result) { |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 641 | const Register argument = rax; |
| 642 | if (types_.Contains(type)) { |
| 643 | // If we see an expected oddball, return its ToBoolean value tos_. |
| 644 | Label different_value; |
| 645 | __ CompareRoot(argument, value); |
| 646 | __ j(not_equal, &different_value, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 647 | if (!result) { |
| 648 | // If we have to return zero, there is no way around clearing tos_. |
| 649 | __ Set(tos_, 0); |
| 650 | } else if (!tos_.is(argument)) { |
| 651 | // If we have to return non-zero, we can re-use the argument if it is the |
| 652 | // same register as the result, because we never see Smi-zero here. |
| 653 | __ Set(tos_, 1); |
| 654 | } |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 655 | __ ret(1 * kPointerSize); |
| 656 | __ bind(&different_value); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | |
| 660 | |
| 661 | void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 662 | __ pop(rcx); // Get return address, operand is now on top of stack. |
| 663 | __ Push(Smi::FromInt(tos_.code())); |
| 664 | __ Push(Smi::FromInt(types_.ToByte())); |
| 665 | __ push(rcx); // Push return address. |
| 666 | // Patch the caller to an appropriate specialized stub and return the |
| 667 | // operation result to the caller of the stub. |
| 668 | __ TailCallExternalReference( |
| 669 | ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), |
| 670 | 3, |
| 671 | 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 675 | class FloatingPointHelper : public AllStatic { |
| 676 | public: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 677 | enum ConvertUndefined { |
| 678 | CONVERT_UNDEFINED_TO_ZERO, |
| 679 | BAILOUT_ON_UNDEFINED |
| 680 | }; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 681 | // Load the operands from rdx and rax into xmm0 and xmm1, as doubles. |
| 682 | // If the operands are not both numbers, jump to not_numbers. |
| 683 | // Leaves rdx and rax unchanged. SmiOperands assumes both are smis. |
| 684 | // NumberOperands assumes both are smis or heap numbers. |
| 685 | static void LoadSSE2SmiOperands(MacroAssembler* masm); |
| 686 | static void LoadSSE2NumberOperands(MacroAssembler* masm); |
| 687 | static void LoadSSE2UnknownOperands(MacroAssembler* masm, |
| 688 | Label* not_numbers); |
| 689 | |
| 690 | // Takes the operands in rdx and rax and loads them as integers in rax |
| 691 | // and rcx. |
| 692 | static void LoadAsIntegers(MacroAssembler* masm, |
| 693 | Label* operand_conversion_failure, |
| 694 | Register heap_number_map); |
| 695 | // As above, but we know the operands to be numbers. In that case, |
| 696 | // conversion can't fail. |
| 697 | static void LoadNumbersAsIntegers(MacroAssembler* masm); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 698 | |
| 699 | // Tries to convert two values to smis losslessly. |
| 700 | // This fails if either argument is not a Smi nor a HeapNumber, |
| 701 | // or if it's a HeapNumber with a value that can't be converted |
| 702 | // losslessly to a Smi. In that case, control transitions to the |
| 703 | // on_not_smis label. |
| 704 | // On success, either control goes to the on_success label (if one is |
| 705 | // provided), or it falls through at the end of the code (if on_success |
| 706 | // is NULL). |
| 707 | // On success, both first and second holds Smi tagged values. |
| 708 | // One of first or second must be non-Smi when entering. |
| 709 | static void NumbersToSmis(MacroAssembler* masm, |
| 710 | Register first, |
| 711 | Register second, |
| 712 | Register scratch1, |
| 713 | Register scratch2, |
| 714 | Register scratch3, |
| 715 | Label* on_success, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 716 | Label* on_not_smis, |
| 717 | ConvertUndefined convert_undefined); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 718 | }; |
| 719 | |
| 720 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 721 | // Get the integer part of a heap number. |
| 722 | // Overwrites the contents of rdi, rbx and rcx. Result cannot be rdi or rbx. |
| 723 | void IntegerConvert(MacroAssembler* masm, |
| 724 | Register result, |
| 725 | Register source) { |
| 726 | // Result may be rcx. If result and source are the same register, source will |
| 727 | // be overwritten. |
| 728 | ASSERT(!result.is(rdi) && !result.is(rbx)); |
| 729 | // TODO(lrn): When type info reaches here, if value is a 32-bit integer, use |
| 730 | // cvttsd2si (32-bit version) directly. |
| 731 | Register double_exponent = rbx; |
| 732 | Register double_value = rdi; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 733 | Label done, exponent_63_plus; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 734 | // Get double and extract exponent. |
| 735 | __ movq(double_value, FieldOperand(source, HeapNumber::kValueOffset)); |
| 736 | // Clear result preemptively, in case we need to return zero. |
| 737 | __ xorl(result, result); |
| 738 | __ movq(xmm0, double_value); // Save copy in xmm0 in case we need it there. |
| 739 | // Double to remove sign bit, shift exponent down to least significant bits. |
| 740 | // and subtract bias to get the unshifted, unbiased exponent. |
| 741 | __ lea(double_exponent, Operand(double_value, double_value, times_1, 0)); |
| 742 | __ shr(double_exponent, Immediate(64 - HeapNumber::kExponentBits)); |
| 743 | __ subl(double_exponent, Immediate(HeapNumber::kExponentBias)); |
| 744 | // Check whether the exponent is too big for a 63 bit unsigned integer. |
| 745 | __ cmpl(double_exponent, Immediate(63)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 746 | __ j(above_equal, &exponent_63_plus, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 747 | // Handle exponent range 0..62. |
| 748 | __ cvttsd2siq(result, xmm0); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 749 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 750 | |
| 751 | __ bind(&exponent_63_plus); |
| 752 | // Exponent negative or 63+. |
| 753 | __ cmpl(double_exponent, Immediate(83)); |
| 754 | // If exponent negative or above 83, number contains no significant bits in |
| 755 | // the range 0..2^31, so result is zero, and rcx already holds zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 756 | __ j(above, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 757 | |
| 758 | // Exponent in rage 63..83. |
| 759 | // Mantissa * 2^exponent contains bits in the range 2^0..2^31, namely |
| 760 | // the least significant exponent-52 bits. |
| 761 | |
| 762 | // Negate low bits of mantissa if value is negative. |
| 763 | __ addq(double_value, double_value); // Move sign bit to carry. |
| 764 | __ sbbl(result, result); // And convert carry to -1 in result register. |
| 765 | // if scratch2 is negative, do (scratch2-1)^-1, otherwise (scratch2-0)^0. |
| 766 | __ addl(double_value, result); |
| 767 | // Do xor in opposite directions depending on where we want the result |
| 768 | // (depending on whether result is rcx or not). |
| 769 | |
| 770 | if (result.is(rcx)) { |
| 771 | __ xorl(double_value, result); |
| 772 | // Left shift mantissa by (exponent - mantissabits - 1) to save the |
| 773 | // bits that have positional values below 2^32 (the extra -1 comes from the |
| 774 | // doubling done above to move the sign bit into the carry flag). |
| 775 | __ leal(rcx, Operand(double_exponent, -HeapNumber::kMantissaBits - 1)); |
| 776 | __ shll_cl(double_value); |
| 777 | __ movl(result, double_value); |
| 778 | } else { |
| 779 | // As the then-branch, but move double-value to result before shifting. |
| 780 | __ xorl(result, double_value); |
| 781 | __ leal(rcx, Operand(double_exponent, -HeapNumber::kMantissaBits - 1)); |
| 782 | __ shll_cl(result); |
| 783 | } |
| 784 | |
| 785 | __ bind(&done); |
| 786 | } |
| 787 | |
| 788 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 789 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 790 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 791 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 792 | GenerateTypeTransition(masm); |
| 793 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 794 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 795 | GenerateSmiStub(masm); |
| 796 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 797 | case UnaryOpIC::HEAP_NUMBER: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 798 | GenerateHeapNumberStub(masm); |
| 799 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 800 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 801 | GenerateGenericStub(masm); |
| 802 | break; |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 807 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 808 | __ pop(rcx); // Save return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 809 | |
| 810 | __ push(rax); // the operand |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 811 | __ Push(Smi::FromInt(op_)); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 812 | __ Push(Smi::FromInt(mode_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 813 | __ Push(Smi::FromInt(operand_type_)); |
| 814 | |
| 815 | __ push(rcx); // Push return address. |
| 816 | |
| 817 | // Patch the caller to an appropriate specialized stub and return the |
| 818 | // operation result to the caller of the stub. |
| 819 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 820 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | |
| 824 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 825 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 826 | switch (op_) { |
| 827 | case Token::SUB: |
| 828 | GenerateSmiStubSub(masm); |
| 829 | break; |
| 830 | case Token::BIT_NOT: |
| 831 | GenerateSmiStubBitNot(masm); |
| 832 | break; |
| 833 | default: |
| 834 | UNREACHABLE(); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 839 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 840 | Label slow; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 841 | GenerateSmiCodeSub(masm, &slow, &slow, Label::kNear, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 842 | __ bind(&slow); |
| 843 | GenerateTypeTransition(masm); |
| 844 | } |
| 845 | |
| 846 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 847 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 848 | Label non_smi; |
| 849 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 850 | __ bind(&non_smi); |
| 851 | GenerateTypeTransition(masm); |
| 852 | } |
| 853 | |
| 854 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 855 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 856 | Label* non_smi, |
| 857 | Label* slow, |
| 858 | Label::Distance non_smi_near, |
| 859 | Label::Distance slow_near) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 860 | Label done; |
| 861 | __ JumpIfNotSmi(rax, non_smi, non_smi_near); |
| 862 | __ SmiNeg(rax, rax, &done, Label::kNear); |
| 863 | __ jmp(slow, slow_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 864 | __ bind(&done); |
| 865 | __ ret(0); |
| 866 | } |
| 867 | |
| 868 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 869 | void UnaryOpStub::GenerateSmiCodeBitNot(MacroAssembler* masm, |
| 870 | Label* non_smi, |
| 871 | Label::Distance non_smi_near) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 872 | __ JumpIfNotSmi(rax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 873 | __ SmiNot(rax, rax); |
| 874 | __ ret(0); |
| 875 | } |
| 876 | |
| 877 | |
| 878 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 879 | void UnaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 880 | switch (op_) { |
| 881 | case Token::SUB: |
| 882 | GenerateHeapNumberStubSub(masm); |
| 883 | break; |
| 884 | case Token::BIT_NOT: |
| 885 | GenerateHeapNumberStubBitNot(masm); |
| 886 | break; |
| 887 | default: |
| 888 | UNREACHABLE(); |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 893 | void UnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 894 | Label non_smi, slow, call_builtin; |
| 895 | GenerateSmiCodeSub(masm, &non_smi, &call_builtin, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 896 | __ bind(&non_smi); |
| 897 | GenerateHeapNumberCodeSub(masm, &slow); |
| 898 | __ bind(&slow); |
| 899 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 900 | __ bind(&call_builtin); |
| 901 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 905 | void UnaryOpStub::GenerateHeapNumberStubBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 906 | MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 907 | Label non_smi, slow; |
| 908 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 909 | __ bind(&non_smi); |
| 910 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 911 | __ bind(&slow); |
| 912 | GenerateTypeTransition(masm); |
| 913 | } |
| 914 | |
| 915 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 916 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 917 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 918 | // Check if the operand is a heap number. |
| 919 | __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset), |
| 920 | Heap::kHeapNumberMapRootIndex); |
| 921 | __ j(not_equal, slow); |
| 922 | |
| 923 | // Operand is a float, negate its value by flipping the sign bit. |
| 924 | if (mode_ == UNARY_OVERWRITE) { |
| 925 | __ Set(kScratchRegister, 0x01); |
| 926 | __ shl(kScratchRegister, Immediate(63)); |
| 927 | __ xor_(FieldOperand(rax, HeapNumber::kValueOffset), kScratchRegister); |
| 928 | } else { |
| 929 | // Allocate a heap number before calculating the answer, |
| 930 | // so we don't have an untagged double around during GC. |
| 931 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 932 | __ AllocateHeapNumber(rcx, rbx, &slow_allocate_heapnumber); |
| 933 | __ jmp(&heapnumber_allocated); |
| 934 | |
| 935 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 936 | { |
| 937 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 938 | __ push(rax); |
| 939 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 940 | __ movq(rcx, rax); |
| 941 | __ pop(rax); |
| 942 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 943 | __ bind(&heapnumber_allocated); |
| 944 | // rcx: allocated 'empty' number |
| 945 | |
| 946 | // Copy the double value to the new heap number, flipping the sign. |
| 947 | __ movq(rdx, FieldOperand(rax, HeapNumber::kValueOffset)); |
| 948 | __ Set(kScratchRegister, 0x01); |
| 949 | __ shl(kScratchRegister, Immediate(63)); |
| 950 | __ xor_(rdx, kScratchRegister); // Flip sign. |
| 951 | __ movq(FieldOperand(rcx, HeapNumber::kValueOffset), rdx); |
| 952 | __ movq(rax, rcx); |
| 953 | } |
| 954 | __ ret(0); |
| 955 | } |
| 956 | |
| 957 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 958 | void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm, |
| 959 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 960 | // Check if the operand is a heap number. |
| 961 | __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset), |
| 962 | Heap::kHeapNumberMapRootIndex); |
| 963 | __ j(not_equal, slow); |
| 964 | |
| 965 | // Convert the heap number in rax to an untagged integer in rcx. |
| 966 | IntegerConvert(masm, rax, rax); |
| 967 | |
| 968 | // Do the bitwise operation and smi tag the result. |
| 969 | __ notl(rax); |
| 970 | __ Integer32ToSmi(rax, rax); |
| 971 | __ ret(0); |
| 972 | } |
| 973 | |
| 974 | |
| 975 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 976 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 977 | switch (op_) { |
| 978 | case Token::SUB: |
| 979 | GenerateGenericStubSub(masm); |
| 980 | break; |
| 981 | case Token::BIT_NOT: |
| 982 | GenerateGenericStubBitNot(masm); |
| 983 | break; |
| 984 | default: |
| 985 | UNREACHABLE(); |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 990 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 991 | Label non_smi, slow; |
| 992 | GenerateSmiCodeSub(masm, &non_smi, &slow, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 993 | __ bind(&non_smi); |
| 994 | GenerateHeapNumberCodeSub(masm, &slow); |
| 995 | __ bind(&slow); |
| 996 | GenerateGenericCodeFallback(masm); |
| 997 | } |
| 998 | |
| 999 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1000 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1001 | Label non_smi, slow; |
| 1002 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1003 | __ bind(&non_smi); |
| 1004 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1005 | __ bind(&slow); |
| 1006 | GenerateGenericCodeFallback(masm); |
| 1007 | } |
| 1008 | |
| 1009 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1010 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1011 | // Handle the slow case by jumping to the JavaScript builtin. |
| 1012 | __ pop(rcx); // pop return address |
| 1013 | __ push(rax); |
| 1014 | __ push(rcx); // push return address |
| 1015 | switch (op_) { |
| 1016 | case Token::SUB: |
| 1017 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 1018 | break; |
| 1019 | case Token::BIT_NOT: |
| 1020 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 1021 | break; |
| 1022 | default: |
| 1023 | UNREACHABLE(); |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1028 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1029 | const char* op_name = Token::Name(op_); |
| 1030 | const char* overwrite_name = NULL; // Make g++ happy. |
| 1031 | switch (mode_) { |
| 1032 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 1033 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 1034 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1035 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 1036 | op_name, |
| 1037 | overwrite_name, |
| 1038 | UnaryOpIC::GetName(operand_type_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1042 | void BinaryOpStub::Initialize() {} |
| 1043 | |
| 1044 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1045 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1046 | __ pop(rcx); // Save return address. |
| 1047 | __ push(rdx); |
| 1048 | __ push(rax); |
| 1049 | // Left and right arguments are now on top. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1050 | __ Push(Smi::FromInt(MinorKey())); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1051 | |
| 1052 | __ push(rcx); // Push return address. |
| 1053 | |
| 1054 | // Patch the caller to an appropriate specialized stub and return the |
| 1055 | // operation result to the caller of the stub. |
| 1056 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1057 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1058 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1059 | 3, |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1060 | 1); |
| 1061 | } |
| 1062 | |
| 1063 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1064 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1065 | MacroAssembler* masm, |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1066 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1067 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 1068 | Token::Value op) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1069 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1070 | // Arguments to BinaryOpStub are in rdx and rax. |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 1071 | const Register left = rdx; |
| 1072 | const Register right = rax; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1073 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1074 | // We only generate heapnumber answers for overflowing calculations |
| 1075 | // for the four basic arithmetic operations and logical right shift by 0. |
| 1076 | bool generate_inline_heapnumber_results = |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1077 | (allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS) && |
| 1078 | (op == Token::ADD || op == Token::SUB || |
| 1079 | op == Token::MUL || op == Token::DIV || op == Token::SHR); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1080 | |
| 1081 | // Smi check of both operands. If op is BIT_OR, the check is delayed |
| 1082 | // until after the OR operation. |
| 1083 | Label not_smis; |
| 1084 | Label use_fp_on_smis; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1085 | Label fail; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1086 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1087 | if (op != Token::BIT_OR) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1088 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 1089 | __ JumpIfNotBothSmi(left, right, ¬_smis); |
| 1090 | } |
| 1091 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1092 | Label smi_values; |
| 1093 | __ bind(&smi_values); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1094 | // Perform the operation. |
| 1095 | Comment perform_smi(masm, "-- Perform smi operation"); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1096 | switch (op) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1097 | case Token::ADD: |
| 1098 | ASSERT(right.is(rax)); |
| 1099 | __ SmiAdd(right, right, left, &use_fp_on_smis); // ADD is commutative. |
| 1100 | break; |
| 1101 | |
| 1102 | case Token::SUB: |
| 1103 | __ SmiSub(left, left, right, &use_fp_on_smis); |
| 1104 | __ movq(rax, left); |
| 1105 | break; |
| 1106 | |
| 1107 | case Token::MUL: |
| 1108 | ASSERT(right.is(rax)); |
| 1109 | __ SmiMul(right, right, left, &use_fp_on_smis); // MUL is commutative. |
| 1110 | break; |
| 1111 | |
| 1112 | case Token::DIV: |
| 1113 | // SmiDiv will not accept left in rdx or right in rax. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1114 | __ movq(rbx, rax); |
| 1115 | __ movq(rcx, rdx); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 1116 | __ SmiDiv(rax, rcx, rbx, &use_fp_on_smis); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1117 | break; |
| 1118 | |
| 1119 | case Token::MOD: |
| 1120 | // SmiMod will not accept left in rdx or right in rax. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1121 | __ movq(rbx, rax); |
| 1122 | __ movq(rcx, rdx); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 1123 | __ SmiMod(rax, rcx, rbx, &use_fp_on_smis); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1124 | break; |
| 1125 | |
| 1126 | case Token::BIT_OR: { |
| 1127 | ASSERT(right.is(rax)); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1128 | __ SmiOrIfSmis(right, right, left, ¬_smis); // BIT_OR is commutative. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1129 | break; |
| 1130 | } |
| 1131 | case Token::BIT_XOR: |
| 1132 | ASSERT(right.is(rax)); |
| 1133 | __ SmiXor(right, right, left); // BIT_XOR is commutative. |
| 1134 | break; |
| 1135 | |
| 1136 | case Token::BIT_AND: |
| 1137 | ASSERT(right.is(rax)); |
| 1138 | __ SmiAnd(right, right, left); // BIT_AND is commutative. |
| 1139 | break; |
| 1140 | |
| 1141 | case Token::SHL: |
| 1142 | __ SmiShiftLeft(left, left, right); |
| 1143 | __ movq(rax, left); |
| 1144 | break; |
| 1145 | |
| 1146 | case Token::SAR: |
| 1147 | __ SmiShiftArithmeticRight(left, left, right); |
| 1148 | __ movq(rax, left); |
| 1149 | break; |
| 1150 | |
| 1151 | case Token::SHR: |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1152 | __ SmiShiftLogicalRight(left, left, right, &use_fp_on_smis); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1153 | __ movq(rax, left); |
| 1154 | break; |
| 1155 | |
| 1156 | default: |
| 1157 | UNREACHABLE(); |
| 1158 | } |
| 1159 | |
| 1160 | // 5. Emit return of result in rax. Some operations have registers pushed. |
| 1161 | __ ret(0); |
| 1162 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1163 | if (use_fp_on_smis.is_linked()) { |
| 1164 | // 6. For some operations emit inline code to perform floating point |
| 1165 | // operations on known smis (e.g., if the result of the operation |
| 1166 | // overflowed the smi range). |
| 1167 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1168 | if (op == Token::DIV || op == Token::MOD) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1169 | // Restore left and right to rdx and rax. |
| 1170 | __ movq(rdx, rcx); |
| 1171 | __ movq(rax, rbx); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1172 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1173 | |
| 1174 | if (generate_inline_heapnumber_results) { |
| 1175 | __ AllocateHeapNumber(rcx, rbx, slow); |
| 1176 | Comment perform_float(masm, "-- Perform float operation on smis"); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1177 | if (op == Token::SHR) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1178 | __ SmiToInteger32(left, left); |
| 1179 | __ cvtqsi2sd(xmm0, left); |
| 1180 | } else { |
| 1181 | FloatingPointHelper::LoadSSE2SmiOperands(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1182 | switch (op) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1183 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1184 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1185 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1186 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1187 | default: UNREACHABLE(); |
| 1188 | } |
| 1189 | } |
| 1190 | __ movsd(FieldOperand(rcx, HeapNumber::kValueOffset), xmm0); |
| 1191 | __ movq(rax, rcx); |
| 1192 | __ ret(0); |
| 1193 | } else { |
| 1194 | __ jmp(&fail); |
| 1195 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | // 7. Non-smi operands reach the end of the code generated by |
| 1199 | // GenerateSmiCode, and fall through to subsequent code, |
| 1200 | // with the operands in rdx and rax. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1201 | // But first we check if non-smi values are HeapNumbers holding |
| 1202 | // values that could be smi. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1203 | __ bind(¬_smis); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1204 | Comment done_comment(masm, "-- Enter non-smi code"); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1205 | FloatingPointHelper::ConvertUndefined convert_undefined = |
| 1206 | FloatingPointHelper::BAILOUT_ON_UNDEFINED; |
| 1207 | // This list must be in sync with BinaryOpPatch() behavior in ic.cc. |
| 1208 | if (op == Token::BIT_AND || |
| 1209 | op == Token::BIT_OR || |
| 1210 | op == Token::BIT_XOR || |
| 1211 | op == Token::SAR || |
| 1212 | op == Token::SHL || |
| 1213 | op == Token::SHR) { |
| 1214 | convert_undefined = FloatingPointHelper::CONVERT_UNDEFINED_TO_ZERO; |
| 1215 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1216 | FloatingPointHelper::NumbersToSmis(masm, left, right, rbx, rdi, rcx, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1217 | &smi_values, &fail, convert_undefined); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1218 | __ jmp(&smi_values); |
| 1219 | __ bind(&fail); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1223 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1224 | Label* alloc_failure, |
| 1225 | OverwriteMode mode); |
| 1226 | |
| 1227 | |
| 1228 | static void BinaryOpStub_GenerateFloatingPointCode(MacroAssembler* masm, |
| 1229 | Label* allocation_failure, |
| 1230 | Label* non_numeric_failure, |
| 1231 | Token::Value op, |
| 1232 | OverwriteMode mode) { |
| 1233 | switch (op) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1234 | case Token::ADD: |
| 1235 | case Token::SUB: |
| 1236 | case Token::MUL: |
| 1237 | case Token::DIV: { |
| 1238 | FloatingPointHelper::LoadSSE2UnknownOperands(masm, non_numeric_failure); |
| 1239 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1240 | switch (op) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1241 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1242 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1243 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1244 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1245 | default: UNREACHABLE(); |
| 1246 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1247 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1248 | masm, allocation_failure, mode); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1249 | __ movsd(FieldOperand(rax, HeapNumber::kValueOffset), xmm0); |
| 1250 | __ ret(0); |
| 1251 | break; |
| 1252 | } |
| 1253 | case Token::MOD: { |
| 1254 | // For MOD we jump to the allocation_failure label, to call runtime. |
| 1255 | __ jmp(allocation_failure); |
| 1256 | break; |
| 1257 | } |
| 1258 | case Token::BIT_OR: |
| 1259 | case Token::BIT_AND: |
| 1260 | case Token::BIT_XOR: |
| 1261 | case Token::SAR: |
| 1262 | case Token::SHL: |
| 1263 | case Token::SHR: { |
| 1264 | Label non_smi_shr_result; |
| 1265 | Register heap_number_map = r9; |
| 1266 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 1267 | FloatingPointHelper::LoadAsIntegers(masm, non_numeric_failure, |
| 1268 | heap_number_map); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1269 | switch (op) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1270 | case Token::BIT_OR: __ orl(rax, rcx); break; |
| 1271 | case Token::BIT_AND: __ andl(rax, rcx); break; |
| 1272 | case Token::BIT_XOR: __ xorl(rax, rcx); break; |
| 1273 | case Token::SAR: __ sarl_cl(rax); break; |
| 1274 | case Token::SHL: __ shll_cl(rax); break; |
| 1275 | case Token::SHR: { |
| 1276 | __ shrl_cl(rax); |
| 1277 | // Check if result is negative. This can only happen for a shift |
| 1278 | // by zero. |
| 1279 | __ testl(rax, rax); |
| 1280 | __ j(negative, &non_smi_shr_result); |
| 1281 | break; |
| 1282 | } |
| 1283 | default: UNREACHABLE(); |
| 1284 | } |
| 1285 | STATIC_ASSERT(kSmiValueSize == 32); |
| 1286 | // Tag smi result and return. |
| 1287 | __ Integer32ToSmi(rax, rax); |
| 1288 | __ Ret(); |
| 1289 | |
| 1290 | // Logical shift right can produce an unsigned int32 that is not |
| 1291 | // an int32, and so is not in the smi range. Allocate a heap number |
| 1292 | // in that case. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1293 | if (op == Token::SHR) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1294 | __ bind(&non_smi_shr_result); |
| 1295 | Label allocation_failed; |
| 1296 | __ movl(rbx, rax); // rbx holds result value (uint32 value as int64). |
| 1297 | // Allocate heap number in new space. |
| 1298 | // Not using AllocateHeapNumber macro in order to reuse |
| 1299 | // already loaded heap_number_map. |
| 1300 | __ AllocateInNewSpace(HeapNumber::kSize, |
| 1301 | rax, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1302 | rdx, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1303 | no_reg, |
| 1304 | &allocation_failed, |
| 1305 | TAG_OBJECT); |
| 1306 | // Set the map. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1307 | __ AssertRootValue(heap_number_map, |
| 1308 | Heap::kHeapNumberMapRootIndex, |
| 1309 | "HeapNumberMap register clobbered."); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1310 | __ movq(FieldOperand(rax, HeapObject::kMapOffset), |
| 1311 | heap_number_map); |
| 1312 | __ cvtqsi2sd(xmm0, rbx); |
| 1313 | __ movsd(FieldOperand(rax, HeapNumber::kValueOffset), xmm0); |
| 1314 | __ Ret(); |
| 1315 | |
| 1316 | __ bind(&allocation_failed); |
| 1317 | // We need tagged values in rdx and rax for the following code, |
| 1318 | // not int32 in rax and rcx. |
| 1319 | __ Integer32ToSmi(rax, rcx); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1320 | __ Integer32ToSmi(rdx, rbx); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1321 | __ jmp(allocation_failure); |
| 1322 | } |
| 1323 | break; |
| 1324 | } |
| 1325 | default: UNREACHABLE(); break; |
| 1326 | } |
| 1327 | // No fall-through from this generated code. |
| 1328 | if (FLAG_debug_code) { |
| 1329 | __ Abort("Unexpected fall-through in " |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1330 | "BinaryStub_GenerateFloatingPointCode."); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1335 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1336 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1337 | Label left_not_string, call_runtime; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1338 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1339 | // Registers containing left and right operands respectively. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1340 | Register left = rdx; |
| 1341 | Register right = rax; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1342 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1343 | // Test if left operand is a string. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1344 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1345 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, rcx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1346 | __ j(above_equal, &left_not_string, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1347 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 1348 | GenerateRegisterArgsPush(masm); |
| 1349 | __ TailCallStub(&string_add_left_stub); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1350 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1351 | // Left operand is not a string, test right. |
| 1352 | __ bind(&left_not_string); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1353 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1354 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, rcx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1355 | __ j(above_equal, &call_runtime, Label::kNear); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1356 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1357 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
| 1358 | GenerateRegisterArgsPush(masm); |
| 1359 | __ TailCallStub(&string_add_right_stub); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1360 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1361 | // Neither argument is a string. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1362 | __ bind(&call_runtime); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1366 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1367 | Label call_runtime; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1368 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1369 | result_type_ == BinaryOpIC::SMI) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1370 | // Only allow smi results. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1371 | BinaryOpStub_GenerateSmiCode(masm, NULL, NO_HEAPNUMBER_RESULTS, op_); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1372 | } else { |
| 1373 | // Allow heap number result and don't make a transition if a heap number |
| 1374 | // cannot be allocated. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1375 | BinaryOpStub_GenerateSmiCode( |
| 1376 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1377 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1378 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1379 | // Code falls through if the result is not returned as either a smi or heap |
| 1380 | // number. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1381 | GenerateTypeTransition(masm); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1382 | |
| 1383 | if (call_runtime.is_linked()) { |
| 1384 | __ bind(&call_runtime); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1385 | GenerateRegisterArgsPush(masm); |
| 1386 | GenerateCallRuntime(masm); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1387 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1391 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
| 1392 | // The int32 case is identical to the Smi case. We avoid creating this |
| 1393 | // ic state on x64. |
| 1394 | UNREACHABLE(); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1398 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1399 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1400 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1401 | ASSERT(op_ == Token::ADD); |
| 1402 | // If both arguments are strings, call the string add stub. |
| 1403 | // Otherwise, do a transition. |
| 1404 | |
| 1405 | // Registers containing left and right operands respectively. |
| 1406 | Register left = rdx; |
| 1407 | Register right = rax; |
| 1408 | |
| 1409 | // Test if left operand is a string. |
| 1410 | __ JumpIfSmi(left, &call_runtime); |
| 1411 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, rcx); |
| 1412 | __ j(above_equal, &call_runtime); |
| 1413 | |
| 1414 | // Test if right operand is a string. |
| 1415 | __ JumpIfSmi(right, &call_runtime); |
| 1416 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, rcx); |
| 1417 | __ j(above_equal, &call_runtime); |
| 1418 | |
| 1419 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 1420 | GenerateRegisterArgsPush(masm); |
| 1421 | __ TailCallStub(&string_add_stub); |
| 1422 | |
| 1423 | __ bind(&call_runtime); |
| 1424 | GenerateTypeTransition(masm); |
| 1425 | } |
| 1426 | |
| 1427 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1428 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1429 | Label call_runtime; |
| 1430 | |
| 1431 | if (op_ == Token::ADD) { |
| 1432 | // Handle string addition here, because it is the only operation |
| 1433 | // that does not do a ToNumber conversion on the operands. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1434 | GenerateAddStrings(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | // Convert oddball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1438 | Label check, done; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1439 | __ CompareRoot(rdx, Heap::kUndefinedValueRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1440 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1441 | if (Token::IsBitOp(op_)) { |
| 1442 | __ xor_(rdx, rdx); |
| 1443 | } else { |
| 1444 | __ LoadRoot(rdx, Heap::kNanValueRootIndex); |
| 1445 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1446 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1447 | __ bind(&check); |
| 1448 | __ CompareRoot(rax, Heap::kUndefinedValueRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1449 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1450 | if (Token::IsBitOp(op_)) { |
| 1451 | __ xor_(rax, rax); |
| 1452 | } else { |
| 1453 | __ LoadRoot(rax, Heap::kNanValueRootIndex); |
| 1454 | } |
| 1455 | __ bind(&done); |
| 1456 | |
| 1457 | GenerateHeapNumberStub(masm); |
| 1458 | } |
| 1459 | |
| 1460 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1461 | static void BinaryOpStub_CheckSmiInput(MacroAssembler* masm, |
| 1462 | Register input, |
| 1463 | Label* fail) { |
| 1464 | Label ok; |
| 1465 | __ JumpIfSmi(input, &ok, Label::kNear); |
| 1466 | Register heap_number_map = r8; |
| 1467 | Register scratch1 = r9; |
| 1468 | Register scratch2 = r10; |
| 1469 | // HeapNumbers containing 32bit integer values are also allowed. |
| 1470 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 1471 | __ cmpq(FieldOperand(input, HeapObject::kMapOffset), heap_number_map); |
| 1472 | __ j(not_equal, fail); |
| 1473 | __ movsd(xmm0, FieldOperand(input, HeapNumber::kValueOffset)); |
| 1474 | // Convert, convert back, and compare the two doubles' bits. |
| 1475 | __ cvttsd2siq(scratch2, xmm0); |
| 1476 | __ cvtlsi2sd(xmm1, scratch2); |
| 1477 | __ movq(scratch1, xmm0); |
| 1478 | __ movq(scratch2, xmm1); |
| 1479 | __ cmpq(scratch1, scratch2); |
| 1480 | __ j(not_equal, fail); |
| 1481 | __ bind(&ok); |
| 1482 | } |
| 1483 | |
| 1484 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1485 | void BinaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1486 | Label gc_required, not_number; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1487 | |
| 1488 | // It could be that only SMIs have been seen at either the left |
| 1489 | // or the right operand. For precise type feedback, patch the IC |
| 1490 | // again if this changes. |
| 1491 | if (left_type_ == BinaryOpIC::SMI) { |
| 1492 | BinaryOpStub_CheckSmiInput(masm, rdx, ¬_number); |
| 1493 | } |
| 1494 | if (right_type_ == BinaryOpIC::SMI) { |
| 1495 | BinaryOpStub_CheckSmiInput(masm, rax, ¬_number); |
| 1496 | } |
| 1497 | |
| 1498 | BinaryOpStub_GenerateFloatingPointCode( |
| 1499 | masm, &gc_required, ¬_number, op_, mode_); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1500 | |
| 1501 | __ bind(¬_number); |
| 1502 | GenerateTypeTransition(masm); |
| 1503 | |
| 1504 | __ bind(&gc_required); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1505 | GenerateRegisterArgsPush(masm); |
| 1506 | GenerateCallRuntime(masm); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1510 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1511 | Label call_runtime, call_string_add_or_runtime; |
| 1512 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1513 | BinaryOpStub_GenerateSmiCode( |
| 1514 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1515 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1516 | BinaryOpStub_GenerateFloatingPointCode( |
| 1517 | masm, &call_runtime, &call_string_add_or_runtime, op_, mode_); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1518 | |
| 1519 | __ bind(&call_string_add_or_runtime); |
| 1520 | if (op_ == Token::ADD) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1521 | GenerateAddStrings(masm); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | __ bind(&call_runtime); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1525 | GenerateRegisterArgsPush(masm); |
| 1526 | GenerateCallRuntime(masm); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1530 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1531 | Label* alloc_failure, |
| 1532 | OverwriteMode mode) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1533 | Label skip_allocation; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1534 | switch (mode) { |
| 1535 | case OVERWRITE_LEFT: { |
| 1536 | // If the argument in rdx is already an object, we skip the |
| 1537 | // allocation of a heap number. |
| 1538 | __ JumpIfNotSmi(rdx, &skip_allocation); |
| 1539 | // Allocate a heap number for the result. Keep eax and edx intact |
| 1540 | // for the possible runtime call. |
| 1541 | __ AllocateHeapNumber(rbx, rcx, alloc_failure); |
| 1542 | // Now rdx can be overwritten losing one of the arguments as we are |
| 1543 | // now done and will not need it any more. |
| 1544 | __ movq(rdx, rbx); |
| 1545 | __ bind(&skip_allocation); |
| 1546 | // Use object in rdx as a result holder |
| 1547 | __ movq(rax, rdx); |
| 1548 | break; |
| 1549 | } |
| 1550 | case OVERWRITE_RIGHT: |
| 1551 | // If the argument in rax is already an object, we skip the |
| 1552 | // allocation of a heap number. |
| 1553 | __ JumpIfNotSmi(rax, &skip_allocation); |
| 1554 | // Fall through! |
| 1555 | case NO_OVERWRITE: |
| 1556 | // Allocate a heap number for the result. Keep rax and rdx intact |
| 1557 | // for the possible runtime call. |
| 1558 | __ AllocateHeapNumber(rbx, rcx, alloc_failure); |
| 1559 | // Now rax can be overwritten losing one of the arguments as we are |
| 1560 | // now done and will not need it any more. |
| 1561 | __ movq(rax, rbx); |
| 1562 | __ bind(&skip_allocation); |
| 1563 | break; |
| 1564 | default: UNREACHABLE(); |
| 1565 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1569 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1570 | __ pop(rcx); |
| 1571 | __ push(rdx); |
| 1572 | __ push(rax); |
| 1573 | __ push(rcx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1577 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1578 | // TAGGED case: |
| 1579 | // Input: |
| 1580 | // rsp[8]: argument (should be number). |
| 1581 | // rsp[0]: return address. |
| 1582 | // Output: |
| 1583 | // rax: tagged double result. |
| 1584 | // UNTAGGED case: |
| 1585 | // Input:: |
| 1586 | // rsp[0]: return address. |
| 1587 | // xmm1: untagged double input argument |
| 1588 | // Output: |
| 1589 | // xmm1: untagged double result. |
| 1590 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1591 | Label runtime_call; |
| 1592 | Label runtime_call_clear_stack; |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1593 | Label skip_cache; |
| 1594 | const bool tagged = (argument_type_ == TAGGED); |
| 1595 | if (tagged) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1596 | Label input_not_smi, loaded; |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1597 | // Test that rax is a number. |
| 1598 | __ movq(rax, Operand(rsp, kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1599 | __ JumpIfNotSmi(rax, &input_not_smi, Label::kNear); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1600 | // Input is a smi. Untag and load it onto the FPU stack. |
| 1601 | // Then load the bits of the double into rbx. |
| 1602 | __ SmiToInteger32(rax, rax); |
| 1603 | __ subq(rsp, Immediate(kDoubleSize)); |
| 1604 | __ cvtlsi2sd(xmm1, rax); |
| 1605 | __ movsd(Operand(rsp, 0), xmm1); |
| 1606 | __ movq(rbx, xmm1); |
| 1607 | __ movq(rdx, xmm1); |
| 1608 | __ fld_d(Operand(rsp, 0)); |
| 1609 | __ addq(rsp, Immediate(kDoubleSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1610 | __ jmp(&loaded, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1611 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1612 | __ bind(&input_not_smi); |
| 1613 | // Check if input is a HeapNumber. |
| 1614 | __ LoadRoot(rbx, Heap::kHeapNumberMapRootIndex); |
| 1615 | __ cmpq(rbx, FieldOperand(rax, HeapObject::kMapOffset)); |
| 1616 | __ j(not_equal, &runtime_call); |
| 1617 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 1618 | // bits into rbx. |
| 1619 | __ fld_d(FieldOperand(rax, HeapNumber::kValueOffset)); |
| 1620 | __ movq(rbx, FieldOperand(rax, HeapNumber::kValueOffset)); |
| 1621 | __ movq(rdx, rbx); |
| 1622 | |
| 1623 | __ bind(&loaded); |
| 1624 | } else { // UNTAGGED. |
| 1625 | __ movq(rbx, xmm1); |
| 1626 | __ movq(rdx, xmm1); |
| 1627 | } |
| 1628 | |
| 1629 | // ST[0] == double value, if TAGGED. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1630 | // rbx = bits of double value. |
| 1631 | // rdx = also bits of double value. |
| 1632 | // Compute hash (h is 32 bits, bits are 64 and the shifts are arithmetic): |
| 1633 | // h = h0 = bits ^ (bits >> 32); |
| 1634 | // h ^= h >> 16; |
| 1635 | // h ^= h >> 8; |
| 1636 | // h = h & (cacheSize - 1); |
| 1637 | // or h = (h0 ^ (h0 >> 8) ^ (h0 >> 16) ^ (h0 >> 24)) & (cacheSize - 1) |
| 1638 | __ sar(rdx, Immediate(32)); |
| 1639 | __ xorl(rdx, rbx); |
| 1640 | __ movl(rcx, rdx); |
| 1641 | __ movl(rax, rdx); |
| 1642 | __ movl(rdi, rdx); |
| 1643 | __ sarl(rdx, Immediate(8)); |
| 1644 | __ sarl(rcx, Immediate(16)); |
| 1645 | __ sarl(rax, Immediate(24)); |
| 1646 | __ xorl(rcx, rdx); |
| 1647 | __ xorl(rax, rdi); |
| 1648 | __ xorl(rcx, rax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1649 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
| 1650 | __ andl(rcx, Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1651 | |
| 1652 | // ST[0] == double value. |
| 1653 | // rbx = bits of double value. |
| 1654 | // rcx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1655 | ExternalReference cache_array = |
| 1656 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 1657 | __ movq(rax, cache_array); |
| 1658 | int cache_array_index = |
| 1659 | type_ * sizeof(Isolate::Current()->transcendental_cache()->caches_[0]); |
| 1660 | __ movq(rax, Operand(rax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1661 | // rax points to the cache for the type type_. |
| 1662 | // If NULL, the cache hasn't been initialized yet, so go through runtime. |
| 1663 | __ testq(rax, rax); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1664 | __ j(zero, &runtime_call_clear_stack); // Only clears stack if TAGGED. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1665 | #ifdef DEBUG |
| 1666 | // Check that the layout of cache elements match expectations. |
| 1667 | { // NOLINT - doesn't like a single brace on a line. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1668 | TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1669 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 1670 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 1671 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 1672 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 1673 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 1674 | // Two uint_32's and a pointer per element. |
| 1675 | CHECK_EQ(16, static_cast<int>(elem2_start - elem_start)); |
| 1676 | CHECK_EQ(0, static_cast<int>(elem_in0 - elem_start)); |
| 1677 | CHECK_EQ(kIntSize, static_cast<int>(elem_in1 - elem_start)); |
| 1678 | CHECK_EQ(2 * kIntSize, static_cast<int>(elem_out - elem_start)); |
| 1679 | } |
| 1680 | #endif |
| 1681 | // Find the address of the rcx'th entry in the cache, i.e., &rax[rcx*16]. |
| 1682 | __ addl(rcx, rcx); |
| 1683 | __ lea(rcx, Operand(rax, rcx, times_8, 0)); |
| 1684 | // 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] | 1685 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1686 | __ cmpq(rbx, Operand(rcx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1687 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1688 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1689 | Counters* counters = masm->isolate()->counters(); |
| 1690 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1691 | __ movq(rax, Operand(rcx, 2 * kIntSize)); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1692 | if (tagged) { |
| 1693 | __ fstp(0); // Clear FPU stack. |
| 1694 | __ ret(kPointerSize); |
| 1695 | } else { // UNTAGGED. |
| 1696 | __ movsd(xmm1, FieldOperand(rax, HeapNumber::kValueOffset)); |
| 1697 | __ Ret(); |
| 1698 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1699 | |
| 1700 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1701 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1702 | // Update cache with new value. |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1703 | if (tagged) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1704 | __ AllocateHeapNumber(rax, rdi, &runtime_call_clear_stack); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1705 | } else { // UNTAGGED. |
| 1706 | __ AllocateHeapNumber(rax, rdi, &skip_cache); |
| 1707 | __ movsd(FieldOperand(rax, HeapNumber::kValueOffset), xmm1); |
| 1708 | __ fld_d(FieldOperand(rax, HeapNumber::kValueOffset)); |
| 1709 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1710 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1711 | __ movq(Operand(rcx, 0), rbx); |
| 1712 | __ movq(Operand(rcx, 2 * kIntSize), rax); |
| 1713 | __ fstp_d(FieldOperand(rax, HeapNumber::kValueOffset)); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1714 | if (tagged) { |
| 1715 | __ ret(kPointerSize); |
| 1716 | } else { // UNTAGGED. |
| 1717 | __ movsd(xmm1, FieldOperand(rax, HeapNumber::kValueOffset)); |
| 1718 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1719 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1720 | // Skip cache and return answer directly, only in untagged case. |
| 1721 | __ bind(&skip_cache); |
| 1722 | __ subq(rsp, Immediate(kDoubleSize)); |
| 1723 | __ movsd(Operand(rsp, 0), xmm1); |
| 1724 | __ fld_d(Operand(rsp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1725 | GenerateOperation(masm, type_); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1726 | __ fstp_d(Operand(rsp, 0)); |
| 1727 | __ movsd(xmm1, Operand(rsp, 0)); |
| 1728 | __ addq(rsp, Immediate(kDoubleSize)); |
| 1729 | // We return the value in xmm1 without adding it to the cache, but |
| 1730 | // 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] | 1731 | { |
| 1732 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1733 | // Allocate an unused object bigger than a HeapNumber. |
| 1734 | __ Push(Smi::FromInt(2 * kDoubleSize)); |
| 1735 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 1736 | } |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1737 | __ Ret(); |
| 1738 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1739 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1740 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 1741 | if (tagged) { |
| 1742 | __ bind(&runtime_call_clear_stack); |
| 1743 | __ fstp(0); |
| 1744 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1745 | __ TailCallExternalReference( |
| 1746 | ExternalReference(RuntimeFunction(), masm->isolate()), 1, 1); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1747 | } else { // UNTAGGED. |
| 1748 | __ bind(&runtime_call_clear_stack); |
| 1749 | __ bind(&runtime_call); |
| 1750 | __ AllocateHeapNumber(rax, rdi, &skip_cache); |
| 1751 | __ movsd(FieldOperand(rax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1752 | { |
| 1753 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1754 | __ push(rax); |
| 1755 | __ CallRuntime(RuntimeFunction(), 1); |
| 1756 | } |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1757 | __ movsd(xmm1, FieldOperand(rax, HeapNumber::kValueOffset)); |
| 1758 | __ Ret(); |
| 1759 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | |
| 1763 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 1764 | switch (type_) { |
| 1765 | // Add more cases when necessary. |
| 1766 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 1767 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1768 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1769 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1770 | default: |
| 1771 | UNIMPLEMENTED(); |
| 1772 | return Runtime::kAbort; |
| 1773 | } |
| 1774 | } |
| 1775 | |
| 1776 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1777 | void TranscendentalCacheStub::GenerateOperation( |
| 1778 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1779 | // Registers: |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1780 | // rax: Newly allocated HeapNumber, which must be preserved. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1781 | // rbx: Bits of input double. Must be preserved. |
| 1782 | // rcx: Pointer to cache entry. Must be preserved. |
| 1783 | // st(0): Input double |
| 1784 | Label done; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1785 | if (type == TranscendentalCache::SIN || |
| 1786 | type == TranscendentalCache::COS || |
| 1787 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1788 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 1789 | // return NaN for infinities and NaN. They can share all code except |
| 1790 | // the actual fsin/fcos operation. |
| 1791 | Label in_range; |
| 1792 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 1793 | // work. We must reduce it to the appropriate range. |
| 1794 | __ movq(rdi, rbx); |
| 1795 | // Move exponent and sign bits to low bits. |
| 1796 | __ shr(rdi, Immediate(HeapNumber::kMantissaBits)); |
| 1797 | // Remove sign bit. |
| 1798 | __ andl(rdi, Immediate((1 << HeapNumber::kExponentBits) - 1)); |
| 1799 | int supported_exponent_limit = (63 + HeapNumber::kExponentBias); |
| 1800 | __ cmpl(rdi, Immediate(supported_exponent_limit)); |
| 1801 | __ j(below, &in_range); |
| 1802 | // Check for infinity and NaN. Both return NaN for sin. |
| 1803 | __ cmpl(rdi, Immediate(0x7ff)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1804 | Label non_nan_result; |
| 1805 | __ j(not_equal, &non_nan_result, Label::kNear); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1806 | // Input is +/-Infinity or NaN. Result is NaN. |
| 1807 | __ fstp(0); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1808 | // NaN is represented by 0x7ff8000000000000. |
| 1809 | __ subq(rsp, Immediate(kPointerSize)); |
| 1810 | __ movl(Operand(rsp, 4), Immediate(0x7ff80000)); |
| 1811 | __ movl(Operand(rsp, 0), Immediate(0x00000000)); |
| 1812 | __ fld_d(Operand(rsp, 0)); |
| 1813 | __ addq(rsp, Immediate(kPointerSize)); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1814 | __ jmp(&done); |
| 1815 | |
| 1816 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1817 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1818 | // Use fpmod to restrict argument to the range +/-2*PI. |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1819 | __ movq(rdi, rax); // Save rax before using fnstsw_ax. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1820 | __ fldpi(); |
| 1821 | __ fadd(0); |
| 1822 | __ fld(1); |
| 1823 | // FPU Stack: input, 2*pi, input. |
| 1824 | { |
| 1825 | Label no_exceptions; |
| 1826 | __ fwait(); |
| 1827 | __ fnstsw_ax(); |
| 1828 | // Clear if Illegal Operand or Zero Division exceptions are set. |
| 1829 | __ testl(rax, Immediate(5)); // #IO and #ZD flags of FPU status word. |
| 1830 | __ j(zero, &no_exceptions); |
| 1831 | __ fnclex(); |
| 1832 | __ bind(&no_exceptions); |
| 1833 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1834 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1835 | // Compute st(0) % st(1) |
| 1836 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1837 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1838 | __ bind(&partial_remainder_loop); |
| 1839 | __ fprem1(); |
| 1840 | __ fwait(); |
| 1841 | __ fnstsw_ax(); |
| 1842 | __ testl(rax, Immediate(0x400)); // Check C2 bit of FPU status word. |
| 1843 | // If C2 is set, computation only has partial result. Loop to |
| 1844 | // continue computation. |
| 1845 | __ j(not_zero, &partial_remainder_loop); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1846 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1847 | // FPU Stack: input, 2*pi, input % 2*pi |
| 1848 | __ fstp(2); |
| 1849 | // FPU Stack: input % 2*pi, 2*pi, |
| 1850 | __ fstp(0); |
| 1851 | // FPU Stack: input % 2*pi |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1852 | __ movq(rax, rdi); // Restore rax, pointer to the new HeapNumber. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1853 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1854 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1855 | case TranscendentalCache::SIN: |
| 1856 | __ fsin(); |
| 1857 | break; |
| 1858 | case TranscendentalCache::COS: |
| 1859 | __ fcos(); |
| 1860 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1861 | case TranscendentalCache::TAN: |
| 1862 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 1863 | // FP register stack. |
| 1864 | __ fptan(); |
| 1865 | __ fstp(0); // Pop FP register stack. |
| 1866 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1867 | default: |
| 1868 | UNREACHABLE(); |
| 1869 | } |
| 1870 | __ bind(&done); |
| 1871 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1872 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1873 | __ fldln2(); |
| 1874 | __ fxch(); |
| 1875 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1876 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1877 | } |
| 1878 | |
| 1879 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1880 | // Input: rdx, rax are the left and right objects of a bit op. |
| 1881 | // Output: rax, rcx are left and right integers for a bit op. |
| 1882 | void FloatingPointHelper::LoadNumbersAsIntegers(MacroAssembler* masm) { |
| 1883 | // Check float operands. |
| 1884 | Label done; |
| 1885 | Label rax_is_smi; |
| 1886 | Label rax_is_object; |
| 1887 | Label rdx_is_object; |
| 1888 | |
| 1889 | __ JumpIfNotSmi(rdx, &rdx_is_object); |
| 1890 | __ SmiToInteger32(rdx, rdx); |
| 1891 | __ JumpIfSmi(rax, &rax_is_smi); |
| 1892 | |
| 1893 | __ bind(&rax_is_object); |
| 1894 | IntegerConvert(masm, rcx, rax); // Uses rdi, rcx and rbx. |
| 1895 | __ jmp(&done); |
| 1896 | |
| 1897 | __ bind(&rdx_is_object); |
| 1898 | IntegerConvert(masm, rdx, rdx); // Uses rdi, rcx and rbx. |
| 1899 | __ JumpIfNotSmi(rax, &rax_is_object); |
| 1900 | __ bind(&rax_is_smi); |
| 1901 | __ SmiToInteger32(rcx, rax); |
| 1902 | |
| 1903 | __ bind(&done); |
| 1904 | __ movl(rax, rdx); |
| 1905 | } |
| 1906 | |
| 1907 | |
| 1908 | // Input: rdx, rax are the left and right objects of a bit op. |
| 1909 | // Output: rax, rcx are left and right integers for a bit op. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1910 | // Jump to conversion_failure: rdx and rax are unchanged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1911 | void FloatingPointHelper::LoadAsIntegers(MacroAssembler* masm, |
| 1912 | Label* conversion_failure, |
| 1913 | Register heap_number_map) { |
| 1914 | // Check float operands. |
| 1915 | Label arg1_is_object, check_undefined_arg1; |
| 1916 | Label arg2_is_object, check_undefined_arg2; |
| 1917 | Label load_arg2, done; |
| 1918 | |
| 1919 | __ JumpIfNotSmi(rdx, &arg1_is_object); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1920 | __ SmiToInteger32(r8, rdx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1921 | __ jmp(&load_arg2); |
| 1922 | |
| 1923 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 1924 | __ bind(&check_undefined_arg1); |
| 1925 | __ CompareRoot(rdx, Heap::kUndefinedValueRootIndex); |
| 1926 | __ j(not_equal, conversion_failure); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 1927 | __ Set(r8, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1928 | __ jmp(&load_arg2); |
| 1929 | |
| 1930 | __ bind(&arg1_is_object); |
| 1931 | __ cmpq(FieldOperand(rdx, HeapObject::kMapOffset), heap_number_map); |
| 1932 | __ j(not_equal, &check_undefined_arg1); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1933 | // Get the untagged integer version of the rdx heap number in rcx. |
| 1934 | IntegerConvert(masm, r8, rdx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1935 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1936 | // Here r8 has the untagged integer, rax has a Smi or a heap number. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1937 | __ bind(&load_arg2); |
| 1938 | // Test if arg2 is a Smi. |
| 1939 | __ JumpIfNotSmi(rax, &arg2_is_object); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1940 | __ SmiToInteger32(rcx, rax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1941 | __ jmp(&done); |
| 1942 | |
| 1943 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 1944 | __ bind(&check_undefined_arg2); |
| 1945 | __ CompareRoot(rax, Heap::kUndefinedValueRootIndex); |
| 1946 | __ j(not_equal, conversion_failure); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 1947 | __ Set(rcx, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1948 | __ jmp(&done); |
| 1949 | |
| 1950 | __ bind(&arg2_is_object); |
| 1951 | __ cmpq(FieldOperand(rax, HeapObject::kMapOffset), heap_number_map); |
| 1952 | __ j(not_equal, &check_undefined_arg2); |
| 1953 | // Get the untagged integer version of the rax heap number in rcx. |
| 1954 | IntegerConvert(masm, rcx, rax); |
| 1955 | __ bind(&done); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1956 | __ movl(rax, r8); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | |
| 1960 | void FloatingPointHelper::LoadSSE2SmiOperands(MacroAssembler* masm) { |
| 1961 | __ SmiToInteger32(kScratchRegister, rdx); |
| 1962 | __ cvtlsi2sd(xmm0, kScratchRegister); |
| 1963 | __ SmiToInteger32(kScratchRegister, rax); |
| 1964 | __ cvtlsi2sd(xmm1, kScratchRegister); |
| 1965 | } |
| 1966 | |
| 1967 | |
| 1968 | void FloatingPointHelper::LoadSSE2NumberOperands(MacroAssembler* masm) { |
| 1969 | Label load_smi_rdx, load_nonsmi_rax, load_smi_rax, done; |
| 1970 | // Load operand in rdx into xmm0. |
| 1971 | __ JumpIfSmi(rdx, &load_smi_rdx); |
| 1972 | __ movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset)); |
| 1973 | // Load operand in rax into xmm1. |
| 1974 | __ JumpIfSmi(rax, &load_smi_rax); |
| 1975 | __ bind(&load_nonsmi_rax); |
| 1976 | __ movsd(xmm1, FieldOperand(rax, HeapNumber::kValueOffset)); |
| 1977 | __ jmp(&done); |
| 1978 | |
| 1979 | __ bind(&load_smi_rdx); |
| 1980 | __ SmiToInteger32(kScratchRegister, rdx); |
| 1981 | __ cvtlsi2sd(xmm0, kScratchRegister); |
| 1982 | __ JumpIfNotSmi(rax, &load_nonsmi_rax); |
| 1983 | |
| 1984 | __ bind(&load_smi_rax); |
| 1985 | __ SmiToInteger32(kScratchRegister, rax); |
| 1986 | __ cvtlsi2sd(xmm1, kScratchRegister); |
| 1987 | |
| 1988 | __ bind(&done); |
| 1989 | } |
| 1990 | |
| 1991 | |
| 1992 | void FloatingPointHelper::LoadSSE2UnknownOperands(MacroAssembler* masm, |
| 1993 | Label* not_numbers) { |
| 1994 | Label load_smi_rdx, load_nonsmi_rax, load_smi_rax, load_float_rax, done; |
| 1995 | // Load operand in rdx into xmm0, or branch to not_numbers. |
| 1996 | __ LoadRoot(rcx, Heap::kHeapNumberMapRootIndex); |
| 1997 | __ JumpIfSmi(rdx, &load_smi_rdx); |
| 1998 | __ cmpq(FieldOperand(rdx, HeapObject::kMapOffset), rcx); |
| 1999 | __ j(not_equal, not_numbers); // Argument in rdx is not a number. |
| 2000 | __ movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset)); |
| 2001 | // Load operand in rax into xmm1, or branch to not_numbers. |
| 2002 | __ JumpIfSmi(rax, &load_smi_rax); |
| 2003 | |
| 2004 | __ bind(&load_nonsmi_rax); |
| 2005 | __ cmpq(FieldOperand(rax, HeapObject::kMapOffset), rcx); |
| 2006 | __ j(not_equal, not_numbers); |
| 2007 | __ movsd(xmm1, FieldOperand(rax, HeapNumber::kValueOffset)); |
| 2008 | __ jmp(&done); |
| 2009 | |
| 2010 | __ bind(&load_smi_rdx); |
| 2011 | __ SmiToInteger32(kScratchRegister, rdx); |
| 2012 | __ cvtlsi2sd(xmm0, kScratchRegister); |
| 2013 | __ JumpIfNotSmi(rax, &load_nonsmi_rax); |
| 2014 | |
| 2015 | __ bind(&load_smi_rax); |
| 2016 | __ SmiToInteger32(kScratchRegister, rax); |
| 2017 | __ cvtlsi2sd(xmm1, kScratchRegister); |
| 2018 | __ bind(&done); |
| 2019 | } |
| 2020 | |
| 2021 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2022 | void FloatingPointHelper::NumbersToSmis(MacroAssembler* masm, |
| 2023 | Register first, |
| 2024 | Register second, |
| 2025 | Register scratch1, |
| 2026 | Register scratch2, |
| 2027 | Register scratch3, |
| 2028 | Label* on_success, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2029 | Label* on_not_smis, |
| 2030 | ConvertUndefined convert_undefined) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2031 | Register heap_number_map = scratch3; |
| 2032 | Register smi_result = scratch1; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2033 | Label done, maybe_undefined_first, maybe_undefined_second, first_done; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2034 | |
| 2035 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2036 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2037 | Label first_smi; |
| 2038 | __ JumpIfSmi(first, &first_smi, Label::kNear); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2039 | __ cmpq(FieldOperand(first, HeapObject::kMapOffset), heap_number_map); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2040 | __ j(not_equal, |
| 2041 | (convert_undefined == CONVERT_UNDEFINED_TO_ZERO) |
| 2042 | ? &maybe_undefined_first |
| 2043 | : on_not_smis); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2044 | // Convert HeapNumber to smi if possible. |
| 2045 | __ movsd(xmm0, FieldOperand(first, HeapNumber::kValueOffset)); |
| 2046 | __ movq(scratch2, xmm0); |
| 2047 | __ cvttsd2siq(smi_result, xmm0); |
| 2048 | // Check if conversion was successful by converting back and |
| 2049 | // comparing to the original double's bits. |
| 2050 | __ cvtlsi2sd(xmm1, smi_result); |
| 2051 | __ movq(kScratchRegister, xmm1); |
| 2052 | __ cmpq(scratch2, kScratchRegister); |
| 2053 | __ j(not_equal, on_not_smis); |
| 2054 | __ Integer32ToSmi(first, smi_result); |
| 2055 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2056 | __ bind(&first_done); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2057 | __ JumpIfSmi(second, (on_success != NULL) ? on_success : &done); |
| 2058 | __ bind(&first_smi); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2059 | __ AssertNotSmi(second); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2060 | __ cmpq(FieldOperand(second, HeapObject::kMapOffset), heap_number_map); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2061 | __ j(not_equal, |
| 2062 | (convert_undefined == CONVERT_UNDEFINED_TO_ZERO) |
| 2063 | ? &maybe_undefined_second |
| 2064 | : on_not_smis); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2065 | // Convert second to smi, if possible. |
| 2066 | __ movsd(xmm0, FieldOperand(second, HeapNumber::kValueOffset)); |
| 2067 | __ movq(scratch2, xmm0); |
| 2068 | __ cvttsd2siq(smi_result, xmm0); |
| 2069 | __ cvtlsi2sd(xmm1, smi_result); |
| 2070 | __ movq(kScratchRegister, xmm1); |
| 2071 | __ cmpq(scratch2, kScratchRegister); |
| 2072 | __ j(not_equal, on_not_smis); |
| 2073 | __ Integer32ToSmi(second, smi_result); |
| 2074 | if (on_success != NULL) { |
| 2075 | __ jmp(on_success); |
| 2076 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2077 | __ jmp(&done); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2078 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2079 | |
| 2080 | __ bind(&maybe_undefined_first); |
| 2081 | __ CompareRoot(first, Heap::kUndefinedValueRootIndex); |
| 2082 | __ j(not_equal, on_not_smis); |
| 2083 | __ xor_(first, first); |
| 2084 | __ jmp(&first_done); |
| 2085 | |
| 2086 | __ bind(&maybe_undefined_second); |
| 2087 | __ CompareRoot(second, Heap::kUndefinedValueRootIndex); |
| 2088 | __ j(not_equal, on_not_smis); |
| 2089 | __ xor_(second, second); |
| 2090 | if (on_success != NULL) { |
| 2091 | __ jmp(on_success); |
| 2092 | } |
| 2093 | // Else: fall through. |
| 2094 | |
| 2095 | __ bind(&done); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2099 | void MathPowStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2100 | // Choose register conforming to calling convention (when bailing out). |
| 2101 | #ifdef _WIN64 |
| 2102 | const Register exponent = rdx; |
| 2103 | #else |
| 2104 | const Register exponent = rdi; |
| 2105 | #endif |
| 2106 | const Register base = rax; |
| 2107 | const Register scratch = rcx; |
| 2108 | const XMMRegister double_result = xmm3; |
| 2109 | const XMMRegister double_base = xmm2; |
| 2110 | const XMMRegister double_exponent = xmm1; |
| 2111 | const XMMRegister double_scratch = xmm4; |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2112 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2113 | Label call_runtime, done, exponent_not_smi, int_exponent; |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2114 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2115 | // Save 1 in double_result - we need this several times later on. |
| 2116 | __ movq(scratch, Immediate(1)); |
| 2117 | __ cvtlsi2sd(double_result, scratch); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2118 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2119 | if (exponent_type_ == ON_STACK) { |
| 2120 | Label base_is_smi, unpack_exponent; |
| 2121 | // The exponent and base are supplied as arguments on the stack. |
| 2122 | // This can only happen if the stub is called from non-optimized code. |
| 2123 | // Load input parameters from stack. |
| 2124 | __ movq(base, Operand(rsp, 2 * kPointerSize)); |
| 2125 | __ movq(exponent, Operand(rsp, 1 * kPointerSize)); |
| 2126 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 2127 | __ CompareRoot(FieldOperand(base, HeapObject::kMapOffset), |
| 2128 | Heap::kHeapNumberMapRootIndex); |
| 2129 | __ j(not_equal, &call_runtime); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2130 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2131 | __ movsd(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 2132 | __ jmp(&unpack_exponent, Label::kNear); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2133 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2134 | __ bind(&base_is_smi); |
| 2135 | __ SmiToInteger32(base, base); |
| 2136 | __ cvtlsi2sd(double_base, base); |
| 2137 | __ bind(&unpack_exponent); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2138 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2139 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2140 | __ SmiToInteger32(exponent, exponent); |
| 2141 | __ jmp(&int_exponent); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2142 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2143 | __ bind(&exponent_not_smi); |
| 2144 | __ CompareRoot(FieldOperand(exponent, HeapObject::kMapOffset), |
| 2145 | Heap::kHeapNumberMapRootIndex); |
| 2146 | __ j(not_equal, &call_runtime); |
| 2147 | __ movsd(double_exponent, FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2148 | } else if (exponent_type_ == TAGGED) { |
| 2149 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2150 | __ SmiToInteger32(exponent, exponent); |
| 2151 | __ jmp(&int_exponent); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2152 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2153 | __ bind(&exponent_not_smi); |
| 2154 | __ movsd(double_exponent, FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2155 | } |
| 2156 | |
| 2157 | if (exponent_type_ != INTEGER) { |
| 2158 | Label fast_power; |
| 2159 | // Detect integer exponents stored as double. |
| 2160 | __ cvttsd2si(exponent, double_exponent); |
| 2161 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 2162 | __ cmpl(exponent, Immediate(0x80000000u)); |
| 2163 | __ j(equal, &call_runtime); |
| 2164 | __ cvtlsi2sd(double_scratch, exponent); |
| 2165 | // Already ruled out NaNs for exponent. |
| 2166 | __ ucomisd(double_exponent, double_scratch); |
| 2167 | __ j(equal, &int_exponent); |
| 2168 | |
| 2169 | if (exponent_type_ == ON_STACK) { |
| 2170 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 2171 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 2172 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 2173 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 2174 | // Test for 0.5. |
| 2175 | // Load double_scratch with 0.5. |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 2176 | __ movq(scratch, V8_UINT64_C(0x3FE0000000000000), RelocInfo::NONE64); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2177 | __ movq(double_scratch, scratch); |
| 2178 | // Already ruled out NaNs for exponent. |
| 2179 | __ ucomisd(double_scratch, double_exponent); |
| 2180 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 2181 | |
| 2182 | // Calculates square root of base. Check for the special case of |
| 2183 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 2184 | // According to IEEE-754, double-precision -Infinity has the highest |
| 2185 | // 12 bits set and the lowest 52 bits cleared. |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 2186 | __ movq(scratch, V8_UINT64_C(0xFFF0000000000000), RelocInfo::NONE64); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2187 | __ movq(double_scratch, scratch); |
| 2188 | __ ucomisd(double_scratch, double_base); |
| 2189 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 2190 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 2191 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 2192 | __ j(carry, &continue_sqrt, Label::kNear); |
| 2193 | |
| 2194 | // Set result to Infinity in the special case. |
| 2195 | __ xorps(double_result, double_result); |
| 2196 | __ subsd(double_result, double_scratch); |
| 2197 | __ jmp(&done); |
| 2198 | |
| 2199 | __ bind(&continue_sqrt); |
| 2200 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 2201 | __ xorps(double_scratch, double_scratch); |
| 2202 | __ addsd(double_scratch, double_base); // Convert -0 to 0. |
| 2203 | __ sqrtsd(double_result, double_scratch); |
| 2204 | __ jmp(&done); |
| 2205 | |
| 2206 | // Test for -0.5. |
| 2207 | __ bind(¬_plus_half); |
| 2208 | // Load double_scratch with -0.5 by substracting 1. |
| 2209 | __ subsd(double_scratch, double_result); |
| 2210 | // Already ruled out NaNs for exponent. |
| 2211 | __ ucomisd(double_scratch, double_exponent); |
| 2212 | __ j(not_equal, &fast_power, Label::kNear); |
| 2213 | |
| 2214 | // Calculates reciprocal of square root of base. Check for the special |
| 2215 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 2216 | // According to IEEE-754, double-precision -Infinity has the highest |
| 2217 | // 12 bits set and the lowest 52 bits cleared. |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 2218 | __ movq(scratch, V8_UINT64_C(0xFFF0000000000000), RelocInfo::NONE64); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2219 | __ movq(double_scratch, scratch); |
| 2220 | __ ucomisd(double_scratch, double_base); |
| 2221 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 2222 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 2223 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 2224 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 2225 | |
| 2226 | // Set result to 0 in the special case. |
| 2227 | __ xorps(double_result, double_result); |
| 2228 | __ jmp(&done); |
| 2229 | |
| 2230 | __ bind(&continue_rsqrt); |
| 2231 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 2232 | __ xorps(double_exponent, double_exponent); |
| 2233 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 2234 | __ sqrtsd(double_exponent, double_exponent); |
| 2235 | __ divsd(double_result, double_exponent); |
| 2236 | __ jmp(&done); |
| 2237 | } |
| 2238 | |
| 2239 | // Using FPU instructions to calculate power. |
| 2240 | Label fast_power_failed; |
| 2241 | __ bind(&fast_power); |
| 2242 | __ fnclex(); // Clear flags to catch exceptions later. |
| 2243 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 2244 | __ subq(rsp, Immediate(kDoubleSize)); |
| 2245 | __ movsd(Operand(rsp, 0), double_exponent); |
| 2246 | __ fld_d(Operand(rsp, 0)); // E |
| 2247 | __ movsd(Operand(rsp, 0), double_base); |
| 2248 | __ fld_d(Operand(rsp, 0)); // B, E |
| 2249 | |
| 2250 | // Exponent is in st(1) and base is in st(0) |
| 2251 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 2252 | // FYL2X calculates st(1) * log2(st(0)) |
| 2253 | __ fyl2x(); // X |
| 2254 | __ fld(0); // X, X |
| 2255 | __ frndint(); // rnd(X), X |
| 2256 | __ fsub(1); // rnd(X), X-rnd(X) |
| 2257 | __ fxch(1); // X - rnd(X), rnd(X) |
| 2258 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 2259 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 2260 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 2261 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2262 | // FSCALE calculates st(0) * 2^st(1) |
| 2263 | __ fscale(); // 2^X, rnd(X) |
| 2264 | __ fstp(1); |
| 2265 | // Bail out to runtime in case of exceptions in the status word. |
| 2266 | __ fnstsw_ax(); |
| 2267 | __ testb(rax, Immediate(0x5F)); // Check for all but precision exception. |
| 2268 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 2269 | __ fstp_d(Operand(rsp, 0)); |
| 2270 | __ movsd(double_result, Operand(rsp, 0)); |
| 2271 | __ addq(rsp, Immediate(kDoubleSize)); |
| 2272 | __ jmp(&done); |
| 2273 | |
| 2274 | __ bind(&fast_power_failed); |
| 2275 | __ fninit(); |
| 2276 | __ addq(rsp, Immediate(kDoubleSize)); |
| 2277 | __ jmp(&call_runtime); |
| 2278 | } |
| 2279 | |
| 2280 | // Calculate power with integer exponent. |
| 2281 | __ bind(&int_exponent); |
| 2282 | const XMMRegister double_scratch2 = double_exponent; |
| 2283 | // Back up exponent as we need to check if exponent is negative later. |
| 2284 | __ movq(scratch, exponent); // Back up exponent. |
| 2285 | __ movsd(double_scratch, double_base); // Back up base. |
| 2286 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2287 | |
| 2288 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2289 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2290 | __ testl(scratch, scratch); |
| 2291 | __ j(positive, &no_neg, Label::kNear); |
| 2292 | __ negl(scratch); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2293 | __ bind(&no_neg); |
| 2294 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2295 | __ j(zero, &while_false, Label::kNear); |
| 2296 | __ shrl(scratch, Immediate(1)); |
| 2297 | // Above condition means CF==0 && ZF==0. This means that the |
| 2298 | // bit that has been shifted out is 0 and the result is not 0. |
| 2299 | __ j(above, &while_true, Label::kNear); |
| 2300 | __ movsd(double_result, double_scratch); |
| 2301 | __ j(zero, &while_false, Label::kNear); |
| 2302 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2303 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2304 | __ shrl(scratch, Immediate(1)); |
danno@chromium.org | 2ab0c3b | 2012-10-05 08:50:56 +0000 | [diff] [blame] | 2305 | __ mulsd(double_scratch, double_scratch); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2306 | __ j(above, &while_true, Label::kNear); |
| 2307 | __ mulsd(double_result, double_scratch); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2308 | __ j(not_zero, &while_true); |
| 2309 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2310 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2311 | // If the exponent is negative, return 1/result. |
| 2312 | __ testl(exponent, exponent); |
| 2313 | __ j(greater, &done); |
| 2314 | __ divsd(double_scratch2, double_result); |
| 2315 | __ movsd(double_result, double_scratch2); |
| 2316 | // Test whether result is zero. Bail out to check for subnormal result. |
| 2317 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 2318 | __ xorps(double_scratch2, double_scratch2); |
| 2319 | __ ucomisd(double_scratch2, double_result); |
| 2320 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 2321 | // and may not have contained the exponent value in the first place when the |
| 2322 | // input was a smi. We reset it with exponent value before bailing out. |
| 2323 | __ j(not_equal, &done); |
| 2324 | __ cvtlsi2sd(double_exponent, exponent); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2325 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2326 | // Returning or bailing out. |
| 2327 | Counters* counters = masm->isolate()->counters(); |
| 2328 | if (exponent_type_ == ON_STACK) { |
| 2329 | // The arguments are still on the stack. |
| 2330 | __ bind(&call_runtime); |
| 2331 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2332 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2333 | // The stub is called from non-optimized code, which expects the result |
| 2334 | // as heap number in eax. |
| 2335 | __ bind(&done); |
| 2336 | __ AllocateHeapNumber(rax, rcx, &call_runtime); |
| 2337 | __ movsd(FieldOperand(rax, HeapNumber::kValueOffset), double_result); |
| 2338 | __ IncrementCounter(counters->math_pow(), 1); |
| 2339 | __ ret(2 * kPointerSize); |
| 2340 | } else { |
| 2341 | __ bind(&call_runtime); |
| 2342 | // Move base to the correct argument register. Exponent is already in xmm1. |
| 2343 | __ movsd(xmm0, double_base); |
| 2344 | ASSERT(double_exponent.is(xmm1)); |
| 2345 | { |
| 2346 | AllowExternalCallThatCantCauseGC scope(masm); |
| 2347 | __ PrepareCallCFunction(2); |
| 2348 | __ CallCFunction( |
| 2349 | ExternalReference::power_double_double_function(masm->isolate()), 2); |
| 2350 | } |
| 2351 | // Return value is in xmm0. |
| 2352 | __ movsd(double_result, xmm0); |
| 2353 | // Restore context register. |
| 2354 | __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2355 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2356 | __ bind(&done); |
| 2357 | __ IncrementCounter(counters->math_pow(), 1); |
| 2358 | __ ret(0); |
| 2359 | } |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2363 | void ArrayLengthStub::Generate(MacroAssembler* masm) { |
| 2364 | Label miss; |
| 2365 | Register receiver; |
| 2366 | if (kind() == Code::KEYED_LOAD_IC) { |
| 2367 | // ----------- S t a t e ------------- |
| 2368 | // -- rax : key |
| 2369 | // -- rdx : receiver |
| 2370 | // -- rsp[0] : return address |
| 2371 | // ----------------------------------- |
| 2372 | __ Cmp(rax, masm->isolate()->factory()->length_symbol()); |
| 2373 | receiver = rdx; |
| 2374 | } else { |
| 2375 | ASSERT(kind() == Code::LOAD_IC); |
| 2376 | // ----------- S t a t e ------------- |
| 2377 | // -- rax : receiver |
| 2378 | // -- rcx : name |
| 2379 | // -- rsp[0] : return address |
| 2380 | // ----------------------------------- |
| 2381 | receiver = rax; |
| 2382 | } |
| 2383 | |
| 2384 | StubCompiler::GenerateLoadArrayLength(masm, receiver, r8, &miss); |
| 2385 | __ bind(&miss); |
| 2386 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 2387 | } |
| 2388 | |
| 2389 | |
| 2390 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 2391 | Label miss; |
| 2392 | Register receiver; |
| 2393 | if (kind() == Code::KEYED_LOAD_IC) { |
| 2394 | // ----------- S t a t e ------------- |
| 2395 | // -- rax : key |
| 2396 | // -- rdx : receiver |
| 2397 | // -- rsp[0] : return address |
| 2398 | // ----------------------------------- |
| 2399 | __ Cmp(rax, masm->isolate()->factory()->prototype_symbol()); |
| 2400 | receiver = rdx; |
| 2401 | } else { |
| 2402 | ASSERT(kind() == Code::LOAD_IC); |
| 2403 | // ----------- S t a t e ------------- |
| 2404 | // -- rax : receiver |
| 2405 | // -- rcx : name |
| 2406 | // -- rsp[0] : return address |
| 2407 | // ----------------------------------- |
| 2408 | receiver = rax; |
| 2409 | } |
| 2410 | |
| 2411 | StubCompiler::GenerateLoadFunctionPrototype(masm, receiver, r8, r9, &miss); |
| 2412 | __ bind(&miss); |
| 2413 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 2414 | } |
| 2415 | |
| 2416 | |
| 2417 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 2418 | Label miss; |
| 2419 | Register receiver; |
| 2420 | if (kind() == Code::KEYED_LOAD_IC) { |
| 2421 | // ----------- S t a t e ------------- |
| 2422 | // -- rax : key |
| 2423 | // -- rdx : receiver |
| 2424 | // -- rsp[0] : return address |
| 2425 | // ----------------------------------- |
| 2426 | __ Cmp(rax, masm->isolate()->factory()->length_symbol()); |
| 2427 | receiver = rdx; |
| 2428 | } else { |
| 2429 | ASSERT(kind() == Code::LOAD_IC); |
| 2430 | // ----------- S t a t e ------------- |
| 2431 | // -- rax : receiver |
| 2432 | // -- rcx : name |
| 2433 | // -- rsp[0] : return address |
| 2434 | // ----------------------------------- |
| 2435 | receiver = rax; |
| 2436 | } |
| 2437 | |
| 2438 | StubCompiler::GenerateLoadStringLength(masm, receiver, r8, r9, &miss, |
| 2439 | support_wrapper_); |
| 2440 | __ bind(&miss); |
| 2441 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 2442 | } |
| 2443 | |
| 2444 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 2445 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 2446 | // ----------- S t a t e ------------- |
| 2447 | // -- rax : value |
| 2448 | // -- rcx : key |
| 2449 | // -- rdx : receiver |
| 2450 | // -- rsp[0] : return address |
| 2451 | // ----------------------------------- |
| 2452 | // |
| 2453 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 2454 | // (currently anything except for external arrays which means anything with |
| 2455 | // elements of FixedArray type). Value must be a number, but only smis are |
| 2456 | // accepted as the most common case. |
| 2457 | |
| 2458 | Label miss; |
| 2459 | |
| 2460 | Register receiver = rdx; |
| 2461 | Register value = rax; |
| 2462 | Register scratch = rbx; |
| 2463 | if (kind() == Code::KEYED_STORE_IC) { |
| 2464 | __ Cmp(rcx, masm->isolate()->factory()->length_symbol()); |
| 2465 | } |
| 2466 | |
| 2467 | // Check that the receiver isn't a smi. |
| 2468 | __ JumpIfSmi(receiver, &miss); |
| 2469 | |
| 2470 | // Check that the object is a JS array. |
| 2471 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 2472 | __ j(not_equal, &miss); |
| 2473 | |
| 2474 | // Check that elements are FixedArray. |
| 2475 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 2476 | // fast elements (including COW). |
| 2477 | __ movq(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 2478 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 2479 | __ j(not_equal, &miss); |
| 2480 | |
| 2481 | // Check that the array has fast properties, otherwise the length |
| 2482 | // property might have been redefined. |
| 2483 | __ movq(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 2484 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 2485 | Heap::kHashTableMapRootIndex); |
| 2486 | __ j(equal, &miss); |
| 2487 | |
| 2488 | // Check that value is a smi. |
| 2489 | __ JumpIfNotSmi(value, &miss); |
| 2490 | |
| 2491 | // Prepare tail call to StoreIC_ArrayLength. |
| 2492 | __ pop(scratch); |
| 2493 | __ push(receiver); |
| 2494 | __ push(value); |
| 2495 | __ push(scratch); // return address |
| 2496 | |
| 2497 | ExternalReference ref = |
| 2498 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 2499 | __ TailCallExternalReference(ref, 2, 1); |
| 2500 | |
| 2501 | __ bind(&miss); |
| 2502 | |
| 2503 | StubCompiler::GenerateStoreMiss(masm, kind()); |
| 2504 | } |
| 2505 | |
| 2506 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2507 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 2508 | // The key is in rdx and the parameter count is in rax. |
| 2509 | |
| 2510 | // The displacement is used for skipping the frame pointer on the |
| 2511 | // stack. It is the offset of the last parameter (if any) relative |
| 2512 | // to the frame pointer. |
| 2513 | static const int kDisplacement = 1 * kPointerSize; |
| 2514 | |
| 2515 | // Check that the key is a smi. |
| 2516 | Label slow; |
| 2517 | __ JumpIfNotSmi(rdx, &slow); |
| 2518 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2519 | // Check if the calling frame is an arguments adaptor frame. We look at the |
| 2520 | // context offset, and if the frame is not a regular one, then we find a |
| 2521 | // Smi instead of the context. We can't use SmiCompare here, because that |
| 2522 | // only works for comparing two smis. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2523 | Label adaptor; |
| 2524 | __ movq(rbx, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2525 | __ Cmp(Operand(rbx, StandardFrameConstants::kContextOffset), |
| 2526 | Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2527 | __ j(equal, &adaptor); |
| 2528 | |
| 2529 | // Check index against formal parameters count limit passed in |
| 2530 | // through register rax. Use unsigned comparison to get negative |
| 2531 | // check for free. |
| 2532 | __ cmpq(rdx, rax); |
| 2533 | __ j(above_equal, &slow); |
| 2534 | |
| 2535 | // Read the argument from the stack and return it. |
| 2536 | SmiIndex index = masm->SmiToIndex(rax, rax, kPointerSizeLog2); |
| 2537 | __ lea(rbx, Operand(rbp, index.reg, index.scale, 0)); |
| 2538 | index = masm->SmiToNegativeIndex(rdx, rdx, kPointerSizeLog2); |
| 2539 | __ movq(rax, Operand(rbx, index.reg, index.scale, kDisplacement)); |
| 2540 | __ Ret(); |
| 2541 | |
| 2542 | // Arguments adaptor case: Check index against actual arguments |
| 2543 | // limit found in the arguments adaptor frame. Use unsigned |
| 2544 | // comparison to get negative check for free. |
| 2545 | __ bind(&adaptor); |
| 2546 | __ movq(rcx, Operand(rbx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2547 | __ cmpq(rdx, rcx); |
| 2548 | __ j(above_equal, &slow); |
| 2549 | |
| 2550 | // Read the argument from the stack and return it. |
| 2551 | index = masm->SmiToIndex(rax, rcx, kPointerSizeLog2); |
| 2552 | __ lea(rbx, Operand(rbx, index.reg, index.scale, 0)); |
| 2553 | index = masm->SmiToNegativeIndex(rdx, rdx, kPointerSizeLog2); |
| 2554 | __ movq(rax, Operand(rbx, index.reg, index.scale, kDisplacement)); |
| 2555 | __ Ret(); |
| 2556 | |
| 2557 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 2558 | // by calling the runtime system. |
| 2559 | __ bind(&slow); |
| 2560 | __ pop(rbx); // Return address. |
| 2561 | __ push(rdx); |
| 2562 | __ push(rbx); |
| 2563 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 2564 | } |
| 2565 | |
| 2566 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2567 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 2568 | // Stack layout: |
| 2569 | // rsp[0] : return address |
| 2570 | // rsp[8] : number of parameters (tagged) |
| 2571 | // rsp[16] : receiver displacement |
| 2572 | // rsp[24] : function |
| 2573 | // Registers used over the whole function: |
| 2574 | // rbx: the mapped parameter count (untagged) |
| 2575 | // rax: the allocated object (tagged). |
| 2576 | |
| 2577 | Factory* factory = masm->isolate()->factory(); |
| 2578 | |
| 2579 | __ SmiToInteger64(rbx, Operand(rsp, 1 * kPointerSize)); |
| 2580 | // rbx = parameter count (untagged) |
| 2581 | |
| 2582 | // Check if the calling frame is an arguments adaptor frame. |
| 2583 | Label runtime; |
| 2584 | Label adaptor_frame, try_allocate; |
| 2585 | __ movq(rdx, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
| 2586 | __ movq(rcx, Operand(rdx, StandardFrameConstants::kContextOffset)); |
| 2587 | __ Cmp(rcx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
| 2588 | __ j(equal, &adaptor_frame); |
| 2589 | |
| 2590 | // No adaptor, parameter count = argument count. |
| 2591 | __ movq(rcx, rbx); |
| 2592 | __ jmp(&try_allocate, Label::kNear); |
| 2593 | |
| 2594 | // We have an adaptor frame. Patch the parameters pointer. |
| 2595 | __ bind(&adaptor_frame); |
| 2596 | __ SmiToInteger64(rcx, |
| 2597 | Operand(rdx, |
| 2598 | ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2599 | __ lea(rdx, Operand(rdx, rcx, times_pointer_size, |
| 2600 | StandardFrameConstants::kCallerSPOffset)); |
| 2601 | __ movq(Operand(rsp, 2 * kPointerSize), rdx); |
| 2602 | |
| 2603 | // rbx = parameter count (untagged) |
| 2604 | // rcx = argument count (untagged) |
| 2605 | // Compute the mapped parameter count = min(rbx, rcx) in rbx. |
| 2606 | __ cmpq(rbx, rcx); |
| 2607 | __ j(less_equal, &try_allocate, Label::kNear); |
| 2608 | __ movq(rbx, rcx); |
| 2609 | |
| 2610 | __ bind(&try_allocate); |
| 2611 | |
| 2612 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 2613 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 2614 | const int kParameterMapHeaderSize = |
| 2615 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 2616 | Label no_parameter_map; |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2617 | __ xor_(r8, r8); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2618 | __ testq(rbx, rbx); |
| 2619 | __ j(zero, &no_parameter_map, Label::kNear); |
| 2620 | __ lea(r8, Operand(rbx, times_pointer_size, kParameterMapHeaderSize)); |
| 2621 | __ bind(&no_parameter_map); |
| 2622 | |
| 2623 | // 2. Backing store. |
| 2624 | __ lea(r8, Operand(r8, rcx, times_pointer_size, FixedArray::kHeaderSize)); |
| 2625 | |
| 2626 | // 3. Arguments object. |
| 2627 | __ addq(r8, Immediate(Heap::kArgumentsObjectSize)); |
| 2628 | |
| 2629 | // Do the allocation of all three objects in one go. |
| 2630 | __ AllocateInNewSpace(r8, rax, rdx, rdi, &runtime, TAG_OBJECT); |
| 2631 | |
| 2632 | // rax = address of new object(s) (tagged) |
| 2633 | // rcx = argument count (untagged) |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2634 | // Get the arguments boilerplate from the current native context into rdi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2635 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2636 | __ movq(rdi, Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 2637 | __ movq(rdi, FieldOperand(rdi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2638 | __ testq(rbx, rbx); |
| 2639 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 2640 | |
| 2641 | const int kIndex = Context::ARGUMENTS_BOILERPLATE_INDEX; |
| 2642 | __ movq(rdi, Operand(rdi, Context::SlotOffset(kIndex))); |
| 2643 | __ jmp(©, Label::kNear); |
| 2644 | |
| 2645 | const int kAliasedIndex = Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX; |
| 2646 | __ bind(&has_mapped_parameters); |
| 2647 | __ movq(rdi, Operand(rdi, Context::SlotOffset(kAliasedIndex))); |
| 2648 | __ bind(©); |
| 2649 | |
| 2650 | // rax = address of new object (tagged) |
| 2651 | // rbx = mapped parameter count (untagged) |
| 2652 | // rcx = argument count (untagged) |
| 2653 | // rdi = address of boilerplate object (tagged) |
| 2654 | // Copy the JS object part. |
| 2655 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 2656 | __ movq(rdx, FieldOperand(rdi, i)); |
| 2657 | __ movq(FieldOperand(rax, i), rdx); |
| 2658 | } |
| 2659 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2660 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2661 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 2662 | __ movq(rdx, Operand(rsp, 3 * kPointerSize)); |
| 2663 | __ movq(FieldOperand(rax, JSObject::kHeaderSize + |
| 2664 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 2665 | rdx); |
| 2666 | |
| 2667 | // Use the length (smi tagged) and set that as an in-object property too. |
| 2668 | // Note: rcx is tagged from here on. |
| 2669 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 2670 | __ Integer32ToSmi(rcx, rcx); |
| 2671 | __ movq(FieldOperand(rax, JSObject::kHeaderSize + |
| 2672 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 2673 | rcx); |
| 2674 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2675 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2676 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 2677 | // backing store. |
| 2678 | __ lea(rdi, Operand(rax, Heap::kArgumentsObjectSize)); |
| 2679 | __ movq(FieldOperand(rax, JSObject::kElementsOffset), rdi); |
| 2680 | |
| 2681 | // rax = address of new object (tagged) |
| 2682 | // rbx = mapped parameter count (untagged) |
| 2683 | // rcx = argument count (tagged) |
| 2684 | // rdi = address of parameter map or backing store (tagged) |
| 2685 | |
| 2686 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 2687 | Label skip_parameter_map; |
| 2688 | __ testq(rbx, rbx); |
| 2689 | __ j(zero, &skip_parameter_map); |
| 2690 | |
| 2691 | __ LoadRoot(kScratchRegister, Heap::kNonStrictArgumentsElementsMapRootIndex); |
| 2692 | // rbx contains the untagged argument count. Add 2 and tag to write. |
| 2693 | __ movq(FieldOperand(rdi, FixedArray::kMapOffset), kScratchRegister); |
| 2694 | __ Integer64PlusConstantToSmi(r9, rbx, 2); |
| 2695 | __ movq(FieldOperand(rdi, FixedArray::kLengthOffset), r9); |
| 2696 | __ movq(FieldOperand(rdi, FixedArray::kHeaderSize + 0 * kPointerSize), rsi); |
| 2697 | __ lea(r9, Operand(rdi, rbx, times_pointer_size, kParameterMapHeaderSize)); |
| 2698 | __ movq(FieldOperand(rdi, FixedArray::kHeaderSize + 1 * kPointerSize), r9); |
| 2699 | |
| 2700 | // Copy the parameter slots and the holes in the arguments. |
| 2701 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 2702 | // where parameters are stored in reverse order, at |
| 2703 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 2704 | // The mapped parameter thus need to get indices |
| 2705 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 2706 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 2707 | // We loop from right to left. |
| 2708 | Label parameters_loop, parameters_test; |
| 2709 | |
| 2710 | // Load tagged parameter count into r9. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2711 | __ Integer32ToSmi(r9, rbx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2712 | __ Move(r8, Smi::FromInt(Context::MIN_CONTEXT_SLOTS)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2713 | __ addq(r8, Operand(rsp, 1 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2714 | __ subq(r8, r9); |
| 2715 | __ Move(r11, factory->the_hole_value()); |
| 2716 | __ movq(rdx, rdi); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2717 | __ lea(rdi, Operand(rdi, rbx, times_pointer_size, kParameterMapHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2718 | // r9 = loop variable (tagged) |
| 2719 | // r8 = mapping index (tagged) |
| 2720 | // r11 = the hole value |
| 2721 | // rdx = address of parameter map (tagged) |
| 2722 | // rdi = address of backing store (tagged) |
| 2723 | __ jmp(¶meters_test, Label::kNear); |
| 2724 | |
| 2725 | __ bind(¶meters_loop); |
| 2726 | __ SmiSubConstant(r9, r9, Smi::FromInt(1)); |
| 2727 | __ SmiToInteger64(kScratchRegister, r9); |
| 2728 | __ movq(FieldOperand(rdx, kScratchRegister, |
| 2729 | times_pointer_size, |
| 2730 | kParameterMapHeaderSize), |
| 2731 | r8); |
| 2732 | __ movq(FieldOperand(rdi, kScratchRegister, |
| 2733 | times_pointer_size, |
| 2734 | FixedArray::kHeaderSize), |
| 2735 | r11); |
| 2736 | __ SmiAddConstant(r8, r8, Smi::FromInt(1)); |
| 2737 | __ bind(¶meters_test); |
| 2738 | __ SmiTest(r9); |
| 2739 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 2740 | |
| 2741 | __ bind(&skip_parameter_map); |
| 2742 | |
| 2743 | // rcx = argument count (tagged) |
| 2744 | // rdi = address of backing store (tagged) |
| 2745 | // Copy arguments header and remaining slots (if there are any). |
| 2746 | __ Move(FieldOperand(rdi, FixedArray::kMapOffset), |
| 2747 | factory->fixed_array_map()); |
| 2748 | __ movq(FieldOperand(rdi, FixedArray::kLengthOffset), rcx); |
| 2749 | |
| 2750 | Label arguments_loop, arguments_test; |
| 2751 | __ movq(r8, rbx); |
| 2752 | __ movq(rdx, Operand(rsp, 2 * kPointerSize)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2753 | // Untag rcx for the loop below. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2754 | __ SmiToInteger64(rcx, rcx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2755 | __ lea(kScratchRegister, Operand(r8, times_pointer_size, 0)); |
| 2756 | __ subq(rdx, kScratchRegister); |
| 2757 | __ jmp(&arguments_test, Label::kNear); |
| 2758 | |
| 2759 | __ bind(&arguments_loop); |
| 2760 | __ subq(rdx, Immediate(kPointerSize)); |
| 2761 | __ movq(r9, Operand(rdx, 0)); |
| 2762 | __ movq(FieldOperand(rdi, r8, |
| 2763 | times_pointer_size, |
| 2764 | FixedArray::kHeaderSize), |
| 2765 | r9); |
| 2766 | __ addq(r8, Immediate(1)); |
| 2767 | |
| 2768 | __ bind(&arguments_test); |
| 2769 | __ cmpq(r8, rcx); |
| 2770 | __ j(less, &arguments_loop, Label::kNear); |
| 2771 | |
| 2772 | // Return and remove the on-stack parameters. |
| 2773 | __ ret(3 * kPointerSize); |
| 2774 | |
| 2775 | // Do the runtime call to allocate the arguments object. |
| 2776 | // rcx = argument count (untagged) |
| 2777 | __ bind(&runtime); |
| 2778 | __ Integer32ToSmi(rcx, rcx); |
| 2779 | __ movq(Operand(rsp, 1 * kPointerSize), rcx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 2780 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | |
| 2784 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
| 2785 | // esp[0] : return address |
| 2786 | // esp[8] : number of parameters |
| 2787 | // esp[16] : receiver displacement |
| 2788 | // esp[24] : function |
| 2789 | |
| 2790 | // Check if the calling frame is an arguments adaptor frame. |
| 2791 | Label runtime; |
| 2792 | __ movq(rdx, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
| 2793 | __ movq(rcx, Operand(rdx, StandardFrameConstants::kContextOffset)); |
| 2794 | __ Cmp(rcx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
| 2795 | __ j(not_equal, &runtime); |
| 2796 | |
| 2797 | // Patch the arguments.length and the parameters pointer. |
| 2798 | __ movq(rcx, Operand(rdx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2799 | __ movq(Operand(rsp, 1 * kPointerSize), rcx); |
| 2800 | __ SmiToInteger64(rcx, rcx); |
| 2801 | __ lea(rdx, Operand(rdx, rcx, times_pointer_size, |
| 2802 | StandardFrameConstants::kCallerSPOffset)); |
| 2803 | __ movq(Operand(rsp, 2 * kPointerSize), rdx); |
| 2804 | |
| 2805 | __ bind(&runtime); |
| 2806 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 2807 | } |
| 2808 | |
| 2809 | |
| 2810 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2811 | // rsp[0] : return address |
| 2812 | // rsp[8] : number of parameters |
| 2813 | // rsp[16] : receiver displacement |
| 2814 | // rsp[24] : function |
| 2815 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2816 | // Check if the calling frame is an arguments adaptor frame. |
| 2817 | Label adaptor_frame, try_allocate, runtime; |
| 2818 | __ movq(rdx, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2819 | __ movq(rcx, Operand(rdx, StandardFrameConstants::kContextOffset)); |
| 2820 | __ Cmp(rcx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2821 | __ j(equal, &adaptor_frame); |
| 2822 | |
| 2823 | // Get the length from the frame. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2824 | __ movq(rcx, Operand(rsp, 1 * kPointerSize)); |
| 2825 | __ SmiToInteger64(rcx, rcx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2826 | __ jmp(&try_allocate); |
| 2827 | |
| 2828 | // Patch the arguments.length and the parameters pointer. |
| 2829 | __ bind(&adaptor_frame); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2830 | __ movq(rcx, Operand(rdx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2831 | __ movq(Operand(rsp, 1 * kPointerSize), rcx); |
| 2832 | __ SmiToInteger64(rcx, rcx); |
| 2833 | __ lea(rdx, Operand(rdx, rcx, times_pointer_size, |
| 2834 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2835 | __ movq(Operand(rsp, 2 * kPointerSize), rdx); |
| 2836 | |
| 2837 | // Try the new space allocation. Start out with computing the size of |
| 2838 | // the arguments object and the elements array. |
| 2839 | Label add_arguments_object; |
| 2840 | __ bind(&try_allocate); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2841 | __ testq(rcx, rcx); |
| 2842 | __ j(zero, &add_arguments_object, Label::kNear); |
| 2843 | __ lea(rcx, Operand(rcx, times_pointer_size, FixedArray::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2844 | __ bind(&add_arguments_object); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2845 | __ addq(rcx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2846 | |
| 2847 | // Do the allocation of both objects in one go. |
| 2848 | __ AllocateInNewSpace(rcx, rax, rdx, rbx, &runtime, TAG_OBJECT); |
| 2849 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2850 | // Get the arguments boilerplate from the current native context. |
| 2851 | __ movq(rdi, Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 2852 | __ movq(rdi, FieldOperand(rdi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2853 | const int offset = |
| 2854 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 2855 | __ movq(rdi, Operand(rdi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2856 | |
| 2857 | // Copy the JS object part. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2858 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 2859 | __ movq(rbx, FieldOperand(rdi, i)); |
| 2860 | __ movq(FieldOperand(rax, i), rbx); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2861 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2862 | |
| 2863 | // Get the length (smi tagged) and set that as an in-object property too. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2864 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2865 | __ movq(rcx, Operand(rsp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2866 | __ movq(FieldOperand(rax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2867 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2868 | rcx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2869 | |
| 2870 | // If there are no actual arguments, we're done. |
| 2871 | Label done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2872 | __ testq(rcx, rcx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2873 | __ j(zero, &done); |
| 2874 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2875 | // Get the parameters pointer from the stack. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2876 | __ movq(rdx, Operand(rsp, 2 * kPointerSize)); |
| 2877 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2878 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2879 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2880 | __ lea(rdi, Operand(rax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2881 | __ movq(FieldOperand(rax, JSObject::kElementsOffset), rdi); |
| 2882 | __ LoadRoot(kScratchRegister, Heap::kFixedArrayMapRootIndex); |
| 2883 | __ movq(FieldOperand(rdi, FixedArray::kMapOffset), kScratchRegister); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2884 | |
| 2885 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2886 | __ movq(FieldOperand(rdi, FixedArray::kLengthOffset), rcx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2887 | // Untag the length for the loop below. |
| 2888 | __ SmiToInteger64(rcx, rcx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2889 | |
| 2890 | // Copy the fixed array slots. |
| 2891 | Label loop; |
| 2892 | __ bind(&loop); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2893 | __ movq(rbx, Operand(rdx, -1 * kPointerSize)); // Skip receiver. |
| 2894 | __ movq(FieldOperand(rdi, FixedArray::kHeaderSize), rbx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2895 | __ addq(rdi, Immediate(kPointerSize)); |
| 2896 | __ subq(rdx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2897 | __ decq(rcx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2898 | __ j(not_zero, &loop); |
| 2899 | |
| 2900 | // Return and remove the on-stack parameters. |
| 2901 | __ bind(&done); |
| 2902 | __ ret(3 * kPointerSize); |
| 2903 | |
| 2904 | // Do the runtime call to allocate the arguments object. |
| 2905 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2906 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | |
| 2910 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 2911 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 2912 | // time or if regexp entry in generated code is turned off runtime switch or |
| 2913 | // at compilation. |
| 2914 | #ifdef V8_INTERPRETED_REGEXP |
| 2915 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 2916 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2917 | |
| 2918 | // Stack frame on entry. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2919 | // rsp[0]: return address |
| 2920 | // rsp[8]: last_match_info (expected JSArray) |
| 2921 | // rsp[16]: previous index |
| 2922 | // rsp[24]: subject string |
| 2923 | // rsp[32]: JSRegExp object |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2924 | |
| 2925 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 2926 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 2927 | static const int kSubjectOffset = 3 * kPointerSize; |
| 2928 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 2929 | |
| 2930 | Label runtime; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2931 | // Ensure that a RegExp stack is allocated. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2932 | Isolate* isolate = masm->isolate(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2933 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2934 | ExternalReference::address_of_regexp_stack_memory_address(isolate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2935 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2936 | ExternalReference::address_of_regexp_stack_memory_size(isolate); |
| 2937 | __ Load(kScratchRegister, address_of_regexp_stack_memory_size); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2938 | __ testq(kScratchRegister, kScratchRegister); |
| 2939 | __ j(zero, &runtime); |
| 2940 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2941 | // Check that the first argument is a JSRegExp object. |
| 2942 | __ movq(rax, Operand(rsp, kJSRegExpOffset)); |
| 2943 | __ JumpIfSmi(rax, &runtime); |
| 2944 | __ CmpObjectType(rax, JS_REGEXP_TYPE, kScratchRegister); |
| 2945 | __ j(not_equal, &runtime); |
| 2946 | // Check that the RegExp has been compiled (data contains a fixed array). |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2947 | __ movq(rax, FieldOperand(rax, JSRegExp::kDataOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2948 | if (FLAG_debug_code) { |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2949 | Condition is_smi = masm->CheckSmi(rax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2950 | __ Check(NegateCondition(is_smi), |
| 2951 | "Unexpected type for RegExp data, FixedArray expected"); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2952 | __ CmpObjectType(rax, FIXED_ARRAY_TYPE, kScratchRegister); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2953 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 2954 | } |
| 2955 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2956 | // rax: RegExp data (FixedArray) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2957 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2958 | __ SmiToInteger32(rbx, FieldOperand(rax, JSRegExp::kDataTagOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2959 | __ cmpl(rbx, Immediate(JSRegExp::IRREGEXP)); |
| 2960 | __ j(not_equal, &runtime); |
| 2961 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2962 | // rax: RegExp data (FixedArray) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2963 | // Check that the number of captures fit in the static offsets vector buffer. |
| 2964 | __ SmiToInteger32(rdx, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2965 | FieldOperand(rax, JSRegExp::kIrregexpCaptureCountOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2966 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 2967 | __ leal(rdx, Operand(rdx, rdx, times_1, 2)); |
| 2968 | // Check that the static offsets vector buffer is large enough. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 2969 | __ cmpl(rdx, Immediate(Isolate::kJSRegexpStaticOffsetsVectorSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2970 | __ j(above, &runtime); |
| 2971 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2972 | // rax: RegExp data (FixedArray) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2973 | // rdx: Number of capture registers |
| 2974 | // Check that the second argument is a string. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2975 | __ movq(rdi, Operand(rsp, kSubjectOffset)); |
| 2976 | __ JumpIfSmi(rdi, &runtime); |
| 2977 | Condition is_string = masm->IsObjectStringType(rdi, rbx, rbx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2978 | __ j(NegateCondition(is_string), &runtime); |
| 2979 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2980 | // rdi: Subject string. |
| 2981 | // rax: RegExp data (FixedArray). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2982 | // rdx: Number of capture registers. |
| 2983 | // Check that the third argument is a positive smi less than the string |
| 2984 | // length. A negative value will be greater (unsigned comparison). |
| 2985 | __ movq(rbx, Operand(rsp, kPreviousIndexOffset)); |
| 2986 | __ JumpIfNotSmi(rbx, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2987 | __ SmiCompare(rbx, FieldOperand(rdi, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2988 | __ j(above_equal, &runtime); |
| 2989 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2990 | // rax: RegExp data (FixedArray) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2991 | // rdx: Number of capture registers |
| 2992 | // Check that the fourth object is a JSArray object. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2993 | __ movq(rdi, Operand(rsp, kLastMatchInfoOffset)); |
| 2994 | __ JumpIfSmi(rdi, &runtime); |
| 2995 | __ CmpObjectType(rdi, JS_ARRAY_TYPE, kScratchRegister); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2996 | __ j(not_equal, &runtime); |
| 2997 | // Check that the JSArray is in fast case. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2998 | __ movq(rbx, FieldOperand(rdi, JSArray::kElementsOffset)); |
| 2999 | __ movq(rdi, FieldOperand(rbx, HeapObject::kMapOffset)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3000 | __ CompareRoot(FieldOperand(rbx, HeapObject::kMapOffset), |
| 3001 | Heap::kFixedArrayMapRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3002 | __ j(not_equal, &runtime); |
| 3003 | // Check that the last match info has space for the capture registers and the |
| 3004 | // additional information. Ensure no overflow in add. |
| 3005 | STATIC_ASSERT(FixedArray::kMaxLength < kMaxInt - FixedArray::kLengthOffset); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3006 | __ SmiToInteger32(rdi, FieldOperand(rbx, FixedArray::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3007 | __ addl(rdx, Immediate(RegExpImpl::kLastMatchOverhead)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3008 | __ cmpl(rdx, rdi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3009 | __ j(greater, &runtime); |
| 3010 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3011 | // Reset offset for possibly sliced string. |
| 3012 | __ Set(r14, 0); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3013 | // rax: RegExp data (FixedArray) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3014 | // Check the representation and encoding of the subject string. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3015 | Label seq_ascii_string, seq_two_byte_string, check_code; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3016 | __ movq(rdi, Operand(rsp, kSubjectOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3017 | // Make a copy of the original subject string. |
| 3018 | __ movq(r15, rdi); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3019 | __ movq(rbx, FieldOperand(rdi, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3020 | __ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset)); |
| 3021 | // First check for flat two byte string. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3022 | __ andb(rbx, Immediate(kIsNotStringMask | |
| 3023 | kStringRepresentationMask | |
| 3024 | kStringEncodingMask | |
| 3025 | kShortExternalStringMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3026 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3027 | __ j(zero, &seq_two_byte_string, Label::kNear); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3028 | // 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] | 3029 | // string type tests will succeed if subject is not a string or a short |
| 3030 | // external string. |
| 3031 | __ andb(rbx, Immediate(kIsNotStringMask | |
| 3032 | kStringRepresentationMask | |
| 3033 | kShortExternalStringMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3034 | __ j(zero, &seq_ascii_string, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3035 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3036 | // rbx: whether subject is a string and if yes, its string representation |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3037 | // Check for flat cons string or sliced string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3038 | // A flat cons string is a cons string where the second part is the empty |
| 3039 | // string. In that case the subject string is just the first part of the cons |
| 3040 | // string. Also in this case the first part of the cons string is known to be |
| 3041 | // a sequential string or an external string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3042 | // 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] | 3043 | Label cons_string, external_string, check_encoding; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3044 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3045 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3046 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3047 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3048 | __ cmpq(rbx, Immediate(kExternalStringTag)); |
| 3049 | __ j(less, &cons_string, Label::kNear); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3050 | __ j(equal, &external_string); |
| 3051 | |
| 3052 | // Catch non-string subject or short external string. |
| 3053 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 3054 | __ testb(rbx, Immediate(kIsNotStringMask | kShortExternalStringMask)); |
| 3055 | __ j(not_zero, &runtime); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3056 | |
| 3057 | // String is sliced. |
| 3058 | __ SmiToInteger32(r14, FieldOperand(rdi, SlicedString::kOffsetOffset)); |
| 3059 | __ movq(rdi, FieldOperand(rdi, SlicedString::kParentOffset)); |
| 3060 | // r14: slice offset |
| 3061 | // r15: original subject string |
| 3062 | // rdi: parent string |
| 3063 | __ jmp(&check_encoding, Label::kNear); |
| 3064 | // String is a cons string, check whether it is flat. |
| 3065 | __ bind(&cons_string); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3066 | __ CompareRoot(FieldOperand(rdi, ConsString::kSecondOffset), |
| 3067 | Heap::kEmptyStringRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3068 | __ j(not_equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3069 | __ movq(rdi, FieldOperand(rdi, ConsString::kFirstOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3070 | // rdi: first part of cons string or parent of sliced string. |
| 3071 | // rbx: map of first part of cons string or map of parent of sliced string. |
| 3072 | // Is first part of cons or parent of slice a flat two byte string? |
| 3073 | __ bind(&check_encoding); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3074 | __ movq(rbx, FieldOperand(rdi, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3075 | __ testb(FieldOperand(rbx, Map::kInstanceTypeOffset), |
| 3076 | Immediate(kStringRepresentationMask | kStringEncodingMask)); |
| 3077 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3078 | __ j(zero, &seq_two_byte_string, Label::kNear); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3079 | // Any other flat string must be sequential ASCII or external. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3080 | __ testb(FieldOperand(rbx, Map::kInstanceTypeOffset), |
| 3081 | Immediate(kStringRepresentationMask)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3082 | __ j(not_zero, &external_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3083 | |
| 3084 | __ bind(&seq_ascii_string); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3085 | // rdi: subject string (sequential ASCII) |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3086 | // rax: RegExp data (FixedArray) |
| 3087 | __ movq(r11, FieldOperand(rax, JSRegExp::kDataAsciiCodeOffset)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3088 | __ Set(rcx, 1); // Type is ASCII. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3089 | __ jmp(&check_code, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3090 | |
| 3091 | __ bind(&seq_two_byte_string); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3092 | // rdi: subject string (flat two-byte) |
| 3093 | // rax: RegExp data (FixedArray) |
| 3094 | __ movq(r11, FieldOperand(rax, JSRegExp::kDataUC16CodeOffset)); |
| 3095 | __ Set(rcx, 0); // Type is two byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3096 | |
| 3097 | __ bind(&check_code); |
| 3098 | // Check that the irregexp code has been generated for the actual string |
| 3099 | // 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] | 3100 | // smi (code flushing support) |
| 3101 | __ JumpIfSmi(r11, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3102 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3103 | // rdi: subject string |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3104 | // rcx: encoding of subject string (1 if ASCII, 0 if two_byte); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3105 | // r11: code |
| 3106 | // Load used arguments before starting to push arguments for call to native |
| 3107 | // RegExp code to avoid handling changing stack height. |
| 3108 | __ SmiToInteger64(rbx, Operand(rsp, kPreviousIndexOffset)); |
| 3109 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3110 | // rdi: subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3111 | // rbx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3112 | // rcx: encoding of subject string (1 if ASCII 0 if two_byte); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3113 | // r11: code |
| 3114 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3115 | Counters* counters = masm->isolate()->counters(); |
| 3116 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3117 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3118 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3119 | static const int kRegExpExecuteArguments = 9; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3120 | int argument_slots_on_stack = |
| 3121 | masm->ArgumentStackSlotsForCFunctionCall(kRegExpExecuteArguments); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3122 | __ EnterApiExitFrame(argument_slots_on_stack); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3123 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3124 | // Argument 9: Pass current isolate address. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3125 | // __ movq(Operand(rsp, (argument_slots_on_stack - 1) * kPointerSize), |
| 3126 | // Immediate(ExternalReference::isolate_address())); |
| 3127 | __ LoadAddress(kScratchRegister, ExternalReference::isolate_address()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3128 | __ movq(Operand(rsp, (argument_slots_on_stack - 1) * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3129 | kScratchRegister); |
| 3130 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3131 | // Argument 8: Indicate that this is a direct call from JavaScript. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3132 | __ movq(Operand(rsp, (argument_slots_on_stack - 2) * kPointerSize), |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3133 | Immediate(1)); |
| 3134 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3135 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3136 | __ movq(kScratchRegister, address_of_regexp_stack_memory_address); |
| 3137 | __ movq(r9, Operand(kScratchRegister, 0)); |
| 3138 | __ movq(kScratchRegister, address_of_regexp_stack_memory_size); |
| 3139 | __ addq(r9, Operand(kScratchRegister, 0)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3140 | __ movq(Operand(rsp, (argument_slots_on_stack - 3) * kPointerSize), r9); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3141 | |
| 3142 | // Argument 6: Set the number of capture registers to zero to force global |
| 3143 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 3144 | // Argument 6 is passed in r9 on Linux and on the stack on Windows. |
| 3145 | #ifdef _WIN64 |
| 3146 | __ movq(Operand(rsp, (argument_slots_on_stack - 4) * kPointerSize), |
| 3147 | Immediate(0)); |
| 3148 | #else |
| 3149 | __ Set(r9, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3150 | #endif |
| 3151 | |
| 3152 | // Argument 5: static offsets vector buffer. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3153 | __ LoadAddress(r8, |
| 3154 | ExternalReference::address_of_static_offsets_vector(isolate)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3155 | // Argument 5 passed in r8 on Linux and on the stack on Windows. |
| 3156 | #ifdef _WIN64 |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3157 | __ movq(Operand(rsp, (argument_slots_on_stack - 5) * kPointerSize), r8); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3158 | #endif |
| 3159 | |
| 3160 | // First four arguments are passed in registers on both Linux and Windows. |
| 3161 | #ifdef _WIN64 |
| 3162 | Register arg4 = r9; |
| 3163 | Register arg3 = r8; |
| 3164 | Register arg2 = rdx; |
| 3165 | Register arg1 = rcx; |
| 3166 | #else |
| 3167 | Register arg4 = rcx; |
| 3168 | Register arg3 = rdx; |
| 3169 | Register arg2 = rsi; |
| 3170 | Register arg1 = rdi; |
| 3171 | #endif |
| 3172 | |
| 3173 | // Keep track on aliasing between argX defined above and the registers used. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3174 | // rdi: subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3175 | // rbx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3176 | // rcx: encoding of subject string (1 if ASCII 0 if two_byte); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3177 | // r11: code |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3178 | // r14: slice offset |
| 3179 | // r15: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3180 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3181 | // Argument 2: Previous index. |
| 3182 | __ movq(arg2, rbx); |
| 3183 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3184 | // Argument 4: End of string data |
| 3185 | // Argument 3: Start of string data |
| 3186 | Label setup_two_byte, setup_rest, got_length, length_not_from_slice; |
| 3187 | // Prepare start and end index of the input. |
| 3188 | // Load the length from the original sliced string if that is the case. |
| 3189 | __ addq(rbx, r14); |
| 3190 | __ SmiToInteger32(arg3, FieldOperand(r15, String::kLengthOffset)); |
| 3191 | __ addq(r14, arg3); // Using arg3 as scratch. |
| 3192 | |
| 3193 | // rbx: start index of the input |
| 3194 | // r14: end index of the input |
| 3195 | // r15: original subject string |
| 3196 | __ testb(rcx, rcx); // Last use of rcx as encoding of subject string. |
| 3197 | __ j(zero, &setup_two_byte, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3198 | __ lea(arg4, FieldOperand(rdi, r14, times_1, SeqOneByteString::kHeaderSize)); |
| 3199 | __ lea(arg3, FieldOperand(rdi, rbx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3200 | __ jmp(&setup_rest, Label::kNear); |
| 3201 | __ bind(&setup_two_byte); |
| 3202 | __ lea(arg4, FieldOperand(rdi, r14, times_2, SeqTwoByteString::kHeaderSize)); |
| 3203 | __ lea(arg3, FieldOperand(rdi, rbx, times_2, SeqTwoByteString::kHeaderSize)); |
| 3204 | __ bind(&setup_rest); |
| 3205 | |
| 3206 | // Argument 1: Original subject string. |
| 3207 | // The original subject is in the previous stack frame. Therefore we have to |
| 3208 | // use rbp, which points exactly to one pointer size below the previous rsp. |
| 3209 | // (Because creating a new stack frame pushes the previous rbp onto the stack |
| 3210 | // and thereby moves up rsp by one kPointerSize.) |
| 3211 | __ movq(arg1, r15); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3212 | |
| 3213 | // Locate the code entry and call it. |
| 3214 | __ addq(r11, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3215 | __ call(r11); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3216 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3217 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3218 | |
| 3219 | // Check the result. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3220 | Label success; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3221 | Label exception; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3222 | __ cmpl(rax, Immediate(1)); |
| 3223 | // We expect exactly one result since we force the called regexp to behave |
| 3224 | // as non-global. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3225 | __ j(equal, &success, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3226 | __ cmpl(rax, Immediate(NativeRegExpMacroAssembler::EXCEPTION)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3227 | __ j(equal, &exception); |
| 3228 | __ cmpl(rax, Immediate(NativeRegExpMacroAssembler::FAILURE)); |
| 3229 | // If none of the above, it can only be retry. |
| 3230 | // Handle that in the runtime system. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3231 | __ j(not_equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3232 | |
| 3233 | // For failure return null. |
| 3234 | __ LoadRoot(rax, Heap::kNullValueRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3235 | __ ret(4 * kPointerSize); |
| 3236 | |
| 3237 | // Load RegExp data. |
| 3238 | __ bind(&success); |
| 3239 | __ movq(rax, Operand(rsp, kJSRegExpOffset)); |
| 3240 | __ movq(rcx, FieldOperand(rax, JSRegExp::kDataOffset)); |
| 3241 | __ SmiToInteger32(rax, |
| 3242 | FieldOperand(rcx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3243 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 3244 | __ leal(rdx, Operand(rax, rax, times_1, 2)); |
| 3245 | |
| 3246 | // rdx: Number of capture registers |
| 3247 | // Load last_match_info which is still known to be a fast case JSArray. |
| 3248 | __ movq(rax, Operand(rsp, kLastMatchInfoOffset)); |
| 3249 | __ movq(rbx, FieldOperand(rax, JSArray::kElementsOffset)); |
| 3250 | |
| 3251 | // rbx: last_match_info backing store (FixedArray) |
| 3252 | // rdx: number of capture registers |
| 3253 | // Store the capture count. |
| 3254 | __ Integer32ToSmi(kScratchRegister, rdx); |
| 3255 | __ movq(FieldOperand(rbx, RegExpImpl::kLastCaptureCountOffset), |
| 3256 | kScratchRegister); |
| 3257 | // Store last subject and last input. |
| 3258 | __ movq(rax, Operand(rsp, kSubjectOffset)); |
| 3259 | __ movq(FieldOperand(rbx, RegExpImpl::kLastSubjectOffset), rax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3260 | __ RecordWriteField(rbx, |
| 3261 | RegExpImpl::kLastSubjectOffset, |
| 3262 | rax, |
| 3263 | rdi, |
| 3264 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3265 | __ movq(rax, Operand(rsp, kSubjectOffset)); |
| 3266 | __ movq(FieldOperand(rbx, RegExpImpl::kLastInputOffset), rax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3267 | __ RecordWriteField(rbx, |
| 3268 | RegExpImpl::kLastInputOffset, |
| 3269 | rax, |
| 3270 | rdi, |
| 3271 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3272 | |
| 3273 | // Get the static offsets vector filled by the native regexp code. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3274 | __ LoadAddress(rcx, |
| 3275 | ExternalReference::address_of_static_offsets_vector(isolate)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3276 | |
| 3277 | // rbx: last_match_info backing store (FixedArray) |
| 3278 | // rcx: offsets vector |
| 3279 | // rdx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3280 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3281 | // Capture register counter starts from number of capture registers and |
| 3282 | // counts down until wraping after zero. |
| 3283 | __ bind(&next_capture); |
| 3284 | __ subq(rdx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3285 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3286 | // Read the value from the static offsets vector buffer and make it a smi. |
| 3287 | __ movl(rdi, Operand(rcx, rdx, times_int_size, 0)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3288 | __ Integer32ToSmi(rdi, rdi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3289 | // Store the smi value in the last match info. |
| 3290 | __ movq(FieldOperand(rbx, |
| 3291 | rdx, |
| 3292 | times_pointer_size, |
| 3293 | RegExpImpl::kFirstCaptureOffset), |
| 3294 | rdi); |
| 3295 | __ jmp(&next_capture); |
| 3296 | __ bind(&done); |
| 3297 | |
| 3298 | // Return last match info. |
| 3299 | __ movq(rax, Operand(rsp, kLastMatchInfoOffset)); |
| 3300 | __ ret(4 * kPointerSize); |
| 3301 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3302 | __ bind(&exception); |
| 3303 | // Result must now be exception. If there is no pending exception already a |
| 3304 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 3305 | // haven't created the exception yet. Handle that in the runtime system. |
| 3306 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3307 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3308 | Isolate::kPendingExceptionAddress, isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3309 | Operand pending_exception_operand = |
| 3310 | masm->ExternalOperand(pending_exception_address, rbx); |
| 3311 | __ movq(rax, pending_exception_operand); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3312 | __ LoadRoot(rdx, Heap::kTheHoleValueRootIndex); |
| 3313 | __ cmpq(rax, rdx); |
| 3314 | __ j(equal, &runtime); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3315 | __ movq(pending_exception_operand, rdx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3316 | |
| 3317 | __ CompareRoot(rax, Heap::kTerminationExceptionRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3318 | Label termination_exception; |
| 3319 | __ j(equal, &termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3320 | __ Throw(rax); |
| 3321 | |
| 3322 | __ bind(&termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 3323 | __ ThrowUncatchable(rax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3324 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3325 | // External string. Short external strings have already been ruled out. |
| 3326 | // rdi: subject string (expected to be external) |
| 3327 | // rbx: scratch |
| 3328 | __ bind(&external_string); |
| 3329 | __ movq(rbx, FieldOperand(rdi, HeapObject::kMapOffset)); |
| 3330 | __ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset)); |
| 3331 | if (FLAG_debug_code) { |
| 3332 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 3333 | // Sequential strings have already been ruled out. |
| 3334 | __ testb(rbx, Immediate(kIsIndirectStringMask)); |
| 3335 | __ Assert(zero, "external string expected, but not found"); |
| 3336 | } |
| 3337 | __ movq(rdi, FieldOperand(rdi, ExternalString::kResourceDataOffset)); |
| 3338 | // Move the pointer so that offset-wise, it looks like a sequential string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3339 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3340 | __ subq(rdi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 3341 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 3342 | __ testb(rbx, Immediate(kStringEncodingMask)); |
| 3343 | __ j(not_zero, &seq_ascii_string); |
| 3344 | __ jmp(&seq_two_byte_string); |
| 3345 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3346 | // Do the runtime call to execute the regexp. |
| 3347 | __ bind(&runtime); |
| 3348 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3349 | #endif // V8_INTERPRETED_REGEXP |
| 3350 | } |
| 3351 | |
| 3352 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3353 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 3354 | const int kMaxInlineLength = 100; |
| 3355 | Label slowcase; |
| 3356 | Label done; |
| 3357 | __ movq(r8, Operand(rsp, kPointerSize * 3)); |
| 3358 | __ JumpIfNotSmi(r8, &slowcase); |
| 3359 | __ SmiToInteger32(rbx, r8); |
| 3360 | __ cmpl(rbx, Immediate(kMaxInlineLength)); |
| 3361 | __ j(above, &slowcase); |
| 3362 | // Smi-tagging is equivalent to multiplying by 2. |
| 3363 | STATIC_ASSERT(kSmiTag == 0); |
| 3364 | STATIC_ASSERT(kSmiTagSize == 1); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3365 | // Allocate RegExpResult followed by FixedArray with size in rbx. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3366 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 3367 | // Elements: [Map][Length][..elements..] |
| 3368 | __ AllocateInNewSpace(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 3369 | times_pointer_size, |
| 3370 | rbx, // In: Number of elements. |
| 3371 | rax, // Out: Start of allocation (tagged). |
| 3372 | rcx, // Out: End of allocation. |
| 3373 | rdx, // Scratch register |
| 3374 | &slowcase, |
| 3375 | TAG_OBJECT); |
| 3376 | // rax: Start of allocated area, object-tagged. |
| 3377 | // rbx: Number of array elements as int32. |
| 3378 | // r8: Number of array elements as smi. |
| 3379 | |
| 3380 | // Set JSArray map to global.regexp_result_map(). |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3381 | __ movq(rdx, ContextOperand(rsi, Context::GLOBAL_OBJECT_INDEX)); |
| 3382 | __ movq(rdx, FieldOperand(rdx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3383 | __ movq(rdx, ContextOperand(rdx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 3384 | __ movq(FieldOperand(rax, HeapObject::kMapOffset), rdx); |
| 3385 | |
| 3386 | // Set empty properties FixedArray. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3387 | __ LoadRoot(kScratchRegister, Heap::kEmptyFixedArrayRootIndex); |
| 3388 | __ movq(FieldOperand(rax, JSObject::kPropertiesOffset), kScratchRegister); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3389 | |
| 3390 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 3391 | __ lea(rcx, Operand(rax, JSRegExpResult::kSize)); |
| 3392 | __ movq(FieldOperand(rax, JSObject::kElementsOffset), rcx); |
| 3393 | |
| 3394 | // Set input, index and length fields from arguments. |
| 3395 | __ movq(r8, Operand(rsp, kPointerSize * 1)); |
| 3396 | __ movq(FieldOperand(rax, JSRegExpResult::kInputOffset), r8); |
| 3397 | __ movq(r8, Operand(rsp, kPointerSize * 2)); |
| 3398 | __ movq(FieldOperand(rax, JSRegExpResult::kIndexOffset), r8); |
| 3399 | __ movq(r8, Operand(rsp, kPointerSize * 3)); |
| 3400 | __ movq(FieldOperand(rax, JSArray::kLengthOffset), r8); |
| 3401 | |
| 3402 | // Fill out the elements FixedArray. |
| 3403 | // rax: JSArray. |
| 3404 | // rcx: FixedArray. |
| 3405 | // rbx: Number of elements in array as int32. |
| 3406 | |
| 3407 | // Set map. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3408 | __ LoadRoot(kScratchRegister, Heap::kFixedArrayMapRootIndex); |
| 3409 | __ movq(FieldOperand(rcx, HeapObject::kMapOffset), kScratchRegister); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3410 | // Set length. |
| 3411 | __ Integer32ToSmi(rdx, rbx); |
| 3412 | __ movq(FieldOperand(rcx, FixedArray::kLengthOffset), rdx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3413 | // Fill contents of fixed-array with undefined. |
| 3414 | __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3415 | __ lea(rcx, FieldOperand(rcx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3416 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3417 | // rax: JSArray. |
| 3418 | // rbx: Number of elements in array that remains to be filled, as int32. |
| 3419 | // rcx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3420 | // rdx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3421 | Label loop; |
| 3422 | __ testl(rbx, rbx); |
| 3423 | __ bind(&loop); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3424 | __ j(less_equal, &done); // Jump if rcx is negative or zero. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3425 | __ subl(rbx, Immediate(1)); |
| 3426 | __ movq(Operand(rcx, rbx, times_pointer_size, 0), rdx); |
| 3427 | __ jmp(&loop); |
| 3428 | |
| 3429 | __ bind(&done); |
| 3430 | __ ret(3 * kPointerSize); |
| 3431 | |
| 3432 | __ bind(&slowcase); |
| 3433 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 3434 | } |
| 3435 | |
| 3436 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3437 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 3438 | Register object, |
| 3439 | Register result, |
| 3440 | Register scratch1, |
| 3441 | Register scratch2, |
| 3442 | bool object_is_smi, |
| 3443 | Label* not_found) { |
| 3444 | // Use of registers. Register result is used as a temporary. |
| 3445 | Register number_string_cache = result; |
| 3446 | Register mask = scratch1; |
| 3447 | Register scratch = scratch2; |
| 3448 | |
| 3449 | // Load the number string cache. |
| 3450 | __ LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex); |
| 3451 | |
| 3452 | // Make the hash mask from the length of the number string cache. It |
| 3453 | // contains two elements (number and string) for each cache entry. |
| 3454 | __ SmiToInteger32( |
| 3455 | mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 3456 | __ shrl(mask, Immediate(1)); |
| 3457 | __ subq(mask, Immediate(1)); // Make mask. |
| 3458 | |
| 3459 | // Calculate the entry in the number string cache. The hash value in the |
| 3460 | // number string cache for smis is just the smi value, and the hash for |
| 3461 | // doubles is the xor of the upper and lower words. See |
| 3462 | // Heap::GetNumberStringCache. |
| 3463 | Label is_smi; |
| 3464 | Label load_result_from_cache; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3465 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3466 | if (!object_is_smi) { |
| 3467 | __ JumpIfSmi(object, &is_smi); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3468 | __ CheckMap(object, |
| 3469 | factory->heap_number_map(), |
| 3470 | not_found, |
| 3471 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3472 | |
| 3473 | STATIC_ASSERT(8 == kDoubleSize); |
| 3474 | __ movl(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 3475 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 3476 | GenerateConvertHashCodeToIndex(masm, scratch, mask); |
| 3477 | |
| 3478 | Register index = scratch; |
| 3479 | Register probe = mask; |
| 3480 | __ movq(probe, |
| 3481 | FieldOperand(number_string_cache, |
| 3482 | index, |
| 3483 | times_1, |
| 3484 | FixedArray::kHeaderSize)); |
| 3485 | __ JumpIfSmi(probe, not_found); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3486 | __ movsd(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 3487 | __ movsd(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 3488 | __ ucomisd(xmm0, xmm1); |
| 3489 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 3490 | __ j(not_equal, not_found); // The cache did not contain this value. |
| 3491 | __ jmp(&load_result_from_cache); |
| 3492 | } |
| 3493 | |
| 3494 | __ bind(&is_smi); |
| 3495 | __ SmiToInteger32(scratch, object); |
| 3496 | GenerateConvertHashCodeToIndex(masm, scratch, mask); |
| 3497 | |
| 3498 | Register index = scratch; |
| 3499 | // Check if the entry is the smi we are looking for. |
| 3500 | __ cmpq(object, |
| 3501 | FieldOperand(number_string_cache, |
| 3502 | index, |
| 3503 | times_1, |
| 3504 | FixedArray::kHeaderSize)); |
| 3505 | __ j(not_equal, not_found); |
| 3506 | |
| 3507 | // Get the result from the cache. |
| 3508 | __ bind(&load_result_from_cache); |
| 3509 | __ movq(result, |
| 3510 | FieldOperand(number_string_cache, |
| 3511 | index, |
| 3512 | times_1, |
| 3513 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3514 | Counters* counters = masm->isolate()->counters(); |
| 3515 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | |
| 3519 | void NumberToStringStub::GenerateConvertHashCodeToIndex(MacroAssembler* masm, |
| 3520 | Register hash, |
| 3521 | Register mask) { |
| 3522 | __ and_(hash, mask); |
| 3523 | // Each entry in string cache consists of two pointer sized fields, |
| 3524 | // but times_twice_pointer_size (multiplication by 16) scale factor |
| 3525 | // is not supported by addrmode on x64 platform. |
| 3526 | // So we have to premultiply entry index before lookup. |
| 3527 | __ shl(hash, Immediate(kPointerSizeLog2 + 1)); |
| 3528 | } |
| 3529 | |
| 3530 | |
| 3531 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 3532 | Label runtime; |
| 3533 | |
| 3534 | __ movq(rbx, Operand(rsp, kPointerSize)); |
| 3535 | |
| 3536 | // Generate code to lookup number in the number string cache. |
| 3537 | GenerateLookupNumberStringCache(masm, rbx, rax, r8, r9, false, &runtime); |
| 3538 | __ ret(1 * kPointerSize); |
| 3539 | |
| 3540 | __ bind(&runtime); |
| 3541 | // Handle number to string in the runtime system if not found in the cache. |
| 3542 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 3543 | } |
| 3544 | |
| 3545 | |
| 3546 | static int NegativeComparisonResult(Condition cc) { |
| 3547 | ASSERT(cc != equal); |
| 3548 | ASSERT((cc == less) || (cc == less_equal) |
| 3549 | || (cc == greater) || (cc == greater_equal)); |
| 3550 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 3551 | } |
| 3552 | |
| 3553 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3554 | static void CheckInputType(MacroAssembler* masm, |
| 3555 | Register input, |
| 3556 | CompareIC::State expected, |
| 3557 | Label* fail) { |
| 3558 | Label ok; |
| 3559 | if (expected == CompareIC::SMI) { |
| 3560 | __ JumpIfNotSmi(input, fail); |
| 3561 | } else if (expected == CompareIC::HEAP_NUMBER) { |
| 3562 | __ JumpIfSmi(input, &ok); |
| 3563 | __ CompareMap(input, masm->isolate()->factory()->heap_number_map(), NULL); |
| 3564 | __ j(not_equal, fail); |
| 3565 | } |
| 3566 | // We could be strict about symbol/string here, but as long as |
| 3567 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 3568 | __ bind(&ok); |
| 3569 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3570 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3571 | |
| 3572 | static void BranchIfNonSymbol(MacroAssembler* masm, |
| 3573 | Label* label, |
| 3574 | Register object, |
| 3575 | Register scratch) { |
| 3576 | __ JumpIfSmi(object, label); |
| 3577 | __ movq(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 3578 | __ movzxbq(scratch, |
| 3579 | FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 3580 | // Ensure that no non-strings have the symbol bit set. |
| 3581 | STATIC_ASSERT(LAST_TYPE < kNotStringTag + kIsSymbolMask); |
| 3582 | STATIC_ASSERT(kSymbolTag != 0); |
| 3583 | __ testb(scratch, Immediate(kIsSymbolMask)); |
| 3584 | __ j(zero, label); |
| 3585 | } |
| 3586 | |
| 3587 | |
| 3588 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3589 | Label check_unequal_objects, done; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3590 | Condition cc = GetCondition(); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3591 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3592 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3593 | Label miss; |
| 3594 | CheckInputType(masm, rdx, left_, &miss); |
| 3595 | CheckInputType(masm, rax, right_, &miss); |
| 3596 | |
| 3597 | // Compare two smis. |
| 3598 | Label non_smi, smi_done; |
| 3599 | __ JumpIfNotBothSmi(rax, rdx, &non_smi); |
| 3600 | __ subq(rdx, rax); |
| 3601 | __ j(no_overflow, &smi_done); |
| 3602 | __ not_(rdx); // Correct sign in case of overflow. rdx cannot be 0 here. |
| 3603 | __ bind(&smi_done); |
| 3604 | __ movq(rax, rdx); |
| 3605 | __ ret(0); |
| 3606 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3607 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3608 | // The compare stub returns a positive, negative, or zero 64-bit integer |
| 3609 | // value in rax, corresponding to result of comparing the two inputs. |
| 3610 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 3611 | // it is certain that at least one operand isn't a smi. |
| 3612 | |
| 3613 | // Two identical objects are equal unless they are both NaN or undefined. |
| 3614 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3615 | Label not_identical; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3616 | __ cmpq(rax, rdx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3617 | __ j(not_equal, ¬_identical, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3618 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3619 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3620 | // Check for undefined. undefined OP undefined is false even though |
| 3621 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3622 | Label check_for_nan; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3623 | __ CompareRoot(rdx, Heap::kUndefinedValueRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3624 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3625 | __ Set(rax, NegativeComparisonResult(cc)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3626 | __ ret(0); |
| 3627 | __ bind(&check_for_nan); |
| 3628 | } |
| 3629 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3630 | // 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] | 3631 | // so we do the second best thing - test it ourselves. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3632 | Label heap_number; |
| 3633 | // If it's not a heap number, then return equal for (in)equality operator. |
| 3634 | __ Cmp(FieldOperand(rdx, HeapObject::kMapOffset), |
| 3635 | factory->heap_number_map()); |
| 3636 | __ j(equal, &heap_number, Label::kNear); |
| 3637 | if (cc != equal) { |
| 3638 | // Call runtime on identical objects. Otherwise return equal. |
| 3639 | __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx); |
| 3640 | __ j(above_equal, ¬_identical, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3641 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3642 | __ Set(rax, EQUAL); |
| 3643 | __ ret(0); |
| 3644 | |
| 3645 | __ bind(&heap_number); |
| 3646 | // It is a heap number, so return equal if it's not NaN. |
| 3647 | // For NaN, return 1 for every condition except greater and |
| 3648 | // greater-equal. Return -1 for them, so the comparison yields |
| 3649 | // false for all conditions except not-equal. |
| 3650 | __ Set(rax, EQUAL); |
| 3651 | __ movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset)); |
| 3652 | __ ucomisd(xmm0, xmm0); |
| 3653 | __ setcc(parity_even, rax); |
| 3654 | // rax is 0 for equal non-NaN heapnumbers, 1 for NaNs. |
| 3655 | if (cc == greater_equal || cc == greater) { |
| 3656 | __ neg(rax); |
| 3657 | } |
| 3658 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3659 | |
| 3660 | __ bind(¬_identical); |
| 3661 | } |
| 3662 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3663 | if (cc == equal) { // Both strict and non-strict. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3664 | Label slow; // Fallthrough label. |
| 3665 | |
| 3666 | // If we're doing a strict equality comparison, we don't have to do |
| 3667 | // type conversion, so we generate code to do fast comparison for objects |
| 3668 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 3669 | // slow-case code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3670 | if (strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3671 | // If either is a Smi (we know that not both are), then they can only |
| 3672 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 3673 | { |
| 3674 | Label not_smis; |
| 3675 | __ SelectNonSmi(rbx, rax, rdx, ¬_smis); |
| 3676 | |
| 3677 | // Check if the non-smi operand is a heap number. |
| 3678 | __ Cmp(FieldOperand(rbx, HeapObject::kMapOffset), |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3679 | factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3680 | // If heap number, handle it in the slow case. |
| 3681 | __ j(equal, &slow); |
| 3682 | // Return non-equal. ebx (the lower half of rbx) is not zero. |
| 3683 | __ movq(rax, rbx); |
| 3684 | __ ret(0); |
| 3685 | |
| 3686 | __ bind(¬_smis); |
| 3687 | } |
| 3688 | |
| 3689 | // If either operand is a JSObject or an oddball value, then they are not |
| 3690 | // equal since their pointers are different |
| 3691 | // There is no test for undetectability in strict equality. |
| 3692 | |
| 3693 | // If the first object is a JS object, we have done pointer comparison. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3694 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3695 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3696 | __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3697 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3698 | // Return non-zero (eax (not rax) is not zero) |
| 3699 | Label return_not_equal; |
| 3700 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 3701 | __ bind(&return_not_equal); |
| 3702 | __ ret(0); |
| 3703 | |
| 3704 | __ bind(&first_non_object); |
| 3705 | // Check for oddballs: true, false, null, undefined. |
| 3706 | __ CmpInstanceType(rcx, ODDBALL_TYPE); |
| 3707 | __ j(equal, &return_not_equal); |
| 3708 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3709 | __ CmpObjectType(rdx, FIRST_SPEC_OBJECT_TYPE, rcx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3710 | __ j(above_equal, &return_not_equal); |
| 3711 | |
| 3712 | // Check for oddballs: true, false, null, undefined. |
| 3713 | __ CmpInstanceType(rcx, ODDBALL_TYPE); |
| 3714 | __ j(equal, &return_not_equal); |
| 3715 | |
| 3716 | // Fall through to the general case. |
| 3717 | } |
| 3718 | __ bind(&slow); |
| 3719 | } |
| 3720 | |
| 3721 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3722 | Label non_number_comparison; |
| 3723 | Label unordered; |
| 3724 | FloatingPointHelper::LoadSSE2UnknownOperands(masm, &non_number_comparison); |
| 3725 | __ xorl(rax, rax); |
| 3726 | __ xorl(rcx, rcx); |
| 3727 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3728 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3729 | // Don't base result on EFLAGS when a NaN is involved. |
| 3730 | __ j(parity_even, &unordered, Label::kNear); |
| 3731 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 3732 | __ setcc(above, rax); |
| 3733 | __ setcc(below, rcx); |
| 3734 | __ subq(rax, rcx); |
| 3735 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3736 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3737 | // If one of the numbers was NaN, then the result is always false. |
| 3738 | // The cc is never not-equal. |
| 3739 | __ bind(&unordered); |
| 3740 | ASSERT(cc != not_equal); |
| 3741 | if (cc == less || cc == less_equal) { |
| 3742 | __ Set(rax, 1); |
| 3743 | } else { |
| 3744 | __ Set(rax, -1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3745 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3746 | __ ret(0); |
| 3747 | |
| 3748 | // The number comparison code did not provide a valid result. |
| 3749 | __ bind(&non_number_comparison); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3750 | |
| 3751 | // Fast negative check for symbol-to-symbol equality. |
| 3752 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3753 | if (cc == equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3754 | BranchIfNonSymbol(masm, &check_for_strings, rax, kScratchRegister); |
| 3755 | BranchIfNonSymbol(masm, &check_for_strings, rdx, kScratchRegister); |
| 3756 | |
| 3757 | // We've already checked for object identity, so if both operands |
| 3758 | // are symbols they aren't equal. Register eax (not rax) already holds a |
| 3759 | // non-zero value, which indicates not equal, so just return. |
| 3760 | __ ret(0); |
| 3761 | } |
| 3762 | |
| 3763 | __ bind(&check_for_strings); |
| 3764 | |
| 3765 | __ JumpIfNotBothSequentialAsciiStrings( |
| 3766 | rdx, rax, rcx, rbx, &check_unequal_objects); |
| 3767 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3768 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3769 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3770 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3771 | rdx, |
| 3772 | rax, |
| 3773 | rcx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3774 | rbx); |
| 3775 | } else { |
| 3776 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 3777 | rdx, |
| 3778 | rax, |
| 3779 | rcx, |
| 3780 | rbx, |
| 3781 | rdi, |
| 3782 | r8); |
| 3783 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3784 | |
| 3785 | #ifdef DEBUG |
| 3786 | __ Abort("Unexpected fall-through from string comparison"); |
| 3787 | #endif |
| 3788 | |
| 3789 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3790 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3791 | // Not strict equality. Objects are unequal if |
| 3792 | // they are both JSObjects and not undetectable, |
| 3793 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3794 | Label not_both_objects, return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3795 | // At most one is a smi, so we can test for smi by adding the two. |
| 3796 | // A smi plus a heap object has the low bit set, a heap object plus |
| 3797 | // a heap object has the low bit clear. |
| 3798 | STATIC_ASSERT(kSmiTag == 0); |
| 3799 | STATIC_ASSERT(kSmiTagMask == 1); |
| 3800 | __ lea(rcx, Operand(rax, rdx, times_1, 0)); |
| 3801 | __ testb(rcx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3802 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3803 | __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rbx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3804 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3805 | __ CmpObjectType(rdx, FIRST_SPEC_OBJECT_TYPE, rcx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3806 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3807 | __ testb(FieldOperand(rbx, Map::kBitFieldOffset), |
| 3808 | Immediate(1 << Map::kIsUndetectable)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3809 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3810 | __ testb(FieldOperand(rcx, Map::kBitFieldOffset), |
| 3811 | Immediate(1 << Map::kIsUndetectable)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3812 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3813 | // The objects are both undetectable, so they both compare as the value |
| 3814 | // undefined, and are equal. |
| 3815 | __ Set(rax, EQUAL); |
| 3816 | __ bind(&return_unequal); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3817 | // Return non-equal by returning the non-zero object pointer in rax, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3818 | // or return equal if we fell through to here. |
| 3819 | __ ret(0); |
| 3820 | __ bind(¬_both_objects); |
| 3821 | } |
| 3822 | |
| 3823 | // Push arguments below the return address to prepare jump to builtin. |
| 3824 | __ pop(rcx); |
| 3825 | __ push(rdx); |
| 3826 | __ push(rax); |
| 3827 | |
| 3828 | // Figure out which native to call and setup the arguments. |
| 3829 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3830 | if (cc == equal) { |
| 3831 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3832 | } else { |
| 3833 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3834 | __ Push(Smi::FromInt(NegativeComparisonResult(cc))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | // Restore return address on the stack. |
| 3838 | __ push(rcx); |
| 3839 | |
| 3840 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 3841 | // tagged as a small integer. |
| 3842 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3843 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3844 | __ bind(&miss); |
| 3845 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3846 | } |
| 3847 | |
| 3848 | |
| 3849 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 3850 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3851 | } |
| 3852 | |
| 3853 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3854 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 3855 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 3856 | } |
| 3857 | |
| 3858 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3859 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 3860 | // Cache the called function in a global property cell. Cache states |
| 3861 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 3862 | // megamorphic. |
| 3863 | // rbx : cache cell for call target |
| 3864 | // rdi : the function to call |
| 3865 | Isolate* isolate = masm->isolate(); |
| 3866 | Label initialize, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3867 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3868 | // Load the cache state into rcx. |
| 3869 | __ movq(rcx, FieldOperand(rbx, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3870 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3871 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 3872 | // function without changing the state. |
| 3873 | __ cmpq(rcx, rdi); |
| 3874 | __ j(equal, &done, Label::kNear); |
| 3875 | __ Cmp(rcx, TypeFeedbackCells::MegamorphicSentinel(isolate)); |
| 3876 | __ j(equal, &done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3877 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3878 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 3879 | // megamorphic. |
| 3880 | __ Cmp(rcx, TypeFeedbackCells::UninitializedSentinel(isolate)); |
| 3881 | __ j(equal, &initialize, Label::kNear); |
| 3882 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 3883 | // write-barrier is needed. |
| 3884 | __ Move(FieldOperand(rbx, JSGlobalPropertyCell::kValueOffset), |
| 3885 | TypeFeedbackCells::MegamorphicSentinel(isolate)); |
| 3886 | __ jmp(&done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3887 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3888 | // An uninitialized cache is patched with the function. |
| 3889 | __ bind(&initialize); |
| 3890 | __ movq(FieldOperand(rbx, JSGlobalPropertyCell::kValueOffset), rdi); |
| 3891 | // No need for a write barrier here - cells are rescanned. |
| 3892 | |
| 3893 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3897 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3898 | // rbx : cache cell for call target |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 3899 | // rdi : the function to call |
| 3900 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3901 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3902 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3903 | // The receiver might implicitly be the global object. This is |
| 3904 | // indicated by passing the hole as the receiver to the call |
| 3905 | // function stub. |
| 3906 | if (ReceiverMightBeImplicit()) { |
| 3907 | Label call; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3908 | // Get the receiver from the stack. |
| 3909 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3910 | __ movq(rax, Operand(rsp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3911 | // Call as function is indicated with the hole. |
| 3912 | __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); |
| 3913 | __ j(not_equal, &call, Label::kNear); |
| 3914 | // Patch the receiver on the stack with the global receiver object. |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 3915 | __ movq(rcx, GlobalObjectOperand()); |
| 3916 | __ movq(rcx, FieldOperand(rcx, GlobalObject::kGlobalReceiverOffset)); |
| 3917 | __ movq(Operand(rsp, (argc_ + 1) * kPointerSize), rcx); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3918 | __ bind(&call); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3919 | } |
| 3920 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3921 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3922 | __ JumpIfSmi(rdi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3923 | // Goto slow case if we do not have a function. |
| 3924 | __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); |
| 3925 | __ j(not_equal, &slow); |
| 3926 | |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 3927 | if (RecordCallTarget()) { |
| 3928 | GenerateRecordCallTarget(masm); |
| 3929 | } |
| 3930 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3931 | // Fast-case: Just invoke the function. |
| 3932 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3933 | |
| 3934 | if (ReceiverMightBeImplicit()) { |
| 3935 | Label call_as_function; |
| 3936 | __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); |
| 3937 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3938 | __ InvokeFunction(rdi, |
| 3939 | actual, |
| 3940 | JUMP_FUNCTION, |
| 3941 | NullCallWrapper(), |
| 3942 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3943 | __ bind(&call_as_function); |
| 3944 | } |
| 3945 | __ InvokeFunction(rdi, |
| 3946 | actual, |
| 3947 | JUMP_FUNCTION, |
| 3948 | NullCallWrapper(), |
| 3949 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3950 | |
| 3951 | // Slow-case: Non-function called. |
| 3952 | __ bind(&slow); |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 3953 | if (RecordCallTarget()) { |
| 3954 | // If there is a call target cache, mark it megamorphic in the |
| 3955 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 3956 | // object (undefined) so no write barrier is needed. |
| 3957 | __ Move(FieldOperand(rbx, JSGlobalPropertyCell::kValueOffset), |
| 3958 | TypeFeedbackCells::MegamorphicSentinel(isolate)); |
| 3959 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3960 | // Check for function proxy. |
| 3961 | __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE); |
| 3962 | __ j(not_equal, &non_function); |
| 3963 | __ pop(rcx); |
| 3964 | __ push(rdi); // put proxy as additional argument under return address |
| 3965 | __ push(rcx); |
| 3966 | __ Set(rax, argc_ + 1); |
| 3967 | __ Set(rbx, 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3968 | __ SetCallKind(rcx, CALL_AS_METHOD); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3969 | __ GetBuiltinEntry(rdx, Builtins::CALL_FUNCTION_PROXY); |
| 3970 | { |
| 3971 | Handle<Code> adaptor = |
| 3972 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 3973 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 3974 | } |
| 3975 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3976 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 3977 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3978 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3979 | __ movq(Operand(rsp, (argc_ + 1) * kPointerSize), rdi); |
| 3980 | __ Set(rax, argc_); |
| 3981 | __ Set(rbx, 0); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3982 | __ SetCallKind(rcx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3983 | __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3984 | Handle<Code> adaptor = |
| 3985 | Isolate::Current()->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3986 | __ Jump(adaptor, RelocInfo::CODE_TARGET); |
| 3987 | } |
| 3988 | |
| 3989 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3990 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 3991 | // rax : number of arguments |
| 3992 | // rbx : cache cell for call target |
| 3993 | // rdi : constructor function |
| 3994 | Label slow, non_function_call; |
| 3995 | |
| 3996 | // Check that function is not a smi. |
| 3997 | __ JumpIfSmi(rdi, &non_function_call); |
| 3998 | // Check that function is a JSFunction. |
| 3999 | __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); |
| 4000 | __ j(not_equal, &slow); |
| 4001 | |
| 4002 | if (RecordCallTarget()) { |
| 4003 | GenerateRecordCallTarget(masm); |
| 4004 | } |
| 4005 | |
| 4006 | // Jump to the function-specific construct stub. |
| 4007 | __ movq(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
| 4008 | __ movq(rbx, FieldOperand(rbx, SharedFunctionInfo::kConstructStubOffset)); |
| 4009 | __ lea(rbx, FieldOperand(rbx, Code::kHeaderSize)); |
| 4010 | __ jmp(rbx); |
| 4011 | |
| 4012 | // rdi: called object |
| 4013 | // rax: number of arguments |
| 4014 | // rcx: object map |
| 4015 | Label do_call; |
| 4016 | __ bind(&slow); |
| 4017 | __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE); |
| 4018 | __ j(not_equal, &non_function_call); |
| 4019 | __ GetBuiltinEntry(rdx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4020 | __ jmp(&do_call); |
| 4021 | |
| 4022 | __ bind(&non_function_call); |
| 4023 | __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4024 | __ bind(&do_call); |
| 4025 | // Set expected number of arguments to zero (not changing rax). |
| 4026 | __ Set(rbx, 0); |
| 4027 | __ SetCallKind(rcx, CALL_AS_METHOD); |
| 4028 | __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 4029 | RelocInfo::CODE_TARGET); |
| 4030 | } |
| 4031 | |
| 4032 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4033 | bool CEntryStub::NeedsImmovableCode() { |
| 4034 | return false; |
| 4035 | } |
| 4036 | |
| 4037 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4038 | bool CEntryStub::IsPregenerated() { |
| 4039 | #ifdef _WIN64 |
| 4040 | return result_size_ == 1; |
| 4041 | #else |
| 4042 | return true; |
| 4043 | #endif |
| 4044 | } |
| 4045 | |
| 4046 | |
| 4047 | void CodeStub::GenerateStubsAheadOfTime() { |
| 4048 | CEntryStub::GenerateAheadOfTime(); |
| 4049 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(); |
| 4050 | // It is important that the store buffer overflow stubs are generated first. |
| 4051 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(); |
| 4052 | } |
| 4053 | |
| 4054 | |
| 4055 | void CodeStub::GenerateFPStubs() { |
| 4056 | } |
| 4057 | |
| 4058 | |
| 4059 | void CEntryStub::GenerateAheadOfTime() { |
| 4060 | CEntryStub stub(1, kDontSaveFPRegs); |
| 4061 | stub.GetCode()->set_is_pregenerated(true); |
| 4062 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4063 | save_doubles.GetCode()->set_is_pregenerated(true); |
| 4064 | } |
| 4065 | |
| 4066 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4067 | static void JumpIfOOM(MacroAssembler* masm, |
| 4068 | Register value, |
| 4069 | Register scratch, |
| 4070 | Label* oom_label) { |
| 4071 | __ movq(scratch, value); |
| 4072 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 4073 | STATIC_ASSERT(kFailureTag == 3); |
| 4074 | __ and_(scratch, Immediate(0xf)); |
| 4075 | __ cmpq(scratch, Immediate(0xf)); |
| 4076 | __ j(equal, oom_label); |
| 4077 | } |
| 4078 | |
| 4079 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4080 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 4081 | Label* throw_normal_exception, |
| 4082 | Label* throw_termination_exception, |
| 4083 | Label* throw_out_of_memory_exception, |
| 4084 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4085 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4086 | // rax: result parameter for PerformGC, if any. |
| 4087 | // rbx: pointer to C function (C callee-saved). |
| 4088 | // rbp: frame pointer (restored after C call). |
| 4089 | // rsp: stack pointer (restored after C call). |
| 4090 | // r14: number of arguments including receiver (C callee-saved). |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4091 | // r15: pointer to the first argument (C callee-saved). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4092 | // This pointer is reused in LeaveExitFrame(), so it is stored in a |
| 4093 | // callee-saved register. |
| 4094 | |
| 4095 | // Simple results returned in rax (both AMD64 and Win64 calling conventions). |
| 4096 | // Complex results must be written to address passed as first argument. |
| 4097 | // AMD64 calling convention: a struct of two pointers in rax+rdx |
| 4098 | |
| 4099 | // Check stack alignment. |
| 4100 | if (FLAG_debug_code) { |
| 4101 | __ CheckStackAlignment(); |
| 4102 | } |
| 4103 | |
| 4104 | if (do_gc) { |
| 4105 | // Pass failure code returned from last attempt as first argument to |
| 4106 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 4107 | // stack is known to be aligned. This function takes one argument which is |
| 4108 | // passed in register. |
| 4109 | #ifdef _WIN64 |
| 4110 | __ movq(rcx, rax); |
| 4111 | #else // _WIN64 |
| 4112 | __ movq(rdi, rax); |
| 4113 | #endif |
| 4114 | __ movq(kScratchRegister, |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4115 | ExternalReference::perform_gc_function(masm->isolate())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4116 | __ call(kScratchRegister); |
| 4117 | } |
| 4118 | |
| 4119 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4120 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4121 | if (always_allocate_scope) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4122 | Operand scope_depth_operand = masm->ExternalOperand(scope_depth); |
| 4123 | __ incl(scope_depth_operand); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4124 | } |
| 4125 | |
| 4126 | // Call C function. |
| 4127 | #ifdef _WIN64 |
| 4128 | // Windows 64-bit ABI passes arguments in rcx, rdx, r8, r9 |
| 4129 | // Store Arguments object on stack, below the 4 WIN64 ABI parameter slots. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4130 | __ movq(StackSpaceOperand(0), r14); // argc. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4131 | __ movq(StackSpaceOperand(1), r15); // argv. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4132 | if (result_size_ < 2) { |
| 4133 | // Pass a pointer to the Arguments object as the first argument. |
| 4134 | // Return result in single register (rax). |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4135 | __ lea(rcx, StackSpaceOperand(0)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4136 | __ LoadAddress(rdx, ExternalReference::isolate_address()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4137 | } else { |
| 4138 | ASSERT_EQ(2, result_size_); |
| 4139 | // Pass a pointer to the result location as the first argument. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4140 | __ lea(rcx, StackSpaceOperand(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4141 | // Pass a pointer to the Arguments object as the second argument. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4142 | __ lea(rdx, StackSpaceOperand(0)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4143 | __ LoadAddress(r8, ExternalReference::isolate_address()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4144 | } |
| 4145 | |
| 4146 | #else // _WIN64 |
| 4147 | // GCC passes arguments in rdi, rsi, rdx, rcx, r8, r9. |
| 4148 | __ movq(rdi, r14); // argc. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4149 | __ movq(rsi, r15); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4150 | __ movq(rdx, ExternalReference::isolate_address()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4151 | #endif |
| 4152 | __ call(rbx); |
| 4153 | // Result is in rax - do not destroy this register! |
| 4154 | |
| 4155 | if (always_allocate_scope) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4156 | Operand scope_depth_operand = masm->ExternalOperand(scope_depth); |
| 4157 | __ decl(scope_depth_operand); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4158 | } |
| 4159 | |
| 4160 | // Check for failure result. |
| 4161 | Label failure_returned; |
| 4162 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 4163 | #ifdef _WIN64 |
| 4164 | // If return value is on the stack, pop it to registers. |
| 4165 | if (result_size_ > 1) { |
| 4166 | ASSERT_EQ(2, result_size_); |
| 4167 | // Read result values stored on stack. Result is stored |
| 4168 | // above the four argument mirror slots and the two |
| 4169 | // Arguments object slots. |
| 4170 | __ movq(rax, Operand(rsp, 6 * kPointerSize)); |
| 4171 | __ movq(rdx, Operand(rsp, 7 * kPointerSize)); |
| 4172 | } |
| 4173 | #endif |
| 4174 | __ lea(rcx, Operand(rax, 1)); |
| 4175 | // Lower 2 bits of rcx are 0 iff rax has failure tag. |
| 4176 | __ testl(rcx, Immediate(kFailureTagMask)); |
| 4177 | __ j(zero, &failure_returned); |
| 4178 | |
| 4179 | // Exit the JavaScript to C++ exit frame. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4180 | __ LeaveExitFrame(save_doubles_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4181 | __ ret(0); |
| 4182 | |
| 4183 | // Handling of failure. |
| 4184 | __ bind(&failure_returned); |
| 4185 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4186 | Label retry; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4187 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 4188 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 4189 | __ testl(rax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4190 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4191 | |
| 4192 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4193 | JumpIfOOM(masm, rax, kScratchRegister, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4194 | |
| 4195 | // Retrieve the pending exception and clear the variable. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4196 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4197 | Isolate::kPendingExceptionAddress, masm->isolate()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4198 | Operand pending_exception_operand = |
| 4199 | masm->ExternalOperand(pending_exception_address); |
| 4200 | __ movq(rax, pending_exception_operand); |
| 4201 | __ LoadRoot(rdx, Heap::kTheHoleValueRootIndex); |
| 4202 | __ movq(pending_exception_operand, rdx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4203 | |
| 4204 | // Special handling of termination exceptions which are uncatchable |
| 4205 | // by javascript code. |
| 4206 | __ CompareRoot(rax, Heap::kTerminationExceptionRootIndex); |
| 4207 | __ j(equal, throw_termination_exception); |
| 4208 | |
| 4209 | // Handle normal exception. |
| 4210 | __ jmp(throw_normal_exception); |
| 4211 | |
| 4212 | // Retry. |
| 4213 | __ bind(&retry); |
| 4214 | } |
| 4215 | |
| 4216 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4217 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 4218 | // rax: number of arguments including receiver |
| 4219 | // rbx: pointer to C function (C callee-saved) |
| 4220 | // rbp: frame pointer of calling JS frame (restored after C call) |
| 4221 | // rsp: stack pointer (restored after C call) |
| 4222 | // rsi: current context (restored) |
| 4223 | |
| 4224 | // NOTE: Invocations of builtins may return failure objects |
| 4225 | // instead of a proper result. The builtin entry handles |
| 4226 | // this by performing a garbage collection and retrying the |
| 4227 | // builtin once. |
| 4228 | |
| 4229 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4230 | #ifdef _WIN64 |
| 4231 | int arg_stack_space = (result_size_ < 2 ? 2 : 4); |
| 4232 | #else |
| 4233 | int arg_stack_space = 0; |
| 4234 | #endif |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4235 | __ EnterExitFrame(arg_stack_space, save_doubles_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4236 | |
| 4237 | // rax: Holds the context at this point, but should not be used. |
| 4238 | // On entry to code generated by GenerateCore, it must hold |
| 4239 | // a failure result if the collect_garbage argument to GenerateCore |
| 4240 | // is true. This failure result can be the result of code |
| 4241 | // generated by a previous call to GenerateCore. The value |
| 4242 | // of rax is then passed to Runtime::PerformGC. |
| 4243 | // rbx: pointer to builtin function (C callee-saved). |
| 4244 | // rbp: frame pointer of exit frame (restored after C call). |
| 4245 | // rsp: stack pointer (restored after C call). |
| 4246 | // r14: number of arguments including receiver (C callee-saved). |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4247 | // r15: argv pointer (C callee-saved). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4248 | |
| 4249 | Label throw_normal_exception; |
| 4250 | Label throw_termination_exception; |
| 4251 | Label throw_out_of_memory_exception; |
| 4252 | |
| 4253 | // Call into the runtime system. |
| 4254 | GenerateCore(masm, |
| 4255 | &throw_normal_exception, |
| 4256 | &throw_termination_exception, |
| 4257 | &throw_out_of_memory_exception, |
| 4258 | false, |
| 4259 | false); |
| 4260 | |
| 4261 | // Do space-specific GC and retry runtime call. |
| 4262 | GenerateCore(masm, |
| 4263 | &throw_normal_exception, |
| 4264 | &throw_termination_exception, |
| 4265 | &throw_out_of_memory_exception, |
| 4266 | true, |
| 4267 | false); |
| 4268 | |
| 4269 | // Do full GC and retry runtime call one final time. |
| 4270 | Failure* failure = Failure::InternalError(); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4271 | __ movq(rax, failure, RelocInfo::NONE64); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4272 | GenerateCore(masm, |
| 4273 | &throw_normal_exception, |
| 4274 | &throw_termination_exception, |
| 4275 | &throw_out_of_memory_exception, |
| 4276 | true, |
| 4277 | true); |
| 4278 | |
| 4279 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4280 | // Set external caught exception to false. |
| 4281 | Isolate* isolate = masm->isolate(); |
| 4282 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 4283 | isolate); |
| 4284 | __ Set(rax, static_cast<int64_t>(false)); |
| 4285 | __ Store(external_caught, rax); |
| 4286 | |
| 4287 | // Set pending exception and rax to out of memory exception. |
| 4288 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 4289 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4290 | Label already_have_failure; |
| 4291 | JumpIfOOM(masm, rax, kScratchRegister, &already_have_failure); |
| 4292 | __ movq(rax, Failure::OutOfMemoryException(0x1), RelocInfo::NONE64); |
| 4293 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4294 | __ Store(pending_exception, rax); |
| 4295 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4296 | |
| 4297 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4298 | __ ThrowUncatchable(rax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4299 | |
| 4300 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4301 | __ Throw(rax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | |
| 4305 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4306 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4307 | Label not_outermost_js, not_outermost_js_2; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4308 | { // NOLINT. Scope block confuses linter. |
| 4309 | MacroAssembler::NoRootArrayScope uninitialized_root_register(masm); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4310 | // Set up frame. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4311 | __ push(rbp); |
| 4312 | __ movq(rbp, rsp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4313 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4314 | // Push the stack frame type marker twice. |
| 4315 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 4316 | // Scratch register is neither callee-save, nor an argument register on any |
| 4317 | // platform. It's free to use at this point. |
| 4318 | // Cannot use smi-register for loading yet. |
| 4319 | __ movq(kScratchRegister, |
| 4320 | reinterpret_cast<uint64_t>(Smi::FromInt(marker)), |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4321 | RelocInfo::NONE64); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4322 | __ push(kScratchRegister); // context slot |
| 4323 | __ push(kScratchRegister); // function slot |
| 4324 | // Save callee-saved registers (X64/Win64 calling conventions). |
| 4325 | __ push(r12); |
| 4326 | __ push(r13); |
| 4327 | __ push(r14); |
| 4328 | __ push(r15); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4329 | #ifdef _WIN64 |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4330 | __ push(rdi); // Only callee save in Win64 ABI, argument in AMD64 ABI. |
| 4331 | __ push(rsi); // Only callee save in Win64 ABI, argument in AMD64 ABI. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4332 | #endif |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4333 | __ push(rbx); |
| 4334 | // TODO(X64): On Win64, if we ever use XMM6-XMM15, the low low 64 bits are |
| 4335 | // callee save as well. |
| 4336 | |
| 4337 | // Set up the roots and smi constant registers. |
| 4338 | // Needs to be done before any further smi loads. |
| 4339 | __ InitializeSmiConstantRegister(); |
| 4340 | __ InitializeRootRegister(); |
| 4341 | } |
| 4342 | |
| 4343 | Isolate* isolate = masm->isolate(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4344 | |
| 4345 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4346 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4347 | { |
| 4348 | Operand c_entry_fp_operand = masm->ExternalOperand(c_entry_fp); |
| 4349 | __ push(c_entry_fp_operand); |
| 4350 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4351 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4352 | // 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] | 4353 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4354 | __ Load(rax, js_entry_sp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4355 | __ testq(rax, rax); |
| 4356 | __ j(not_zero, ¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4357 | __ Push(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4358 | __ movq(rax, rbp); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4359 | __ Store(js_entry_sp, rax); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4360 | Label cont; |
| 4361 | __ jmp(&cont); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4362 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4363 | __ Push(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)); |
| 4364 | __ bind(&cont); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4365 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4366 | // Jump to a faked try block that does the invoke, with a faked catch |
| 4367 | // block that sets the pending exception. |
| 4368 | __ jmp(&invoke); |
| 4369 | __ bind(&handler_entry); |
| 4370 | handler_offset_ = handler_entry.pos(); |
| 4371 | // Caught exception: Store result (exception) in the pending exception |
| 4372 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4373 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4374 | isolate); |
| 4375 | __ Store(pending_exception, rax); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4376 | __ movq(rax, Failure::Exception(), RelocInfo::NONE64); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4377 | __ jmp(&exit); |
| 4378 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4379 | // Invoke: Link this frame into the handler chain. There's only one |
| 4380 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4381 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 4382 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4383 | |
| 4384 | // Clear any pending exceptions. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4385 | __ LoadRoot(rax, Heap::kTheHoleValueRootIndex); |
| 4386 | __ Store(pending_exception, rax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4387 | |
| 4388 | // Fake a receiver (NULL). |
| 4389 | __ push(Immediate(0)); // receiver |
| 4390 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4391 | // Invoke the function by calling through JS entry trampoline builtin and |
| 4392 | // pop the faked function when we return. We load the address from an |
| 4393 | // external reference instead of inlining the call target address directly |
| 4394 | // in the code, because the builtin stubs may not have been generated yet |
| 4395 | // at the time this code is generated. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4396 | if (is_construct) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4397 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4398 | isolate); |
| 4399 | __ Load(rax, construct_entry); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4400 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4401 | ExternalReference entry(Builtins::kJSEntryTrampoline, isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4402 | __ Load(rax, entry); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4403 | } |
| 4404 | __ lea(kScratchRegister, FieldOperand(rax, Code::kHeaderSize)); |
| 4405 | __ call(kScratchRegister); |
| 4406 | |
| 4407 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4408 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4409 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4410 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4411 | // Check if the current stack frame is marked as the outermost JS frame. |
| 4412 | __ pop(rbx); |
| 4413 | __ Cmp(rbx, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4414 | __ j(not_equal, ¬_outermost_js_2); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4415 | __ movq(kScratchRegister, js_entry_sp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4416 | __ movq(Operand(kScratchRegister, 0), Immediate(0)); |
| 4417 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4418 | |
| 4419 | // Restore the top frame descriptor from the stack. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4420 | { Operand c_entry_fp_operand = masm->ExternalOperand(c_entry_fp); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4421 | __ pop(c_entry_fp_operand); |
| 4422 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4423 | |
| 4424 | // Restore callee-saved registers (X64 conventions). |
| 4425 | __ pop(rbx); |
| 4426 | #ifdef _WIN64 |
| 4427 | // Callee save on in Win64 ABI, arguments/volatile in AMD64 ABI. |
| 4428 | __ pop(rsi); |
| 4429 | __ pop(rdi); |
| 4430 | #endif |
| 4431 | __ pop(r15); |
| 4432 | __ pop(r14); |
| 4433 | __ pop(r13); |
| 4434 | __ pop(r12); |
| 4435 | __ addq(rsp, Immediate(2 * kPointerSize)); // remove markers |
| 4436 | |
| 4437 | // Restore frame pointer and return. |
| 4438 | __ pop(rbp); |
| 4439 | __ ret(0); |
| 4440 | } |
| 4441 | |
| 4442 | |
| 4443 | void InstanceofStub::Generate(MacroAssembler* masm) { |
| 4444 | // Implements "value instanceof function" operator. |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4445 | // Expected input state with no inline cache: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4446 | // rsp[0] : return address |
| 4447 | // rsp[1] : function pointer |
| 4448 | // rsp[2] : value |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4449 | // Expected input state with an inline one-element cache: |
| 4450 | // rsp[0] : return address |
| 4451 | // rsp[1] : offset from return address to location of inline cache |
| 4452 | // rsp[2] : function pointer |
| 4453 | // rsp[3] : value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4454 | // Returns a bitwise zero to indicate that the value |
| 4455 | // is and instance of the function and anything else to |
| 4456 | // indicate that the value is not an instance. |
| 4457 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4458 | static const int kOffsetToMapCheckValue = 2; |
| 4459 | static const int kOffsetToResultValue = 18; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4460 | // The last 4 bytes of the instruction sequence |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4461 | // movq(rdi, FieldOperand(rax, HeapObject::kMapOffset)) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4462 | // Move(kScratchRegister, FACTORY->the_hole_value()) |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4463 | // in front of the hole value address. |
| 4464 | static const unsigned int kWordBeforeMapCheckValue = 0xBA49FF78; |
| 4465 | // The last 4 bytes of the instruction sequence |
| 4466 | // __ j(not_equal, &cache_miss); |
| 4467 | // __ LoadRoot(ToRegister(instr->result()), Heap::kTheHoleValueRootIndex); |
| 4468 | // before the offset of the hole value in the root array. |
| 4469 | static const unsigned int kWordBeforeResultValue = 0x458B4909; |
| 4470 | // Only the inline check flag is supported on X64. |
| 4471 | ASSERT(flags_ == kNoFlags || HasCallSiteInlineCheck()); |
| 4472 | int extra_stack_space = HasCallSiteInlineCheck() ? kPointerSize : 0; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4473 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4474 | // Get the object - go slow case if it's a smi. |
| 4475 | Label slow; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4476 | |
| 4477 | __ movq(rax, Operand(rsp, 2 * kPointerSize + extra_stack_space)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4478 | __ JumpIfSmi(rax, &slow); |
| 4479 | |
| 4480 | // Check that the left hand is a JS object. Leave its map in rax. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4481 | __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4482 | __ j(below, &slow); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4483 | __ CmpInstanceType(rax, LAST_SPEC_OBJECT_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4484 | __ j(above, &slow); |
| 4485 | |
| 4486 | // Get the prototype of the function. |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4487 | __ movq(rdx, Operand(rsp, 1 * kPointerSize + extra_stack_space)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4488 | // rdx is function, rax is map. |
| 4489 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4490 | // If there is a call site cache don't look in the global cache, but do the |
| 4491 | // real lookup and update the call site cache. |
| 4492 | if (!HasCallSiteInlineCheck()) { |
| 4493 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4494 | Label miss; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4495 | __ CompareRoot(rdx, Heap::kInstanceofCacheFunctionRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4496 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4497 | __ CompareRoot(rax, Heap::kInstanceofCacheMapRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4498 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4499 | __ LoadRoot(rax, Heap::kInstanceofCacheAnswerRootIndex); |
| 4500 | __ ret(2 * kPointerSize); |
| 4501 | __ bind(&miss); |
| 4502 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4503 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4504 | __ TryGetFunctionPrototype(rdx, rbx, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4505 | |
| 4506 | // Check that the function prototype is a JS object. |
| 4507 | __ JumpIfSmi(rbx, &slow); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4508 | __ CmpObjectType(rbx, FIRST_SPEC_OBJECT_TYPE, kScratchRegister); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4509 | __ j(below, &slow); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4510 | __ CmpInstanceType(kScratchRegister, LAST_SPEC_OBJECT_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4511 | __ j(above, &slow); |
| 4512 | |
| 4513 | // Register mapping: |
| 4514 | // rax is object map. |
| 4515 | // rdx is function. |
| 4516 | // rbx is function prototype. |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4517 | if (!HasCallSiteInlineCheck()) { |
| 4518 | __ StoreRoot(rdx, Heap::kInstanceofCacheFunctionRootIndex); |
| 4519 | __ StoreRoot(rax, Heap::kInstanceofCacheMapRootIndex); |
| 4520 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4521 | // Get return address and delta to inlined map check. |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4522 | __ movq(kScratchRegister, Operand(rsp, 0 * kPointerSize)); |
| 4523 | __ subq(kScratchRegister, Operand(rsp, 1 * kPointerSize)); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4524 | if (FLAG_debug_code) { |
| 4525 | __ movl(rdi, Immediate(kWordBeforeMapCheckValue)); |
| 4526 | __ cmpl(Operand(kScratchRegister, kOffsetToMapCheckValue - 4), rdi); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4527 | __ Assert(equal, "InstanceofStub unexpected call site cache (check)."); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4528 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4529 | __ movq(kScratchRegister, |
| 4530 | Operand(kScratchRegister, kOffsetToMapCheckValue)); |
| 4531 | __ movq(Operand(kScratchRegister, 0), rax); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4532 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4533 | |
| 4534 | __ movq(rcx, FieldOperand(rax, Map::kPrototypeOffset)); |
| 4535 | |
| 4536 | // Loop through the prototype chain looking for the function prototype. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4537 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4538 | __ LoadRoot(kScratchRegister, Heap::kNullValueRootIndex); |
| 4539 | __ bind(&loop); |
| 4540 | __ cmpq(rcx, rbx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4541 | __ j(equal, &is_instance, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4542 | __ cmpq(rcx, kScratchRegister); |
| 4543 | // The code at is_not_instance assumes that kScratchRegister contains a |
| 4544 | // non-zero GCable value (the null object in this case). |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4545 | __ j(equal, &is_not_instance, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4546 | __ movq(rcx, FieldOperand(rcx, HeapObject::kMapOffset)); |
| 4547 | __ movq(rcx, FieldOperand(rcx, Map::kPrototypeOffset)); |
| 4548 | __ jmp(&loop); |
| 4549 | |
| 4550 | __ bind(&is_instance); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4551 | if (!HasCallSiteInlineCheck()) { |
| 4552 | __ xorl(rax, rax); |
| 4553 | // Store bitwise zero in the cache. This is a Smi in GC terms. |
| 4554 | STATIC_ASSERT(kSmiTag == 0); |
| 4555 | __ StoreRoot(rax, Heap::kInstanceofCacheAnswerRootIndex); |
| 4556 | } else { |
| 4557 | // Store offset of true in the root array at the inline check site. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4558 | int true_offset = 0x100 + |
| 4559 | (Heap::kTrueValueRootIndex << kPointerSizeLog2) - kRootRegisterBias; |
| 4560 | // Assert it is a 1-byte signed value. |
| 4561 | ASSERT(true_offset >= 0 && true_offset < 0x100); |
| 4562 | __ movl(rax, Immediate(true_offset)); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4563 | __ movq(kScratchRegister, Operand(rsp, 0 * kPointerSize)); |
| 4564 | __ subq(kScratchRegister, Operand(rsp, 1 * kPointerSize)); |
| 4565 | __ movb(Operand(kScratchRegister, kOffsetToResultValue), rax); |
| 4566 | if (FLAG_debug_code) { |
| 4567 | __ movl(rax, Immediate(kWordBeforeResultValue)); |
| 4568 | __ cmpl(Operand(kScratchRegister, kOffsetToResultValue - 4), rax); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4569 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)."); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4570 | } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 4571 | __ Set(rax, 0); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4572 | } |
| 4573 | __ ret(2 * kPointerSize + extra_stack_space); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4574 | |
| 4575 | __ bind(&is_not_instance); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4576 | if (!HasCallSiteInlineCheck()) { |
| 4577 | // We have to store a non-zero value in the cache. |
| 4578 | __ StoreRoot(kScratchRegister, Heap::kInstanceofCacheAnswerRootIndex); |
| 4579 | } else { |
| 4580 | // Store offset of false in the root array at the inline check site. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4581 | int false_offset = 0x100 + |
| 4582 | (Heap::kFalseValueRootIndex << kPointerSizeLog2) - kRootRegisterBias; |
| 4583 | // Assert it is a 1-byte signed value. |
| 4584 | ASSERT(false_offset >= 0 && false_offset < 0x100); |
| 4585 | __ movl(rax, Immediate(false_offset)); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4586 | __ movq(kScratchRegister, Operand(rsp, 0 * kPointerSize)); |
| 4587 | __ subq(kScratchRegister, Operand(rsp, 1 * kPointerSize)); |
| 4588 | __ movb(Operand(kScratchRegister, kOffsetToResultValue), rax); |
| 4589 | if (FLAG_debug_code) { |
| 4590 | __ movl(rax, Immediate(kWordBeforeResultValue)); |
| 4591 | __ cmpl(Operand(kScratchRegister, kOffsetToResultValue - 4), rax); |
| 4592 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 4593 | } |
| 4594 | } |
| 4595 | __ ret(2 * kPointerSize + extra_stack_space); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4596 | |
| 4597 | // Slow-case: Go through the JavaScript implementation. |
| 4598 | __ bind(&slow); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4599 | if (HasCallSiteInlineCheck()) { |
| 4600 | // Remove extra value from the stack. |
| 4601 | __ pop(rcx); |
| 4602 | __ pop(rax); |
| 4603 | __ push(rcx); |
| 4604 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4605 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 4606 | } |
| 4607 | |
| 4608 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4609 | // Passing arguments in registers is not supported. |
| 4610 | Register InstanceofStub::left() { return no_reg; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4611 | |
| 4612 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4613 | Register InstanceofStub::right() { return no_reg; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4614 | |
| 4615 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4616 | // ------------------------------------------------------------------------- |
| 4617 | // StringCharCodeAtGenerator |
| 4618 | |
| 4619 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 4620 | Label flat_string; |
| 4621 | Label ascii_string; |
| 4622 | Label got_char_code; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4623 | Label sliced_string; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4624 | |
| 4625 | // If the receiver is a smi trigger the non-string case. |
| 4626 | __ JumpIfSmi(object_, receiver_not_string_); |
| 4627 | |
| 4628 | // Fetch the instance type of the receiver into result register. |
| 4629 | __ movq(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 4630 | __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 4631 | // If the receiver is not a string trigger the non-string case. |
| 4632 | __ testb(result_, Immediate(kIsNotStringMask)); |
| 4633 | __ j(not_zero, receiver_not_string_); |
| 4634 | |
| 4635 | // If the index is non-smi trigger the non-smi case. |
| 4636 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4637 | __ bind(&got_smi_index_); |
| 4638 | |
| 4639 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4640 | __ SmiCompare(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4641 | __ j(above_equal, index_out_of_range_); |
| 4642 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4643 | __ SmiToInteger32(index_, index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4644 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4645 | StringCharLoadGenerator::Generate( |
| 4646 | masm, object_, index_, result_, &call_runtime_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4647 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4648 | __ Integer32ToSmi(result_, result_); |
| 4649 | __ bind(&exit_); |
| 4650 | } |
| 4651 | |
| 4652 | |
| 4653 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4654 | MacroAssembler* masm, |
| 4655 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4656 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 4657 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4658 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4659 | // Index is not a smi. |
| 4660 | __ bind(&index_not_smi_); |
| 4661 | // If index is a heap number, try converting it to an integer. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4662 | __ CheckMap(index_, |
| 4663 | factory->heap_number_map(), |
| 4664 | index_not_number_, |
| 4665 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4666 | call_helper.BeforeCall(masm); |
| 4667 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4668 | __ push(index_); // Consumed by runtime conversion function. |
| 4669 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 4670 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 4671 | } else { |
| 4672 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 4673 | // NumberToSmi discards numbers that are not exact integers. |
| 4674 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 4675 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4676 | if (!index_.is(rax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4677 | // Save the conversion result before the pop instructions below |
| 4678 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4679 | __ movq(index_, rax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4680 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4681 | __ pop(object_); |
| 4682 | // Reload the instance type. |
| 4683 | __ movq(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 4684 | __ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 4685 | call_helper.AfterCall(masm); |
| 4686 | // If index is still not a smi, it must be out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4687 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4688 | // Otherwise, return to the fast path. |
| 4689 | __ jmp(&got_smi_index_); |
| 4690 | |
| 4691 | // Call runtime. We get here when the receiver is a string and the |
| 4692 | // index is a number, but the code of getting the actual character |
| 4693 | // is too complex (e.g., when the string needs to be flattened). |
| 4694 | __ bind(&call_runtime_); |
| 4695 | call_helper.BeforeCall(masm); |
| 4696 | __ push(object_); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4697 | __ Integer32ToSmi(index_, index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4698 | __ push(index_); |
| 4699 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 4700 | if (!result_.is(rax)) { |
| 4701 | __ movq(result_, rax); |
| 4702 | } |
| 4703 | call_helper.AfterCall(masm); |
| 4704 | __ jmp(&exit_); |
| 4705 | |
| 4706 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 4707 | } |
| 4708 | |
| 4709 | |
| 4710 | // ------------------------------------------------------------------------- |
| 4711 | // StringCharFromCodeGenerator |
| 4712 | |
| 4713 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 4714 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 4715 | __ JumpIfNotSmi(code_, &slow_case_); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4716 | __ SmiCompare(code_, Smi::FromInt(String::kMaxOneByteCharCode)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4717 | __ j(above, &slow_case_); |
| 4718 | |
| 4719 | __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex); |
| 4720 | SmiIndex index = masm->SmiToIndex(kScratchRegister, code_, kPointerSizeLog2); |
| 4721 | __ movq(result_, FieldOperand(result_, index.reg, index.scale, |
| 4722 | FixedArray::kHeaderSize)); |
| 4723 | __ CompareRoot(result_, Heap::kUndefinedValueRootIndex); |
| 4724 | __ j(equal, &slow_case_); |
| 4725 | __ bind(&exit_); |
| 4726 | } |
| 4727 | |
| 4728 | |
| 4729 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4730 | MacroAssembler* masm, |
| 4731 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4732 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 4733 | |
| 4734 | __ bind(&slow_case_); |
| 4735 | call_helper.BeforeCall(masm); |
| 4736 | __ push(code_); |
| 4737 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 4738 | if (!result_.is(rax)) { |
| 4739 | __ movq(result_, rax); |
| 4740 | } |
| 4741 | call_helper.AfterCall(masm); |
| 4742 | __ jmp(&exit_); |
| 4743 | |
| 4744 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 4745 | } |
| 4746 | |
| 4747 | |
| 4748 | // ------------------------------------------------------------------------- |
| 4749 | // StringCharAtGenerator |
| 4750 | |
| 4751 | void StringCharAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 4752 | char_code_at_generator_.GenerateFast(masm); |
| 4753 | char_from_code_generator_.GenerateFast(masm); |
| 4754 | } |
| 4755 | |
| 4756 | |
| 4757 | void StringCharAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4758 | MacroAssembler* masm, |
| 4759 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4760 | char_code_at_generator_.GenerateSlow(masm, call_helper); |
| 4761 | char_from_code_generator_.GenerateSlow(masm, call_helper); |
| 4762 | } |
| 4763 | |
| 4764 | |
| 4765 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4766 | Label call_runtime, call_builtin; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4767 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4768 | |
| 4769 | // Load the two arguments. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4770 | __ movq(rax, Operand(rsp, 2 * kPointerSize)); // First argument (left). |
| 4771 | __ movq(rdx, Operand(rsp, 1 * kPointerSize)); // Second argument (right). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4772 | |
| 4773 | // Make sure that both arguments are strings if not known in advance. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4774 | if (flags_ == NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4775 | __ JumpIfSmi(rax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4776 | __ CmpObjectType(rax, FIRST_NONSTRING_TYPE, r8); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4777 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4778 | |
| 4779 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4780 | __ JumpIfSmi(rdx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4781 | __ CmpObjectType(rdx, FIRST_NONSTRING_TYPE, r9); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4782 | __ j(above_equal, &call_runtime); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4783 | } else { |
| 4784 | // Here at least one of the arguments is definitely a string. |
| 4785 | // We convert the one that is not known to be a string. |
| 4786 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 4787 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 4788 | GenerateConvertArgument(masm, 2 * kPointerSize, rax, rbx, rcx, rdi, |
| 4789 | &call_builtin); |
| 4790 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 4791 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 4792 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 4793 | GenerateConvertArgument(masm, 1 * kPointerSize, rdx, rbx, rcx, rdi, |
| 4794 | &call_builtin); |
| 4795 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 4796 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4797 | } |
| 4798 | |
| 4799 | // Both arguments are strings. |
| 4800 | // rax: first string |
| 4801 | // rdx: second string |
| 4802 | // 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] | 4803 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4804 | __ movq(rcx, FieldOperand(rdx, String::kLengthOffset)); |
| 4805 | __ SmiTest(rcx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4806 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4807 | // Second string is empty, result is first string which is already in rax. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4808 | Counters* counters = masm->isolate()->counters(); |
| 4809 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4810 | __ ret(2 * kPointerSize); |
| 4811 | __ bind(&second_not_zero_length); |
| 4812 | __ movq(rbx, FieldOperand(rax, String::kLengthOffset)); |
| 4813 | __ SmiTest(rbx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4814 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4815 | // First string is empty, result is second string which is in rdx. |
| 4816 | __ movq(rax, rdx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4817 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4818 | __ ret(2 * kPointerSize); |
| 4819 | |
| 4820 | // Both strings are non-empty. |
| 4821 | // rax: first string |
| 4822 | // rbx: length of first string |
| 4823 | // rcx: length of second string |
| 4824 | // rdx: second string |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4825 | // r8: map of first string (if flags_ == NO_STRING_ADD_FLAGS) |
| 4826 | // r9: map of second string (if flags_ == NO_STRING_ADD_FLAGS) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4827 | Label string_add_flat_result, longer_than_two; |
| 4828 | __ bind(&both_not_zero_length); |
| 4829 | |
| 4830 | // If arguments where known to be strings, maps are not loaded to r8 and r9 |
| 4831 | // by the code above. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4832 | if (flags_ != NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4833 | __ movq(r8, FieldOperand(rax, HeapObject::kMapOffset)); |
| 4834 | __ movq(r9, FieldOperand(rdx, HeapObject::kMapOffset)); |
| 4835 | } |
| 4836 | // Get the instance types of the two strings as they will be needed soon. |
| 4837 | __ movzxbl(r8, FieldOperand(r8, Map::kInstanceTypeOffset)); |
| 4838 | __ movzxbl(r9, FieldOperand(r9, Map::kInstanceTypeOffset)); |
| 4839 | |
| 4840 | // Look at the length of the result of adding the two strings. |
| 4841 | STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue / 2); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4842 | __ SmiAdd(rbx, rbx, rcx); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4843 | // Use the symbol table when adding two one character strings, as it |
| 4844 | // helps later optimizations to return a symbol here. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4845 | __ SmiCompare(rbx, Smi::FromInt(2)); |
| 4846 | __ j(not_equal, &longer_than_two); |
| 4847 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4848 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4849 | __ JumpIfBothInstanceTypesAreNotSequentialAscii(r8, r9, rbx, rcx, |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4850 | &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4851 | |
| 4852 | // Get the two characters forming the sub string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4853 | __ movzxbq(rbx, FieldOperand(rax, SeqOneByteString::kHeaderSize)); |
| 4854 | __ movzxbq(rcx, FieldOperand(rdx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4855 | |
| 4856 | // Try to lookup two character string in symbol table. If it is not found |
| 4857 | // just allocate a new one. |
| 4858 | Label make_two_character_string, make_flat_ascii_string; |
| 4859 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4860 | masm, rbx, rcx, r14, r11, rdi, r15, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4861 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4862 | __ ret(2 * kPointerSize); |
| 4863 | |
| 4864 | __ bind(&make_two_character_string); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4865 | __ Set(rdi, 2); |
| 4866 | __ AllocateAsciiString(rax, rdi, r8, r9, r11, &call_runtime); |
| 4867 | // rbx - first byte: first character |
| 4868 | // rbx - second byte: *maybe* second character |
| 4869 | // Make sure that the second byte of rbx contains the second character. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4870 | __ movzxbq(rcx, FieldOperand(rdx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4871 | __ shll(rcx, Immediate(kBitsPerByte)); |
| 4872 | __ orl(rbx, rcx); |
| 4873 | // Write both characters to the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4874 | __ movw(FieldOperand(rax, SeqOneByteString::kHeaderSize), rbx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4875 | __ IncrementCounter(counters->string_add_native(), 1); |
| 4876 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4877 | |
| 4878 | __ bind(&longer_than_two); |
| 4879 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4880 | __ SmiCompare(rbx, Smi::FromInt(ConsString::kMinLength)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4881 | __ j(below, &string_add_flat_result); |
| 4882 | // Handle exceptionally long strings in the runtime system. |
| 4883 | STATIC_ASSERT((String::kMaxLength & 0x80000000) == 0); |
| 4884 | __ SmiCompare(rbx, Smi::FromInt(String::kMaxLength)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4885 | __ j(above, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4886 | |
| 4887 | // If result is not supposed to be flat, allocate a cons string object. If |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4888 | // both strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4889 | // rax: first string |
| 4890 | // rbx: length of resulting flat string |
| 4891 | // rdx: second string |
| 4892 | // r8: instance type of first string |
| 4893 | // r9: instance type of second string |
| 4894 | Label non_ascii, allocated, ascii_data; |
| 4895 | __ movl(rcx, r8); |
| 4896 | __ and_(rcx, r9); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4897 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4898 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 4899 | __ testl(rcx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4900 | __ j(zero, &non_ascii); |
| 4901 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4902 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4903 | __ AllocateAsciiConsString(rcx, rdi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4904 | __ bind(&allocated); |
| 4905 | // Fill the fields of the cons string. |
| 4906 | __ movq(FieldOperand(rcx, ConsString::kLengthOffset), rbx); |
| 4907 | __ movq(FieldOperand(rcx, ConsString::kHashFieldOffset), |
| 4908 | Immediate(String::kEmptyHashField)); |
| 4909 | __ movq(FieldOperand(rcx, ConsString::kFirstOffset), rax); |
| 4910 | __ movq(FieldOperand(rcx, ConsString::kSecondOffset), rdx); |
| 4911 | __ movq(rax, rcx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4912 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4913 | __ ret(2 * kPointerSize); |
| 4914 | __ bind(&non_ascii); |
| 4915 | // 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] | 4916 | // to contain only ASCII characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4917 | // rcx: first instance type AND second instance type. |
| 4918 | // r8: first instance type. |
| 4919 | // r9: second instance type. |
| 4920 | __ testb(rcx, Immediate(kAsciiDataHintMask)); |
| 4921 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4922 | __ xor_(r8, r9); |
| 4923 | STATIC_ASSERT(kOneByteStringTag != 0 && kAsciiDataHintTag != 0); |
| 4924 | __ andb(r8, Immediate(kOneByteStringTag | kAsciiDataHintTag)); |
| 4925 | __ cmpb(r8, Immediate(kOneByteStringTag | kAsciiDataHintTag)); |
| 4926 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4927 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4928 | __ AllocateTwoByteConsString(rcx, rdi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4929 | __ jmp(&allocated); |
| 4930 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4931 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4932 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4933 | // Handle creating a flat result from either external or sequential strings. |
| 4934 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4935 | // rax: first string |
| 4936 | // rbx: length of resulting flat string as smi |
| 4937 | // rdx: second string |
| 4938 | // r8: instance type of first string |
| 4939 | // r9: instance type of first string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4940 | Label first_prepared, second_prepared; |
| 4941 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4942 | __ bind(&string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4943 | |
| 4944 | __ SmiToInteger32(r14, FieldOperand(rax, SeqString::kLengthOffset)); |
| 4945 | // r14: length of first string |
| 4946 | STATIC_ASSERT(kSeqStringTag == 0); |
| 4947 | __ testb(r8, Immediate(kStringRepresentationMask)); |
| 4948 | __ j(zero, &first_is_sequential, Label::kNear); |
| 4949 | // Rule out short external string and load string resource. |
| 4950 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 4951 | __ testb(r8, Immediate(kShortExternalStringMask)); |
| 4952 | __ j(not_zero, &call_runtime); |
| 4953 | __ movq(rcx, FieldOperand(rax, ExternalString::kResourceDataOffset)); |
| 4954 | __ jmp(&first_prepared, Label::kNear); |
| 4955 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4956 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
| 4957 | __ lea(rcx, FieldOperand(rax, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4958 | __ bind(&first_prepared); |
| 4959 | |
| 4960 | // Check whether both strings have same encoding. |
| 4961 | __ xorl(r8, r9); |
| 4962 | __ testb(r8, Immediate(kStringEncodingMask)); |
| 4963 | __ j(not_zero, &call_runtime); |
| 4964 | |
| 4965 | __ SmiToInteger32(r15, FieldOperand(rdx, SeqString::kLengthOffset)); |
| 4966 | // r15: length of second string |
| 4967 | STATIC_ASSERT(kSeqStringTag == 0); |
| 4968 | __ testb(r9, Immediate(kStringRepresentationMask)); |
| 4969 | __ j(zero, &second_is_sequential, Label::kNear); |
| 4970 | // Rule out short external string and load string resource. |
| 4971 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 4972 | __ testb(r9, Immediate(kShortExternalStringMask)); |
| 4973 | __ j(not_zero, &call_runtime); |
| 4974 | __ movq(rdx, FieldOperand(rdx, ExternalString::kResourceDataOffset)); |
| 4975 | __ jmp(&second_prepared, Label::kNear); |
| 4976 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4977 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
| 4978 | __ lea(rdx, FieldOperand(rdx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4979 | __ bind(&second_prepared); |
| 4980 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4981 | Label non_ascii_string_add_flat_result; |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4982 | // r9: instance type of second string |
| 4983 | // First string and second string have the same encoding. |
| 4984 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 4985 | __ SmiToInteger32(rbx, rbx); |
| 4986 | __ testb(r9, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4987 | __ j(zero, &non_ascii_string_add_flat_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4988 | |
| 4989 | __ bind(&make_flat_ascii_string); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4990 | // Both strings are ASCII strings. As they are short they are both flat. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4991 | __ AllocateAsciiString(rax, rbx, rdi, r8, r9, &call_runtime); |
| 4992 | // rax: result string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4993 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4994 | __ lea(rbx, FieldOperand(rax, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4995 | // rcx: first char of first string |
| 4996 | // rbx: first character of result |
| 4997 | // r14: length of first string |
| 4998 | StringHelper::GenerateCopyCharacters(masm, rbx, rcx, r14, true); |
| 4999 | // rbx: next character of result |
| 5000 | // rdx: first char of second string |
| 5001 | // r15: length of second string |
| 5002 | StringHelper::GenerateCopyCharacters(masm, rbx, rdx, r15, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5003 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5004 | __ ret(2 * kPointerSize); |
| 5005 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5006 | __ bind(&non_ascii_string_add_flat_result); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5007 | // Both strings are ASCII strings. As they are short they are both flat. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5008 | __ AllocateTwoByteString(rax, rbx, rdi, r8, r9, &call_runtime); |
| 5009 | // rax: result string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5010 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5011 | __ lea(rbx, FieldOperand(rax, SeqTwoByteString::kHeaderSize)); |
| 5012 | // rcx: first char of first string |
| 5013 | // rbx: first character of result |
| 5014 | // r14: length of first string |
| 5015 | StringHelper::GenerateCopyCharacters(masm, rbx, rcx, r14, false); |
| 5016 | // rbx: next character of result |
| 5017 | // rdx: first char of second string |
| 5018 | // r15: length of second string |
| 5019 | StringHelper::GenerateCopyCharacters(masm, rbx, rdx, r15, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5020 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5021 | __ ret(2 * kPointerSize); |
| 5022 | |
| 5023 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5024 | __ bind(&call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5025 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5026 | |
| 5027 | if (call_builtin.is_linked()) { |
| 5028 | __ bind(&call_builtin); |
| 5029 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 5030 | } |
| 5031 | } |
| 5032 | |
| 5033 | |
| 5034 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 5035 | int stack_offset, |
| 5036 | Register arg, |
| 5037 | Register scratch1, |
| 5038 | Register scratch2, |
| 5039 | Register scratch3, |
| 5040 | Label* slow) { |
| 5041 | // First check if the argument is already a string. |
| 5042 | Label not_string, done; |
| 5043 | __ JumpIfSmi(arg, ¬_string); |
| 5044 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 5045 | __ j(below, &done); |
| 5046 | |
| 5047 | // Check the number to string cache. |
| 5048 | Label not_cached; |
| 5049 | __ bind(¬_string); |
| 5050 | // Puts the cached result into scratch1. |
| 5051 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 5052 | arg, |
| 5053 | scratch1, |
| 5054 | scratch2, |
| 5055 | scratch3, |
| 5056 | false, |
| 5057 | ¬_cached); |
| 5058 | __ movq(arg, scratch1); |
| 5059 | __ movq(Operand(rsp, stack_offset), arg); |
| 5060 | __ jmp(&done); |
| 5061 | |
| 5062 | // Check if the argument is a safe string wrapper. |
| 5063 | __ bind(¬_cached); |
| 5064 | __ JumpIfSmi(arg, slow); |
| 5065 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 5066 | __ j(not_equal, slow); |
| 5067 | __ testb(FieldOperand(scratch1, Map::kBitField2Offset), |
| 5068 | Immediate(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 5069 | __ j(zero, slow); |
| 5070 | __ movq(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 5071 | __ movq(Operand(rsp, stack_offset), arg); |
| 5072 | |
| 5073 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5074 | } |
| 5075 | |
| 5076 | |
| 5077 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5078 | Register dest, |
| 5079 | Register src, |
| 5080 | Register count, |
| 5081 | bool ascii) { |
| 5082 | Label loop; |
| 5083 | __ bind(&loop); |
| 5084 | // This loop just copies one character at a time, as it is only used for very |
| 5085 | // short strings. |
| 5086 | if (ascii) { |
| 5087 | __ movb(kScratchRegister, Operand(src, 0)); |
| 5088 | __ movb(Operand(dest, 0), kScratchRegister); |
| 5089 | __ incq(src); |
| 5090 | __ incq(dest); |
| 5091 | } else { |
| 5092 | __ movzxwl(kScratchRegister, Operand(src, 0)); |
| 5093 | __ movw(Operand(dest, 0), kScratchRegister); |
| 5094 | __ addq(src, Immediate(2)); |
| 5095 | __ addq(dest, Immediate(2)); |
| 5096 | } |
| 5097 | __ decl(count); |
| 5098 | __ j(not_zero, &loop); |
| 5099 | } |
| 5100 | |
| 5101 | |
| 5102 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 5103 | Register dest, |
| 5104 | Register src, |
| 5105 | Register count, |
| 5106 | bool ascii) { |
| 5107 | // Copy characters using rep movs of doublewords. Align destination on 4 byte |
| 5108 | // boundary before starting rep movs. Copy remaining characters after running |
| 5109 | // rep movs. |
| 5110 | // Count is positive int32, dest and src are character pointers. |
| 5111 | ASSERT(dest.is(rdi)); // rep movs destination |
| 5112 | ASSERT(src.is(rsi)); // rep movs source |
| 5113 | ASSERT(count.is(rcx)); // rep movs count |
| 5114 | |
| 5115 | // Nothing to do for zero characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5116 | Label done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5117 | __ testl(count, count); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5118 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5119 | |
| 5120 | // Make count the number of bytes to copy. |
| 5121 | if (!ascii) { |
| 5122 | STATIC_ASSERT(2 == sizeof(uc16)); |
| 5123 | __ addl(count, count); |
| 5124 | } |
| 5125 | |
| 5126 | // 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] | 5127 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5128 | __ testl(count, Immediate(~7)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5129 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5130 | |
| 5131 | // Copy from edi to esi using rep movs instruction. |
| 5132 | __ movl(kScratchRegister, count); |
| 5133 | __ shr(count, Immediate(3)); // Number of doublewords to copy. |
| 5134 | __ repmovsq(); |
| 5135 | |
| 5136 | // Find number of bytes left. |
| 5137 | __ movl(count, kScratchRegister); |
| 5138 | __ and_(count, Immediate(7)); |
| 5139 | |
| 5140 | // Check if there are more bytes to copy. |
| 5141 | __ bind(&last_bytes); |
| 5142 | __ testl(count, count); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5143 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5144 | |
| 5145 | // Copy remaining characters. |
| 5146 | Label loop; |
| 5147 | __ bind(&loop); |
| 5148 | __ movb(kScratchRegister, Operand(src, 0)); |
| 5149 | __ movb(Operand(dest, 0), kScratchRegister); |
| 5150 | __ incq(src); |
| 5151 | __ incq(dest); |
| 5152 | __ decl(count); |
| 5153 | __ j(not_zero, &loop); |
| 5154 | |
| 5155 | __ bind(&done); |
| 5156 | } |
| 5157 | |
| 5158 | void StringHelper::GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 5159 | Register c1, |
| 5160 | Register c2, |
| 5161 | Register scratch1, |
| 5162 | Register scratch2, |
| 5163 | Register scratch3, |
| 5164 | Register scratch4, |
| 5165 | Label* not_found) { |
| 5166 | // Register scratch3 is the general scratch register in this function. |
| 5167 | Register scratch = scratch3; |
| 5168 | |
| 5169 | // Make sure that both characters are not digits as such strings has a |
| 5170 | // 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] | 5171 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5172 | __ leal(scratch, Operand(c1, -'0')); |
| 5173 | __ cmpl(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5174 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5175 | __ leal(scratch, Operand(c2, -'0')); |
| 5176 | __ cmpl(scratch, Immediate(static_cast<int>('9' - '0'))); |
| 5177 | __ j(below_equal, not_found); |
| 5178 | |
| 5179 | __ bind(¬_array_index); |
| 5180 | // Calculate the two character string hash. |
| 5181 | Register hash = scratch1; |
| 5182 | GenerateHashInit(masm, hash, c1, scratch); |
| 5183 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 5184 | GenerateHashGetHash(masm, hash, scratch); |
| 5185 | |
| 5186 | // Collect the two characters in a register. |
| 5187 | Register chars = c1; |
| 5188 | __ shl(c2, Immediate(kBitsPerByte)); |
| 5189 | __ orl(chars, c2); |
| 5190 | |
| 5191 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5192 | // hash: hash of two character string. |
| 5193 | |
| 5194 | // Load the symbol table. |
| 5195 | Register symbol_table = c2; |
| 5196 | __ LoadRoot(symbol_table, Heap::kSymbolTableRootIndex); |
| 5197 | |
| 5198 | // Calculate capacity mask from the symbol table capacity. |
| 5199 | Register mask = scratch2; |
| 5200 | __ SmiToInteger32(mask, |
| 5201 | FieldOperand(symbol_table, SymbolTable::kCapacityOffset)); |
| 5202 | __ decl(mask); |
| 5203 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5204 | Register map = scratch4; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5205 | |
| 5206 | // Registers |
| 5207 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5208 | // hash: hash of two character string (32-bit int) |
| 5209 | // symbol_table: symbol table |
| 5210 | // mask: capacity mask (32-bit int) |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5211 | // map: - |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5212 | // scratch: - |
| 5213 | |
| 5214 | // Perform a number of probes in the symbol table. |
| 5215 | static const int kProbes = 4; |
| 5216 | Label found_in_symbol_table; |
| 5217 | Label next_probe[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5218 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5219 | for (int i = 0; i < kProbes; i++) { |
| 5220 | // Calculate entry in symbol table. |
| 5221 | __ movl(scratch, hash); |
| 5222 | if (i > 0) { |
| 5223 | __ addl(scratch, Immediate(SymbolTable::GetProbeOffset(i))); |
| 5224 | } |
| 5225 | __ andl(scratch, mask); |
| 5226 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5227 | // Load the entry from the symbol table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5228 | STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
| 5229 | __ movq(candidate, |
| 5230 | FieldOperand(symbol_table, |
| 5231 | scratch, |
| 5232 | times_pointer_size, |
| 5233 | SymbolTable::kElementsStartOffset)); |
| 5234 | |
| 5235 | // If entry is undefined no string with this hash can be found. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5236 | Label is_string; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5237 | __ CmpObjectType(candidate, ODDBALL_TYPE, map); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5238 | __ j(not_equal, &is_string, Label::kNear); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5239 | |
| 5240 | __ CompareRoot(candidate, Heap::kUndefinedValueRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5241 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5242 | // Must be the hole (deleted entry). |
| 5243 | if (FLAG_debug_code) { |
| 5244 | __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); |
| 5245 | __ cmpq(kScratchRegister, candidate); |
| 5246 | __ Assert(equal, "oddball in symbol table is not undefined or the hole"); |
| 5247 | } |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5248 | __ jmp(&next_probe[i]); |
| 5249 | |
| 5250 | __ bind(&is_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5251 | |
| 5252 | // If length is not 2 the string is not a candidate. |
| 5253 | __ SmiCompare(FieldOperand(candidate, String::kLengthOffset), |
| 5254 | Smi::FromInt(2)); |
| 5255 | __ j(not_equal, &next_probe[i]); |
| 5256 | |
| 5257 | // We use kScratchRegister as a temporary register in assumption that |
| 5258 | // JumpIfInstanceTypeIsNotSequentialAscii does not use it implicitly |
| 5259 | Register temp = kScratchRegister; |
| 5260 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5261 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5262 | __ movzxbl(temp, FieldOperand(map, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5263 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 5264 | temp, temp, &next_probe[i]); |
| 5265 | |
| 5266 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5267 | __ movl(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5268 | __ andl(temp, Immediate(0x0000ffff)); |
| 5269 | __ cmpl(chars, temp); |
| 5270 | __ j(equal, &found_in_symbol_table); |
| 5271 | __ bind(&next_probe[i]); |
| 5272 | } |
| 5273 | |
| 5274 | // No matching 2 character string found by probing. |
| 5275 | __ jmp(not_found); |
| 5276 | |
| 5277 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5278 | Register result = candidate; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5279 | __ bind(&found_in_symbol_table); |
| 5280 | if (!result.is(rax)) { |
| 5281 | __ movq(rax, result); |
| 5282 | } |
| 5283 | } |
| 5284 | |
| 5285 | |
| 5286 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 5287 | Register hash, |
| 5288 | Register character, |
| 5289 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5290 | // hash = (seed + character) + ((seed + character) << 10); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5291 | __ LoadRoot(scratch, Heap::kHashSeedRootIndex); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5292 | __ SmiToInteger32(scratch, scratch); |
| 5293 | __ addl(scratch, character); |
| 5294 | __ movl(hash, scratch); |
| 5295 | __ shll(scratch, Immediate(10)); |
| 5296 | __ addl(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5297 | // hash ^= hash >> 6; |
| 5298 | __ movl(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5299 | __ shrl(scratch, Immediate(6)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5300 | __ xorl(hash, scratch); |
| 5301 | } |
| 5302 | |
| 5303 | |
| 5304 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 5305 | Register hash, |
| 5306 | Register character, |
| 5307 | Register scratch) { |
| 5308 | // hash += character; |
| 5309 | __ addl(hash, character); |
| 5310 | // hash += hash << 10; |
| 5311 | __ movl(scratch, hash); |
| 5312 | __ shll(scratch, Immediate(10)); |
| 5313 | __ addl(hash, scratch); |
| 5314 | // hash ^= hash >> 6; |
| 5315 | __ movl(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5316 | __ shrl(scratch, Immediate(6)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5317 | __ xorl(hash, scratch); |
| 5318 | } |
| 5319 | |
| 5320 | |
| 5321 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 5322 | Register hash, |
| 5323 | Register scratch) { |
| 5324 | // hash += hash << 3; |
| 5325 | __ leal(hash, Operand(hash, hash, times_8, 0)); |
| 5326 | // hash ^= hash >> 11; |
| 5327 | __ movl(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5328 | __ shrl(scratch, Immediate(11)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5329 | __ xorl(hash, scratch); |
| 5330 | // hash += hash << 15; |
| 5331 | __ movl(scratch, hash); |
| 5332 | __ shll(scratch, Immediate(15)); |
| 5333 | __ addl(hash, scratch); |
| 5334 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5335 | __ andl(hash, Immediate(String::kHashBitMask)); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5336 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5337 | // if (hash == 0) hash = 27; |
| 5338 | Label hash_not_zero; |
| 5339 | __ j(not_zero, &hash_not_zero); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5340 | __ Set(hash, StringHasher::kZeroHash); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5341 | __ bind(&hash_not_zero); |
| 5342 | } |
| 5343 | |
| 5344 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 5345 | Label runtime; |
| 5346 | |
| 5347 | // Stack frame on entry. |
| 5348 | // rsp[0]: return address |
| 5349 | // rsp[8]: to |
| 5350 | // rsp[16]: from |
| 5351 | // rsp[24]: string |
| 5352 | |
| 5353 | const int kToOffset = 1 * kPointerSize; |
| 5354 | const int kFromOffset = kToOffset + kPointerSize; |
| 5355 | const int kStringOffset = kFromOffset + kPointerSize; |
| 5356 | const int kArgumentsSize = (kStringOffset + kPointerSize) - kToOffset; |
| 5357 | |
| 5358 | // Make sure first argument is a string. |
| 5359 | __ movq(rax, Operand(rsp, kStringOffset)); |
| 5360 | STATIC_ASSERT(kSmiTag == 0); |
| 5361 | __ testl(rax, Immediate(kSmiTagMask)); |
| 5362 | __ j(zero, &runtime); |
| 5363 | Condition is_string = masm->IsObjectStringType(rax, rbx, rbx); |
| 5364 | __ j(NegateCondition(is_string), &runtime); |
| 5365 | |
| 5366 | // rax: string |
| 5367 | // rbx: instance type |
| 5368 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5369 | __ movq(rcx, Operand(rsp, kToOffset)); |
| 5370 | __ movq(rdx, Operand(rsp, kFromOffset)); |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 5371 | __ JumpUnlessBothNonNegativeSmi(rcx, rdx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5372 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 5373 | __ SmiSub(rcx, rcx, rdx); // Overflow doesn't happen. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5374 | __ cmpq(rcx, FieldOperand(rax, String::kLengthOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5375 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5376 | // Shorter than original string's length: an actual substring. |
| 5377 | __ j(below, ¬_original_string, Label::kNear); |
| 5378 | // Longer than original string's length or negative: unsafe arguments. |
| 5379 | __ j(above, &runtime); |
| 5380 | // Return original string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5381 | Counters* counters = masm->isolate()->counters(); |
| 5382 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 5383 | __ ret(kArgumentsSize); |
| 5384 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5385 | __ SmiToInteger32(rcx, rcx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5386 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5387 | // rax: string |
| 5388 | // rbx: instance type |
| 5389 | // rcx: sub string length |
| 5390 | // rdx: from index (smi) |
| 5391 | // Deal with different string types: update the index if necessary |
| 5392 | // and put the underlying string into edi. |
| 5393 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 5394 | // If the string is not indirect, it can only be sequential or external. |
| 5395 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 5396 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 5397 | __ testb(rbx, Immediate(kIsIndirectStringMask)); |
| 5398 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 5399 | |
| 5400 | __ testb(rbx, Immediate(kSlicedNotConsMask)); |
| 5401 | __ j(not_zero, &sliced_string, Label::kNear); |
| 5402 | // Cons string. Check whether it is flat, then fetch first part. |
| 5403 | // Flat cons strings have an empty second part. |
| 5404 | __ CompareRoot(FieldOperand(rax, ConsString::kSecondOffset), |
| 5405 | Heap::kEmptyStringRootIndex); |
| 5406 | __ j(not_equal, &runtime); |
| 5407 | __ movq(rdi, FieldOperand(rax, ConsString::kFirstOffset)); |
| 5408 | // Update instance type. |
| 5409 | __ movq(rbx, FieldOperand(rdi, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5410 | __ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5411 | __ jmp(&underlying_unpacked, Label::kNear); |
| 5412 | |
| 5413 | __ bind(&sliced_string); |
| 5414 | // Sliced string. Fetch parent and correct start index by offset. |
| 5415 | __ addq(rdx, FieldOperand(rax, SlicedString::kOffsetOffset)); |
| 5416 | __ movq(rdi, FieldOperand(rax, SlicedString::kParentOffset)); |
| 5417 | // Update instance type. |
| 5418 | __ movq(rbx, FieldOperand(rdi, HeapObject::kMapOffset)); |
| 5419 | __ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset)); |
| 5420 | __ jmp(&underlying_unpacked, Label::kNear); |
| 5421 | |
| 5422 | __ bind(&seq_or_external_string); |
| 5423 | // Sequential or external string. Just move string to the correct register. |
| 5424 | __ movq(rdi, rax); |
| 5425 | |
| 5426 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5427 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5428 | if (FLAG_string_slices) { |
| 5429 | Label copy_routine; |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5430 | // rdi: underlying subject string |
| 5431 | // rbx: instance type of underlying subject string |
| 5432 | // rdx: adjusted start index (smi) |
| 5433 | // rcx: length |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5434 | // If coming from the make_two_character_string path, the string |
| 5435 | // is too short to be sliced anyways. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5436 | __ cmpq(rcx, Immediate(SlicedString::kMinLength)); |
| 5437 | // Short slice. Copy instead of slicing. |
| 5438 | __ j(less, ©_routine); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5439 | // Allocate new sliced string. At this point we do not reload the instance |
| 5440 | // type including the string encoding because we simply rely on the info |
| 5441 | // provided by the original string. It does not matter if the original |
| 5442 | // string's encoding is wrong because we always have to recheck encoding of |
| 5443 | // the newly created string's parent anyways due to externalized strings. |
| 5444 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5445 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5446 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5447 | __ testb(rbx, Immediate(kStringEncodingMask)); |
| 5448 | __ j(zero, &two_byte_slice, Label::kNear); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5449 | __ AllocateAsciiSlicedString(rax, rbx, r14, &runtime); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5450 | __ jmp(&set_slice_header, Label::kNear); |
| 5451 | __ bind(&two_byte_slice); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5452 | __ AllocateTwoByteSlicedString(rax, rbx, r14, &runtime); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5453 | __ bind(&set_slice_header); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5454 | __ Integer32ToSmi(rcx, rcx); |
| 5455 | __ movq(FieldOperand(rax, SlicedString::kLengthOffset), rcx); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5456 | __ movq(FieldOperand(rax, SlicedString::kHashFieldOffset), |
| 5457 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 5458 | __ movq(FieldOperand(rax, SlicedString::kParentOffset), rdi); |
| 5459 | __ movq(FieldOperand(rax, SlicedString::kOffsetOffset), rdx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5460 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 5461 | __ ret(kArgumentsSize); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5462 | |
| 5463 | __ bind(©_routine); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5464 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5465 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5466 | // rdi: underlying subject string |
| 5467 | // rbx: instance type of underlying subject string |
| 5468 | // rdx: adjusted start index (smi) |
| 5469 | // rcx: length |
| 5470 | // The subject string can only be external or sequential string of either |
| 5471 | // encoding at this point. |
| 5472 | Label two_byte_sequential, sequential_string; |
| 5473 | STATIC_ASSERT(kExternalStringTag != 0); |
| 5474 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5475 | __ testb(rbx, Immediate(kExternalStringTag)); |
| 5476 | __ j(zero, &sequential_string); |
| 5477 | |
| 5478 | // Handle external string. |
| 5479 | // Rule out short external strings. |
| 5480 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 5481 | __ testb(rbx, Immediate(kShortExternalStringMask)); |
| 5482 | __ j(not_zero, &runtime); |
| 5483 | __ movq(rdi, FieldOperand(rdi, ExternalString::kResourceDataOffset)); |
| 5484 | // Move the pointer so that offset-wise, it looks like a sequential string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5485 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5486 | __ subq(rdi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5487 | |
| 5488 | __ bind(&sequential_string); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5489 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5490 | __ testb(rbx, Immediate(kStringEncodingMask)); |
| 5491 | __ j(zero, &two_byte_sequential); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5492 | |
| 5493 | // Allocate the result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5494 | __ AllocateAsciiString(rax, rcx, r11, r14, r15, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5495 | |
| 5496 | // rax: result string |
| 5497 | // rcx: result string length |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5498 | __ movq(r14, rsi); // esi used by following code. |
| 5499 | { // Locate character of sub string start. |
| 5500 | SmiIndex smi_as_index = masm->SmiToIndex(rdx, rdx, times_1); |
| 5501 | __ lea(rsi, Operand(rdi, smi_as_index.reg, smi_as_index.scale, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5502 | SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5503 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5504 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5505 | __ lea(rdi, FieldOperand(rax, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5506 | |
| 5507 | // rax: result string |
| 5508 | // rcx: result length |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5509 | // rdi: first character of result |
| 5510 | // rsi: character of sub string start |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5511 | // r14: original value of rsi |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5512 | StringHelper::GenerateCopyCharactersREP(masm, rdi, rsi, rcx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5513 | __ movq(rsi, r14); // Restore rsi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5514 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5515 | __ ret(kArgumentsSize); |
| 5516 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5517 | __ bind(&two_byte_sequential); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5518 | // Allocate the result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5519 | __ AllocateTwoByteString(rax, rcx, r11, r14, r15, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5520 | |
| 5521 | // rax: result string |
| 5522 | // rcx: result string length |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5523 | __ movq(r14, rsi); // esi used by following code. |
| 5524 | { // Locate character of sub string start. |
| 5525 | SmiIndex smi_as_index = masm->SmiToIndex(rdx, rdx, times_2); |
| 5526 | __ lea(rsi, Operand(rdi, smi_as_index.reg, smi_as_index.scale, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5527 | SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5528 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5529 | // Locate first character of result. |
| 5530 | __ lea(rdi, FieldOperand(rax, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5531 | |
| 5532 | // rax: result string |
| 5533 | // rcx: result length |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5534 | // rdi: first character of result |
| 5535 | // rsi: character of sub string start |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5536 | // r14: original value of rsi |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5537 | StringHelper::GenerateCopyCharactersREP(masm, rdi, rsi, rcx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5538 | __ movq(rsi, r14); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5539 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5540 | __ ret(kArgumentsSize); |
| 5541 | |
| 5542 | // Just jump to runtime to create the sub string. |
| 5543 | __ bind(&runtime); |
| 5544 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
| 5545 | } |
| 5546 | |
| 5547 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5548 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 5549 | Register left, |
| 5550 | Register right, |
| 5551 | Register scratch1, |
| 5552 | Register scratch2) { |
| 5553 | Register length = scratch1; |
| 5554 | |
| 5555 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5556 | Label check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5557 | __ movq(length, FieldOperand(left, String::kLengthOffset)); |
| 5558 | __ SmiCompare(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5559 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5560 | __ Move(rax, Smi::FromInt(NOT_EQUAL)); |
| 5561 | __ ret(0); |
| 5562 | |
| 5563 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5564 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5565 | __ bind(&check_zero_length); |
| 5566 | STATIC_ASSERT(kSmiTag == 0); |
| 5567 | __ SmiTest(length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5568 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5569 | __ Move(rax, Smi::FromInt(EQUAL)); |
| 5570 | __ ret(0); |
| 5571 | |
| 5572 | // Compare characters. |
| 5573 | __ bind(&compare_chars); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5574 | Label strings_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5575 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5576 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5577 | |
| 5578 | // Characters are equal. |
| 5579 | __ Move(rax, Smi::FromInt(EQUAL)); |
| 5580 | __ ret(0); |
| 5581 | |
| 5582 | // Characters are not equal. |
| 5583 | __ bind(&strings_not_equal); |
| 5584 | __ Move(rax, Smi::FromInt(NOT_EQUAL)); |
| 5585 | __ ret(0); |
| 5586 | } |
| 5587 | |
| 5588 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5589 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 5590 | Register left, |
| 5591 | Register right, |
| 5592 | Register scratch1, |
| 5593 | Register scratch2, |
| 5594 | Register scratch3, |
| 5595 | Register scratch4) { |
| 5596 | // Ensure that you can always subtract a string length from a non-negative |
| 5597 | // number (e.g. another length). |
| 5598 | STATIC_ASSERT(String::kMaxLength < 0x7fffffff); |
| 5599 | |
| 5600 | // Find minimum length and length difference. |
| 5601 | __ movq(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 5602 | __ movq(scratch4, scratch1); |
| 5603 | __ SmiSub(scratch4, |
| 5604 | scratch4, |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 5605 | FieldOperand(right, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5606 | // Register scratch4 now holds left.length - right.length. |
| 5607 | const Register length_difference = scratch4; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5608 | Label left_shorter; |
| 5609 | __ j(less, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5610 | // The right string isn't longer that the left one. |
| 5611 | // Get the right string's length by subtracting the (non-negative) difference |
| 5612 | // from the left string's length. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 5613 | __ SmiSub(scratch1, scratch1, length_difference); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5614 | __ bind(&left_shorter); |
| 5615 | // Register scratch1 now holds Min(left.length, right.length). |
| 5616 | const Register min_length = scratch1; |
| 5617 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5618 | Label compare_lengths; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5619 | // If min-length is zero, go directly to comparing lengths. |
| 5620 | __ SmiTest(min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5621 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5622 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5623 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5624 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5625 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5626 | &result_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5627 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5628 | // Completed loop without finding different characters. |
| 5629 | // Compare lengths (precomputed). |
| 5630 | __ bind(&compare_lengths); |
| 5631 | __ SmiTest(length_difference); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5632 | #ifndef ENABLE_LATIN_1 |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5633 | __ j(not_zero, &result_not_equal, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5634 | #else |
| 5635 | Label length_not_equal; |
| 5636 | __ j(not_zero, &length_not_equal, Label::kNear); |
| 5637 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5638 | |
| 5639 | // Result is EQUAL. |
| 5640 | __ Move(rax, Smi::FromInt(EQUAL)); |
| 5641 | __ ret(0); |
| 5642 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5643 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5644 | #ifdef ENABLE_LATIN_1 |
| 5645 | Label result_less; |
| 5646 | __ bind(&length_not_equal); |
| 5647 | __ j(greater, &result_greater, Label::kNear); |
| 5648 | __ jmp(&result_less, Label::kNear); |
| 5649 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5650 | __ bind(&result_not_equal); |
| 5651 | // Unequal comparison of left to right, either character or length. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5652 | #ifndef ENABLE_LATIN_1 |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5653 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5654 | #else |
| 5655 | __ j(above, &result_greater, Label::kNear); |
| 5656 | __ bind(&result_less); |
| 5657 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5658 | |
| 5659 | // Result is LESS. |
| 5660 | __ Move(rax, Smi::FromInt(LESS)); |
| 5661 | __ ret(0); |
| 5662 | |
| 5663 | // Result is GREATER. |
| 5664 | __ bind(&result_greater); |
| 5665 | __ Move(rax, Smi::FromInt(GREATER)); |
| 5666 | __ ret(0); |
| 5667 | } |
| 5668 | |
| 5669 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5670 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 5671 | MacroAssembler* masm, |
| 5672 | Register left, |
| 5673 | Register right, |
| 5674 | Register length, |
| 5675 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5676 | Label* chars_not_equal, |
| 5677 | Label::Distance near_jump) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5678 | // Change index to run from -length to -1 by adding length to string |
| 5679 | // start. This means that loop ends when index reaches zero, which |
| 5680 | // doesn't need an additional compare. |
| 5681 | __ SmiToInteger32(length, length); |
| 5682 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5683 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5684 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5685 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5686 | __ neg(length); |
| 5687 | Register index = length; // index = -length; |
| 5688 | |
| 5689 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5690 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5691 | __ bind(&loop); |
| 5692 | __ movb(scratch, Operand(left, index, times_1, 0)); |
| 5693 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5694 | __ j(not_equal, chars_not_equal, near_jump); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 5695 | __ incq(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5696 | __ j(not_zero, &loop); |
| 5697 | } |
| 5698 | |
| 5699 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5700 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 5701 | Label runtime; |
| 5702 | |
| 5703 | // Stack frame on entry. |
| 5704 | // rsp[0]: return address |
| 5705 | // rsp[8]: right string |
| 5706 | // rsp[16]: left string |
| 5707 | |
| 5708 | __ movq(rdx, Operand(rsp, 2 * kPointerSize)); // left |
| 5709 | __ movq(rax, Operand(rsp, 1 * kPointerSize)); // right |
| 5710 | |
| 5711 | // Check for identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5712 | Label not_same; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5713 | __ cmpq(rdx, rax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5714 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5715 | __ Move(rax, Smi::FromInt(EQUAL)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5716 | Counters* counters = masm->isolate()->counters(); |
| 5717 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5718 | __ ret(2 * kPointerSize); |
| 5719 | |
| 5720 | __ bind(¬_same); |
| 5721 | |
| 5722 | // Check that both are sequential ASCII strings. |
| 5723 | __ JumpIfNotBothSequentialAsciiStrings(rdx, rax, rcx, rbx, &runtime); |
| 5724 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5725 | // Inline comparison of ASCII strings. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5726 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5727 | // Drop arguments from the stack |
| 5728 | __ pop(rcx); |
| 5729 | __ addq(rsp, Immediate(2 * kPointerSize)); |
| 5730 | __ push(rcx); |
| 5731 | GenerateCompareFlatAsciiStrings(masm, rdx, rax, rcx, rbx, rdi, r8); |
| 5732 | |
| 5733 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 5734 | // tagged as a small integer. |
| 5735 | __ bind(&runtime); |
| 5736 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 5737 | } |
| 5738 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 5739 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5740 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5741 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5742 | Label miss; |
| 5743 | __ JumpIfNotBothSmi(rdx, rax, &miss, Label::kNear); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5744 | |
| 5745 | if (GetCondition() == equal) { |
| 5746 | // For equality we do not care about the sign of the result. |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5747 | __ subq(rax, rdx); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5748 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5749 | Label done; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5750 | __ subq(rdx, rax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5751 | __ j(no_overflow, &done, Label::kNear); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5752 | // Correct sign of result in case of overflow. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 5753 | __ not_(rdx); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5754 | __ bind(&done); |
| 5755 | __ movq(rax, rdx); |
| 5756 | } |
| 5757 | __ ret(0); |
| 5758 | |
| 5759 | __ bind(&miss); |
| 5760 | GenerateMiss(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5761 | } |
| 5762 | |
| 5763 | |
| 5764 | void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5765 | ASSERT(state_ == CompareIC::HEAP_NUMBER); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5766 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5767 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 5768 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5769 | Label miss; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5770 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5771 | if (left_ == CompareIC::SMI) { |
| 5772 | __ JumpIfNotSmi(rdx, &miss); |
| 5773 | } |
| 5774 | if (right_ == CompareIC::SMI) { |
| 5775 | __ JumpIfNotSmi(rax, &miss); |
| 5776 | } |
| 5777 | |
| 5778 | // Load left and right operand. |
| 5779 | Label done, left, left_smi, right_smi; |
| 5780 | __ JumpIfSmi(rax, &right_smi, Label::kNear); |
| 5781 | __ CompareMap(rax, masm->isolate()->factory()->heap_number_map(), NULL); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 5782 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5783 | __ movsd(xmm1, FieldOperand(rax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5784 | __ jmp(&left, Label::kNear); |
| 5785 | __ bind(&right_smi); |
| 5786 | __ SmiToInteger32(rcx, rax); // Can't clobber rax yet. |
| 5787 | __ cvtlsi2sd(xmm1, rcx); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5788 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5789 | __ bind(&left); |
| 5790 | __ JumpIfSmi(rdx, &left_smi, Label::kNear); |
| 5791 | __ CompareMap(rdx, masm->isolate()->factory()->heap_number_map(), NULL); |
| 5792 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 5793 | __ movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset)); |
| 5794 | __ jmp(&done); |
| 5795 | __ bind(&left_smi); |
| 5796 | __ SmiToInteger32(rcx, rdx); // Can't clobber rdx yet. |
| 5797 | __ cvtlsi2sd(xmm0, rcx); |
| 5798 | |
| 5799 | __ bind(&done); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5800 | // Compare operands |
| 5801 | __ ucomisd(xmm0, xmm1); |
| 5802 | |
| 5803 | // Don't base result on EFLAGS when a NaN is involved. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5804 | __ j(parity_even, &unordered, Label::kNear); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5805 | |
| 5806 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 5807 | // Performing mov, because xor would destroy the flag register. |
| 5808 | __ movl(rax, Immediate(0)); |
| 5809 | __ movl(rcx, Immediate(0)); |
| 5810 | __ setcc(above, rax); // Add one to zero if carry clear and not equal. |
| 5811 | __ sbbq(rax, rcx); // Subtract one if below (aka. carry set). |
| 5812 | __ ret(0); |
| 5813 | |
| 5814 | __ bind(&unordered); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5815 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5816 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 5817 | CompareIC::GENERIC); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5818 | __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 5819 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 5820 | __ bind(&maybe_undefined1); |
| 5821 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 5822 | __ Cmp(rax, masm->isolate()->factory()->undefined_value()); |
| 5823 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5824 | __ JumpIfSmi(rdx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 5825 | __ CmpObjectType(rdx, HEAP_NUMBER_TYPE, rcx); |
| 5826 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 5827 | __ jmp(&unordered); |
| 5828 | } |
| 5829 | |
| 5830 | __ bind(&maybe_undefined2); |
| 5831 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 5832 | __ Cmp(rdx, masm->isolate()->factory()->undefined_value()); |
| 5833 | __ j(equal, &unordered); |
| 5834 | } |
| 5835 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5836 | __ bind(&miss); |
| 5837 | GenerateMiss(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5841 | void ICCompareStub::GenerateSymbols(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5842 | ASSERT(state_ == CompareIC::SYMBOL); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5843 | ASSERT(GetCondition() == equal); |
| 5844 | |
| 5845 | // Registers containing left and right operands respectively. |
| 5846 | Register left = rdx; |
| 5847 | Register right = rax; |
| 5848 | Register tmp1 = rcx; |
| 5849 | Register tmp2 = rbx; |
| 5850 | |
| 5851 | // Check that both operands are heap objects. |
| 5852 | Label miss; |
| 5853 | Condition cond = masm->CheckEitherSmi(left, right, tmp1); |
| 5854 | __ j(cond, &miss, Label::kNear); |
| 5855 | |
| 5856 | // Check that both operands are symbols. |
| 5857 | __ movq(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 5858 | __ movq(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 5859 | __ movzxbq(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 5860 | __ movzxbq(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 5861 | STATIC_ASSERT(kSymbolTag != 0); |
| 5862 | __ and_(tmp1, tmp2); |
| 5863 | __ testb(tmp1, Immediate(kIsSymbolMask)); |
| 5864 | __ j(zero, &miss, Label::kNear); |
| 5865 | |
| 5866 | // Symbols are compared by identity. |
| 5867 | Label done; |
| 5868 | __ cmpq(left, right); |
| 5869 | // Make sure rax is non-zero. At this point input operands are |
| 5870 | // guaranteed to be non-zero. |
| 5871 | ASSERT(right.is(rax)); |
| 5872 | __ j(not_equal, &done, Label::kNear); |
| 5873 | STATIC_ASSERT(EQUAL == 0); |
| 5874 | STATIC_ASSERT(kSmiTag == 0); |
| 5875 | __ Move(rax, Smi::FromInt(EQUAL)); |
| 5876 | __ bind(&done); |
| 5877 | __ ret(0); |
| 5878 | |
| 5879 | __ bind(&miss); |
| 5880 | GenerateMiss(masm); |
| 5881 | } |
| 5882 | |
| 5883 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5884 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5885 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5886 | Label miss; |
| 5887 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 5888 | bool equality = Token::IsEqualityOp(op_); |
| 5889 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5890 | // Registers containing left and right operands respectively. |
| 5891 | Register left = rdx; |
| 5892 | Register right = rax; |
| 5893 | Register tmp1 = rcx; |
| 5894 | Register tmp2 = rbx; |
| 5895 | Register tmp3 = rdi; |
| 5896 | |
| 5897 | // Check that both operands are heap objects. |
| 5898 | Condition cond = masm->CheckEitherSmi(left, right, tmp1); |
| 5899 | __ j(cond, &miss); |
| 5900 | |
| 5901 | // Check that both operands are strings. This leaves the instance |
| 5902 | // types loaded in tmp1 and tmp2. |
| 5903 | __ movq(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 5904 | __ movq(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 5905 | __ movzxbq(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 5906 | __ movzxbq(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 5907 | __ movq(tmp3, tmp1); |
| 5908 | STATIC_ASSERT(kNotStringTag != 0); |
| 5909 | __ or_(tmp3, tmp2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5910 | __ testb(tmp3, Immediate(kIsNotStringMask)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5911 | __ j(not_zero, &miss); |
| 5912 | |
| 5913 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5914 | Label not_same; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5915 | __ cmpq(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5916 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5917 | STATIC_ASSERT(EQUAL == 0); |
| 5918 | STATIC_ASSERT(kSmiTag == 0); |
| 5919 | __ Move(rax, Smi::FromInt(EQUAL)); |
| 5920 | __ ret(0); |
| 5921 | |
| 5922 | // Handle not identical strings. |
| 5923 | __ bind(¬_same); |
| 5924 | |
| 5925 | // Check that both strings are symbols. If they are, we're done |
| 5926 | // because we already know they are not identical. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 5927 | if (equality) { |
| 5928 | Label do_compare; |
| 5929 | STATIC_ASSERT(kSymbolTag != 0); |
| 5930 | __ and_(tmp1, tmp2); |
| 5931 | __ testb(tmp1, Immediate(kIsSymbolMask)); |
| 5932 | __ j(zero, &do_compare, Label::kNear); |
| 5933 | // Make sure rax is non-zero. At this point input operands are |
| 5934 | // guaranteed to be non-zero. |
| 5935 | ASSERT(right.is(rax)); |
| 5936 | __ ret(0); |
| 5937 | __ bind(&do_compare); |
| 5938 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5939 | |
| 5940 | // Check that both strings are sequential ASCII. |
| 5941 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5942 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 5943 | |
| 5944 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 5945 | if (equality) { |
| 5946 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 5947 | masm, left, right, tmp1, tmp2); |
| 5948 | } else { |
| 5949 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 5950 | masm, left, right, tmp1, tmp2, tmp3, kScratchRegister); |
| 5951 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5952 | |
| 5953 | // Handle more complex cases in runtime. |
| 5954 | __ bind(&runtime); |
| 5955 | __ pop(tmp1); // Return address. |
| 5956 | __ push(left); |
| 5957 | __ push(right); |
| 5958 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 5959 | if (equality) { |
| 5960 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 5961 | } else { |
| 5962 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 5963 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5964 | |
| 5965 | __ bind(&miss); |
| 5966 | GenerateMiss(masm); |
| 5967 | } |
| 5968 | |
| 5969 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5970 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5971 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5972 | Label miss; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5973 | Condition either_smi = masm->CheckEitherSmi(rdx, rax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5974 | __ j(either_smi, &miss, Label::kNear); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5975 | |
| 5976 | __ CmpObjectType(rax, JS_OBJECT_TYPE, rcx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5977 | __ j(not_equal, &miss, Label::kNear); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5978 | __ CmpObjectType(rdx, JS_OBJECT_TYPE, rcx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5979 | __ j(not_equal, &miss, Label::kNear); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5980 | |
| 5981 | ASSERT(GetCondition() == equal); |
| 5982 | __ subq(rax, rdx); |
| 5983 | __ ret(0); |
| 5984 | |
| 5985 | __ bind(&miss); |
| 5986 | GenerateMiss(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5987 | } |
| 5988 | |
| 5989 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5990 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 5991 | Label miss; |
| 5992 | Condition either_smi = masm->CheckEitherSmi(rdx, rax); |
| 5993 | __ j(either_smi, &miss, Label::kNear); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 5994 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5995 | __ movq(rcx, FieldOperand(rax, HeapObject::kMapOffset)); |
| 5996 | __ movq(rbx, FieldOperand(rdx, HeapObject::kMapOffset)); |
| 5997 | __ Cmp(rcx, known_map_); |
| 5998 | __ j(not_equal, &miss, Label::kNear); |
| 5999 | __ Cmp(rbx, known_map_); |
| 6000 | __ j(not_equal, &miss, Label::kNear); |
| 6001 | |
| 6002 | __ subq(rax, rdx); |
| 6003 | __ ret(0); |
| 6004 | |
| 6005 | __ bind(&miss); |
| 6006 | GenerateMiss(masm); |
| 6007 | } |
| 6008 | |
| 6009 | |
| 6010 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6011 | { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6012 | // Call the runtime system in a fresh internal frame. |
| 6013 | ExternalReference miss = |
| 6014 | ExternalReference(IC_Utility(IC::kCompareIC_Miss), masm->isolate()); |
| 6015 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6016 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 6017 | __ push(rdx); |
| 6018 | __ push(rax); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6019 | __ push(rdx); |
| 6020 | __ push(rax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6021 | __ Push(Smi::FromInt(op_)); |
| 6022 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6023 | |
| 6024 | // Compute the entry point of the rewritten stub. |
| 6025 | __ lea(rdi, FieldOperand(rax, Code::kHeaderSize)); |
| 6026 | __ pop(rax); |
| 6027 | __ pop(rdx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6028 | } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 6029 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 6030 | // Do a tail call to the rewritten stub. |
| 6031 | __ jmp(rdi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6032 | } |
| 6033 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 6034 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6035 | void StringDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 6036 | Label* miss, |
| 6037 | Label* done, |
| 6038 | Register properties, |
| 6039 | Handle<String> name, |
| 6040 | Register r0) { |
| 6041 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6042 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6043 | // undefined value), it guarantees the hash table doesn't contain the |
| 6044 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6045 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6046 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6047 | // r0 points to properties hash. |
| 6048 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6049 | Register index = r0; |
| 6050 | // Capacity is smi 2^n. |
| 6051 | __ SmiToInteger32(index, FieldOperand(properties, kCapacityOffset)); |
| 6052 | __ decl(index); |
| 6053 | __ and_(index, |
| 6054 | Immediate(name->Hash() + StringDictionary::GetProbeOffset(i))); |
| 6055 | |
| 6056 | // Scale the index by multiplying by the entry size. |
| 6057 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6058 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 6059 | |
| 6060 | Register entity_name = r0; |
| 6061 | // Having undefined at this place means the name is not contained. |
| 6062 | ASSERT_EQ(kSmiTagSize, 1); |
| 6063 | __ movq(entity_name, Operand(properties, |
| 6064 | index, |
| 6065 | times_pointer_size, |
| 6066 | kElementsStartOffset - kHeapObjectTag)); |
| 6067 | __ Cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 6068 | __ j(equal, done); |
| 6069 | |
| 6070 | // Stop if found the property. |
| 6071 | __ Cmp(entity_name, Handle<String>(name)); |
| 6072 | __ j(equal, miss); |
| 6073 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6074 | Label the_hole; |
| 6075 | // Check for the hole and skip. |
| 6076 | __ CompareRoot(entity_name, Heap::kTheHoleValueRootIndex); |
| 6077 | __ j(equal, &the_hole, Label::kNear); |
| 6078 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6079 | // Check if the entry name is not a symbol. |
| 6080 | __ movq(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 6081 | __ testb(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 6082 | Immediate(kIsSymbolMask)); |
| 6083 | __ j(zero, miss); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6084 | |
| 6085 | __ bind(&the_hole); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6086 | } |
| 6087 | |
| 6088 | StringDictionaryLookupStub stub(properties, |
| 6089 | r0, |
| 6090 | r0, |
| 6091 | StringDictionaryLookupStub::NEGATIVE_LOOKUP); |
| 6092 | __ Push(Handle<Object>(name)); |
| 6093 | __ push(Immediate(name->Hash())); |
| 6094 | __ CallStub(&stub); |
| 6095 | __ testq(r0, r0); |
| 6096 | __ j(not_zero, miss); |
| 6097 | __ jmp(done); |
| 6098 | } |
| 6099 | |
| 6100 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6101 | // Probe the string dictionary in the |elements| register. Jump to the |
| 6102 | // |done| label if a property with the given name is found leaving the |
| 6103 | // index into the dictionary in |r1|. Jump to the |miss| label |
| 6104 | // otherwise. |
| 6105 | void StringDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 6106 | Label* miss, |
| 6107 | Label* done, |
| 6108 | Register elements, |
| 6109 | Register name, |
| 6110 | Register r0, |
| 6111 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 6112 | ASSERT(!elements.is(r0)); |
| 6113 | ASSERT(!elements.is(r1)); |
| 6114 | ASSERT(!name.is(r0)); |
| 6115 | ASSERT(!name.is(r1)); |
| 6116 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 6117 | __ AssertString(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6118 | |
| 6119 | __ SmiToInteger32(r0, FieldOperand(elements, kCapacityOffset)); |
| 6120 | __ decl(r0); |
| 6121 | |
| 6122 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6123 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6124 | __ movl(r1, FieldOperand(name, String::kHashFieldOffset)); |
| 6125 | __ shrl(r1, Immediate(String::kHashShift)); |
| 6126 | if (i > 0) { |
| 6127 | __ addl(r1, Immediate(StringDictionary::GetProbeOffset(i))); |
| 6128 | } |
| 6129 | __ and_(r1, r0); |
| 6130 | |
| 6131 | // Scale the index by multiplying by the entry size. |
| 6132 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6133 | __ lea(r1, Operand(r1, r1, times_2, 0)); // r1 = r1 * 3 |
| 6134 | |
| 6135 | // Check if the key is identical to the name. |
| 6136 | __ cmpq(name, Operand(elements, r1, times_pointer_size, |
| 6137 | kElementsStartOffset - kHeapObjectTag)); |
| 6138 | __ j(equal, done); |
| 6139 | } |
| 6140 | |
| 6141 | StringDictionaryLookupStub stub(elements, |
| 6142 | r0, |
| 6143 | r1, |
| 6144 | POSITIVE_LOOKUP); |
| 6145 | __ push(name); |
| 6146 | __ movl(r0, FieldOperand(name, String::kHashFieldOffset)); |
| 6147 | __ shrl(r0, Immediate(String::kHashShift)); |
| 6148 | __ push(r0); |
| 6149 | __ CallStub(&stub); |
| 6150 | |
| 6151 | __ testq(r0, r0); |
| 6152 | __ j(zero, miss); |
| 6153 | __ jmp(done); |
| 6154 | } |
| 6155 | |
| 6156 | |
| 6157 | void StringDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6158 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 6159 | // 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] | 6160 | // Stack frame on entry: |
| 6161 | // esp[0 * kPointerSize]: return address. |
| 6162 | // esp[1 * kPointerSize]: key's hash. |
| 6163 | // esp[2 * kPointerSize]: key. |
| 6164 | // Registers: |
| 6165 | // dictionary_: StringDictionary to probe. |
| 6166 | // result_: used as scratch. |
| 6167 | // index_: will hold an index of entry if lookup is successful. |
| 6168 | // might alias with result_. |
| 6169 | // Returns: |
| 6170 | // result_ is zero if lookup failed, non zero otherwise. |
| 6171 | |
| 6172 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 6173 | |
| 6174 | Register scratch = result_; |
| 6175 | |
| 6176 | __ SmiToInteger32(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 6177 | __ decl(scratch); |
| 6178 | __ push(scratch); |
| 6179 | |
| 6180 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6181 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6182 | // undefined value), it guarantees the hash table doesn't contain the |
| 6183 | // property. It's true even if some slots represent deleted properties |
| 6184 | // (their names are the null value). |
| 6185 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 6186 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6187 | __ movq(scratch, Operand(rsp, 2 * kPointerSize)); |
| 6188 | if (i > 0) { |
| 6189 | __ addl(scratch, Immediate(StringDictionary::GetProbeOffset(i))); |
| 6190 | } |
| 6191 | __ and_(scratch, Operand(rsp, 0)); |
| 6192 | |
| 6193 | // Scale the index by multiplying by the entry size. |
| 6194 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6195 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 6196 | |
| 6197 | // Having undefined at this place means the name is not contained. |
| 6198 | __ movq(scratch, Operand(dictionary_, |
| 6199 | index_, |
| 6200 | times_pointer_size, |
| 6201 | kElementsStartOffset - kHeapObjectTag)); |
| 6202 | |
| 6203 | __ Cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 6204 | __ j(equal, ¬_in_dictionary); |
| 6205 | |
| 6206 | // Stop if found the property. |
| 6207 | __ cmpq(scratch, Operand(rsp, 3 * kPointerSize)); |
| 6208 | __ j(equal, &in_dictionary); |
| 6209 | |
| 6210 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
| 6211 | // If we hit a non symbol key during negative lookup |
| 6212 | // we have to bailout as this key might be equal to the |
| 6213 | // key we are looking for. |
| 6214 | |
| 6215 | // Check if the entry name is not a symbol. |
| 6216 | __ movq(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 6217 | __ testb(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 6218 | Immediate(kIsSymbolMask)); |
| 6219 | __ j(zero, &maybe_in_dictionary); |
| 6220 | } |
| 6221 | } |
| 6222 | |
| 6223 | __ bind(&maybe_in_dictionary); |
| 6224 | // If we are doing negative lookup then probing failure should be |
| 6225 | // treated as a lookup success. For positive lookup probing failure |
| 6226 | // should be treated as lookup failure. |
| 6227 | if (mode_ == POSITIVE_LOOKUP) { |
| 6228 | __ movq(scratch, Immediate(0)); |
| 6229 | __ Drop(1); |
| 6230 | __ ret(2 * kPointerSize); |
| 6231 | } |
| 6232 | |
| 6233 | __ bind(&in_dictionary); |
| 6234 | __ movq(scratch, Immediate(1)); |
| 6235 | __ Drop(1); |
| 6236 | __ ret(2 * kPointerSize); |
| 6237 | |
| 6238 | __ bind(¬_in_dictionary); |
| 6239 | __ movq(scratch, Immediate(0)); |
| 6240 | __ Drop(1); |
| 6241 | __ ret(2 * kPointerSize); |
| 6242 | } |
| 6243 | |
| 6244 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6245 | struct AheadOfTimeWriteBarrierStubList { |
| 6246 | Register object, value, address; |
| 6247 | RememberedSetAction action; |
| 6248 | }; |
| 6249 | |
| 6250 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6251 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 6252 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6253 | struct AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
| 6254 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6255 | { REG(rbx), REG(rax), REG(rdi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6256 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6257 | { REG(rbx), REG(rcx), REG(rdx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6258 | // Used in CompileStoreGlobal. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6259 | { REG(rbx), REG(rcx), REG(rdx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6260 | // Used in StoreStubCompiler::CompileStoreField and |
| 6261 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6262 | { REG(rdx), REG(rcx), REG(rbx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6263 | // GenerateStoreField calls the stub with two different permutations of |
| 6264 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6265 | { REG(rbx), REG(rcx), REG(rdx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6266 | // StoreIC::GenerateNormal via GenerateDictionaryStore. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6267 | { REG(rbx), REG(r8), REG(r9), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6268 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6269 | { REG(rbx), REG(rdx), REG(rcx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6270 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6271 | { REG(rdi), REG(rbx), REG(rcx), EMIT_REMEMBERED_SET}, |
| 6272 | { REG(rdx), REG(rdi), REG(rbx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 6273 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 6274 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6275 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6276 | { REG(rdx), REG(rbx), REG(rdi), EMIT_REMEMBERED_SET}, |
| 6277 | { REG(rdx), REG(rbx), REG(rdi), OMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 6278 | // ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6279 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6280 | { REG(rdx), REG(r11), REG(r15), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6281 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6282 | { REG(r11), REG(rax), REG(r15), EMIT_REMEMBERED_SET}, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 6283 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6284 | { REG(rbx), REG(rax), REG(rcx), EMIT_REMEMBERED_SET}, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 6285 | // FastNewClosureStub::Generate |
| 6286 | { REG(rcx), REG(rdx), REG(rbx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6287 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6288 | { 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] | 6289 | }; |
| 6290 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6291 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6292 | |
| 6293 | bool RecordWriteStub::IsPregenerated() { |
| 6294 | for (AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
| 6295 | !entry->object.is(no_reg); |
| 6296 | entry++) { |
| 6297 | if (object_.is(entry->object) && |
| 6298 | value_.is(entry->value) && |
| 6299 | address_.is(entry->address) && |
| 6300 | remembered_set_action_ == entry->action && |
| 6301 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 6302 | return true; |
| 6303 | } |
| 6304 | } |
| 6305 | return false; |
| 6306 | } |
| 6307 | |
| 6308 | |
| 6309 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime() { |
| 6310 | StoreBufferOverflowStub stub1(kDontSaveFPRegs); |
| 6311 | stub1.GetCode()->set_is_pregenerated(true); |
| 6312 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
| 6313 | stub2.GetCode()->set_is_pregenerated(true); |
| 6314 | } |
| 6315 | |
| 6316 | |
| 6317 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime() { |
| 6318 | for (AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
| 6319 | !entry->object.is(no_reg); |
| 6320 | entry++) { |
| 6321 | RecordWriteStub stub(entry->object, |
| 6322 | entry->value, |
| 6323 | entry->address, |
| 6324 | entry->action, |
| 6325 | kDontSaveFPRegs); |
| 6326 | stub.GetCode()->set_is_pregenerated(true); |
| 6327 | } |
| 6328 | } |
| 6329 | |
| 6330 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 6331 | bool CodeStub::CanUseFPRegisters() { |
| 6332 | return true; // Always have SSE2 on x64. |
| 6333 | } |
| 6334 | |
| 6335 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6336 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 6337 | // the value has just been written into the object, now this stub makes sure |
| 6338 | // we keep the GC informed. The word in the object where the value has been |
| 6339 | // written is in the address register. |
| 6340 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 6341 | Label skip_to_incremental_noncompacting; |
| 6342 | Label skip_to_incremental_compacting; |
| 6343 | |
| 6344 | // The first two instructions are generated with labels so as to get the |
| 6345 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 6346 | // forth between a compare instructions (a nop in this position) and the |
| 6347 | // real branch when we start and stop incremental heap marking. |
| 6348 | // See RecordWriteStub::Patch for details. |
| 6349 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 6350 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 6351 | |
| 6352 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 6353 | __ RememberedSetHelper(object_, |
| 6354 | address_, |
| 6355 | value_, |
| 6356 | save_fp_regs_mode_, |
| 6357 | MacroAssembler::kReturnAtEnd); |
| 6358 | } else { |
| 6359 | __ ret(0); |
| 6360 | } |
| 6361 | |
| 6362 | __ bind(&skip_to_incremental_noncompacting); |
| 6363 | GenerateIncremental(masm, INCREMENTAL); |
| 6364 | |
| 6365 | __ bind(&skip_to_incremental_compacting); |
| 6366 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 6367 | |
| 6368 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 6369 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 6370 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 6371 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 6372 | } |
| 6373 | |
| 6374 | |
| 6375 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 6376 | regs_.Save(masm); |
| 6377 | |
| 6378 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 6379 | Label dont_need_remembered_set; |
| 6380 | |
| 6381 | __ movq(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 6382 | __ JumpIfNotInNewSpace(regs_.scratch0(), |
| 6383 | regs_.scratch0(), |
| 6384 | &dont_need_remembered_set); |
| 6385 | |
| 6386 | __ CheckPageFlag(regs_.object(), |
| 6387 | regs_.scratch0(), |
| 6388 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 6389 | not_zero, |
| 6390 | &dont_need_remembered_set); |
| 6391 | |
| 6392 | // First notify the incremental marker if necessary, then update the |
| 6393 | // remembered set. |
| 6394 | CheckNeedsToInformIncrementalMarker( |
| 6395 | masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode); |
| 6396 | InformIncrementalMarker(masm, mode); |
| 6397 | regs_.Restore(masm); |
| 6398 | __ RememberedSetHelper(object_, |
| 6399 | address_, |
| 6400 | value_, |
| 6401 | save_fp_regs_mode_, |
| 6402 | MacroAssembler::kReturnAtEnd); |
| 6403 | |
| 6404 | __ bind(&dont_need_remembered_set); |
| 6405 | } |
| 6406 | |
| 6407 | CheckNeedsToInformIncrementalMarker( |
| 6408 | masm, kReturnOnNoNeedToInformIncrementalMarker, mode); |
| 6409 | InformIncrementalMarker(masm, mode); |
| 6410 | regs_.Restore(masm); |
| 6411 | __ ret(0); |
| 6412 | } |
| 6413 | |
| 6414 | |
| 6415 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 6416 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 6417 | #ifdef _WIN64 |
| 6418 | Register arg3 = r8; |
| 6419 | Register arg2 = rdx; |
| 6420 | Register arg1 = rcx; |
| 6421 | #else |
| 6422 | Register arg3 = rdx; |
| 6423 | Register arg2 = rsi; |
| 6424 | Register arg1 = rdi; |
| 6425 | #endif |
| 6426 | Register address = |
| 6427 | arg1.is(regs_.address()) ? kScratchRegister : regs_.address(); |
| 6428 | ASSERT(!address.is(regs_.object())); |
| 6429 | ASSERT(!address.is(arg1)); |
| 6430 | __ Move(address, regs_.address()); |
| 6431 | __ Move(arg1, regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 6432 | // TODO(gc) Can we just set address arg2 in the beginning? |
| 6433 | __ Move(arg2, address); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6434 | __ LoadAddress(arg3, ExternalReference::isolate_address()); |
| 6435 | int argument_count = 3; |
| 6436 | |
| 6437 | AllowExternalCallThatCantCauseGC scope(masm); |
| 6438 | __ PrepareCallCFunction(argument_count); |
| 6439 | if (mode == INCREMENTAL_COMPACTION) { |
| 6440 | __ CallCFunction( |
| 6441 | ExternalReference::incremental_evacuation_record_write_function( |
| 6442 | masm->isolate()), |
| 6443 | argument_count); |
| 6444 | } else { |
| 6445 | ASSERT(mode == INCREMENTAL); |
| 6446 | __ CallCFunction( |
| 6447 | ExternalReference::incremental_marking_record_write_function( |
| 6448 | masm->isolate()), |
| 6449 | argument_count); |
| 6450 | } |
| 6451 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 6452 | } |
| 6453 | |
| 6454 | |
| 6455 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 6456 | MacroAssembler* masm, |
| 6457 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 6458 | Mode mode) { |
| 6459 | Label on_black; |
| 6460 | Label need_incremental; |
| 6461 | Label need_incremental_pop_object; |
| 6462 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 6463 | __ movq(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 6464 | __ and_(regs_.scratch0(), regs_.object()); |
| 6465 | __ movq(regs_.scratch1(), |
| 6466 | Operand(regs_.scratch0(), |
| 6467 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 6468 | __ subq(regs_.scratch1(), Immediate(1)); |
| 6469 | __ movq(Operand(regs_.scratch0(), |
| 6470 | MemoryChunk::kWriteBarrierCounterOffset), |
| 6471 | regs_.scratch1()); |
| 6472 | __ j(negative, &need_incremental); |
| 6473 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6474 | // Let's look at the color of the object: If it is not black we don't have |
| 6475 | // to inform the incremental marker. |
| 6476 | __ JumpIfBlack(regs_.object(), |
| 6477 | regs_.scratch0(), |
| 6478 | regs_.scratch1(), |
| 6479 | &on_black, |
| 6480 | Label::kNear); |
| 6481 | |
| 6482 | regs_.Restore(masm); |
| 6483 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 6484 | __ RememberedSetHelper(object_, |
| 6485 | address_, |
| 6486 | value_, |
| 6487 | save_fp_regs_mode_, |
| 6488 | MacroAssembler::kReturnAtEnd); |
| 6489 | } else { |
| 6490 | __ ret(0); |
| 6491 | } |
| 6492 | |
| 6493 | __ bind(&on_black); |
| 6494 | |
| 6495 | // Get the value from the slot. |
| 6496 | __ movq(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 6497 | |
| 6498 | if (mode == INCREMENTAL_COMPACTION) { |
| 6499 | Label ensure_not_white; |
| 6500 | |
| 6501 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 6502 | regs_.scratch1(), // Scratch. |
| 6503 | MemoryChunk::kEvacuationCandidateMask, |
| 6504 | zero, |
| 6505 | &ensure_not_white, |
| 6506 | Label::kNear); |
| 6507 | |
| 6508 | __ CheckPageFlag(regs_.object(), |
| 6509 | regs_.scratch1(), // Scratch. |
| 6510 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 6511 | zero, |
| 6512 | &need_incremental); |
| 6513 | |
| 6514 | __ bind(&ensure_not_white); |
| 6515 | } |
| 6516 | |
| 6517 | // We need an extra register for this, so we push the object register |
| 6518 | // temporarily. |
| 6519 | __ push(regs_.object()); |
| 6520 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 6521 | regs_.scratch1(), // Scratch. |
| 6522 | regs_.object(), // Scratch. |
| 6523 | &need_incremental_pop_object, |
| 6524 | Label::kNear); |
| 6525 | __ pop(regs_.object()); |
| 6526 | |
| 6527 | regs_.Restore(masm); |
| 6528 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 6529 | __ RememberedSetHelper(object_, |
| 6530 | address_, |
| 6531 | value_, |
| 6532 | save_fp_regs_mode_, |
| 6533 | MacroAssembler::kReturnAtEnd); |
| 6534 | } else { |
| 6535 | __ ret(0); |
| 6536 | } |
| 6537 | |
| 6538 | __ bind(&need_incremental_pop_object); |
| 6539 | __ pop(regs_.object()); |
| 6540 | |
| 6541 | __ bind(&need_incremental); |
| 6542 | |
| 6543 | // Fall through when we need to inform the incremental marker. |
| 6544 | } |
| 6545 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 6546 | |
| 6547 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 6548 | // ----------- S t a t e ------------- |
| 6549 | // -- rax : element value to store |
| 6550 | // -- rbx : array literal |
| 6551 | // -- rdi : map of array literal |
| 6552 | // -- rcx : element index as smi |
| 6553 | // -- rdx : array literal index in function |
| 6554 | // -- rsp[0] : return address |
| 6555 | // ----------------------------------- |
| 6556 | |
| 6557 | Label element_done; |
| 6558 | Label double_elements; |
| 6559 | Label smi_element; |
| 6560 | Label slow_elements; |
| 6561 | Label fast_elements; |
| 6562 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 6563 | __ CheckFastElements(rdi, &double_elements); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 6564 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 6565 | // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 6566 | __ JumpIfSmi(rax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 6567 | __ CheckFastSmiElements(rdi, &fast_elements); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 6568 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 6569 | // Store into the array literal requires a elements transition. Call into |
| 6570 | // the runtime. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 6571 | |
| 6572 | __ bind(&slow_elements); |
| 6573 | __ pop(rdi); // Pop return address and remember to put back later for tail |
| 6574 | // call. |
| 6575 | __ push(rbx); |
| 6576 | __ push(rcx); |
| 6577 | __ push(rax); |
| 6578 | __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 6579 | __ push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); |
| 6580 | __ push(rdx); |
| 6581 | __ push(rdi); // Return return address so that tail call returns to right |
| 6582 | // place. |
| 6583 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 6584 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 6585 | // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 6586 | __ bind(&fast_elements); |
| 6587 | __ SmiToInteger32(kScratchRegister, rcx); |
| 6588 | __ movq(rbx, FieldOperand(rbx, JSObject::kElementsOffset)); |
| 6589 | __ lea(rcx, FieldOperand(rbx, kScratchRegister, times_pointer_size, |
| 6590 | FixedArrayBase::kHeaderSize)); |
| 6591 | __ movq(Operand(rcx, 0), rax); |
| 6592 | // Update the write barrier for the array store. |
| 6593 | __ RecordWrite(rbx, rcx, rax, |
| 6594 | kDontSaveFPRegs, |
| 6595 | EMIT_REMEMBERED_SET, |
| 6596 | OMIT_SMI_CHECK); |
| 6597 | __ ret(0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 6598 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 6599 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or |
| 6600 | // FAST_*_ELEMENTS, and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 6601 | __ bind(&smi_element); |
| 6602 | __ SmiToInteger32(kScratchRegister, rcx); |
| 6603 | __ movq(rbx, FieldOperand(rbx, JSObject::kElementsOffset)); |
| 6604 | __ movq(FieldOperand(rbx, kScratchRegister, times_pointer_size, |
| 6605 | FixedArrayBase::kHeaderSize), rax); |
| 6606 | __ ret(0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 6607 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 6608 | // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS. |
| 6609 | __ bind(&double_elements); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 6610 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 6611 | __ movq(r9, FieldOperand(rbx, JSObject::kElementsOffset)); |
| 6612 | __ SmiToInteger32(r11, rcx); |
| 6613 | __ StoreNumberToDoubleElements(rax, |
| 6614 | r9, |
| 6615 | r11, |
| 6616 | xmm0, |
| 6617 | &slow_elements); |
| 6618 | __ ret(0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 6619 | } |
| 6620 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 6621 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 6622 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
| 6623 | ASSERT(!Serializer::enabled()); |
| 6624 | CEntryStub ces(1, kSaveFPRegs); |
| 6625 | __ Call(ces.GetCode(), RelocInfo::CODE_TARGET); |
| 6626 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 6627 | __ ret(0); // Return to IC Miss stub, continuation still on stack. |
| 6628 | } |
| 6629 | |
| 6630 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 6631 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 6632 | if (entry_hook_ != NULL) { |
| 6633 | ProfileEntryHookStub stub; |
| 6634 | masm->CallStub(&stub); |
| 6635 | } |
| 6636 | } |
| 6637 | |
| 6638 | |
| 6639 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 6640 | // Save volatile registers. |
| 6641 | // Live registers at this point are the same as at the start of any |
| 6642 | // JS function: |
| 6643 | // o rdi: the JS function object being called (i.e. ourselves) |
| 6644 | // o rsi: our context |
| 6645 | // o rbp: our caller's frame pointer |
| 6646 | // o rsp: stack pointer (pointing to return address) |
| 6647 | // o rcx: rcx is zero for method calls and non-zero for function calls. |
| 6648 | #ifdef _WIN64 |
| 6649 | const int kNumSavedRegisters = 1; |
| 6650 | |
| 6651 | __ push(rcx); |
| 6652 | #else |
| 6653 | const int kNumSavedRegisters = 3; |
| 6654 | |
| 6655 | __ push(rcx); |
| 6656 | __ push(rdi); |
| 6657 | __ push(rsi); |
| 6658 | #endif |
| 6659 | |
| 6660 | // Calculate the original stack pointer and store it in the second arg. |
| 6661 | #ifdef _WIN64 |
| 6662 | __ lea(rdx, Operand(rsp, kNumSavedRegisters * kPointerSize)); |
| 6663 | #else |
| 6664 | __ lea(rsi, Operand(rsp, kNumSavedRegisters * kPointerSize)); |
| 6665 | #endif |
| 6666 | |
| 6667 | // Calculate the function address to the first arg. |
| 6668 | #ifdef _WIN64 |
| 6669 | __ movq(rcx, Operand(rdx, 0)); |
| 6670 | __ subq(rcx, Immediate(Assembler::kShortCallInstructionLength)); |
| 6671 | #else |
| 6672 | __ movq(rdi, Operand(rsi, 0)); |
| 6673 | __ subq(rdi, Immediate(Assembler::kShortCallInstructionLength)); |
| 6674 | #endif |
| 6675 | |
| 6676 | // Call the entry hook function. |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 6677 | __ movq(rax, &entry_hook_, RelocInfo::NONE64); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 6678 | __ movq(rax, Operand(rax, 0)); |
| 6679 | |
| 6680 | AllowExternalCallThatCantCauseGC scope(masm); |
| 6681 | |
| 6682 | const int kArgumentCount = 2; |
| 6683 | __ PrepareCallCFunction(kArgumentCount); |
| 6684 | __ CallCFunction(rax, kArgumentCount); |
| 6685 | |
| 6686 | // Restore volatile regs. |
| 6687 | #ifdef _WIN64 |
| 6688 | __ pop(rcx); |
| 6689 | #else |
| 6690 | __ pop(rsi); |
| 6691 | __ pop(rdi); |
| 6692 | __ pop(rcx); |
| 6693 | #endif |
| 6694 | |
| 6695 | __ Ret(); |
| 6696 | } |
| 6697 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6698 | #undef __ |
| 6699 | |
| 6700 | } } // namespace v8::internal |
| 6701 | |
| 6702 | #endif // V8_TARGET_ARCH_X64 |