danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +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_ARM) |
| 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 | |
| 40 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 41 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 42 | Isolate* isolate, |
| 43 | CodeStubInterfaceDescriptor* descriptor) { |
| 44 | static Register registers[] = { r1, r0 }; |
| 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) |
| 53 | |
| 54 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, |
| 55 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 56 | Condition cond); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 57 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 58 | Register lhs, |
| 59 | Register rhs, |
| 60 | Label* lhs_not_nan, |
| 61 | Label* slow, |
| 62 | bool strict); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 63 | static void EmitTwoNonNanDoubleComparison(MacroAssembler* masm, Condition cond); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 64 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 65 | Register lhs, |
| 66 | Register rhs); |
| 67 | |
| 68 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 69 | // Check if the operand is a heap number. |
| 70 | static void EmitCheckForHeapNumber(MacroAssembler* masm, Register operand, |
| 71 | Register scratch1, Register scratch2, |
| 72 | Label* not_a_heap_number) { |
| 73 | __ ldr(scratch1, FieldMemOperand(operand, HeapObject::kMapOffset)); |
| 74 | __ LoadRoot(scratch2, Heap::kHeapNumberMapRootIndex); |
| 75 | __ cmp(scratch1, scratch2); |
| 76 | __ b(ne, not_a_heap_number); |
| 77 | } |
| 78 | |
| 79 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 80 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 81 | // The ToNumber stub takes one argument in eax. |
| 82 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 83 | __ JumpIfNotSmi(r0, &check_heap_number); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 84 | __ Ret(); |
| 85 | |
| 86 | __ bind(&check_heap_number); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 87 | EmitCheckForHeapNumber(masm, r0, r1, ip, &call_builtin); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 88 | __ Ret(); |
| 89 | |
| 90 | __ bind(&call_builtin); |
| 91 | __ push(r0); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 92 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 96 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 97 | // Create a new closure from the given function info in new |
| 98 | // space. Set the context to the current context in cp. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 99 | Counters* counters = masm->isolate()->counters(); |
| 100 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 101 | Label gc; |
| 102 | |
| 103 | // Pop the function info from the stack. |
| 104 | __ pop(r3); |
| 105 | |
| 106 | // Attempt to allocate new JSFunction in new space. |
| 107 | __ AllocateInNewSpace(JSFunction::kSize, |
| 108 | r0, |
| 109 | r1, |
| 110 | r2, |
| 111 | &gc, |
| 112 | TAG_OBJECT); |
| 113 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 114 | __ IncrementCounter(counters->fast_new_closure_total(), 1, r6, r7); |
| 115 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 116 | int map_index = (language_mode_ == CLASSIC_MODE) |
| 117 | ? Context::FUNCTION_MAP_INDEX |
| 118 | : Context::STRICT_MODE_FUNCTION_MAP_INDEX; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 119 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 120 | // 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] | 121 | // as the map of the allocated object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 122 | __ ldr(r2, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 123 | __ ldr(r2, FieldMemOperand(r2, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 124 | __ ldr(r5, MemOperand(r2, Context::SlotOffset(map_index))); |
| 125 | __ str(r5, FieldMemOperand(r0, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 126 | |
| 127 | // Initialize the rest of the function. We don't have to update the |
| 128 | // write barrier because the allocated object is in new space. |
| 129 | __ LoadRoot(r1, Heap::kEmptyFixedArrayRootIndex); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 130 | __ LoadRoot(r5, Heap::kTheHoleValueRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 131 | __ str(r1, FieldMemOperand(r0, JSObject::kPropertiesOffset)); |
| 132 | __ str(r1, FieldMemOperand(r0, JSObject::kElementsOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 133 | __ str(r5, FieldMemOperand(r0, JSFunction::kPrototypeOrInitialMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 134 | __ str(r3, FieldMemOperand(r0, JSFunction::kSharedFunctionInfoOffset)); |
| 135 | __ str(cp, FieldMemOperand(r0, JSFunction::kContextOffset)); |
| 136 | __ str(r1, FieldMemOperand(r0, JSFunction::kLiteralsOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 137 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 138 | // Initialize the code pointer in the function to be the one |
| 139 | // found in the shared function info object. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 140 | // But first check if there is an optimized version for our context. |
| 141 | Label check_optimized; |
| 142 | Label install_unoptimized; |
| 143 | if (FLAG_cache_optimized_code) { |
| 144 | __ ldr(r1, |
| 145 | FieldMemOperand(r3, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 146 | __ tst(r1, r1); |
| 147 | __ b(ne, &check_optimized); |
| 148 | } |
| 149 | __ bind(&install_unoptimized); |
| 150 | __ LoadRoot(r4, Heap::kUndefinedValueRootIndex); |
| 151 | __ str(r4, FieldMemOperand(r0, JSFunction::kNextFunctionLinkOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 152 | __ ldr(r3, FieldMemOperand(r3, SharedFunctionInfo::kCodeOffset)); |
| 153 | __ add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 154 | __ str(r3, FieldMemOperand(r0, JSFunction::kCodeEntryOffset)); |
| 155 | |
| 156 | // Return result. The argument function info has been popped already. |
| 157 | __ Ret(); |
| 158 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 159 | __ bind(&check_optimized); |
| 160 | |
| 161 | __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1, r6, r7); |
| 162 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 163 | // r2 holds native context, r1 points to fixed array of 3-element entries |
| 164 | // (native context, optimized code, literals). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 165 | // The optimized code map must never be empty, so check the first elements. |
| 166 | Label install_optimized; |
| 167 | // Speculatively move code object into r4. |
| 168 | __ ldr(r4, FieldMemOperand(r1, FixedArray::kHeaderSize + kPointerSize)); |
| 169 | __ ldr(r5, FieldMemOperand(r1, FixedArray::kHeaderSize)); |
| 170 | __ cmp(r2, r5); |
| 171 | __ b(eq, &install_optimized); |
| 172 | |
| 173 | // Iterate through the rest of map backwards. r4 holds an index as a Smi. |
| 174 | Label loop; |
| 175 | __ ldr(r4, FieldMemOperand(r1, FixedArray::kLengthOffset)); |
| 176 | __ bind(&loop); |
| 177 | // Do not double check first entry. |
| 178 | |
| 179 | __ cmp(r4, Operand(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
| 180 | __ b(eq, &install_unoptimized); |
| 181 | __ sub(r4, r4, Operand( |
| 182 | Smi::FromInt(SharedFunctionInfo::kEntryLength))); // Skip an entry. |
| 183 | __ add(r5, r1, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 184 | __ add(r5, r5, Operand(r4, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 185 | __ ldr(r5, MemOperand(r5)); |
| 186 | __ cmp(r2, r5); |
| 187 | __ b(ne, &loop); |
| 188 | // Hit: fetch the optimized code. |
| 189 | __ add(r5, r1, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 190 | __ add(r5, r5, Operand(r4, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 191 | __ add(r5, r5, Operand(kPointerSize)); |
| 192 | __ ldr(r4, MemOperand(r5)); |
| 193 | |
| 194 | __ bind(&install_optimized); |
| 195 | __ IncrementCounter(counters->fast_new_closure_install_optimized(), |
| 196 | 1, r6, r7); |
| 197 | |
| 198 | // TODO(fschneider): Idea: store proper code pointers in the map and either |
| 199 | // unmangle them on marking or do nothing as the whole map is discarded on |
| 200 | // major GC anyway. |
| 201 | __ add(r4, r4, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 202 | __ str(r4, FieldMemOperand(r0, JSFunction::kCodeEntryOffset)); |
| 203 | |
| 204 | // Now link a function into a list of optimized functions. |
| 205 | __ ldr(r4, ContextOperand(r2, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 206 | |
| 207 | __ str(r4, FieldMemOperand(r0, JSFunction::kNextFunctionLinkOffset)); |
| 208 | // No need for write barrier as JSFunction (eax) is in the new space. |
| 209 | |
| 210 | __ str(r0, ContextOperand(r2, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 211 | // Store JSFunction (eax) into edx before issuing write barrier as |
| 212 | // it clobbers all the registers passed. |
| 213 | __ mov(r4, r0); |
| 214 | __ RecordWriteContextSlot( |
| 215 | r2, |
| 216 | Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), |
| 217 | r4, |
| 218 | r1, |
| 219 | kLRHasNotBeenSaved, |
| 220 | kDontSaveFPRegs); |
| 221 | |
| 222 | // Return result. The argument function info has been popped already. |
| 223 | __ Ret(); |
| 224 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 225 | // Create a new closure through the slower runtime call. |
| 226 | __ bind(&gc); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 227 | __ LoadRoot(r4, Heap::kFalseValueRootIndex); |
| 228 | __ Push(cp, r3, r4); |
| 229 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | |
| 233 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 234 | // Try to allocate the context in new space. |
| 235 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 236 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 237 | |
| 238 | // Attempt to allocate the context in new space. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 239 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 240 | r0, |
| 241 | r1, |
| 242 | r2, |
| 243 | &gc, |
| 244 | TAG_OBJECT); |
| 245 | |
| 246 | // Load the function from the stack. |
| 247 | __ ldr(r3, MemOperand(sp, 0)); |
| 248 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 249 | // Set up the object header. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 250 | __ LoadRoot(r1, Heap::kFunctionContextMapRootIndex); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 251 | __ mov(r2, Operand(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 252 | __ str(r2, FieldMemOperand(r0, FixedArray::kLengthOffset)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 253 | __ str(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 254 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 255 | // Set up the fixed slots, copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 256 | __ ldr(r2, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 257 | __ mov(r1, Operand(Smi::FromInt(0))); |
| 258 | __ str(r3, MemOperand(r0, Context::SlotOffset(Context::CLOSURE_INDEX))); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 259 | __ str(cp, MemOperand(r0, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 260 | __ str(r1, MemOperand(r0, Context::SlotOffset(Context::EXTENSION_INDEX))); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 261 | __ str(r2, MemOperand(r0, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 262 | |
| 263 | // Initialize the rest of the slots to undefined. |
| 264 | __ LoadRoot(r1, Heap::kUndefinedValueRootIndex); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 265 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 266 | __ str(r1, MemOperand(r0, Context::SlotOffset(i))); |
| 267 | } |
| 268 | |
| 269 | // Remove the on-stack argument and return. |
| 270 | __ mov(cp, r0); |
| 271 | __ pop(); |
| 272 | __ Ret(); |
| 273 | |
| 274 | // Need to collect. Call into runtime system. |
| 275 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 276 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 280 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 281 | // Stack layout on entry: |
| 282 | // |
| 283 | // [sp]: function. |
| 284 | // [sp + kPointerSize]: serialized scope info |
| 285 | |
| 286 | // Try to allocate the context in new space. |
| 287 | Label gc; |
| 288 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 289 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
| 290 | r0, r1, r2, &gc, TAG_OBJECT); |
| 291 | |
| 292 | // Load the function from the stack. |
| 293 | __ ldr(r3, MemOperand(sp, 0)); |
| 294 | |
| 295 | // Load the serialized scope info from the stack. |
| 296 | __ ldr(r1, MemOperand(sp, 1 * kPointerSize)); |
| 297 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 298 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 299 | __ LoadRoot(r2, Heap::kBlockContextMapRootIndex); |
| 300 | __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 301 | __ mov(r2, Operand(Smi::FromInt(length))); |
| 302 | __ str(r2, FieldMemOperand(r0, FixedArray::kLengthOffset)); |
| 303 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 304 | // 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] | 305 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 306 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 307 | // we still have to look up. |
| 308 | Label after_sentinel; |
| 309 | __ JumpIfNotSmi(r3, &after_sentinel); |
| 310 | if (FLAG_debug_code) { |
| 311 | const char* message = "Expected 0 as a Smi sentinel"; |
| 312 | __ cmp(r3, Operand::Zero()); |
| 313 | __ Assert(eq, message); |
| 314 | } |
| 315 | __ ldr(r3, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 316 | __ ldr(r3, FieldMemOperand(r3, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 317 | __ ldr(r3, ContextOperand(r3, Context::CLOSURE_INDEX)); |
| 318 | __ bind(&after_sentinel); |
| 319 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 320 | // Set up the fixed slots, copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 321 | __ ldr(r2, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 322 | __ str(r3, ContextOperand(r0, Context::CLOSURE_INDEX)); |
| 323 | __ str(cp, ContextOperand(r0, Context::PREVIOUS_INDEX)); |
| 324 | __ str(r1, ContextOperand(r0, Context::EXTENSION_INDEX)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 325 | __ str(r2, ContextOperand(r0, Context::GLOBAL_OBJECT_INDEX)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 326 | |
| 327 | // Initialize the rest of the slots to the hole value. |
| 328 | __ LoadRoot(r1, Heap::kTheHoleValueRootIndex); |
| 329 | for (int i = 0; i < slots_; i++) { |
| 330 | __ str(r1, ContextOperand(r0, i + Context::MIN_CONTEXT_SLOTS)); |
| 331 | } |
| 332 | |
| 333 | // Remove the on-stack argument and return. |
| 334 | __ mov(cp, r0); |
| 335 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 336 | __ Ret(); |
| 337 | |
| 338 | // Need to collect. Call into runtime system. |
| 339 | __ bind(&gc); |
| 340 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 341 | } |
| 342 | |
| 343 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 344 | static void GenerateFastCloneShallowArrayCommon( |
| 345 | MacroAssembler* masm, |
| 346 | int length, |
| 347 | FastCloneShallowArrayStub::Mode mode, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 348 | AllocationSiteMode allocation_site_mode, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 349 | Label* fail) { |
| 350 | // Registers on entry: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 351 | // |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 352 | // r3: boilerplate literal array. |
| 353 | ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 354 | |
| 355 | // All sizes here are multiples of kPointerSize. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 356 | int elements_size = 0; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 357 | if (length > 0) { |
| 358 | elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 359 | ? FixedDoubleArray::SizeFor(length) |
| 360 | : FixedArray::SizeFor(length); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 361 | } |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 362 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 363 | int size = JSArray::kSize; |
| 364 | int allocation_info_start = size; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 365 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 366 | size += AllocationSiteInfo::kSize; |
| 367 | } |
| 368 | size += elements_size; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 369 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 370 | // Allocate both the JS array and the elements array in one big |
| 371 | // allocation. This avoids multiple limit checks. |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 372 | AllocationFlags flags = TAG_OBJECT; |
| 373 | if (mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS) { |
| 374 | flags = static_cast<AllocationFlags>(DOUBLE_ALIGNMENT | flags); |
| 375 | } |
| 376 | __ AllocateInNewSpace(size, r0, r1, r2, fail, flags); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 377 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 378 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 379 | __ mov(r2, Operand(Handle<Map>(masm->isolate()->heap()-> |
| 380 | allocation_site_info_map()))); |
| 381 | __ str(r2, FieldMemOperand(r0, allocation_info_start)); |
| 382 | __ str(r3, FieldMemOperand(r0, allocation_info_start + kPointerSize)); |
| 383 | } |
| 384 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 385 | // Copy the JS array part. |
| 386 | for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 387 | if ((i != JSArray::kElementsOffset) || (length == 0)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 388 | __ ldr(r1, FieldMemOperand(r3, i)); |
| 389 | __ str(r1, FieldMemOperand(r0, i)); |
| 390 | } |
| 391 | } |
| 392 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 393 | if (length > 0) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 394 | // Get hold of the elements array of the boilerplate and setup the |
| 395 | // elements pointer in the resulting object. |
| 396 | __ ldr(r3, FieldMemOperand(r3, JSArray::kElementsOffset)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 397 | if (allocation_site_mode == TRACK_ALLOCATION_SITE) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 398 | __ add(r2, r0, Operand(JSArray::kSize + AllocationSiteInfo::kSize)); |
| 399 | } else { |
| 400 | __ add(r2, r0, Operand(JSArray::kSize)); |
| 401 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 402 | __ str(r2, FieldMemOperand(r0, JSArray::kElementsOffset)); |
| 403 | |
| 404 | // Copy the elements array. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 405 | ASSERT((elements_size % kPointerSize) == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 406 | __ CopyFields(r2, r3, r1.bit(), elements_size / kPointerSize); |
| 407 | } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) { |
| 411 | // Stack layout on entry: |
| 412 | // |
| 413 | // [sp]: constant elements. |
| 414 | // [sp + kPointerSize]: literal index. |
| 415 | // [sp + (2 * kPointerSize)]: literals array. |
| 416 | |
| 417 | // Load boilerplate object into r3 and check if we need to create a |
| 418 | // boilerplate. |
| 419 | Label slow_case; |
| 420 | __ ldr(r3, MemOperand(sp, 2 * kPointerSize)); |
| 421 | __ ldr(r0, MemOperand(sp, 1 * kPointerSize)); |
| 422 | __ add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 423 | __ ldr(r3, MemOperand(r3, r0, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 424 | __ CompareRoot(r3, Heap::kUndefinedValueRootIndex); |
| 425 | __ b(eq, &slow_case); |
| 426 | |
| 427 | FastCloneShallowArrayStub::Mode mode = mode_; |
| 428 | if (mode == CLONE_ANY_ELEMENTS) { |
| 429 | Label double_elements, check_fast_elements; |
| 430 | __ ldr(r0, FieldMemOperand(r3, JSArray::kElementsOffset)); |
| 431 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 432 | __ CompareRoot(r0, Heap::kFixedCOWArrayMapRootIndex); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 433 | __ b(ne, &check_fast_elements); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 434 | GenerateFastCloneShallowArrayCommon(masm, 0, COPY_ON_WRITE_ELEMENTS, |
| 435 | allocation_site_mode_, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 436 | &slow_case); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 437 | // Return and remove the on-stack parameters. |
| 438 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 439 | __ Ret(); |
| 440 | |
| 441 | __ bind(&check_fast_elements); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 442 | __ CompareRoot(r0, Heap::kFixedArrayMapRootIndex); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 443 | __ b(ne, &double_elements); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 444 | GenerateFastCloneShallowArrayCommon(masm, length_, CLONE_ELEMENTS, |
| 445 | allocation_site_mode_, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 446 | &slow_case); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 447 | // Return and remove the on-stack parameters. |
| 448 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 449 | __ Ret(); |
| 450 | |
| 451 | __ bind(&double_elements); |
| 452 | mode = CLONE_DOUBLE_ELEMENTS; |
| 453 | // Fall through to generate the code to handle double elements. |
| 454 | } |
| 455 | |
| 456 | if (FLAG_debug_code) { |
| 457 | const char* message; |
| 458 | Heap::RootListIndex expected_map_index; |
| 459 | if (mode == CLONE_ELEMENTS) { |
| 460 | message = "Expected (writable) fixed array"; |
| 461 | expected_map_index = Heap::kFixedArrayMapRootIndex; |
| 462 | } else if (mode == CLONE_DOUBLE_ELEMENTS) { |
| 463 | message = "Expected (writable) fixed double array"; |
| 464 | expected_map_index = Heap::kFixedDoubleArrayMapRootIndex; |
| 465 | } else { |
| 466 | ASSERT(mode == COPY_ON_WRITE_ELEMENTS); |
| 467 | message = "Expected copy-on-write fixed array"; |
| 468 | expected_map_index = Heap::kFixedCOWArrayMapRootIndex; |
| 469 | } |
| 470 | __ push(r3); |
| 471 | __ ldr(r3, FieldMemOperand(r3, JSArray::kElementsOffset)); |
| 472 | __ ldr(r3, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 473 | __ CompareRoot(r3, expected_map_index); |
| 474 | __ Assert(eq, message); |
| 475 | __ pop(r3); |
| 476 | } |
| 477 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 478 | GenerateFastCloneShallowArrayCommon(masm, length_, mode, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 479 | allocation_site_mode_, |
| 480 | &slow_case); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 481 | |
| 482 | // Return and remove the on-stack parameters. |
| 483 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 484 | __ Ret(); |
| 485 | |
| 486 | __ bind(&slow_case); |
| 487 | __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
| 488 | } |
| 489 | |
| 490 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 491 | void FastCloneShallowObjectStub::Generate(MacroAssembler* masm) { |
| 492 | // Stack layout on entry: |
| 493 | // |
| 494 | // [sp]: object literal flags. |
| 495 | // [sp + kPointerSize]: constant properties. |
| 496 | // [sp + (2 * kPointerSize)]: literal index. |
| 497 | // [sp + (3 * kPointerSize)]: literals array. |
| 498 | |
| 499 | // Load boilerplate object into r3 and check if we need to create a |
| 500 | // boilerplate. |
| 501 | Label slow_case; |
| 502 | __ ldr(r3, MemOperand(sp, 3 * kPointerSize)); |
| 503 | __ ldr(r0, MemOperand(sp, 2 * kPointerSize)); |
| 504 | __ add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 505 | __ ldr(r3, MemOperand(r3, r0, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 506 | __ CompareRoot(r3, Heap::kUndefinedValueRootIndex); |
| 507 | __ b(eq, &slow_case); |
| 508 | |
| 509 | // Check that the boilerplate contains only fast properties and we can |
| 510 | // statically determine the instance size. |
| 511 | int size = JSObject::kHeaderSize + length_ * kPointerSize; |
| 512 | __ ldr(r0, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 513 | __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceSizeOffset)); |
| 514 | __ cmp(r0, Operand(size >> kPointerSizeLog2)); |
| 515 | __ b(ne, &slow_case); |
| 516 | |
| 517 | // Allocate the JS object and copy header together with all in-object |
| 518 | // properties from the boilerplate. |
| 519 | __ AllocateInNewSpace(size, r0, r1, r2, &slow_case, TAG_OBJECT); |
| 520 | for (int i = 0; i < size; i += kPointerSize) { |
| 521 | __ ldr(r1, FieldMemOperand(r3, i)); |
| 522 | __ str(r1, FieldMemOperand(r0, i)); |
| 523 | } |
| 524 | |
| 525 | // Return and remove the on-stack parameters. |
| 526 | __ add(sp, sp, Operand(4 * kPointerSize)); |
| 527 | __ Ret(); |
| 528 | |
| 529 | __ bind(&slow_case); |
| 530 | __ TailCallRuntime(Runtime::kCreateObjectLiteralShallow, 4, 1); |
| 531 | } |
| 532 | |
| 533 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 534 | // Takes a Smi and converts to an IEEE 64 bit floating point value in two |
| 535 | // registers. The format is 1 sign bit, 11 exponent bits (biased 1023) and |
| 536 | // 52 fraction bits (20 in the first word, 32 in the second). Zeros is a |
| 537 | // scratch register. Destroys the source register. No GC occurs during this |
| 538 | // stub so you don't have to set up the frame. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 539 | class ConvertToDoubleStub : public PlatformCodeStub { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 540 | public: |
| 541 | ConvertToDoubleStub(Register result_reg_1, |
| 542 | Register result_reg_2, |
| 543 | Register source_reg, |
| 544 | Register scratch_reg) |
| 545 | : result1_(result_reg_1), |
| 546 | result2_(result_reg_2), |
| 547 | source_(source_reg), |
| 548 | zeros_(scratch_reg) { } |
| 549 | |
| 550 | private: |
| 551 | Register result1_; |
| 552 | Register result2_; |
| 553 | Register source_; |
| 554 | Register zeros_; |
| 555 | |
| 556 | // Minor key encoding in 16 bits. |
| 557 | class ModeBits: public BitField<OverwriteMode, 0, 2> {}; |
| 558 | class OpBits: public BitField<Token::Value, 2, 14> {}; |
| 559 | |
| 560 | Major MajorKey() { return ConvertToDouble; } |
| 561 | int MinorKey() { |
| 562 | // Encode the parameters in a unique 16 bit value. |
| 563 | return result1_.code() + |
| 564 | (result2_.code() << 4) + |
| 565 | (source_.code() << 8) + |
| 566 | (zeros_.code() << 12); |
| 567 | } |
| 568 | |
| 569 | void Generate(MacroAssembler* masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 570 | }; |
| 571 | |
| 572 | |
| 573 | void ConvertToDoubleStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 574 | Register exponent = result1_; |
| 575 | Register mantissa = result2_; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 576 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 577 | Label not_special; |
| 578 | // Convert from Smi to integer. |
| 579 | __ mov(source_, Operand(source_, ASR, kSmiTagSize)); |
| 580 | // Move sign bit from source to destination. This works because the sign bit |
| 581 | // in the exponent word of the double has the same position and polarity as |
| 582 | // the 2's complement sign bit in a Smi. |
| 583 | STATIC_ASSERT(HeapNumber::kSignMask == 0x80000000u); |
| 584 | __ and_(exponent, source_, Operand(HeapNumber::kSignMask), SetCC); |
| 585 | // Subtract from 0 if source was negative. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 586 | __ rsb(source_, source_, Operand::Zero(), LeaveCC, ne); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 587 | |
| 588 | // We have -1, 0 or 1, which we treat specially. Register source_ contains |
| 589 | // absolute value: it is either equal to 1 (special case of -1 and 1), |
| 590 | // greater than 1 (not a special case) or less than 1 (special case of 0). |
| 591 | __ cmp(source_, Operand(1)); |
| 592 | __ b(gt, ¬_special); |
| 593 | |
| 594 | // For 1 or -1 we need to or in the 0 exponent (biased to 1023). |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 595 | const uint32_t exponent_word_for_1 = |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 596 | HeapNumber::kExponentBias << HeapNumber::kExponentShift; |
| 597 | __ orr(exponent, exponent, Operand(exponent_word_for_1), LeaveCC, eq); |
| 598 | // 1, 0 and -1 all have 0 for the second word. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 599 | __ mov(mantissa, Operand::Zero()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 600 | __ Ret(); |
| 601 | |
| 602 | __ bind(¬_special); |
| 603 | // Count leading zeros. Uses mantissa for a scratch register on pre-ARM5. |
| 604 | // Gets the wrong answer for 0, but we already checked for that case above. |
| 605 | __ CountLeadingZeros(zeros_, source_, mantissa); |
| 606 | // Compute exponent and or it into the exponent register. |
| 607 | // We use mantissa as a scratch register here. Use a fudge factor to |
| 608 | // divide the constant 31 + HeapNumber::kExponentBias, 0x41d, into two parts |
| 609 | // that fit in the ARM's constant field. |
| 610 | int fudge = 0x400; |
| 611 | __ rsb(mantissa, zeros_, Operand(31 + HeapNumber::kExponentBias - fudge)); |
| 612 | __ add(mantissa, mantissa, Operand(fudge)); |
| 613 | __ orr(exponent, |
| 614 | exponent, |
| 615 | Operand(mantissa, LSL, HeapNumber::kExponentShift)); |
| 616 | // Shift up the source chopping the top bit off. |
| 617 | __ add(zeros_, zeros_, Operand(1)); |
| 618 | // This wouldn't work for 1.0 or -1.0 as the shift would be 32 which means 0. |
| 619 | __ mov(source_, Operand(source_, LSL, zeros_)); |
| 620 | // Compute lower part of fraction (last 12 bits). |
| 621 | __ mov(mantissa, Operand(source_, LSL, HeapNumber::kMantissaBitsInTopWord)); |
| 622 | // And the top (top 20 bits). |
| 623 | __ orr(exponent, |
| 624 | exponent, |
| 625 | Operand(source_, LSR, 32 - HeapNumber::kMantissaBitsInTopWord)); |
| 626 | __ Ret(); |
| 627 | } |
| 628 | |
| 629 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 630 | void FloatingPointHelper::LoadSmis(MacroAssembler* masm, |
| 631 | FloatingPointHelper::Destination destination, |
| 632 | Register scratch1, |
| 633 | Register scratch2) { |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 634 | if (CpuFeatures::IsSupported(VFP2)) { |
| 635 | CpuFeatures::Scope scope(VFP2); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 636 | __ mov(scratch1, Operand(r0, ASR, kSmiTagSize)); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 637 | __ vmov(d7.high(), scratch1); |
| 638 | __ vcvt_f64_s32(d7, d7.high()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 639 | __ mov(scratch1, Operand(r1, ASR, kSmiTagSize)); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 640 | __ vmov(d6.high(), scratch1); |
| 641 | __ vcvt_f64_s32(d6, d6.high()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 642 | if (destination == kCoreRegisters) { |
| 643 | __ vmov(r2, r3, d7); |
| 644 | __ vmov(r0, r1, d6); |
| 645 | } |
| 646 | } else { |
| 647 | ASSERT(destination == kCoreRegisters); |
| 648 | // Write Smi from r0 to r3 and r2 in double format. |
| 649 | __ mov(scratch1, Operand(r0)); |
| 650 | ConvertToDoubleStub stub1(r3, r2, scratch1, scratch2); |
| 651 | __ push(lr); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 652 | __ Call(stub1.GetCode()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 653 | // Write Smi from r1 to r1 and r0 in double format. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 654 | __ mov(scratch1, Operand(r1)); |
| 655 | ConvertToDoubleStub stub2(r1, r0, scratch1, scratch2); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 656 | __ Call(stub2.GetCode()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 657 | __ pop(lr); |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 662 | void FloatingPointHelper::LoadNumber(MacroAssembler* masm, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 663 | Destination destination, |
| 664 | Register object, |
| 665 | DwVfpRegister dst, |
| 666 | Register dst1, |
| 667 | Register dst2, |
| 668 | Register heap_number_map, |
| 669 | Register scratch1, |
| 670 | Register scratch2, |
| 671 | Label* not_number) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 672 | __ AssertRootValue(heap_number_map, |
| 673 | Heap::kHeapNumberMapRootIndex, |
| 674 | "HeapNumberMap register clobbered."); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 675 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 676 | Label is_smi, done; |
| 677 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 678 | // Smi-check |
| 679 | __ UntagAndJumpIfSmi(scratch1, object, &is_smi); |
| 680 | // Heap number check |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 681 | __ JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_number); |
| 682 | |
| 683 | // Handle loading a double from a heap number. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 684 | if (CpuFeatures::IsSupported(VFP2) && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 685 | destination == kVFPRegisters) { |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 686 | CpuFeatures::Scope scope(VFP2); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 687 | // Load the double from tagged HeapNumber to double register. |
| 688 | __ sub(scratch1, object, Operand(kHeapObjectTag)); |
| 689 | __ vldr(dst, scratch1, HeapNumber::kValueOffset); |
| 690 | } else { |
| 691 | ASSERT(destination == kCoreRegisters); |
| 692 | // Load the double from heap number to dst1 and dst2 in double format. |
| 693 | __ Ldrd(dst1, dst2, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 694 | } |
| 695 | __ jmp(&done); |
| 696 | |
| 697 | // Handle loading a double from a smi. |
| 698 | __ bind(&is_smi); |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 699 | if (CpuFeatures::IsSupported(VFP2)) { |
| 700 | CpuFeatures::Scope scope(VFP2); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 701 | // Convert smi to double using VFP instructions. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 702 | __ vmov(dst.high(), scratch1); |
| 703 | __ vcvt_f64_s32(dst, dst.high()); |
| 704 | if (destination == kCoreRegisters) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 705 | // Load the converted smi to dst1 and dst2 in double format. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 706 | __ vmov(dst1, dst2, dst); |
| 707 | } |
| 708 | } else { |
| 709 | ASSERT(destination == kCoreRegisters); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 710 | // Write smi to dst1 and dst2 double format. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 711 | __ mov(scratch1, Operand(object)); |
| 712 | ConvertToDoubleStub stub(dst2, dst1, scratch1, scratch2); |
| 713 | __ push(lr); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 714 | __ Call(stub.GetCode()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 715 | __ pop(lr); |
| 716 | } |
| 717 | |
| 718 | __ bind(&done); |
| 719 | } |
| 720 | |
| 721 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 722 | void FloatingPointHelper::ConvertNumberToInt32(MacroAssembler* masm, |
| 723 | Register object, |
| 724 | Register dst, |
| 725 | Register heap_number_map, |
| 726 | Register scratch1, |
| 727 | Register scratch2, |
| 728 | Register scratch3, |
| 729 | DwVfpRegister double_scratch, |
| 730 | Label* not_number) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 731 | __ AssertRootValue(heap_number_map, |
| 732 | Heap::kHeapNumberMapRootIndex, |
| 733 | "HeapNumberMap register clobbered."); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 734 | Label done; |
| 735 | Label not_in_int32_range; |
| 736 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 737 | __ UntagAndJumpIfSmi(dst, object, &done); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 738 | __ ldr(scratch1, FieldMemOperand(object, HeapNumber::kMapOffset)); |
| 739 | __ cmp(scratch1, heap_number_map); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 740 | __ b(ne, not_number); |
| 741 | __ ConvertToInt32(object, |
| 742 | dst, |
| 743 | scratch1, |
| 744 | scratch2, |
| 745 | double_scratch, |
| 746 | ¬_in_int32_range); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 747 | __ jmp(&done); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 748 | |
| 749 | __ bind(¬_in_int32_range); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 750 | __ ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 751 | __ ldr(scratch2, FieldMemOperand(object, HeapNumber::kMantissaOffset)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 752 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 753 | __ EmitOutOfInt32RangeTruncate(dst, |
| 754 | scratch1, |
| 755 | scratch2, |
| 756 | scratch3); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 757 | __ bind(&done); |
| 758 | } |
| 759 | |
| 760 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 761 | void FloatingPointHelper::ConvertIntToDouble(MacroAssembler* masm, |
| 762 | Register int_scratch, |
| 763 | Destination destination, |
| 764 | DwVfpRegister double_dst, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 765 | Register dst_mantissa, |
| 766 | Register dst_exponent, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 767 | Register scratch2, |
| 768 | SwVfpRegister single_scratch) { |
| 769 | ASSERT(!int_scratch.is(scratch2)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 770 | ASSERT(!int_scratch.is(dst_mantissa)); |
| 771 | ASSERT(!int_scratch.is(dst_exponent)); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 772 | |
| 773 | Label done; |
| 774 | |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 775 | if (CpuFeatures::IsSupported(VFP2)) { |
| 776 | CpuFeatures::Scope scope(VFP2); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 777 | __ vmov(single_scratch, int_scratch); |
| 778 | __ vcvt_f64_s32(double_dst, single_scratch); |
| 779 | if (destination == kCoreRegisters) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 780 | __ vmov(dst_mantissa, dst_exponent, double_dst); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 781 | } |
| 782 | } else { |
| 783 | Label fewer_than_20_useful_bits; |
| 784 | // Expected output: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 785 | // | dst_exponent | dst_mantissa | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 786 | // | s | exp | mantissa | |
| 787 | |
| 788 | // Check for zero. |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 789 | __ cmp(int_scratch, Operand::Zero()); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 790 | __ mov(dst_exponent, int_scratch); |
| 791 | __ mov(dst_mantissa, int_scratch); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 792 | __ b(eq, &done); |
| 793 | |
| 794 | // Preload the sign of the value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 795 | __ and_(dst_exponent, int_scratch, Operand(HeapNumber::kSignMask), SetCC); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 796 | // Get the absolute value of the object (as an unsigned integer). |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 797 | __ rsb(int_scratch, int_scratch, Operand::Zero(), SetCC, mi); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 798 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 799 | // Get mantissa[51:20]. |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 800 | |
| 801 | // Get the position of the first set bit. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 802 | __ CountLeadingZeros(dst_mantissa, int_scratch, scratch2); |
| 803 | __ rsb(dst_mantissa, dst_mantissa, Operand(31)); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 804 | |
| 805 | // Set the exponent. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 806 | __ add(scratch2, dst_mantissa, Operand(HeapNumber::kExponentBias)); |
| 807 | __ Bfi(dst_exponent, scratch2, scratch2, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 808 | HeapNumber::kExponentShift, HeapNumber::kExponentBits); |
| 809 | |
| 810 | // Clear the first non null bit. |
| 811 | __ mov(scratch2, Operand(1)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 812 | __ bic(int_scratch, int_scratch, Operand(scratch2, LSL, dst_mantissa)); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 813 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 814 | __ cmp(dst_mantissa, Operand(HeapNumber::kMantissaBitsInTopWord)); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 815 | // Get the number of bits to set in the lower part of the mantissa. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 816 | __ sub(scratch2, dst_mantissa, Operand(HeapNumber::kMantissaBitsInTopWord), |
| 817 | SetCC); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 818 | __ b(mi, &fewer_than_20_useful_bits); |
| 819 | // Set the higher 20 bits of the mantissa. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 820 | __ orr(dst_exponent, dst_exponent, Operand(int_scratch, LSR, scratch2)); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 821 | __ rsb(scratch2, scratch2, Operand(32)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 822 | __ mov(dst_mantissa, Operand(int_scratch, LSL, scratch2)); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 823 | __ b(&done); |
| 824 | |
| 825 | __ bind(&fewer_than_20_useful_bits); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 826 | __ rsb(scratch2, dst_mantissa, Operand(HeapNumber::kMantissaBitsInTopWord)); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 827 | __ mov(scratch2, Operand(int_scratch, LSL, scratch2)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 828 | __ orr(dst_exponent, dst_exponent, scratch2); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 829 | // Set dst1 to 0. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 830 | __ mov(dst_mantissa, Operand::Zero()); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 831 | } |
| 832 | __ bind(&done); |
| 833 | } |
| 834 | |
| 835 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 836 | void FloatingPointHelper::LoadNumberAsInt32Double(MacroAssembler* masm, |
| 837 | Register object, |
| 838 | Destination destination, |
| 839 | DwVfpRegister double_dst, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 840 | DwVfpRegister double_scratch, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 841 | Register dst_mantissa, |
| 842 | Register dst_exponent, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 843 | Register heap_number_map, |
| 844 | Register scratch1, |
| 845 | Register scratch2, |
| 846 | SwVfpRegister single_scratch, |
| 847 | Label* not_int32) { |
| 848 | ASSERT(!scratch1.is(object) && !scratch2.is(object)); |
| 849 | ASSERT(!scratch1.is(scratch2)); |
| 850 | ASSERT(!heap_number_map.is(object) && |
| 851 | !heap_number_map.is(scratch1) && |
| 852 | !heap_number_map.is(scratch2)); |
| 853 | |
| 854 | Label done, obj_is_not_smi; |
| 855 | |
| 856 | __ JumpIfNotSmi(object, &obj_is_not_smi); |
| 857 | __ SmiUntag(scratch1, object); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 858 | ConvertIntToDouble(masm, scratch1, destination, double_dst, dst_mantissa, |
| 859 | dst_exponent, scratch2, single_scratch); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 860 | __ b(&done); |
| 861 | |
| 862 | __ bind(&obj_is_not_smi); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 863 | __ AssertRootValue(heap_number_map, |
| 864 | Heap::kHeapNumberMapRootIndex, |
| 865 | "HeapNumberMap register clobbered."); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 866 | __ JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_int32); |
| 867 | |
| 868 | // Load the number. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 869 | if (CpuFeatures::IsSupported(VFP2)) { |
| 870 | CpuFeatures::Scope scope(VFP2); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 871 | // Load the double value. |
| 872 | __ sub(scratch1, object, Operand(kHeapObjectTag)); |
| 873 | __ vldr(double_dst, scratch1, HeapNumber::kValueOffset); |
| 874 | |
| 875 | __ EmitVFPTruncate(kRoundToZero, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 876 | scratch1, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 877 | double_dst, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 878 | scratch2, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 879 | double_scratch, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 880 | kCheckForInexactConversion); |
| 881 | |
| 882 | // Jump to not_int32 if the operation did not succeed. |
| 883 | __ b(ne, not_int32); |
| 884 | |
| 885 | if (destination == kCoreRegisters) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 886 | __ vmov(dst_mantissa, dst_exponent, double_dst); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | } else { |
| 890 | ASSERT(!scratch1.is(object) && !scratch2.is(object)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 891 | // Load the double value in the destination registers. |
| 892 | bool save_registers = object.is(dst_mantissa) || object.is(dst_exponent); |
| 893 | if (save_registers) { |
| 894 | // Save both output registers, because the other one probably holds |
| 895 | // an important value too. |
| 896 | __ Push(dst_exponent, dst_mantissa); |
| 897 | } |
| 898 | __ Ldrd(dst_mantissa, dst_exponent, |
| 899 | FieldMemOperand(object, HeapNumber::kValueOffset)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 900 | |
| 901 | // Check for 0 and -0. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 902 | Label zero; |
| 903 | __ bic(scratch1, dst_exponent, Operand(HeapNumber::kSignMask)); |
| 904 | __ orr(scratch1, scratch1, Operand(dst_mantissa)); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 905 | __ cmp(scratch1, Operand::Zero()); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 906 | __ b(eq, &zero); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 907 | |
| 908 | // Check that the value can be exactly represented by a 32-bit integer. |
| 909 | // Jump to not_int32 if that's not the case. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 910 | Label restore_input_and_miss; |
| 911 | DoubleIs32BitInteger(masm, dst_exponent, dst_mantissa, scratch1, scratch2, |
| 912 | &restore_input_and_miss); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 913 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 914 | // dst_* were trashed. Reload the double value. |
| 915 | if (save_registers) { |
| 916 | __ Pop(dst_exponent, dst_mantissa); |
| 917 | } |
| 918 | __ Ldrd(dst_mantissa, dst_exponent, |
| 919 | FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 920 | __ b(&done); |
| 921 | |
| 922 | __ bind(&restore_input_and_miss); |
| 923 | if (save_registers) { |
| 924 | __ Pop(dst_exponent, dst_mantissa); |
| 925 | } |
| 926 | __ b(not_int32); |
| 927 | |
| 928 | __ bind(&zero); |
| 929 | if (save_registers) { |
| 930 | __ Drop(2); |
| 931 | } |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | __ bind(&done); |
| 935 | } |
| 936 | |
| 937 | |
| 938 | void FloatingPointHelper::LoadNumberAsInt32(MacroAssembler* masm, |
| 939 | Register object, |
| 940 | Register dst, |
| 941 | Register heap_number_map, |
| 942 | Register scratch1, |
| 943 | Register scratch2, |
| 944 | Register scratch3, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 945 | DwVfpRegister double_scratch0, |
| 946 | DwVfpRegister double_scratch1, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 947 | Label* not_int32) { |
| 948 | ASSERT(!dst.is(object)); |
| 949 | ASSERT(!scratch1.is(object) && !scratch2.is(object) && !scratch3.is(object)); |
| 950 | ASSERT(!scratch1.is(scratch2) && |
| 951 | !scratch1.is(scratch3) && |
| 952 | !scratch2.is(scratch3)); |
| 953 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 954 | Label done, maybe_undefined; |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 955 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 956 | __ UntagAndJumpIfSmi(dst, object, &done); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 957 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 958 | __ AssertRootValue(heap_number_map, |
| 959 | Heap::kHeapNumberMapRootIndex, |
| 960 | "HeapNumberMap register clobbered."); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 961 | |
| 962 | __ JumpIfNotHeapNumber(object, heap_number_map, scratch1, &maybe_undefined); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 963 | |
| 964 | // Object is a heap number. |
| 965 | // Convert the floating point value to a 32-bit integer. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 966 | if (CpuFeatures::IsSupported(VFP2)) { |
| 967 | CpuFeatures::Scope scope(VFP2); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 968 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 969 | // Load the double value. |
| 970 | __ sub(scratch1, object, Operand(kHeapObjectTag)); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 971 | __ vldr(double_scratch0, scratch1, HeapNumber::kValueOffset); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 972 | |
| 973 | __ EmitVFPTruncate(kRoundToZero, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 974 | dst, |
| 975 | double_scratch0, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 976 | scratch1, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 977 | double_scratch1, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 978 | kCheckForInexactConversion); |
| 979 | |
| 980 | // Jump to not_int32 if the operation did not succeed. |
| 981 | __ b(ne, not_int32); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 982 | } else { |
| 983 | // Load the double value in the destination registers. |
| 984 | __ ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 985 | __ ldr(scratch2, FieldMemOperand(object, HeapNumber::kMantissaOffset)); |
| 986 | |
| 987 | // Check for 0 and -0. |
| 988 | __ bic(dst, scratch1, Operand(HeapNumber::kSignMask)); |
| 989 | __ orr(dst, scratch2, Operand(dst)); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 990 | __ cmp(dst, Operand::Zero()); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 991 | __ b(eq, &done); |
| 992 | |
| 993 | DoubleIs32BitInteger(masm, scratch1, scratch2, dst, scratch3, not_int32); |
| 994 | |
| 995 | // Registers state after DoubleIs32BitInteger. |
| 996 | // dst: mantissa[51:20]. |
| 997 | // scratch2: 1 |
| 998 | |
| 999 | // Shift back the higher bits of the mantissa. |
| 1000 | __ mov(dst, Operand(dst, LSR, scratch3)); |
| 1001 | // Set the implicit first bit. |
| 1002 | __ rsb(scratch3, scratch3, Operand(32)); |
| 1003 | __ orr(dst, dst, Operand(scratch2, LSL, scratch3)); |
| 1004 | // Set the sign. |
| 1005 | __ ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 1006 | __ tst(scratch1, Operand(HeapNumber::kSignMask)); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1007 | __ rsb(dst, dst, Operand::Zero(), LeaveCC, mi); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1008 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1009 | __ b(&done); |
| 1010 | |
| 1011 | __ bind(&maybe_undefined); |
| 1012 | __ CompareRoot(object, Heap::kUndefinedValueRootIndex); |
| 1013 | __ b(ne, not_int32); |
| 1014 | // |undefined| is truncated to 0. |
| 1015 | __ mov(dst, Operand(Smi::FromInt(0))); |
| 1016 | // Fall through. |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1017 | |
| 1018 | __ bind(&done); |
| 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | void FloatingPointHelper::DoubleIs32BitInteger(MacroAssembler* masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1023 | Register src_exponent, |
| 1024 | Register src_mantissa, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1025 | Register dst, |
| 1026 | Register scratch, |
| 1027 | Label* not_int32) { |
| 1028 | // Get exponent alone in scratch. |
| 1029 | __ Ubfx(scratch, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1030 | src_exponent, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1031 | HeapNumber::kExponentShift, |
| 1032 | HeapNumber::kExponentBits); |
| 1033 | |
| 1034 | // Substract the bias from the exponent. |
| 1035 | __ sub(scratch, scratch, Operand(HeapNumber::kExponentBias), SetCC); |
| 1036 | |
| 1037 | // src1: higher (exponent) part of the double value. |
| 1038 | // src2: lower (mantissa) part of the double value. |
| 1039 | // scratch: unbiased exponent. |
| 1040 | |
| 1041 | // Fast cases. Check for obvious non 32-bit integer values. |
| 1042 | // Negative exponent cannot yield 32-bit integers. |
| 1043 | __ b(mi, not_int32); |
| 1044 | // Exponent greater than 31 cannot yield 32-bit integers. |
| 1045 | // Also, a positive value with an exponent equal to 31 is outside of the |
| 1046 | // signed 32-bit integer range. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1047 | // Another way to put it is that if (exponent - signbit) > 30 then the |
| 1048 | // number cannot be represented as an int32. |
| 1049 | Register tmp = dst; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1050 | __ sub(tmp, scratch, Operand(src_exponent, LSR, 31)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1051 | __ cmp(tmp, Operand(30)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1052 | __ b(gt, not_int32); |
| 1053 | // - Bits [21:0] in the mantissa are not null. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1054 | __ tst(src_mantissa, Operand(0x3fffff)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1055 | __ b(ne, not_int32); |
| 1056 | |
| 1057 | // Otherwise the exponent needs to be big enough to shift left all the |
| 1058 | // non zero bits left. So we need the (30 - exponent) last bits of the |
| 1059 | // 31 higher bits of the mantissa to be null. |
| 1060 | // Because bits [21:0] are null, we can check instead that the |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1061 | // (32 - exponent) last bits of the 32 higher bits of the mantissa are null. |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1062 | |
| 1063 | // Get the 32 higher bits of the mantissa in dst. |
| 1064 | __ Ubfx(dst, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1065 | src_mantissa, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1066 | HeapNumber::kMantissaBitsInTopWord, |
| 1067 | 32 - HeapNumber::kMantissaBitsInTopWord); |
| 1068 | __ orr(dst, |
| 1069 | dst, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1070 | Operand(src_exponent, LSL, HeapNumber::kNonMantissaBitsInTopWord)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1071 | |
| 1072 | // Create the mask and test the lower bits (of the higher bits). |
| 1073 | __ rsb(scratch, scratch, Operand(32)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1074 | __ mov(src_mantissa, Operand(1)); |
| 1075 | __ mov(src_exponent, Operand(src_mantissa, LSL, scratch)); |
| 1076 | __ sub(src_exponent, src_exponent, Operand(1)); |
| 1077 | __ tst(dst, src_exponent); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1078 | __ b(ne, not_int32); |
| 1079 | } |
| 1080 | |
| 1081 | |
| 1082 | void FloatingPointHelper::CallCCodeForDoubleOperation( |
| 1083 | MacroAssembler* masm, |
| 1084 | Token::Value op, |
| 1085 | Register heap_number_result, |
| 1086 | Register scratch) { |
| 1087 | // Using core registers: |
| 1088 | // r0: Left value (least significant part of mantissa). |
| 1089 | // r1: Left value (sign, exponent, top of mantissa). |
| 1090 | // r2: Right value (least significant part of mantissa). |
| 1091 | // r3: Right value (sign, exponent, top of mantissa). |
| 1092 | |
| 1093 | // Assert that heap_number_result is callee-saved. |
| 1094 | // We currently always use r5 to pass it. |
| 1095 | ASSERT(heap_number_result.is(r5)); |
| 1096 | |
| 1097 | // Push the current return address before the C call. Return will be |
| 1098 | // through pop(pc) below. |
| 1099 | __ push(lr); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1100 | __ PrepareCallCFunction(0, 2, scratch); |
| 1101 | if (masm->use_eabi_hardfloat()) { |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 1102 | CpuFeatures::Scope scope(VFP2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1103 | __ vmov(d0, r0, r1); |
| 1104 | __ vmov(d1, r2, r3); |
| 1105 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1106 | { |
| 1107 | AllowExternalCallThatCantCauseGC scope(masm); |
| 1108 | __ CallCFunction( |
| 1109 | ExternalReference::double_fp_operation(op, masm->isolate()), 0, 2); |
| 1110 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1111 | // Store answer in the overwritable heap number. Double returned in |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1112 | // registers r0 and r1 or in d0. |
| 1113 | if (masm->use_eabi_hardfloat()) { |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 1114 | CpuFeatures::Scope scope(VFP2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1115 | __ vstr(d0, |
| 1116 | FieldMemOperand(heap_number_result, HeapNumber::kValueOffset)); |
| 1117 | } else { |
| 1118 | __ Strd(r0, r1, FieldMemOperand(heap_number_result, |
| 1119 | HeapNumber::kValueOffset)); |
| 1120 | } |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1121 | // Place heap_number_result in r0 and return to the pushed return address. |
| 1122 | __ mov(r0, Operand(heap_number_result)); |
| 1123 | __ pop(pc); |
| 1124 | } |
| 1125 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1126 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1127 | bool WriteInt32ToHeapNumberStub::IsPregenerated() { |
| 1128 | // These variants are compiled ahead of time. See next method. |
| 1129 | if (the_int_.is(r1) && the_heap_number_.is(r0) && scratch_.is(r2)) { |
| 1130 | return true; |
| 1131 | } |
| 1132 | if (the_int_.is(r2) && the_heap_number_.is(r0) && scratch_.is(r3)) { |
| 1133 | return true; |
| 1134 | } |
| 1135 | // Other register combinations are generated as and when they are needed, |
| 1136 | // so it is unsafe to call them from stubs (we can't generate a stub while |
| 1137 | // we are generating a stub). |
| 1138 | return false; |
| 1139 | } |
| 1140 | |
| 1141 | |
| 1142 | void WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime() { |
| 1143 | WriteInt32ToHeapNumberStub stub1(r1, r0, r2); |
| 1144 | WriteInt32ToHeapNumberStub stub2(r2, r0, r3); |
| 1145 | stub1.GetCode()->set_is_pregenerated(true); |
| 1146 | stub2.GetCode()->set_is_pregenerated(true); |
| 1147 | } |
| 1148 | |
| 1149 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1150 | // See comment for class. |
| 1151 | void WriteInt32ToHeapNumberStub::Generate(MacroAssembler* masm) { |
| 1152 | Label max_negative_int; |
| 1153 | // the_int_ has the answer which is a signed int32 but not a Smi. |
| 1154 | // We test for the special value that has a different exponent. This test |
| 1155 | // has the neat side effect of setting the flags according to the sign. |
| 1156 | STATIC_ASSERT(HeapNumber::kSignMask == 0x80000000u); |
| 1157 | __ cmp(the_int_, Operand(0x80000000u)); |
| 1158 | __ b(eq, &max_negative_int); |
| 1159 | // Set up the correct exponent in scratch_. All non-Smi int32s have the same. |
| 1160 | // A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased). |
| 1161 | uint32_t non_smi_exponent = |
| 1162 | (HeapNumber::kExponentBias + 30) << HeapNumber::kExponentShift; |
| 1163 | __ mov(scratch_, Operand(non_smi_exponent)); |
| 1164 | // Set the sign bit in scratch_ if the value was negative. |
| 1165 | __ orr(scratch_, scratch_, Operand(HeapNumber::kSignMask), LeaveCC, cs); |
| 1166 | // Subtract from 0 if the value was negative. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1167 | __ rsb(the_int_, the_int_, Operand::Zero(), LeaveCC, cs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1168 | // We should be masking the implict first digit of the mantissa away here, |
| 1169 | // but it just ends up combining harmlessly with the last digit of the |
| 1170 | // exponent that happens to be 1. The sign bit is 0 so we shift 10 to get |
| 1171 | // the most significant 1 to hit the last bit of the 12 bit sign and exponent. |
| 1172 | ASSERT(((1 << HeapNumber::kExponentShift) & non_smi_exponent) != 0); |
| 1173 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 1174 | __ orr(scratch_, scratch_, Operand(the_int_, LSR, shift_distance)); |
| 1175 | __ str(scratch_, FieldMemOperand(the_heap_number_, |
| 1176 | HeapNumber::kExponentOffset)); |
| 1177 | __ mov(scratch_, Operand(the_int_, LSL, 32 - shift_distance)); |
| 1178 | __ str(scratch_, FieldMemOperand(the_heap_number_, |
| 1179 | HeapNumber::kMantissaOffset)); |
| 1180 | __ Ret(); |
| 1181 | |
| 1182 | __ bind(&max_negative_int); |
| 1183 | // The max negative int32 is stored as a positive number in the mantissa of |
| 1184 | // a double because it uses a sign bit instead of using two's complement. |
| 1185 | // The actual mantissa bits stored are all 0 because the implicit most |
| 1186 | // significant 1 bit is not stored. |
| 1187 | non_smi_exponent += 1 << HeapNumber::kExponentShift; |
| 1188 | __ mov(ip, Operand(HeapNumber::kSignMask | non_smi_exponent)); |
| 1189 | __ str(ip, FieldMemOperand(the_heap_number_, HeapNumber::kExponentOffset)); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1190 | __ mov(ip, Operand::Zero()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1191 | __ str(ip, FieldMemOperand(the_heap_number_, HeapNumber::kMantissaOffset)); |
| 1192 | __ Ret(); |
| 1193 | } |
| 1194 | |
| 1195 | |
| 1196 | // Handle the case where the lhs and rhs are the same object. |
| 1197 | // Equality is almost reflexive (everything but NaN), so this is a test |
| 1198 | // for "identity and not NaN". |
| 1199 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, |
| 1200 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1201 | Condition cond) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1202 | Label not_identical; |
| 1203 | Label heap_number, return_equal; |
| 1204 | __ cmp(r0, r1); |
| 1205 | __ b(ne, ¬_identical); |
| 1206 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1207 | // Test for NaN. Sadly, we can't just compare to FACTORY->nan_value(), |
| 1208 | // so we do the second best thing - test it ourselves. |
| 1209 | // They are both equal and they are not both Smis so both of them are not |
| 1210 | // Smis. If it's not a heap number, then return equal. |
| 1211 | if (cond == lt || cond == gt) { |
| 1212 | __ CompareObjectType(r0, r4, r4, FIRST_SPEC_OBJECT_TYPE); |
| 1213 | __ b(ge, slow); |
| 1214 | } else { |
| 1215 | __ CompareObjectType(r0, r4, r4, HEAP_NUMBER_TYPE); |
| 1216 | __ b(eq, &heap_number); |
| 1217 | // Comparing JS objects with <=, >= is complicated. |
| 1218 | if (cond != eq) { |
| 1219 | __ cmp(r4, Operand(FIRST_SPEC_OBJECT_TYPE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1220 | __ b(ge, slow); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1221 | // Normally here we fall through to return_equal, but undefined is |
| 1222 | // special: (undefined == undefined) == true, but |
| 1223 | // (undefined <= undefined) == false! See ECMAScript 11.8.5. |
| 1224 | if (cond == le || cond == ge) { |
| 1225 | __ cmp(r4, Operand(ODDBALL_TYPE)); |
| 1226 | __ b(ne, &return_equal); |
| 1227 | __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
| 1228 | __ cmp(r0, r2); |
| 1229 | __ b(ne, &return_equal); |
| 1230 | if (cond == le) { |
| 1231 | // undefined <= undefined should fail. |
| 1232 | __ mov(r0, Operand(GREATER)); |
| 1233 | } else { |
| 1234 | // undefined >= undefined should fail. |
| 1235 | __ mov(r0, Operand(LESS)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1236 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1237 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | __ bind(&return_equal); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1243 | if (cond == lt) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1244 | __ mov(r0, Operand(GREATER)); // Things aren't less than themselves. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1245 | } else if (cond == gt) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1246 | __ mov(r0, Operand(LESS)); // Things aren't greater than themselves. |
| 1247 | } else { |
| 1248 | __ mov(r0, Operand(EQUAL)); // Things are <=, >=, ==, === themselves. |
| 1249 | } |
| 1250 | __ Ret(); |
| 1251 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1252 | // For less and greater we don't have to check for NaN since the result of |
| 1253 | // x < x is false regardless. For the others here is some code to check |
| 1254 | // for NaN. |
| 1255 | if (cond != lt && cond != gt) { |
| 1256 | __ bind(&heap_number); |
| 1257 | // It is a heap number, so return non-equal if it's NaN and equal if it's |
| 1258 | // not NaN. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1259 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1260 | // The representation of NaN values has all exponent bits (52..62) set, |
| 1261 | // and not all mantissa bits (0..51) clear. |
| 1262 | // Read top bits of double representation (second word of value). |
| 1263 | __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 1264 | // Test that exponent bits are all set. |
| 1265 | __ Sbfx(r3, r2, HeapNumber::kExponentShift, HeapNumber::kExponentBits); |
| 1266 | // NaNs have all-one exponents so they sign extend to -1. |
| 1267 | __ cmp(r3, Operand(-1)); |
| 1268 | __ b(ne, &return_equal); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1269 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1270 | // Shift out flag and all exponent bits, retaining only mantissa. |
| 1271 | __ mov(r2, Operand(r2, LSL, HeapNumber::kNonMantissaBitsInTopWord)); |
| 1272 | // Or with all low-bits of mantissa. |
| 1273 | __ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset)); |
| 1274 | __ orr(r0, r3, Operand(r2), SetCC); |
| 1275 | // For equal we already have the right value in r0: Return zero (equal) |
| 1276 | // if all bits in mantissa are zero (it's an Infinity) and non-zero if |
| 1277 | // not (it's a NaN). For <= and >= we need to load r0 with the failing |
| 1278 | // value if it's a NaN. |
| 1279 | if (cond != eq) { |
| 1280 | // All-zero means Infinity means equal. |
| 1281 | __ Ret(eq); |
| 1282 | if (cond == le) { |
| 1283 | __ mov(r0, Operand(GREATER)); // NaN <= NaN should fail. |
| 1284 | } else { |
| 1285 | __ mov(r0, Operand(LESS)); // NaN >= NaN should fail. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1286 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1287 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1288 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1289 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1290 | // No fall through here. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1291 | |
| 1292 | __ bind(¬_identical); |
| 1293 | } |
| 1294 | |
| 1295 | |
| 1296 | // See comment at call site. |
| 1297 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 1298 | Register lhs, |
| 1299 | Register rhs, |
| 1300 | Label* lhs_not_nan, |
| 1301 | Label* slow, |
| 1302 | bool strict) { |
| 1303 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 1304 | (lhs.is(r1) && rhs.is(r0))); |
| 1305 | |
| 1306 | Label rhs_is_smi; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1307 | __ JumpIfSmi(rhs, &rhs_is_smi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1308 | |
| 1309 | // Lhs is a Smi. Check whether the rhs is a heap number. |
| 1310 | __ CompareObjectType(rhs, r4, r4, HEAP_NUMBER_TYPE); |
| 1311 | if (strict) { |
| 1312 | // If rhs is not a number and lhs is a Smi then strict equality cannot |
| 1313 | // succeed. Return non-equal |
| 1314 | // If rhs is r0 then there is already a non zero value in it. |
| 1315 | if (!rhs.is(r0)) { |
| 1316 | __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne); |
| 1317 | } |
| 1318 | __ Ret(ne); |
| 1319 | } else { |
| 1320 | // Smi compared non-strictly with a non-Smi non-heap-number. Call |
| 1321 | // the runtime. |
| 1322 | __ b(ne, slow); |
| 1323 | } |
| 1324 | |
| 1325 | // Lhs is a smi, rhs is a number. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 1326 | if (CpuFeatures::IsSupported(VFP2)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1327 | // Convert lhs to a double in d7. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 1328 | CpuFeatures::Scope scope(VFP2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1329 | __ SmiToDoubleVFPRegister(lhs, d7, r7, s15); |
| 1330 | // Load the double from rhs, tagged HeapNumber r0, to d6. |
| 1331 | __ sub(r7, rhs, Operand(kHeapObjectTag)); |
| 1332 | __ vldr(d6, r7, HeapNumber::kValueOffset); |
| 1333 | } else { |
| 1334 | __ push(lr); |
| 1335 | // Convert lhs to a double in r2, r3. |
| 1336 | __ mov(r7, Operand(lhs)); |
| 1337 | ConvertToDoubleStub stub1(r3, r2, r7, r6); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1338 | __ Call(stub1.GetCode()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1339 | // Load rhs to a double in r0, r1. |
| 1340 | __ Ldrd(r0, r1, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 1341 | __ pop(lr); |
| 1342 | } |
| 1343 | |
| 1344 | // We now have both loaded as doubles but we can skip the lhs nan check |
| 1345 | // since it's a smi. |
| 1346 | __ jmp(lhs_not_nan); |
| 1347 | |
| 1348 | __ bind(&rhs_is_smi); |
| 1349 | // Rhs is a smi. Check whether the non-smi lhs is a heap number. |
| 1350 | __ CompareObjectType(lhs, r4, r4, HEAP_NUMBER_TYPE); |
| 1351 | if (strict) { |
| 1352 | // If lhs is not a number and rhs is a smi then strict equality cannot |
| 1353 | // succeed. Return non-equal. |
| 1354 | // If lhs is r0 then there is already a non zero value in it. |
| 1355 | if (!lhs.is(r0)) { |
| 1356 | __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne); |
| 1357 | } |
| 1358 | __ Ret(ne); |
| 1359 | } else { |
| 1360 | // Smi compared non-strictly with a non-smi non-heap-number. Call |
| 1361 | // the runtime. |
| 1362 | __ b(ne, slow); |
| 1363 | } |
| 1364 | |
| 1365 | // Rhs is a smi, lhs is a heap number. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 1366 | if (CpuFeatures::IsSupported(VFP2)) { |
| 1367 | CpuFeatures::Scope scope(VFP2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1368 | // Load the double from lhs, tagged HeapNumber r1, to d7. |
| 1369 | __ sub(r7, lhs, Operand(kHeapObjectTag)); |
| 1370 | __ vldr(d7, r7, HeapNumber::kValueOffset); |
| 1371 | // Convert rhs to a double in d6 . |
| 1372 | __ SmiToDoubleVFPRegister(rhs, d6, r7, s13); |
| 1373 | } else { |
| 1374 | __ push(lr); |
| 1375 | // Load lhs to a double in r2, r3. |
| 1376 | __ Ldrd(r2, r3, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 1377 | // Convert rhs to a double in r0, r1. |
| 1378 | __ mov(r7, Operand(rhs)); |
| 1379 | ConvertToDoubleStub stub2(r1, r0, r7, r6); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1380 | __ Call(stub2.GetCode()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1381 | __ pop(lr); |
| 1382 | } |
| 1383 | // Fall through to both_loaded_as_doubles. |
| 1384 | } |
| 1385 | |
| 1386 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1387 | void EmitNanCheck(MacroAssembler* masm, Label* lhs_not_nan, Condition cond) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1388 | bool exp_first = (HeapNumber::kExponentOffset == HeapNumber::kValueOffset); |
| 1389 | Register rhs_exponent = exp_first ? r0 : r1; |
| 1390 | Register lhs_exponent = exp_first ? r2 : r3; |
| 1391 | Register rhs_mantissa = exp_first ? r1 : r0; |
| 1392 | Register lhs_mantissa = exp_first ? r3 : r2; |
| 1393 | Label one_is_nan, neither_is_nan; |
| 1394 | |
| 1395 | __ Sbfx(r4, |
| 1396 | lhs_exponent, |
| 1397 | HeapNumber::kExponentShift, |
| 1398 | HeapNumber::kExponentBits); |
| 1399 | // NaNs have all-one exponents so they sign extend to -1. |
| 1400 | __ cmp(r4, Operand(-1)); |
| 1401 | __ b(ne, lhs_not_nan); |
| 1402 | __ mov(r4, |
| 1403 | Operand(lhs_exponent, LSL, HeapNumber::kNonMantissaBitsInTopWord), |
| 1404 | SetCC); |
| 1405 | __ b(ne, &one_is_nan); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1406 | __ cmp(lhs_mantissa, Operand::Zero()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1407 | __ b(ne, &one_is_nan); |
| 1408 | |
| 1409 | __ bind(lhs_not_nan); |
| 1410 | __ Sbfx(r4, |
| 1411 | rhs_exponent, |
| 1412 | HeapNumber::kExponentShift, |
| 1413 | HeapNumber::kExponentBits); |
| 1414 | // NaNs have all-one exponents so they sign extend to -1. |
| 1415 | __ cmp(r4, Operand(-1)); |
| 1416 | __ b(ne, &neither_is_nan); |
| 1417 | __ mov(r4, |
| 1418 | Operand(rhs_exponent, LSL, HeapNumber::kNonMantissaBitsInTopWord), |
| 1419 | SetCC); |
| 1420 | __ b(ne, &one_is_nan); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1421 | __ cmp(rhs_mantissa, Operand::Zero()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1422 | __ b(eq, &neither_is_nan); |
| 1423 | |
| 1424 | __ bind(&one_is_nan); |
| 1425 | // NaN comparisons always fail. |
| 1426 | // Load whatever we need in r0 to make the comparison fail. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1427 | if (cond == lt || cond == le) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1428 | __ mov(r0, Operand(GREATER)); |
| 1429 | } else { |
| 1430 | __ mov(r0, Operand(LESS)); |
| 1431 | } |
| 1432 | __ Ret(); |
| 1433 | |
| 1434 | __ bind(&neither_is_nan); |
| 1435 | } |
| 1436 | |
| 1437 | |
| 1438 | // See comment at call site. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1439 | static void EmitTwoNonNanDoubleComparison(MacroAssembler* masm, |
| 1440 | Condition cond) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1441 | bool exp_first = (HeapNumber::kExponentOffset == HeapNumber::kValueOffset); |
| 1442 | Register rhs_exponent = exp_first ? r0 : r1; |
| 1443 | Register lhs_exponent = exp_first ? r2 : r3; |
| 1444 | Register rhs_mantissa = exp_first ? r1 : r0; |
| 1445 | Register lhs_mantissa = exp_first ? r3 : r2; |
| 1446 | |
| 1447 | // r0, r1, r2, r3 have the two doubles. Neither is a NaN. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1448 | if (cond == eq) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1449 | // Doubles are not equal unless they have the same bit pattern. |
| 1450 | // Exception: 0 and -0. |
| 1451 | __ cmp(rhs_mantissa, Operand(lhs_mantissa)); |
| 1452 | __ orr(r0, rhs_mantissa, Operand(lhs_mantissa), LeaveCC, ne); |
| 1453 | // Return non-zero if the numbers are unequal. |
| 1454 | __ Ret(ne); |
| 1455 | |
| 1456 | __ sub(r0, rhs_exponent, Operand(lhs_exponent), SetCC); |
| 1457 | // If exponents are equal then return 0. |
| 1458 | __ Ret(eq); |
| 1459 | |
| 1460 | // Exponents are unequal. The only way we can return that the numbers |
| 1461 | // are equal is if one is -0 and the other is 0. We already dealt |
| 1462 | // with the case where both are -0 or both are 0. |
| 1463 | // We start by seeing if the mantissas (that are equal) or the bottom |
| 1464 | // 31 bits of the rhs exponent are non-zero. If so we return not |
| 1465 | // equal. |
| 1466 | __ orr(r4, lhs_mantissa, Operand(lhs_exponent, LSL, kSmiTagSize), SetCC); |
| 1467 | __ mov(r0, Operand(r4), LeaveCC, ne); |
| 1468 | __ Ret(ne); |
| 1469 | // Now they are equal if and only if the lhs exponent is zero in its |
| 1470 | // low 31 bits. |
| 1471 | __ mov(r0, Operand(rhs_exponent, LSL, kSmiTagSize)); |
| 1472 | __ Ret(); |
| 1473 | } else { |
| 1474 | // Call a native function to do a comparison between two non-NaNs. |
| 1475 | // Call C routine that may not cause GC or other trouble. |
| 1476 | __ push(lr); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1477 | __ PrepareCallCFunction(0, 2, r5); |
| 1478 | if (masm->use_eabi_hardfloat()) { |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 1479 | CpuFeatures::Scope scope(VFP2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1480 | __ vmov(d0, r0, r1); |
| 1481 | __ vmov(d1, r2, r3); |
| 1482 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1483 | |
| 1484 | AllowExternalCallThatCantCauseGC scope(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1485 | __ CallCFunction(ExternalReference::compare_doubles(masm->isolate()), |
| 1486 | 0, 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1487 | __ pop(pc); // Return. |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | |
| 1492 | // See comment at call site. |
| 1493 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 1494 | Register lhs, |
| 1495 | Register rhs) { |
| 1496 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 1497 | (lhs.is(r1) && rhs.is(r0))); |
| 1498 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1499 | // If either operand is a JS object or an oddball value, then they are |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1500 | // not equal since their pointers are different. |
| 1501 | // There is no test for undetectability in strict equality. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1502 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1503 | Label first_non_object; |
| 1504 | // Get the type of the first operand into r2 and compare it with |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1505 | // FIRST_SPEC_OBJECT_TYPE. |
| 1506 | __ CompareObjectType(rhs, r2, r2, FIRST_SPEC_OBJECT_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1507 | __ b(lt, &first_non_object); |
| 1508 | |
| 1509 | // Return non-zero (r0 is not zero) |
| 1510 | Label return_not_equal; |
| 1511 | __ bind(&return_not_equal); |
| 1512 | __ Ret(); |
| 1513 | |
| 1514 | __ bind(&first_non_object); |
| 1515 | // Check for oddballs: true, false, null, undefined. |
| 1516 | __ cmp(r2, Operand(ODDBALL_TYPE)); |
| 1517 | __ b(eq, &return_not_equal); |
| 1518 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1519 | __ CompareObjectType(lhs, r3, r3, FIRST_SPEC_OBJECT_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1520 | __ b(ge, &return_not_equal); |
| 1521 | |
| 1522 | // Check for oddballs: true, false, null, undefined. |
| 1523 | __ cmp(r3, Operand(ODDBALL_TYPE)); |
| 1524 | __ b(eq, &return_not_equal); |
| 1525 | |
| 1526 | // Now that we have the types we might as well check for symbol-symbol. |
| 1527 | // Ensure that no non-strings have the symbol bit set. |
| 1528 | STATIC_ASSERT(LAST_TYPE < kNotStringTag + kIsSymbolMask); |
| 1529 | STATIC_ASSERT(kSymbolTag != 0); |
| 1530 | __ and_(r2, r2, Operand(r3)); |
| 1531 | __ tst(r2, Operand(kIsSymbolMask)); |
| 1532 | __ b(ne, &return_not_equal); |
| 1533 | } |
| 1534 | |
| 1535 | |
| 1536 | // See comment at call site. |
| 1537 | static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm, |
| 1538 | Register lhs, |
| 1539 | Register rhs, |
| 1540 | Label* both_loaded_as_doubles, |
| 1541 | Label* not_heap_numbers, |
| 1542 | Label* slow) { |
| 1543 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 1544 | (lhs.is(r1) && rhs.is(r0))); |
| 1545 | |
| 1546 | __ CompareObjectType(rhs, r3, r2, HEAP_NUMBER_TYPE); |
| 1547 | __ b(ne, not_heap_numbers); |
| 1548 | __ ldr(r2, FieldMemOperand(lhs, HeapObject::kMapOffset)); |
| 1549 | __ cmp(r2, r3); |
| 1550 | __ b(ne, slow); // First was a heap number, second wasn't. Go slow case. |
| 1551 | |
| 1552 | // Both are heap numbers. Load them up then jump to the code we have |
| 1553 | // for that. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 1554 | if (CpuFeatures::IsSupported(VFP2)) { |
| 1555 | CpuFeatures::Scope scope(VFP2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1556 | __ sub(r7, rhs, Operand(kHeapObjectTag)); |
| 1557 | __ vldr(d6, r7, HeapNumber::kValueOffset); |
| 1558 | __ sub(r7, lhs, Operand(kHeapObjectTag)); |
| 1559 | __ vldr(d7, r7, HeapNumber::kValueOffset); |
| 1560 | } else { |
| 1561 | __ Ldrd(r2, r3, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 1562 | __ Ldrd(r0, r1, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 1563 | } |
| 1564 | __ jmp(both_loaded_as_doubles); |
| 1565 | } |
| 1566 | |
| 1567 | |
| 1568 | // Fast negative check for symbol-to-symbol equality. |
| 1569 | static void EmitCheckForSymbolsOrObjects(MacroAssembler* masm, |
| 1570 | Register lhs, |
| 1571 | Register rhs, |
| 1572 | Label* possible_strings, |
| 1573 | Label* not_both_strings) { |
| 1574 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 1575 | (lhs.is(r1) && rhs.is(r0))); |
| 1576 | |
| 1577 | // r2 is object type of rhs. |
| 1578 | // Ensure that no non-strings have the symbol bit set. |
| 1579 | Label object_test; |
| 1580 | STATIC_ASSERT(kSymbolTag != 0); |
| 1581 | __ tst(r2, Operand(kIsNotStringMask)); |
| 1582 | __ b(ne, &object_test); |
| 1583 | __ tst(r2, Operand(kIsSymbolMask)); |
| 1584 | __ b(eq, possible_strings); |
| 1585 | __ CompareObjectType(lhs, r3, r3, FIRST_NONSTRING_TYPE); |
| 1586 | __ b(ge, not_both_strings); |
| 1587 | __ tst(r3, Operand(kIsSymbolMask)); |
| 1588 | __ b(eq, possible_strings); |
| 1589 | |
| 1590 | // Both are symbols. We already checked they weren't the same pointer |
| 1591 | // so they are not equal. |
| 1592 | __ mov(r0, Operand(NOT_EQUAL)); |
| 1593 | __ Ret(); |
| 1594 | |
| 1595 | __ bind(&object_test); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1596 | __ cmp(r2, Operand(FIRST_SPEC_OBJECT_TYPE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1597 | __ b(lt, not_both_strings); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1598 | __ CompareObjectType(lhs, r2, r3, FIRST_SPEC_OBJECT_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1599 | __ b(lt, not_both_strings); |
| 1600 | // If both objects are undetectable, they are equal. Otherwise, they |
| 1601 | // are not equal, since they are different objects and an object is not |
| 1602 | // equal to undefined. |
| 1603 | __ ldr(r3, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 1604 | __ ldrb(r2, FieldMemOperand(r2, Map::kBitFieldOffset)); |
| 1605 | __ ldrb(r3, FieldMemOperand(r3, Map::kBitFieldOffset)); |
| 1606 | __ and_(r0, r2, Operand(r3)); |
| 1607 | __ and_(r0, r0, Operand(1 << Map::kIsUndetectable)); |
| 1608 | __ eor(r0, r0, Operand(1 << Map::kIsUndetectable)); |
| 1609 | __ Ret(); |
| 1610 | } |
| 1611 | |
| 1612 | |
| 1613 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 1614 | Register object, |
| 1615 | Register result, |
| 1616 | Register scratch1, |
| 1617 | Register scratch2, |
| 1618 | Register scratch3, |
| 1619 | bool object_is_smi, |
| 1620 | Label* not_found) { |
| 1621 | // Use of registers. Register result is used as a temporary. |
| 1622 | Register number_string_cache = result; |
| 1623 | Register mask = scratch3; |
| 1624 | |
| 1625 | // Load the number string cache. |
| 1626 | __ LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex); |
| 1627 | |
| 1628 | // Make the hash mask from the length of the number string cache. It |
| 1629 | // contains two elements (number and string) for each cache entry. |
| 1630 | __ ldr(mask, FieldMemOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 1631 | // Divide length by two (length is a smi). |
| 1632 | __ mov(mask, Operand(mask, ASR, kSmiTagSize + 1)); |
| 1633 | __ sub(mask, mask, Operand(1)); // Make mask. |
| 1634 | |
| 1635 | // Calculate the entry in the number string cache. The hash value in the |
| 1636 | // number string cache for smis is just the smi value, and the hash for |
| 1637 | // doubles is the xor of the upper and lower words. See |
| 1638 | // Heap::GetNumberStringCache. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1639 | Isolate* isolate = masm->isolate(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1640 | Label is_smi; |
| 1641 | Label load_result_from_cache; |
| 1642 | if (!object_is_smi) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1643 | __ JumpIfSmi(object, &is_smi); |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 1644 | if (CpuFeatures::IsSupported(VFP2)) { |
| 1645 | CpuFeatures::Scope scope(VFP2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1646 | __ CheckMap(object, |
| 1647 | scratch1, |
| 1648 | Heap::kHeapNumberMapRootIndex, |
| 1649 | not_found, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1650 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1651 | |
| 1652 | STATIC_ASSERT(8 == kDoubleSize); |
| 1653 | __ add(scratch1, |
| 1654 | object, |
| 1655 | Operand(HeapNumber::kValueOffset - kHeapObjectTag)); |
| 1656 | __ ldm(ia, scratch1, scratch1.bit() | scratch2.bit()); |
| 1657 | __ eor(scratch1, scratch1, Operand(scratch2)); |
| 1658 | __ and_(scratch1, scratch1, Operand(mask)); |
| 1659 | |
| 1660 | // Calculate address of entry in string cache: each entry consists |
| 1661 | // of two pointer sized fields. |
| 1662 | __ add(scratch1, |
| 1663 | number_string_cache, |
| 1664 | Operand(scratch1, LSL, kPointerSizeLog2 + 1)); |
| 1665 | |
| 1666 | Register probe = mask; |
| 1667 | __ ldr(probe, |
| 1668 | FieldMemOperand(scratch1, FixedArray::kHeaderSize)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1669 | __ JumpIfSmi(probe, not_found); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1670 | __ sub(scratch2, object, Operand(kHeapObjectTag)); |
| 1671 | __ vldr(d0, scratch2, HeapNumber::kValueOffset); |
| 1672 | __ sub(probe, probe, Operand(kHeapObjectTag)); |
| 1673 | __ vldr(d1, probe, HeapNumber::kValueOffset); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1674 | __ VFPCompareAndSetFlags(d0, d1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1675 | __ b(ne, not_found); // The cache did not contain this value. |
| 1676 | __ b(&load_result_from_cache); |
| 1677 | } else { |
| 1678 | __ b(not_found); |
| 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | __ bind(&is_smi); |
| 1683 | Register scratch = scratch1; |
| 1684 | __ and_(scratch, mask, Operand(object, ASR, 1)); |
| 1685 | // Calculate address of entry in string cache: each entry consists |
| 1686 | // of two pointer sized fields. |
| 1687 | __ add(scratch, |
| 1688 | number_string_cache, |
| 1689 | Operand(scratch, LSL, kPointerSizeLog2 + 1)); |
| 1690 | |
| 1691 | // Check if the entry is the smi we are looking for. |
| 1692 | Register probe = mask; |
| 1693 | __ ldr(probe, FieldMemOperand(scratch, FixedArray::kHeaderSize)); |
| 1694 | __ cmp(object, probe); |
| 1695 | __ b(ne, not_found); |
| 1696 | |
| 1697 | // Get the result from the cache. |
| 1698 | __ bind(&load_result_from_cache); |
| 1699 | __ ldr(result, |
| 1700 | FieldMemOperand(scratch, FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1701 | __ IncrementCounter(isolate->counters()->number_to_string_native(), |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1702 | 1, |
| 1703 | scratch1, |
| 1704 | scratch2); |
| 1705 | } |
| 1706 | |
| 1707 | |
| 1708 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 1709 | Label runtime; |
| 1710 | |
| 1711 | __ ldr(r1, MemOperand(sp, 0)); |
| 1712 | |
| 1713 | // Generate code to lookup number in the number string cache. |
| 1714 | GenerateLookupNumberStringCache(masm, r1, r0, r2, r3, r4, false, &runtime); |
| 1715 | __ add(sp, sp, Operand(1 * kPointerSize)); |
| 1716 | __ Ret(); |
| 1717 | |
| 1718 | __ bind(&runtime); |
| 1719 | // Handle number to string in the runtime system if not found in the cache. |
| 1720 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 1721 | } |
| 1722 | |
| 1723 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1724 | static void ICCompareStub_CheckInputType(MacroAssembler* masm, |
| 1725 | Register input, |
| 1726 | Register scratch, |
| 1727 | CompareIC::State expected, |
| 1728 | Label* fail) { |
| 1729 | Label ok; |
| 1730 | if (expected == CompareIC::SMI) { |
| 1731 | __ JumpIfNotSmi(input, fail); |
| 1732 | } else if (expected == CompareIC::HEAP_NUMBER) { |
| 1733 | __ JumpIfSmi(input, &ok); |
| 1734 | __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail, |
| 1735 | DONT_DO_SMI_CHECK); |
| 1736 | } |
| 1737 | // We could be strict about symbol/string here, but as long as |
| 1738 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 1739 | __ bind(&ok); |
| 1740 | } |
| 1741 | |
| 1742 | |
| 1743 | // On entry r1 and r2 are the values to be compared. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1744 | // On exit r0 is 0, positive or negative to indicate the result of |
| 1745 | // the comparison. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1746 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 1747 | Register lhs = r1; |
| 1748 | Register rhs = r0; |
| 1749 | Condition cc = GetCondition(); |
| 1750 | |
| 1751 | Label miss; |
| 1752 | ICCompareStub_CheckInputType(masm, lhs, r2, left_, &miss); |
| 1753 | ICCompareStub_CheckInputType(masm, rhs, r3, right_, &miss); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1754 | |
| 1755 | Label slow; // Call builtin. |
| 1756 | Label not_smis, both_loaded_as_doubles, lhs_not_nan; |
| 1757 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1758 | Label not_two_smis, smi_done; |
| 1759 | __ orr(r2, r1, r0); |
| 1760 | __ JumpIfNotSmi(r2, ¬_two_smis); |
| 1761 | __ mov(r1, Operand(r1, ASR, 1)); |
| 1762 | __ sub(r0, r1, Operand(r0, ASR, 1)); |
| 1763 | __ Ret(); |
| 1764 | __ bind(¬_two_smis); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 1765 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1766 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 1767 | // it is certain that at least one operand isn't a smi. |
| 1768 | |
| 1769 | // Handle the case where the objects are identical. Either returns the answer |
| 1770 | // or goes to slow. Only falls through if the objects were not identical. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1771 | EmitIdenticalObjectComparison(masm, &slow, cc); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1772 | |
| 1773 | // If either is a Smi (we know that not both are), then they can only |
| 1774 | // be strictly equal if the other is a HeapNumber. |
| 1775 | STATIC_ASSERT(kSmiTag == 0); |
| 1776 | ASSERT_EQ(0, Smi::FromInt(0)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1777 | __ and_(r2, lhs, Operand(rhs)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1778 | __ JumpIfNotSmi(r2, ¬_smis); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1779 | // One operand is a smi. EmitSmiNonsmiComparison generates code that can: |
| 1780 | // 1) Return the answer. |
| 1781 | // 2) Go to slow. |
| 1782 | // 3) Fall through to both_loaded_as_doubles. |
| 1783 | // 4) Jump to lhs_not_nan. |
| 1784 | // In cases 3 and 4 we have found out we were dealing with a number-number |
| 1785 | // comparison. If VFP3 is supported the double values of the numbers have |
| 1786 | // been loaded into d7 and d6. Otherwise, the double values have been loaded |
| 1787 | // into r0, r1, r2, and r3. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1788 | EmitSmiNonsmiComparison(masm, lhs, rhs, &lhs_not_nan, &slow, strict()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1789 | |
| 1790 | __ bind(&both_loaded_as_doubles); |
| 1791 | // The arguments have been converted to doubles and stored in d6 and d7, if |
| 1792 | // VFP3 is supported, or in r0, r1, r2, and r3. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1793 | Isolate* isolate = masm->isolate(); |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 1794 | if (CpuFeatures::IsSupported(VFP2)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1795 | __ bind(&lhs_not_nan); |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 1796 | CpuFeatures::Scope scope(VFP2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1797 | Label no_nan; |
| 1798 | // ARMv7 VFP3 instructions to implement double precision comparison. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1799 | __ VFPCompareAndSetFlags(d7, d6); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1800 | Label nan; |
| 1801 | __ b(vs, &nan); |
| 1802 | __ mov(r0, Operand(EQUAL), LeaveCC, eq); |
| 1803 | __ mov(r0, Operand(LESS), LeaveCC, lt); |
| 1804 | __ mov(r0, Operand(GREATER), LeaveCC, gt); |
| 1805 | __ Ret(); |
| 1806 | |
| 1807 | __ bind(&nan); |
| 1808 | // If one of the sides was a NaN then the v flag is set. Load r0 with |
| 1809 | // whatever it takes to make the comparison fail, since comparisons with NaN |
| 1810 | // always fail. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1811 | if (cc == lt || cc == le) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1812 | __ mov(r0, Operand(GREATER)); |
| 1813 | } else { |
| 1814 | __ mov(r0, Operand(LESS)); |
| 1815 | } |
| 1816 | __ Ret(); |
| 1817 | } else { |
| 1818 | // Checks for NaN in the doubles we have loaded. Can return the answer or |
| 1819 | // fall through if neither is a NaN. Also binds lhs_not_nan. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1820 | EmitNanCheck(masm, &lhs_not_nan, cc); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1821 | // Compares two doubles in r0, r1, r2, r3 that are not NaNs. Returns the |
| 1822 | // answer. Never falls through. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1823 | EmitTwoNonNanDoubleComparison(masm, cc); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | __ bind(¬_smis); |
| 1827 | // At this point we know we are dealing with two different objects, |
| 1828 | // and neither of them is a Smi. The objects are in rhs_ and lhs_. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1829 | if (strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1830 | // This returns non-equal for some object types, or falls through if it |
| 1831 | // was not lucky. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1832 | EmitStrictTwoHeapObjectCompare(masm, lhs, rhs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | Label check_for_symbols; |
| 1836 | Label flat_string_check; |
| 1837 | // Check for heap-number-heap-number comparison. Can jump to slow case, |
| 1838 | // or load both doubles into r0, r1, r2, r3 and jump to the code that handles |
| 1839 | // that case. If the inputs are not doubles then jumps to check_for_symbols. |
| 1840 | // In this case r2 will contain the type of rhs_. Never falls through. |
| 1841 | EmitCheckForTwoHeapNumbers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1842 | lhs, |
| 1843 | rhs, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1844 | &both_loaded_as_doubles, |
| 1845 | &check_for_symbols, |
| 1846 | &flat_string_check); |
| 1847 | |
| 1848 | __ bind(&check_for_symbols); |
| 1849 | // In the strict case the EmitStrictTwoHeapObjectCompare already took care of |
| 1850 | // symbols. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1851 | if (cc == eq && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1852 | // Returns an answer for two symbols or two detectable objects. |
| 1853 | // Otherwise jumps to string case or not both strings case. |
| 1854 | // Assumes that r2 is the type of rhs_ on entry. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1855 | EmitCheckForSymbolsOrObjects(masm, lhs, rhs, &flat_string_check, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | // Check for both being sequential ASCII strings, and inline if that is the |
| 1859 | // case. |
| 1860 | __ bind(&flat_string_check); |
| 1861 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1862 | __ JumpIfNonSmisNotBothSequentialAsciiStrings(lhs, rhs, r2, r3, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1863 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1864 | __ IncrementCounter(isolate->counters()->string_compare_native(), 1, r2, r3); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1865 | if (cc == eq) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1866 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1867 | lhs, |
| 1868 | rhs, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1869 | r2, |
| 1870 | r3, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1871 | r4); |
| 1872 | } else { |
| 1873 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1874 | lhs, |
| 1875 | rhs, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1876 | r2, |
| 1877 | r3, |
| 1878 | r4, |
| 1879 | r5); |
| 1880 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1881 | // Never falls through to here. |
| 1882 | |
| 1883 | __ bind(&slow); |
| 1884 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1885 | __ Push(lhs, rhs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1886 | // Figure out which native to call and setup the arguments. |
| 1887 | Builtins::JavaScript native; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1888 | if (cc == eq) { |
| 1889 | native = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1890 | } else { |
| 1891 | native = Builtins::COMPARE; |
| 1892 | int ncr; // NaN compare result |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1893 | if (cc == lt || cc == le) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1894 | ncr = GREATER; |
| 1895 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1896 | ASSERT(cc == gt || cc == ge); // remaining cases |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1897 | ncr = LESS; |
| 1898 | } |
| 1899 | __ mov(r0, Operand(Smi::FromInt(ncr))); |
| 1900 | __ push(r0); |
| 1901 | } |
| 1902 | |
| 1903 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 1904 | // tagged as a small integer. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1905 | __ InvokeBuiltin(native, JUMP_FUNCTION); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1906 | |
| 1907 | __ bind(&miss); |
| 1908 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1912 | // The stub expects its argument in the tos_ register and returns its result in |
| 1913 | // it, too: zero for false, and a non-zero value for true. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1914 | void ToBooleanStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1915 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 1916 | // we cannot call anything that could cause a GC from this stub. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1917 | Label patch; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1918 | const Register map = r9.is(tos_) ? r7 : r9; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1919 | const Register temp = map; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1920 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1921 | // undefined -> false. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1922 | CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1923 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1924 | // Boolean -> its value. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1925 | CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); |
| 1926 | CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1927 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1928 | // 'null' -> false. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1929 | CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1930 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1931 | if (types_.Contains(SMI)) { |
| 1932 | // Smis: 0 -> false, all other -> true |
| 1933 | __ tst(tos_, Operand(kSmiTagMask)); |
| 1934 | // tos_ contains the correct return value already |
| 1935 | __ Ret(eq); |
| 1936 | } else if (types_.NeedsMap()) { |
| 1937 | // If we need a map later and have a Smi -> patch. |
| 1938 | __ JumpIfSmi(tos_, &patch); |
| 1939 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1940 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1941 | if (types_.NeedsMap()) { |
| 1942 | __ ldr(map, FieldMemOperand(tos_, HeapObject::kMapOffset)); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1943 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1944 | if (types_.CanBeUndetectable()) { |
| 1945 | __ ldrb(ip, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 1946 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
| 1947 | // Undetectable -> false. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1948 | __ mov(tos_, Operand::Zero(), LeaveCC, ne); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1949 | __ Ret(ne); |
| 1950 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1951 | } |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1952 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1953 | if (types_.Contains(SPEC_OBJECT)) { |
| 1954 | // Spec object -> true. |
| 1955 | __ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE); |
| 1956 | // tos_ contains the correct non-zero return value already. |
| 1957 | __ Ret(ge); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1958 | } |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1959 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1960 | if (types_.Contains(STRING)) { |
| 1961 | // String value -> false iff empty. |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1962 | __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1963 | __ ldr(tos_, FieldMemOperand(tos_, String::kLengthOffset), lt); |
| 1964 | __ Ret(lt); // the string length is OK as the return value |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1965 | } |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1966 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1967 | if (types_.Contains(HEAP_NUMBER)) { |
| 1968 | // Heap number -> false iff +0, -0, or NaN. |
| 1969 | Label not_heap_number; |
| 1970 | __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 1971 | __ b(ne, ¬_heap_number); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1972 | |
| 1973 | if (CpuFeatures::IsSupported(VFP2)) { |
| 1974 | CpuFeatures::Scope scope(VFP2); |
| 1975 | |
| 1976 | __ vldr(d1, FieldMemOperand(tos_, HeapNumber::kValueOffset)); |
| 1977 | __ VFPCompareAndSetFlags(d1, 0.0); |
| 1978 | // "tos_" is a register, and contains a non zero value by default. |
| 1979 | // Hence we only need to overwrite "tos_" with zero to return false for |
| 1980 | // FP_ZERO or FP_NAN cases. Otherwise, by default it returns true. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1981 | __ mov(tos_, Operand::Zero(), LeaveCC, eq); // for FP_ZERO |
| 1982 | __ mov(tos_, Operand::Zero(), LeaveCC, vs); // for FP_NAN |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1983 | } else { |
| 1984 | Label done, not_nan, not_zero; |
| 1985 | __ ldr(temp, FieldMemOperand(tos_, HeapNumber::kExponentOffset)); |
| 1986 | // -0 maps to false: |
| 1987 | __ bic( |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1988 | temp, temp, Operand(HeapNumber::kSignMask, RelocInfo::NONE32), SetCC); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1989 | __ b(ne, ¬_zero); |
| 1990 | // If exponent word is zero then the answer depends on the mantissa word. |
| 1991 | __ ldr(tos_, FieldMemOperand(tos_, HeapNumber::kMantissaOffset)); |
| 1992 | __ jmp(&done); |
| 1993 | |
| 1994 | // Check for NaN. |
| 1995 | __ bind(¬_zero); |
| 1996 | // We already zeroed the sign bit, now shift out the mantissa so we only |
| 1997 | // have the exponent left. |
| 1998 | __ mov(temp, Operand(temp, LSR, HeapNumber::kMantissaBitsInTopWord)); |
| 1999 | unsigned int shifted_exponent_mask = |
| 2000 | HeapNumber::kExponentMask >> HeapNumber::kMantissaBitsInTopWord; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2001 | __ cmp(temp, Operand(shifted_exponent_mask, RelocInfo::NONE32)); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2002 | __ b(ne, ¬_nan); // If exponent is not 0x7ff then it can't be a NaN. |
| 2003 | |
| 2004 | // Reload exponent word. |
| 2005 | __ ldr(temp, FieldMemOperand(tos_, HeapNumber::kExponentOffset)); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2006 | __ tst(temp, Operand(HeapNumber::kMantissaMask, RelocInfo::NONE32)); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2007 | // If mantissa is not zero then we have a NaN, so return 0. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2008 | __ mov(tos_, Operand::Zero(), LeaveCC, ne); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2009 | __ b(ne, &done); |
| 2010 | |
| 2011 | // Load mantissa word. |
| 2012 | __ ldr(temp, FieldMemOperand(tos_, HeapNumber::kMantissaOffset)); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2013 | __ cmp(temp, Operand::Zero()); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2014 | // If mantissa is not zero then we have a NaN, so return 0. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2015 | __ mov(tos_, Operand::Zero(), LeaveCC, ne); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2016 | __ b(ne, &done); |
| 2017 | |
| 2018 | __ bind(¬_nan); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2019 | __ mov(tos_, Operand(1, RelocInfo::NONE32)); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2020 | __ bind(&done); |
| 2021 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2022 | __ Ret(); |
| 2023 | __ bind(¬_heap_number); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2024 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2025 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2026 | __ bind(&patch); |
| 2027 | GenerateTypeTransition(masm); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2028 | } |
| 2029 | |
| 2030 | |
| 2031 | void ToBooleanStub::CheckOddball(MacroAssembler* masm, |
| 2032 | Type type, |
| 2033 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2034 | bool result) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2035 | if (types_.Contains(type)) { |
| 2036 | // If we see an expected oddball, return its ToBoolean value tos_. |
| 2037 | __ LoadRoot(ip, value); |
| 2038 | __ cmp(tos_, ip); |
| 2039 | // The value of a root is never NULL, so we can avoid loading a non-null |
| 2040 | // value into tos_ when we want to return 'true'. |
| 2041 | if (!result) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2042 | __ mov(tos_, Operand::Zero(), LeaveCC, eq); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2043 | } |
| 2044 | __ Ret(eq); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2045 | } |
| 2046 | } |
| 2047 | |
| 2048 | |
| 2049 | void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 2050 | if (!tos_.is(r3)) { |
| 2051 | __ mov(r3, Operand(tos_)); |
| 2052 | } |
| 2053 | __ mov(r2, Operand(Smi::FromInt(tos_.code()))); |
| 2054 | __ mov(r1, Operand(Smi::FromInt(types_.ToByte()))); |
| 2055 | __ Push(r3, r2, r1); |
| 2056 | // Patch the caller to an appropriate specialized stub and return the |
| 2057 | // operation result to the caller of the stub. |
| 2058 | __ TailCallExternalReference( |
| 2059 | ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), |
| 2060 | 3, |
| 2061 | 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2065 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 2066 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 2067 | // store the registers in any particular way, but we do have to store and |
| 2068 | // restore them. |
| 2069 | __ stm(db_w, sp, kCallerSaved | lr.bit()); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 2070 | |
| 2071 | const Register scratch = r1; |
| 2072 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2073 | if (save_doubles_ == kSaveFPRegs) { |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 2074 | CpuFeatures::Scope scope(VFP2); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 2075 | // Check CPU flags for number of registers, setting the Z condition flag. |
| 2076 | __ CheckFor32DRegs(scratch); |
| 2077 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2078 | __ sub(sp, sp, Operand(kDoubleSize * DwVfpRegister::kNumRegisters)); |
| 2079 | for (int i = 0; i < DwVfpRegister::kNumRegisters; i++) { |
| 2080 | DwVfpRegister reg = DwVfpRegister::from_code(i); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 2081 | __ vstr(reg, MemOperand(sp, i * kDoubleSize), i < 16 ? al : ne); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2082 | } |
| 2083 | } |
| 2084 | const int argument_count = 1; |
| 2085 | const int fp_argument_count = 0; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2086 | |
| 2087 | AllowExternalCallThatCantCauseGC scope(masm); |
| 2088 | __ PrepareCallCFunction(argument_count, fp_argument_count, scratch); |
| 2089 | __ mov(r0, Operand(ExternalReference::isolate_address())); |
| 2090 | __ CallCFunction( |
| 2091 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 2092 | argument_count); |
| 2093 | if (save_doubles_ == kSaveFPRegs) { |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 2094 | CpuFeatures::Scope scope(VFP2); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 2095 | |
| 2096 | // Check CPU flags for number of registers, setting the Z condition flag. |
| 2097 | __ CheckFor32DRegs(scratch); |
| 2098 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2099 | for (int i = 0; i < DwVfpRegister::kNumRegisters; i++) { |
| 2100 | DwVfpRegister reg = DwVfpRegister::from_code(i); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 2101 | __ vldr(reg, MemOperand(sp, i * kDoubleSize), i < 16 ? al : ne); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2102 | } |
| 2103 | __ add(sp, sp, Operand(kDoubleSize * DwVfpRegister::kNumRegisters)); |
| 2104 | } |
| 2105 | __ ldm(ia_w, sp, kCallerSaved | pc.bit()); // Also pop pc to get Ret(0). |
| 2106 | } |
| 2107 | |
| 2108 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 2109 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2110 | const char* op_name = Token::Name(op_); |
| 2111 | const char* overwrite_name = NULL; // Make g++ happy. |
| 2112 | switch (mode_) { |
| 2113 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 2114 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 2115 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 2116 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 2117 | op_name, |
| 2118 | overwrite_name, |
| 2119 | UnaryOpIC::GetName(operand_type_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | |
| 2123 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2124 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2125 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2126 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2127 | GenerateTypeTransition(masm); |
| 2128 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2129 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2130 | GenerateSmiStub(masm); |
| 2131 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2132 | case UnaryOpIC::HEAP_NUMBER: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2133 | GenerateHeapNumberStub(masm); |
| 2134 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2135 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2136 | GenerateGenericStub(masm); |
| 2137 | break; |
| 2138 | } |
| 2139 | } |
| 2140 | |
| 2141 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2142 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2143 | __ mov(r3, Operand(r0)); // the operand |
| 2144 | __ mov(r2, Operand(Smi::FromInt(op_))); |
| 2145 | __ mov(r1, Operand(Smi::FromInt(mode_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2146 | __ mov(r0, Operand(Smi::FromInt(operand_type_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2147 | __ Push(r3, r2, r1, r0); |
| 2148 | |
| 2149 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2150 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | |
| 2154 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2155 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2156 | switch (op_) { |
| 2157 | case Token::SUB: |
| 2158 | GenerateSmiStubSub(masm); |
| 2159 | break; |
| 2160 | case Token::BIT_NOT: |
| 2161 | GenerateSmiStubBitNot(masm); |
| 2162 | break; |
| 2163 | default: |
| 2164 | UNREACHABLE(); |
| 2165 | } |
| 2166 | } |
| 2167 | |
| 2168 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2169 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2170 | Label non_smi, slow; |
| 2171 | GenerateSmiCodeSub(masm, &non_smi, &slow); |
| 2172 | __ bind(&non_smi); |
| 2173 | __ bind(&slow); |
| 2174 | GenerateTypeTransition(masm); |
| 2175 | } |
| 2176 | |
| 2177 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2178 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2179 | Label non_smi; |
| 2180 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 2181 | __ bind(&non_smi); |
| 2182 | GenerateTypeTransition(masm); |
| 2183 | } |
| 2184 | |
| 2185 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2186 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 2187 | Label* non_smi, |
| 2188 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2189 | __ JumpIfNotSmi(r0, non_smi); |
| 2190 | |
| 2191 | // The result of negating zero or the smallest negative smi is not a smi. |
| 2192 | __ bic(ip, r0, Operand(0x80000000), SetCC); |
| 2193 | __ b(eq, slow); |
| 2194 | |
| 2195 | // Return '0 - value'. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2196 | __ rsb(r0, r0, Operand::Zero()); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2197 | __ Ret(); |
| 2198 | } |
| 2199 | |
| 2200 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2201 | void UnaryOpStub::GenerateSmiCodeBitNot(MacroAssembler* masm, |
| 2202 | Label* non_smi) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2203 | __ JumpIfNotSmi(r0, non_smi); |
| 2204 | |
| 2205 | // Flip bits and revert inverted smi-tag. |
| 2206 | __ mvn(r0, Operand(r0)); |
| 2207 | __ bic(r0, r0, Operand(kSmiTagMask)); |
| 2208 | __ Ret(); |
| 2209 | } |
| 2210 | |
| 2211 | |
| 2212 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2213 | void UnaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2214 | switch (op_) { |
| 2215 | case Token::SUB: |
| 2216 | GenerateHeapNumberStubSub(masm); |
| 2217 | break; |
| 2218 | case Token::BIT_NOT: |
| 2219 | GenerateHeapNumberStubBitNot(masm); |
| 2220 | break; |
| 2221 | default: |
| 2222 | UNREACHABLE(); |
| 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2227 | void UnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2228 | Label non_smi, slow, call_builtin; |
| 2229 | GenerateSmiCodeSub(masm, &non_smi, &call_builtin); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2230 | __ bind(&non_smi); |
| 2231 | GenerateHeapNumberCodeSub(masm, &slow); |
| 2232 | __ bind(&slow); |
| 2233 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2234 | __ bind(&call_builtin); |
| 2235 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2239 | void UnaryOpStub::GenerateHeapNumberStubBitNot(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2240 | Label non_smi, slow; |
| 2241 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 2242 | __ bind(&non_smi); |
| 2243 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 2244 | __ bind(&slow); |
| 2245 | GenerateTypeTransition(masm); |
| 2246 | } |
| 2247 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2248 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 2249 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2250 | EmitCheckForHeapNumber(masm, r0, r1, r6, slow); |
| 2251 | // r0 is a heap number. Get a new heap number in r1. |
| 2252 | if (mode_ == UNARY_OVERWRITE) { |
| 2253 | __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 2254 | __ eor(r2, r2, Operand(HeapNumber::kSignMask)); // Flip sign. |
| 2255 | __ str(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 2256 | } else { |
| 2257 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 2258 | __ AllocateHeapNumber(r1, r2, r3, r6, &slow_allocate_heapnumber); |
| 2259 | __ jmp(&heapnumber_allocated); |
| 2260 | |
| 2261 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2262 | { |
| 2263 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2264 | __ push(r0); |
| 2265 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 2266 | __ mov(r1, Operand(r0)); |
| 2267 | __ pop(r0); |
| 2268 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2269 | |
| 2270 | __ bind(&heapnumber_allocated); |
| 2271 | __ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset)); |
| 2272 | __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 2273 | __ str(r3, FieldMemOperand(r1, HeapNumber::kMantissaOffset)); |
| 2274 | __ eor(r2, r2, Operand(HeapNumber::kSignMask)); // Flip sign. |
| 2275 | __ str(r2, FieldMemOperand(r1, HeapNumber::kExponentOffset)); |
| 2276 | __ mov(r0, Operand(r1)); |
| 2277 | } |
| 2278 | __ Ret(); |
| 2279 | } |
| 2280 | |
| 2281 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2282 | void UnaryOpStub::GenerateHeapNumberCodeBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2283 | MacroAssembler* masm, Label* slow) { |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2284 | Label impossible; |
| 2285 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2286 | EmitCheckForHeapNumber(masm, r0, r1, r6, slow); |
| 2287 | // Convert the heap number is r0 to an untagged integer in r1. |
| 2288 | __ ConvertToInt32(r0, r1, r2, r3, d0, slow); |
| 2289 | |
| 2290 | // Do the bitwise operation and check if the result fits in a smi. |
| 2291 | Label try_float; |
| 2292 | __ mvn(r1, Operand(r1)); |
| 2293 | __ add(r2, r1, Operand(0x40000000), SetCC); |
| 2294 | __ b(mi, &try_float); |
| 2295 | |
| 2296 | // Tag the result as a smi and we're done. |
| 2297 | __ mov(r0, Operand(r1, LSL, kSmiTagSize)); |
| 2298 | __ Ret(); |
| 2299 | |
| 2300 | // Try to store the result in a heap number. |
| 2301 | __ bind(&try_float); |
| 2302 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 2303 | Label slow_allocate_heapnumber, heapnumber_allocated; |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2304 | // Allocate a new heap number without zapping r0, which we need if it fails. |
| 2305 | __ AllocateHeapNumber(r2, r3, r4, r6, &slow_allocate_heapnumber); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2306 | __ jmp(&heapnumber_allocated); |
| 2307 | |
| 2308 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2309 | { |
| 2310 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2311 | __ push(r0); // Push the heap number, not the untagged int32. |
| 2312 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 2313 | __ mov(r2, r0); // Move the new heap number into r2. |
| 2314 | // Get the heap number into r0, now that the new heap number is in r2. |
| 2315 | __ pop(r0); |
| 2316 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2317 | |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2318 | // Convert the heap number in r0 to an untagged integer in r1. |
| 2319 | // This can't go slow-case because it's the same number we already |
| 2320 | // converted once again. |
| 2321 | __ ConvertToInt32(r0, r1, r3, r4, d0, &impossible); |
| 2322 | __ mvn(r1, Operand(r1)); |
| 2323 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2324 | __ bind(&heapnumber_allocated); |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2325 | __ mov(r0, r2); // Move newly allocated heap number to r0. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2326 | } |
| 2327 | |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 2328 | if (CpuFeatures::IsSupported(VFP2)) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2329 | // Convert the int32 in r1 to the heap number in r0. r2 is corrupted. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 2330 | CpuFeatures::Scope scope(VFP2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2331 | __ vmov(s0, r1); |
| 2332 | __ vcvt_f64_s32(d0, s0); |
| 2333 | __ sub(r2, r0, Operand(kHeapObjectTag)); |
| 2334 | __ vstr(d0, r2, HeapNumber::kValueOffset); |
| 2335 | __ Ret(); |
| 2336 | } else { |
| 2337 | // WriteInt32ToHeapNumberStub does not trigger GC, so we do not |
| 2338 | // have to set up a frame. |
| 2339 | WriteInt32ToHeapNumberStub stub(r1, r0, r2); |
| 2340 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 2341 | } |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2342 | |
| 2343 | __ bind(&impossible); |
| 2344 | if (FLAG_debug_code) { |
| 2345 | __ stop("Incorrect assumption in bit-not stub"); |
| 2346 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | |
| 2350 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2351 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2352 | switch (op_) { |
| 2353 | case Token::SUB: |
| 2354 | GenerateGenericStubSub(masm); |
| 2355 | break; |
| 2356 | case Token::BIT_NOT: |
| 2357 | GenerateGenericStubBitNot(masm); |
| 2358 | break; |
| 2359 | default: |
| 2360 | UNREACHABLE(); |
| 2361 | } |
| 2362 | } |
| 2363 | |
| 2364 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2365 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2366 | Label non_smi, slow; |
| 2367 | GenerateSmiCodeSub(masm, &non_smi, &slow); |
| 2368 | __ bind(&non_smi); |
| 2369 | GenerateHeapNumberCodeSub(masm, &slow); |
| 2370 | __ bind(&slow); |
| 2371 | GenerateGenericCodeFallback(masm); |
| 2372 | } |
| 2373 | |
| 2374 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2375 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2376 | Label non_smi, slow; |
| 2377 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 2378 | __ bind(&non_smi); |
| 2379 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 2380 | __ bind(&slow); |
| 2381 | GenerateGenericCodeFallback(masm); |
| 2382 | } |
| 2383 | |
| 2384 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2385 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2386 | // Handle the slow case by jumping to the JavaScript builtin. |
| 2387 | __ push(r0); |
| 2388 | switch (op_) { |
| 2389 | case Token::SUB: |
| 2390 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 2391 | break; |
| 2392 | case Token::BIT_NOT: |
| 2393 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 2394 | break; |
| 2395 | default: |
| 2396 | UNREACHABLE(); |
| 2397 | } |
| 2398 | } |
| 2399 | |
| 2400 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2401 | void BinaryOpStub::Initialize() { |
| 2402 | platform_specific_bit_ = CpuFeatures::IsSupported(VFP2); |
| 2403 | } |
| 2404 | |
| 2405 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2406 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2407 | Label get_result; |
| 2408 | |
| 2409 | __ Push(r1, r0); |
| 2410 | |
| 2411 | __ mov(r2, Operand(Smi::FromInt(MinorKey()))); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2412 | __ push(r2); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2413 | |
| 2414 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2415 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2416 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2417 | 3, |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2418 | 1); |
| 2419 | } |
| 2420 | |
| 2421 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2422 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs( |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2423 | MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2424 | UNIMPLEMENTED(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2428 | void BinaryOpStub_GenerateSmiSmiOperation(MacroAssembler* masm, |
| 2429 | Token::Value op) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2430 | Register left = r1; |
| 2431 | Register right = r0; |
| 2432 | Register scratch1 = r7; |
| 2433 | Register scratch2 = r9; |
| 2434 | |
| 2435 | ASSERT(right.is(r0)); |
| 2436 | STATIC_ASSERT(kSmiTag == 0); |
| 2437 | |
| 2438 | Label not_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2439 | switch (op) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2440 | case Token::ADD: |
| 2441 | __ add(right, left, Operand(right), SetCC); // Add optimistically. |
| 2442 | __ Ret(vc); |
| 2443 | __ sub(right, right, Operand(left)); // Revert optimistic add. |
| 2444 | break; |
| 2445 | case Token::SUB: |
| 2446 | __ sub(right, left, Operand(right), SetCC); // Subtract optimistically. |
| 2447 | __ Ret(vc); |
| 2448 | __ sub(right, left, Operand(right)); // Revert optimistic subtract. |
| 2449 | break; |
| 2450 | case Token::MUL: |
| 2451 | // Remove tag from one of the operands. This way the multiplication result |
| 2452 | // will be a smi if it fits the smi range. |
| 2453 | __ SmiUntag(ip, right); |
| 2454 | // Do multiplication |
| 2455 | // scratch1 = lower 32 bits of ip * left. |
| 2456 | // scratch2 = higher 32 bits of ip * left. |
| 2457 | __ smull(scratch1, scratch2, left, ip); |
| 2458 | // Check for overflowing the smi range - no overflow if higher 33 bits of |
| 2459 | // the result are identical. |
| 2460 | __ mov(ip, Operand(scratch1, ASR, 31)); |
| 2461 | __ cmp(ip, Operand(scratch2)); |
| 2462 | __ b(ne, ¬_smi_result); |
| 2463 | // Go slow on zero result to handle -0. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2464 | __ cmp(scratch1, Operand::Zero()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2465 | __ mov(right, Operand(scratch1), LeaveCC, ne); |
| 2466 | __ Ret(ne); |
| 2467 | // We need -0 if we were multiplying a negative number with 0 to get 0. |
| 2468 | // We know one of them was zero. |
| 2469 | __ add(scratch2, right, Operand(left), SetCC); |
| 2470 | __ mov(right, Operand(Smi::FromInt(0)), LeaveCC, pl); |
| 2471 | __ Ret(pl); // Return smi 0 if the non-zero one was positive. |
| 2472 | // We fall through here if we multiplied a negative number with 0, because |
| 2473 | // that would mean we should produce -0. |
| 2474 | break; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2475 | case Token::DIV: { |
| 2476 | Label div_with_sdiv; |
| 2477 | |
| 2478 | // Check for 0 divisor. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2479 | __ cmp(right, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2480 | __ b(eq, ¬_smi_result); |
| 2481 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2482 | // Check for power of two on the right hand side. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2483 | __ sub(scratch1, right, Operand(1)); |
| 2484 | __ tst(scratch1, right); |
| 2485 | if (CpuFeatures::IsSupported(SUDIV)) { |
| 2486 | __ b(ne, &div_with_sdiv); |
| 2487 | // Check for no remainder. |
| 2488 | __ tst(left, scratch1); |
| 2489 | __ b(ne, ¬_smi_result); |
| 2490 | // Check for positive left hand side. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2491 | __ cmp(left, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2492 | __ b(mi, &div_with_sdiv); |
| 2493 | } else { |
| 2494 | __ b(ne, ¬_smi_result); |
| 2495 | // Check for positive and no remainder. |
| 2496 | __ orr(scratch2, scratch1, Operand(0x80000000u)); |
| 2497 | __ tst(left, scratch2); |
| 2498 | __ b(ne, ¬_smi_result); |
| 2499 | } |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2500 | |
| 2501 | // Perform division by shifting. |
| 2502 | __ CountLeadingZeros(scratch1, scratch1, scratch2); |
| 2503 | __ rsb(scratch1, scratch1, Operand(31)); |
| 2504 | __ mov(right, Operand(left, LSR, scratch1)); |
| 2505 | __ Ret(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2506 | |
| 2507 | if (CpuFeatures::IsSupported(SUDIV)) { |
| 2508 | Label result_not_zero; |
| 2509 | |
| 2510 | __ bind(&div_with_sdiv); |
| 2511 | // Do division. |
| 2512 | __ sdiv(scratch1, left, right); |
| 2513 | // Check that the remainder is zero. |
| 2514 | __ mls(scratch2, scratch1, right, left); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2515 | __ cmp(scratch2, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2516 | __ b(ne, ¬_smi_result); |
| 2517 | // Check for negative zero result. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2518 | __ cmp(scratch1, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2519 | __ b(ne, &result_not_zero); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2520 | __ cmp(right, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2521 | __ b(lt, ¬_smi_result); |
| 2522 | __ bind(&result_not_zero); |
| 2523 | // Check for the corner case of dividing the most negative smi by -1. |
| 2524 | __ cmp(scratch1, Operand(0x40000000)); |
| 2525 | __ b(eq, ¬_smi_result); |
| 2526 | // Tag and return the result. |
| 2527 | __ SmiTag(right, scratch1); |
| 2528 | __ Ret(); |
| 2529 | } |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2530 | break; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2531 | } |
| 2532 | case Token::MOD: { |
| 2533 | Label modulo_with_sdiv; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2534 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2535 | if (CpuFeatures::IsSupported(SUDIV)) { |
| 2536 | // Check for x % 0. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2537 | __ cmp(right, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2538 | __ b(eq, ¬_smi_result); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2539 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2540 | // Check for two positive smis. |
| 2541 | __ orr(scratch1, left, Operand(right)); |
| 2542 | __ tst(scratch1, Operand(0x80000000u)); |
| 2543 | __ b(ne, &modulo_with_sdiv); |
| 2544 | |
| 2545 | // Check for power of two on the right hand side. |
| 2546 | __ sub(scratch1, right, Operand(1)); |
| 2547 | __ tst(scratch1, right); |
| 2548 | __ b(ne, &modulo_with_sdiv); |
| 2549 | } else { |
| 2550 | // Check for two positive smis. |
| 2551 | __ orr(scratch1, left, Operand(right)); |
| 2552 | __ tst(scratch1, Operand(0x80000000u)); |
| 2553 | __ b(ne, ¬_smi_result); |
| 2554 | |
| 2555 | // Check for power of two on the right hand side. |
| 2556 | __ JumpIfNotPowerOfTwoOrZero(right, scratch1, ¬_smi_result); |
| 2557 | } |
| 2558 | |
| 2559 | // Perform modulus by masking (scratch1 contains right - 1). |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2560 | __ and_(right, left, Operand(scratch1)); |
| 2561 | __ Ret(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2562 | |
| 2563 | if (CpuFeatures::IsSupported(SUDIV)) { |
| 2564 | __ bind(&modulo_with_sdiv); |
| 2565 | __ mov(scratch2, right); |
| 2566 | // Perform modulus with sdiv and mls. |
| 2567 | __ sdiv(scratch1, left, right); |
| 2568 | __ mls(right, scratch1, right, left); |
| 2569 | // Return if the result is not 0. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2570 | __ cmp(right, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2571 | __ Ret(ne); |
| 2572 | // The result is 0, check for -0 case. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2573 | __ cmp(left, Operand::Zero()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2574 | __ Ret(pl); |
| 2575 | // This is a -0 case, restore the value of right. |
| 2576 | __ mov(right, scratch2); |
| 2577 | // We fall through here to not_smi_result to produce -0. |
| 2578 | } |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2579 | break; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2580 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2581 | case Token::BIT_OR: |
| 2582 | __ orr(right, left, Operand(right)); |
| 2583 | __ Ret(); |
| 2584 | break; |
| 2585 | case Token::BIT_AND: |
| 2586 | __ and_(right, left, Operand(right)); |
| 2587 | __ Ret(); |
| 2588 | break; |
| 2589 | case Token::BIT_XOR: |
| 2590 | __ eor(right, left, Operand(right)); |
| 2591 | __ Ret(); |
| 2592 | break; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2593 | case Token::SAR: |
| 2594 | // Remove tags from right operand. |
| 2595 | __ GetLeastBitsFromSmi(scratch1, right, 5); |
| 2596 | __ mov(right, Operand(left, ASR, scratch1)); |
| 2597 | // Smi tag result. |
| 2598 | __ bic(right, right, Operand(kSmiTagMask)); |
| 2599 | __ Ret(); |
| 2600 | break; |
| 2601 | case Token::SHR: |
| 2602 | // Remove tags from operands. We can't do this on a 31 bit number |
| 2603 | // because then the 0s get shifted into bit 30 instead of bit 31. |
| 2604 | __ SmiUntag(scratch1, left); |
| 2605 | __ GetLeastBitsFromSmi(scratch2, right, 5); |
| 2606 | __ mov(scratch1, Operand(scratch1, LSR, scratch2)); |
| 2607 | // Unsigned shift is not allowed to produce a negative number, so |
| 2608 | // check the sign bit and the sign bit after Smi tagging. |
| 2609 | __ tst(scratch1, Operand(0xc0000000)); |
| 2610 | __ b(ne, ¬_smi_result); |
| 2611 | // Smi tag result. |
| 2612 | __ SmiTag(right, scratch1); |
| 2613 | __ Ret(); |
| 2614 | break; |
| 2615 | case Token::SHL: |
| 2616 | // Remove tags from operands. |
| 2617 | __ SmiUntag(scratch1, left); |
| 2618 | __ GetLeastBitsFromSmi(scratch2, right, 5); |
| 2619 | __ mov(scratch1, Operand(scratch1, LSL, scratch2)); |
| 2620 | // Check that the signed result fits in a Smi. |
| 2621 | __ add(scratch2, scratch1, Operand(0x40000000), SetCC); |
| 2622 | __ b(mi, ¬_smi_result); |
| 2623 | __ SmiTag(right, scratch1); |
| 2624 | __ Ret(); |
| 2625 | break; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2626 | default: |
| 2627 | UNREACHABLE(); |
| 2628 | } |
| 2629 | __ bind(¬_smi_result); |
| 2630 | } |
| 2631 | |
| 2632 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2633 | void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 2634 | Register result, |
| 2635 | Register heap_number_map, |
| 2636 | Register scratch1, |
| 2637 | Register scratch2, |
| 2638 | Label* gc_required, |
| 2639 | OverwriteMode mode); |
| 2640 | |
| 2641 | |
| 2642 | void BinaryOpStub_GenerateFPOperation(MacroAssembler* masm, |
| 2643 | BinaryOpIC::TypeInfo left_type, |
| 2644 | BinaryOpIC::TypeInfo right_type, |
| 2645 | bool smi_operands, |
| 2646 | Label* not_numbers, |
| 2647 | Label* gc_required, |
| 2648 | Label* miss, |
| 2649 | Token::Value op, |
| 2650 | OverwriteMode mode) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2651 | Register left = r1; |
| 2652 | Register right = r0; |
| 2653 | Register scratch1 = r7; |
| 2654 | Register scratch2 = r9; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2655 | Register scratch3 = r4; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2656 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2657 | ASSERT(smi_operands || (not_numbers != NULL)); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2658 | if (smi_operands) { |
| 2659 | __ AssertSmi(left); |
| 2660 | __ AssertSmi(right); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2661 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2662 | if (left_type == BinaryOpIC::SMI) { |
| 2663 | __ JumpIfNotSmi(left, miss); |
| 2664 | } |
| 2665 | if (right_type == BinaryOpIC::SMI) { |
| 2666 | __ JumpIfNotSmi(right, miss); |
| 2667 | } |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2668 | |
| 2669 | Register heap_number_map = r6; |
| 2670 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2671 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2672 | switch (op) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2673 | case Token::ADD: |
| 2674 | case Token::SUB: |
| 2675 | case Token::MUL: |
| 2676 | case Token::DIV: |
| 2677 | case Token::MOD: { |
| 2678 | // Load left and right operands into d6 and d7 or r0/r1 and r2/r3 |
| 2679 | // depending on whether VFP3 is available or not. |
| 2680 | FloatingPointHelper::Destination destination = |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 2681 | CpuFeatures::IsSupported(VFP2) && |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2682 | op != Token::MOD ? |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2683 | FloatingPointHelper::kVFPRegisters : |
| 2684 | FloatingPointHelper::kCoreRegisters; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2685 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2686 | // Allocate new heap number for result. |
| 2687 | Register result = r5; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2688 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2689 | masm, result, heap_number_map, scratch1, scratch2, gc_required, mode); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2690 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2691 | // Load the operands. |
| 2692 | if (smi_operands) { |
| 2693 | FloatingPointHelper::LoadSmis(masm, destination, scratch1, scratch2); |
| 2694 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2695 | // Load right operand to d7 or r2/r3. |
| 2696 | if (right_type == BinaryOpIC::INT32) { |
| 2697 | FloatingPointHelper::LoadNumberAsInt32Double( |
| 2698 | masm, right, destination, d7, d8, r2, r3, heap_number_map, |
| 2699 | scratch1, scratch2, s0, miss); |
| 2700 | } else { |
| 2701 | Label* fail = (right_type == BinaryOpIC::HEAP_NUMBER) ? miss |
| 2702 | : not_numbers; |
| 2703 | FloatingPointHelper::LoadNumber( |
| 2704 | masm, destination, right, d7, r2, r3, heap_number_map, |
| 2705 | scratch1, scratch2, fail); |
| 2706 | } |
| 2707 | // Load left operand to d6 or r0/r1. This keeps r0/r1 intact if it |
| 2708 | // jumps to |miss|. |
| 2709 | if (left_type == BinaryOpIC::INT32) { |
| 2710 | FloatingPointHelper::LoadNumberAsInt32Double( |
| 2711 | masm, left, destination, d6, d8, r0, r1, heap_number_map, |
| 2712 | scratch1, scratch2, s0, miss); |
| 2713 | } else { |
| 2714 | Label* fail = (left_type == BinaryOpIC::HEAP_NUMBER) ? miss |
| 2715 | : not_numbers; |
| 2716 | FloatingPointHelper::LoadNumber( |
| 2717 | masm, destination, left, d6, r0, r1, heap_number_map, |
| 2718 | scratch1, scratch2, fail); |
| 2719 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2720 | } |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2721 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2722 | // Calculate the result. |
| 2723 | if (destination == FloatingPointHelper::kVFPRegisters) { |
| 2724 | // Using VFP registers: |
| 2725 | // d6: Left value |
| 2726 | // d7: Right value |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 2727 | CpuFeatures::Scope scope(VFP2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2728 | switch (op) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2729 | case Token::ADD: |
| 2730 | __ vadd(d5, d6, d7); |
| 2731 | break; |
| 2732 | case Token::SUB: |
| 2733 | __ vsub(d5, d6, d7); |
| 2734 | break; |
| 2735 | case Token::MUL: |
| 2736 | __ vmul(d5, d6, d7); |
| 2737 | break; |
| 2738 | case Token::DIV: |
| 2739 | __ vdiv(d5, d6, d7); |
| 2740 | break; |
| 2741 | default: |
| 2742 | UNREACHABLE(); |
| 2743 | } |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2744 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2745 | __ sub(r0, result, Operand(kHeapObjectTag)); |
| 2746 | __ vstr(d5, r0, HeapNumber::kValueOffset); |
| 2747 | __ add(r0, r0, Operand(kHeapObjectTag)); |
| 2748 | __ Ret(); |
| 2749 | } else { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2750 | // Call the C function to handle the double operation. |
| 2751 | FloatingPointHelper::CallCCodeForDoubleOperation(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2752 | op, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2753 | result, |
| 2754 | scratch1); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2755 | if (FLAG_debug_code) { |
| 2756 | __ stop("Unreachable code."); |
| 2757 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2758 | } |
| 2759 | break; |
| 2760 | } |
| 2761 | case Token::BIT_OR: |
| 2762 | case Token::BIT_XOR: |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2763 | case Token::BIT_AND: |
| 2764 | case Token::SAR: |
| 2765 | case Token::SHR: |
| 2766 | case Token::SHL: { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2767 | if (smi_operands) { |
| 2768 | __ SmiUntag(r3, left); |
| 2769 | __ SmiUntag(r2, right); |
| 2770 | } else { |
| 2771 | // Convert operands to 32-bit integers. Right in r2 and left in r3. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2772 | FloatingPointHelper::ConvertNumberToInt32(masm, |
| 2773 | left, |
| 2774 | r3, |
| 2775 | heap_number_map, |
| 2776 | scratch1, |
| 2777 | scratch2, |
| 2778 | scratch3, |
| 2779 | d0, |
| 2780 | not_numbers); |
| 2781 | FloatingPointHelper::ConvertNumberToInt32(masm, |
| 2782 | right, |
| 2783 | r2, |
| 2784 | heap_number_map, |
| 2785 | scratch1, |
| 2786 | scratch2, |
| 2787 | scratch3, |
| 2788 | d0, |
| 2789 | not_numbers); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2790 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2791 | |
| 2792 | Label result_not_a_smi; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2793 | switch (op) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2794 | case Token::BIT_OR: |
| 2795 | __ orr(r2, r3, Operand(r2)); |
| 2796 | break; |
| 2797 | case Token::BIT_XOR: |
| 2798 | __ eor(r2, r3, Operand(r2)); |
| 2799 | break; |
| 2800 | case Token::BIT_AND: |
| 2801 | __ and_(r2, r3, Operand(r2)); |
| 2802 | break; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2803 | case Token::SAR: |
| 2804 | // Use only the 5 least significant bits of the shift count. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2805 | __ GetLeastBitsFromInt32(r2, r2, 5); |
| 2806 | __ mov(r2, Operand(r3, ASR, r2)); |
| 2807 | break; |
| 2808 | case Token::SHR: |
| 2809 | // Use only the 5 least significant bits of the shift count. |
| 2810 | __ GetLeastBitsFromInt32(r2, r2, 5); |
| 2811 | __ mov(r2, Operand(r3, LSR, r2), SetCC); |
| 2812 | // SHR is special because it is required to produce a positive answer. |
| 2813 | // The code below for writing into heap numbers isn't capable of |
| 2814 | // writing the register as an unsigned int so we go to slow case if we |
| 2815 | // hit this case. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 2816 | if (CpuFeatures::IsSupported(VFP2)) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2817 | __ b(mi, &result_not_a_smi); |
| 2818 | } else { |
| 2819 | __ b(mi, not_numbers); |
| 2820 | } |
| 2821 | break; |
| 2822 | case Token::SHL: |
| 2823 | // Use only the 5 least significant bits of the shift count. |
| 2824 | __ GetLeastBitsFromInt32(r2, r2, 5); |
| 2825 | __ mov(r2, Operand(r3, LSL, r2)); |
| 2826 | break; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2827 | default: |
| 2828 | UNREACHABLE(); |
| 2829 | } |
| 2830 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2831 | // Check that the *signed* result fits in a smi. |
| 2832 | __ add(r3, r2, Operand(0x40000000), SetCC); |
| 2833 | __ b(mi, &result_not_a_smi); |
| 2834 | __ SmiTag(r0, r2); |
| 2835 | __ Ret(); |
| 2836 | |
| 2837 | // Allocate new heap number for result. |
| 2838 | __ bind(&result_not_a_smi); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2839 | Register result = r5; |
| 2840 | if (smi_operands) { |
| 2841 | __ AllocateHeapNumber( |
| 2842 | result, scratch1, scratch2, heap_number_map, gc_required); |
| 2843 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2844 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2845 | masm, result, heap_number_map, scratch1, scratch2, gc_required, |
| 2846 | mode); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2847 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2848 | |
| 2849 | // r2: Answer as signed int32. |
| 2850 | // r5: Heap number to write answer into. |
| 2851 | |
| 2852 | // Nothing can go wrong now, so move the heap number to r0, which is the |
| 2853 | // result. |
| 2854 | __ mov(r0, Operand(r5)); |
| 2855 | |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 2856 | if (CpuFeatures::IsSupported(VFP2)) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2857 | // Convert the int32 in r2 to the heap number in r0. r3 is corrupted. As |
| 2858 | // mentioned above SHR needs to always produce a positive result. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 2859 | CpuFeatures::Scope scope(VFP2); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2860 | __ vmov(s0, r2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2861 | if (op == Token::SHR) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2862 | __ vcvt_f64_u32(d0, s0); |
| 2863 | } else { |
| 2864 | __ vcvt_f64_s32(d0, s0); |
| 2865 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2866 | __ sub(r3, r0, Operand(kHeapObjectTag)); |
| 2867 | __ vstr(d0, r3, HeapNumber::kValueOffset); |
| 2868 | __ Ret(); |
| 2869 | } else { |
| 2870 | // Tail call that writes the int32 in r2 to the heap number in r0, using |
| 2871 | // r3 as scratch. r0 is preserved and returned. |
| 2872 | WriteInt32ToHeapNumberStub stub(r2, r0, r3); |
| 2873 | __ TailCallStub(&stub); |
| 2874 | } |
| 2875 | break; |
| 2876 | } |
| 2877 | default: |
| 2878 | UNREACHABLE(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2879 | } |
| 2880 | } |
| 2881 | |
| 2882 | |
| 2883 | // Generate the smi code. If the operation on smis are successful this return is |
| 2884 | // generated. If the result is not a smi and heap number allocation is not |
| 2885 | // requested the code falls through. If number allocation is requested but a |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2886 | // heap number cannot be allocated the code jumps to the label gc_required. |
| 2887 | void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2888 | MacroAssembler* masm, |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2889 | Label* use_runtime, |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2890 | Label* gc_required, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2891 | Token::Value op, |
| 2892 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 2893 | OverwriteMode mode) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2894 | Label not_smis; |
| 2895 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2896 | Register left = r1; |
| 2897 | Register right = r0; |
| 2898 | Register scratch1 = r7; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2899 | |
| 2900 | // Perform combined smi check on both operands. |
| 2901 | __ orr(scratch1, left, Operand(right)); |
| 2902 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2903 | __ JumpIfNotSmi(scratch1, ¬_smis); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2904 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2905 | // If the smi-smi operation results in a smi return is generated. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2906 | BinaryOpStub_GenerateSmiSmiOperation(masm, op); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2907 | |
| 2908 | // If heap number results are possible generate the result in an allocated |
| 2909 | // heap number. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2910 | if (allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS) { |
| 2911 | BinaryOpStub_GenerateFPOperation( |
| 2912 | masm, BinaryOpIC::UNINITIALIZED, BinaryOpIC::UNINITIALIZED, true, |
| 2913 | use_runtime, gc_required, ¬_smis, op, mode); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2914 | } |
| 2915 | __ bind(¬_smis); |
| 2916 | } |
| 2917 | |
| 2918 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2919 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2920 | Label not_smis, call_runtime; |
| 2921 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2922 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 2923 | result_type_ == BinaryOpIC::SMI) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2924 | // Only allow smi results. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2925 | BinaryOpStub_GenerateSmiCode( |
| 2926 | masm, &call_runtime, NULL, op_, NO_HEAPNUMBER_RESULTS, mode_); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2927 | } else { |
| 2928 | // Allow heap number result and don't make a transition if a heap number |
| 2929 | // cannot be allocated. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2930 | BinaryOpStub_GenerateSmiCode( |
| 2931 | masm, &call_runtime, &call_runtime, op_, ALLOW_HEAPNUMBER_RESULTS, |
| 2932 | mode_); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | // Code falls through if the result is not returned as either a smi or heap |
| 2936 | // number. |
| 2937 | GenerateTypeTransition(masm); |
| 2938 | |
| 2939 | __ bind(&call_runtime); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2940 | GenerateRegisterArgsPush(masm); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2941 | GenerateCallRuntime(masm); |
| 2942 | } |
| 2943 | |
| 2944 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2945 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2946 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2947 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2948 | ASSERT(op_ == Token::ADD); |
| 2949 | // If both arguments are strings, call the string add stub. |
| 2950 | // Otherwise, do a transition. |
| 2951 | |
| 2952 | // Registers containing left and right operands respectively. |
| 2953 | Register left = r1; |
| 2954 | Register right = r0; |
| 2955 | |
| 2956 | // Test if left operand is a string. |
| 2957 | __ JumpIfSmi(left, &call_runtime); |
| 2958 | __ CompareObjectType(left, r2, r2, FIRST_NONSTRING_TYPE); |
| 2959 | __ b(ge, &call_runtime); |
| 2960 | |
| 2961 | // Test if right operand is a string. |
| 2962 | __ JumpIfSmi(right, &call_runtime); |
| 2963 | __ CompareObjectType(right, r2, r2, FIRST_NONSTRING_TYPE); |
| 2964 | __ b(ge, &call_runtime); |
| 2965 | |
| 2966 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 2967 | GenerateRegisterArgsPush(masm); |
| 2968 | __ TailCallStub(&string_add_stub); |
| 2969 | |
| 2970 | __ bind(&call_runtime); |
| 2971 | GenerateTypeTransition(masm); |
| 2972 | } |
| 2973 | |
| 2974 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2975 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2976 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2977 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2978 | Register left = r1; |
| 2979 | Register right = r0; |
| 2980 | Register scratch1 = r7; |
| 2981 | Register scratch2 = r9; |
| 2982 | DwVfpRegister double_scratch = d0; |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2983 | |
| 2984 | Register heap_number_result = no_reg; |
| 2985 | Register heap_number_map = r6; |
| 2986 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2987 | |
| 2988 | Label call_runtime; |
| 2989 | // Labels for type transition, used for wrong input or output types. |
| 2990 | // Both label are currently actually bound to the same position. We use two |
| 2991 | // different label to differentiate the cause leading to type transition. |
| 2992 | Label transition; |
| 2993 | |
| 2994 | // Smi-smi fast case. |
| 2995 | Label skip; |
| 2996 | __ orr(scratch1, left, right); |
| 2997 | __ JumpIfNotSmi(scratch1, &skip); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2998 | BinaryOpStub_GenerateSmiSmiOperation(masm, op_); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2999 | // Fall through if the result is not a smi. |
| 3000 | __ bind(&skip); |
| 3001 | |
| 3002 | switch (op_) { |
| 3003 | case Token::ADD: |
| 3004 | case Token::SUB: |
| 3005 | case Token::MUL: |
| 3006 | case Token::DIV: |
| 3007 | case Token::MOD: { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3008 | // It could be that only SMIs have been seen at either the left |
| 3009 | // or the right operand. For precise type feedback, patch the IC |
| 3010 | // again if this changes. |
| 3011 | if (left_type_ == BinaryOpIC::SMI) { |
| 3012 | __ JumpIfNotSmi(left, &transition); |
| 3013 | } |
| 3014 | if (right_type_ == BinaryOpIC::SMI) { |
| 3015 | __ JumpIfNotSmi(right, &transition); |
| 3016 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3017 | // Load both operands and check that they are 32-bit integer. |
| 3018 | // Jump to type transition if they are not. The registers r0 and r1 (right |
| 3019 | // and left) are preserved for the runtime call. |
| 3020 | FloatingPointHelper::Destination destination = |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3021 | (CpuFeatures::IsSupported(VFP2) && op_ != Token::MOD) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3022 | ? FloatingPointHelper::kVFPRegisters |
| 3023 | : FloatingPointHelper::kCoreRegisters; |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3024 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3025 | FloatingPointHelper::LoadNumberAsInt32Double(masm, |
| 3026 | right, |
| 3027 | destination, |
| 3028 | d7, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3029 | d8, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3030 | r2, |
| 3031 | r3, |
| 3032 | heap_number_map, |
| 3033 | scratch1, |
| 3034 | scratch2, |
| 3035 | s0, |
| 3036 | &transition); |
| 3037 | FloatingPointHelper::LoadNumberAsInt32Double(masm, |
| 3038 | left, |
| 3039 | destination, |
| 3040 | d6, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3041 | d8, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3042 | r4, |
| 3043 | r5, |
| 3044 | heap_number_map, |
| 3045 | scratch1, |
| 3046 | scratch2, |
| 3047 | s0, |
| 3048 | &transition); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3049 | |
| 3050 | if (destination == FloatingPointHelper::kVFPRegisters) { |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3051 | CpuFeatures::Scope scope(VFP2); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3052 | Label return_heap_number; |
| 3053 | switch (op_) { |
| 3054 | case Token::ADD: |
| 3055 | __ vadd(d5, d6, d7); |
| 3056 | break; |
| 3057 | case Token::SUB: |
| 3058 | __ vsub(d5, d6, d7); |
| 3059 | break; |
| 3060 | case Token::MUL: |
| 3061 | __ vmul(d5, d6, d7); |
| 3062 | break; |
| 3063 | case Token::DIV: |
| 3064 | __ vdiv(d5, d6, d7); |
| 3065 | break; |
| 3066 | default: |
| 3067 | UNREACHABLE(); |
| 3068 | } |
| 3069 | |
| 3070 | if (op_ != Token::DIV) { |
| 3071 | // These operations produce an integer result. |
| 3072 | // Try to return a smi if we can. |
| 3073 | // Otherwise return a heap number if allowed, or jump to type |
| 3074 | // transition. |
| 3075 | |
| 3076 | __ EmitVFPTruncate(kRoundToZero, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3077 | scratch1, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3078 | d5, |
| 3079 | scratch2, |
| 3080 | d8); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3081 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3082 | if (result_type_ <= BinaryOpIC::INT32) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3083 | // If the ne condition is set, result does |
| 3084 | // not fit in a 32-bit integer. |
| 3085 | __ b(ne, &transition); |
| 3086 | } |
| 3087 | |
| 3088 | // Check if the result fits in a smi. |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3089 | __ add(scratch2, scratch1, Operand(0x40000000), SetCC); |
| 3090 | // If not try to return a heap number. |
| 3091 | __ b(mi, &return_heap_number); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3092 | // Check for minus zero. Return heap number for minus zero. |
| 3093 | Label not_zero; |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3094 | __ cmp(scratch1, Operand::Zero()); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3095 | __ b(ne, ¬_zero); |
| 3096 | __ vmov(scratch2, d5.high()); |
| 3097 | __ tst(scratch2, Operand(HeapNumber::kSignMask)); |
| 3098 | __ b(ne, &return_heap_number); |
| 3099 | __ bind(¬_zero); |
| 3100 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3101 | // Tag the result and return. |
| 3102 | __ SmiTag(r0, scratch1); |
| 3103 | __ Ret(); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3104 | } else { |
| 3105 | // DIV just falls through to allocating a heap number. |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3106 | } |
| 3107 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3108 | __ bind(&return_heap_number); |
| 3109 | // Return a heap number, or fall through to type transition or runtime |
| 3110 | // call if we can't. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3111 | if (result_type_ >= ((op_ == Token::DIV) ? BinaryOpIC::HEAP_NUMBER |
| 3112 | : BinaryOpIC::INT32)) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3113 | // We are using vfp registers so r5 is available. |
| 3114 | heap_number_result = r5; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3115 | BinaryOpStub_GenerateHeapResultAllocation(masm, |
| 3116 | heap_number_result, |
| 3117 | heap_number_map, |
| 3118 | scratch1, |
| 3119 | scratch2, |
| 3120 | &call_runtime, |
| 3121 | mode_); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3122 | __ sub(r0, heap_number_result, Operand(kHeapObjectTag)); |
| 3123 | __ vstr(d5, r0, HeapNumber::kValueOffset); |
| 3124 | __ mov(r0, heap_number_result); |
| 3125 | __ Ret(); |
| 3126 | } |
| 3127 | |
| 3128 | // A DIV operation expecting an integer result falls through |
| 3129 | // to type transition. |
| 3130 | |
| 3131 | } else { |
| 3132 | // We preserved r0 and r1 to be able to call runtime. |
| 3133 | // Save the left value on the stack. |
| 3134 | __ Push(r5, r4); |
| 3135 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3136 | Label pop_and_call_runtime; |
| 3137 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3138 | // Allocate a heap number to store the result. |
| 3139 | heap_number_result = r5; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3140 | BinaryOpStub_GenerateHeapResultAllocation(masm, |
| 3141 | heap_number_result, |
| 3142 | heap_number_map, |
| 3143 | scratch1, |
| 3144 | scratch2, |
| 3145 | &pop_and_call_runtime, |
| 3146 | mode_); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3147 | |
| 3148 | // Load the left value from the value saved on the stack. |
| 3149 | __ Pop(r1, r0); |
| 3150 | |
| 3151 | // Call the C function to handle the double operation. |
| 3152 | FloatingPointHelper::CallCCodeForDoubleOperation( |
| 3153 | masm, op_, heap_number_result, scratch1); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3154 | if (FLAG_debug_code) { |
| 3155 | __ stop("Unreachable code."); |
| 3156 | } |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3157 | |
| 3158 | __ bind(&pop_and_call_runtime); |
| 3159 | __ Drop(2); |
| 3160 | __ b(&call_runtime); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | break; |
| 3164 | } |
| 3165 | |
| 3166 | case Token::BIT_OR: |
| 3167 | case Token::BIT_XOR: |
| 3168 | case Token::BIT_AND: |
| 3169 | case Token::SAR: |
| 3170 | case Token::SHR: |
| 3171 | case Token::SHL: { |
| 3172 | Label return_heap_number; |
| 3173 | Register scratch3 = r5; |
| 3174 | // Convert operands to 32-bit integers. Right in r2 and left in r3. The |
| 3175 | // registers r0 and r1 (right and left) are preserved for the runtime |
| 3176 | // call. |
| 3177 | FloatingPointHelper::LoadNumberAsInt32(masm, |
| 3178 | left, |
| 3179 | r3, |
| 3180 | heap_number_map, |
| 3181 | scratch1, |
| 3182 | scratch2, |
| 3183 | scratch3, |
| 3184 | d0, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3185 | d1, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3186 | &transition); |
| 3187 | FloatingPointHelper::LoadNumberAsInt32(masm, |
| 3188 | right, |
| 3189 | r2, |
| 3190 | heap_number_map, |
| 3191 | scratch1, |
| 3192 | scratch2, |
| 3193 | scratch3, |
| 3194 | d0, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3195 | d1, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3196 | &transition); |
| 3197 | |
| 3198 | // The ECMA-262 standard specifies that, for shift operations, only the |
| 3199 | // 5 least significant bits of the shift value should be used. |
| 3200 | switch (op_) { |
| 3201 | case Token::BIT_OR: |
| 3202 | __ orr(r2, r3, Operand(r2)); |
| 3203 | break; |
| 3204 | case Token::BIT_XOR: |
| 3205 | __ eor(r2, r3, Operand(r2)); |
| 3206 | break; |
| 3207 | case Token::BIT_AND: |
| 3208 | __ and_(r2, r3, Operand(r2)); |
| 3209 | break; |
| 3210 | case Token::SAR: |
| 3211 | __ and_(r2, r2, Operand(0x1f)); |
| 3212 | __ mov(r2, Operand(r3, ASR, r2)); |
| 3213 | break; |
| 3214 | case Token::SHR: |
| 3215 | __ and_(r2, r2, Operand(0x1f)); |
| 3216 | __ mov(r2, Operand(r3, LSR, r2), SetCC); |
| 3217 | // SHR is special because it is required to produce a positive answer. |
| 3218 | // We only get a negative result if the shift value (r2) is 0. |
| 3219 | // This result cannot be respresented as a signed 32-bit integer, try |
| 3220 | // to return a heap number if we can. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3221 | // The non vfp2 code does not support this special case, so jump to |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3222 | // runtime if we don't support it. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3223 | if (CpuFeatures::IsSupported(VFP2)) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3224 | __ b(mi, (result_type_ <= BinaryOpIC::INT32) |
| 3225 | ? &transition |
| 3226 | : &return_heap_number); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3227 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3228 | __ b(mi, (result_type_ <= BinaryOpIC::INT32) |
| 3229 | ? &transition |
| 3230 | : &call_runtime); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3231 | } |
| 3232 | break; |
| 3233 | case Token::SHL: |
| 3234 | __ and_(r2, r2, Operand(0x1f)); |
| 3235 | __ mov(r2, Operand(r3, LSL, r2)); |
| 3236 | break; |
| 3237 | default: |
| 3238 | UNREACHABLE(); |
| 3239 | } |
| 3240 | |
| 3241 | // Check if the result fits in a smi. |
| 3242 | __ add(scratch1, r2, Operand(0x40000000), SetCC); |
| 3243 | // If not try to return a heap number. (We know the result is an int32.) |
| 3244 | __ b(mi, &return_heap_number); |
| 3245 | // Tag the result and return. |
| 3246 | __ SmiTag(r0, r2); |
| 3247 | __ Ret(); |
| 3248 | |
| 3249 | __ bind(&return_heap_number); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3250 | heap_number_result = r5; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3251 | BinaryOpStub_GenerateHeapResultAllocation(masm, |
| 3252 | heap_number_result, |
| 3253 | heap_number_map, |
| 3254 | scratch1, |
| 3255 | scratch2, |
| 3256 | &call_runtime, |
| 3257 | mode_); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3258 | |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3259 | if (CpuFeatures::IsSupported(VFP2)) { |
| 3260 | CpuFeatures::Scope scope(VFP2); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3261 | if (op_ != Token::SHR) { |
| 3262 | // Convert the result to a floating point value. |
| 3263 | __ vmov(double_scratch.low(), r2); |
| 3264 | __ vcvt_f64_s32(double_scratch, double_scratch.low()); |
| 3265 | } else { |
| 3266 | // The result must be interpreted as an unsigned 32-bit integer. |
| 3267 | __ vmov(double_scratch.low(), r2); |
| 3268 | __ vcvt_f64_u32(double_scratch, double_scratch.low()); |
| 3269 | } |
| 3270 | |
| 3271 | // Store the result. |
| 3272 | __ sub(r0, heap_number_result, Operand(kHeapObjectTag)); |
| 3273 | __ vstr(double_scratch, r0, HeapNumber::kValueOffset); |
| 3274 | __ mov(r0, heap_number_result); |
| 3275 | __ Ret(); |
| 3276 | } else { |
| 3277 | // Tail call that writes the int32 in r2 to the heap number in r0, using |
| 3278 | // r3 as scratch. r0 is preserved and returned. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3279 | __ mov(r0, r5); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3280 | WriteInt32ToHeapNumberStub stub(r2, r0, r3); |
| 3281 | __ TailCallStub(&stub); |
| 3282 | } |
| 3283 | |
| 3284 | break; |
| 3285 | } |
| 3286 | |
| 3287 | default: |
| 3288 | UNREACHABLE(); |
| 3289 | } |
| 3290 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3291 | // We never expect DIV to yield an integer result, so we always generate |
| 3292 | // type transition code for DIV operations expecting an integer result: the |
| 3293 | // code will fall through to this type transition. |
| 3294 | if (transition.is_linked() || |
| 3295 | ((op_ == Token::DIV) && (result_type_ <= BinaryOpIC::INT32))) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3296 | __ bind(&transition); |
| 3297 | GenerateTypeTransition(masm); |
| 3298 | } |
| 3299 | |
| 3300 | __ bind(&call_runtime); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3301 | GenerateRegisterArgsPush(masm); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3302 | GenerateCallRuntime(masm); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3303 | } |
| 3304 | |
| 3305 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3306 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3307 | Label call_runtime; |
| 3308 | |
| 3309 | if (op_ == Token::ADD) { |
| 3310 | // Handle string addition here, because it is the only operation |
| 3311 | // that does not do a ToNumber conversion on the operands. |
| 3312 | GenerateAddStrings(masm); |
| 3313 | } |
| 3314 | |
| 3315 | // Convert oddball arguments to numbers. |
| 3316 | Label check, done; |
| 3317 | __ CompareRoot(r1, Heap::kUndefinedValueRootIndex); |
| 3318 | __ b(ne, &check); |
| 3319 | if (Token::IsBitOp(op_)) { |
| 3320 | __ mov(r1, Operand(Smi::FromInt(0))); |
| 3321 | } else { |
| 3322 | __ LoadRoot(r1, Heap::kNanValueRootIndex); |
| 3323 | } |
| 3324 | __ jmp(&done); |
| 3325 | __ bind(&check); |
| 3326 | __ CompareRoot(r0, Heap::kUndefinedValueRootIndex); |
| 3327 | __ b(ne, &done); |
| 3328 | if (Token::IsBitOp(op_)) { |
| 3329 | __ mov(r0, Operand(Smi::FromInt(0))); |
| 3330 | } else { |
| 3331 | __ LoadRoot(r0, Heap::kNanValueRootIndex); |
| 3332 | } |
| 3333 | __ bind(&done); |
| 3334 | |
| 3335 | GenerateHeapNumberStub(masm); |
| 3336 | } |
| 3337 | |
| 3338 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3339 | void BinaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3340 | Label call_runtime, transition; |
| 3341 | BinaryOpStub_GenerateFPOperation( |
| 3342 | masm, left_type_, right_type_, false, |
| 3343 | &transition, &call_runtime, &transition, op_, mode_); |
| 3344 | |
| 3345 | __ bind(&transition); |
| 3346 | GenerateTypeTransition(masm); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3347 | |
| 3348 | __ bind(&call_runtime); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3349 | GenerateRegisterArgsPush(masm); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3350 | GenerateCallRuntime(masm); |
| 3351 | } |
| 3352 | |
| 3353 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3354 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3355 | Label call_runtime, call_string_add_or_runtime, transition; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3356 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3357 | BinaryOpStub_GenerateSmiCode( |
| 3358 | masm, &call_runtime, &call_runtime, op_, ALLOW_HEAPNUMBER_RESULTS, mode_); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3359 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3360 | BinaryOpStub_GenerateFPOperation( |
| 3361 | masm, left_type_, right_type_, false, |
| 3362 | &call_string_add_or_runtime, &call_runtime, &transition, op_, mode_); |
| 3363 | |
| 3364 | __ bind(&transition); |
| 3365 | GenerateTypeTransition(masm); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3366 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3367 | __ bind(&call_string_add_or_runtime); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3368 | if (op_ == Token::ADD) { |
| 3369 | GenerateAddStrings(masm); |
| 3370 | } |
| 3371 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3372 | __ bind(&call_runtime); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3373 | GenerateRegisterArgsPush(masm); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3374 | GenerateCallRuntime(masm); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3378 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3379 | ASSERT(op_ == Token::ADD); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3380 | Label left_not_string, call_runtime; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3381 | |
| 3382 | Register left = r1; |
| 3383 | Register right = r0; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3384 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3385 | // Check if left argument is a string. |
| 3386 | __ JumpIfSmi(left, &left_not_string); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3387 | __ CompareObjectType(left, r2, r2, FIRST_NONSTRING_TYPE); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3388 | __ b(ge, &left_not_string); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3389 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3390 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 3391 | GenerateRegisterArgsPush(masm); |
| 3392 | __ TailCallStub(&string_add_left_stub); |
| 3393 | |
| 3394 | // Left operand is not a string, test right. |
| 3395 | __ bind(&left_not_string); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3396 | __ JumpIfSmi(right, &call_runtime); |
| 3397 | __ CompareObjectType(right, r2, r2, FIRST_NONSTRING_TYPE); |
| 3398 | __ b(ge, &call_runtime); |
| 3399 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3400 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3401 | GenerateRegisterArgsPush(masm); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3402 | __ TailCallStub(&string_add_right_stub); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3403 | |
| 3404 | // At least one argument is not a string. |
| 3405 | __ bind(&call_runtime); |
| 3406 | } |
| 3407 | |
| 3408 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3409 | void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 3410 | Register result, |
| 3411 | Register heap_number_map, |
| 3412 | Register scratch1, |
| 3413 | Register scratch2, |
| 3414 | Label* gc_required, |
| 3415 | OverwriteMode mode) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3416 | // Code below will scratch result if allocation fails. To keep both arguments |
| 3417 | // intact for the runtime call result cannot be one of these. |
| 3418 | ASSERT(!result.is(r0) && !result.is(r1)); |
| 3419 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3420 | if (mode == OVERWRITE_LEFT || mode == OVERWRITE_RIGHT) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3421 | Label skip_allocation, allocated; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3422 | Register overwritable_operand = mode == OVERWRITE_LEFT ? r1 : r0; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3423 | // If the overwritable operand is already an object, we skip the |
| 3424 | // allocation of a heap number. |
| 3425 | __ JumpIfNotSmi(overwritable_operand, &skip_allocation); |
| 3426 | // Allocate a heap number for the result. |
| 3427 | __ AllocateHeapNumber( |
| 3428 | result, scratch1, scratch2, heap_number_map, gc_required); |
| 3429 | __ b(&allocated); |
| 3430 | __ bind(&skip_allocation); |
| 3431 | // Use object holding the overwritable operand for result. |
| 3432 | __ mov(result, Operand(overwritable_operand)); |
| 3433 | __ bind(&allocated); |
| 3434 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3435 | ASSERT(mode == NO_OVERWRITE); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3436 | __ AllocateHeapNumber( |
| 3437 | result, scratch1, scratch2, heap_number_map, gc_required); |
| 3438 | } |
| 3439 | } |
| 3440 | |
| 3441 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3442 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3443 | __ Push(r1, r0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3444 | } |
| 3445 | |
| 3446 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3447 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3448 | // Untagged case: double input in d2, double result goes |
| 3449 | // into d2. |
| 3450 | // Tagged case: tagged input on top of stack and in r0, |
| 3451 | // tagged result (heap number) goes into r0. |
| 3452 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3453 | Label input_not_smi; |
| 3454 | Label loaded; |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3455 | Label calculate; |
| 3456 | Label invalid_cache; |
| 3457 | const Register scratch0 = r9; |
| 3458 | const Register scratch1 = r7; |
| 3459 | const Register cache_entry = r0; |
| 3460 | const bool tagged = (argument_type_ == TAGGED); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3461 | |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3462 | if (CpuFeatures::IsSupported(VFP2)) { |
| 3463 | CpuFeatures::Scope scope(VFP2); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3464 | if (tagged) { |
| 3465 | // Argument is a number and is on stack and in r0. |
| 3466 | // Load argument and check if it is a smi. |
| 3467 | __ JumpIfNotSmi(r0, &input_not_smi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3468 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3469 | // Input is a smi. Convert to double and load the low and high words |
| 3470 | // of the double into r2, r3. |
| 3471 | __ IntegerToDoubleConversionWithVFP3(r0, r3, r2); |
| 3472 | __ b(&loaded); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3473 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3474 | __ bind(&input_not_smi); |
| 3475 | // Check if input is a HeapNumber. |
| 3476 | __ CheckMap(r0, |
| 3477 | r1, |
| 3478 | Heap::kHeapNumberMapRootIndex, |
| 3479 | &calculate, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3480 | DONT_DO_SMI_CHECK); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3481 | // Input is a HeapNumber. Load it to a double register and store the |
| 3482 | // low and high words into r2, r3. |
| 3483 | __ vldr(d0, FieldMemOperand(r0, HeapNumber::kValueOffset)); |
| 3484 | __ vmov(r2, r3, d0); |
| 3485 | } else { |
| 3486 | // Input is untagged double in d2. Output goes to d2. |
| 3487 | __ vmov(r2, r3, d2); |
| 3488 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3489 | __ bind(&loaded); |
| 3490 | // r2 = low 32 bits of double value |
| 3491 | // r3 = high 32 bits of double value |
| 3492 | // Compute hash (the shifts are arithmetic): |
| 3493 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 3494 | __ eor(r1, r2, Operand(r3)); |
| 3495 | __ eor(r1, r1, Operand(r1, ASR, 16)); |
| 3496 | __ eor(r1, r1, Operand(r1, ASR, 8)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3497 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
| 3498 | __ And(r1, r1, Operand(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3499 | |
| 3500 | // r2 = low 32 bits of double value. |
| 3501 | // r3 = high 32 bits of double value. |
| 3502 | // r1 = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3503 | Isolate* isolate = masm->isolate(); |
| 3504 | ExternalReference cache_array = |
| 3505 | ExternalReference::transcendental_cache_array_address(isolate); |
| 3506 | __ mov(cache_entry, Operand(cache_array)); |
| 3507 | // cache_entry points to cache array. |
| 3508 | int cache_array_index |
| 3509 | = type_ * sizeof(isolate->transcendental_cache()->caches_[0]); |
| 3510 | __ ldr(cache_entry, MemOperand(cache_entry, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3511 | // r0 points to the cache for the type type_. |
| 3512 | // If NULL, the cache hasn't been initialized yet, so go through runtime. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3513 | __ cmp(cache_entry, Operand::Zero()); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3514 | __ b(eq, &invalid_cache); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3515 | |
| 3516 | #ifdef DEBUG |
| 3517 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3518 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3519 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 3520 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 3521 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 3522 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 3523 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 3524 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 3525 | CHECK_EQ(0, elem_in0 - elem_start); |
| 3526 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 3527 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 3528 | } |
| 3529 | #endif |
| 3530 | |
| 3531 | // Find the address of the r1'st entry in the cache, i.e., &r0[r1*12]. |
| 3532 | __ add(r1, r1, Operand(r1, LSL, 1)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3533 | __ add(cache_entry, cache_entry, Operand(r1, LSL, 2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3534 | // Check if cache matches: Double value is stored in uint32_t[2] array. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3535 | __ ldm(ia, cache_entry, r4.bit() | r5.bit() | r6.bit()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3536 | __ cmp(r2, r4); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3537 | __ cmp(r3, r5, eq); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3538 | __ b(ne, &calculate); |
| 3539 | // Cache hit. Load result, cleanup and return. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3540 | Counters* counters = masm->isolate()->counters(); |
| 3541 | __ IncrementCounter( |
| 3542 | counters->transcendental_cache_hit(), 1, scratch0, scratch1); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3543 | if (tagged) { |
| 3544 | // Pop input value from stack and load result into r0. |
| 3545 | __ pop(); |
| 3546 | __ mov(r0, Operand(r6)); |
| 3547 | } else { |
| 3548 | // Load result into d2. |
| 3549 | __ vldr(d2, FieldMemOperand(r6, HeapNumber::kValueOffset)); |
| 3550 | } |
| 3551 | __ Ret(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3552 | } // if (CpuFeatures::IsSupported(VFP3)) |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3553 | |
| 3554 | __ bind(&calculate); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3555 | Counters* counters = masm->isolate()->counters(); |
| 3556 | __ IncrementCounter( |
| 3557 | counters->transcendental_cache_miss(), 1, scratch0, scratch1); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3558 | if (tagged) { |
| 3559 | __ bind(&invalid_cache); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3560 | ExternalReference runtime_function = |
| 3561 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 3562 | __ TailCallExternalReference(runtime_function, 1, 1); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3563 | } else { |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3564 | ASSERT(CpuFeatures::IsSupported(VFP2)); |
| 3565 | CpuFeatures::Scope scope(VFP2); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3566 | |
| 3567 | Label no_update; |
| 3568 | Label skip_cache; |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3569 | |
| 3570 | // Call C function to calculate the result and update the cache. |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 3571 | // r0: precalculated cache entry address. |
| 3572 | // r2 and r3: parts of the double value. |
| 3573 | // Store r0, r2 and r3 on stack for later before calling C function. |
| 3574 | __ Push(r3, r2, cache_entry); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3575 | GenerateCallCFunction(masm, scratch0); |
| 3576 | __ GetCFunctionDoubleResult(d2); |
| 3577 | |
| 3578 | // Try to update the cache. If we cannot allocate a |
| 3579 | // heap number, we return the result without updating. |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 3580 | __ Pop(r3, r2, cache_entry); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3581 | __ LoadRoot(r5, Heap::kHeapNumberMapRootIndex); |
| 3582 | __ AllocateHeapNumber(r6, scratch0, scratch1, r5, &no_update); |
| 3583 | __ vstr(d2, FieldMemOperand(r6, HeapNumber::kValueOffset)); |
| 3584 | __ stm(ia, cache_entry, r2.bit() | r3.bit() | r6.bit()); |
| 3585 | __ Ret(); |
| 3586 | |
| 3587 | __ bind(&invalid_cache); |
| 3588 | // The cache is invalid. Call runtime which will recreate the |
| 3589 | // cache. |
| 3590 | __ LoadRoot(r5, Heap::kHeapNumberMapRootIndex); |
| 3591 | __ AllocateHeapNumber(r0, scratch0, scratch1, r5, &skip_cache); |
| 3592 | __ vstr(d2, FieldMemOperand(r0, HeapNumber::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3593 | { |
| 3594 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3595 | __ push(r0); |
| 3596 | __ CallRuntime(RuntimeFunction(), 1); |
| 3597 | } |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3598 | __ vldr(d2, FieldMemOperand(r0, HeapNumber::kValueOffset)); |
| 3599 | __ Ret(); |
| 3600 | |
| 3601 | __ bind(&skip_cache); |
| 3602 | // Call C function to calculate the result and answer directly |
| 3603 | // without updating the cache. |
| 3604 | GenerateCallCFunction(masm, scratch0); |
| 3605 | __ GetCFunctionDoubleResult(d2); |
| 3606 | __ bind(&no_update); |
| 3607 | |
| 3608 | // We return the value in d2 without adding it to the cache, but |
| 3609 | // 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] | 3610 | { |
| 3611 | FrameScope scope(masm, StackFrame::INTERNAL); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3612 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3613 | // Allocate an aligned object larger than a HeapNumber. |
| 3614 | ASSERT(4 * kPointerSize >= HeapNumber::kSize); |
| 3615 | __ mov(scratch0, Operand(4 * kPointerSize)); |
| 3616 | __ push(scratch0); |
| 3617 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 3618 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3619 | __ Ret(); |
| 3620 | } |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3621 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3622 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3623 | |
| 3624 | void TranscendentalCacheStub::GenerateCallCFunction(MacroAssembler* masm, |
| 3625 | Register scratch) { |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3626 | ASSERT(CpuFeatures::IsEnabled(VFP2)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3627 | Isolate* isolate = masm->isolate(); |
| 3628 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3629 | __ push(lr); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3630 | __ PrepareCallCFunction(0, 1, scratch); |
| 3631 | if (masm->use_eabi_hardfloat()) { |
| 3632 | __ vmov(d0, d2); |
| 3633 | } else { |
| 3634 | __ vmov(r0, r1, d2); |
| 3635 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3636 | AllowExternalCallThatCantCauseGC scope(masm); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3637 | switch (type_) { |
| 3638 | case TranscendentalCache::SIN: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3639 | __ CallCFunction(ExternalReference::math_sin_double_function(isolate), |
| 3640 | 0, 1); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3641 | break; |
| 3642 | case TranscendentalCache::COS: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3643 | __ CallCFunction(ExternalReference::math_cos_double_function(isolate), |
| 3644 | 0, 1); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3645 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3646 | case TranscendentalCache::TAN: |
| 3647 | __ CallCFunction(ExternalReference::math_tan_double_function(isolate), |
| 3648 | 0, 1); |
| 3649 | break; |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3650 | case TranscendentalCache::LOG: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3651 | __ CallCFunction(ExternalReference::math_log_double_function(isolate), |
| 3652 | 0, 1); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3653 | break; |
| 3654 | default: |
| 3655 | UNIMPLEMENTED(); |
| 3656 | break; |
| 3657 | } |
| 3658 | __ pop(lr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3659 | } |
| 3660 | |
| 3661 | |
| 3662 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 3663 | switch (type_) { |
| 3664 | // Add more cases when necessary. |
| 3665 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 3666 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3667 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3668 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3669 | default: |
| 3670 | UNIMPLEMENTED(); |
| 3671 | return Runtime::kAbort; |
| 3672 | } |
| 3673 | } |
| 3674 | |
| 3675 | |
| 3676 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 3677 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3681 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 3682 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 3683 | } |
| 3684 | |
| 3685 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3686 | void MathPowStub::Generate(MacroAssembler* masm) { |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 3687 | CpuFeatures::Scope vfp2_scope(VFP2); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3688 | const Register base = r1; |
| 3689 | const Register exponent = r2; |
| 3690 | const Register heapnumbermap = r5; |
| 3691 | const Register heapnumber = r0; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3692 | const DwVfpRegister double_base = d1; |
| 3693 | const DwVfpRegister double_exponent = d2; |
| 3694 | const DwVfpRegister double_result = d3; |
| 3695 | const DwVfpRegister double_scratch = d0; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3696 | const SwVfpRegister single_scratch = s0; |
| 3697 | const Register scratch = r9; |
| 3698 | const Register scratch2 = r7; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3699 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3700 | Label call_runtime, done, int_exponent; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3701 | if (exponent_type_ == ON_STACK) { |
| 3702 | Label base_is_smi, unpack_exponent; |
| 3703 | // The exponent and base are supplied as arguments on the stack. |
| 3704 | // This can only happen if the stub is called from non-optimized code. |
| 3705 | // Load input parameters from stack to double registers. |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3706 | __ ldr(base, MemOperand(sp, 1 * kPointerSize)); |
| 3707 | __ ldr(exponent, MemOperand(sp, 0 * kPointerSize)); |
| 3708 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3709 | __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3710 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3711 | __ UntagAndJumpIfSmi(scratch, base, &base_is_smi); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3712 | __ ldr(scratch, FieldMemOperand(base, JSObject::kMapOffset)); |
| 3713 | __ cmp(scratch, heapnumbermap); |
| 3714 | __ b(ne, &call_runtime); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3715 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3716 | __ vldr(double_base, FieldMemOperand(base, HeapNumber::kValueOffset)); |
| 3717 | __ jmp(&unpack_exponent); |
| 3718 | |
| 3719 | __ bind(&base_is_smi); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3720 | __ vmov(single_scratch, scratch); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3721 | __ vcvt_f64_s32(double_base, single_scratch); |
| 3722 | __ bind(&unpack_exponent); |
| 3723 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3724 | __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3725 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3726 | __ ldr(scratch, FieldMemOperand(exponent, JSObject::kMapOffset)); |
| 3727 | __ cmp(scratch, heapnumbermap); |
| 3728 | __ b(ne, &call_runtime); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3729 | __ vldr(double_exponent, |
| 3730 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3731 | } else if (exponent_type_ == TAGGED) { |
| 3732 | // Base is already in double_base. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3733 | __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3734 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3735 | __ vldr(double_exponent, |
| 3736 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
| 3737 | } |
| 3738 | |
| 3739 | if (exponent_type_ != INTEGER) { |
| 3740 | Label int_exponent_convert; |
| 3741 | // Detect integer exponents stored as double. |
| 3742 | __ vcvt_u32_f64(single_scratch, double_exponent); |
| 3743 | // We do not check for NaN or Infinity here because comparing numbers on |
| 3744 | // ARM correctly distinguishes NaNs. We end up calling the built-in. |
| 3745 | __ vcvt_f64_u32(double_scratch, single_scratch); |
| 3746 | __ VFPCompareAndSetFlags(double_scratch, double_exponent); |
| 3747 | __ b(eq, &int_exponent_convert); |
| 3748 | |
| 3749 | if (exponent_type_ == ON_STACK) { |
| 3750 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 3751 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 3752 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 3753 | Label not_plus_half; |
| 3754 | |
| 3755 | // Test for 0.5. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3756 | __ vmov(double_scratch, 0.5, scratch); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3757 | __ VFPCompareAndSetFlags(double_exponent, double_scratch); |
| 3758 | __ b(ne, ¬_plus_half); |
| 3759 | |
| 3760 | // Calculates square root of base. Check for the special case of |
| 3761 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3762 | __ vmov(double_scratch, -V8_INFINITY, scratch); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3763 | __ VFPCompareAndSetFlags(double_base, double_scratch); |
| 3764 | __ vneg(double_result, double_scratch, eq); |
| 3765 | __ b(eq, &done); |
| 3766 | |
| 3767 | // Add +0 to convert -0 to +0. |
| 3768 | __ vadd(double_scratch, double_base, kDoubleRegZero); |
| 3769 | __ vsqrt(double_result, double_scratch); |
| 3770 | __ jmp(&done); |
| 3771 | |
| 3772 | __ bind(¬_plus_half); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3773 | __ vmov(double_scratch, -0.5, scratch); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3774 | __ VFPCompareAndSetFlags(double_exponent, double_scratch); |
| 3775 | __ b(ne, &call_runtime); |
| 3776 | |
| 3777 | // Calculates square root of base. Check for the special case of |
| 3778 | // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3779 | __ vmov(double_scratch, -V8_INFINITY, scratch); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3780 | __ VFPCompareAndSetFlags(double_base, double_scratch); |
| 3781 | __ vmov(double_result, kDoubleRegZero, eq); |
| 3782 | __ b(eq, &done); |
| 3783 | |
| 3784 | // Add +0 to convert -0 to +0. |
| 3785 | __ vadd(double_scratch, double_base, kDoubleRegZero); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3786 | __ vmov(double_result, 1.0, scratch); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3787 | __ vsqrt(double_scratch, double_scratch); |
| 3788 | __ vdiv(double_result, double_result, double_scratch); |
| 3789 | __ jmp(&done); |
| 3790 | } |
| 3791 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3792 | __ push(lr); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3793 | { |
| 3794 | AllowExternalCallThatCantCauseGC scope(masm); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3795 | __ PrepareCallCFunction(0, 2, scratch); |
| 3796 | __ SetCallCDoubleArguments(double_base, double_exponent); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3797 | __ CallCFunction( |
| 3798 | ExternalReference::power_double_double_function(masm->isolate()), |
| 3799 | 0, 2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3800 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3801 | __ pop(lr); |
| 3802 | __ GetCFunctionDoubleResult(double_result); |
| 3803 | __ jmp(&done); |
| 3804 | |
| 3805 | __ bind(&int_exponent_convert); |
| 3806 | __ vcvt_u32_f64(single_scratch, double_exponent); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3807 | __ vmov(scratch, single_scratch); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3810 | // Calculate power with integer exponent. |
| 3811 | __ bind(&int_exponent); |
| 3812 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3813 | // Get two copies of exponent in the registers scratch and exponent. |
| 3814 | if (exponent_type_ == INTEGER) { |
| 3815 | __ mov(scratch, exponent); |
| 3816 | } else { |
| 3817 | // Exponent has previously been stored into scratch as untagged integer. |
| 3818 | __ mov(exponent, scratch); |
| 3819 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3820 | __ vmov(double_scratch, double_base); // Back up base. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3821 | __ vmov(double_result, 1.0, scratch2); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3822 | |
| 3823 | // Get absolute value of exponent. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3824 | __ cmp(scratch, Operand::Zero()); |
| 3825 | __ mov(scratch2, Operand::Zero(), LeaveCC, mi); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3826 | __ sub(scratch, scratch2, scratch, LeaveCC, mi); |
| 3827 | |
| 3828 | Label while_true; |
| 3829 | __ bind(&while_true); |
| 3830 | __ mov(scratch, Operand(scratch, ASR, 1), SetCC); |
| 3831 | __ vmul(double_result, double_result, double_scratch, cs); |
| 3832 | __ vmul(double_scratch, double_scratch, double_scratch, ne); |
| 3833 | __ b(ne, &while_true); |
| 3834 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3835 | __ cmp(exponent, Operand::Zero()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3836 | __ b(ge, &done); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3837 | __ vmov(double_scratch, 1.0, scratch); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3838 | __ vdiv(double_result, double_scratch, double_result); |
| 3839 | // Test whether result is zero. Bail out to check for subnormal result. |
| 3840 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 3841 | __ VFPCompareAndSetFlags(double_result, 0.0); |
| 3842 | __ b(ne, &done); |
| 3843 | // double_exponent may not containe the exponent value if the input was a |
| 3844 | // smi. We set it with exponent value before bailing out. |
| 3845 | __ vmov(single_scratch, exponent); |
| 3846 | __ vcvt_f64_s32(double_exponent, single_scratch); |
| 3847 | |
| 3848 | // Returning or bailing out. |
| 3849 | Counters* counters = masm->isolate()->counters(); |
| 3850 | if (exponent_type_ == ON_STACK) { |
| 3851 | // The arguments are still on the stack. |
| 3852 | __ bind(&call_runtime); |
| 3853 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
| 3854 | |
| 3855 | // The stub is called from non-optimized code, which expects the result |
| 3856 | // as heap number in exponent. |
| 3857 | __ bind(&done); |
| 3858 | __ AllocateHeapNumber( |
| 3859 | heapnumber, scratch, scratch2, heapnumbermap, &call_runtime); |
| 3860 | __ vstr(double_result, |
| 3861 | FieldMemOperand(heapnumber, HeapNumber::kValueOffset)); |
| 3862 | ASSERT(heapnumber.is(r0)); |
| 3863 | __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2); |
| 3864 | __ Ret(2); |
| 3865 | } else { |
| 3866 | __ push(lr); |
| 3867 | { |
| 3868 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3869 | __ PrepareCallCFunction(0, 2, scratch); |
| 3870 | __ SetCallCDoubleArguments(double_base, double_exponent); |
| 3871 | __ CallCFunction( |
| 3872 | ExternalReference::power_double_double_function(masm->isolate()), |
| 3873 | 0, 2); |
| 3874 | } |
| 3875 | __ pop(lr); |
| 3876 | __ GetCFunctionDoubleResult(double_result); |
| 3877 | |
| 3878 | __ bind(&done); |
| 3879 | __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2); |
| 3880 | __ Ret(); |
| 3881 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3882 | } |
| 3883 | |
| 3884 | |
| 3885 | bool CEntryStub::NeedsImmovableCode() { |
| 3886 | return true; |
| 3887 | } |
| 3888 | |
| 3889 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3890 | bool CEntryStub::IsPregenerated() { |
| 3891 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 3892 | result_size_ == 1; |
| 3893 | } |
| 3894 | |
| 3895 | |
| 3896 | void CodeStub::GenerateStubsAheadOfTime() { |
| 3897 | CEntryStub::GenerateAheadOfTime(); |
| 3898 | WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime(); |
| 3899 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(); |
| 3900 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(); |
| 3901 | } |
| 3902 | |
| 3903 | |
| 3904 | void CodeStub::GenerateFPStubs() { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3905 | SaveFPRegsMode mode = CpuFeatures::IsSupported(VFP2) |
| 3906 | ? kSaveFPRegs |
| 3907 | : kDontSaveFPRegs; |
| 3908 | CEntryStub save_doubles(1, mode); |
| 3909 | StoreBufferOverflowStub stub(mode); |
| 3910 | // These stubs might already be in the snapshot, detect that and don't |
| 3911 | // regenerate, which would lead to code stub initialization state being messed |
| 3912 | // up. |
| 3913 | Code* save_doubles_code = NULL; |
| 3914 | Code* store_buffer_overflow_code = NULL; |
| 3915 | if (!save_doubles.FindCodeInCache(&save_doubles_code, ISOLATE)) { |
| 3916 | if (CpuFeatures::IsSupported(VFP2)) { |
| 3917 | CpuFeatures::Scope scope2(VFP2); |
| 3918 | save_doubles_code = *save_doubles.GetCode(); |
| 3919 | store_buffer_overflow_code = *stub.GetCode(); |
| 3920 | } else { |
| 3921 | save_doubles_code = *save_doubles.GetCode(); |
| 3922 | store_buffer_overflow_code = *stub.GetCode(); |
| 3923 | } |
| 3924 | save_doubles_code->set_is_pregenerated(true); |
| 3925 | store_buffer_overflow_code->set_is_pregenerated(true); |
| 3926 | } |
| 3927 | ISOLATE->set_fp_stubs_generated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3928 | } |
| 3929 | |
| 3930 | |
| 3931 | void CEntryStub::GenerateAheadOfTime() { |
| 3932 | CEntryStub stub(1, kDontSaveFPRegs); |
| 3933 | Handle<Code> code = stub.GetCode(); |
| 3934 | code->set_is_pregenerated(true); |
| 3935 | } |
| 3936 | |
| 3937 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3938 | static void JumpIfOOM(MacroAssembler* masm, |
| 3939 | Register value, |
| 3940 | Register scratch, |
| 3941 | Label* oom_label) { |
| 3942 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 3943 | STATIC_ASSERT(kFailureTag == 3); |
| 3944 | __ and_(scratch, value, Operand(0xf)); |
| 3945 | __ cmp(scratch, Operand(0xf)); |
| 3946 | __ b(eq, oom_label); |
| 3947 | } |
| 3948 | |
| 3949 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3950 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 3951 | Label* throw_normal_exception, |
| 3952 | Label* throw_termination_exception, |
| 3953 | Label* throw_out_of_memory_exception, |
| 3954 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3955 | bool always_allocate) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3956 | // r0: result parameter for PerformGC, if any |
| 3957 | // r4: number of arguments including receiver (C callee-saved) |
| 3958 | // r5: pointer to builtin function (C callee-saved) |
| 3959 | // r6: pointer to the first argument (C callee-saved) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3960 | Isolate* isolate = masm->isolate(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3961 | |
| 3962 | if (do_gc) { |
| 3963 | // Passing r0. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3964 | __ PrepareCallCFunction(1, 0, r1); |
| 3965 | __ CallCFunction(ExternalReference::perform_gc_function(isolate), |
| 3966 | 1, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3967 | } |
| 3968 | |
| 3969 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3970 | ExternalReference::heap_always_allocate_scope_depth(isolate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3971 | if (always_allocate) { |
| 3972 | __ mov(r0, Operand(scope_depth)); |
| 3973 | __ ldr(r1, MemOperand(r0)); |
| 3974 | __ add(r1, r1, Operand(1)); |
| 3975 | __ str(r1, MemOperand(r0)); |
| 3976 | } |
| 3977 | |
| 3978 | // Call C built-in. |
| 3979 | // r0 = argc, r1 = argv |
| 3980 | __ mov(r0, Operand(r4)); |
| 3981 | __ mov(r1, Operand(r6)); |
| 3982 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3983 | #if defined(V8_HOST_ARCH_ARM) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3984 | int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
| 3985 | int frame_alignment_mask = frame_alignment - 1; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3986 | if (FLAG_debug_code) { |
| 3987 | if (frame_alignment > kPointerSize) { |
| 3988 | Label alignment_as_expected; |
| 3989 | ASSERT(IsPowerOf2(frame_alignment)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3990 | __ tst(sp, Operand(frame_alignment_mask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3991 | __ b(eq, &alignment_as_expected); |
| 3992 | // Don't use Check here, as it will call Runtime_Abort re-entering here. |
| 3993 | __ stop("Unexpected alignment"); |
| 3994 | __ bind(&alignment_as_expected); |
| 3995 | } |
| 3996 | } |
| 3997 | #endif |
| 3998 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3999 | __ mov(r2, Operand(ExternalReference::isolate_address())); |
| 4000 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4001 | // To let the GC traverse the return address of the exit frames, we need to |
| 4002 | // know where the return address is. The CEntryStub is unmovable, so |
| 4003 | // we can store the address on the stack to be able to find it again and |
| 4004 | // we never have to restore it, because it will not change. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4005 | // Compute the return address in lr to return to after the jump below. Pc is |
| 4006 | // already at '+ 8' from the current instruction but return is after three |
| 4007 | // instructions so add another 4 to pc to get the return address. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4008 | { |
| 4009 | // Prevent literal pool emission before return address. |
| 4010 | Assembler::BlockConstPoolScope block_const_pool(masm); |
| 4011 | masm->add(lr, pc, Operand(4)); |
| 4012 | __ str(lr, MemOperand(sp, 0)); |
| 4013 | masm->Jump(r5); |
| 4014 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4015 | |
| 4016 | if (always_allocate) { |
| 4017 | // It's okay to clobber r2 and r3 here. Don't mess with r0 and r1 |
| 4018 | // though (contain the result). |
| 4019 | __ mov(r2, Operand(scope_depth)); |
| 4020 | __ ldr(r3, MemOperand(r2)); |
| 4021 | __ sub(r3, r3, Operand(1)); |
| 4022 | __ str(r3, MemOperand(r2)); |
| 4023 | } |
| 4024 | |
| 4025 | // check for failure result |
| 4026 | Label failure_returned; |
| 4027 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 4028 | // Lower 2 bits of r2 are 0 iff r0 has failure tag. |
| 4029 | __ add(r2, r0, Operand(1)); |
| 4030 | __ tst(r2, Operand(kFailureTagMask)); |
| 4031 | __ b(eq, &failure_returned); |
| 4032 | |
| 4033 | // Exit C frame and return. |
| 4034 | // r0:r1: result |
| 4035 | // sp: stack pointer |
| 4036 | // fp: frame pointer |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4037 | // Callee-saved register r4 still holds argc. |
| 4038 | __ LeaveExitFrame(save_doubles_, r4); |
| 4039 | __ mov(pc, lr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4040 | |
| 4041 | // check if we should retry or throw exception |
| 4042 | Label retry; |
| 4043 | __ bind(&failure_returned); |
| 4044 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 4045 | __ tst(r0, Operand(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
| 4046 | __ b(eq, &retry); |
| 4047 | |
| 4048 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4049 | JumpIfOOM(masm, r0, ip, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4050 | |
| 4051 | // Retrieve the pending exception and clear the variable. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4052 | __ mov(r3, Operand(isolate->factory()->the_hole_value())); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4053 | __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4054 | isolate))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4055 | __ ldr(r0, MemOperand(ip)); |
| 4056 | __ str(r3, MemOperand(ip)); |
| 4057 | |
| 4058 | // Special handling of termination exceptions which are uncatchable |
| 4059 | // by javascript code. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4060 | __ cmp(r0, Operand(isolate->factory()->termination_exception())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4061 | __ b(eq, throw_termination_exception); |
| 4062 | |
| 4063 | // Handle normal exception. |
| 4064 | __ jmp(throw_normal_exception); |
| 4065 | |
| 4066 | __ bind(&retry); // pass last failure (r0) as parameter (r0) when retrying |
| 4067 | } |
| 4068 | |
| 4069 | |
| 4070 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 4071 | // Called from JavaScript; parameters are on stack as if calling JS function |
| 4072 | // r0: number of arguments including receiver |
| 4073 | // r1: pointer to builtin function |
| 4074 | // fp: frame pointer (restored after C call) |
| 4075 | // sp: stack pointer (restored as callee's sp after C call) |
| 4076 | // cp: current context (C callee-saved) |
| 4077 | |
| 4078 | // Result returned in r0 or r0+r1 by default. |
| 4079 | |
| 4080 | // NOTE: Invocations of builtins may return failure objects |
| 4081 | // instead of a proper result. The builtin entry handles |
| 4082 | // this by performing a garbage collection and retrying the |
| 4083 | // builtin once. |
| 4084 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4085 | // Compute the argv pointer in a callee-saved register. |
| 4086 | __ add(r6, sp, Operand(r0, LSL, kPointerSizeLog2)); |
| 4087 | __ sub(r6, r6, Operand(kPointerSize)); |
| 4088 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4089 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4090 | FrameScope scope(masm, StackFrame::MANUAL); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4091 | __ EnterExitFrame(save_doubles_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4092 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4093 | // Set up argc and the builtin function in callee-saved registers. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4094 | __ mov(r4, Operand(r0)); |
| 4095 | __ mov(r5, Operand(r1)); |
| 4096 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4097 | // r4: number of arguments (C callee-saved) |
| 4098 | // r5: pointer to builtin function (C callee-saved) |
| 4099 | // r6: pointer to first argument (C callee-saved) |
| 4100 | |
| 4101 | Label throw_normal_exception; |
| 4102 | Label throw_termination_exception; |
| 4103 | Label throw_out_of_memory_exception; |
| 4104 | |
| 4105 | // Call into the runtime system. |
| 4106 | GenerateCore(masm, |
| 4107 | &throw_normal_exception, |
| 4108 | &throw_termination_exception, |
| 4109 | &throw_out_of_memory_exception, |
| 4110 | false, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4111 | false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4112 | |
| 4113 | // Do space-specific GC and retry runtime call. |
| 4114 | GenerateCore(masm, |
| 4115 | &throw_normal_exception, |
| 4116 | &throw_termination_exception, |
| 4117 | &throw_out_of_memory_exception, |
| 4118 | true, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4119 | false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4120 | |
| 4121 | // Do full GC and retry runtime call one final time. |
| 4122 | Failure* failure = Failure::InternalError(); |
| 4123 | __ mov(r0, Operand(reinterpret_cast<int32_t>(failure))); |
| 4124 | GenerateCore(masm, |
| 4125 | &throw_normal_exception, |
| 4126 | &throw_termination_exception, |
| 4127 | &throw_out_of_memory_exception, |
| 4128 | true, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4129 | true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4130 | |
| 4131 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4132 | // Set external caught exception to false. |
| 4133 | Isolate* isolate = masm->isolate(); |
| 4134 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 4135 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4136 | __ mov(r0, Operand(false, RelocInfo::NONE32)); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4137 | __ mov(r2, Operand(external_caught)); |
| 4138 | __ str(r0, MemOperand(r2)); |
| 4139 | |
| 4140 | // Set pending exception and r0 to out of memory exception. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4141 | Label already_have_failure; |
| 4142 | JumpIfOOM(masm, r0, ip, &already_have_failure); |
| 4143 | Failure* out_of_memory = Failure::OutOfMemoryException(0x1); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4144 | __ mov(r0, Operand(reinterpret_cast<int32_t>(out_of_memory))); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4145 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4146 | __ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
| 4147 | isolate))); |
| 4148 | __ str(r0, MemOperand(r2)); |
| 4149 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4150 | |
| 4151 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4152 | __ ThrowUncatchable(r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4153 | |
| 4154 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4155 | __ Throw(r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | |
| 4159 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
| 4160 | // r0: code entry |
| 4161 | // r1: function |
| 4162 | // r2: receiver |
| 4163 | // r3: argc |
| 4164 | // [sp+0]: argv |
| 4165 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4166 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4167 | |
| 4168 | // Called from C, so do not pop argc and args on exit (preserve sp) |
| 4169 | // No need to save register-passed args |
| 4170 | // Save callee-saved registers (incl. cp and fp), sp, and lr |
| 4171 | __ stm(db_w, sp, kCalleeSaved | lr.bit()); |
| 4172 | |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 4173 | if (CpuFeatures::IsSupported(VFP2)) { |
| 4174 | CpuFeatures::Scope scope(VFP2); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4175 | // Save callee-saved vfp registers. |
| 4176 | __ vstm(db_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4177 | // Set up the reserved register for 0.0. |
| 4178 | __ vmov(kDoubleRegZero, 0.0); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4179 | } |
| 4180 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4181 | // Get address of argv, see stm above. |
| 4182 | // r0: code entry |
| 4183 | // r1: function |
| 4184 | // r2: receiver |
| 4185 | // r3: argc |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4186 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4187 | // Set up argv in r4. |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4188 | int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize; |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 4189 | if (CpuFeatures::IsSupported(VFP2)) { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4190 | offset_to_argv += kNumDoubleCalleeSaved * kDoubleSize; |
| 4191 | } |
| 4192 | __ ldr(r4, MemOperand(sp, offset_to_argv)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4193 | |
| 4194 | // Push a frame with special values setup to mark it as an entry frame. |
| 4195 | // r0: code entry |
| 4196 | // r1: function |
| 4197 | // r2: receiver |
| 4198 | // r3: argc |
| 4199 | // r4: argv |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4200 | Isolate* isolate = masm->isolate(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4201 | __ mov(r8, Operand(-1)); // Push a bad frame pointer to fail if it is used. |
| 4202 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 4203 | __ mov(r7, Operand(Smi::FromInt(marker))); |
| 4204 | __ mov(r6, Operand(Smi::FromInt(marker))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4205 | __ mov(r5, |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4206 | Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4207 | __ ldr(r5, MemOperand(r5)); |
| 4208 | __ Push(r8, r7, r6, r5); |
| 4209 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4210 | // Set up frame pointer for the frame to be pushed. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4211 | __ add(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset)); |
| 4212 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4213 | // If this is the outermost JS call, set js_entry_sp value. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4214 | Label non_outermost_js; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4215 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4216 | __ mov(r5, Operand(ExternalReference(js_entry_sp))); |
| 4217 | __ ldr(r6, MemOperand(r5)); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4218 | __ cmp(r6, Operand::Zero()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4219 | __ b(ne, &non_outermost_js); |
| 4220 | __ str(fp, MemOperand(r5)); |
| 4221 | __ mov(ip, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 4222 | Label cont; |
| 4223 | __ b(&cont); |
| 4224 | __ bind(&non_outermost_js); |
| 4225 | __ mov(ip, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
| 4226 | __ bind(&cont); |
| 4227 | __ push(ip); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4228 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4229 | // Jump to a faked try block that does the invoke, with a faked catch |
| 4230 | // block that sets the pending exception. |
| 4231 | __ jmp(&invoke); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4232 | |
| 4233 | // Block literal pool emission whilst taking the position of the handler |
| 4234 | // entry. This avoids making the assumption that literal pools are always |
| 4235 | // emitted after an instruction is emitted, rather than before. |
| 4236 | { |
| 4237 | Assembler::BlockConstPoolScope block_const_pool(masm); |
| 4238 | __ bind(&handler_entry); |
| 4239 | handler_offset_ = handler_entry.pos(); |
| 4240 | // Caught exception: Store result (exception) in the pending exception |
| 4241 | // field in the JSEnv and return a failure sentinel. Coming in here the |
| 4242 | // fp will be invalid because the PushTryHandler below sets it to 0 to |
| 4243 | // signal the existence of the JSEntry frame. |
| 4244 | __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
| 4245 | isolate))); |
| 4246 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4247 | __ str(r0, MemOperand(ip)); |
| 4248 | __ mov(r0, Operand(reinterpret_cast<int32_t>(Failure::Exception()))); |
| 4249 | __ b(&exit); |
| 4250 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4251 | // Invoke: Link this frame into the handler chain. There's only one |
| 4252 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4253 | __ bind(&invoke); |
| 4254 | // Must preserve r0-r4, r5-r7 are available. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 4255 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4256 | // If an exception not caught by another handler occurs, this handler |
| 4257 | // returns control to the code after the bl(&invoke) above, which |
| 4258 | // restores all kCalleeSaved registers (including cp and fp) to their |
| 4259 | // saved values before returning a failure to C. |
| 4260 | |
| 4261 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4262 | __ mov(r5, Operand(isolate->factory()->the_hole_value())); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4263 | __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4264 | isolate))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4265 | __ str(r5, MemOperand(ip)); |
| 4266 | |
| 4267 | // Invoke the function by calling through JS entry trampoline builtin. |
| 4268 | // Notice that we cannot store a reference to the trampoline code directly in |
| 4269 | // this stub, because runtime stubs are not traversed when doing GC. |
| 4270 | |
| 4271 | // Expected registers by Builtins::JSEntryTrampoline |
| 4272 | // r0: code entry |
| 4273 | // r1: function |
| 4274 | // r2: receiver |
| 4275 | // r3: argc |
| 4276 | // r4: argv |
| 4277 | if (is_construct) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4278 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4279 | isolate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4280 | __ mov(ip, Operand(construct_entry)); |
| 4281 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4282 | ExternalReference entry(Builtins::kJSEntryTrampoline, isolate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4283 | __ mov(ip, Operand(entry)); |
| 4284 | } |
| 4285 | __ ldr(ip, MemOperand(ip)); // deref address |
| 4286 | |
| 4287 | // Branch and link to JSEntryTrampoline. We don't use the double underscore |
| 4288 | // macro for the add instruction because we don't want the coverage tool |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4289 | // inserting instructions here after we read the pc. We block literal pool |
| 4290 | // emission for the same reason. |
| 4291 | { |
| 4292 | Assembler::BlockConstPoolScope block_const_pool(masm); |
| 4293 | __ mov(lr, Operand(pc)); |
| 4294 | masm->add(pc, ip, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4295 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4296 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4297 | // Unlink this frame from the handler chain. |
| 4298 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4299 | |
| 4300 | __ bind(&exit); // r0 holds result |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4301 | // Check if the current stack frame is marked as the outermost JS frame. |
| 4302 | Label non_outermost_js_2; |
| 4303 | __ pop(r5); |
| 4304 | __ cmp(r5, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 4305 | __ b(ne, &non_outermost_js_2); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4306 | __ mov(r6, Operand::Zero()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4307 | __ mov(r5, Operand(ExternalReference(js_entry_sp))); |
| 4308 | __ str(r6, MemOperand(r5)); |
| 4309 | __ bind(&non_outermost_js_2); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4310 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4311 | // Restore the top frame descriptors from the stack. |
| 4312 | __ pop(r3); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4313 | __ mov(ip, |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4314 | Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4315 | __ str(r3, MemOperand(ip)); |
| 4316 | |
| 4317 | // Reset the stack to the callee saved registers. |
| 4318 | __ add(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset)); |
| 4319 | |
| 4320 | // Restore callee-saved registers and return. |
| 4321 | #ifdef DEBUG |
| 4322 | if (FLAG_debug_code) { |
| 4323 | __ mov(lr, Operand(pc)); |
| 4324 | } |
| 4325 | #endif |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4326 | |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 4327 | if (CpuFeatures::IsSupported(VFP2)) { |
| 4328 | CpuFeatures::Scope scope(VFP2); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4329 | // Restore callee-saved vfp registers. |
| 4330 | __ vldm(ia_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg); |
| 4331 | } |
| 4332 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4333 | __ ldm(ia_w, sp, kCalleeSaved | pc.bit()); |
| 4334 | } |
| 4335 | |
| 4336 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4337 | // Uses registers r0 to r4. |
| 4338 | // Expected input (depending on whether args are in registers or on the stack): |
| 4339 | // * object: r0 or at sp + 1 * kPointerSize. |
| 4340 | // * function: r1 or at sp. |
| 4341 | // |
| 4342 | // An inlined call site may have been generated before calling this stub. |
| 4343 | // In this case the offset to the inline site to patch is passed on the stack, |
| 4344 | // in the safepoint slot for register r4. |
| 4345 | // (See LCodeGen::DoInstanceOfKnownGlobal) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4346 | void InstanceofStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4347 | // Call site inlining and patching implies arguments in registers. |
| 4348 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 4349 | // ReturnTrueFalse is only implemented for inlined call sites. |
| 4350 | ASSERT(!ReturnTrueFalseObject() || HasCallSiteInlineCheck()); |
| 4351 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4352 | // Fixed register usage throughout the stub: |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 4353 | const Register object = r0; // Object (lhs). |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4354 | Register map = r3; // Map of the object. |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 4355 | const Register function = r1; // Function (rhs). |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4356 | const Register prototype = r4; // Prototype of the function. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4357 | const Register inline_site = r9; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4358 | const Register scratch = r2; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4359 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4360 | const int32_t kDeltaToLoadBoolResult = 4 * kPointerSize; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4361 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4362 | Label slow, loop, is_instance, is_not_instance, not_js_object; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4363 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4364 | if (!HasArgsInRegisters()) { |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 4365 | __ ldr(object, MemOperand(sp, 1 * kPointerSize)); |
| 4366 | __ ldr(function, MemOperand(sp, 0)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4367 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4368 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4369 | // Check that the left hand is a JS object and load map. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4370 | __ JumpIfSmi(object, ¬_js_object); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 4371 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4372 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4373 | // If there is a call site cache don't look in the global cache, but do the |
| 4374 | // real lookup and update the call site cache. |
| 4375 | if (!HasCallSiteInlineCheck()) { |
| 4376 | Label miss; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4377 | __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4378 | __ b(ne, &miss); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4379 | __ CompareRoot(map, Heap::kInstanceofCacheMapRootIndex); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4380 | __ b(ne, &miss); |
| 4381 | __ LoadRoot(r0, Heap::kInstanceofCacheAnswerRootIndex); |
| 4382 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4383 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4384 | __ bind(&miss); |
| 4385 | } |
| 4386 | |
| 4387 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4388 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4389 | |
| 4390 | // Check that the function prototype is a JS object. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4391 | __ JumpIfSmi(prototype, &slow); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4392 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4393 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4394 | // Update the global instanceof or call site inlined cache with the current |
| 4395 | // map and function. The cached answer will be set when it is known below. |
| 4396 | if (!HasCallSiteInlineCheck()) { |
| 4397 | __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex); |
| 4398 | __ StoreRoot(map, Heap::kInstanceofCacheMapRootIndex); |
| 4399 | } else { |
| 4400 | ASSERT(HasArgsInRegisters()); |
| 4401 | // Patch the (relocated) inlined map check. |
| 4402 | |
| 4403 | // The offset was stored in r4 safepoint slot. |
| 4404 | // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal) |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4405 | __ LoadFromSafepointRegisterSlot(scratch, r4); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4406 | __ sub(inline_site, lr, scratch); |
| 4407 | // Get the map location in scratch and patch it. |
| 4408 | __ GetRelocatedValueLocation(inline_site, scratch); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4409 | __ ldr(scratch, MemOperand(scratch)); |
| 4410 | __ str(map, FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4411 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4412 | |
| 4413 | // Register mapping: r3 is object map and r4 is function prototype. |
| 4414 | // Get prototype of object into r2. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4415 | __ ldr(scratch, FieldMemOperand(map, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4416 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4417 | // We don't need map any more. Use it as a scratch register. |
| 4418 | Register scratch2 = map; |
| 4419 | map = no_reg; |
| 4420 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4421 | // Loop through the prototype chain looking for the function prototype. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4422 | __ LoadRoot(scratch2, Heap::kNullValueRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4423 | __ bind(&loop); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4424 | __ cmp(scratch, Operand(prototype)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4425 | __ b(eq, &is_instance); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4426 | __ cmp(scratch, scratch2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4427 | __ b(eq, &is_not_instance); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4428 | __ ldr(scratch, FieldMemOperand(scratch, HeapObject::kMapOffset)); |
| 4429 | __ ldr(scratch, FieldMemOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4430 | __ jmp(&loop); |
| 4431 | |
| 4432 | __ bind(&is_instance); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4433 | if (!HasCallSiteInlineCheck()) { |
| 4434 | __ mov(r0, Operand(Smi::FromInt(0))); |
| 4435 | __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex); |
| 4436 | } else { |
| 4437 | // Patch the call site to return true. |
| 4438 | __ LoadRoot(r0, Heap::kTrueValueRootIndex); |
| 4439 | __ add(inline_site, inline_site, Operand(kDeltaToLoadBoolResult)); |
| 4440 | // Get the boolean result location in scratch and patch it. |
| 4441 | __ GetRelocatedValueLocation(inline_site, scratch); |
| 4442 | __ str(r0, MemOperand(scratch)); |
| 4443 | |
| 4444 | if (!ReturnTrueFalseObject()) { |
| 4445 | __ mov(r0, Operand(Smi::FromInt(0))); |
| 4446 | } |
| 4447 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4448 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4449 | |
| 4450 | __ bind(&is_not_instance); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4451 | if (!HasCallSiteInlineCheck()) { |
| 4452 | __ mov(r0, Operand(Smi::FromInt(1))); |
| 4453 | __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex); |
| 4454 | } else { |
| 4455 | // Patch the call site to return false. |
| 4456 | __ LoadRoot(r0, Heap::kFalseValueRootIndex); |
| 4457 | __ add(inline_site, inline_site, Operand(kDeltaToLoadBoolResult)); |
| 4458 | // Get the boolean result location in scratch and patch it. |
| 4459 | __ GetRelocatedValueLocation(inline_site, scratch); |
| 4460 | __ str(r0, MemOperand(scratch)); |
| 4461 | |
| 4462 | if (!ReturnTrueFalseObject()) { |
| 4463 | __ mov(r0, Operand(Smi::FromInt(1))); |
| 4464 | } |
| 4465 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4466 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4467 | |
| 4468 | Label object_not_null, object_not_null_or_smi; |
| 4469 | __ bind(¬_js_object); |
| 4470 | // Before null, smi and string value checks, check that the rhs is a function |
| 4471 | // as for a non-function rhs an exception needs to be thrown. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4472 | __ JumpIfSmi(function, &slow); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4473 | __ CompareObjectType(function, scratch2, scratch, JS_FUNCTION_TYPE); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4474 | __ b(ne, &slow); |
| 4475 | |
| 4476 | // Null is not instance of anything. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4477 | __ cmp(scratch, Operand(masm->isolate()->factory()->null_value())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4478 | __ b(ne, &object_not_null); |
| 4479 | __ mov(r0, Operand(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4480 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4481 | |
| 4482 | __ bind(&object_not_null); |
| 4483 | // Smi values are not instances of anything. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4484 | __ JumpIfNotSmi(object, &object_not_null_or_smi); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4485 | __ mov(r0, Operand(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4486 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4487 | |
| 4488 | __ bind(&object_not_null_or_smi); |
| 4489 | // String values are not instances of anything. |
| 4490 | __ IsObjectJSStringType(object, scratch, &slow); |
| 4491 | __ mov(r0, Operand(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4492 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4493 | |
| 4494 | // Slow-case. Tail call builtin. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4495 | __ bind(&slow); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4496 | if (!ReturnTrueFalseObject()) { |
| 4497 | if (HasArgsInRegisters()) { |
| 4498 | __ Push(r0, r1); |
| 4499 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4500 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4501 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4502 | { |
| 4503 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4504 | __ Push(r0, r1); |
| 4505 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 4506 | } |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4507 | __ cmp(r0, Operand::Zero()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4508 | __ LoadRoot(r0, Heap::kTrueValueRootIndex, eq); |
| 4509 | __ LoadRoot(r0, Heap::kFalseValueRootIndex, ne); |
| 4510 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
| 4511 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4512 | } |
| 4513 | |
| 4514 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 4515 | void ArrayLengthStub::Generate(MacroAssembler* masm) { |
| 4516 | Label miss; |
| 4517 | Register receiver; |
| 4518 | if (kind() == Code::KEYED_LOAD_IC) { |
| 4519 | // ----------- S t a t e ------------- |
| 4520 | // -- lr : return address |
| 4521 | // -- r0 : key |
| 4522 | // -- r1 : receiver |
| 4523 | // ----------------------------------- |
| 4524 | __ cmp(r0, Operand(masm->isolate()->factory()->length_symbol())); |
| 4525 | __ b(ne, &miss); |
| 4526 | receiver = r1; |
| 4527 | } else { |
| 4528 | ASSERT(kind() == Code::LOAD_IC); |
| 4529 | // ----------- S t a t e ------------- |
| 4530 | // -- r2 : name |
| 4531 | // -- lr : return address |
| 4532 | // -- r0 : receiver |
| 4533 | // -- sp[0] : receiver |
| 4534 | // ----------------------------------- |
| 4535 | receiver = r0; |
| 4536 | } |
| 4537 | |
| 4538 | StubCompiler::GenerateLoadArrayLength(masm, receiver, r3, &miss); |
| 4539 | __ bind(&miss); |
| 4540 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 4541 | } |
| 4542 | |
| 4543 | |
| 4544 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 4545 | Label miss; |
| 4546 | Register receiver; |
| 4547 | if (kind() == Code::KEYED_LOAD_IC) { |
| 4548 | // ----------- S t a t e ------------- |
| 4549 | // -- lr : return address |
| 4550 | // -- r0 : key |
| 4551 | // -- r1 : receiver |
| 4552 | // ----------------------------------- |
| 4553 | __ cmp(r0, Operand(masm->isolate()->factory()->prototype_symbol())); |
| 4554 | __ b(ne, &miss); |
| 4555 | receiver = r1; |
| 4556 | } else { |
| 4557 | ASSERT(kind() == Code::LOAD_IC); |
| 4558 | // ----------- S t a t e ------------- |
| 4559 | // -- r2 : name |
| 4560 | // -- lr : return address |
| 4561 | // -- r0 : receiver |
| 4562 | // -- sp[0] : receiver |
| 4563 | // ----------------------------------- |
| 4564 | receiver = r0; |
| 4565 | } |
| 4566 | |
| 4567 | StubCompiler::GenerateLoadFunctionPrototype(masm, receiver, r3, r4, &miss); |
| 4568 | __ bind(&miss); |
| 4569 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 4570 | } |
| 4571 | |
| 4572 | |
| 4573 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 4574 | Label miss; |
| 4575 | Register receiver; |
| 4576 | if (kind() == Code::KEYED_LOAD_IC) { |
| 4577 | // ----------- S t a t e ------------- |
| 4578 | // -- lr : return address |
| 4579 | // -- r0 : key |
| 4580 | // -- r1 : receiver |
| 4581 | // ----------------------------------- |
| 4582 | __ cmp(r0, Operand(masm->isolate()->factory()->length_symbol())); |
| 4583 | __ b(ne, &miss); |
| 4584 | receiver = r1; |
| 4585 | } else { |
| 4586 | ASSERT(kind() == Code::LOAD_IC); |
| 4587 | // ----------- S t a t e ------------- |
| 4588 | // -- r2 : name |
| 4589 | // -- lr : return address |
| 4590 | // -- r0 : receiver |
| 4591 | // -- sp[0] : receiver |
| 4592 | // ----------------------------------- |
| 4593 | receiver = r0; |
| 4594 | } |
| 4595 | |
| 4596 | StubCompiler::GenerateLoadStringLength(masm, receiver, r3, r4, &miss, |
| 4597 | support_wrapper_); |
| 4598 | |
| 4599 | __ bind(&miss); |
| 4600 | StubCompiler::GenerateLoadMiss(masm, kind()); |
| 4601 | } |
| 4602 | |
| 4603 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 4604 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 4605 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 4606 | // (currently anything except for external arrays which means anything with |
| 4607 | // elements of FixedArray type). Value must be a number, but only smis are |
| 4608 | // accepted as the most common case. |
| 4609 | Label miss; |
| 4610 | |
| 4611 | Register receiver; |
| 4612 | Register value; |
| 4613 | if (kind() == Code::KEYED_STORE_IC) { |
| 4614 | // ----------- S t a t e ------------- |
| 4615 | // -- lr : return address |
| 4616 | // -- r0 : value |
| 4617 | // -- r1 : key |
| 4618 | // -- r2 : receiver |
| 4619 | // ----------------------------------- |
| 4620 | __ cmp(r1, Operand(masm->isolate()->factory()->length_symbol())); |
| 4621 | __ b(ne, &miss); |
| 4622 | receiver = r2; |
| 4623 | value = r0; |
| 4624 | } else { |
| 4625 | ASSERT(kind() == Code::STORE_IC); |
| 4626 | // ----------- S t a t e ------------- |
| 4627 | // -- lr : return address |
| 4628 | // -- r0 : value |
| 4629 | // -- r1 : receiver |
| 4630 | // -- r2 : key |
| 4631 | // ----------------------------------- |
| 4632 | receiver = r1; |
| 4633 | value = r0; |
| 4634 | } |
| 4635 | Register scratch = r3; |
| 4636 | |
| 4637 | // Check that the receiver isn't a smi. |
| 4638 | __ JumpIfSmi(receiver, &miss); |
| 4639 | |
| 4640 | // Check that the object is a JS array. |
| 4641 | __ CompareObjectType(receiver, scratch, scratch, JS_ARRAY_TYPE); |
| 4642 | __ b(ne, &miss); |
| 4643 | |
| 4644 | // Check that elements are FixedArray. |
| 4645 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 4646 | // fast elements (including COW). |
| 4647 | __ ldr(scratch, FieldMemOperand(receiver, JSArray::kElementsOffset)); |
| 4648 | __ CompareObjectType(scratch, scratch, scratch, FIXED_ARRAY_TYPE); |
| 4649 | __ b(ne, &miss); |
| 4650 | |
| 4651 | // Check that the array has fast properties, otherwise the length |
| 4652 | // property might have been redefined. |
| 4653 | __ ldr(scratch, FieldMemOperand(receiver, JSArray::kPropertiesOffset)); |
| 4654 | __ ldr(scratch, FieldMemOperand(scratch, FixedArray::kMapOffset)); |
| 4655 | __ CompareRoot(scratch, Heap::kHashTableMapRootIndex); |
| 4656 | __ b(eq, &miss); |
| 4657 | |
| 4658 | // Check that value is a smi. |
| 4659 | __ JumpIfNotSmi(value, &miss); |
| 4660 | |
| 4661 | // Prepare tail call to StoreIC_ArrayLength. |
| 4662 | __ Push(receiver, value); |
| 4663 | |
| 4664 | ExternalReference ref = |
| 4665 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 4666 | __ TailCallExternalReference(ref, 2, 1); |
| 4667 | |
| 4668 | __ bind(&miss); |
| 4669 | |
| 4670 | StubCompiler::GenerateStoreMiss(masm, kind()); |
| 4671 | } |
| 4672 | |
| 4673 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4674 | Register InstanceofStub::left() { return r0; } |
| 4675 | |
| 4676 | |
| 4677 | Register InstanceofStub::right() { return r1; } |
| 4678 | |
| 4679 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4680 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 4681 | // The displacement is the offset of the last parameter (if any) |
| 4682 | // relative to the frame pointer. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4683 | const int kDisplacement = |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4684 | StandardFrameConstants::kCallerSPOffset - kPointerSize; |
| 4685 | |
| 4686 | // Check that the key is a smi. |
| 4687 | Label slow; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4688 | __ JumpIfNotSmi(r1, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4689 | |
| 4690 | // Check if the calling frame is an arguments adaptor frame. |
| 4691 | Label adaptor; |
| 4692 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4693 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 4694 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4695 | __ b(eq, &adaptor); |
| 4696 | |
| 4697 | // Check index against formal parameters count limit passed in |
| 4698 | // through register r0. Use unsigned comparison to get negative |
| 4699 | // check for free. |
| 4700 | __ cmp(r1, r0); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4701 | __ b(hs, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4702 | |
| 4703 | // Read the argument from the stack and return it. |
| 4704 | __ sub(r3, r0, r1); |
| 4705 | __ add(r3, fp, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 4706 | __ ldr(r0, MemOperand(r3, kDisplacement)); |
| 4707 | __ Jump(lr); |
| 4708 | |
| 4709 | // Arguments adaptor case: Check index against actual arguments |
| 4710 | // limit found in the arguments adaptor frame. Use unsigned |
| 4711 | // comparison to get negative check for free. |
| 4712 | __ bind(&adaptor); |
| 4713 | __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4714 | __ cmp(r1, r0); |
| 4715 | __ b(cs, &slow); |
| 4716 | |
| 4717 | // Read the argument from the adaptor frame and return it. |
| 4718 | __ sub(r3, r0, r1); |
| 4719 | __ add(r3, r2, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 4720 | __ ldr(r0, MemOperand(r3, kDisplacement)); |
| 4721 | __ Jump(lr); |
| 4722 | |
| 4723 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 4724 | // by calling the runtime system. |
| 4725 | __ bind(&slow); |
| 4726 | __ push(r1); |
| 4727 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 4728 | } |
| 4729 | |
| 4730 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4731 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4732 | // sp[0] : number of parameters |
| 4733 | // sp[4] : receiver displacement |
| 4734 | // sp[8] : function |
| 4735 | |
| 4736 | // Check if the calling frame is an arguments adaptor frame. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4737 | Label runtime; |
| 4738 | __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4739 | __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset)); |
| 4740 | __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4741 | __ b(ne, &runtime); |
| 4742 | |
| 4743 | // Patch the arguments.length and the parameters pointer in the current frame. |
| 4744 | __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4745 | __ str(r2, MemOperand(sp, 0 * kPointerSize)); |
| 4746 | __ add(r3, r3, Operand(r2, LSL, 1)); |
| 4747 | __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 4748 | __ str(r3, MemOperand(sp, 1 * kPointerSize)); |
| 4749 | |
| 4750 | __ bind(&runtime); |
| 4751 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 4752 | } |
| 4753 | |
| 4754 | |
| 4755 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 4756 | // Stack layout: |
| 4757 | // sp[0] : number of parameters (tagged) |
| 4758 | // sp[4] : address of receiver argument |
| 4759 | // sp[8] : function |
| 4760 | // Registers used over whole function: |
| 4761 | // r6 : allocated object (tagged) |
| 4762 | // r9 : mapped parameter count (tagged) |
| 4763 | |
| 4764 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
| 4765 | // r1 = parameter count (tagged) |
| 4766 | |
| 4767 | // Check if the calling frame is an arguments adaptor frame. |
| 4768 | Label runtime; |
| 4769 | Label adaptor_frame, try_allocate; |
| 4770 | __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4771 | __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset)); |
| 4772 | __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4773 | __ b(eq, &adaptor_frame); |
| 4774 | |
| 4775 | // No adaptor, parameter count = argument count. |
| 4776 | __ mov(r2, r1); |
| 4777 | __ b(&try_allocate); |
| 4778 | |
| 4779 | // We have an adaptor frame. Patch the parameters pointer. |
| 4780 | __ bind(&adaptor_frame); |
| 4781 | __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4782 | __ add(r3, r3, Operand(r2, LSL, 1)); |
| 4783 | __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 4784 | __ str(r3, MemOperand(sp, 1 * kPointerSize)); |
| 4785 | |
| 4786 | // r1 = parameter count (tagged) |
| 4787 | // r2 = argument count (tagged) |
| 4788 | // Compute the mapped parameter count = min(r1, r2) in r1. |
| 4789 | __ cmp(r1, Operand(r2)); |
| 4790 | __ mov(r1, Operand(r2), LeaveCC, gt); |
| 4791 | |
| 4792 | __ bind(&try_allocate); |
| 4793 | |
| 4794 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 4795 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 4796 | const int kParameterMapHeaderSize = |
| 4797 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 4798 | // If there are no mapped parameters, we do not need the parameter_map. |
| 4799 | __ cmp(r1, Operand(Smi::FromInt(0))); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4800 | __ mov(r9, Operand::Zero(), LeaveCC, eq); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4801 | __ mov(r9, Operand(r1, LSL, 1), LeaveCC, ne); |
| 4802 | __ add(r9, r9, Operand(kParameterMapHeaderSize), LeaveCC, ne); |
| 4803 | |
| 4804 | // 2. Backing store. |
| 4805 | __ add(r9, r9, Operand(r2, LSL, 1)); |
| 4806 | __ add(r9, r9, Operand(FixedArray::kHeaderSize)); |
| 4807 | |
| 4808 | // 3. Arguments object. |
| 4809 | __ add(r9, r9, Operand(Heap::kArgumentsObjectSize)); |
| 4810 | |
| 4811 | // Do the allocation of all three objects in one go. |
| 4812 | __ AllocateInNewSpace(r9, r0, r3, r4, &runtime, TAG_OBJECT); |
| 4813 | |
| 4814 | // r0 = address of new object(s) (tagged) |
| 4815 | // r2 = argument count (tagged) |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4816 | // Get the arguments boilerplate from the current native context into r4. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4817 | const int kNormalOffset = |
| 4818 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX); |
| 4819 | const int kAliasedOffset = |
| 4820 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX); |
| 4821 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4822 | __ ldr(r4, MemOperand(r8, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 4823 | __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset)); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4824 | __ cmp(r1, Operand::Zero()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4825 | __ ldr(r4, MemOperand(r4, kNormalOffset), eq); |
| 4826 | __ ldr(r4, MemOperand(r4, kAliasedOffset), ne); |
| 4827 | |
| 4828 | // r0 = address of new object (tagged) |
| 4829 | // r1 = mapped parameter count (tagged) |
| 4830 | // r2 = argument count (tagged) |
| 4831 | // r4 = address of boilerplate object (tagged) |
| 4832 | // Copy the JS object part. |
| 4833 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 4834 | __ ldr(r3, FieldMemOperand(r4, i)); |
| 4835 | __ str(r3, FieldMemOperand(r0, i)); |
| 4836 | } |
| 4837 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4838 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4839 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 4840 | __ ldr(r3, MemOperand(sp, 2 * kPointerSize)); |
| 4841 | const int kCalleeOffset = JSObject::kHeaderSize + |
| 4842 | Heap::kArgumentsCalleeIndex * kPointerSize; |
| 4843 | __ str(r3, FieldMemOperand(r0, kCalleeOffset)); |
| 4844 | |
| 4845 | // Use the length (smi tagged) and set that as an in-object property too. |
| 4846 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 4847 | const int kLengthOffset = JSObject::kHeaderSize + |
| 4848 | Heap::kArgumentsLengthIndex * kPointerSize; |
| 4849 | __ str(r2, FieldMemOperand(r0, kLengthOffset)); |
| 4850 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4851 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4852 | // If we allocated a parameter map, r4 will point there, otherwise |
| 4853 | // it will point to the backing store. |
| 4854 | __ add(r4, r0, Operand(Heap::kArgumentsObjectSize)); |
| 4855 | __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 4856 | |
| 4857 | // r0 = address of new object (tagged) |
| 4858 | // r1 = mapped parameter count (tagged) |
| 4859 | // r2 = argument count (tagged) |
| 4860 | // r4 = address of parameter map or backing store (tagged) |
| 4861 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 4862 | Label skip_parameter_map; |
| 4863 | __ cmp(r1, Operand(Smi::FromInt(0))); |
| 4864 | // Move backing store address to r3, because it is |
| 4865 | // expected there when filling in the unmapped arguments. |
| 4866 | __ mov(r3, r4, LeaveCC, eq); |
| 4867 | __ b(eq, &skip_parameter_map); |
| 4868 | |
| 4869 | __ LoadRoot(r6, Heap::kNonStrictArgumentsElementsMapRootIndex); |
| 4870 | __ str(r6, FieldMemOperand(r4, FixedArray::kMapOffset)); |
| 4871 | __ add(r6, r1, Operand(Smi::FromInt(2))); |
| 4872 | __ str(r6, FieldMemOperand(r4, FixedArray::kLengthOffset)); |
| 4873 | __ str(r8, FieldMemOperand(r4, FixedArray::kHeaderSize + 0 * kPointerSize)); |
| 4874 | __ add(r6, r4, Operand(r1, LSL, 1)); |
| 4875 | __ add(r6, r6, Operand(kParameterMapHeaderSize)); |
| 4876 | __ str(r6, FieldMemOperand(r4, FixedArray::kHeaderSize + 1 * kPointerSize)); |
| 4877 | |
| 4878 | // Copy the parameter slots and the holes in the arguments. |
| 4879 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 4880 | // where parameters are stored in reverse order, at |
| 4881 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 4882 | // The mapped parameter thus need to get indices |
| 4883 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 4884 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 4885 | // We loop from right to left. |
| 4886 | Label parameters_loop, parameters_test; |
| 4887 | __ mov(r6, r1); |
| 4888 | __ ldr(r9, MemOperand(sp, 0 * kPointerSize)); |
| 4889 | __ add(r9, r9, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 4890 | __ sub(r9, r9, Operand(r1)); |
| 4891 | __ LoadRoot(r7, Heap::kTheHoleValueRootIndex); |
| 4892 | __ add(r3, r4, Operand(r6, LSL, 1)); |
| 4893 | __ add(r3, r3, Operand(kParameterMapHeaderSize)); |
| 4894 | |
| 4895 | // r6 = loop variable (tagged) |
| 4896 | // r1 = mapping index (tagged) |
| 4897 | // r3 = address of backing store (tagged) |
| 4898 | // r4 = address of parameter map (tagged) |
| 4899 | // r5 = temporary scratch (a.o., for address calculation) |
| 4900 | // r7 = the hole value |
| 4901 | __ jmp(¶meters_test); |
| 4902 | |
| 4903 | __ bind(¶meters_loop); |
| 4904 | __ sub(r6, r6, Operand(Smi::FromInt(1))); |
| 4905 | __ mov(r5, Operand(r6, LSL, 1)); |
| 4906 | __ add(r5, r5, Operand(kParameterMapHeaderSize - kHeapObjectTag)); |
| 4907 | __ str(r9, MemOperand(r4, r5)); |
| 4908 | __ sub(r5, r5, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize)); |
| 4909 | __ str(r7, MemOperand(r3, r5)); |
| 4910 | __ add(r9, r9, Operand(Smi::FromInt(1))); |
| 4911 | __ bind(¶meters_test); |
| 4912 | __ cmp(r6, Operand(Smi::FromInt(0))); |
| 4913 | __ b(ne, ¶meters_loop); |
| 4914 | |
| 4915 | __ bind(&skip_parameter_map); |
| 4916 | // r2 = argument count (tagged) |
| 4917 | // r3 = address of backing store (tagged) |
| 4918 | // r5 = scratch |
| 4919 | // Copy arguments header and remaining slots (if there are any). |
| 4920 | __ LoadRoot(r5, Heap::kFixedArrayMapRootIndex); |
| 4921 | __ str(r5, FieldMemOperand(r3, FixedArray::kMapOffset)); |
| 4922 | __ str(r2, FieldMemOperand(r3, FixedArray::kLengthOffset)); |
| 4923 | |
| 4924 | Label arguments_loop, arguments_test; |
| 4925 | __ mov(r9, r1); |
| 4926 | __ ldr(r4, MemOperand(sp, 1 * kPointerSize)); |
| 4927 | __ sub(r4, r4, Operand(r9, LSL, 1)); |
| 4928 | __ jmp(&arguments_test); |
| 4929 | |
| 4930 | __ bind(&arguments_loop); |
| 4931 | __ sub(r4, r4, Operand(kPointerSize)); |
| 4932 | __ ldr(r6, MemOperand(r4, 0)); |
| 4933 | __ add(r5, r3, Operand(r9, LSL, 1)); |
| 4934 | __ str(r6, FieldMemOperand(r5, FixedArray::kHeaderSize)); |
| 4935 | __ add(r9, r9, Operand(Smi::FromInt(1))); |
| 4936 | |
| 4937 | __ bind(&arguments_test); |
| 4938 | __ cmp(r9, Operand(r2)); |
| 4939 | __ b(lt, &arguments_loop); |
| 4940 | |
| 4941 | // Return and remove the on-stack parameters. |
| 4942 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 4943 | __ Ret(); |
| 4944 | |
| 4945 | // Do the runtime call to allocate the arguments object. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4946 | // r2 = argument count (tagged) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4947 | __ bind(&runtime); |
| 4948 | __ str(r2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count. |
| 4949 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 4950 | } |
| 4951 | |
| 4952 | |
| 4953 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 4954 | // sp[0] : number of parameters |
| 4955 | // sp[4] : receiver displacement |
| 4956 | // sp[8] : function |
| 4957 | // Check if the calling frame is an arguments adaptor frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4958 | Label adaptor_frame, try_allocate, runtime; |
| 4959 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4960 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 4961 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4962 | __ b(eq, &adaptor_frame); |
| 4963 | |
| 4964 | // Get the length from the frame. |
| 4965 | __ ldr(r1, MemOperand(sp, 0)); |
| 4966 | __ b(&try_allocate); |
| 4967 | |
| 4968 | // Patch the arguments.length and the parameters pointer. |
| 4969 | __ bind(&adaptor_frame); |
| 4970 | __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4971 | __ str(r1, MemOperand(sp, 0)); |
| 4972 | __ add(r3, r2, Operand(r1, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 4973 | __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 4974 | __ str(r3, MemOperand(sp, 1 * kPointerSize)); |
| 4975 | |
| 4976 | // Try the new space allocation. Start out with computing the size |
| 4977 | // of the arguments object and the elements array in words. |
| 4978 | Label add_arguments_object; |
| 4979 | __ bind(&try_allocate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4980 | __ cmp(r1, Operand::Zero()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4981 | __ b(eq, &add_arguments_object); |
| 4982 | __ mov(r1, Operand(r1, LSR, kSmiTagSize)); |
| 4983 | __ add(r1, r1, Operand(FixedArray::kHeaderSize / kPointerSize)); |
| 4984 | __ bind(&add_arguments_object); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4985 | __ add(r1, r1, Operand(Heap::kArgumentsObjectSizeStrict / kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4986 | |
| 4987 | // Do the allocation of both objects in one go. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4988 | __ AllocateInNewSpace(r1, |
| 4989 | r0, |
| 4990 | r2, |
| 4991 | r3, |
| 4992 | &runtime, |
| 4993 | static_cast<AllocationFlags>(TAG_OBJECT | |
| 4994 | SIZE_IN_WORDS)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4995 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4996 | // Get the arguments boilerplate from the current native context. |
| 4997 | __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 4998 | __ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4999 | __ ldr(r4, MemOperand(r4, Context::SlotOffset( |
| 5000 | Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5001 | |
| 5002 | // Copy the JS object part. |
| 5003 | __ CopyFields(r0, r4, r3.bit(), JSObject::kHeaderSize / kPointerSize); |
| 5004 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5005 | // Get the length (smi tagged) and set that as an in-object property too. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5006 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5007 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5008 | __ str(r1, FieldMemOperand(r0, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5009 | Heap::kArgumentsLengthIndex * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5010 | |
| 5011 | // If there are no actual arguments, we're done. |
| 5012 | Label done; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5013 | __ cmp(r1, Operand::Zero()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5014 | __ b(eq, &done); |
| 5015 | |
| 5016 | // Get the parameters pointer from the stack. |
| 5017 | __ ldr(r2, MemOperand(sp, 1 * kPointerSize)); |
| 5018 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5019 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5020 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5021 | __ add(r4, r0, Operand(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5022 | __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 5023 | __ LoadRoot(r3, Heap::kFixedArrayMapRootIndex); |
| 5024 | __ str(r3, FieldMemOperand(r4, FixedArray::kMapOffset)); |
| 5025 | __ str(r1, FieldMemOperand(r4, FixedArray::kLengthOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5026 | // Untag the length for the loop. |
| 5027 | __ mov(r1, Operand(r1, LSR, kSmiTagSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5028 | |
| 5029 | // Copy the fixed array slots. |
| 5030 | Label loop; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5031 | // Set up r4 to point to the first array slot. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5032 | __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5033 | __ bind(&loop); |
| 5034 | // Pre-decrement r2 with kPointerSize on each iteration. |
| 5035 | // Pre-decrement in order to skip receiver. |
| 5036 | __ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex)); |
| 5037 | // Post-increment r4 with kPointerSize on each iteration. |
| 5038 | __ str(r3, MemOperand(r4, kPointerSize, PostIndex)); |
| 5039 | __ sub(r1, r1, Operand(1)); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5040 | __ cmp(r1, Operand::Zero()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5041 | __ b(ne, &loop); |
| 5042 | |
| 5043 | // Return and remove the on-stack parameters. |
| 5044 | __ bind(&done); |
| 5045 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 5046 | __ Ret(); |
| 5047 | |
| 5048 | // Do the runtime call to allocate the arguments object. |
| 5049 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5050 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | |
| 5054 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 5055 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 5056 | // time or if regexp entry in generated code is turned off runtime switch or |
| 5057 | // at compilation. |
| 5058 | #ifdef V8_INTERPRETED_REGEXP |
| 5059 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 5060 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5061 | |
| 5062 | // Stack frame on entry. |
| 5063 | // sp[0]: last_match_info (expected JSArray) |
| 5064 | // sp[4]: previous index |
| 5065 | // sp[8]: subject string |
| 5066 | // sp[12]: JSRegExp object |
| 5067 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5068 | const int kLastMatchInfoOffset = 0 * kPointerSize; |
| 5069 | const int kPreviousIndexOffset = 1 * kPointerSize; |
| 5070 | const int kSubjectOffset = 2 * kPointerSize; |
| 5071 | const int kJSRegExpOffset = 3 * kPointerSize; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5072 | |
| 5073 | Label runtime, invoke_regexp; |
| 5074 | |
| 5075 | // Allocation of registers for this function. These are in callee save |
| 5076 | // registers and will be preserved by the call to the native RegExp code, as |
| 5077 | // this code is called using the normal C calling convention. When calling |
| 5078 | // directly from generated code the native RegExp code will not do a GC and |
| 5079 | // therefore the content of these registers are safe to use after the call. |
| 5080 | Register subject = r4; |
| 5081 | Register regexp_data = r5; |
| 5082 | Register last_match_info_elements = r6; |
| 5083 | |
| 5084 | // Ensure that a RegExp stack is allocated. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5085 | Isolate* isolate = masm->isolate(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5086 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5087 | ExternalReference::address_of_regexp_stack_memory_address(isolate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5088 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5089 | ExternalReference::address_of_regexp_stack_memory_size(isolate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5090 | __ mov(r0, Operand(address_of_regexp_stack_memory_size)); |
| 5091 | __ ldr(r0, MemOperand(r0, 0)); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5092 | __ cmp(r0, Operand::Zero()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5093 | __ b(eq, &runtime); |
| 5094 | |
| 5095 | // Check that the first argument is a JSRegExp object. |
| 5096 | __ ldr(r0, MemOperand(sp, kJSRegExpOffset)); |
| 5097 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5098 | __ JumpIfSmi(r0, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5099 | __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE); |
| 5100 | __ b(ne, &runtime); |
| 5101 | |
| 5102 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 5103 | __ ldr(regexp_data, FieldMemOperand(r0, JSRegExp::kDataOffset)); |
| 5104 | if (FLAG_debug_code) { |
| 5105 | __ tst(regexp_data, Operand(kSmiTagMask)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 5106 | __ Check(ne, "Unexpected type for RegExp data, FixedArray expected"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5107 | __ CompareObjectType(regexp_data, r0, r0, FIXED_ARRAY_TYPE); |
| 5108 | __ Check(eq, "Unexpected type for RegExp data, FixedArray expected"); |
| 5109 | } |
| 5110 | |
| 5111 | // regexp_data: RegExp data (FixedArray) |
| 5112 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 5113 | __ ldr(r0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset)); |
| 5114 | __ cmp(r0, Operand(Smi::FromInt(JSRegExp::IRREGEXP))); |
| 5115 | __ b(ne, &runtime); |
| 5116 | |
| 5117 | // regexp_data: RegExp data (FixedArray) |
| 5118 | // Check that the number of captures fit in the static offsets vector buffer. |
| 5119 | __ ldr(r2, |
| 5120 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 5121 | // Calculate number of capture registers (number_of_captures + 1) * 2. This |
| 5122 | // uses the asumption that smis are 2 * their untagged value. |
| 5123 | STATIC_ASSERT(kSmiTag == 0); |
| 5124 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 5125 | __ add(r2, r2, Operand(2)); // r2 was a smi. |
| 5126 | // Check that the static offsets vector buffer is large enough. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5127 | __ cmp(r2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5128 | __ b(hi, &runtime); |
| 5129 | |
| 5130 | // r2: Number of capture registers |
| 5131 | // regexp_data: RegExp data (FixedArray) |
| 5132 | // Check that the second argument is a string. |
| 5133 | __ ldr(subject, MemOperand(sp, kSubjectOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5134 | __ JumpIfSmi(subject, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5135 | Condition is_string = masm->IsObjectStringType(subject, r0); |
| 5136 | __ b(NegateCondition(is_string), &runtime); |
| 5137 | // Get the length of the string to r3. |
| 5138 | __ ldr(r3, FieldMemOperand(subject, String::kLengthOffset)); |
| 5139 | |
| 5140 | // r2: Number of capture registers |
| 5141 | // r3: Length of subject string as a smi |
| 5142 | // subject: Subject string |
| 5143 | // regexp_data: RegExp data (FixedArray) |
| 5144 | // Check that the third argument is a positive smi less than the subject |
| 5145 | // string length. A negative value will be greater (unsigned comparison). |
| 5146 | __ ldr(r0, MemOperand(sp, kPreviousIndexOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5147 | __ JumpIfNotSmi(r0, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5148 | __ cmp(r3, Operand(r0)); |
| 5149 | __ b(ls, &runtime); |
| 5150 | |
| 5151 | // r2: Number of capture registers |
| 5152 | // subject: Subject string |
| 5153 | // regexp_data: RegExp data (FixedArray) |
| 5154 | // Check that the fourth object is a JSArray object. |
| 5155 | __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5156 | __ JumpIfSmi(r0, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5157 | __ CompareObjectType(r0, r1, r1, JS_ARRAY_TYPE); |
| 5158 | __ b(ne, &runtime); |
| 5159 | // Check that the JSArray is in fast case. |
| 5160 | __ ldr(last_match_info_elements, |
| 5161 | FieldMemOperand(r0, JSArray::kElementsOffset)); |
| 5162 | __ ldr(r0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5163 | __ CompareRoot(r0, Heap::kFixedArrayMapRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5164 | __ b(ne, &runtime); |
| 5165 | // Check that the last match info has space for the capture registers and the |
| 5166 | // additional information. |
| 5167 | __ ldr(r0, |
| 5168 | FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset)); |
| 5169 | __ add(r2, r2, Operand(RegExpImpl::kLastMatchOverhead)); |
| 5170 | __ cmp(r2, Operand(r0, ASR, kSmiTagSize)); |
| 5171 | __ b(gt, &runtime); |
| 5172 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5173 | // Reset offset for possibly sliced string. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5174 | __ mov(r9, Operand::Zero()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5175 | // subject: Subject string |
| 5176 | // regexp_data: RegExp data (FixedArray) |
| 5177 | // Check the representation and encoding of the subject string. |
| 5178 | Label seq_string; |
| 5179 | __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 5180 | __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5181 | // First check for flat string. None of the following string type tests will |
| 5182 | // succeed if subject is not a string or a short external string. |
| 5183 | __ and_(r1, |
| 5184 | r0, |
| 5185 | Operand(kIsNotStringMask | |
| 5186 | kStringRepresentationMask | |
| 5187 | kShortExternalStringMask), |
| 5188 | SetCC); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5189 | STATIC_ASSERT((kStringTag | kSeqStringTag) == 0); |
| 5190 | __ b(eq, &seq_string); |
| 5191 | |
| 5192 | // subject: Subject string |
| 5193 | // regexp_data: RegExp data (FixedArray) |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5194 | // r1: whether subject is a string and if yes, its string representation |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5195 | // Check for flat cons string or sliced string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5196 | // A flat cons string is a cons string where the second part is the empty |
| 5197 | // string. In that case the subject string is just the first part of the cons |
| 5198 | // string. Also in this case the first part of the cons string is known to be |
| 5199 | // a sequential string or an external string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5200 | // 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] | 5201 | Label cons_string, external_string, check_encoding; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5202 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 5203 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5204 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 5205 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5206 | __ cmp(r1, Operand(kExternalStringTag)); |
| 5207 | __ b(lt, &cons_string); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5208 | __ b(eq, &external_string); |
| 5209 | |
| 5210 | // Catch non-string subject or short external string. |
| 5211 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 5212 | __ tst(r1, Operand(kIsNotStringMask | kShortExternalStringMask)); |
| 5213 | __ b(ne, &runtime); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5214 | |
| 5215 | // String is sliced. |
| 5216 | __ ldr(r9, FieldMemOperand(subject, SlicedString::kOffsetOffset)); |
| 5217 | __ mov(r9, Operand(r9, ASR, kSmiTagSize)); |
| 5218 | __ ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset)); |
| 5219 | // r9: offset of sliced string, smi-tagged. |
| 5220 | __ jmp(&check_encoding); |
| 5221 | // String is a cons string, check whether it is flat. |
| 5222 | __ bind(&cons_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5223 | __ ldr(r0, FieldMemOperand(subject, ConsString::kSecondOffset)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5224 | __ CompareRoot(r0, Heap::kEmptyStringRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5225 | __ b(ne, &runtime); |
| 5226 | __ ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5227 | // Is first part of cons or parent of slice a flat string? |
| 5228 | __ bind(&check_encoding); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5229 | __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 5230 | __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5231 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5232 | __ tst(r0, Operand(kStringRepresentationMask)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5233 | __ b(ne, &external_string); |
| 5234 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5235 | __ bind(&seq_string); |
| 5236 | // subject: Subject string |
| 5237 | // regexp_data: RegExp data (FixedArray) |
| 5238 | // r0: Instance type of subject string |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5239 | STATIC_ASSERT(4 == kOneByteStringTag); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5240 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5241 | // Find the code object based on the assumptions above. |
| 5242 | __ and_(r0, r0, Operand(kStringEncodingMask)); |
| 5243 | __ mov(r3, Operand(r0, ASR, 2), SetCC); |
| 5244 | __ ldr(r7, FieldMemOperand(regexp_data, JSRegExp::kDataAsciiCodeOffset), ne); |
| 5245 | __ ldr(r7, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset), eq); |
| 5246 | |
| 5247 | // Check that the irregexp code has been generated for the actual string |
| 5248 | // 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] | 5249 | // a smi (code flushing support). |
| 5250 | __ JumpIfSmi(r7, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5251 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5252 | // r3: encoding of subject string (1 if ASCII, 0 if two_byte); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5253 | // r7: code |
| 5254 | // subject: Subject string |
| 5255 | // regexp_data: RegExp data (FixedArray) |
| 5256 | // Load used arguments before starting to push arguments for call to native |
| 5257 | // RegExp code to avoid handling changing stack height. |
| 5258 | __ ldr(r1, MemOperand(sp, kPreviousIndexOffset)); |
| 5259 | __ mov(r1, Operand(r1, ASR, kSmiTagSize)); |
| 5260 | |
| 5261 | // r1: previous index |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5262 | // r3: encoding of subject string (1 if ASCII, 0 if two_byte); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5263 | // r7: code |
| 5264 | // subject: Subject string |
| 5265 | // regexp_data: RegExp data (FixedArray) |
| 5266 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5267 | __ IncrementCounter(isolate->counters()->regexp_entry_native(), 1, r0, r2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5268 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5269 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 5270 | const int kRegExpExecuteArguments = 9; |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5271 | const int kParameterRegisters = 4; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5272 | __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5273 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5274 | // Stack pointer now points to cell where return address is to be written. |
| 5275 | // Arguments are before that on the stack or in registers. |
| 5276 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 5277 | // Argument 9 (sp[20]): Pass current isolate address. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5278 | __ mov(r0, Operand(ExternalReference::isolate_address())); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 5279 | __ str(r0, MemOperand(sp, 5 * kPointerSize)); |
| 5280 | |
| 5281 | // Argument 8 (sp[16]): Indicate that this is a direct call from JavaScript. |
| 5282 | __ mov(r0, Operand(1)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5283 | __ str(r0, MemOperand(sp, 4 * kPointerSize)); |
| 5284 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 5285 | // Argument 7 (sp[12]): Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5286 | __ mov(r0, Operand(address_of_regexp_stack_memory_address)); |
| 5287 | __ ldr(r0, MemOperand(r0, 0)); |
| 5288 | __ mov(r2, Operand(address_of_regexp_stack_memory_size)); |
| 5289 | __ ldr(r2, MemOperand(r2, 0)); |
| 5290 | __ add(r0, r0, Operand(r2)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 5291 | __ str(r0, MemOperand(sp, 3 * kPointerSize)); |
| 5292 | |
| 5293 | // Argument 6: Set the number of capture registers to zero to force global |
| 5294 | // regexps to behave as non-global. This does not affect non-global regexps. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5295 | __ mov(r0, Operand::Zero()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5296 | __ str(r0, MemOperand(sp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5297 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5298 | // Argument 5 (sp[4]): static offsets vector buffer. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5299 | __ mov(r0, |
| 5300 | Operand(ExternalReference::address_of_static_offsets_vector(isolate))); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5301 | __ str(r0, MemOperand(sp, 1 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5302 | |
| 5303 | // For arguments 4 and 3 get string length, calculate start of string data and |
| 5304 | // calculate the shift of the index (0 for ASCII and 1 for two byte). |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5305 | __ add(r8, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5306 | __ eor(r3, r3, Operand(1)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5307 | // Load the length from the original subject string from the previous stack |
| 5308 | // frame. Therefore we have to use fp, which points exactly to two pointer |
| 5309 | // sizes below the previous sp. (Because creating a new stack frame pushes |
| 5310 | // the previous fp onto the stack and moves up sp by 2 * kPointerSize.) |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5311 | __ ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5312 | // If slice offset is not 0, load the length from the original sliced string. |
| 5313 | // Argument 4, r3: End of string data |
| 5314 | // Argument 3, r2: Start of string data |
| 5315 | // Prepare start and end index of the input. |
| 5316 | __ add(r9, r8, Operand(r9, LSL, r3)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5317 | __ add(r2, r9, Operand(r1, LSL, r3)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5318 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5319 | __ ldr(r8, FieldMemOperand(subject, String::kLengthOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5320 | __ mov(r8, Operand(r8, ASR, kSmiTagSize)); |
| 5321 | __ add(r3, r9, Operand(r8, LSL, r3)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5322 | |
| 5323 | // Argument 2 (r1): Previous index. |
| 5324 | // Already there |
| 5325 | |
| 5326 | // Argument 1 (r0): Subject string. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5327 | __ mov(r0, subject); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5328 | |
| 5329 | // Locate the code entry and call it. |
| 5330 | __ add(r7, r7, Operand(Code::kHeaderSize - kHeapObjectTag)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5331 | DirectCEntryStub stub; |
| 5332 | stub.GenerateCall(masm, r7); |
| 5333 | |
| 5334 | __ LeaveExitFrame(false, no_reg); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5335 | |
| 5336 | // r0: result |
| 5337 | // subject: subject string (callee saved) |
| 5338 | // regexp_data: RegExp data (callee saved) |
| 5339 | // last_match_info_elements: Last match info elements (callee saved) |
| 5340 | |
| 5341 | // Check the result. |
| 5342 | Label success; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5343 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 5344 | __ cmp(r0, Operand(1)); |
| 5345 | // We expect exactly one result since we force the called regexp to behave |
| 5346 | // as non-global. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5347 | __ b(eq, &success); |
| 5348 | Label failure; |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5349 | __ cmp(r0, Operand(NativeRegExpMacroAssembler::FAILURE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5350 | __ b(eq, &failure); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5351 | __ cmp(r0, Operand(NativeRegExpMacroAssembler::EXCEPTION)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5352 | // If not exception it can only be retry. Handle that in the runtime system. |
| 5353 | __ b(ne, &runtime); |
| 5354 | // Result must now be exception. If there is no pending exception already a |
| 5355 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 5356 | // haven't created the exception yet. Handle that in the runtime system. |
| 5357 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5358 | __ mov(r1, Operand(isolate->factory()->the_hole_value())); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5359 | __ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5360 | isolate))); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5361 | __ ldr(r0, MemOperand(r2, 0)); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5362 | __ cmp(r0, r1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5363 | __ b(eq, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5364 | |
| 5365 | __ str(r1, MemOperand(r2, 0)); // Clear pending exception. |
| 5366 | |
| 5367 | // Check if the exception is a termination. If so, throw as uncatchable. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5368 | __ CompareRoot(r0, Heap::kTerminationExceptionRootIndex); |
| 5369 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5370 | Label termination_exception; |
| 5371 | __ b(eq, &termination_exception); |
| 5372 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5373 | __ Throw(r0); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5374 | |
| 5375 | __ bind(&termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5376 | __ ThrowUncatchable(r0); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5377 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5378 | __ bind(&failure); |
| 5379 | // For failure and exception return null. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 5380 | __ mov(r0, Operand(masm->isolate()->factory()->null_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5381 | __ add(sp, sp, Operand(4 * kPointerSize)); |
| 5382 | __ Ret(); |
| 5383 | |
| 5384 | // Process the result from the native regexp code. |
| 5385 | __ bind(&success); |
| 5386 | __ ldr(r1, |
| 5387 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 5388 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 5389 | STATIC_ASSERT(kSmiTag == 0); |
| 5390 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 5391 | __ add(r1, r1, Operand(2)); // r1 was a smi. |
| 5392 | |
| 5393 | // r1: number of capture registers |
| 5394 | // r4: subject string |
| 5395 | // Store the capture count. |
| 5396 | __ mov(r2, Operand(r1, LSL, kSmiTagSize + kSmiShiftSize)); // To smi. |
| 5397 | __ str(r2, FieldMemOperand(last_match_info_elements, |
| 5398 | RegExpImpl::kLastCaptureCountOffset)); |
| 5399 | // Store last subject and last input. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5400 | __ str(subject, |
| 5401 | FieldMemOperand(last_match_info_elements, |
| 5402 | RegExpImpl::kLastSubjectOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5403 | __ mov(r2, subject); |
| 5404 | __ RecordWriteField(last_match_info_elements, |
| 5405 | RegExpImpl::kLastSubjectOffset, |
| 5406 | r2, |
| 5407 | r7, |
| 5408 | kLRHasNotBeenSaved, |
| 5409 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5410 | __ str(subject, |
| 5411 | FieldMemOperand(last_match_info_elements, |
| 5412 | RegExpImpl::kLastInputOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5413 | __ RecordWriteField(last_match_info_elements, |
| 5414 | RegExpImpl::kLastInputOffset, |
| 5415 | subject, |
| 5416 | r7, |
| 5417 | kLRHasNotBeenSaved, |
| 5418 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5419 | |
| 5420 | // Get the static offsets vector filled by the native regexp code. |
| 5421 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5422 | ExternalReference::address_of_static_offsets_vector(isolate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5423 | __ mov(r2, Operand(address_of_static_offsets_vector)); |
| 5424 | |
| 5425 | // r1: number of capture registers |
| 5426 | // r2: offsets vector |
| 5427 | Label next_capture, done; |
| 5428 | // Capture register counter starts from number of capture registers and |
| 5429 | // counts down until wraping after zero. |
| 5430 | __ add(r0, |
| 5431 | last_match_info_elements, |
| 5432 | Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag)); |
| 5433 | __ bind(&next_capture); |
| 5434 | __ sub(r1, r1, Operand(1), SetCC); |
| 5435 | __ b(mi, &done); |
| 5436 | // Read the value from the static offsets vector buffer. |
| 5437 | __ ldr(r3, MemOperand(r2, kPointerSize, PostIndex)); |
| 5438 | // Store the smi value in the last match info. |
| 5439 | __ mov(r3, Operand(r3, LSL, kSmiTagSize)); |
| 5440 | __ str(r3, MemOperand(r0, kPointerSize, PostIndex)); |
| 5441 | __ jmp(&next_capture); |
| 5442 | __ bind(&done); |
| 5443 | |
| 5444 | // Return last match info. |
| 5445 | __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset)); |
| 5446 | __ add(sp, sp, Operand(4 * kPointerSize)); |
| 5447 | __ Ret(); |
| 5448 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5449 | // External string. Short external strings have already been ruled out. |
| 5450 | // r0: scratch |
| 5451 | __ bind(&external_string); |
| 5452 | __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 5453 | __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset)); |
| 5454 | if (FLAG_debug_code) { |
| 5455 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 5456 | // Sequential strings have already been ruled out. |
| 5457 | __ tst(r0, Operand(kIsIndirectStringMask)); |
| 5458 | __ Assert(eq, "external string expected, but not found"); |
| 5459 | } |
| 5460 | __ ldr(subject, |
| 5461 | FieldMemOperand(subject, ExternalString::kResourceDataOffset)); |
| 5462 | // 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] | 5463 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5464 | __ sub(subject, |
| 5465 | subject, |
| 5466 | Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5467 | __ jmp(&seq_string); |
| 5468 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5469 | // Do the runtime call to execute the regexp. |
| 5470 | __ bind(&runtime); |
| 5471 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 5472 | #endif // V8_INTERPRETED_REGEXP |
| 5473 | } |
| 5474 | |
| 5475 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5476 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 5477 | const int kMaxInlineLength = 100; |
| 5478 | Label slowcase; |
| 5479 | Label done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 5480 | Factory* factory = masm->isolate()->factory(); |
| 5481 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5482 | __ ldr(r1, MemOperand(sp, kPointerSize * 2)); |
| 5483 | STATIC_ASSERT(kSmiTag == 0); |
| 5484 | STATIC_ASSERT(kSmiTagSize == 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5485 | __ JumpIfNotSmi(r1, &slowcase); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5486 | __ cmp(r1, Operand(Smi::FromInt(kMaxInlineLength))); |
| 5487 | __ b(hi, &slowcase); |
| 5488 | // Smi-tagging is equivalent to multiplying by 2. |
| 5489 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 5490 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 5491 | // Elements: [Map][Length][..elements..] |
| 5492 | // Size of JSArray with two in-object properties and the header of a |
| 5493 | // FixedArray. |
| 5494 | int objects_size = |
| 5495 | (JSRegExpResult::kSize + FixedArray::kHeaderSize) / kPointerSize; |
| 5496 | __ mov(r5, Operand(r1, LSR, kSmiTagSize + kSmiShiftSize)); |
| 5497 | __ add(r2, r5, Operand(objects_size)); |
| 5498 | __ AllocateInNewSpace( |
| 5499 | r2, // In: Size, in words. |
| 5500 | r0, // Out: Start of allocation (tagged). |
| 5501 | r3, // Scratch register. |
| 5502 | r4, // Scratch register. |
| 5503 | &slowcase, |
| 5504 | static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS)); |
| 5505 | // r0: Start of allocated area, object-tagged. |
| 5506 | // r1: Number of elements in array, as smi. |
| 5507 | // r5: Number of elements, untagged. |
| 5508 | |
| 5509 | // Set JSArray map to global.regexp_result_map(). |
| 5510 | // Set empty properties FixedArray. |
| 5511 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 5512 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5513 | __ ldr(r2, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5514 | __ add(r3, r0, Operand(JSRegExpResult::kSize)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 5515 | __ mov(r4, Operand(factory->empty_fixed_array())); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5516 | __ ldr(r2, FieldMemOperand(r2, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5517 | __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 5518 | __ ldr(r2, ContextOperand(r2, Context::REGEXP_RESULT_MAP_INDEX)); |
| 5519 | __ str(r4, FieldMemOperand(r0, JSObject::kPropertiesOffset)); |
| 5520 | __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5521 | |
| 5522 | // Set input, index and length fields from arguments. |
| 5523 | __ ldr(r1, MemOperand(sp, kPointerSize * 0)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5524 | __ ldr(r2, MemOperand(sp, kPointerSize * 1)); |
| 5525 | __ ldr(r6, MemOperand(sp, kPointerSize * 2)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5526 | __ str(r1, FieldMemOperand(r0, JSRegExpResult::kInputOffset)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5527 | __ str(r2, FieldMemOperand(r0, JSRegExpResult::kIndexOffset)); |
| 5528 | __ str(r6, FieldMemOperand(r0, JSArray::kLengthOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5529 | |
| 5530 | // Fill out the elements FixedArray. |
| 5531 | // r0: JSArray, tagged. |
| 5532 | // r3: FixedArray, tagged. |
| 5533 | // r5: Number of elements in array, untagged. |
| 5534 | |
| 5535 | // Set map. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 5536 | __ mov(r2, Operand(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5537 | __ str(r2, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 5538 | // Set FixedArray length. |
| 5539 | __ mov(r6, Operand(r5, LSL, kSmiTagSize)); |
| 5540 | __ str(r6, FieldMemOperand(r3, FixedArray::kLengthOffset)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5541 | // Fill contents of fixed-array with undefined. |
| 5542 | __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5543 | __ add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5544 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5545 | // r0: JSArray, tagged. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5546 | // r2: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5547 | // r3: Start of elements in FixedArray. |
| 5548 | // r5: Number of elements to fill. |
| 5549 | Label loop; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5550 | __ cmp(r5, Operand::Zero()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5551 | __ bind(&loop); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5552 | __ b(le, &done); // Jump if r5 is negative or zero. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5553 | __ sub(r5, r5, Operand(1), SetCC); |
| 5554 | __ str(r2, MemOperand(r3, r5, LSL, kPointerSizeLog2)); |
| 5555 | __ jmp(&loop); |
| 5556 | |
| 5557 | __ bind(&done); |
| 5558 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 5559 | __ Ret(); |
| 5560 | |
| 5561 | __ bind(&slowcase); |
| 5562 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 5563 | } |
| 5564 | |
| 5565 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5566 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 5567 | // Cache the called function in a global property cell. Cache states |
| 5568 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 5569 | // megamorphic. |
| 5570 | // r1 : the function to call |
| 5571 | // r2 : cache cell for call target |
| 5572 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5573 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5574 | ASSERT_EQ(*TypeFeedbackCells::MegamorphicSentinel(masm->isolate()), |
| 5575 | masm->isolate()->heap()->undefined_value()); |
| 5576 | ASSERT_EQ(*TypeFeedbackCells::UninitializedSentinel(masm->isolate()), |
| 5577 | masm->isolate()->heap()->the_hole_value()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5578 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5579 | // Load the cache state into r3. |
| 5580 | __ ldr(r3, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5581 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5582 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 5583 | // function without changing the state. |
| 5584 | __ cmp(r3, r1); |
| 5585 | __ b(eq, &done); |
| 5586 | __ CompareRoot(r3, Heap::kUndefinedValueRootIndex); |
| 5587 | __ b(eq, &done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5588 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5589 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 5590 | // megamorphic. |
| 5591 | __ CompareRoot(r3, Heap::kTheHoleValueRootIndex); |
| 5592 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 5593 | // write-barrier is needed. |
| 5594 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex, ne); |
| 5595 | __ str(ip, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset), ne); |
| 5596 | |
| 5597 | // An uninitialized cache is patched with the function. |
| 5598 | __ str(r1, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset), eq); |
| 5599 | // No need for a write barrier here - cells are rescanned. |
| 5600 | |
| 5601 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5602 | } |
| 5603 | |
| 5604 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5605 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5606 | // r1 : the function to call |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5607 | // r2 : cache cell for call target |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5608 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5609 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5610 | // The receiver might implicitly be the global object. This is |
| 5611 | // indicated by passing the hole as the receiver to the call |
| 5612 | // function stub. |
| 5613 | if (ReceiverMightBeImplicit()) { |
| 5614 | Label call; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5615 | // Get the receiver from the stack. |
| 5616 | // function, receiver [, arguments] |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5617 | __ ldr(r4, MemOperand(sp, argc_ * kPointerSize)); |
| 5618 | // Call as function is indicated with the hole. |
| 5619 | __ CompareRoot(r4, Heap::kTheHoleValueRootIndex); |
| 5620 | __ b(ne, &call); |
| 5621 | // Patch the receiver on the stack with the global receiver object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5622 | __ ldr(r3, |
| 5623 | MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 5624 | __ ldr(r3, FieldMemOperand(r3, GlobalObject::kGlobalReceiverOffset)); |
| 5625 | __ str(r3, MemOperand(sp, argc_ * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5626 | __ bind(&call); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5627 | } |
| 5628 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5629 | // Check that the function is really a JavaScript function. |
| 5630 | // r1: pushed function (to be verified) |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5631 | __ JumpIfSmi(r1, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5632 | // Get the map of the function object. |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 5633 | __ CompareObjectType(r1, r3, r3, JS_FUNCTION_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5634 | __ b(ne, &slow); |
| 5635 | |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 5636 | if (RecordCallTarget()) { |
| 5637 | GenerateRecordCallTarget(masm); |
| 5638 | } |
| 5639 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5640 | // Fast-case: Invoke the function now. |
| 5641 | // r1: pushed function |
| 5642 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5643 | |
| 5644 | if (ReceiverMightBeImplicit()) { |
| 5645 | Label call_as_function; |
| 5646 | __ CompareRoot(r4, Heap::kTheHoleValueRootIndex); |
| 5647 | __ b(eq, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5648 | __ InvokeFunction(r1, |
| 5649 | actual, |
| 5650 | JUMP_FUNCTION, |
| 5651 | NullCallWrapper(), |
| 5652 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5653 | __ bind(&call_as_function); |
| 5654 | } |
| 5655 | __ InvokeFunction(r1, |
| 5656 | actual, |
| 5657 | JUMP_FUNCTION, |
| 5658 | NullCallWrapper(), |
| 5659 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5660 | |
| 5661 | // Slow-case: Non-function called. |
| 5662 | __ bind(&slow); |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 5663 | if (RecordCallTarget()) { |
| 5664 | // If there is a call target cache, mark it megamorphic in the |
| 5665 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 5666 | // object (undefined) so no write barrier is needed. |
| 5667 | ASSERT_EQ(*TypeFeedbackCells::MegamorphicSentinel(masm->isolate()), |
| 5668 | masm->isolate()->heap()->undefined_value()); |
| 5669 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 5670 | __ str(ip, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset)); |
| 5671 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5672 | // Check for function proxy. |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 5673 | __ cmp(r3, Operand(JS_FUNCTION_PROXY_TYPE)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5674 | __ b(ne, &non_function); |
| 5675 | __ push(r1); // put proxy as additional argument |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5676 | __ mov(r0, Operand(argc_ + 1, RelocInfo::NONE32)); |
| 5677 | __ mov(r2, Operand::Zero()); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5678 | __ GetBuiltinEntry(r3, Builtins::CALL_FUNCTION_PROXY); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5679 | __ SetCallKind(r5, CALL_AS_METHOD); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5680 | { |
| 5681 | Handle<Code> adaptor = |
| 5682 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 5683 | __ Jump(adaptor, RelocInfo::CODE_TARGET); |
| 5684 | } |
| 5685 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5686 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 5687 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5688 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5689 | __ str(r1, MemOperand(sp, argc_ * kPointerSize)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5690 | __ mov(r0, Operand(argc_)); // Set up the number of arguments. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5691 | __ mov(r2, Operand::Zero()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5692 | __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 5693 | __ SetCallKind(r5, CALL_AS_METHOD); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5694 | __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5695 | RelocInfo::CODE_TARGET); |
| 5696 | } |
| 5697 | |
| 5698 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5699 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 5700 | // r0 : number of arguments |
| 5701 | // r1 : the function to call |
| 5702 | // r2 : cache cell for call target |
| 5703 | Label slow, non_function_call; |
| 5704 | |
| 5705 | // Check that the function is not a smi. |
| 5706 | __ JumpIfSmi(r1, &non_function_call); |
| 5707 | // Check that the function is a JSFunction. |
| 5708 | __ CompareObjectType(r1, r3, r3, JS_FUNCTION_TYPE); |
| 5709 | __ b(ne, &slow); |
| 5710 | |
| 5711 | if (RecordCallTarget()) { |
| 5712 | GenerateRecordCallTarget(masm); |
| 5713 | } |
| 5714 | |
| 5715 | // Jump to the function-specific construct stub. |
| 5716 | __ ldr(r2, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 5717 | __ ldr(r2, FieldMemOperand(r2, SharedFunctionInfo::kConstructStubOffset)); |
| 5718 | __ add(pc, r2, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 5719 | |
| 5720 | // r0: number of arguments |
| 5721 | // r1: called object |
| 5722 | // r3: object type |
| 5723 | Label do_call; |
| 5724 | __ bind(&slow); |
| 5725 | __ cmp(r3, Operand(JS_FUNCTION_PROXY_TYPE)); |
| 5726 | __ b(ne, &non_function_call); |
| 5727 | __ GetBuiltinEntry(r3, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 5728 | __ jmp(&do_call); |
| 5729 | |
| 5730 | __ bind(&non_function_call); |
| 5731 | __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 5732 | __ bind(&do_call); |
| 5733 | // Set expected number of arguments to zero (not changing r0). |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5734 | __ mov(r2, Operand::Zero()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5735 | __ SetCallKind(r5, CALL_AS_METHOD); |
| 5736 | __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 5737 | RelocInfo::CODE_TARGET); |
| 5738 | } |
| 5739 | |
| 5740 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5741 | // StringCharCodeAtGenerator |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5742 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 5743 | Label flat_string; |
| 5744 | Label ascii_string; |
| 5745 | Label got_char_code; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5746 | Label sliced_string; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5747 | |
| 5748 | // If the receiver is a smi trigger the non-string case. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 5749 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5750 | |
| 5751 | // Fetch the instance type of the receiver into result register. |
| 5752 | __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 5753 | __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 5754 | // If the receiver is not a string trigger the non-string case. |
| 5755 | __ tst(result_, Operand(kIsNotStringMask)); |
| 5756 | __ b(ne, receiver_not_string_); |
| 5757 | |
| 5758 | // If the index is non-smi trigger the non-smi case. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 5759 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5760 | __ bind(&got_smi_index_); |
| 5761 | |
| 5762 | // Check for index out of range. |
| 5763 | __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5764 | __ cmp(ip, Operand(index_)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5765 | __ b(ls, index_out_of_range_); |
| 5766 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5767 | __ mov(index_, Operand(index_, ASR, kSmiTagSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5768 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5769 | StringCharLoadGenerator::Generate(masm, |
| 5770 | object_, |
| 5771 | index_, |
| 5772 | result_, |
| 5773 | &call_runtime_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5774 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5775 | __ mov(result_, Operand(result_, LSL, kSmiTagSize)); |
| 5776 | __ bind(&exit_); |
| 5777 | } |
| 5778 | |
| 5779 | |
| 5780 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5781 | MacroAssembler* masm, |
| 5782 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5783 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5784 | |
| 5785 | // Index is not a smi. |
| 5786 | __ bind(&index_not_smi_); |
| 5787 | // If index is a heap number, try converting it to an integer. |
| 5788 | __ CheckMap(index_, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5789 | result_, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5790 | Heap::kHeapNumberMapRootIndex, |
| 5791 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5792 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5793 | call_helper.BeforeCall(masm); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5794 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5795 | __ push(index_); // Consumed by runtime conversion function. |
| 5796 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5797 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5798 | } else { |
| 5799 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5800 | // NumberToSmi discards numbers that are not exact integers. |
| 5801 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5802 | } |
| 5803 | // Save the conversion result before the pop instructions below |
| 5804 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5805 | __ Move(index_, r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5806 | __ pop(object_); |
| 5807 | // Reload the instance type. |
| 5808 | __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 5809 | __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 5810 | call_helper.AfterCall(masm); |
| 5811 | // 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] | 5812 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5813 | // Otherwise, return to the fast path. |
| 5814 | __ jmp(&got_smi_index_); |
| 5815 | |
| 5816 | // Call runtime. We get here when the receiver is a string and the |
| 5817 | // index is a number, but the code of getting the actual character |
| 5818 | // is too complex (e.g., when the string needs to be flattened). |
| 5819 | __ bind(&call_runtime_); |
| 5820 | call_helper.BeforeCall(masm); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5821 | __ mov(index_, Operand(index_, LSL, kSmiTagSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5822 | __ Push(object_, index_); |
| 5823 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5824 | __ Move(result_, r0); |
| 5825 | call_helper.AfterCall(masm); |
| 5826 | __ jmp(&exit_); |
| 5827 | |
| 5828 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5829 | } |
| 5830 | |
| 5831 | |
| 5832 | // ------------------------------------------------------------------------- |
| 5833 | // StringCharFromCodeGenerator |
| 5834 | |
| 5835 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5836 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5837 | STATIC_ASSERT(kSmiTag == 0); |
| 5838 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5839 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5840 | __ tst(code_, |
| 5841 | Operand(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5842 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 5843 | __ b(ne, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5844 | |
| 5845 | __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5846 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5847 | STATIC_ASSERT(kSmiTag == 0); |
| 5848 | __ add(result_, result_, Operand(code_, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5849 | __ ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5850 | __ CompareRoot(result_, Heap::kUndefinedValueRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5851 | __ b(eq, &slow_case_); |
| 5852 | __ bind(&exit_); |
| 5853 | } |
| 5854 | |
| 5855 | |
| 5856 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5857 | MacroAssembler* masm, |
| 5858 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5859 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5860 | |
| 5861 | __ bind(&slow_case_); |
| 5862 | call_helper.BeforeCall(masm); |
| 5863 | __ push(code_); |
| 5864 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5865 | __ Move(result_, r0); |
| 5866 | call_helper.AfterCall(masm); |
| 5867 | __ jmp(&exit_); |
| 5868 | |
| 5869 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5870 | } |
| 5871 | |
| 5872 | |
| 5873 | // ------------------------------------------------------------------------- |
| 5874 | // StringCharAtGenerator |
| 5875 | |
| 5876 | void StringCharAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 5877 | char_code_at_generator_.GenerateFast(masm); |
| 5878 | char_from_code_generator_.GenerateFast(masm); |
| 5879 | } |
| 5880 | |
| 5881 | |
| 5882 | void StringCharAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5883 | MacroAssembler* masm, |
| 5884 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5885 | char_code_at_generator_.GenerateSlow(masm, call_helper); |
| 5886 | char_from_code_generator_.GenerateSlow(masm, call_helper); |
| 5887 | } |
| 5888 | |
| 5889 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5890 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5891 | Register dest, |
| 5892 | Register src, |
| 5893 | Register count, |
| 5894 | Register scratch, |
| 5895 | bool ascii) { |
| 5896 | Label loop; |
| 5897 | Label done; |
| 5898 | // This loop just copies one character at a time, as it is only used for very |
| 5899 | // short strings. |
| 5900 | if (!ascii) { |
| 5901 | __ add(count, count, Operand(count), SetCC); |
| 5902 | } else { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5903 | __ cmp(count, Operand::Zero()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5904 | } |
| 5905 | __ b(eq, &done); |
| 5906 | |
| 5907 | __ bind(&loop); |
| 5908 | __ ldrb(scratch, MemOperand(src, 1, PostIndex)); |
| 5909 | // Perform sub between load and dependent store to get the load time to |
| 5910 | // complete. |
| 5911 | __ sub(count, count, Operand(1), SetCC); |
| 5912 | __ strb(scratch, MemOperand(dest, 1, PostIndex)); |
| 5913 | // last iteration. |
| 5914 | __ b(gt, &loop); |
| 5915 | |
| 5916 | __ bind(&done); |
| 5917 | } |
| 5918 | |
| 5919 | |
| 5920 | enum CopyCharactersFlags { |
| 5921 | COPY_ASCII = 1, |
| 5922 | DEST_ALWAYS_ALIGNED = 2 |
| 5923 | }; |
| 5924 | |
| 5925 | |
| 5926 | void StringHelper::GenerateCopyCharactersLong(MacroAssembler* masm, |
| 5927 | Register dest, |
| 5928 | Register src, |
| 5929 | Register count, |
| 5930 | Register scratch1, |
| 5931 | Register scratch2, |
| 5932 | Register scratch3, |
| 5933 | Register scratch4, |
| 5934 | Register scratch5, |
| 5935 | int flags) { |
| 5936 | bool ascii = (flags & COPY_ASCII) != 0; |
| 5937 | bool dest_always_aligned = (flags & DEST_ALWAYS_ALIGNED) != 0; |
| 5938 | |
| 5939 | if (dest_always_aligned && FLAG_debug_code) { |
| 5940 | // Check that destination is actually word aligned if the flag says |
| 5941 | // that it is. |
| 5942 | __ tst(dest, Operand(kPointerAlignmentMask)); |
| 5943 | __ Check(eq, "Destination of copy not aligned."); |
| 5944 | } |
| 5945 | |
| 5946 | const int kReadAlignment = 4; |
| 5947 | const int kReadAlignmentMask = kReadAlignment - 1; |
| 5948 | // Ensure that reading an entire aligned word containing the last character |
| 5949 | // of a string will not read outside the allocated area (because we pad up |
| 5950 | // to kObjectAlignment). |
| 5951 | STATIC_ASSERT(kObjectAlignment >= kReadAlignment); |
| 5952 | // Assumes word reads and writes are little endian. |
| 5953 | // Nothing to do for zero characters. |
| 5954 | Label done; |
| 5955 | if (!ascii) { |
| 5956 | __ add(count, count, Operand(count), SetCC); |
| 5957 | } else { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5958 | __ cmp(count, Operand::Zero()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5959 | } |
| 5960 | __ b(eq, &done); |
| 5961 | |
| 5962 | // Assume that you cannot read (or write) unaligned. |
| 5963 | Label byte_loop; |
| 5964 | // Must copy at least eight bytes, otherwise just do it one byte at a time. |
| 5965 | __ cmp(count, Operand(8)); |
| 5966 | __ add(count, dest, Operand(count)); |
| 5967 | Register limit = count; // Read until src equals this. |
| 5968 | __ b(lt, &byte_loop); |
| 5969 | |
| 5970 | if (!dest_always_aligned) { |
| 5971 | // Align dest by byte copying. Copies between zero and three bytes. |
| 5972 | __ and_(scratch4, dest, Operand(kReadAlignmentMask), SetCC); |
| 5973 | Label dest_aligned; |
| 5974 | __ b(eq, &dest_aligned); |
| 5975 | __ cmp(scratch4, Operand(2)); |
| 5976 | __ ldrb(scratch1, MemOperand(src, 1, PostIndex)); |
| 5977 | __ ldrb(scratch2, MemOperand(src, 1, PostIndex), le); |
| 5978 | __ ldrb(scratch3, MemOperand(src, 1, PostIndex), lt); |
| 5979 | __ strb(scratch1, MemOperand(dest, 1, PostIndex)); |
| 5980 | __ strb(scratch2, MemOperand(dest, 1, PostIndex), le); |
| 5981 | __ strb(scratch3, MemOperand(dest, 1, PostIndex), lt); |
| 5982 | __ bind(&dest_aligned); |
| 5983 | } |
| 5984 | |
| 5985 | Label simple_loop; |
| 5986 | |
| 5987 | __ sub(scratch4, dest, Operand(src)); |
| 5988 | __ and_(scratch4, scratch4, Operand(0x03), SetCC); |
| 5989 | __ b(eq, &simple_loop); |
| 5990 | // Shift register is number of bits in a source word that |
| 5991 | // must be combined with bits in the next source word in order |
| 5992 | // to create a destination word. |
| 5993 | |
| 5994 | // Complex loop for src/dst that are not aligned the same way. |
| 5995 | { |
| 5996 | Label loop; |
| 5997 | __ mov(scratch4, Operand(scratch4, LSL, 3)); |
| 5998 | Register left_shift = scratch4; |
| 5999 | __ and_(src, src, Operand(~3)); // Round down to load previous word. |
| 6000 | __ ldr(scratch1, MemOperand(src, 4, PostIndex)); |
| 6001 | // Store the "shift" most significant bits of scratch in the least |
| 6002 | // signficant bits (i.e., shift down by (32-shift)). |
| 6003 | __ rsb(scratch2, left_shift, Operand(32)); |
| 6004 | Register right_shift = scratch2; |
| 6005 | __ mov(scratch1, Operand(scratch1, LSR, right_shift)); |
| 6006 | |
| 6007 | __ bind(&loop); |
| 6008 | __ ldr(scratch3, MemOperand(src, 4, PostIndex)); |
| 6009 | __ sub(scratch5, limit, Operand(dest)); |
| 6010 | __ orr(scratch1, scratch1, Operand(scratch3, LSL, left_shift)); |
| 6011 | __ str(scratch1, MemOperand(dest, 4, PostIndex)); |
| 6012 | __ mov(scratch1, Operand(scratch3, LSR, right_shift)); |
| 6013 | // Loop if four or more bytes left to copy. |
| 6014 | // Compare to eight, because we did the subtract before increasing dst. |
| 6015 | __ sub(scratch5, scratch5, Operand(8), SetCC); |
| 6016 | __ b(ge, &loop); |
| 6017 | } |
| 6018 | // There is now between zero and three bytes left to copy (negative that |
| 6019 | // number is in scratch5), and between one and three bytes already read into |
| 6020 | // scratch1 (eight times that number in scratch4). We may have read past |
| 6021 | // the end of the string, but because objects are aligned, we have not read |
| 6022 | // past the end of the object. |
| 6023 | // Find the minimum of remaining characters to move and preloaded characters |
| 6024 | // and write those as bytes. |
| 6025 | __ add(scratch5, scratch5, Operand(4), SetCC); |
| 6026 | __ b(eq, &done); |
| 6027 | __ cmp(scratch4, Operand(scratch5, LSL, 3), ne); |
| 6028 | // Move minimum of bytes read and bytes left to copy to scratch4. |
| 6029 | __ mov(scratch5, Operand(scratch4, LSR, 3), LeaveCC, lt); |
| 6030 | // Between one and three (value in scratch5) characters already read into |
| 6031 | // scratch ready to write. |
| 6032 | __ cmp(scratch5, Operand(2)); |
| 6033 | __ strb(scratch1, MemOperand(dest, 1, PostIndex)); |
| 6034 | __ mov(scratch1, Operand(scratch1, LSR, 8), LeaveCC, ge); |
| 6035 | __ strb(scratch1, MemOperand(dest, 1, PostIndex), ge); |
| 6036 | __ mov(scratch1, Operand(scratch1, LSR, 8), LeaveCC, gt); |
| 6037 | __ strb(scratch1, MemOperand(dest, 1, PostIndex), gt); |
| 6038 | // Copy any remaining bytes. |
| 6039 | __ b(&byte_loop); |
| 6040 | |
| 6041 | // Simple loop. |
| 6042 | // Copy words from src to dst, until less than four bytes left. |
| 6043 | // Both src and dest are word aligned. |
| 6044 | __ bind(&simple_loop); |
| 6045 | { |
| 6046 | Label loop; |
| 6047 | __ bind(&loop); |
| 6048 | __ ldr(scratch1, MemOperand(src, 4, PostIndex)); |
| 6049 | __ sub(scratch3, limit, Operand(dest)); |
| 6050 | __ str(scratch1, MemOperand(dest, 4, PostIndex)); |
| 6051 | // Compare to 8, not 4, because we do the substraction before increasing |
| 6052 | // dest. |
| 6053 | __ cmp(scratch3, Operand(8)); |
| 6054 | __ b(ge, &loop); |
| 6055 | } |
| 6056 | |
| 6057 | // Copy bytes from src to dst until dst hits limit. |
| 6058 | __ bind(&byte_loop); |
| 6059 | __ cmp(dest, Operand(limit)); |
| 6060 | __ ldrb(scratch1, MemOperand(src, 1, PostIndex), lt); |
| 6061 | __ b(ge, &done); |
| 6062 | __ strb(scratch1, MemOperand(dest, 1, PostIndex)); |
| 6063 | __ b(&byte_loop); |
| 6064 | |
| 6065 | __ bind(&done); |
| 6066 | } |
| 6067 | |
| 6068 | |
| 6069 | void StringHelper::GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 6070 | Register c1, |
| 6071 | Register c2, |
| 6072 | Register scratch1, |
| 6073 | Register scratch2, |
| 6074 | Register scratch3, |
| 6075 | Register scratch4, |
| 6076 | Register scratch5, |
| 6077 | Label* not_found) { |
| 6078 | // Register scratch3 is the general scratch register in this function. |
| 6079 | Register scratch = scratch3; |
| 6080 | |
| 6081 | // Make sure that both characters are not digits as such strings has a |
| 6082 | // different hash algorithm. Don't try to look for these in the symbol table. |
| 6083 | Label not_array_index; |
| 6084 | __ sub(scratch, c1, Operand(static_cast<int>('0'))); |
| 6085 | __ cmp(scratch, Operand(static_cast<int>('9' - '0'))); |
| 6086 | __ b(hi, ¬_array_index); |
| 6087 | __ sub(scratch, c2, Operand(static_cast<int>('0'))); |
| 6088 | __ cmp(scratch, Operand(static_cast<int>('9' - '0'))); |
| 6089 | |
| 6090 | // If check failed combine both characters into single halfword. |
| 6091 | // This is required by the contract of the method: code at the |
| 6092 | // not_found branch expects this combination in c1 register |
| 6093 | __ orr(c1, c1, Operand(c2, LSL, kBitsPerByte), LeaveCC, ls); |
| 6094 | __ b(ls, not_found); |
| 6095 | |
| 6096 | __ bind(¬_array_index); |
| 6097 | // Calculate the two character string hash. |
| 6098 | Register hash = scratch1; |
| 6099 | StringHelper::GenerateHashInit(masm, hash, c1); |
| 6100 | StringHelper::GenerateHashAddCharacter(masm, hash, c2); |
| 6101 | StringHelper::GenerateHashGetHash(masm, hash); |
| 6102 | |
| 6103 | // Collect the two characters in a register. |
| 6104 | Register chars = c1; |
| 6105 | __ orr(chars, chars, Operand(c2, LSL, kBitsPerByte)); |
| 6106 | |
| 6107 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6108 | // hash: hash of two character string. |
| 6109 | |
| 6110 | // Load symbol table |
| 6111 | // Load address of first element of the symbol table. |
| 6112 | Register symbol_table = c2; |
| 6113 | __ LoadRoot(symbol_table, Heap::kSymbolTableRootIndex); |
| 6114 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6115 | Register undefined = scratch4; |
| 6116 | __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex); |
| 6117 | |
| 6118 | // Calculate capacity mask from the symbol table capacity. |
| 6119 | Register mask = scratch2; |
| 6120 | __ ldr(mask, FieldMemOperand(symbol_table, SymbolTable::kCapacityOffset)); |
| 6121 | __ mov(mask, Operand(mask, ASR, 1)); |
| 6122 | __ sub(mask, mask, Operand(1)); |
| 6123 | |
| 6124 | // Calculate untagged address of the first element of the symbol table. |
| 6125 | Register first_symbol_table_element = symbol_table; |
| 6126 | __ add(first_symbol_table_element, symbol_table, |
| 6127 | Operand(SymbolTable::kElementsStartOffset - kHeapObjectTag)); |
| 6128 | |
| 6129 | // Registers |
| 6130 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6131 | // hash: hash of two character string |
| 6132 | // mask: capacity mask |
| 6133 | // first_symbol_table_element: address of the first element of |
| 6134 | // the symbol table |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6135 | // undefined: the undefined object |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6136 | // scratch: - |
| 6137 | |
| 6138 | // Perform a number of probes in the symbol table. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6139 | const int kProbes = 4; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6140 | Label found_in_symbol_table; |
| 6141 | Label next_probe[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6142 | Register candidate = scratch5; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6143 | for (int i = 0; i < kProbes; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6144 | // Calculate entry in symbol table. |
| 6145 | if (i > 0) { |
| 6146 | __ add(candidate, hash, Operand(SymbolTable::GetProbeOffset(i))); |
| 6147 | } else { |
| 6148 | __ mov(candidate, hash); |
| 6149 | } |
| 6150 | |
| 6151 | __ and_(candidate, candidate, Operand(mask)); |
| 6152 | |
| 6153 | // Load the entry from the symble table. |
| 6154 | STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
| 6155 | __ ldr(candidate, |
| 6156 | MemOperand(first_symbol_table_element, |
| 6157 | candidate, |
| 6158 | LSL, |
| 6159 | kPointerSizeLog2)); |
| 6160 | |
| 6161 | // If entry is undefined no string with this hash can be found. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6162 | Label is_string; |
| 6163 | __ CompareObjectType(candidate, scratch, scratch, ODDBALL_TYPE); |
| 6164 | __ b(ne, &is_string); |
| 6165 | |
| 6166 | __ cmp(undefined, candidate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6167 | __ b(eq, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6168 | // Must be the hole (deleted entry). |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6169 | if (FLAG_debug_code) { |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6170 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6171 | __ cmp(ip, candidate); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6172 | __ Assert(eq, "oddball in symbol table is not undefined or the hole"); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6173 | } |
| 6174 | __ jmp(&next_probe[i]); |
| 6175 | |
| 6176 | __ bind(&is_string); |
| 6177 | |
| 6178 | // Check that the candidate is a non-external ASCII string. The instance |
| 6179 | // type is still in the scratch register from the CompareObjectType |
| 6180 | // operation. |
| 6181 | __ JumpIfInstanceTypeIsNotSequentialAscii(scratch, scratch, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6182 | |
| 6183 | // If length is not 2 the string is not a candidate. |
| 6184 | __ ldr(scratch, FieldMemOperand(candidate, String::kLengthOffset)); |
| 6185 | __ cmp(scratch, Operand(Smi::FromInt(2))); |
| 6186 | __ b(ne, &next_probe[i]); |
| 6187 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6188 | // Check if the two characters match. |
| 6189 | // Assumes that word load is little endian. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6190 | __ ldrh(scratch, FieldMemOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6191 | __ cmp(chars, scratch); |
| 6192 | __ b(eq, &found_in_symbol_table); |
| 6193 | __ bind(&next_probe[i]); |
| 6194 | } |
| 6195 | |
| 6196 | // No matching 2 character string found by probing. |
| 6197 | __ jmp(not_found); |
| 6198 | |
| 6199 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6200 | Register result = candidate; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6201 | __ bind(&found_in_symbol_table); |
| 6202 | __ Move(r0, result); |
| 6203 | } |
| 6204 | |
| 6205 | |
| 6206 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 6207 | Register hash, |
| 6208 | Register character) { |
| 6209 | // hash = character + (character << 10); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6210 | __ LoadRoot(hash, Heap::kHashSeedRootIndex); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6211 | // Untag smi seed and add the character. |
| 6212 | __ add(hash, character, Operand(hash, LSR, kSmiTagSize)); |
| 6213 | // hash += hash << 10; |
| 6214 | __ add(hash, hash, Operand(hash, LSL, 10)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6215 | // hash ^= hash >> 6; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6216 | __ eor(hash, hash, Operand(hash, LSR, 6)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6217 | } |
| 6218 | |
| 6219 | |
| 6220 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 6221 | Register hash, |
| 6222 | Register character) { |
| 6223 | // hash += character; |
| 6224 | __ add(hash, hash, Operand(character)); |
| 6225 | // hash += hash << 10; |
| 6226 | __ add(hash, hash, Operand(hash, LSL, 10)); |
| 6227 | // hash ^= hash >> 6; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6228 | __ eor(hash, hash, Operand(hash, LSR, 6)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6229 | } |
| 6230 | |
| 6231 | |
| 6232 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 6233 | Register hash) { |
| 6234 | // hash += hash << 3; |
| 6235 | __ add(hash, hash, Operand(hash, LSL, 3)); |
| 6236 | // hash ^= hash >> 11; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6237 | __ eor(hash, hash, Operand(hash, LSR, 11)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6238 | // hash += hash << 15; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6239 | __ add(hash, hash, Operand(hash, LSL, 15)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6240 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6241 | __ and_(hash, hash, Operand(String::kHashBitMask), SetCC); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6242 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6243 | // if (hash == 0) hash = 27; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6244 | __ mov(hash, Operand(StringHasher::kZeroHash), LeaveCC, eq); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6245 | } |
| 6246 | |
| 6247 | |
| 6248 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6249 | Label runtime; |
| 6250 | |
| 6251 | // Stack frame on entry. |
| 6252 | // lr: return address |
| 6253 | // sp[0]: to |
| 6254 | // sp[4]: from |
| 6255 | // sp[8]: string |
| 6256 | |
| 6257 | // This stub is called from the native-call %_SubString(...), so |
| 6258 | // nothing can be assumed about the arguments. It is tested that: |
| 6259 | // "string" is a sequential string, |
| 6260 | // both "from" and "to" are smis, and |
| 6261 | // 0 <= from <= to <= string.length. |
| 6262 | // If any of these assumptions fail, we call the runtime system. |
| 6263 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6264 | const int kToOffset = 0 * kPointerSize; |
| 6265 | const int kFromOffset = 1 * kPointerSize; |
| 6266 | const int kStringOffset = 2 * kPointerSize; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6267 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6268 | __ Ldrd(r2, r3, MemOperand(sp, kToOffset)); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 6269 | STATIC_ASSERT(kFromOffset == kToOffset + 4); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6270 | STATIC_ASSERT(kSmiTag == 0); |
| 6271 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 6272 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6273 | // Arithmetic shift right by one un-smi-tags. In this case we rotate right |
| 6274 | // instead because we bail out on non-smi values: ROR and ASR are equivalent |
| 6275 | // for smis but they set the flags in a way that's easier to optimize. |
| 6276 | __ mov(r2, Operand(r2, ROR, 1), SetCC); |
| 6277 | __ mov(r3, Operand(r3, ROR, 1), SetCC, cc); |
| 6278 | // If either to or from had the smi tag bit set, then C is set now, and N |
| 6279 | // has the same value: we rotated by 1, so the bottom bit is now the top bit. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 6280 | // We want to bailout to runtime here if From is negative. In that case, the |
| 6281 | // next instruction is not executed and we fall through to bailing out to |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6282 | // runtime. |
| 6283 | // Executed if both r2 and r3 are untagged integers. |
| 6284 | __ sub(r2, r2, Operand(r3), SetCC, cc); |
| 6285 | // One of the above un-smis or the above SUB could have set N==1. |
| 6286 | __ b(mi, &runtime); // Either "from" or "to" is not an smi, or from > to. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6287 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6288 | // Make sure first argument is a string. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6289 | __ ldr(r0, MemOperand(sp, kStringOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6290 | STATIC_ASSERT(kSmiTag == 0); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6291 | // Do a JumpIfSmi, but fold its jump into the subsequent string test. |
| 6292 | __ tst(r0, Operand(kSmiTagMask)); |
| 6293 | Condition is_string = masm->IsObjectStringType(r0, r1, ne); |
| 6294 | ASSERT(is_string == eq); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6295 | __ b(NegateCondition(is_string), &runtime); |
| 6296 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6297 | // Short-cut for the case of trivial substring. |
| 6298 | Label return_r0; |
| 6299 | // r0: original string |
| 6300 | // r2: result string length |
| 6301 | __ ldr(r4, FieldMemOperand(r0, String::kLengthOffset)); |
| 6302 | __ cmp(r2, Operand(r4, ASR, 1)); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6303 | // Return original string. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6304 | __ b(eq, &return_r0); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6305 | // Longer than original string's length or negative: unsafe arguments. |
| 6306 | __ b(hi, &runtime); |
| 6307 | // Shorter than original string's length: an actual substring. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6308 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6309 | // Deal with different string types: update the index if necessary |
| 6310 | // and put the underlying string into r5. |
| 6311 | // r0: original string |
| 6312 | // r1: instance type |
| 6313 | // r2: length |
| 6314 | // r3: from index (untagged) |
| 6315 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6316 | // If the string is not indirect, it can only be sequential or external. |
| 6317 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6318 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6319 | __ tst(r1, Operand(kIsIndirectStringMask)); |
| 6320 | __ b(eq, &seq_or_external_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6321 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6322 | __ tst(r1, Operand(kSlicedNotConsMask)); |
| 6323 | __ b(ne, &sliced_string); |
| 6324 | // Cons string. Check whether it is flat, then fetch first part. |
| 6325 | __ ldr(r5, FieldMemOperand(r0, ConsString::kSecondOffset)); |
| 6326 | __ CompareRoot(r5, Heap::kEmptyStringRootIndex); |
| 6327 | __ b(ne, &runtime); |
| 6328 | __ ldr(r5, FieldMemOperand(r0, ConsString::kFirstOffset)); |
| 6329 | // Update instance type. |
| 6330 | __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset)); |
| 6331 | __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset)); |
| 6332 | __ jmp(&underlying_unpacked); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6333 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6334 | __ bind(&sliced_string); |
| 6335 | // Sliced string. Fetch parent and correct start index by offset. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6336 | __ ldr(r5, FieldMemOperand(r0, SlicedString::kParentOffset)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6337 | __ ldr(r4, FieldMemOperand(r0, SlicedString::kOffsetOffset)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 6338 | __ add(r3, r3, Operand(r4, ASR, 1)); // Add offset to index. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6339 | // Update instance type. |
| 6340 | __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset)); |
| 6341 | __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset)); |
| 6342 | __ jmp(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6343 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6344 | __ bind(&seq_or_external_string); |
| 6345 | // Sequential or external string. Just move string to the expected register. |
| 6346 | __ mov(r5, r0); |
| 6347 | |
| 6348 | __ bind(&underlying_unpacked); |
| 6349 | |
| 6350 | if (FLAG_string_slices) { |
| 6351 | Label copy_routine; |
| 6352 | // r5: underlying subject string |
| 6353 | // r1: instance type of underlying subject string |
| 6354 | // r2: length |
| 6355 | // r3: adjusted start index (untagged) |
| 6356 | __ cmp(r2, Operand(SlicedString::kMinLength)); |
| 6357 | // Short slice. Copy instead of slicing. |
| 6358 | __ b(lt, ©_routine); |
| 6359 | // Allocate new sliced string. At this point we do not reload the instance |
| 6360 | // type including the string encoding because we simply rely on the info |
| 6361 | // provided by the original string. It does not matter if the original |
| 6362 | // string's encoding is wrong because we always have to recheck encoding of |
| 6363 | // the newly created string's parent anyways due to externalized strings. |
| 6364 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6365 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6366 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6367 | __ tst(r1, Operand(kStringEncodingMask)); |
| 6368 | __ b(eq, &two_byte_slice); |
| 6369 | __ AllocateAsciiSlicedString(r0, r2, r6, r7, &runtime); |
| 6370 | __ jmp(&set_slice_header); |
| 6371 | __ bind(&two_byte_slice); |
| 6372 | __ AllocateTwoByteSlicedString(r0, r2, r6, r7, &runtime); |
| 6373 | __ bind(&set_slice_header); |
| 6374 | __ mov(r3, Operand(r3, LSL, 1)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6375 | __ str(r5, FieldMemOperand(r0, SlicedString::kParentOffset)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6376 | __ str(r3, FieldMemOperand(r0, SlicedString::kOffsetOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6377 | __ jmp(&return_r0); |
| 6378 | |
| 6379 | __ bind(©_routine); |
| 6380 | } |
| 6381 | |
| 6382 | // r5: underlying subject string |
| 6383 | // r1: instance type of underlying subject string |
| 6384 | // r2: length |
| 6385 | // r3: adjusted start index (untagged) |
| 6386 | Label two_byte_sequential, sequential_string, allocate_result; |
| 6387 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6388 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6389 | __ tst(r1, Operand(kExternalStringTag)); |
| 6390 | __ b(eq, &sequential_string); |
| 6391 | |
| 6392 | // Handle external string. |
| 6393 | // Rule out short external strings. |
| 6394 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6395 | __ tst(r1, Operand(kShortExternalStringTag)); |
| 6396 | __ b(ne, &runtime); |
| 6397 | __ ldr(r5, FieldMemOperand(r5, ExternalString::kResourceDataOffset)); |
| 6398 | // r5 already points to the first character of underlying string. |
| 6399 | __ jmp(&allocate_result); |
| 6400 | |
| 6401 | __ bind(&sequential_string); |
| 6402 | // Locate first character of underlying subject string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6403 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
| 6404 | __ add(r5, r5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6405 | |
| 6406 | __ bind(&allocate_result); |
| 6407 | // Sequential acii string. Allocate the result. |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6408 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6409 | __ tst(r1, Operand(kStringEncodingMask)); |
| 6410 | __ b(eq, &two_byte_sequential); |
| 6411 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6412 | // Allocate and copy the resulting ASCII string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6413 | __ AllocateAsciiString(r0, r2, r4, r6, r7, &runtime); |
| 6414 | |
| 6415 | // Locate first character of substring to copy. |
| 6416 | __ add(r5, r5, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6417 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6418 | __ add(r1, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6419 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6420 | // r0: result string |
| 6421 | // r1: first character of result string |
| 6422 | // r2: result string length |
| 6423 | // r5: first character of substring to copy |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6424 | STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6425 | StringHelper::GenerateCopyCharactersLong(masm, r1, r5, r2, r3, r4, r6, r7, r9, |
| 6426 | COPY_ASCII | DEST_ALWAYS_ALIGNED); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6427 | __ jmp(&return_r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6428 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6429 | // Allocate and copy the resulting two-byte string. |
| 6430 | __ bind(&two_byte_sequential); |
| 6431 | __ AllocateTwoByteString(r0, r2, r4, r6, r7, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6432 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6433 | // Locate first character of substring to copy. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6434 | STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6435 | __ add(r5, r5, Operand(r3, LSL, 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6436 | // Locate first character of result. |
| 6437 | __ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6438 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6439 | // r0: result string. |
| 6440 | // r1: first character of result. |
| 6441 | // r2: result length. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6442 | // r5: first character of substring to copy. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6443 | STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 6444 | StringHelper::GenerateCopyCharactersLong( |
| 6445 | masm, r1, r5, r2, r3, r4, r6, r7, r9, DEST_ALWAYS_ALIGNED); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6446 | |
| 6447 | __ bind(&return_r0); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6448 | Counters* counters = masm->isolate()->counters(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6449 | __ IncrementCounter(counters->sub_string_native(), 1, r3, r4); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6450 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 6451 | __ Ret(); |
| 6452 | |
| 6453 | // Just jump to runtime to create the sub string. |
| 6454 | __ bind(&runtime); |
| 6455 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
| 6456 | } |
| 6457 | |
| 6458 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6459 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6460 | Register left, |
| 6461 | Register right, |
| 6462 | Register scratch1, |
| 6463 | Register scratch2, |
| 6464 | Register scratch3) { |
| 6465 | Register length = scratch1; |
| 6466 | |
| 6467 | // Compare lengths. |
| 6468 | Label strings_not_equal, check_zero_length; |
| 6469 | __ ldr(length, FieldMemOperand(left, String::kLengthOffset)); |
| 6470 | __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 6471 | __ cmp(length, scratch2); |
| 6472 | __ b(eq, &check_zero_length); |
| 6473 | __ bind(&strings_not_equal); |
| 6474 | __ mov(r0, Operand(Smi::FromInt(NOT_EQUAL))); |
| 6475 | __ Ret(); |
| 6476 | |
| 6477 | // Check if the length is zero. |
| 6478 | Label compare_chars; |
| 6479 | __ bind(&check_zero_length); |
| 6480 | STATIC_ASSERT(kSmiTag == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6481 | __ cmp(length, Operand::Zero()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6482 | __ b(ne, &compare_chars); |
| 6483 | __ mov(r0, Operand(Smi::FromInt(EQUAL))); |
| 6484 | __ Ret(); |
| 6485 | |
| 6486 | // Compare characters. |
| 6487 | __ bind(&compare_chars); |
| 6488 | GenerateAsciiCharsCompareLoop(masm, |
| 6489 | left, right, length, scratch2, scratch3, |
| 6490 | &strings_not_equal); |
| 6491 | |
| 6492 | // Characters are equal. |
| 6493 | __ mov(r0, Operand(Smi::FromInt(EQUAL))); |
| 6494 | __ Ret(); |
| 6495 | } |
| 6496 | |
| 6497 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6498 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6499 | Register left, |
| 6500 | Register right, |
| 6501 | Register scratch1, |
| 6502 | Register scratch2, |
| 6503 | Register scratch3, |
| 6504 | Register scratch4) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6505 | Label result_not_equal, compare_lengths; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6506 | // Find minimum length and length difference. |
| 6507 | __ ldr(scratch1, FieldMemOperand(left, String::kLengthOffset)); |
| 6508 | __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 6509 | __ sub(scratch3, scratch1, Operand(scratch2), SetCC); |
| 6510 | Register length_delta = scratch3; |
| 6511 | __ mov(scratch1, scratch2, LeaveCC, gt); |
| 6512 | Register min_length = scratch1; |
| 6513 | STATIC_ASSERT(kSmiTag == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6514 | __ cmp(min_length, Operand::Zero()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6515 | __ b(eq, &compare_lengths); |
| 6516 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6517 | // Compare loop. |
| 6518 | GenerateAsciiCharsCompareLoop(masm, |
| 6519 | left, right, min_length, scratch2, scratch4, |
| 6520 | &result_not_equal); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6521 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6522 | // Compare lengths - strings up to min-length are equal. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6523 | __ bind(&compare_lengths); |
| 6524 | ASSERT(Smi::FromInt(EQUAL) == static_cast<Smi*>(0)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6525 | // Use length_delta as result if it's zero. |
| 6526 | __ mov(r0, Operand(length_delta), SetCC); |
| 6527 | __ bind(&result_not_equal); |
| 6528 | // Conditionally update the result based either on length_delta or |
| 6529 | // the last comparion performed in the loop above. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6530 | __ mov(r0, Operand(Smi::FromInt(GREATER)), LeaveCC, gt); |
| 6531 | __ mov(r0, Operand(Smi::FromInt(LESS)), LeaveCC, lt); |
| 6532 | __ Ret(); |
| 6533 | } |
| 6534 | |
| 6535 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6536 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6537 | MacroAssembler* masm, |
| 6538 | Register left, |
| 6539 | Register right, |
| 6540 | Register length, |
| 6541 | Register scratch1, |
| 6542 | Register scratch2, |
| 6543 | Label* chars_not_equal) { |
| 6544 | // Change index to run from -length to -1 by adding length to string |
| 6545 | // start. This means that loop ends when index reaches zero, which |
| 6546 | // doesn't need an additional compare. |
| 6547 | __ SmiUntag(length); |
| 6548 | __ add(scratch1, length, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6549 | Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6550 | __ add(left, left, Operand(scratch1)); |
| 6551 | __ add(right, right, Operand(scratch1)); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 6552 | __ rsb(length, length, Operand::Zero()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6553 | Register index = length; // index = -length; |
| 6554 | |
| 6555 | // Compare loop. |
| 6556 | Label loop; |
| 6557 | __ bind(&loop); |
| 6558 | __ ldrb(scratch1, MemOperand(left, index)); |
| 6559 | __ ldrb(scratch2, MemOperand(right, index)); |
| 6560 | __ cmp(scratch1, scratch2); |
| 6561 | __ b(ne, chars_not_equal); |
| 6562 | __ add(index, index, Operand(1), SetCC); |
| 6563 | __ b(ne, &loop); |
| 6564 | } |
| 6565 | |
| 6566 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6567 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6568 | Label runtime; |
| 6569 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6570 | Counters* counters = masm->isolate()->counters(); |
| 6571 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6572 | // Stack frame on entry. |
| 6573 | // sp[0]: right string |
| 6574 | // sp[4]: left string |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 6575 | __ Ldrd(r0 , r1, MemOperand(sp)); // Load right in r0, left in r1. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6576 | |
| 6577 | Label not_same; |
| 6578 | __ cmp(r0, r1); |
| 6579 | __ b(ne, ¬_same); |
| 6580 | STATIC_ASSERT(EQUAL == 0); |
| 6581 | STATIC_ASSERT(kSmiTag == 0); |
| 6582 | __ mov(r0, Operand(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6583 | __ IncrementCounter(counters->string_compare_native(), 1, r1, r2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6584 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6585 | __ Ret(); |
| 6586 | |
| 6587 | __ bind(¬_same); |
| 6588 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6589 | // Check that both objects are sequential ASCII strings. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 6590 | __ JumpIfNotBothSequentialAsciiStrings(r1, r0, r2, r3, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6591 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6592 | // Compare flat ASCII strings natively. Remove arguments from stack first. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6593 | __ IncrementCounter(counters->string_compare_native(), 1, r2, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6594 | __ add(sp, sp, Operand(2 * kPointerSize)); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 6595 | GenerateCompareFlatAsciiStrings(masm, r1, r0, r2, r3, r4, r5); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6596 | |
| 6597 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6598 | // tagged as a small integer. |
| 6599 | __ bind(&runtime); |
| 6600 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6601 | } |
| 6602 | |
| 6603 | |
| 6604 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6605 | Label call_runtime, call_builtin; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6606 | Builtins::JavaScript builtin_id = Builtins::ADD; |
| 6607 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6608 | Counters* counters = masm->isolate()->counters(); |
| 6609 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6610 | // Stack on entry: |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6611 | // sp[0]: second argument (right). |
| 6612 | // sp[4]: first argument (left). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6613 | |
| 6614 | // Load the two arguments. |
| 6615 | __ ldr(r0, MemOperand(sp, 1 * kPointerSize)); // First argument. |
| 6616 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); // Second argument. |
| 6617 | |
| 6618 | // 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] | 6619 | if (flags_ == NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6620 | __ JumpIfEitherSmi(r0, r1, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6621 | // Load instance types. |
| 6622 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 6623 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 6624 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 6625 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 6626 | STATIC_ASSERT(kStringTag == 0); |
| 6627 | // If either is not a string, go to runtime. |
| 6628 | __ tst(r4, Operand(kIsNotStringMask)); |
| 6629 | __ tst(r5, Operand(kIsNotStringMask), eq); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6630 | __ b(ne, &call_runtime); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6631 | } else { |
| 6632 | // Here at least one of the arguments is definitely a string. |
| 6633 | // We convert the one that is not known to be a string. |
| 6634 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 6635 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 6636 | GenerateConvertArgument( |
| 6637 | masm, 1 * kPointerSize, r0, r2, r3, r4, r5, &call_builtin); |
| 6638 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 6639 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 6640 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 6641 | GenerateConvertArgument( |
| 6642 | masm, 0 * kPointerSize, r1, r2, r3, r4, r5, &call_builtin); |
| 6643 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 6644 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6645 | } |
| 6646 | |
| 6647 | // Both arguments are strings. |
| 6648 | // r0: first string |
| 6649 | // r1: second string |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6650 | // r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 6651 | // r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6652 | { |
| 6653 | Label strings_not_empty; |
| 6654 | // Check if either of the strings are empty. In that case return the other. |
| 6655 | __ ldr(r2, FieldMemOperand(r0, String::kLengthOffset)); |
| 6656 | __ ldr(r3, FieldMemOperand(r1, String::kLengthOffset)); |
| 6657 | STATIC_ASSERT(kSmiTag == 0); |
| 6658 | __ cmp(r2, Operand(Smi::FromInt(0))); // Test if first string is empty. |
| 6659 | __ mov(r0, Operand(r1), LeaveCC, eq); // If first is empty, return second. |
| 6660 | STATIC_ASSERT(kSmiTag == 0); |
| 6661 | // Else test if second string is empty. |
| 6662 | __ cmp(r3, Operand(Smi::FromInt(0)), ne); |
| 6663 | __ b(ne, &strings_not_empty); // If either string was empty, return r0. |
| 6664 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6665 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6666 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6667 | __ Ret(); |
| 6668 | |
| 6669 | __ bind(&strings_not_empty); |
| 6670 | } |
| 6671 | |
| 6672 | __ mov(r2, Operand(r2, ASR, kSmiTagSize)); |
| 6673 | __ mov(r3, Operand(r3, ASR, kSmiTagSize)); |
| 6674 | // Both strings are non-empty. |
| 6675 | // r0: first string |
| 6676 | // r1: second string |
| 6677 | // r2: length of first string |
| 6678 | // r3: length of second string |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6679 | // r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 6680 | // r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6681 | // Look at the length of the result of adding the two strings. |
| 6682 | Label string_add_flat_result, longer_than_two; |
| 6683 | // Adding two lengths can't overflow. |
| 6684 | STATIC_ASSERT(String::kMaxLength < String::kMaxLength * 2); |
| 6685 | __ add(r6, r2, Operand(r3)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6686 | // Use the symbol table when adding two one character strings, as it |
| 6687 | // helps later optimizations to return a symbol here. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6688 | __ cmp(r6, Operand(2)); |
| 6689 | __ b(ne, &longer_than_two); |
| 6690 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6691 | // Check that both strings are non-external ASCII strings. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6692 | if (flags_ != NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6693 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 6694 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 6695 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 6696 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 6697 | } |
| 6698 | __ JumpIfBothInstanceTypesAreNotSequentialAscii(r4, r5, r6, r7, |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6699 | &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6700 | |
| 6701 | // Get the two characters forming the sub string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6702 | __ ldrb(r2, FieldMemOperand(r0, SeqOneByteString::kHeaderSize)); |
| 6703 | __ ldrb(r3, FieldMemOperand(r1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6704 | |
| 6705 | // Try to lookup two character string in symbol table. If it is not found |
| 6706 | // just allocate a new one. |
| 6707 | Label make_two_character_string; |
| 6708 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
| 6709 | masm, r2, r3, r6, r7, r4, r5, r9, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6710 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6711 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6712 | __ Ret(); |
| 6713 | |
| 6714 | __ bind(&make_two_character_string); |
| 6715 | // Resulting string has length 2 and first chars of two strings |
| 6716 | // are combined into single halfword in r2 register. |
| 6717 | // So we can fill resulting string without two loops by a single |
| 6718 | // halfword store instruction (which assumes that processor is |
| 6719 | // in a little endian mode) |
| 6720 | __ mov(r6, Operand(2)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6721 | __ AllocateAsciiString(r0, r6, r4, r5, r9, &call_runtime); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6722 | __ strh(r2, FieldMemOperand(r0, SeqOneByteString::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6723 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6724 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6725 | __ Ret(); |
| 6726 | |
| 6727 | __ bind(&longer_than_two); |
| 6728 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6729 | __ cmp(r6, Operand(ConsString::kMinLength)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6730 | __ b(lt, &string_add_flat_result); |
| 6731 | // Handle exceptionally long strings in the runtime system. |
| 6732 | STATIC_ASSERT((String::kMaxLength & 0x80000000) == 0); |
| 6733 | ASSERT(IsPowerOf2(String::kMaxLength + 1)); |
| 6734 | // kMaxLength + 1 is representable as shifted literal, kMaxLength is not. |
| 6735 | __ cmp(r6, Operand(String::kMaxLength + 1)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6736 | __ b(hs, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6737 | |
| 6738 | // If result is not supposed to be flat, allocate a cons string object. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6739 | // If both strings are ASCII the result is an ASCII cons string. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6740 | if (flags_ != NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6741 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 6742 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 6743 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 6744 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 6745 | } |
| 6746 | Label non_ascii, allocated, ascii_data; |
| 6747 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 6748 | __ tst(r4, Operand(kStringEncodingMask)); |
| 6749 | __ tst(r5, Operand(kStringEncodingMask), ne); |
| 6750 | __ b(eq, &non_ascii); |
| 6751 | |
| 6752 | // Allocate an ASCII cons string. |
| 6753 | __ bind(&ascii_data); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6754 | __ AllocateAsciiConsString(r7, r6, r4, r5, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6755 | __ bind(&allocated); |
| 6756 | // Fill the fields of the cons string. |
| 6757 | __ str(r0, FieldMemOperand(r7, ConsString::kFirstOffset)); |
| 6758 | __ str(r1, FieldMemOperand(r7, ConsString::kSecondOffset)); |
| 6759 | __ mov(r0, Operand(r7)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6760 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6761 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6762 | __ Ret(); |
| 6763 | |
| 6764 | __ bind(&non_ascii); |
| 6765 | // At least one of the strings is two-byte. Check whether it happens |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6766 | // to contain only ASCII characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6767 | // r4: first instance type. |
| 6768 | // r5: second instance type. |
| 6769 | __ tst(r4, Operand(kAsciiDataHintMask)); |
| 6770 | __ tst(r5, Operand(kAsciiDataHintMask), ne); |
| 6771 | __ b(ne, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 6772 | __ eor(r4, r4, Operand(r5)); |
| 6773 | STATIC_ASSERT(kOneByteStringTag != 0 && kAsciiDataHintTag != 0); |
| 6774 | __ and_(r4, r4, Operand(kOneByteStringTag | kAsciiDataHintTag)); |
| 6775 | __ cmp(r4, Operand(kOneByteStringTag | kAsciiDataHintTag)); |
| 6776 | __ b(eq, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6777 | |
| 6778 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6779 | __ AllocateTwoByteConsString(r7, r6, r4, r5, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6780 | __ jmp(&allocated); |
| 6781 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6782 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6783 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6784 | // Handle creating a flat result from either external or sequential strings. |
| 6785 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6786 | // r0: first string |
| 6787 | // r1: second string |
| 6788 | // r2: length of first string |
| 6789 | // r3: length of second string |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6790 | // r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 6791 | // r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6792 | // r6: sum of lengths. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6793 | Label first_prepared, second_prepared; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6794 | __ bind(&string_add_flat_result); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6795 | if (flags_ != NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6796 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 6797 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 6798 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 6799 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 6800 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6801 | |
| 6802 | // Check whether both strings have same encoding |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6803 | __ eor(r7, r4, Operand(r5)); |
| 6804 | __ tst(r7, Operand(kStringEncodingMask)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6805 | __ b(ne, &call_runtime); |
| 6806 | |
| 6807 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6808 | __ tst(r4, Operand(kStringRepresentationMask)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6809 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6810 | __ add(r7, |
| 6811 | r0, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6812 | Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag), |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6813 | LeaveCC, |
| 6814 | eq); |
| 6815 | __ b(eq, &first_prepared); |
| 6816 | // External string: rule out short external string and load string resource. |
| 6817 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 6818 | __ tst(r4, Operand(kShortExternalStringMask)); |
| 6819 | __ b(ne, &call_runtime); |
| 6820 | __ ldr(r7, FieldMemOperand(r0, ExternalString::kResourceDataOffset)); |
| 6821 | __ bind(&first_prepared); |
| 6822 | |
| 6823 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6824 | __ tst(r5, Operand(kStringRepresentationMask)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6825 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6826 | __ add(r1, |
| 6827 | r1, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6828 | Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag), |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6829 | LeaveCC, |
| 6830 | eq); |
| 6831 | __ b(eq, &second_prepared); |
| 6832 | // External string: rule out short external string and load string resource. |
| 6833 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 6834 | __ tst(r5, Operand(kShortExternalStringMask)); |
| 6835 | __ b(ne, &call_runtime); |
| 6836 | __ ldr(r1, FieldMemOperand(r1, ExternalString::kResourceDataOffset)); |
| 6837 | __ bind(&second_prepared); |
| 6838 | |
| 6839 | Label non_ascii_string_add_flat_result; |
| 6840 | // r7: first character of first string |
| 6841 | // r1: first character of second string |
| 6842 | // r2: length of first string. |
| 6843 | // r3: length of second string. |
| 6844 | // r6: sum of lengths. |
| 6845 | // Both strings have the same encoding. |
| 6846 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 6847 | __ tst(r5, Operand(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6848 | __ b(eq, &non_ascii_string_add_flat_result); |
| 6849 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6850 | __ AllocateAsciiString(r0, r6, r4, r5, r9, &call_runtime); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6851 | __ add(r6, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6852 | // r0: result string. |
| 6853 | // r7: first character of first string. |
| 6854 | // r1: first character of second string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6855 | // r2: length of first string. |
| 6856 | // r3: length of second string. |
| 6857 | // r6: first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6858 | StringHelper::GenerateCopyCharacters(masm, r6, r7, r2, r4, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6859 | // r6: next character of result. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6860 | StringHelper::GenerateCopyCharacters(masm, r6, r1, r3, r4, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6861 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6862 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6863 | __ Ret(); |
| 6864 | |
| 6865 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6866 | __ AllocateTwoByteString(r0, r6, r4, r5, r9, &call_runtime); |
| 6867 | __ add(r6, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6868 | // r0: result string. |
| 6869 | // r7: first character of first string. |
| 6870 | // r1: first character of second string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6871 | // r2: length of first string. |
| 6872 | // r3: length of second string. |
| 6873 | // r6: first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6874 | StringHelper::GenerateCopyCharacters(masm, r6, r7, r2, r4, false); |
| 6875 | // r6: next character of result. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6876 | StringHelper::GenerateCopyCharacters(masm, r6, r1, r3, r4, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6877 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6878 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6879 | __ Ret(); |
| 6880 | |
| 6881 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6882 | __ bind(&call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6883 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6884 | |
| 6885 | if (call_builtin.is_linked()) { |
| 6886 | __ bind(&call_builtin); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 6887 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6888 | } |
| 6889 | } |
| 6890 | |
| 6891 | |
| 6892 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 6893 | int stack_offset, |
| 6894 | Register arg, |
| 6895 | Register scratch1, |
| 6896 | Register scratch2, |
| 6897 | Register scratch3, |
| 6898 | Register scratch4, |
| 6899 | Label* slow) { |
| 6900 | // First check if the argument is already a string. |
| 6901 | Label not_string, done; |
| 6902 | __ JumpIfSmi(arg, ¬_string); |
| 6903 | __ CompareObjectType(arg, scratch1, scratch1, FIRST_NONSTRING_TYPE); |
| 6904 | __ b(lt, &done); |
| 6905 | |
| 6906 | // Check the number to string cache. |
| 6907 | Label not_cached; |
| 6908 | __ bind(¬_string); |
| 6909 | // Puts the cached result into scratch1. |
| 6910 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 6911 | arg, |
| 6912 | scratch1, |
| 6913 | scratch2, |
| 6914 | scratch3, |
| 6915 | scratch4, |
| 6916 | false, |
| 6917 | ¬_cached); |
| 6918 | __ mov(arg, scratch1); |
| 6919 | __ str(arg, MemOperand(sp, stack_offset)); |
| 6920 | __ jmp(&done); |
| 6921 | |
| 6922 | // Check if the argument is a safe string wrapper. |
| 6923 | __ bind(¬_cached); |
| 6924 | __ JumpIfSmi(arg, slow); |
| 6925 | __ CompareObjectType( |
| 6926 | arg, scratch1, scratch2, JS_VALUE_TYPE); // map -> scratch1. |
| 6927 | __ b(ne, slow); |
| 6928 | __ ldrb(scratch2, FieldMemOperand(scratch1, Map::kBitField2Offset)); |
| 6929 | __ and_(scratch2, |
| 6930 | scratch2, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 6931 | __ cmp(scratch2, |
| 6932 | Operand(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 6933 | __ b(ne, slow); |
| 6934 | __ ldr(arg, FieldMemOperand(arg, JSValue::kValueOffset)); |
| 6935 | __ str(arg, MemOperand(sp, stack_offset)); |
| 6936 | |
| 6937 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6938 | } |
| 6939 | |
| 6940 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6941 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6942 | ASSERT(state_ == CompareIC::SMI); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6943 | Label miss; |
| 6944 | __ orr(r2, r1, r0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6945 | __ JumpIfNotSmi(r2, &miss); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6946 | |
| 6947 | if (GetCondition() == eq) { |
| 6948 | // For equality we do not care about the sign of the result. |
| 6949 | __ sub(r0, r0, r1, SetCC); |
| 6950 | } else { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 6951 | // Untag before subtracting to avoid handling overflow. |
| 6952 | __ SmiUntag(r1); |
| 6953 | __ sub(r0, r1, SmiUntagOperand(r0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6954 | } |
| 6955 | __ Ret(); |
| 6956 | |
| 6957 | __ bind(&miss); |
| 6958 | GenerateMiss(masm); |
| 6959 | } |
| 6960 | |
| 6961 | |
| 6962 | void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6963 | ASSERT(state_ == CompareIC::HEAP_NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6964 | |
| 6965 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6966 | Label unordered, maybe_undefined1, maybe_undefined2; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6967 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6968 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6969 | if (left_ == CompareIC::SMI) { |
| 6970 | __ JumpIfNotSmi(r1, &miss); |
| 6971 | } |
| 6972 | if (right_ == CompareIC::SMI) { |
| 6973 | __ JumpIfNotSmi(r0, &miss); |
| 6974 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6975 | |
| 6976 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6977 | // stub if NaN is involved or VFP2 is unsupported. |
verwaest@chromium.org | b6d052d | 2012-07-27 08:03:27 +0000 | [diff] [blame] | 6978 | if (CpuFeatures::IsSupported(VFP2)) { |
| 6979 | CpuFeatures::Scope scope(VFP2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6980 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6981 | // Load left and right operand. |
| 6982 | Label done, left, left_smi, right_smi; |
| 6983 | __ JumpIfSmi(r0, &right_smi); |
| 6984 | __ CheckMap(r0, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1, |
| 6985 | DONT_DO_SMI_CHECK); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6986 | __ sub(r2, r0, Operand(kHeapObjectTag)); |
| 6987 | __ vldr(d1, r2, HeapNumber::kValueOffset); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6988 | __ b(&left); |
| 6989 | __ bind(&right_smi); |
| 6990 | __ SmiUntag(r2, r0); // Can't clobber r0 yet. |
| 6991 | SwVfpRegister single_scratch = d2.low(); |
| 6992 | __ vmov(single_scratch, r2); |
| 6993 | __ vcvt_f64_s32(d1, single_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6994 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6995 | __ bind(&left); |
| 6996 | __ JumpIfSmi(r1, &left_smi); |
| 6997 | __ CheckMap(r1, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2, |
| 6998 | DONT_DO_SMI_CHECK); |
| 6999 | __ sub(r2, r1, Operand(kHeapObjectTag)); |
| 7000 | __ vldr(d0, r2, HeapNumber::kValueOffset); |
| 7001 | __ b(&done); |
| 7002 | __ bind(&left_smi); |
| 7003 | __ SmiUntag(r2, r1); // Can't clobber r1 yet. |
| 7004 | single_scratch = d3.low(); |
| 7005 | __ vmov(single_scratch, r2); |
| 7006 | __ vcvt_f64_s32(d0, single_scratch); |
| 7007 | |
| 7008 | __ bind(&done); |
| 7009 | // Compare operands. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 7010 | __ VFPCompareAndSetFlags(d0, d1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7011 | |
| 7012 | // Don't base result on status bits when a NaN is involved. |
| 7013 | __ b(vs, &unordered); |
| 7014 | |
| 7015 | // Return a result of -1, 0, or 1, based on status bits. |
| 7016 | __ mov(r0, Operand(EQUAL), LeaveCC, eq); |
| 7017 | __ mov(r0, Operand(LESS), LeaveCC, lt); |
| 7018 | __ mov(r0, Operand(GREATER), LeaveCC, gt); |
| 7019 | __ Ret(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7020 | } |
| 7021 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 7022 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7023 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 7024 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 7025 | CompareIC::GENERIC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7026 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 7027 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 7028 | __ bind(&maybe_undefined1); |
| 7029 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 7030 | __ CompareRoot(r0, Heap::kUndefinedValueRootIndex); |
| 7031 | __ b(ne, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 7032 | __ JumpIfSmi(r1, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 7033 | __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE); |
| 7034 | __ b(ne, &maybe_undefined2); |
| 7035 | __ jmp(&unordered); |
| 7036 | } |
| 7037 | |
| 7038 | __ bind(&maybe_undefined2); |
| 7039 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 7040 | __ CompareRoot(r1, Heap::kUndefinedValueRootIndex); |
| 7041 | __ b(eq, &unordered); |
| 7042 | } |
| 7043 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7044 | __ bind(&miss); |
| 7045 | GenerateMiss(masm); |
| 7046 | } |
| 7047 | |
| 7048 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7049 | void ICCompareStub::GenerateSymbols(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 7050 | ASSERT(state_ == CompareIC::SYMBOL); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7051 | Label miss; |
| 7052 | |
| 7053 | // Registers containing left and right operands respectively. |
| 7054 | Register left = r1; |
| 7055 | Register right = r0; |
| 7056 | Register tmp1 = r2; |
| 7057 | Register tmp2 = r3; |
| 7058 | |
| 7059 | // Check that both operands are heap objects. |
| 7060 | __ JumpIfEitherSmi(left, right, &miss); |
| 7061 | |
| 7062 | // Check that both operands are symbols. |
| 7063 | __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 7064 | __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 7065 | __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 7066 | __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 7067 | STATIC_ASSERT(kSymbolTag != 0); |
| 7068 | __ and_(tmp1, tmp1, Operand(tmp2)); |
| 7069 | __ tst(tmp1, Operand(kIsSymbolMask)); |
| 7070 | __ b(eq, &miss); |
| 7071 | |
| 7072 | // Symbols are compared by identity. |
| 7073 | __ cmp(left, right); |
| 7074 | // Make sure r0 is non-zero. At this point input operands are |
| 7075 | // guaranteed to be non-zero. |
| 7076 | ASSERT(right.is(r0)); |
| 7077 | STATIC_ASSERT(EQUAL == 0); |
| 7078 | STATIC_ASSERT(kSmiTag == 0); |
| 7079 | __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq); |
| 7080 | __ Ret(); |
| 7081 | |
| 7082 | __ bind(&miss); |
| 7083 | GenerateMiss(masm); |
| 7084 | } |
| 7085 | |
| 7086 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7087 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 7088 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7089 | Label miss; |
| 7090 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7091 | bool equality = Token::IsEqualityOp(op_); |
| 7092 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7093 | // Registers containing left and right operands respectively. |
| 7094 | Register left = r1; |
| 7095 | Register right = r0; |
| 7096 | Register tmp1 = r2; |
| 7097 | Register tmp2 = r3; |
| 7098 | Register tmp3 = r4; |
| 7099 | Register tmp4 = r5; |
| 7100 | |
| 7101 | // Check that both operands are heap objects. |
| 7102 | __ JumpIfEitherSmi(left, right, &miss); |
| 7103 | |
| 7104 | // Check that both operands are strings. This leaves the instance |
| 7105 | // types loaded in tmp1 and tmp2. |
| 7106 | __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 7107 | __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 7108 | __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 7109 | __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 7110 | STATIC_ASSERT(kNotStringTag != 0); |
| 7111 | __ orr(tmp3, tmp1, tmp2); |
| 7112 | __ tst(tmp3, Operand(kIsNotStringMask)); |
| 7113 | __ b(ne, &miss); |
| 7114 | |
| 7115 | // Fast check for identical strings. |
| 7116 | __ cmp(left, right); |
| 7117 | STATIC_ASSERT(EQUAL == 0); |
| 7118 | STATIC_ASSERT(kSmiTag == 0); |
| 7119 | __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq); |
| 7120 | __ Ret(eq); |
| 7121 | |
| 7122 | // Handle not identical strings. |
| 7123 | |
| 7124 | // Check that both strings are symbols. If they are, we're done |
| 7125 | // because we already know they are not identical. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7126 | if (equality) { |
| 7127 | ASSERT(GetCondition() == eq); |
| 7128 | STATIC_ASSERT(kSymbolTag != 0); |
| 7129 | __ and_(tmp3, tmp1, Operand(tmp2)); |
| 7130 | __ tst(tmp3, Operand(kIsSymbolMask)); |
| 7131 | // Make sure r0 is non-zero. At this point input operands are |
| 7132 | // guaranteed to be non-zero. |
| 7133 | ASSERT(right.is(r0)); |
| 7134 | __ Ret(ne); |
| 7135 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7136 | |
| 7137 | // Check that both strings are sequential ASCII. |
| 7138 | Label runtime; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7139 | __ JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 7140 | tmp1, tmp2, tmp3, tmp4, &runtime); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7141 | |
| 7142 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7143 | if (equality) { |
| 7144 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 7145 | masm, left, right, tmp1, tmp2, tmp3); |
| 7146 | } else { |
| 7147 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 7148 | masm, left, right, tmp1, tmp2, tmp3, tmp4); |
| 7149 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7150 | |
| 7151 | // Handle more complex cases in runtime. |
| 7152 | __ bind(&runtime); |
| 7153 | __ Push(left, right); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7154 | if (equality) { |
| 7155 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 7156 | } else { |
| 7157 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 7158 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7159 | |
| 7160 | __ bind(&miss); |
| 7161 | GenerateMiss(masm); |
| 7162 | } |
| 7163 | |
| 7164 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7165 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 7166 | ASSERT(state_ == CompareIC::OBJECT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7167 | Label miss; |
| 7168 | __ and_(r2, r1, Operand(r0)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 7169 | __ JumpIfSmi(r2, &miss); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7170 | |
| 7171 | __ CompareObjectType(r0, r2, r2, JS_OBJECT_TYPE); |
| 7172 | __ b(ne, &miss); |
| 7173 | __ CompareObjectType(r1, r2, r2, JS_OBJECT_TYPE); |
| 7174 | __ b(ne, &miss); |
| 7175 | |
| 7176 | ASSERT(GetCondition() == eq); |
| 7177 | __ sub(r0, r0, Operand(r1)); |
| 7178 | __ Ret(); |
| 7179 | |
| 7180 | __ bind(&miss); |
| 7181 | GenerateMiss(masm); |
| 7182 | } |
| 7183 | |
| 7184 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7185 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 7186 | Label miss; |
| 7187 | __ and_(r2, r1, Operand(r0)); |
| 7188 | __ JumpIfSmi(r2, &miss); |
| 7189 | __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 7190 | __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 7191 | __ cmp(r2, Operand(known_map_)); |
| 7192 | __ b(ne, &miss); |
| 7193 | __ cmp(r3, Operand(known_map_)); |
| 7194 | __ b(ne, &miss); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7195 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7196 | __ sub(r0, r0, Operand(r1)); |
| 7197 | __ Ret(); |
| 7198 | |
| 7199 | __ bind(&miss); |
| 7200 | GenerateMiss(masm); |
| 7201 | } |
| 7202 | |
| 7203 | |
| 7204 | |
| 7205 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7206 | { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7207 | // Call the runtime system in a fresh internal frame. |
| 7208 | ExternalReference miss = |
| 7209 | ExternalReference(IC_Utility(IC::kCompareIC_Miss), masm->isolate()); |
| 7210 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7211 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 7212 | __ Push(r1, r0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7213 | __ push(lr); |
| 7214 | __ Push(r1, r0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7215 | __ mov(ip, Operand(Smi::FromInt(op_))); |
| 7216 | __ push(ip); |
| 7217 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7218 | // Compute the entry point of the rewritten stub. |
| 7219 | __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 7220 | // Restore registers. |
| 7221 | __ pop(lr); |
| 7222 | __ pop(r0); |
| 7223 | __ pop(r1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7224 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7225 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7226 | __ Jump(r2); |
| 7227 | } |
| 7228 | |
| 7229 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 7230 | void DirectCEntryStub::Generate(MacroAssembler* masm) { |
| 7231 | __ ldr(pc, MemOperand(sp, 0)); |
| 7232 | } |
| 7233 | |
| 7234 | |
| 7235 | void DirectCEntryStub::GenerateCall(MacroAssembler* masm, |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 7236 | ExternalReference function) { |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 7237 | __ mov(r2, Operand(function)); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 7238 | GenerateCall(masm, r2); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 7239 | } |
| 7240 | |
| 7241 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 7242 | void DirectCEntryStub::GenerateCall(MacroAssembler* masm, |
| 7243 | Register target) { |
| 7244 | __ mov(lr, Operand(reinterpret_cast<intptr_t>(GetCode().location()), |
| 7245 | RelocInfo::CODE_TARGET)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 7246 | |
| 7247 | // Prevent literal pool emission during calculation of return address. |
| 7248 | Assembler::BlockConstPoolScope block_const_pool(masm); |
| 7249 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 7250 | // Push return address (accessible to GC through exit frame pc). |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 7251 | // Note that using pc with str is deprecated. |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 7252 | Label start; |
| 7253 | __ bind(&start); |
| 7254 | __ add(ip, pc, Operand(Assembler::kInstrSize)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 7255 | __ str(ip, MemOperand(sp, 0)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 7256 | __ Jump(target); // Call the C++ function. |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 7257 | ASSERT_EQ(Assembler::kInstrSize + Assembler::kPcLoadDelta, |
| 7258 | masm->SizeOfCodeGeneratedSince(&start)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 7259 | } |
| 7260 | |
| 7261 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7262 | void StringDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 7263 | Label* miss, |
| 7264 | Label* done, |
| 7265 | Register receiver, |
| 7266 | Register properties, |
| 7267 | Handle<String> name, |
| 7268 | Register scratch0) { |
| 7269 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7270 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7271 | // undefined value), it guarantees the hash table doesn't contain the |
| 7272 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7273 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7274 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7275 | // scratch0 points to properties hash. |
| 7276 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7277 | Register index = scratch0; |
| 7278 | // Capacity is smi 2^n. |
| 7279 | __ ldr(index, FieldMemOperand(properties, kCapacityOffset)); |
| 7280 | __ sub(index, index, Operand(1)); |
| 7281 | __ and_(index, index, Operand( |
| 7282 | Smi::FromInt(name->Hash() + StringDictionary::GetProbeOffset(i)))); |
| 7283 | |
| 7284 | // Scale the index by multiplying by the entry size. |
| 7285 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7286 | __ add(index, index, Operand(index, LSL, 1)); // index *= 3. |
| 7287 | |
| 7288 | Register entity_name = scratch0; |
| 7289 | // Having undefined at this place means the name is not contained. |
| 7290 | ASSERT_EQ(kSmiTagSize, 1); |
| 7291 | Register tmp = properties; |
| 7292 | __ add(tmp, properties, Operand(index, LSL, 1)); |
| 7293 | __ ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset)); |
| 7294 | |
| 7295 | ASSERT(!tmp.is(entity_name)); |
| 7296 | __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex); |
| 7297 | __ cmp(entity_name, tmp); |
| 7298 | __ b(eq, done); |
| 7299 | |
| 7300 | if (i != kInlinedProbes - 1) { |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7301 | // Load the hole ready for use below: |
| 7302 | __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex); |
| 7303 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7304 | // Stop if found the property. |
| 7305 | __ cmp(entity_name, Operand(Handle<String>(name))); |
| 7306 | __ b(eq, miss); |
| 7307 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7308 | Label the_hole; |
| 7309 | __ cmp(entity_name, tmp); |
| 7310 | __ b(eq, &the_hole); |
| 7311 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7312 | // Check if the entry name is not a symbol. |
| 7313 | __ ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset)); |
| 7314 | __ ldrb(entity_name, |
| 7315 | FieldMemOperand(entity_name, Map::kInstanceTypeOffset)); |
| 7316 | __ tst(entity_name, Operand(kIsSymbolMask)); |
| 7317 | __ b(eq, miss); |
| 7318 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7319 | __ bind(&the_hole); |
| 7320 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7321 | // Restore the properties. |
| 7322 | __ ldr(properties, |
| 7323 | FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 7324 | } |
| 7325 | } |
| 7326 | |
| 7327 | const int spill_mask = |
| 7328 | (lr.bit() | r6.bit() | r5.bit() | r4.bit() | r3.bit() | |
| 7329 | r2.bit() | r1.bit() | r0.bit()); |
| 7330 | |
| 7331 | __ stm(db_w, sp, spill_mask); |
| 7332 | __ ldr(r0, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 7333 | __ mov(r1, Operand(Handle<String>(name))); |
| 7334 | StringDictionaryLookupStub stub(NEGATIVE_LOOKUP); |
| 7335 | __ CallStub(&stub); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 7336 | __ cmp(r0, Operand::Zero()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7337 | __ ldm(ia_w, sp, spill_mask); |
| 7338 | |
| 7339 | __ b(eq, done); |
| 7340 | __ b(ne, miss); |
| 7341 | } |
| 7342 | |
| 7343 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7344 | // Probe the string dictionary in the |elements| register. Jump to the |
| 7345 | // |done| label if a property with the given name is found. Jump to |
| 7346 | // the |miss| label otherwise. |
| 7347 | // If lookup was successful |scratch2| will be equal to elements + 4 * index. |
| 7348 | void StringDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 7349 | Label* miss, |
| 7350 | Label* done, |
| 7351 | Register elements, |
| 7352 | Register name, |
| 7353 | Register scratch1, |
| 7354 | Register scratch2) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 7355 | ASSERT(!elements.is(scratch1)); |
| 7356 | ASSERT(!elements.is(scratch2)); |
| 7357 | ASSERT(!name.is(scratch1)); |
| 7358 | ASSERT(!name.is(scratch2)); |
| 7359 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 7360 | __ AssertString(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7361 | |
| 7362 | // Compute the capacity mask. |
| 7363 | __ ldr(scratch1, FieldMemOperand(elements, kCapacityOffset)); |
| 7364 | __ mov(scratch1, Operand(scratch1, ASR, kSmiTagSize)); // convert smi to int |
| 7365 | __ sub(scratch1, scratch1, Operand(1)); |
| 7366 | |
| 7367 | // Generate an unrolled loop that performs a few probes before |
| 7368 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 7369 | // cover ~93% of loads from dictionaries. |
| 7370 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7371 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7372 | __ ldr(scratch2, FieldMemOperand(name, String::kHashFieldOffset)); |
| 7373 | if (i > 0) { |
| 7374 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 7375 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 7376 | // shifted in the following and instruction. |
| 7377 | ASSERT(StringDictionary::GetProbeOffset(i) < |
| 7378 | 1 << (32 - String::kHashFieldOffset)); |
| 7379 | __ add(scratch2, scratch2, Operand( |
| 7380 | StringDictionary::GetProbeOffset(i) << String::kHashShift)); |
| 7381 | } |
| 7382 | __ and_(scratch2, scratch1, Operand(scratch2, LSR, String::kHashShift)); |
| 7383 | |
| 7384 | // Scale the index by multiplying by the element size. |
| 7385 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7386 | // scratch2 = scratch2 * 3. |
| 7387 | __ add(scratch2, scratch2, Operand(scratch2, LSL, 1)); |
| 7388 | |
| 7389 | // Check if the key is identical to the name. |
| 7390 | __ add(scratch2, elements, Operand(scratch2, LSL, 2)); |
| 7391 | __ ldr(ip, FieldMemOperand(scratch2, kElementsStartOffset)); |
| 7392 | __ cmp(name, Operand(ip)); |
| 7393 | __ b(eq, done); |
| 7394 | } |
| 7395 | |
| 7396 | const int spill_mask = |
| 7397 | (lr.bit() | r6.bit() | r5.bit() | r4.bit() | |
| 7398 | r3.bit() | r2.bit() | r1.bit() | r0.bit()) & |
| 7399 | ~(scratch1.bit() | scratch2.bit()); |
| 7400 | |
| 7401 | __ stm(db_w, sp, spill_mask); |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 7402 | if (name.is(r0)) { |
| 7403 | ASSERT(!elements.is(r1)); |
| 7404 | __ Move(r1, name); |
| 7405 | __ Move(r0, elements); |
| 7406 | } else { |
| 7407 | __ Move(r0, elements); |
| 7408 | __ Move(r1, name); |
| 7409 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7410 | StringDictionaryLookupStub stub(POSITIVE_LOOKUP); |
| 7411 | __ CallStub(&stub); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 7412 | __ cmp(r0, Operand::Zero()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7413 | __ mov(scratch2, Operand(r2)); |
| 7414 | __ ldm(ia_w, sp, spill_mask); |
| 7415 | |
| 7416 | __ b(ne, done); |
| 7417 | __ b(eq, miss); |
| 7418 | } |
| 7419 | |
| 7420 | |
| 7421 | void StringDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7422 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 7423 | // 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] | 7424 | // Registers: |
| 7425 | // result: StringDictionary to probe |
| 7426 | // r1: key |
| 7427 | // : StringDictionary to probe. |
| 7428 | // index_: will hold an index of entry if lookup is successful. |
| 7429 | // might alias with result_. |
| 7430 | // Returns: |
| 7431 | // result_ is zero if lookup failed, non zero otherwise. |
| 7432 | |
| 7433 | Register result = r0; |
| 7434 | Register dictionary = r0; |
| 7435 | Register key = r1; |
| 7436 | Register index = r2; |
| 7437 | Register mask = r3; |
| 7438 | Register hash = r4; |
| 7439 | Register undefined = r5; |
| 7440 | Register entry_key = r6; |
| 7441 | |
| 7442 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 7443 | |
| 7444 | __ ldr(mask, FieldMemOperand(dictionary, kCapacityOffset)); |
| 7445 | __ mov(mask, Operand(mask, ASR, kSmiTagSize)); |
| 7446 | __ sub(mask, mask, Operand(1)); |
| 7447 | |
| 7448 | __ ldr(hash, FieldMemOperand(key, String::kHashFieldOffset)); |
| 7449 | |
| 7450 | __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex); |
| 7451 | |
| 7452 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 7453 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7454 | // Capacity is smi 2^n. |
| 7455 | if (i > 0) { |
| 7456 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 7457 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 7458 | // shifted in the following and instruction. |
| 7459 | ASSERT(StringDictionary::GetProbeOffset(i) < |
| 7460 | 1 << (32 - String::kHashFieldOffset)); |
| 7461 | __ add(index, hash, Operand( |
| 7462 | StringDictionary::GetProbeOffset(i) << String::kHashShift)); |
| 7463 | } else { |
| 7464 | __ mov(index, Operand(hash)); |
| 7465 | } |
| 7466 | __ and_(index, mask, Operand(index, LSR, String::kHashShift)); |
| 7467 | |
| 7468 | // Scale the index by multiplying by the entry size. |
| 7469 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7470 | __ add(index, index, Operand(index, LSL, 1)); // index *= 3. |
| 7471 | |
| 7472 | ASSERT_EQ(kSmiTagSize, 1); |
| 7473 | __ add(index, dictionary, Operand(index, LSL, 2)); |
| 7474 | __ ldr(entry_key, FieldMemOperand(index, kElementsStartOffset)); |
| 7475 | |
| 7476 | // Having undefined at this place means the name is not contained. |
| 7477 | __ cmp(entry_key, Operand(undefined)); |
| 7478 | __ b(eq, ¬_in_dictionary); |
| 7479 | |
| 7480 | // Stop if found the property. |
| 7481 | __ cmp(entry_key, Operand(key)); |
| 7482 | __ b(eq, &in_dictionary); |
| 7483 | |
| 7484 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
| 7485 | // Check if the entry name is not a symbol. |
| 7486 | __ ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset)); |
| 7487 | __ ldrb(entry_key, |
| 7488 | FieldMemOperand(entry_key, Map::kInstanceTypeOffset)); |
| 7489 | __ tst(entry_key, Operand(kIsSymbolMask)); |
| 7490 | __ b(eq, &maybe_in_dictionary); |
| 7491 | } |
| 7492 | } |
| 7493 | |
| 7494 | __ bind(&maybe_in_dictionary); |
| 7495 | // If we are doing negative lookup then probing failure should be |
| 7496 | // treated as a lookup success. For positive lookup probing failure |
| 7497 | // should be treated as lookup failure. |
| 7498 | if (mode_ == POSITIVE_LOOKUP) { |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 7499 | __ mov(result, Operand::Zero()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7500 | __ Ret(); |
| 7501 | } |
| 7502 | |
| 7503 | __ bind(&in_dictionary); |
| 7504 | __ mov(result, Operand(1)); |
| 7505 | __ Ret(); |
| 7506 | |
| 7507 | __ bind(¬_in_dictionary); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 7508 | __ mov(result, Operand::Zero()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7509 | __ Ret(); |
| 7510 | } |
| 7511 | |
| 7512 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7513 | struct AheadOfTimeWriteBarrierStubList { |
| 7514 | Register object, value, address; |
| 7515 | RememberedSetAction action; |
| 7516 | }; |
| 7517 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7518 | #define REG(Name) { kRegister_ ## Name ## _Code } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7519 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7520 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7521 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7522 | { REG(r6), REG(r4), REG(r7), EMIT_REMEMBERED_SET }, |
| 7523 | { REG(r6), REG(r2), REG(r7), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7524 | // Used in CompileArrayPushCall. |
| 7525 | // Also used in StoreIC::GenerateNormal via GenerateDictionaryStore. |
| 7526 | // Also used in KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7527 | { REG(r3), REG(r4), REG(r5), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7528 | // Used in CompileStoreGlobal. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7529 | { REG(r4), REG(r1), REG(r2), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7530 | // Used in StoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7531 | { REG(r1), REG(r2), REG(r3), EMIT_REMEMBERED_SET }, |
| 7532 | { REG(r3), REG(r2), REG(r1), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7533 | // Used in KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7534 | { REG(r2), REG(r1), REG(r3), EMIT_REMEMBERED_SET }, |
| 7535 | { REG(r3), REG(r1), REG(r2), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7536 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7537 | { REG(r3), REG(r2), REG(r4), EMIT_REMEMBERED_SET }, |
| 7538 | { REG(r2), REG(r3), REG(r4), EMIT_REMEMBERED_SET }, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7539 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7540 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7541 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7542 | { REG(r2), REG(r3), REG(r9), EMIT_REMEMBERED_SET }, |
| 7543 | { REG(r2), REG(r3), REG(r9), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7544 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7545 | { REG(r6), REG(r2), REG(r0), EMIT_REMEMBERED_SET }, |
| 7546 | { REG(r2), REG(r6), REG(r9), EMIT_REMEMBERED_SET }, |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7547 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7548 | { REG(r5), REG(r0), REG(r6), EMIT_REMEMBERED_SET }, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7549 | // FastNewClosureStub::Generate |
| 7550 | { REG(r2), REG(r4), REG(r1), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7551 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7552 | { 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] | 7553 | }; |
| 7554 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7555 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7556 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7557 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7558 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7559 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7560 | !entry->object.is(no_reg); |
| 7561 | entry++) { |
| 7562 | if (object_.is(entry->object) && |
| 7563 | value_.is(entry->value) && |
| 7564 | address_.is(entry->address) && |
| 7565 | remembered_set_action_ == entry->action && |
| 7566 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7567 | return true; |
| 7568 | } |
| 7569 | } |
| 7570 | return false; |
| 7571 | } |
| 7572 | |
| 7573 | |
| 7574 | bool StoreBufferOverflowStub::IsPregenerated() { |
| 7575 | return save_doubles_ == kDontSaveFPRegs || ISOLATE->fp_stubs_generated(); |
| 7576 | } |
| 7577 | |
| 7578 | |
| 7579 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime() { |
| 7580 | StoreBufferOverflowStub stub1(kDontSaveFPRegs); |
| 7581 | stub1.GetCode()->set_is_pregenerated(true); |
| 7582 | } |
| 7583 | |
| 7584 | |
| 7585 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7586 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7587 | !entry->object.is(no_reg); |
| 7588 | entry++) { |
| 7589 | RecordWriteStub stub(entry->object, |
| 7590 | entry->value, |
| 7591 | entry->address, |
| 7592 | entry->action, |
| 7593 | kDontSaveFPRegs); |
| 7594 | stub.GetCode()->set_is_pregenerated(true); |
| 7595 | } |
| 7596 | } |
| 7597 | |
| 7598 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7599 | bool CodeStub::CanUseFPRegisters() { |
| 7600 | return CpuFeatures::IsSupported(VFP2); |
| 7601 | } |
| 7602 | |
| 7603 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7604 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7605 | // the value has just been written into the object, now this stub makes sure |
| 7606 | // we keep the GC informed. The word in the object where the value has been |
| 7607 | // written is in the address register. |
| 7608 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7609 | Label skip_to_incremental_noncompacting; |
| 7610 | Label skip_to_incremental_compacting; |
| 7611 | |
| 7612 | // The first two instructions are generated with labels so as to get the |
| 7613 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7614 | // forth between a compare instructions (a nop in this position) and the |
| 7615 | // real branch when we start and stop incremental heap marking. |
| 7616 | // See RecordWriteStub::Patch for details. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 7617 | { |
| 7618 | // Block literal pool emission, as the position of these two instructions |
| 7619 | // is assumed by the patching code. |
| 7620 | Assembler::BlockConstPoolScope block_const_pool(masm); |
| 7621 | __ b(&skip_to_incremental_noncompacting); |
| 7622 | __ b(&skip_to_incremental_compacting); |
| 7623 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7624 | |
| 7625 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7626 | __ RememberedSetHelper(object_, |
| 7627 | address_, |
| 7628 | value_, |
| 7629 | save_fp_regs_mode_, |
| 7630 | MacroAssembler::kReturnAtEnd); |
| 7631 | } |
| 7632 | __ Ret(); |
| 7633 | |
| 7634 | __ bind(&skip_to_incremental_noncompacting); |
| 7635 | GenerateIncremental(masm, INCREMENTAL); |
| 7636 | |
| 7637 | __ bind(&skip_to_incremental_compacting); |
| 7638 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7639 | |
| 7640 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7641 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7642 | ASSERT(Assembler::GetBranchOffset(masm->instr_at(0)) < (1 << 12)); |
| 7643 | ASSERT(Assembler::GetBranchOffset(masm->instr_at(4)) < (1 << 12)); |
| 7644 | PatchBranchIntoNop(masm, 0); |
| 7645 | PatchBranchIntoNop(masm, Assembler::kInstrSize); |
| 7646 | } |
| 7647 | |
| 7648 | |
| 7649 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7650 | regs_.Save(masm); |
| 7651 | |
| 7652 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7653 | Label dont_need_remembered_set; |
| 7654 | |
| 7655 | __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0)); |
| 7656 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7657 | regs_.scratch0(), |
| 7658 | &dont_need_remembered_set); |
| 7659 | |
| 7660 | __ CheckPageFlag(regs_.object(), |
| 7661 | regs_.scratch0(), |
| 7662 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7663 | ne, |
| 7664 | &dont_need_remembered_set); |
| 7665 | |
| 7666 | // First notify the incremental marker if necessary, then update the |
| 7667 | // remembered set. |
| 7668 | CheckNeedsToInformIncrementalMarker( |
| 7669 | masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode); |
| 7670 | InformIncrementalMarker(masm, mode); |
| 7671 | regs_.Restore(masm); |
| 7672 | __ RememberedSetHelper(object_, |
| 7673 | address_, |
| 7674 | value_, |
| 7675 | save_fp_regs_mode_, |
| 7676 | MacroAssembler::kReturnAtEnd); |
| 7677 | |
| 7678 | __ bind(&dont_need_remembered_set); |
| 7679 | } |
| 7680 | |
| 7681 | CheckNeedsToInformIncrementalMarker( |
| 7682 | masm, kReturnOnNoNeedToInformIncrementalMarker, mode); |
| 7683 | InformIncrementalMarker(masm, mode); |
| 7684 | regs_.Restore(masm); |
| 7685 | __ Ret(); |
| 7686 | } |
| 7687 | |
| 7688 | |
| 7689 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7690 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7691 | int argument_count = 3; |
| 7692 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7693 | Register address = |
| 7694 | r0.is(regs_.address()) ? regs_.scratch0() : regs_.address(); |
| 7695 | ASSERT(!address.is(regs_.object())); |
| 7696 | ASSERT(!address.is(r0)); |
| 7697 | __ Move(address, regs_.address()); |
| 7698 | __ Move(r0, regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 7699 | __ Move(r1, address); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7700 | __ mov(r2, Operand(ExternalReference::isolate_address())); |
| 7701 | |
| 7702 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7703 | if (mode == INCREMENTAL_COMPACTION) { |
| 7704 | __ CallCFunction( |
| 7705 | ExternalReference::incremental_evacuation_record_write_function( |
| 7706 | masm->isolate()), |
| 7707 | argument_count); |
| 7708 | } else { |
| 7709 | ASSERT(mode == INCREMENTAL); |
| 7710 | __ CallCFunction( |
| 7711 | ExternalReference::incremental_marking_record_write_function( |
| 7712 | masm->isolate()), |
| 7713 | argument_count); |
| 7714 | } |
| 7715 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7716 | } |
| 7717 | |
| 7718 | |
| 7719 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7720 | MacroAssembler* masm, |
| 7721 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7722 | Mode mode) { |
| 7723 | Label on_black; |
| 7724 | Label need_incremental; |
| 7725 | Label need_incremental_pop_scratch; |
| 7726 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7727 | __ and_(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask)); |
| 7728 | __ ldr(regs_.scratch1(), |
| 7729 | MemOperand(regs_.scratch0(), |
| 7730 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7731 | __ sub(regs_.scratch1(), regs_.scratch1(), Operand(1), SetCC); |
| 7732 | __ str(regs_.scratch1(), |
| 7733 | MemOperand(regs_.scratch0(), |
| 7734 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7735 | __ b(mi, &need_incremental); |
| 7736 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7737 | // Let's look at the color of the object: If it is not black we don't have |
| 7738 | // to inform the incremental marker. |
| 7739 | __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black); |
| 7740 | |
| 7741 | regs_.Restore(masm); |
| 7742 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7743 | __ RememberedSetHelper(object_, |
| 7744 | address_, |
| 7745 | value_, |
| 7746 | save_fp_regs_mode_, |
| 7747 | MacroAssembler::kReturnAtEnd); |
| 7748 | } else { |
| 7749 | __ Ret(); |
| 7750 | } |
| 7751 | |
| 7752 | __ bind(&on_black); |
| 7753 | |
| 7754 | // Get the value from the slot. |
| 7755 | __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0)); |
| 7756 | |
| 7757 | if (mode == INCREMENTAL_COMPACTION) { |
| 7758 | Label ensure_not_white; |
| 7759 | |
| 7760 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7761 | regs_.scratch1(), // Scratch. |
| 7762 | MemoryChunk::kEvacuationCandidateMask, |
| 7763 | eq, |
| 7764 | &ensure_not_white); |
| 7765 | |
| 7766 | __ CheckPageFlag(regs_.object(), |
| 7767 | regs_.scratch1(), // Scratch. |
| 7768 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7769 | eq, |
| 7770 | &need_incremental); |
| 7771 | |
| 7772 | __ bind(&ensure_not_white); |
| 7773 | } |
| 7774 | |
| 7775 | // We need extra registers for this, so we push the object and the address |
| 7776 | // register temporarily. |
| 7777 | __ Push(regs_.object(), regs_.address()); |
| 7778 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7779 | regs_.scratch1(), // Scratch. |
| 7780 | regs_.object(), // Scratch. |
| 7781 | regs_.address(), // Scratch. |
| 7782 | &need_incremental_pop_scratch); |
| 7783 | __ Pop(regs_.object(), regs_.address()); |
| 7784 | |
| 7785 | regs_.Restore(masm); |
| 7786 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7787 | __ RememberedSetHelper(object_, |
| 7788 | address_, |
| 7789 | value_, |
| 7790 | save_fp_regs_mode_, |
| 7791 | MacroAssembler::kReturnAtEnd); |
| 7792 | } else { |
| 7793 | __ Ret(); |
| 7794 | } |
| 7795 | |
| 7796 | __ bind(&need_incremental_pop_scratch); |
| 7797 | __ Pop(regs_.object(), regs_.address()); |
| 7798 | |
| 7799 | __ bind(&need_incremental); |
| 7800 | |
| 7801 | // Fall through when we need to inform the incremental marker. |
| 7802 | } |
| 7803 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7804 | |
| 7805 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7806 | // ----------- S t a t e ------------- |
| 7807 | // -- r0 : element value to store |
| 7808 | // -- r1 : array literal |
| 7809 | // -- r2 : map of array literal |
| 7810 | // -- r3 : element index as smi |
| 7811 | // -- r4 : array literal index in function as smi |
| 7812 | // ----------------------------------- |
| 7813 | |
| 7814 | Label element_done; |
| 7815 | Label double_elements; |
| 7816 | Label smi_element; |
| 7817 | Label slow_elements; |
| 7818 | Label fast_elements; |
| 7819 | |
| 7820 | __ CheckFastElements(r2, r5, &double_elements); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7821 | // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7822 | __ JumpIfSmi(r0, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7823 | __ CheckFastSmiElements(r2, r5, &fast_elements); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7824 | |
| 7825 | // Store into the array literal requires a elements transition. Call into |
| 7826 | // the runtime. |
| 7827 | __ bind(&slow_elements); |
| 7828 | // call. |
| 7829 | __ Push(r1, r3, r0); |
| 7830 | __ ldr(r5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7831 | __ ldr(r5, FieldMemOperand(r5, JSFunction::kLiteralsOffset)); |
| 7832 | __ Push(r5, r4); |
| 7833 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7834 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7835 | // 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] | 7836 | __ bind(&fast_elements); |
| 7837 | __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 7838 | __ add(r6, r5, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 7839 | __ add(r6, r6, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 7840 | __ str(r0, MemOperand(r6, 0)); |
| 7841 | // Update the write barrier for the array store. |
| 7842 | __ RecordWrite(r5, r6, r0, kLRHasNotBeenSaved, kDontSaveFPRegs, |
| 7843 | EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); |
| 7844 | __ Ret(); |
| 7845 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7846 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7847 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7848 | __ bind(&smi_element); |
| 7849 | __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 7850 | __ add(r6, r5, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 7851 | __ str(r0, FieldMemOperand(r6, FixedArray::kHeaderSize)); |
| 7852 | __ Ret(); |
| 7853 | |
| 7854 | // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS. |
| 7855 | __ bind(&double_elements); |
| 7856 | __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 7857 | __ StoreNumberToDoubleElements(r0, r3, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7858 | // Overwrites all regs after this. |
| 7859 | r5, r6, r7, r9, r2, |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7860 | &slow_elements); |
| 7861 | __ Ret(); |
| 7862 | } |
| 7863 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7864 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7865 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
| 7866 | ASSERT(!Serializer::enabled()); |
| 7867 | bool save_fp_regs = CpuFeatures::IsSupported(VFP2); |
| 7868 | CEntryStub ces(1, save_fp_regs ? kSaveFPRegs : kDontSaveFPRegs); |
| 7869 | __ Call(ces.GetCode(), RelocInfo::CODE_TARGET); |
| 7870 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 7871 | __ Ret(); |
| 7872 | } |
| 7873 | |
| 7874 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7875 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 7876 | if (entry_hook_ != NULL) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 7877 | PredictableCodeSizeScope predictable(masm, 4 * Assembler::kInstrSize); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7878 | ProfileEntryHookStub stub; |
| 7879 | __ push(lr); |
| 7880 | __ CallStub(&stub); |
| 7881 | __ pop(lr); |
| 7882 | } |
| 7883 | } |
| 7884 | |
| 7885 | |
| 7886 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 7887 | // The entry hook is a "push lr" instruction, followed by a call. |
| 7888 | const int32_t kReturnAddressDistanceFromFunctionStart = |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 7889 | 3 * Assembler::kInstrSize; |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7890 | |
| 7891 | // Save live volatile registers. |
| 7892 | __ Push(lr, r5, r1); |
| 7893 | const int32_t kNumSavedRegs = 3; |
| 7894 | |
| 7895 | // Compute the function's address for the first argument. |
| 7896 | __ sub(r0, lr, Operand(kReturnAddressDistanceFromFunctionStart)); |
| 7897 | |
| 7898 | // The caller's return address is above the saved temporaries. |
| 7899 | // Grab that for the second argument to the hook. |
| 7900 | __ add(r1, sp, Operand(kNumSavedRegs * kPointerSize)); |
| 7901 | |
| 7902 | // Align the stack if necessary. |
| 7903 | int frame_alignment = masm->ActivationFrameAlignment(); |
| 7904 | if (frame_alignment > kPointerSize) { |
| 7905 | __ mov(r5, sp); |
| 7906 | ASSERT(IsPowerOf2(frame_alignment)); |
| 7907 | __ and_(sp, sp, Operand(-frame_alignment)); |
| 7908 | } |
| 7909 | |
| 7910 | #if defined(V8_HOST_ARCH_ARM) |
| 7911 | __ mov(ip, Operand(reinterpret_cast<int32_t>(&entry_hook_))); |
| 7912 | __ ldr(ip, MemOperand(ip)); |
| 7913 | #else |
| 7914 | // Under the simulator we need to indirect the entry hook through a |
| 7915 | // trampoline function at a known address. |
| 7916 | Address trampoline_address = reinterpret_cast<Address>( |
| 7917 | reinterpret_cast<intptr_t>(EntryHookTrampoline)); |
| 7918 | ApiFunction dispatcher(trampoline_address); |
| 7919 | __ mov(ip, Operand(ExternalReference(&dispatcher, |
| 7920 | ExternalReference::BUILTIN_CALL, |
| 7921 | masm->isolate()))); |
| 7922 | #endif |
| 7923 | __ Call(ip); |
| 7924 | |
| 7925 | // Restore the stack pointer if needed. |
| 7926 | if (frame_alignment > kPointerSize) { |
| 7927 | __ mov(sp, r5); |
| 7928 | } |
| 7929 | |
| 7930 | __ Pop(lr, r5, r1); |
| 7931 | __ Ret(); |
| 7932 | } |
| 7933 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7934 | #undef __ |
| 7935 | |
| 7936 | } } // namespace v8::internal |
| 7937 | |
| 7938 | #endif // V8_TARGET_ARCH_ARM |