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" |
| 35 | |
| 36 | namespace v8 { |
| 37 | namespace internal { |
| 38 | |
| 39 | |
| 40 | #define __ ACCESS_MASM(masm) |
| 41 | |
| 42 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, |
| 43 | Label* slow, |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 44 | Condition cond, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 45 | bool never_nan_nan); |
| 46 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 47 | Register lhs, |
| 48 | Register rhs, |
| 49 | Label* lhs_not_nan, |
| 50 | Label* slow, |
| 51 | bool strict); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 52 | static void EmitTwoNonNanDoubleComparison(MacroAssembler* masm, Condition cond); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 53 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 54 | Register lhs, |
| 55 | Register rhs); |
| 56 | |
| 57 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 58 | // Check if the operand is a heap number. |
| 59 | static void EmitCheckForHeapNumber(MacroAssembler* masm, Register operand, |
| 60 | Register scratch1, Register scratch2, |
| 61 | Label* not_a_heap_number) { |
| 62 | __ ldr(scratch1, FieldMemOperand(operand, HeapObject::kMapOffset)); |
| 63 | __ LoadRoot(scratch2, Heap::kHeapNumberMapRootIndex); |
| 64 | __ cmp(scratch1, scratch2); |
| 65 | __ b(ne, not_a_heap_number); |
| 66 | } |
| 67 | |
| 68 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 69 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 70 | // The ToNumber stub takes one argument in eax. |
| 71 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 72 | __ JumpIfNotSmi(r0, &check_heap_number); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 73 | __ Ret(); |
| 74 | |
| 75 | __ bind(&check_heap_number); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 76 | EmitCheckForHeapNumber(masm, r0, r1, ip, &call_builtin); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 77 | __ Ret(); |
| 78 | |
| 79 | __ bind(&call_builtin); |
| 80 | __ push(r0); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 81 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 85 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 86 | // Create a new closure from the given function info in new |
| 87 | // space. Set the context to the current context in cp. |
| 88 | Label gc; |
| 89 | |
| 90 | // Pop the function info from the stack. |
| 91 | __ pop(r3); |
| 92 | |
| 93 | // Attempt to allocate new JSFunction in new space. |
| 94 | __ AllocateInNewSpace(JSFunction::kSize, |
| 95 | r0, |
| 96 | r1, |
| 97 | r2, |
| 98 | &gc, |
| 99 | TAG_OBJECT); |
| 100 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 101 | int map_index = (language_mode_ == CLASSIC_MODE) |
| 102 | ? Context::FUNCTION_MAP_INDEX |
| 103 | : Context::STRICT_MODE_FUNCTION_MAP_INDEX; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 104 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 105 | // Compute the function map in the current global context and set that |
| 106 | // as the map of the allocated object. |
| 107 | __ ldr(r2, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 108 | __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalContextOffset)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 109 | __ ldr(r2, MemOperand(r2, Context::SlotOffset(map_index))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 110 | __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 111 | |
| 112 | // Initialize the rest of the function. We don't have to update the |
| 113 | // write barrier because the allocated object is in new space. |
| 114 | __ LoadRoot(r1, Heap::kEmptyFixedArrayRootIndex); |
| 115 | __ LoadRoot(r2, Heap::kTheHoleValueRootIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 116 | __ LoadRoot(r4, Heap::kUndefinedValueRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 117 | __ str(r1, FieldMemOperand(r0, JSObject::kPropertiesOffset)); |
| 118 | __ str(r1, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 119 | __ str(r2, FieldMemOperand(r0, JSFunction::kPrototypeOrInitialMapOffset)); |
| 120 | __ str(r3, FieldMemOperand(r0, JSFunction::kSharedFunctionInfoOffset)); |
| 121 | __ str(cp, FieldMemOperand(r0, JSFunction::kContextOffset)); |
| 122 | __ str(r1, FieldMemOperand(r0, JSFunction::kLiteralsOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 123 | __ str(r4, FieldMemOperand(r0, JSFunction::kNextFunctionLinkOffset)); |
| 124 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 125 | // Initialize the code pointer in the function to be the one |
| 126 | // found in the shared function info object. |
| 127 | __ ldr(r3, FieldMemOperand(r3, SharedFunctionInfo::kCodeOffset)); |
| 128 | __ add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 129 | __ str(r3, FieldMemOperand(r0, JSFunction::kCodeEntryOffset)); |
| 130 | |
| 131 | // Return result. The argument function info has been popped already. |
| 132 | __ Ret(); |
| 133 | |
| 134 | // Create a new closure through the slower runtime call. |
| 135 | __ bind(&gc); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 136 | __ LoadRoot(r4, Heap::kFalseValueRootIndex); |
| 137 | __ Push(cp, r3, r4); |
| 138 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | |
| 142 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 143 | // Try to allocate the context in new space. |
| 144 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 145 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 146 | |
| 147 | // Attempt to allocate the context in new space. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 148 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 149 | r0, |
| 150 | r1, |
| 151 | r2, |
| 152 | &gc, |
| 153 | TAG_OBJECT); |
| 154 | |
| 155 | // Load the function from the stack. |
| 156 | __ ldr(r3, MemOperand(sp, 0)); |
| 157 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 158 | // Set up the object header. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 159 | __ LoadRoot(r1, Heap::kFunctionContextMapRootIndex); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 160 | __ mov(r2, Operand(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 161 | __ str(r2, FieldMemOperand(r0, FixedArray::kLengthOffset)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 162 | __ str(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 163 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 164 | // Set up the fixed slots, copy the global object from the previous context. |
| 165 | __ ldr(r2, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 166 | __ mov(r1, Operand(Smi::FromInt(0))); |
| 167 | __ str(r3, MemOperand(r0, Context::SlotOffset(Context::CLOSURE_INDEX))); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 168 | __ str(cp, MemOperand(r0, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 169 | __ str(r1, MemOperand(r0, Context::SlotOffset(Context::EXTENSION_INDEX))); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 170 | __ str(r2, MemOperand(r0, Context::SlotOffset(Context::GLOBAL_INDEX))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 171 | |
| 172 | // Initialize the rest of the slots to undefined. |
| 173 | __ LoadRoot(r1, Heap::kUndefinedValueRootIndex); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 174 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 175 | __ str(r1, MemOperand(r0, Context::SlotOffset(i))); |
| 176 | } |
| 177 | |
| 178 | // Remove the on-stack argument and return. |
| 179 | __ mov(cp, r0); |
| 180 | __ pop(); |
| 181 | __ Ret(); |
| 182 | |
| 183 | // Need to collect. Call into runtime system. |
| 184 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 185 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 189 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 190 | // Stack layout on entry: |
| 191 | // |
| 192 | // [sp]: function. |
| 193 | // [sp + kPointerSize]: serialized scope info |
| 194 | |
| 195 | // Try to allocate the context in new space. |
| 196 | Label gc; |
| 197 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 198 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
| 199 | r0, r1, r2, &gc, TAG_OBJECT); |
| 200 | |
| 201 | // Load the function from the stack. |
| 202 | __ ldr(r3, MemOperand(sp, 0)); |
| 203 | |
| 204 | // Load the serialized scope info from the stack. |
| 205 | __ ldr(r1, MemOperand(sp, 1 * kPointerSize)); |
| 206 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 207 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 208 | __ LoadRoot(r2, Heap::kBlockContextMapRootIndex); |
| 209 | __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 210 | __ mov(r2, Operand(Smi::FromInt(length))); |
| 211 | __ str(r2, FieldMemOperand(r0, FixedArray::kLengthOffset)); |
| 212 | |
| 213 | // If this block context is nested in the global context we get a smi |
| 214 | // sentinel instead of a function. The block context should get the |
| 215 | // canonical empty function of the global context as its closure which |
| 216 | // we still have to look up. |
| 217 | Label after_sentinel; |
| 218 | __ JumpIfNotSmi(r3, &after_sentinel); |
| 219 | if (FLAG_debug_code) { |
| 220 | const char* message = "Expected 0 as a Smi sentinel"; |
| 221 | __ cmp(r3, Operand::Zero()); |
| 222 | __ Assert(eq, message); |
| 223 | } |
| 224 | __ ldr(r3, GlobalObjectOperand()); |
| 225 | __ ldr(r3, FieldMemOperand(r3, GlobalObject::kGlobalContextOffset)); |
| 226 | __ ldr(r3, ContextOperand(r3, Context::CLOSURE_INDEX)); |
| 227 | __ bind(&after_sentinel); |
| 228 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 229 | // Set up the fixed slots, copy the global object from the previous context. |
| 230 | __ ldr(r2, ContextOperand(cp, Context::GLOBAL_INDEX)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 231 | __ str(r3, ContextOperand(r0, Context::CLOSURE_INDEX)); |
| 232 | __ str(cp, ContextOperand(r0, Context::PREVIOUS_INDEX)); |
| 233 | __ str(r1, ContextOperand(r0, Context::EXTENSION_INDEX)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 234 | __ str(r2, ContextOperand(r0, Context::GLOBAL_INDEX)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 235 | |
| 236 | // Initialize the rest of the slots to the hole value. |
| 237 | __ LoadRoot(r1, Heap::kTheHoleValueRootIndex); |
| 238 | for (int i = 0; i < slots_; i++) { |
| 239 | __ str(r1, ContextOperand(r0, i + Context::MIN_CONTEXT_SLOTS)); |
| 240 | } |
| 241 | |
| 242 | // Remove the on-stack argument and return. |
| 243 | __ mov(cp, r0); |
| 244 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 245 | __ Ret(); |
| 246 | |
| 247 | // Need to collect. Call into runtime system. |
| 248 | __ bind(&gc); |
| 249 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 250 | } |
| 251 | |
| 252 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 253 | static void GenerateFastCloneShallowArrayCommon( |
| 254 | MacroAssembler* masm, |
| 255 | int length, |
| 256 | FastCloneShallowArrayStub::Mode mode, |
| 257 | Label* fail) { |
| 258 | // Registers on entry: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 259 | // |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 260 | // r3: boilerplate literal array. |
| 261 | ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 262 | |
| 263 | // All sizes here are multiples of kPointerSize. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 264 | int elements_size = 0; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 265 | if (length > 0) { |
| 266 | elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
| 267 | ? FixedDoubleArray::SizeFor(length) |
| 268 | : FixedArray::SizeFor(length); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 269 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 270 | int size = JSArray::kSize + elements_size; |
| 271 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 272 | // Allocate both the JS array and the elements array in one big |
| 273 | // allocation. This avoids multiple limit checks. |
| 274 | __ AllocateInNewSpace(size, |
| 275 | r0, |
| 276 | r1, |
| 277 | r2, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 278 | fail, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 279 | TAG_OBJECT); |
| 280 | |
| 281 | // Copy the JS array part. |
| 282 | for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 283 | if ((i != JSArray::kElementsOffset) || (length == 0)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 284 | __ ldr(r1, FieldMemOperand(r3, i)); |
| 285 | __ str(r1, FieldMemOperand(r0, i)); |
| 286 | } |
| 287 | } |
| 288 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 289 | if (length > 0) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 290 | // Get hold of the elements array of the boilerplate and setup the |
| 291 | // elements pointer in the resulting object. |
| 292 | __ ldr(r3, FieldMemOperand(r3, JSArray::kElementsOffset)); |
| 293 | __ add(r2, r0, Operand(JSArray::kSize)); |
| 294 | __ str(r2, FieldMemOperand(r0, JSArray::kElementsOffset)); |
| 295 | |
| 296 | // Copy the elements array. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 297 | ASSERT((elements_size % kPointerSize) == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 298 | __ CopyFields(r2, r3, r1.bit(), elements_size / kPointerSize); |
| 299 | } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) { |
| 303 | // Stack layout on entry: |
| 304 | // |
| 305 | // [sp]: constant elements. |
| 306 | // [sp + kPointerSize]: literal index. |
| 307 | // [sp + (2 * kPointerSize)]: literals array. |
| 308 | |
| 309 | // Load boilerplate object into r3 and check if we need to create a |
| 310 | // boilerplate. |
| 311 | Label slow_case; |
| 312 | __ ldr(r3, MemOperand(sp, 2 * kPointerSize)); |
| 313 | __ ldr(r0, MemOperand(sp, 1 * kPointerSize)); |
| 314 | __ add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 315 | __ ldr(r3, MemOperand(r3, r0, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 316 | __ CompareRoot(r3, Heap::kUndefinedValueRootIndex); |
| 317 | __ b(eq, &slow_case); |
| 318 | |
| 319 | FastCloneShallowArrayStub::Mode mode = mode_; |
| 320 | if (mode == CLONE_ANY_ELEMENTS) { |
| 321 | Label double_elements, check_fast_elements; |
| 322 | __ ldr(r0, FieldMemOperand(r3, JSArray::kElementsOffset)); |
| 323 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 324 | __ CompareRoot(r0, Heap::kFixedCOWArrayMapRootIndex); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 325 | __ b(ne, &check_fast_elements); |
| 326 | GenerateFastCloneShallowArrayCommon(masm, 0, |
| 327 | COPY_ON_WRITE_ELEMENTS, &slow_case); |
| 328 | // Return and remove the on-stack parameters. |
| 329 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 330 | __ Ret(); |
| 331 | |
| 332 | __ bind(&check_fast_elements); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 333 | __ CompareRoot(r0, Heap::kFixedArrayMapRootIndex); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 334 | __ b(ne, &double_elements); |
| 335 | GenerateFastCloneShallowArrayCommon(masm, length_, |
| 336 | CLONE_ELEMENTS, &slow_case); |
| 337 | // Return and remove the on-stack parameters. |
| 338 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 339 | __ Ret(); |
| 340 | |
| 341 | __ bind(&double_elements); |
| 342 | mode = CLONE_DOUBLE_ELEMENTS; |
| 343 | // Fall through to generate the code to handle double elements. |
| 344 | } |
| 345 | |
| 346 | if (FLAG_debug_code) { |
| 347 | const char* message; |
| 348 | Heap::RootListIndex expected_map_index; |
| 349 | if (mode == CLONE_ELEMENTS) { |
| 350 | message = "Expected (writable) fixed array"; |
| 351 | expected_map_index = Heap::kFixedArrayMapRootIndex; |
| 352 | } else if (mode == CLONE_DOUBLE_ELEMENTS) { |
| 353 | message = "Expected (writable) fixed double array"; |
| 354 | expected_map_index = Heap::kFixedDoubleArrayMapRootIndex; |
| 355 | } else { |
| 356 | ASSERT(mode == COPY_ON_WRITE_ELEMENTS); |
| 357 | message = "Expected copy-on-write fixed array"; |
| 358 | expected_map_index = Heap::kFixedCOWArrayMapRootIndex; |
| 359 | } |
| 360 | __ push(r3); |
| 361 | __ ldr(r3, FieldMemOperand(r3, JSArray::kElementsOffset)); |
| 362 | __ ldr(r3, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 363 | __ CompareRoot(r3, expected_map_index); |
| 364 | __ Assert(eq, message); |
| 365 | __ pop(r3); |
| 366 | } |
| 367 | |
| 368 | GenerateFastCloneShallowArrayCommon(masm, length_, mode, &slow_case); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 369 | |
| 370 | // Return and remove the on-stack parameters. |
| 371 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 372 | __ Ret(); |
| 373 | |
| 374 | __ bind(&slow_case); |
| 375 | __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
| 376 | } |
| 377 | |
| 378 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 379 | void FastCloneShallowObjectStub::Generate(MacroAssembler* masm) { |
| 380 | // Stack layout on entry: |
| 381 | // |
| 382 | // [sp]: object literal flags. |
| 383 | // [sp + kPointerSize]: constant properties. |
| 384 | // [sp + (2 * kPointerSize)]: literal index. |
| 385 | // [sp + (3 * kPointerSize)]: literals array. |
| 386 | |
| 387 | // Load boilerplate object into r3 and check if we need to create a |
| 388 | // boilerplate. |
| 389 | Label slow_case; |
| 390 | __ ldr(r3, MemOperand(sp, 3 * kPointerSize)); |
| 391 | __ ldr(r0, MemOperand(sp, 2 * kPointerSize)); |
| 392 | __ add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 393 | __ ldr(r3, MemOperand(r3, r0, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 394 | __ CompareRoot(r3, Heap::kUndefinedValueRootIndex); |
| 395 | __ b(eq, &slow_case); |
| 396 | |
| 397 | // Check that the boilerplate contains only fast properties and we can |
| 398 | // statically determine the instance size. |
| 399 | int size = JSObject::kHeaderSize + length_ * kPointerSize; |
| 400 | __ ldr(r0, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 401 | __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceSizeOffset)); |
| 402 | __ cmp(r0, Operand(size >> kPointerSizeLog2)); |
| 403 | __ b(ne, &slow_case); |
| 404 | |
| 405 | // Allocate the JS object and copy header together with all in-object |
| 406 | // properties from the boilerplate. |
| 407 | __ AllocateInNewSpace(size, r0, r1, r2, &slow_case, TAG_OBJECT); |
| 408 | for (int i = 0; i < size; i += kPointerSize) { |
| 409 | __ ldr(r1, FieldMemOperand(r3, i)); |
| 410 | __ str(r1, FieldMemOperand(r0, i)); |
| 411 | } |
| 412 | |
| 413 | // Return and remove the on-stack parameters. |
| 414 | __ add(sp, sp, Operand(4 * kPointerSize)); |
| 415 | __ Ret(); |
| 416 | |
| 417 | __ bind(&slow_case); |
| 418 | __ TailCallRuntime(Runtime::kCreateObjectLiteralShallow, 4, 1); |
| 419 | } |
| 420 | |
| 421 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 422 | // Takes a Smi and converts to an IEEE 64 bit floating point value in two |
| 423 | // registers. The format is 1 sign bit, 11 exponent bits (biased 1023) and |
| 424 | // 52 fraction bits (20 in the first word, 32 in the second). Zeros is a |
| 425 | // scratch register. Destroys the source register. No GC occurs during this |
| 426 | // stub so you don't have to set up the frame. |
| 427 | class ConvertToDoubleStub : public CodeStub { |
| 428 | public: |
| 429 | ConvertToDoubleStub(Register result_reg_1, |
| 430 | Register result_reg_2, |
| 431 | Register source_reg, |
| 432 | Register scratch_reg) |
| 433 | : result1_(result_reg_1), |
| 434 | result2_(result_reg_2), |
| 435 | source_(source_reg), |
| 436 | zeros_(scratch_reg) { } |
| 437 | |
| 438 | private: |
| 439 | Register result1_; |
| 440 | Register result2_; |
| 441 | Register source_; |
| 442 | Register zeros_; |
| 443 | |
| 444 | // Minor key encoding in 16 bits. |
| 445 | class ModeBits: public BitField<OverwriteMode, 0, 2> {}; |
| 446 | class OpBits: public BitField<Token::Value, 2, 14> {}; |
| 447 | |
| 448 | Major MajorKey() { return ConvertToDouble; } |
| 449 | int MinorKey() { |
| 450 | // Encode the parameters in a unique 16 bit value. |
| 451 | return result1_.code() + |
| 452 | (result2_.code() << 4) + |
| 453 | (source_.code() << 8) + |
| 454 | (zeros_.code() << 12); |
| 455 | } |
| 456 | |
| 457 | void Generate(MacroAssembler* masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 458 | }; |
| 459 | |
| 460 | |
| 461 | void ConvertToDoubleStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 462 | Register exponent = result1_; |
| 463 | Register mantissa = result2_; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 464 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 465 | Label not_special; |
| 466 | // Convert from Smi to integer. |
| 467 | __ mov(source_, Operand(source_, ASR, kSmiTagSize)); |
| 468 | // Move sign bit from source to destination. This works because the sign bit |
| 469 | // in the exponent word of the double has the same position and polarity as |
| 470 | // the 2's complement sign bit in a Smi. |
| 471 | STATIC_ASSERT(HeapNumber::kSignMask == 0x80000000u); |
| 472 | __ and_(exponent, source_, Operand(HeapNumber::kSignMask), SetCC); |
| 473 | // Subtract from 0 if source was negative. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 474 | __ rsb(source_, source_, Operand(0, RelocInfo::NONE), LeaveCC, ne); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 475 | |
| 476 | // We have -1, 0 or 1, which we treat specially. Register source_ contains |
| 477 | // absolute value: it is either equal to 1 (special case of -1 and 1), |
| 478 | // greater than 1 (not a special case) or less than 1 (special case of 0). |
| 479 | __ cmp(source_, Operand(1)); |
| 480 | __ b(gt, ¬_special); |
| 481 | |
| 482 | // 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] | 483 | const uint32_t exponent_word_for_1 = |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 484 | HeapNumber::kExponentBias << HeapNumber::kExponentShift; |
| 485 | __ orr(exponent, exponent, Operand(exponent_word_for_1), LeaveCC, eq); |
| 486 | // 1, 0 and -1 all have 0 for the second word. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 487 | __ mov(mantissa, Operand(0, RelocInfo::NONE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 488 | __ Ret(); |
| 489 | |
| 490 | __ bind(¬_special); |
| 491 | // Count leading zeros. Uses mantissa for a scratch register on pre-ARM5. |
| 492 | // Gets the wrong answer for 0, but we already checked for that case above. |
| 493 | __ CountLeadingZeros(zeros_, source_, mantissa); |
| 494 | // Compute exponent and or it into the exponent register. |
| 495 | // We use mantissa as a scratch register here. Use a fudge factor to |
| 496 | // divide the constant 31 + HeapNumber::kExponentBias, 0x41d, into two parts |
| 497 | // that fit in the ARM's constant field. |
| 498 | int fudge = 0x400; |
| 499 | __ rsb(mantissa, zeros_, Operand(31 + HeapNumber::kExponentBias - fudge)); |
| 500 | __ add(mantissa, mantissa, Operand(fudge)); |
| 501 | __ orr(exponent, |
| 502 | exponent, |
| 503 | Operand(mantissa, LSL, HeapNumber::kExponentShift)); |
| 504 | // Shift up the source chopping the top bit off. |
| 505 | __ add(zeros_, zeros_, Operand(1)); |
| 506 | // This wouldn't work for 1.0 or -1.0 as the shift would be 32 which means 0. |
| 507 | __ mov(source_, Operand(source_, LSL, zeros_)); |
| 508 | // Compute lower part of fraction (last 12 bits). |
| 509 | __ mov(mantissa, Operand(source_, LSL, HeapNumber::kMantissaBitsInTopWord)); |
| 510 | // And the top (top 20 bits). |
| 511 | __ orr(exponent, |
| 512 | exponent, |
| 513 | Operand(source_, LSR, 32 - HeapNumber::kMantissaBitsInTopWord)); |
| 514 | __ Ret(); |
| 515 | } |
| 516 | |
| 517 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 518 | void FloatingPointHelper::LoadSmis(MacroAssembler* masm, |
| 519 | FloatingPointHelper::Destination destination, |
| 520 | Register scratch1, |
| 521 | Register scratch2) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 522 | if (CpuFeatures::IsSupported(VFP3)) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 523 | CpuFeatures::Scope scope(VFP3); |
| 524 | __ mov(scratch1, Operand(r0, ASR, kSmiTagSize)); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 525 | __ vmov(d7.high(), scratch1); |
| 526 | __ vcvt_f64_s32(d7, d7.high()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 527 | __ mov(scratch1, Operand(r1, ASR, kSmiTagSize)); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 528 | __ vmov(d6.high(), scratch1); |
| 529 | __ vcvt_f64_s32(d6, d6.high()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 530 | if (destination == kCoreRegisters) { |
| 531 | __ vmov(r2, r3, d7); |
| 532 | __ vmov(r0, r1, d6); |
| 533 | } |
| 534 | } else { |
| 535 | ASSERT(destination == kCoreRegisters); |
| 536 | // Write Smi from r0 to r3 and r2 in double format. |
| 537 | __ mov(scratch1, Operand(r0)); |
| 538 | ConvertToDoubleStub stub1(r3, r2, scratch1, scratch2); |
| 539 | __ push(lr); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 540 | __ Call(stub1.GetCode()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 541 | // Write Smi from r1 to r1 and r0 in double format. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 542 | __ mov(scratch1, Operand(r1)); |
| 543 | ConvertToDoubleStub stub2(r1, r0, scratch1, scratch2); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 544 | __ Call(stub2.GetCode()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 545 | __ pop(lr); |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | |
| 550 | void FloatingPointHelper::LoadOperands( |
| 551 | MacroAssembler* masm, |
| 552 | FloatingPointHelper::Destination destination, |
| 553 | Register heap_number_map, |
| 554 | Register scratch1, |
| 555 | Register scratch2, |
| 556 | Label* slow) { |
| 557 | |
| 558 | // Load right operand (r0) to d6 or r2/r3. |
| 559 | LoadNumber(masm, destination, |
| 560 | r0, d7, r2, r3, heap_number_map, scratch1, scratch2, slow); |
| 561 | |
| 562 | // Load left operand (r1) to d7 or r0/r1. |
| 563 | LoadNumber(masm, destination, |
| 564 | r1, d6, r0, r1, heap_number_map, scratch1, scratch2, slow); |
| 565 | } |
| 566 | |
| 567 | |
| 568 | void FloatingPointHelper::LoadNumber(MacroAssembler* masm, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 569 | Destination destination, |
| 570 | Register object, |
| 571 | DwVfpRegister dst, |
| 572 | Register dst1, |
| 573 | Register dst2, |
| 574 | Register heap_number_map, |
| 575 | Register scratch1, |
| 576 | Register scratch2, |
| 577 | Label* not_number) { |
| 578 | if (FLAG_debug_code) { |
| 579 | __ AbortIfNotRootValue(heap_number_map, |
| 580 | Heap::kHeapNumberMapRootIndex, |
| 581 | "HeapNumberMap register clobbered."); |
| 582 | } |
| 583 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 584 | Label is_smi, done; |
| 585 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 586 | // Smi-check |
| 587 | __ UntagAndJumpIfSmi(scratch1, object, &is_smi); |
| 588 | // Heap number check |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 589 | __ JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_number); |
| 590 | |
| 591 | // Handle loading a double from a heap number. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 592 | if (CpuFeatures::IsSupported(VFP3) && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 593 | destination == kVFPRegisters) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 594 | CpuFeatures::Scope scope(VFP3); |
| 595 | // Load the double from tagged HeapNumber to double register. |
| 596 | __ sub(scratch1, object, Operand(kHeapObjectTag)); |
| 597 | __ vldr(dst, scratch1, HeapNumber::kValueOffset); |
| 598 | } else { |
| 599 | ASSERT(destination == kCoreRegisters); |
| 600 | // Load the double from heap number to dst1 and dst2 in double format. |
| 601 | __ Ldrd(dst1, dst2, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 602 | } |
| 603 | __ jmp(&done); |
| 604 | |
| 605 | // Handle loading a double from a smi. |
| 606 | __ bind(&is_smi); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 607 | if (CpuFeatures::IsSupported(VFP3)) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 608 | CpuFeatures::Scope scope(VFP3); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 609 | // Convert smi to double using VFP instructions. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 610 | __ vmov(dst.high(), scratch1); |
| 611 | __ vcvt_f64_s32(dst, dst.high()); |
| 612 | if (destination == kCoreRegisters) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 613 | // Load the converted smi to dst1 and dst2 in double format. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 614 | __ vmov(dst1, dst2, dst); |
| 615 | } |
| 616 | } else { |
| 617 | ASSERT(destination == kCoreRegisters); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 618 | // Write smi to dst1 and dst2 double format. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 619 | __ mov(scratch1, Operand(object)); |
| 620 | ConvertToDoubleStub stub(dst2, dst1, scratch1, scratch2); |
| 621 | __ push(lr); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 622 | __ Call(stub.GetCode()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 623 | __ pop(lr); |
| 624 | } |
| 625 | |
| 626 | __ bind(&done); |
| 627 | } |
| 628 | |
| 629 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 630 | void FloatingPointHelper::ConvertNumberToInt32(MacroAssembler* masm, |
| 631 | Register object, |
| 632 | Register dst, |
| 633 | Register heap_number_map, |
| 634 | Register scratch1, |
| 635 | Register scratch2, |
| 636 | Register scratch3, |
| 637 | DwVfpRegister double_scratch, |
| 638 | Label* not_number) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 639 | if (FLAG_debug_code) { |
| 640 | __ AbortIfNotRootValue(heap_number_map, |
| 641 | Heap::kHeapNumberMapRootIndex, |
| 642 | "HeapNumberMap register clobbered."); |
| 643 | } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 644 | Label done; |
| 645 | Label not_in_int32_range; |
| 646 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 647 | __ UntagAndJumpIfSmi(dst, object, &done); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 648 | __ ldr(scratch1, FieldMemOperand(object, HeapNumber::kMapOffset)); |
| 649 | __ cmp(scratch1, heap_number_map); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 650 | __ b(ne, not_number); |
| 651 | __ ConvertToInt32(object, |
| 652 | dst, |
| 653 | scratch1, |
| 654 | scratch2, |
| 655 | double_scratch, |
| 656 | ¬_in_int32_range); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 657 | __ jmp(&done); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 658 | |
| 659 | __ bind(¬_in_int32_range); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 660 | __ ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 661 | __ ldr(scratch2, FieldMemOperand(object, HeapNumber::kMantissaOffset)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 662 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 663 | __ EmitOutOfInt32RangeTruncate(dst, |
| 664 | scratch1, |
| 665 | scratch2, |
| 666 | scratch3); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 667 | __ bind(&done); |
| 668 | } |
| 669 | |
| 670 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 671 | void FloatingPointHelper::ConvertIntToDouble(MacroAssembler* masm, |
| 672 | Register int_scratch, |
| 673 | Destination destination, |
| 674 | DwVfpRegister double_dst, |
| 675 | Register dst1, |
| 676 | Register dst2, |
| 677 | Register scratch2, |
| 678 | SwVfpRegister single_scratch) { |
| 679 | ASSERT(!int_scratch.is(scratch2)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 680 | ASSERT(!int_scratch.is(dst1)); |
| 681 | ASSERT(!int_scratch.is(dst2)); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 682 | |
| 683 | Label done; |
| 684 | |
| 685 | if (CpuFeatures::IsSupported(VFP3)) { |
| 686 | CpuFeatures::Scope scope(VFP3); |
| 687 | __ vmov(single_scratch, int_scratch); |
| 688 | __ vcvt_f64_s32(double_dst, single_scratch); |
| 689 | if (destination == kCoreRegisters) { |
| 690 | __ vmov(dst1, dst2, double_dst); |
| 691 | } |
| 692 | } else { |
| 693 | Label fewer_than_20_useful_bits; |
| 694 | // Expected output: |
| 695 | // | dst2 | dst1 | |
| 696 | // | s | exp | mantissa | |
| 697 | |
| 698 | // Check for zero. |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 699 | __ cmp(int_scratch, Operand::Zero()); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 700 | __ mov(dst2, int_scratch); |
| 701 | __ mov(dst1, int_scratch); |
| 702 | __ b(eq, &done); |
| 703 | |
| 704 | // Preload the sign of the value. |
| 705 | __ and_(dst2, int_scratch, Operand(HeapNumber::kSignMask), SetCC); |
| 706 | // Get the absolute value of the object (as an unsigned integer). |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 707 | __ rsb(int_scratch, int_scratch, Operand::Zero(), SetCC, mi); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 708 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 709 | // Get mantissa[51:20]. |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 710 | |
| 711 | // Get the position of the first set bit. |
| 712 | __ CountLeadingZeros(dst1, int_scratch, scratch2); |
| 713 | __ rsb(dst1, dst1, Operand(31)); |
| 714 | |
| 715 | // Set the exponent. |
| 716 | __ add(scratch2, dst1, Operand(HeapNumber::kExponentBias)); |
| 717 | __ Bfi(dst2, scratch2, scratch2, |
| 718 | HeapNumber::kExponentShift, HeapNumber::kExponentBits); |
| 719 | |
| 720 | // Clear the first non null bit. |
| 721 | __ mov(scratch2, Operand(1)); |
| 722 | __ bic(int_scratch, int_scratch, Operand(scratch2, LSL, dst1)); |
| 723 | |
| 724 | __ cmp(dst1, Operand(HeapNumber::kMantissaBitsInTopWord)); |
| 725 | // Get the number of bits to set in the lower part of the mantissa. |
| 726 | __ sub(scratch2, dst1, Operand(HeapNumber::kMantissaBitsInTopWord), SetCC); |
| 727 | __ b(mi, &fewer_than_20_useful_bits); |
| 728 | // Set the higher 20 bits of the mantissa. |
| 729 | __ orr(dst2, dst2, Operand(int_scratch, LSR, scratch2)); |
| 730 | __ rsb(scratch2, scratch2, Operand(32)); |
| 731 | __ mov(dst1, Operand(int_scratch, LSL, scratch2)); |
| 732 | __ b(&done); |
| 733 | |
| 734 | __ bind(&fewer_than_20_useful_bits); |
| 735 | __ rsb(scratch2, dst1, Operand(HeapNumber::kMantissaBitsInTopWord)); |
| 736 | __ mov(scratch2, Operand(int_scratch, LSL, scratch2)); |
| 737 | __ orr(dst2, dst2, scratch2); |
| 738 | // Set dst1 to 0. |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 739 | __ mov(dst1, Operand::Zero()); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 740 | } |
| 741 | __ bind(&done); |
| 742 | } |
| 743 | |
| 744 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 745 | void FloatingPointHelper::LoadNumberAsInt32Double(MacroAssembler* masm, |
| 746 | Register object, |
| 747 | Destination destination, |
| 748 | DwVfpRegister double_dst, |
| 749 | Register dst1, |
| 750 | Register dst2, |
| 751 | Register heap_number_map, |
| 752 | Register scratch1, |
| 753 | Register scratch2, |
| 754 | SwVfpRegister single_scratch, |
| 755 | Label* not_int32) { |
| 756 | ASSERT(!scratch1.is(object) && !scratch2.is(object)); |
| 757 | ASSERT(!scratch1.is(scratch2)); |
| 758 | ASSERT(!heap_number_map.is(object) && |
| 759 | !heap_number_map.is(scratch1) && |
| 760 | !heap_number_map.is(scratch2)); |
| 761 | |
| 762 | Label done, obj_is_not_smi; |
| 763 | |
| 764 | __ JumpIfNotSmi(object, &obj_is_not_smi); |
| 765 | __ SmiUntag(scratch1, object); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 766 | ConvertIntToDouble(masm, scratch1, destination, double_dst, dst1, dst2, |
| 767 | scratch2, single_scratch); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 768 | __ b(&done); |
| 769 | |
| 770 | __ bind(&obj_is_not_smi); |
| 771 | if (FLAG_debug_code) { |
| 772 | __ AbortIfNotRootValue(heap_number_map, |
| 773 | Heap::kHeapNumberMapRootIndex, |
| 774 | "HeapNumberMap register clobbered."); |
| 775 | } |
| 776 | __ JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_int32); |
| 777 | |
| 778 | // Load the number. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 779 | if (CpuFeatures::IsSupported(VFP3)) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 780 | CpuFeatures::Scope scope(VFP3); |
| 781 | // Load the double value. |
| 782 | __ sub(scratch1, object, Operand(kHeapObjectTag)); |
| 783 | __ vldr(double_dst, scratch1, HeapNumber::kValueOffset); |
| 784 | |
| 785 | __ EmitVFPTruncate(kRoundToZero, |
| 786 | single_scratch, |
| 787 | double_dst, |
| 788 | scratch1, |
| 789 | scratch2, |
| 790 | kCheckForInexactConversion); |
| 791 | |
| 792 | // Jump to not_int32 if the operation did not succeed. |
| 793 | __ b(ne, not_int32); |
| 794 | |
| 795 | if (destination == kCoreRegisters) { |
| 796 | __ vmov(dst1, dst2, double_dst); |
| 797 | } |
| 798 | |
| 799 | } else { |
| 800 | ASSERT(!scratch1.is(object) && !scratch2.is(object)); |
| 801 | // Load the double value in the destination registers.. |
| 802 | __ Ldrd(dst1, dst2, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 803 | |
| 804 | // Check for 0 and -0. |
| 805 | __ bic(scratch1, dst1, Operand(HeapNumber::kSignMask)); |
| 806 | __ orr(scratch1, scratch1, Operand(dst2)); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 807 | __ cmp(scratch1, Operand::Zero()); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 808 | __ b(eq, &done); |
| 809 | |
| 810 | // Check that the value can be exactly represented by a 32-bit integer. |
| 811 | // Jump to not_int32 if that's not the case. |
| 812 | DoubleIs32BitInteger(masm, dst1, dst2, scratch1, scratch2, not_int32); |
| 813 | |
| 814 | // dst1 and dst2 were trashed. Reload the double value. |
| 815 | __ Ldrd(dst1, dst2, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 816 | } |
| 817 | |
| 818 | __ bind(&done); |
| 819 | } |
| 820 | |
| 821 | |
| 822 | void FloatingPointHelper::LoadNumberAsInt32(MacroAssembler* masm, |
| 823 | Register object, |
| 824 | Register dst, |
| 825 | Register heap_number_map, |
| 826 | Register scratch1, |
| 827 | Register scratch2, |
| 828 | Register scratch3, |
| 829 | DwVfpRegister double_scratch, |
| 830 | Label* not_int32) { |
| 831 | ASSERT(!dst.is(object)); |
| 832 | ASSERT(!scratch1.is(object) && !scratch2.is(object) && !scratch3.is(object)); |
| 833 | ASSERT(!scratch1.is(scratch2) && |
| 834 | !scratch1.is(scratch3) && |
| 835 | !scratch2.is(scratch3)); |
| 836 | |
| 837 | Label done; |
| 838 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 839 | __ UntagAndJumpIfSmi(dst, object, &done); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 840 | |
| 841 | if (FLAG_debug_code) { |
| 842 | __ AbortIfNotRootValue(heap_number_map, |
| 843 | Heap::kHeapNumberMapRootIndex, |
| 844 | "HeapNumberMap register clobbered."); |
| 845 | } |
| 846 | __ JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_int32); |
| 847 | |
| 848 | // Object is a heap number. |
| 849 | // Convert the floating point value to a 32-bit integer. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 850 | if (CpuFeatures::IsSupported(VFP3)) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 851 | CpuFeatures::Scope scope(VFP3); |
| 852 | SwVfpRegister single_scratch = double_scratch.low(); |
| 853 | // Load the double value. |
| 854 | __ sub(scratch1, object, Operand(kHeapObjectTag)); |
| 855 | __ vldr(double_scratch, scratch1, HeapNumber::kValueOffset); |
| 856 | |
| 857 | __ EmitVFPTruncate(kRoundToZero, |
| 858 | single_scratch, |
| 859 | double_scratch, |
| 860 | scratch1, |
| 861 | scratch2, |
| 862 | kCheckForInexactConversion); |
| 863 | |
| 864 | // Jump to not_int32 if the operation did not succeed. |
| 865 | __ b(ne, not_int32); |
| 866 | // Get the result in the destination register. |
| 867 | __ vmov(dst, single_scratch); |
| 868 | |
| 869 | } else { |
| 870 | // Load the double value in the destination registers. |
| 871 | __ ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 872 | __ ldr(scratch2, FieldMemOperand(object, HeapNumber::kMantissaOffset)); |
| 873 | |
| 874 | // Check for 0 and -0. |
| 875 | __ bic(dst, scratch1, Operand(HeapNumber::kSignMask)); |
| 876 | __ orr(dst, scratch2, Operand(dst)); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 877 | __ cmp(dst, Operand::Zero()); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 878 | __ b(eq, &done); |
| 879 | |
| 880 | DoubleIs32BitInteger(masm, scratch1, scratch2, dst, scratch3, not_int32); |
| 881 | |
| 882 | // Registers state after DoubleIs32BitInteger. |
| 883 | // dst: mantissa[51:20]. |
| 884 | // scratch2: 1 |
| 885 | |
| 886 | // Shift back the higher bits of the mantissa. |
| 887 | __ mov(dst, Operand(dst, LSR, scratch3)); |
| 888 | // Set the implicit first bit. |
| 889 | __ rsb(scratch3, scratch3, Operand(32)); |
| 890 | __ orr(dst, dst, Operand(scratch2, LSL, scratch3)); |
| 891 | // Set the sign. |
| 892 | __ ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 893 | __ tst(scratch1, Operand(HeapNumber::kSignMask)); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 894 | __ rsb(dst, dst, Operand::Zero(), LeaveCC, mi); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | __ bind(&done); |
| 898 | } |
| 899 | |
| 900 | |
| 901 | void FloatingPointHelper::DoubleIs32BitInteger(MacroAssembler* masm, |
| 902 | Register src1, |
| 903 | Register src2, |
| 904 | Register dst, |
| 905 | Register scratch, |
| 906 | Label* not_int32) { |
| 907 | // Get exponent alone in scratch. |
| 908 | __ Ubfx(scratch, |
| 909 | src1, |
| 910 | HeapNumber::kExponentShift, |
| 911 | HeapNumber::kExponentBits); |
| 912 | |
| 913 | // Substract the bias from the exponent. |
| 914 | __ sub(scratch, scratch, Operand(HeapNumber::kExponentBias), SetCC); |
| 915 | |
| 916 | // src1: higher (exponent) part of the double value. |
| 917 | // src2: lower (mantissa) part of the double value. |
| 918 | // scratch: unbiased exponent. |
| 919 | |
| 920 | // Fast cases. Check for obvious non 32-bit integer values. |
| 921 | // Negative exponent cannot yield 32-bit integers. |
| 922 | __ b(mi, not_int32); |
| 923 | // Exponent greater than 31 cannot yield 32-bit integers. |
| 924 | // Also, a positive value with an exponent equal to 31 is outside of the |
| 925 | // signed 32-bit integer range. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 926 | // Another way to put it is that if (exponent - signbit) > 30 then the |
| 927 | // number cannot be represented as an int32. |
| 928 | Register tmp = dst; |
| 929 | __ sub(tmp, scratch, Operand(src1, LSR, 31)); |
| 930 | __ cmp(tmp, Operand(30)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 931 | __ b(gt, not_int32); |
| 932 | // - Bits [21:0] in the mantissa are not null. |
| 933 | __ tst(src2, Operand(0x3fffff)); |
| 934 | __ b(ne, not_int32); |
| 935 | |
| 936 | // Otherwise the exponent needs to be big enough to shift left all the |
| 937 | // non zero bits left. So we need the (30 - exponent) last bits of the |
| 938 | // 31 higher bits of the mantissa to be null. |
| 939 | // 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] | 940 | // (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] | 941 | |
| 942 | // Get the 32 higher bits of the mantissa in dst. |
| 943 | __ Ubfx(dst, |
| 944 | src2, |
| 945 | HeapNumber::kMantissaBitsInTopWord, |
| 946 | 32 - HeapNumber::kMantissaBitsInTopWord); |
| 947 | __ orr(dst, |
| 948 | dst, |
| 949 | Operand(src1, LSL, HeapNumber::kNonMantissaBitsInTopWord)); |
| 950 | |
| 951 | // Create the mask and test the lower bits (of the higher bits). |
| 952 | __ rsb(scratch, scratch, Operand(32)); |
| 953 | __ mov(src2, Operand(1)); |
| 954 | __ mov(src1, Operand(src2, LSL, scratch)); |
| 955 | __ sub(src1, src1, Operand(1)); |
| 956 | __ tst(dst, src1); |
| 957 | __ b(ne, not_int32); |
| 958 | } |
| 959 | |
| 960 | |
| 961 | void FloatingPointHelper::CallCCodeForDoubleOperation( |
| 962 | MacroAssembler* masm, |
| 963 | Token::Value op, |
| 964 | Register heap_number_result, |
| 965 | Register scratch) { |
| 966 | // Using core registers: |
| 967 | // r0: Left value (least significant part of mantissa). |
| 968 | // r1: Left value (sign, exponent, top of mantissa). |
| 969 | // r2: Right value (least significant part of mantissa). |
| 970 | // r3: Right value (sign, exponent, top of mantissa). |
| 971 | |
| 972 | // Assert that heap_number_result is callee-saved. |
| 973 | // We currently always use r5 to pass it. |
| 974 | ASSERT(heap_number_result.is(r5)); |
| 975 | |
| 976 | // Push the current return address before the C call. Return will be |
| 977 | // through pop(pc) below. |
| 978 | __ push(lr); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 979 | __ PrepareCallCFunction(0, 2, scratch); |
| 980 | if (masm->use_eabi_hardfloat()) { |
| 981 | CpuFeatures::Scope scope(VFP3); |
| 982 | __ vmov(d0, r0, r1); |
| 983 | __ vmov(d1, r2, r3); |
| 984 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 985 | { |
| 986 | AllowExternalCallThatCantCauseGC scope(masm); |
| 987 | __ CallCFunction( |
| 988 | ExternalReference::double_fp_operation(op, masm->isolate()), 0, 2); |
| 989 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 990 | // Store answer in the overwritable heap number. Double returned in |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 991 | // registers r0 and r1 or in d0. |
| 992 | if (masm->use_eabi_hardfloat()) { |
| 993 | CpuFeatures::Scope scope(VFP3); |
| 994 | __ vstr(d0, |
| 995 | FieldMemOperand(heap_number_result, HeapNumber::kValueOffset)); |
| 996 | } else { |
| 997 | __ Strd(r0, r1, FieldMemOperand(heap_number_result, |
| 998 | HeapNumber::kValueOffset)); |
| 999 | } |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1000 | // Place heap_number_result in r0 and return to the pushed return address. |
| 1001 | __ mov(r0, Operand(heap_number_result)); |
| 1002 | __ pop(pc); |
| 1003 | } |
| 1004 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1005 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1006 | bool WriteInt32ToHeapNumberStub::IsPregenerated() { |
| 1007 | // These variants are compiled ahead of time. See next method. |
| 1008 | if (the_int_.is(r1) && the_heap_number_.is(r0) && scratch_.is(r2)) { |
| 1009 | return true; |
| 1010 | } |
| 1011 | if (the_int_.is(r2) && the_heap_number_.is(r0) && scratch_.is(r3)) { |
| 1012 | return true; |
| 1013 | } |
| 1014 | // Other register combinations are generated as and when they are needed, |
| 1015 | // so it is unsafe to call them from stubs (we can't generate a stub while |
| 1016 | // we are generating a stub). |
| 1017 | return false; |
| 1018 | } |
| 1019 | |
| 1020 | |
| 1021 | void WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime() { |
| 1022 | WriteInt32ToHeapNumberStub stub1(r1, r0, r2); |
| 1023 | WriteInt32ToHeapNumberStub stub2(r2, r0, r3); |
| 1024 | stub1.GetCode()->set_is_pregenerated(true); |
| 1025 | stub2.GetCode()->set_is_pregenerated(true); |
| 1026 | } |
| 1027 | |
| 1028 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1029 | // See comment for class. |
| 1030 | void WriteInt32ToHeapNumberStub::Generate(MacroAssembler* masm) { |
| 1031 | Label max_negative_int; |
| 1032 | // the_int_ has the answer which is a signed int32 but not a Smi. |
| 1033 | // We test for the special value that has a different exponent. This test |
| 1034 | // has the neat side effect of setting the flags according to the sign. |
| 1035 | STATIC_ASSERT(HeapNumber::kSignMask == 0x80000000u); |
| 1036 | __ cmp(the_int_, Operand(0x80000000u)); |
| 1037 | __ b(eq, &max_negative_int); |
| 1038 | // Set up the correct exponent in scratch_. All non-Smi int32s have the same. |
| 1039 | // A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased). |
| 1040 | uint32_t non_smi_exponent = |
| 1041 | (HeapNumber::kExponentBias + 30) << HeapNumber::kExponentShift; |
| 1042 | __ mov(scratch_, Operand(non_smi_exponent)); |
| 1043 | // Set the sign bit in scratch_ if the value was negative. |
| 1044 | __ orr(scratch_, scratch_, Operand(HeapNumber::kSignMask), LeaveCC, cs); |
| 1045 | // Subtract from 0 if the value was negative. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1046 | __ rsb(the_int_, the_int_, Operand(0, RelocInfo::NONE), LeaveCC, cs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1047 | // We should be masking the implict first digit of the mantissa away here, |
| 1048 | // but it just ends up combining harmlessly with the last digit of the |
| 1049 | // exponent that happens to be 1. The sign bit is 0 so we shift 10 to get |
| 1050 | // the most significant 1 to hit the last bit of the 12 bit sign and exponent. |
| 1051 | ASSERT(((1 << HeapNumber::kExponentShift) & non_smi_exponent) != 0); |
| 1052 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 1053 | __ orr(scratch_, scratch_, Operand(the_int_, LSR, shift_distance)); |
| 1054 | __ str(scratch_, FieldMemOperand(the_heap_number_, |
| 1055 | HeapNumber::kExponentOffset)); |
| 1056 | __ mov(scratch_, Operand(the_int_, LSL, 32 - shift_distance)); |
| 1057 | __ str(scratch_, FieldMemOperand(the_heap_number_, |
| 1058 | HeapNumber::kMantissaOffset)); |
| 1059 | __ Ret(); |
| 1060 | |
| 1061 | __ bind(&max_negative_int); |
| 1062 | // The max negative int32 is stored as a positive number in the mantissa of |
| 1063 | // a double because it uses a sign bit instead of using two's complement. |
| 1064 | // The actual mantissa bits stored are all 0 because the implicit most |
| 1065 | // significant 1 bit is not stored. |
| 1066 | non_smi_exponent += 1 << HeapNumber::kExponentShift; |
| 1067 | __ mov(ip, Operand(HeapNumber::kSignMask | non_smi_exponent)); |
| 1068 | __ str(ip, FieldMemOperand(the_heap_number_, HeapNumber::kExponentOffset)); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1069 | __ mov(ip, Operand(0, RelocInfo::NONE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1070 | __ str(ip, FieldMemOperand(the_heap_number_, HeapNumber::kMantissaOffset)); |
| 1071 | __ Ret(); |
| 1072 | } |
| 1073 | |
| 1074 | |
| 1075 | // Handle the case where the lhs and rhs are the same object. |
| 1076 | // Equality is almost reflexive (everything but NaN), so this is a test |
| 1077 | // for "identity and not NaN". |
| 1078 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, |
| 1079 | Label* slow, |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1080 | Condition cond, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1081 | bool never_nan_nan) { |
| 1082 | Label not_identical; |
| 1083 | Label heap_number, return_equal; |
| 1084 | __ cmp(r0, r1); |
| 1085 | __ b(ne, ¬_identical); |
| 1086 | |
| 1087 | // The two objects are identical. If we know that one of them isn't NaN then |
| 1088 | // we now know they test equal. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1089 | if (cond != eq || !never_nan_nan) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1090 | // Test for NaN. Sadly, we can't just compare to FACTORY->nan_value(), |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1091 | // so we do the second best thing - test it ourselves. |
| 1092 | // They are both equal and they are not both Smis so both of them are not |
| 1093 | // Smis. If it's not a heap number, then return equal. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1094 | if (cond == lt || cond == gt) { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1095 | __ CompareObjectType(r0, r4, r4, FIRST_SPEC_OBJECT_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1096 | __ b(ge, slow); |
| 1097 | } else { |
| 1098 | __ CompareObjectType(r0, r4, r4, HEAP_NUMBER_TYPE); |
| 1099 | __ b(eq, &heap_number); |
| 1100 | // Comparing JS objects with <=, >= is complicated. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1101 | if (cond != eq) { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1102 | __ cmp(r4, Operand(FIRST_SPEC_OBJECT_TYPE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1103 | __ b(ge, slow); |
| 1104 | // Normally here we fall through to return_equal, but undefined is |
| 1105 | // special: (undefined == undefined) == true, but |
| 1106 | // (undefined <= undefined) == false! See ECMAScript 11.8.5. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1107 | if (cond == le || cond == ge) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1108 | __ cmp(r4, Operand(ODDBALL_TYPE)); |
| 1109 | __ b(ne, &return_equal); |
| 1110 | __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
| 1111 | __ cmp(r0, r2); |
| 1112 | __ b(ne, &return_equal); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1113 | if (cond == le) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1114 | // undefined <= undefined should fail. |
| 1115 | __ mov(r0, Operand(GREATER)); |
| 1116 | } else { |
| 1117 | // undefined >= undefined should fail. |
| 1118 | __ mov(r0, Operand(LESS)); |
| 1119 | } |
| 1120 | __ Ret(); |
| 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | __ bind(&return_equal); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1127 | if (cond == lt) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1128 | __ mov(r0, Operand(GREATER)); // Things aren't less than themselves. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1129 | } else if (cond == gt) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1130 | __ mov(r0, Operand(LESS)); // Things aren't greater than themselves. |
| 1131 | } else { |
| 1132 | __ mov(r0, Operand(EQUAL)); // Things are <=, >=, ==, === themselves. |
| 1133 | } |
| 1134 | __ Ret(); |
| 1135 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1136 | if (cond != eq || !never_nan_nan) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1137 | // For less and greater we don't have to check for NaN since the result of |
| 1138 | // x < x is false regardless. For the others here is some code to check |
| 1139 | // for NaN. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1140 | if (cond != lt && cond != gt) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1141 | __ bind(&heap_number); |
| 1142 | // It is a heap number, so return non-equal if it's NaN and equal if it's |
| 1143 | // not NaN. |
| 1144 | |
| 1145 | // The representation of NaN values has all exponent bits (52..62) set, |
| 1146 | // and not all mantissa bits (0..51) clear. |
| 1147 | // Read top bits of double representation (second word of value). |
| 1148 | __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 1149 | // Test that exponent bits are all set. |
| 1150 | __ Sbfx(r3, r2, HeapNumber::kExponentShift, HeapNumber::kExponentBits); |
| 1151 | // NaNs have all-one exponents so they sign extend to -1. |
| 1152 | __ cmp(r3, Operand(-1)); |
| 1153 | __ b(ne, &return_equal); |
| 1154 | |
| 1155 | // Shift out flag and all exponent bits, retaining only mantissa. |
| 1156 | __ mov(r2, Operand(r2, LSL, HeapNumber::kNonMantissaBitsInTopWord)); |
| 1157 | // Or with all low-bits of mantissa. |
| 1158 | __ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset)); |
| 1159 | __ orr(r0, r3, Operand(r2), SetCC); |
| 1160 | // For equal we already have the right value in r0: Return zero (equal) |
| 1161 | // if all bits in mantissa are zero (it's an Infinity) and non-zero if |
| 1162 | // not (it's a NaN). For <= and >= we need to load r0 with the failing |
| 1163 | // value if it's a NaN. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1164 | if (cond != eq) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1165 | // All-zero means Infinity means equal. |
| 1166 | __ Ret(eq); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1167 | if (cond == le) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1168 | __ mov(r0, Operand(GREATER)); // NaN <= NaN should fail. |
| 1169 | } else { |
| 1170 | __ mov(r0, Operand(LESS)); // NaN >= NaN should fail. |
| 1171 | } |
| 1172 | } |
| 1173 | __ Ret(); |
| 1174 | } |
| 1175 | // No fall through here. |
| 1176 | } |
| 1177 | |
| 1178 | __ bind(¬_identical); |
| 1179 | } |
| 1180 | |
| 1181 | |
| 1182 | // See comment at call site. |
| 1183 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 1184 | Register lhs, |
| 1185 | Register rhs, |
| 1186 | Label* lhs_not_nan, |
| 1187 | Label* slow, |
| 1188 | bool strict) { |
| 1189 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 1190 | (lhs.is(r1) && rhs.is(r0))); |
| 1191 | |
| 1192 | Label rhs_is_smi; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1193 | __ JumpIfSmi(rhs, &rhs_is_smi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1194 | |
| 1195 | // Lhs is a Smi. Check whether the rhs is a heap number. |
| 1196 | __ CompareObjectType(rhs, r4, r4, HEAP_NUMBER_TYPE); |
| 1197 | if (strict) { |
| 1198 | // If rhs is not a number and lhs is a Smi then strict equality cannot |
| 1199 | // succeed. Return non-equal |
| 1200 | // If rhs is r0 then there is already a non zero value in it. |
| 1201 | if (!rhs.is(r0)) { |
| 1202 | __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne); |
| 1203 | } |
| 1204 | __ Ret(ne); |
| 1205 | } else { |
| 1206 | // Smi compared non-strictly with a non-Smi non-heap-number. Call |
| 1207 | // the runtime. |
| 1208 | __ b(ne, slow); |
| 1209 | } |
| 1210 | |
| 1211 | // Lhs is a smi, rhs is a number. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1212 | if (CpuFeatures::IsSupported(VFP3)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1213 | // Convert lhs to a double in d7. |
| 1214 | CpuFeatures::Scope scope(VFP3); |
| 1215 | __ SmiToDoubleVFPRegister(lhs, d7, r7, s15); |
| 1216 | // Load the double from rhs, tagged HeapNumber r0, to d6. |
| 1217 | __ sub(r7, rhs, Operand(kHeapObjectTag)); |
| 1218 | __ vldr(d6, r7, HeapNumber::kValueOffset); |
| 1219 | } else { |
| 1220 | __ push(lr); |
| 1221 | // Convert lhs to a double in r2, r3. |
| 1222 | __ mov(r7, Operand(lhs)); |
| 1223 | ConvertToDoubleStub stub1(r3, r2, r7, r6); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1224 | __ Call(stub1.GetCode()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1225 | // Load rhs to a double in r0, r1. |
| 1226 | __ Ldrd(r0, r1, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 1227 | __ pop(lr); |
| 1228 | } |
| 1229 | |
| 1230 | // We now have both loaded as doubles but we can skip the lhs nan check |
| 1231 | // since it's a smi. |
| 1232 | __ jmp(lhs_not_nan); |
| 1233 | |
| 1234 | __ bind(&rhs_is_smi); |
| 1235 | // Rhs is a smi. Check whether the non-smi lhs is a heap number. |
| 1236 | __ CompareObjectType(lhs, r4, r4, HEAP_NUMBER_TYPE); |
| 1237 | if (strict) { |
| 1238 | // If lhs is not a number and rhs is a smi then strict equality cannot |
| 1239 | // succeed. Return non-equal. |
| 1240 | // If lhs is r0 then there is already a non zero value in it. |
| 1241 | if (!lhs.is(r0)) { |
| 1242 | __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne); |
| 1243 | } |
| 1244 | __ Ret(ne); |
| 1245 | } else { |
| 1246 | // Smi compared non-strictly with a non-smi non-heap-number. Call |
| 1247 | // the runtime. |
| 1248 | __ b(ne, slow); |
| 1249 | } |
| 1250 | |
| 1251 | // Rhs is a smi, lhs is a heap number. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1252 | if (CpuFeatures::IsSupported(VFP3)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1253 | CpuFeatures::Scope scope(VFP3); |
| 1254 | // Load the double from lhs, tagged HeapNumber r1, to d7. |
| 1255 | __ sub(r7, lhs, Operand(kHeapObjectTag)); |
| 1256 | __ vldr(d7, r7, HeapNumber::kValueOffset); |
| 1257 | // Convert rhs to a double in d6 . |
| 1258 | __ SmiToDoubleVFPRegister(rhs, d6, r7, s13); |
| 1259 | } else { |
| 1260 | __ push(lr); |
| 1261 | // Load lhs to a double in r2, r3. |
| 1262 | __ Ldrd(r2, r3, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 1263 | // Convert rhs to a double in r0, r1. |
| 1264 | __ mov(r7, Operand(rhs)); |
| 1265 | ConvertToDoubleStub stub2(r1, r0, r7, r6); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1266 | __ Call(stub2.GetCode()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1267 | __ pop(lr); |
| 1268 | } |
| 1269 | // Fall through to both_loaded_as_doubles. |
| 1270 | } |
| 1271 | |
| 1272 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1273 | void EmitNanCheck(MacroAssembler* masm, Label* lhs_not_nan, Condition cond) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1274 | bool exp_first = (HeapNumber::kExponentOffset == HeapNumber::kValueOffset); |
| 1275 | Register rhs_exponent = exp_first ? r0 : r1; |
| 1276 | Register lhs_exponent = exp_first ? r2 : r3; |
| 1277 | Register rhs_mantissa = exp_first ? r1 : r0; |
| 1278 | Register lhs_mantissa = exp_first ? r3 : r2; |
| 1279 | Label one_is_nan, neither_is_nan; |
| 1280 | |
| 1281 | __ Sbfx(r4, |
| 1282 | lhs_exponent, |
| 1283 | HeapNumber::kExponentShift, |
| 1284 | HeapNumber::kExponentBits); |
| 1285 | // NaNs have all-one exponents so they sign extend to -1. |
| 1286 | __ cmp(r4, Operand(-1)); |
| 1287 | __ b(ne, lhs_not_nan); |
| 1288 | __ mov(r4, |
| 1289 | Operand(lhs_exponent, LSL, HeapNumber::kNonMantissaBitsInTopWord), |
| 1290 | SetCC); |
| 1291 | __ b(ne, &one_is_nan); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1292 | __ cmp(lhs_mantissa, Operand(0, RelocInfo::NONE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1293 | __ b(ne, &one_is_nan); |
| 1294 | |
| 1295 | __ bind(lhs_not_nan); |
| 1296 | __ Sbfx(r4, |
| 1297 | rhs_exponent, |
| 1298 | HeapNumber::kExponentShift, |
| 1299 | HeapNumber::kExponentBits); |
| 1300 | // NaNs have all-one exponents so they sign extend to -1. |
| 1301 | __ cmp(r4, Operand(-1)); |
| 1302 | __ b(ne, &neither_is_nan); |
| 1303 | __ mov(r4, |
| 1304 | Operand(rhs_exponent, LSL, HeapNumber::kNonMantissaBitsInTopWord), |
| 1305 | SetCC); |
| 1306 | __ b(ne, &one_is_nan); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1307 | __ cmp(rhs_mantissa, Operand(0, RelocInfo::NONE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1308 | __ b(eq, &neither_is_nan); |
| 1309 | |
| 1310 | __ bind(&one_is_nan); |
| 1311 | // NaN comparisons always fail. |
| 1312 | // Load whatever we need in r0 to make the comparison fail. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1313 | if (cond == lt || cond == le) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1314 | __ mov(r0, Operand(GREATER)); |
| 1315 | } else { |
| 1316 | __ mov(r0, Operand(LESS)); |
| 1317 | } |
| 1318 | __ Ret(); |
| 1319 | |
| 1320 | __ bind(&neither_is_nan); |
| 1321 | } |
| 1322 | |
| 1323 | |
| 1324 | // See comment at call site. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1325 | static void EmitTwoNonNanDoubleComparison(MacroAssembler* masm, |
| 1326 | Condition cond) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1327 | bool exp_first = (HeapNumber::kExponentOffset == HeapNumber::kValueOffset); |
| 1328 | Register rhs_exponent = exp_first ? r0 : r1; |
| 1329 | Register lhs_exponent = exp_first ? r2 : r3; |
| 1330 | Register rhs_mantissa = exp_first ? r1 : r0; |
| 1331 | Register lhs_mantissa = exp_first ? r3 : r2; |
| 1332 | |
| 1333 | // 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] | 1334 | if (cond == eq) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1335 | // Doubles are not equal unless they have the same bit pattern. |
| 1336 | // Exception: 0 and -0. |
| 1337 | __ cmp(rhs_mantissa, Operand(lhs_mantissa)); |
| 1338 | __ orr(r0, rhs_mantissa, Operand(lhs_mantissa), LeaveCC, ne); |
| 1339 | // Return non-zero if the numbers are unequal. |
| 1340 | __ Ret(ne); |
| 1341 | |
| 1342 | __ sub(r0, rhs_exponent, Operand(lhs_exponent), SetCC); |
| 1343 | // If exponents are equal then return 0. |
| 1344 | __ Ret(eq); |
| 1345 | |
| 1346 | // Exponents are unequal. The only way we can return that the numbers |
| 1347 | // are equal is if one is -0 and the other is 0. We already dealt |
| 1348 | // with the case where both are -0 or both are 0. |
| 1349 | // We start by seeing if the mantissas (that are equal) or the bottom |
| 1350 | // 31 bits of the rhs exponent are non-zero. If so we return not |
| 1351 | // equal. |
| 1352 | __ orr(r4, lhs_mantissa, Operand(lhs_exponent, LSL, kSmiTagSize), SetCC); |
| 1353 | __ mov(r0, Operand(r4), LeaveCC, ne); |
| 1354 | __ Ret(ne); |
| 1355 | // Now they are equal if and only if the lhs exponent is zero in its |
| 1356 | // low 31 bits. |
| 1357 | __ mov(r0, Operand(rhs_exponent, LSL, kSmiTagSize)); |
| 1358 | __ Ret(); |
| 1359 | } else { |
| 1360 | // Call a native function to do a comparison between two non-NaNs. |
| 1361 | // Call C routine that may not cause GC or other trouble. |
| 1362 | __ push(lr); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1363 | __ PrepareCallCFunction(0, 2, r5); |
| 1364 | if (masm->use_eabi_hardfloat()) { |
| 1365 | CpuFeatures::Scope scope(VFP3); |
| 1366 | __ vmov(d0, r0, r1); |
| 1367 | __ vmov(d1, r2, r3); |
| 1368 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1369 | |
| 1370 | AllowExternalCallThatCantCauseGC scope(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1371 | __ CallCFunction(ExternalReference::compare_doubles(masm->isolate()), |
| 1372 | 0, 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1373 | __ pop(pc); // Return. |
| 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | |
| 1378 | // See comment at call site. |
| 1379 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 1380 | Register lhs, |
| 1381 | Register rhs) { |
| 1382 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 1383 | (lhs.is(r1) && rhs.is(r0))); |
| 1384 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1385 | // 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] | 1386 | // not equal since their pointers are different. |
| 1387 | // There is no test for undetectability in strict equality. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1388 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1389 | Label first_non_object; |
| 1390 | // 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] | 1391 | // FIRST_SPEC_OBJECT_TYPE. |
| 1392 | __ CompareObjectType(rhs, r2, r2, FIRST_SPEC_OBJECT_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1393 | __ b(lt, &first_non_object); |
| 1394 | |
| 1395 | // Return non-zero (r0 is not zero) |
| 1396 | Label return_not_equal; |
| 1397 | __ bind(&return_not_equal); |
| 1398 | __ Ret(); |
| 1399 | |
| 1400 | __ bind(&first_non_object); |
| 1401 | // Check for oddballs: true, false, null, undefined. |
| 1402 | __ cmp(r2, Operand(ODDBALL_TYPE)); |
| 1403 | __ b(eq, &return_not_equal); |
| 1404 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1405 | __ CompareObjectType(lhs, r3, r3, FIRST_SPEC_OBJECT_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1406 | __ b(ge, &return_not_equal); |
| 1407 | |
| 1408 | // Check for oddballs: true, false, null, undefined. |
| 1409 | __ cmp(r3, Operand(ODDBALL_TYPE)); |
| 1410 | __ b(eq, &return_not_equal); |
| 1411 | |
| 1412 | // Now that we have the types we might as well check for symbol-symbol. |
| 1413 | // Ensure that no non-strings have the symbol bit set. |
| 1414 | STATIC_ASSERT(LAST_TYPE < kNotStringTag + kIsSymbolMask); |
| 1415 | STATIC_ASSERT(kSymbolTag != 0); |
| 1416 | __ and_(r2, r2, Operand(r3)); |
| 1417 | __ tst(r2, Operand(kIsSymbolMask)); |
| 1418 | __ b(ne, &return_not_equal); |
| 1419 | } |
| 1420 | |
| 1421 | |
| 1422 | // See comment at call site. |
| 1423 | static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm, |
| 1424 | Register lhs, |
| 1425 | Register rhs, |
| 1426 | Label* both_loaded_as_doubles, |
| 1427 | Label* not_heap_numbers, |
| 1428 | Label* slow) { |
| 1429 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 1430 | (lhs.is(r1) && rhs.is(r0))); |
| 1431 | |
| 1432 | __ CompareObjectType(rhs, r3, r2, HEAP_NUMBER_TYPE); |
| 1433 | __ b(ne, not_heap_numbers); |
| 1434 | __ ldr(r2, FieldMemOperand(lhs, HeapObject::kMapOffset)); |
| 1435 | __ cmp(r2, r3); |
| 1436 | __ b(ne, slow); // First was a heap number, second wasn't. Go slow case. |
| 1437 | |
| 1438 | // Both are heap numbers. Load them up then jump to the code we have |
| 1439 | // for that. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1440 | if (CpuFeatures::IsSupported(VFP3)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1441 | CpuFeatures::Scope scope(VFP3); |
| 1442 | __ sub(r7, rhs, Operand(kHeapObjectTag)); |
| 1443 | __ vldr(d6, r7, HeapNumber::kValueOffset); |
| 1444 | __ sub(r7, lhs, Operand(kHeapObjectTag)); |
| 1445 | __ vldr(d7, r7, HeapNumber::kValueOffset); |
| 1446 | } else { |
| 1447 | __ Ldrd(r2, r3, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 1448 | __ Ldrd(r0, r1, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 1449 | } |
| 1450 | __ jmp(both_loaded_as_doubles); |
| 1451 | } |
| 1452 | |
| 1453 | |
| 1454 | // Fast negative check for symbol-to-symbol equality. |
| 1455 | static void EmitCheckForSymbolsOrObjects(MacroAssembler* masm, |
| 1456 | Register lhs, |
| 1457 | Register rhs, |
| 1458 | Label* possible_strings, |
| 1459 | Label* not_both_strings) { |
| 1460 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 1461 | (lhs.is(r1) && rhs.is(r0))); |
| 1462 | |
| 1463 | // r2 is object type of rhs. |
| 1464 | // Ensure that no non-strings have the symbol bit set. |
| 1465 | Label object_test; |
| 1466 | STATIC_ASSERT(kSymbolTag != 0); |
| 1467 | __ tst(r2, Operand(kIsNotStringMask)); |
| 1468 | __ b(ne, &object_test); |
| 1469 | __ tst(r2, Operand(kIsSymbolMask)); |
| 1470 | __ b(eq, possible_strings); |
| 1471 | __ CompareObjectType(lhs, r3, r3, FIRST_NONSTRING_TYPE); |
| 1472 | __ b(ge, not_both_strings); |
| 1473 | __ tst(r3, Operand(kIsSymbolMask)); |
| 1474 | __ b(eq, possible_strings); |
| 1475 | |
| 1476 | // Both are symbols. We already checked they weren't the same pointer |
| 1477 | // so they are not equal. |
| 1478 | __ mov(r0, Operand(NOT_EQUAL)); |
| 1479 | __ Ret(); |
| 1480 | |
| 1481 | __ bind(&object_test); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1482 | __ cmp(r2, Operand(FIRST_SPEC_OBJECT_TYPE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1483 | __ b(lt, not_both_strings); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1484 | __ CompareObjectType(lhs, r2, r3, FIRST_SPEC_OBJECT_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1485 | __ b(lt, not_both_strings); |
| 1486 | // If both objects are undetectable, they are equal. Otherwise, they |
| 1487 | // are not equal, since they are different objects and an object is not |
| 1488 | // equal to undefined. |
| 1489 | __ ldr(r3, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 1490 | __ ldrb(r2, FieldMemOperand(r2, Map::kBitFieldOffset)); |
| 1491 | __ ldrb(r3, FieldMemOperand(r3, Map::kBitFieldOffset)); |
| 1492 | __ and_(r0, r2, Operand(r3)); |
| 1493 | __ and_(r0, r0, Operand(1 << Map::kIsUndetectable)); |
| 1494 | __ eor(r0, r0, Operand(1 << Map::kIsUndetectable)); |
| 1495 | __ Ret(); |
| 1496 | } |
| 1497 | |
| 1498 | |
| 1499 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 1500 | Register object, |
| 1501 | Register result, |
| 1502 | Register scratch1, |
| 1503 | Register scratch2, |
| 1504 | Register scratch3, |
| 1505 | bool object_is_smi, |
| 1506 | Label* not_found) { |
| 1507 | // Use of registers. Register result is used as a temporary. |
| 1508 | Register number_string_cache = result; |
| 1509 | Register mask = scratch3; |
| 1510 | |
| 1511 | // Load the number string cache. |
| 1512 | __ LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex); |
| 1513 | |
| 1514 | // Make the hash mask from the length of the number string cache. It |
| 1515 | // contains two elements (number and string) for each cache entry. |
| 1516 | __ ldr(mask, FieldMemOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 1517 | // Divide length by two (length is a smi). |
| 1518 | __ mov(mask, Operand(mask, ASR, kSmiTagSize + 1)); |
| 1519 | __ sub(mask, mask, Operand(1)); // Make mask. |
| 1520 | |
| 1521 | // Calculate the entry in the number string cache. The hash value in the |
| 1522 | // number string cache for smis is just the smi value, and the hash for |
| 1523 | // doubles is the xor of the upper and lower words. See |
| 1524 | // Heap::GetNumberStringCache. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1525 | Isolate* isolate = masm->isolate(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1526 | Label is_smi; |
| 1527 | Label load_result_from_cache; |
| 1528 | if (!object_is_smi) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1529 | __ JumpIfSmi(object, &is_smi); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1530 | if (CpuFeatures::IsSupported(VFP3)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1531 | CpuFeatures::Scope scope(VFP3); |
| 1532 | __ CheckMap(object, |
| 1533 | scratch1, |
| 1534 | Heap::kHeapNumberMapRootIndex, |
| 1535 | not_found, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1536 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1537 | |
| 1538 | STATIC_ASSERT(8 == kDoubleSize); |
| 1539 | __ add(scratch1, |
| 1540 | object, |
| 1541 | Operand(HeapNumber::kValueOffset - kHeapObjectTag)); |
| 1542 | __ ldm(ia, scratch1, scratch1.bit() | scratch2.bit()); |
| 1543 | __ eor(scratch1, scratch1, Operand(scratch2)); |
| 1544 | __ and_(scratch1, scratch1, Operand(mask)); |
| 1545 | |
| 1546 | // Calculate address of entry in string cache: each entry consists |
| 1547 | // of two pointer sized fields. |
| 1548 | __ add(scratch1, |
| 1549 | number_string_cache, |
| 1550 | Operand(scratch1, LSL, kPointerSizeLog2 + 1)); |
| 1551 | |
| 1552 | Register probe = mask; |
| 1553 | __ ldr(probe, |
| 1554 | FieldMemOperand(scratch1, FixedArray::kHeaderSize)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1555 | __ JumpIfSmi(probe, not_found); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1556 | __ sub(scratch2, object, Operand(kHeapObjectTag)); |
| 1557 | __ vldr(d0, scratch2, HeapNumber::kValueOffset); |
| 1558 | __ sub(probe, probe, Operand(kHeapObjectTag)); |
| 1559 | __ vldr(d1, probe, HeapNumber::kValueOffset); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1560 | __ VFPCompareAndSetFlags(d0, d1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1561 | __ b(ne, not_found); // The cache did not contain this value. |
| 1562 | __ b(&load_result_from_cache); |
| 1563 | } else { |
| 1564 | __ b(not_found); |
| 1565 | } |
| 1566 | } |
| 1567 | |
| 1568 | __ bind(&is_smi); |
| 1569 | Register scratch = scratch1; |
| 1570 | __ and_(scratch, mask, Operand(object, ASR, 1)); |
| 1571 | // Calculate address of entry in string cache: each entry consists |
| 1572 | // of two pointer sized fields. |
| 1573 | __ add(scratch, |
| 1574 | number_string_cache, |
| 1575 | Operand(scratch, LSL, kPointerSizeLog2 + 1)); |
| 1576 | |
| 1577 | // Check if the entry is the smi we are looking for. |
| 1578 | Register probe = mask; |
| 1579 | __ ldr(probe, FieldMemOperand(scratch, FixedArray::kHeaderSize)); |
| 1580 | __ cmp(object, probe); |
| 1581 | __ b(ne, not_found); |
| 1582 | |
| 1583 | // Get the result from the cache. |
| 1584 | __ bind(&load_result_from_cache); |
| 1585 | __ ldr(result, |
| 1586 | FieldMemOperand(scratch, FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1587 | __ IncrementCounter(isolate->counters()->number_to_string_native(), |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1588 | 1, |
| 1589 | scratch1, |
| 1590 | scratch2); |
| 1591 | } |
| 1592 | |
| 1593 | |
| 1594 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 1595 | Label runtime; |
| 1596 | |
| 1597 | __ ldr(r1, MemOperand(sp, 0)); |
| 1598 | |
| 1599 | // Generate code to lookup number in the number string cache. |
| 1600 | GenerateLookupNumberStringCache(masm, r1, r0, r2, r3, r4, false, &runtime); |
| 1601 | __ add(sp, sp, Operand(1 * kPointerSize)); |
| 1602 | __ Ret(); |
| 1603 | |
| 1604 | __ bind(&runtime); |
| 1605 | // Handle number to string in the runtime system if not found in the cache. |
| 1606 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 1607 | } |
| 1608 | |
| 1609 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1610 | // On entry lhs_ and rhs_ are the values to be compared. |
| 1611 | // On exit r0 is 0, positive or negative to indicate the result of |
| 1612 | // the comparison. |
| 1613 | void CompareStub::Generate(MacroAssembler* masm) { |
| 1614 | ASSERT((lhs_.is(r0) && rhs_.is(r1)) || |
| 1615 | (lhs_.is(r1) && rhs_.is(r0))); |
| 1616 | |
| 1617 | Label slow; // Call builtin. |
| 1618 | Label not_smis, both_loaded_as_doubles, lhs_not_nan; |
| 1619 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 1620 | if (include_smi_compare_) { |
| 1621 | Label not_two_smis, smi_done; |
| 1622 | __ orr(r2, r1, r0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1623 | __ JumpIfNotSmi(r2, ¬_two_smis); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1624 | __ mov(r1, Operand(r1, ASR, 1)); |
| 1625 | __ sub(r0, r1, Operand(r0, ASR, 1)); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 1626 | __ Ret(); |
| 1627 | __ bind(¬_two_smis); |
| 1628 | } else if (FLAG_debug_code) { |
| 1629 | __ orr(r2, r1, r0); |
| 1630 | __ tst(r2, Operand(kSmiTagMask)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1631 | __ Assert(ne, "CompareStub: unexpected smi operands."); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 1632 | } |
| 1633 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1634 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 1635 | // it is certain that at least one operand isn't a smi. |
| 1636 | |
| 1637 | // Handle the case where the objects are identical. Either returns the answer |
| 1638 | // or goes to slow. Only falls through if the objects were not identical. |
| 1639 | EmitIdenticalObjectComparison(masm, &slow, cc_, never_nan_nan_); |
| 1640 | |
| 1641 | // If either is a Smi (we know that not both are), then they can only |
| 1642 | // be strictly equal if the other is a HeapNumber. |
| 1643 | STATIC_ASSERT(kSmiTag == 0); |
| 1644 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 1645 | __ and_(r2, lhs_, Operand(rhs_)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1646 | __ JumpIfNotSmi(r2, ¬_smis); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1647 | // One operand is a smi. EmitSmiNonsmiComparison generates code that can: |
| 1648 | // 1) Return the answer. |
| 1649 | // 2) Go to slow. |
| 1650 | // 3) Fall through to both_loaded_as_doubles. |
| 1651 | // 4) Jump to lhs_not_nan. |
| 1652 | // In cases 3 and 4 we have found out we were dealing with a number-number |
| 1653 | // comparison. If VFP3 is supported the double values of the numbers have |
| 1654 | // been loaded into d7 and d6. Otherwise, the double values have been loaded |
| 1655 | // into r0, r1, r2, and r3. |
| 1656 | EmitSmiNonsmiComparison(masm, lhs_, rhs_, &lhs_not_nan, &slow, strict_); |
| 1657 | |
| 1658 | __ bind(&both_loaded_as_doubles); |
| 1659 | // The arguments have been converted to doubles and stored in d6 and d7, if |
| 1660 | // VFP3 is supported, or in r0, r1, r2, and r3. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1661 | Isolate* isolate = masm->isolate(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1662 | if (CpuFeatures::IsSupported(VFP3)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1663 | __ bind(&lhs_not_nan); |
| 1664 | CpuFeatures::Scope scope(VFP3); |
| 1665 | Label no_nan; |
| 1666 | // ARMv7 VFP3 instructions to implement double precision comparison. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1667 | __ VFPCompareAndSetFlags(d7, d6); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1668 | Label nan; |
| 1669 | __ b(vs, &nan); |
| 1670 | __ mov(r0, Operand(EQUAL), LeaveCC, eq); |
| 1671 | __ mov(r0, Operand(LESS), LeaveCC, lt); |
| 1672 | __ mov(r0, Operand(GREATER), LeaveCC, gt); |
| 1673 | __ Ret(); |
| 1674 | |
| 1675 | __ bind(&nan); |
| 1676 | // If one of the sides was a NaN then the v flag is set. Load r0 with |
| 1677 | // whatever it takes to make the comparison fail, since comparisons with NaN |
| 1678 | // always fail. |
| 1679 | if (cc_ == lt || cc_ == le) { |
| 1680 | __ mov(r0, Operand(GREATER)); |
| 1681 | } else { |
| 1682 | __ mov(r0, Operand(LESS)); |
| 1683 | } |
| 1684 | __ Ret(); |
| 1685 | } else { |
| 1686 | // Checks for NaN in the doubles we have loaded. Can return the answer or |
| 1687 | // fall through if neither is a NaN. Also binds lhs_not_nan. |
| 1688 | EmitNanCheck(masm, &lhs_not_nan, cc_); |
| 1689 | // Compares two doubles in r0, r1, r2, r3 that are not NaNs. Returns the |
| 1690 | // answer. Never falls through. |
| 1691 | EmitTwoNonNanDoubleComparison(masm, cc_); |
| 1692 | } |
| 1693 | |
| 1694 | __ bind(¬_smis); |
| 1695 | // At this point we know we are dealing with two different objects, |
| 1696 | // and neither of them is a Smi. The objects are in rhs_ and lhs_. |
| 1697 | if (strict_) { |
| 1698 | // This returns non-equal for some object types, or falls through if it |
| 1699 | // was not lucky. |
| 1700 | EmitStrictTwoHeapObjectCompare(masm, lhs_, rhs_); |
| 1701 | } |
| 1702 | |
| 1703 | Label check_for_symbols; |
| 1704 | Label flat_string_check; |
| 1705 | // Check for heap-number-heap-number comparison. Can jump to slow case, |
| 1706 | // or load both doubles into r0, r1, r2, r3 and jump to the code that handles |
| 1707 | // that case. If the inputs are not doubles then jumps to check_for_symbols. |
| 1708 | // In this case r2 will contain the type of rhs_. Never falls through. |
| 1709 | EmitCheckForTwoHeapNumbers(masm, |
| 1710 | lhs_, |
| 1711 | rhs_, |
| 1712 | &both_loaded_as_doubles, |
| 1713 | &check_for_symbols, |
| 1714 | &flat_string_check); |
| 1715 | |
| 1716 | __ bind(&check_for_symbols); |
| 1717 | // In the strict case the EmitStrictTwoHeapObjectCompare already took care of |
| 1718 | // symbols. |
| 1719 | if (cc_ == eq && !strict_) { |
| 1720 | // Returns an answer for two symbols or two detectable objects. |
| 1721 | // Otherwise jumps to string case or not both strings case. |
| 1722 | // Assumes that r2 is the type of rhs_ on entry. |
| 1723 | EmitCheckForSymbolsOrObjects(masm, lhs_, rhs_, &flat_string_check, &slow); |
| 1724 | } |
| 1725 | |
| 1726 | // Check for both being sequential ASCII strings, and inline if that is the |
| 1727 | // case. |
| 1728 | __ bind(&flat_string_check); |
| 1729 | |
| 1730 | __ JumpIfNonSmisNotBothSequentialAsciiStrings(lhs_, rhs_, r2, r3, &slow); |
| 1731 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1732 | __ IncrementCounter(isolate->counters()->string_compare_native(), 1, r2, r3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1733 | if (cc_ == eq) { |
| 1734 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1735 | lhs_, |
| 1736 | rhs_, |
| 1737 | r2, |
| 1738 | r3, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1739 | r4); |
| 1740 | } else { |
| 1741 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 1742 | lhs_, |
| 1743 | rhs_, |
| 1744 | r2, |
| 1745 | r3, |
| 1746 | r4, |
| 1747 | r5); |
| 1748 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1749 | // Never falls through to here. |
| 1750 | |
| 1751 | __ bind(&slow); |
| 1752 | |
| 1753 | __ Push(lhs_, rhs_); |
| 1754 | // Figure out which native to call and setup the arguments. |
| 1755 | Builtins::JavaScript native; |
| 1756 | if (cc_ == eq) { |
| 1757 | native = strict_ ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
| 1758 | } else { |
| 1759 | native = Builtins::COMPARE; |
| 1760 | int ncr; // NaN compare result |
| 1761 | if (cc_ == lt || cc_ == le) { |
| 1762 | ncr = GREATER; |
| 1763 | } else { |
| 1764 | ASSERT(cc_ == gt || cc_ == ge); // remaining cases |
| 1765 | ncr = LESS; |
| 1766 | } |
| 1767 | __ mov(r0, Operand(Smi::FromInt(ncr))); |
| 1768 | __ push(r0); |
| 1769 | } |
| 1770 | |
| 1771 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 1772 | // tagged as a small integer. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1773 | __ InvokeBuiltin(native, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1777 | // The stub expects its argument in the tos_ register and returns its result in |
| 1778 | // 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] | 1779 | void ToBooleanStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1780 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 1781 | // we cannot call anything that could cause a GC from this stub. |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1782 | // This stub uses VFP3 instructions. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1783 | CpuFeatures::Scope scope(VFP3); |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1784 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1785 | Label patch; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1786 | const Register map = r9.is(tos_) ? r7 : r9; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1787 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1788 | // undefined -> false. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1789 | CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1790 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1791 | // Boolean -> its value. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1792 | CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); |
| 1793 | CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1794 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1795 | // 'null' -> false. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1796 | CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1797 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1798 | if (types_.Contains(SMI)) { |
| 1799 | // Smis: 0 -> false, all other -> true |
| 1800 | __ tst(tos_, Operand(kSmiTagMask)); |
| 1801 | // tos_ contains the correct return value already |
| 1802 | __ Ret(eq); |
| 1803 | } else if (types_.NeedsMap()) { |
| 1804 | // If we need a map later and have a Smi -> patch. |
| 1805 | __ JumpIfSmi(tos_, &patch); |
| 1806 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1807 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1808 | if (types_.NeedsMap()) { |
| 1809 | __ ldr(map, FieldMemOperand(tos_, HeapObject::kMapOffset)); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1810 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1811 | if (types_.CanBeUndetectable()) { |
| 1812 | __ ldrb(ip, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 1813 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
| 1814 | // Undetectable -> false. |
| 1815 | __ mov(tos_, Operand(0, RelocInfo::NONE), LeaveCC, ne); |
| 1816 | __ Ret(ne); |
| 1817 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1818 | } |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1819 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1820 | if (types_.Contains(SPEC_OBJECT)) { |
| 1821 | // Spec object -> true. |
| 1822 | __ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE); |
| 1823 | // tos_ contains the correct non-zero return value already. |
| 1824 | __ Ret(ge); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1825 | } |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1826 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1827 | if (types_.Contains(STRING)) { |
| 1828 | // String value -> false iff empty. |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1829 | __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1830 | __ ldr(tos_, FieldMemOperand(tos_, String::kLengthOffset), lt); |
| 1831 | __ Ret(lt); // the string length is OK as the return value |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1832 | } |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1833 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1834 | if (types_.Contains(HEAP_NUMBER)) { |
| 1835 | // Heap number -> false iff +0, -0, or NaN. |
| 1836 | Label not_heap_number; |
| 1837 | __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 1838 | __ b(ne, ¬_heap_number); |
| 1839 | __ vldr(d1, FieldMemOperand(tos_, HeapNumber::kValueOffset)); |
| 1840 | __ VFPCompareAndSetFlags(d1, 0.0); |
| 1841 | // "tos_" is a register, and contains a non zero value by default. |
| 1842 | // Hence we only need to overwrite "tos_" with zero to return false for |
| 1843 | // FP_ZERO or FP_NAN cases. Otherwise, by default it returns true. |
| 1844 | __ mov(tos_, Operand(0, RelocInfo::NONE), LeaveCC, eq); // for FP_ZERO |
| 1845 | __ mov(tos_, Operand(0, RelocInfo::NONE), LeaveCC, vs); // for FP_NAN |
| 1846 | __ Ret(); |
| 1847 | __ bind(¬_heap_number); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1848 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1849 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1850 | __ bind(&patch); |
| 1851 | GenerateTypeTransition(masm); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | |
| 1855 | void ToBooleanStub::CheckOddball(MacroAssembler* masm, |
| 1856 | Type type, |
| 1857 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1858 | bool result) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1859 | if (types_.Contains(type)) { |
| 1860 | // If we see an expected oddball, return its ToBoolean value tos_. |
| 1861 | __ LoadRoot(ip, value); |
| 1862 | __ cmp(tos_, ip); |
| 1863 | // The value of a root is never NULL, so we can avoid loading a non-null |
| 1864 | // value into tos_ when we want to return 'true'. |
| 1865 | if (!result) { |
| 1866 | __ mov(tos_, Operand(0, RelocInfo::NONE), LeaveCC, eq); |
| 1867 | } |
| 1868 | __ Ret(eq); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | |
| 1873 | void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 1874 | if (!tos_.is(r3)) { |
| 1875 | __ mov(r3, Operand(tos_)); |
| 1876 | } |
| 1877 | __ mov(r2, Operand(Smi::FromInt(tos_.code()))); |
| 1878 | __ mov(r1, Operand(Smi::FromInt(types_.ToByte()))); |
| 1879 | __ Push(r3, r2, r1); |
| 1880 | // Patch the caller to an appropriate specialized stub and return the |
| 1881 | // operation result to the caller of the stub. |
| 1882 | __ TailCallExternalReference( |
| 1883 | ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), |
| 1884 | 3, |
| 1885 | 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1889 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 1890 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 1891 | // store the registers in any particular way, but we do have to store and |
| 1892 | // restore them. |
| 1893 | __ stm(db_w, sp, kCallerSaved | lr.bit()); |
| 1894 | if (save_doubles_ == kSaveFPRegs) { |
| 1895 | CpuFeatures::Scope scope(VFP3); |
| 1896 | __ sub(sp, sp, Operand(kDoubleSize * DwVfpRegister::kNumRegisters)); |
| 1897 | for (int i = 0; i < DwVfpRegister::kNumRegisters; i++) { |
| 1898 | DwVfpRegister reg = DwVfpRegister::from_code(i); |
| 1899 | __ vstr(reg, MemOperand(sp, i * kDoubleSize)); |
| 1900 | } |
| 1901 | } |
| 1902 | const int argument_count = 1; |
| 1903 | const int fp_argument_count = 0; |
| 1904 | const Register scratch = r1; |
| 1905 | |
| 1906 | AllowExternalCallThatCantCauseGC scope(masm); |
| 1907 | __ PrepareCallCFunction(argument_count, fp_argument_count, scratch); |
| 1908 | __ mov(r0, Operand(ExternalReference::isolate_address())); |
| 1909 | __ CallCFunction( |
| 1910 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 1911 | argument_count); |
| 1912 | if (save_doubles_ == kSaveFPRegs) { |
| 1913 | CpuFeatures::Scope scope(VFP3); |
| 1914 | for (int i = 0; i < DwVfpRegister::kNumRegisters; i++) { |
| 1915 | DwVfpRegister reg = DwVfpRegister::from_code(i); |
| 1916 | __ vldr(reg, MemOperand(sp, i * kDoubleSize)); |
| 1917 | } |
| 1918 | __ add(sp, sp, Operand(kDoubleSize * DwVfpRegister::kNumRegisters)); |
| 1919 | } |
| 1920 | __ ldm(ia_w, sp, kCallerSaved | pc.bit()); // Also pop pc to get Ret(0). |
| 1921 | } |
| 1922 | |
| 1923 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1924 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1925 | const char* op_name = Token::Name(op_); |
| 1926 | const char* overwrite_name = NULL; // Make g++ happy. |
| 1927 | switch (mode_) { |
| 1928 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 1929 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 1930 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1931 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 1932 | op_name, |
| 1933 | overwrite_name, |
| 1934 | UnaryOpIC::GetName(operand_type_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | |
| 1938 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1939 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1940 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1941 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1942 | GenerateTypeTransition(masm); |
| 1943 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1944 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1945 | GenerateSmiStub(masm); |
| 1946 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1947 | case UnaryOpIC::HEAP_NUMBER: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1948 | GenerateHeapNumberStub(masm); |
| 1949 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1950 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1951 | GenerateGenericStub(masm); |
| 1952 | break; |
| 1953 | } |
| 1954 | } |
| 1955 | |
| 1956 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1957 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1958 | __ mov(r3, Operand(r0)); // the operand |
| 1959 | __ mov(r2, Operand(Smi::FromInt(op_))); |
| 1960 | __ mov(r1, Operand(Smi::FromInt(mode_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1961 | __ mov(r0, Operand(Smi::FromInt(operand_type_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1962 | __ Push(r3, r2, r1, r0); |
| 1963 | |
| 1964 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1965 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | |
| 1969 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1970 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1971 | switch (op_) { |
| 1972 | case Token::SUB: |
| 1973 | GenerateSmiStubSub(masm); |
| 1974 | break; |
| 1975 | case Token::BIT_NOT: |
| 1976 | GenerateSmiStubBitNot(masm); |
| 1977 | break; |
| 1978 | default: |
| 1979 | UNREACHABLE(); |
| 1980 | } |
| 1981 | } |
| 1982 | |
| 1983 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1984 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1985 | Label non_smi, slow; |
| 1986 | GenerateSmiCodeSub(masm, &non_smi, &slow); |
| 1987 | __ bind(&non_smi); |
| 1988 | __ bind(&slow); |
| 1989 | GenerateTypeTransition(masm); |
| 1990 | } |
| 1991 | |
| 1992 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1993 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1994 | Label non_smi; |
| 1995 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 1996 | __ bind(&non_smi); |
| 1997 | GenerateTypeTransition(masm); |
| 1998 | } |
| 1999 | |
| 2000 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2001 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 2002 | Label* non_smi, |
| 2003 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2004 | __ JumpIfNotSmi(r0, non_smi); |
| 2005 | |
| 2006 | // The result of negating zero or the smallest negative smi is not a smi. |
| 2007 | __ bic(ip, r0, Operand(0x80000000), SetCC); |
| 2008 | __ b(eq, slow); |
| 2009 | |
| 2010 | // Return '0 - value'. |
| 2011 | __ rsb(r0, r0, Operand(0, RelocInfo::NONE)); |
| 2012 | __ Ret(); |
| 2013 | } |
| 2014 | |
| 2015 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2016 | void UnaryOpStub::GenerateSmiCodeBitNot(MacroAssembler* masm, |
| 2017 | Label* non_smi) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2018 | __ JumpIfNotSmi(r0, non_smi); |
| 2019 | |
| 2020 | // Flip bits and revert inverted smi-tag. |
| 2021 | __ mvn(r0, Operand(r0)); |
| 2022 | __ bic(r0, r0, Operand(kSmiTagMask)); |
| 2023 | __ Ret(); |
| 2024 | } |
| 2025 | |
| 2026 | |
| 2027 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2028 | void UnaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2029 | switch (op_) { |
| 2030 | case Token::SUB: |
| 2031 | GenerateHeapNumberStubSub(masm); |
| 2032 | break; |
| 2033 | case Token::BIT_NOT: |
| 2034 | GenerateHeapNumberStubBitNot(masm); |
| 2035 | break; |
| 2036 | default: |
| 2037 | UNREACHABLE(); |
| 2038 | } |
| 2039 | } |
| 2040 | |
| 2041 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2042 | void UnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2043 | Label non_smi, slow, call_builtin; |
| 2044 | GenerateSmiCodeSub(masm, &non_smi, &call_builtin); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2045 | __ bind(&non_smi); |
| 2046 | GenerateHeapNumberCodeSub(masm, &slow); |
| 2047 | __ bind(&slow); |
| 2048 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2049 | __ bind(&call_builtin); |
| 2050 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2054 | void UnaryOpStub::GenerateHeapNumberStubBitNot(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2055 | Label non_smi, slow; |
| 2056 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 2057 | __ bind(&non_smi); |
| 2058 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 2059 | __ bind(&slow); |
| 2060 | GenerateTypeTransition(masm); |
| 2061 | } |
| 2062 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2063 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 2064 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2065 | EmitCheckForHeapNumber(masm, r0, r1, r6, slow); |
| 2066 | // r0 is a heap number. Get a new heap number in r1. |
| 2067 | if (mode_ == UNARY_OVERWRITE) { |
| 2068 | __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 2069 | __ eor(r2, r2, Operand(HeapNumber::kSignMask)); // Flip sign. |
| 2070 | __ str(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 2071 | } else { |
| 2072 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 2073 | __ AllocateHeapNumber(r1, r2, r3, r6, &slow_allocate_heapnumber); |
| 2074 | __ jmp(&heapnumber_allocated); |
| 2075 | |
| 2076 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2077 | { |
| 2078 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2079 | __ push(r0); |
| 2080 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 2081 | __ mov(r1, Operand(r0)); |
| 2082 | __ pop(r0); |
| 2083 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2084 | |
| 2085 | __ bind(&heapnumber_allocated); |
| 2086 | __ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset)); |
| 2087 | __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 2088 | __ str(r3, FieldMemOperand(r1, HeapNumber::kMantissaOffset)); |
| 2089 | __ eor(r2, r2, Operand(HeapNumber::kSignMask)); // Flip sign. |
| 2090 | __ str(r2, FieldMemOperand(r1, HeapNumber::kExponentOffset)); |
| 2091 | __ mov(r0, Operand(r1)); |
| 2092 | } |
| 2093 | __ Ret(); |
| 2094 | } |
| 2095 | |
| 2096 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2097 | void UnaryOpStub::GenerateHeapNumberCodeBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2098 | MacroAssembler* masm, Label* slow) { |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2099 | Label impossible; |
| 2100 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2101 | EmitCheckForHeapNumber(masm, r0, r1, r6, slow); |
| 2102 | // Convert the heap number is r0 to an untagged integer in r1. |
| 2103 | __ ConvertToInt32(r0, r1, r2, r3, d0, slow); |
| 2104 | |
| 2105 | // Do the bitwise operation and check if the result fits in a smi. |
| 2106 | Label try_float; |
| 2107 | __ mvn(r1, Operand(r1)); |
| 2108 | __ add(r2, r1, Operand(0x40000000), SetCC); |
| 2109 | __ b(mi, &try_float); |
| 2110 | |
| 2111 | // Tag the result as a smi and we're done. |
| 2112 | __ mov(r0, Operand(r1, LSL, kSmiTagSize)); |
| 2113 | __ Ret(); |
| 2114 | |
| 2115 | // Try to store the result in a heap number. |
| 2116 | __ bind(&try_float); |
| 2117 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 2118 | Label slow_allocate_heapnumber, heapnumber_allocated; |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2119 | // Allocate a new heap number without zapping r0, which we need if it fails. |
| 2120 | __ AllocateHeapNumber(r2, r3, r4, r6, &slow_allocate_heapnumber); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2121 | __ jmp(&heapnumber_allocated); |
| 2122 | |
| 2123 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2124 | { |
| 2125 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2126 | __ push(r0); // Push the heap number, not the untagged int32. |
| 2127 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 2128 | __ mov(r2, r0); // Move the new heap number into r2. |
| 2129 | // Get the heap number into r0, now that the new heap number is in r2. |
| 2130 | __ pop(r0); |
| 2131 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2132 | |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2133 | // Convert the heap number in r0 to an untagged integer in r1. |
| 2134 | // This can't go slow-case because it's the same number we already |
| 2135 | // converted once again. |
| 2136 | __ ConvertToInt32(r0, r1, r3, r4, d0, &impossible); |
| 2137 | __ mvn(r1, Operand(r1)); |
| 2138 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2139 | __ bind(&heapnumber_allocated); |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2140 | __ mov(r0, r2); // Move newly allocated heap number to r0. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | if (CpuFeatures::IsSupported(VFP3)) { |
| 2144 | // Convert the int32 in r1 to the heap number in r0. r2 is corrupted. |
| 2145 | CpuFeatures::Scope scope(VFP3); |
| 2146 | __ vmov(s0, r1); |
| 2147 | __ vcvt_f64_s32(d0, s0); |
| 2148 | __ sub(r2, r0, Operand(kHeapObjectTag)); |
| 2149 | __ vstr(d0, r2, HeapNumber::kValueOffset); |
| 2150 | __ Ret(); |
| 2151 | } else { |
| 2152 | // WriteInt32ToHeapNumberStub does not trigger GC, so we do not |
| 2153 | // have to set up a frame. |
| 2154 | WriteInt32ToHeapNumberStub stub(r1, r0, r2); |
| 2155 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 2156 | } |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2157 | |
| 2158 | __ bind(&impossible); |
| 2159 | if (FLAG_debug_code) { |
| 2160 | __ stop("Incorrect assumption in bit-not stub"); |
| 2161 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | |
| 2165 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2166 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2167 | switch (op_) { |
| 2168 | case Token::SUB: |
| 2169 | GenerateGenericStubSub(masm); |
| 2170 | break; |
| 2171 | case Token::BIT_NOT: |
| 2172 | GenerateGenericStubBitNot(masm); |
| 2173 | break; |
| 2174 | default: |
| 2175 | UNREACHABLE(); |
| 2176 | } |
| 2177 | } |
| 2178 | |
| 2179 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2180 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2181 | Label non_smi, slow; |
| 2182 | GenerateSmiCodeSub(masm, &non_smi, &slow); |
| 2183 | __ bind(&non_smi); |
| 2184 | GenerateHeapNumberCodeSub(masm, &slow); |
| 2185 | __ bind(&slow); |
| 2186 | GenerateGenericCodeFallback(masm); |
| 2187 | } |
| 2188 | |
| 2189 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2190 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2191 | Label non_smi, slow; |
| 2192 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 2193 | __ bind(&non_smi); |
| 2194 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 2195 | __ bind(&slow); |
| 2196 | GenerateGenericCodeFallback(masm); |
| 2197 | } |
| 2198 | |
| 2199 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2200 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2201 | // Handle the slow case by jumping to the JavaScript builtin. |
| 2202 | __ push(r0); |
| 2203 | switch (op_) { |
| 2204 | case Token::SUB: |
| 2205 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 2206 | break; |
| 2207 | case Token::BIT_NOT: |
| 2208 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 2209 | break; |
| 2210 | default: |
| 2211 | UNREACHABLE(); |
| 2212 | } |
| 2213 | } |
| 2214 | |
| 2215 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2216 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2217 | Label get_result; |
| 2218 | |
| 2219 | __ Push(r1, r0); |
| 2220 | |
| 2221 | __ mov(r2, Operand(Smi::FromInt(MinorKey()))); |
| 2222 | __ mov(r1, Operand(Smi::FromInt(op_))); |
| 2223 | __ mov(r0, Operand(Smi::FromInt(operands_type_))); |
| 2224 | __ Push(r2, r1, r0); |
| 2225 | |
| 2226 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2227 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2228 | masm->isolate()), |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2229 | 5, |
| 2230 | 1); |
| 2231 | } |
| 2232 | |
| 2233 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2234 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs( |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2235 | MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2236 | UNIMPLEMENTED(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2240 | void BinaryOpStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2241 | // Explicitly allow generation of nested stubs. It is safe here because |
| 2242 | // generation code does not use any raw pointers. |
| 2243 | AllowStubCallsScope allow_stub_calls(masm, true); |
| 2244 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2245 | switch (operands_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2246 | case BinaryOpIC::UNINITIALIZED: |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2247 | GenerateTypeTransition(masm); |
| 2248 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2249 | case BinaryOpIC::SMI: |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2250 | GenerateSmiStub(masm); |
| 2251 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2252 | case BinaryOpIC::INT32: |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2253 | GenerateInt32Stub(masm); |
| 2254 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2255 | case BinaryOpIC::HEAP_NUMBER: |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2256 | GenerateHeapNumberStub(masm); |
| 2257 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2258 | case BinaryOpIC::ODDBALL: |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2259 | GenerateOddballStub(masm); |
| 2260 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2261 | case BinaryOpIC::BOTH_STRING: |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2262 | GenerateBothStringStub(masm); |
| 2263 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2264 | case BinaryOpIC::STRING: |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2265 | GenerateStringStub(masm); |
| 2266 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2267 | case BinaryOpIC::GENERIC: |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2268 | GenerateGeneric(masm); |
| 2269 | break; |
| 2270 | default: |
| 2271 | UNREACHABLE(); |
| 2272 | } |
| 2273 | } |
| 2274 | |
| 2275 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 2276 | void BinaryOpStub::PrintName(StringStream* stream) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2277 | const char* op_name = Token::Name(op_); |
| 2278 | const char* overwrite_name; |
| 2279 | switch (mode_) { |
| 2280 | case NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 2281 | case OVERWRITE_RIGHT: overwrite_name = "OverwriteRight"; break; |
| 2282 | case OVERWRITE_LEFT: overwrite_name = "OverwriteLeft"; break; |
| 2283 | default: overwrite_name = "UnknownOverwrite"; break; |
| 2284 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 2285 | stream->Add("BinaryOpStub_%s_%s_%s", |
| 2286 | op_name, |
| 2287 | overwrite_name, |
| 2288 | BinaryOpIC::GetName(operands_type_)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2292 | void BinaryOpStub::GenerateSmiSmiOperation(MacroAssembler* masm) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2293 | Register left = r1; |
| 2294 | Register right = r0; |
| 2295 | Register scratch1 = r7; |
| 2296 | Register scratch2 = r9; |
| 2297 | |
| 2298 | ASSERT(right.is(r0)); |
| 2299 | STATIC_ASSERT(kSmiTag == 0); |
| 2300 | |
| 2301 | Label not_smi_result; |
| 2302 | switch (op_) { |
| 2303 | case Token::ADD: |
| 2304 | __ add(right, left, Operand(right), SetCC); // Add optimistically. |
| 2305 | __ Ret(vc); |
| 2306 | __ sub(right, right, Operand(left)); // Revert optimistic add. |
| 2307 | break; |
| 2308 | case Token::SUB: |
| 2309 | __ sub(right, left, Operand(right), SetCC); // Subtract optimistically. |
| 2310 | __ Ret(vc); |
| 2311 | __ sub(right, left, Operand(right)); // Revert optimistic subtract. |
| 2312 | break; |
| 2313 | case Token::MUL: |
| 2314 | // Remove tag from one of the operands. This way the multiplication result |
| 2315 | // will be a smi if it fits the smi range. |
| 2316 | __ SmiUntag(ip, right); |
| 2317 | // Do multiplication |
| 2318 | // scratch1 = lower 32 bits of ip * left. |
| 2319 | // scratch2 = higher 32 bits of ip * left. |
| 2320 | __ smull(scratch1, scratch2, left, ip); |
| 2321 | // Check for overflowing the smi range - no overflow if higher 33 bits of |
| 2322 | // the result are identical. |
| 2323 | __ mov(ip, Operand(scratch1, ASR, 31)); |
| 2324 | __ cmp(ip, Operand(scratch2)); |
| 2325 | __ b(ne, ¬_smi_result); |
| 2326 | // Go slow on zero result to handle -0. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2327 | __ cmp(scratch1, Operand(0)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2328 | __ mov(right, Operand(scratch1), LeaveCC, ne); |
| 2329 | __ Ret(ne); |
| 2330 | // We need -0 if we were multiplying a negative number with 0 to get 0. |
| 2331 | // We know one of them was zero. |
| 2332 | __ add(scratch2, right, Operand(left), SetCC); |
| 2333 | __ mov(right, Operand(Smi::FromInt(0)), LeaveCC, pl); |
| 2334 | __ Ret(pl); // Return smi 0 if the non-zero one was positive. |
| 2335 | // We fall through here if we multiplied a negative number with 0, because |
| 2336 | // that would mean we should produce -0. |
| 2337 | break; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2338 | case Token::DIV: |
| 2339 | // Check for power of two on the right hand side. |
| 2340 | __ JumpIfNotPowerOfTwoOrZero(right, scratch1, ¬_smi_result); |
| 2341 | // Check for positive and no remainder (scratch1 contains right - 1). |
| 2342 | __ orr(scratch2, scratch1, Operand(0x80000000u)); |
| 2343 | __ tst(left, scratch2); |
| 2344 | __ b(ne, ¬_smi_result); |
| 2345 | |
| 2346 | // Perform division by shifting. |
| 2347 | __ CountLeadingZeros(scratch1, scratch1, scratch2); |
| 2348 | __ rsb(scratch1, scratch1, Operand(31)); |
| 2349 | __ mov(right, Operand(left, LSR, scratch1)); |
| 2350 | __ Ret(); |
| 2351 | break; |
| 2352 | case Token::MOD: |
| 2353 | // Check for two positive smis. |
| 2354 | __ orr(scratch1, left, Operand(right)); |
| 2355 | __ tst(scratch1, Operand(0x80000000u | kSmiTagMask)); |
| 2356 | __ b(ne, ¬_smi_result); |
| 2357 | |
| 2358 | // Check for power of two on the right hand side. |
| 2359 | __ JumpIfNotPowerOfTwoOrZero(right, scratch1, ¬_smi_result); |
| 2360 | |
| 2361 | // Perform modulus by masking. |
| 2362 | __ and_(right, left, Operand(scratch1)); |
| 2363 | __ Ret(); |
| 2364 | break; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2365 | case Token::BIT_OR: |
| 2366 | __ orr(right, left, Operand(right)); |
| 2367 | __ Ret(); |
| 2368 | break; |
| 2369 | case Token::BIT_AND: |
| 2370 | __ and_(right, left, Operand(right)); |
| 2371 | __ Ret(); |
| 2372 | break; |
| 2373 | case Token::BIT_XOR: |
| 2374 | __ eor(right, left, Operand(right)); |
| 2375 | __ Ret(); |
| 2376 | break; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2377 | case Token::SAR: |
| 2378 | // Remove tags from right operand. |
| 2379 | __ GetLeastBitsFromSmi(scratch1, right, 5); |
| 2380 | __ mov(right, Operand(left, ASR, scratch1)); |
| 2381 | // Smi tag result. |
| 2382 | __ bic(right, right, Operand(kSmiTagMask)); |
| 2383 | __ Ret(); |
| 2384 | break; |
| 2385 | case Token::SHR: |
| 2386 | // Remove tags from operands. We can't do this on a 31 bit number |
| 2387 | // because then the 0s get shifted into bit 30 instead of bit 31. |
| 2388 | __ SmiUntag(scratch1, left); |
| 2389 | __ GetLeastBitsFromSmi(scratch2, right, 5); |
| 2390 | __ mov(scratch1, Operand(scratch1, LSR, scratch2)); |
| 2391 | // Unsigned shift is not allowed to produce a negative number, so |
| 2392 | // check the sign bit and the sign bit after Smi tagging. |
| 2393 | __ tst(scratch1, Operand(0xc0000000)); |
| 2394 | __ b(ne, ¬_smi_result); |
| 2395 | // Smi tag result. |
| 2396 | __ SmiTag(right, scratch1); |
| 2397 | __ Ret(); |
| 2398 | break; |
| 2399 | case Token::SHL: |
| 2400 | // Remove tags from operands. |
| 2401 | __ SmiUntag(scratch1, left); |
| 2402 | __ GetLeastBitsFromSmi(scratch2, right, 5); |
| 2403 | __ mov(scratch1, Operand(scratch1, LSL, scratch2)); |
| 2404 | // Check that the signed result fits in a Smi. |
| 2405 | __ add(scratch2, scratch1, Operand(0x40000000), SetCC); |
| 2406 | __ b(mi, ¬_smi_result); |
| 2407 | __ SmiTag(right, scratch1); |
| 2408 | __ Ret(); |
| 2409 | break; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2410 | default: |
| 2411 | UNREACHABLE(); |
| 2412 | } |
| 2413 | __ bind(¬_smi_result); |
| 2414 | } |
| 2415 | |
| 2416 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2417 | void BinaryOpStub::GenerateFPOperation(MacroAssembler* masm, |
| 2418 | bool smi_operands, |
| 2419 | Label* not_numbers, |
| 2420 | Label* gc_required) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2421 | Register left = r1; |
| 2422 | Register right = r0; |
| 2423 | Register scratch1 = r7; |
| 2424 | Register scratch2 = r9; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2425 | Register scratch3 = r4; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2426 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2427 | ASSERT(smi_operands || (not_numbers != NULL)); |
| 2428 | if (smi_operands && FLAG_debug_code) { |
| 2429 | __ AbortIfNotSmi(left); |
| 2430 | __ AbortIfNotSmi(right); |
| 2431 | } |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2432 | |
| 2433 | Register heap_number_map = r6; |
| 2434 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2435 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2436 | switch (op_) { |
| 2437 | case Token::ADD: |
| 2438 | case Token::SUB: |
| 2439 | case Token::MUL: |
| 2440 | case Token::DIV: |
| 2441 | case Token::MOD: { |
| 2442 | // Load left and right operands into d6 and d7 or r0/r1 and r2/r3 |
| 2443 | // depending on whether VFP3 is available or not. |
| 2444 | FloatingPointHelper::Destination destination = |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2445 | CpuFeatures::IsSupported(VFP3) && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2446 | op_ != Token::MOD ? |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2447 | FloatingPointHelper::kVFPRegisters : |
| 2448 | FloatingPointHelper::kCoreRegisters; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2449 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2450 | // Allocate new heap number for result. |
| 2451 | Register result = r5; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2452 | GenerateHeapResultAllocation( |
| 2453 | masm, result, heap_number_map, scratch1, scratch2, gc_required); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2454 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2455 | // Load the operands. |
| 2456 | if (smi_operands) { |
| 2457 | FloatingPointHelper::LoadSmis(masm, destination, scratch1, scratch2); |
| 2458 | } else { |
| 2459 | FloatingPointHelper::LoadOperands(masm, |
| 2460 | destination, |
| 2461 | heap_number_map, |
| 2462 | scratch1, |
| 2463 | scratch2, |
| 2464 | not_numbers); |
| 2465 | } |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2466 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2467 | // Calculate the result. |
| 2468 | if (destination == FloatingPointHelper::kVFPRegisters) { |
| 2469 | // Using VFP registers: |
| 2470 | // d6: Left value |
| 2471 | // d7: Right value |
| 2472 | CpuFeatures::Scope scope(VFP3); |
| 2473 | switch (op_) { |
| 2474 | case Token::ADD: |
| 2475 | __ vadd(d5, d6, d7); |
| 2476 | break; |
| 2477 | case Token::SUB: |
| 2478 | __ vsub(d5, d6, d7); |
| 2479 | break; |
| 2480 | case Token::MUL: |
| 2481 | __ vmul(d5, d6, d7); |
| 2482 | break; |
| 2483 | case Token::DIV: |
| 2484 | __ vdiv(d5, d6, d7); |
| 2485 | break; |
| 2486 | default: |
| 2487 | UNREACHABLE(); |
| 2488 | } |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2489 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2490 | __ sub(r0, result, Operand(kHeapObjectTag)); |
| 2491 | __ vstr(d5, r0, HeapNumber::kValueOffset); |
| 2492 | __ add(r0, r0, Operand(kHeapObjectTag)); |
| 2493 | __ Ret(); |
| 2494 | } else { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2495 | // Call the C function to handle the double operation. |
| 2496 | FloatingPointHelper::CallCCodeForDoubleOperation(masm, |
| 2497 | op_, |
| 2498 | result, |
| 2499 | scratch1); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2500 | if (FLAG_debug_code) { |
| 2501 | __ stop("Unreachable code."); |
| 2502 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2503 | } |
| 2504 | break; |
| 2505 | } |
| 2506 | case Token::BIT_OR: |
| 2507 | case Token::BIT_XOR: |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2508 | case Token::BIT_AND: |
| 2509 | case Token::SAR: |
| 2510 | case Token::SHR: |
| 2511 | case Token::SHL: { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2512 | if (smi_operands) { |
| 2513 | __ SmiUntag(r3, left); |
| 2514 | __ SmiUntag(r2, right); |
| 2515 | } else { |
| 2516 | // 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] | 2517 | FloatingPointHelper::ConvertNumberToInt32(masm, |
| 2518 | left, |
| 2519 | r3, |
| 2520 | heap_number_map, |
| 2521 | scratch1, |
| 2522 | scratch2, |
| 2523 | scratch3, |
| 2524 | d0, |
| 2525 | not_numbers); |
| 2526 | FloatingPointHelper::ConvertNumberToInt32(masm, |
| 2527 | right, |
| 2528 | r2, |
| 2529 | heap_number_map, |
| 2530 | scratch1, |
| 2531 | scratch2, |
| 2532 | scratch3, |
| 2533 | d0, |
| 2534 | not_numbers); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2535 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2536 | |
| 2537 | Label result_not_a_smi; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2538 | switch (op_) { |
| 2539 | case Token::BIT_OR: |
| 2540 | __ orr(r2, r3, Operand(r2)); |
| 2541 | break; |
| 2542 | case Token::BIT_XOR: |
| 2543 | __ eor(r2, r3, Operand(r2)); |
| 2544 | break; |
| 2545 | case Token::BIT_AND: |
| 2546 | __ and_(r2, r3, Operand(r2)); |
| 2547 | break; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2548 | case Token::SAR: |
| 2549 | // Use only the 5 least significant bits of the shift count. |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2550 | __ GetLeastBitsFromInt32(r2, r2, 5); |
| 2551 | __ mov(r2, Operand(r3, ASR, r2)); |
| 2552 | break; |
| 2553 | case Token::SHR: |
| 2554 | // Use only the 5 least significant bits of the shift count. |
| 2555 | __ GetLeastBitsFromInt32(r2, r2, 5); |
| 2556 | __ mov(r2, Operand(r3, LSR, r2), SetCC); |
| 2557 | // SHR is special because it is required to produce a positive answer. |
| 2558 | // The code below for writing into heap numbers isn't capable of |
| 2559 | // writing the register as an unsigned int so we go to slow case if we |
| 2560 | // hit this case. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2561 | if (CpuFeatures::IsSupported(VFP3)) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2562 | __ b(mi, &result_not_a_smi); |
| 2563 | } else { |
| 2564 | __ b(mi, not_numbers); |
| 2565 | } |
| 2566 | break; |
| 2567 | case Token::SHL: |
| 2568 | // Use only the 5 least significant bits of the shift count. |
| 2569 | __ GetLeastBitsFromInt32(r2, r2, 5); |
| 2570 | __ mov(r2, Operand(r3, LSL, r2)); |
| 2571 | break; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2572 | default: |
| 2573 | UNREACHABLE(); |
| 2574 | } |
| 2575 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2576 | // Check that the *signed* result fits in a smi. |
| 2577 | __ add(r3, r2, Operand(0x40000000), SetCC); |
| 2578 | __ b(mi, &result_not_a_smi); |
| 2579 | __ SmiTag(r0, r2); |
| 2580 | __ Ret(); |
| 2581 | |
| 2582 | // Allocate new heap number for result. |
| 2583 | __ bind(&result_not_a_smi); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2584 | Register result = r5; |
| 2585 | if (smi_operands) { |
| 2586 | __ AllocateHeapNumber( |
| 2587 | result, scratch1, scratch2, heap_number_map, gc_required); |
| 2588 | } else { |
| 2589 | GenerateHeapResultAllocation( |
| 2590 | masm, result, heap_number_map, scratch1, scratch2, gc_required); |
| 2591 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2592 | |
| 2593 | // r2: Answer as signed int32. |
| 2594 | // r5: Heap number to write answer into. |
| 2595 | |
| 2596 | // Nothing can go wrong now, so move the heap number to r0, which is the |
| 2597 | // result. |
| 2598 | __ mov(r0, Operand(r5)); |
| 2599 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2600 | if (CpuFeatures::IsSupported(VFP3)) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2601 | // Convert the int32 in r2 to the heap number in r0. r3 is corrupted. As |
| 2602 | // mentioned above SHR needs to always produce a positive result. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2603 | CpuFeatures::Scope scope(VFP3); |
| 2604 | __ vmov(s0, r2); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2605 | if (op_ == Token::SHR) { |
| 2606 | __ vcvt_f64_u32(d0, s0); |
| 2607 | } else { |
| 2608 | __ vcvt_f64_s32(d0, s0); |
| 2609 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2610 | __ sub(r3, r0, Operand(kHeapObjectTag)); |
| 2611 | __ vstr(d0, r3, HeapNumber::kValueOffset); |
| 2612 | __ Ret(); |
| 2613 | } else { |
| 2614 | // Tail call that writes the int32 in r2 to the heap number in r0, using |
| 2615 | // r3 as scratch. r0 is preserved and returned. |
| 2616 | WriteInt32ToHeapNumberStub stub(r2, r0, r3); |
| 2617 | __ TailCallStub(&stub); |
| 2618 | } |
| 2619 | break; |
| 2620 | } |
| 2621 | default: |
| 2622 | UNREACHABLE(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2623 | } |
| 2624 | } |
| 2625 | |
| 2626 | |
| 2627 | // Generate the smi code. If the operation on smis are successful this return is |
| 2628 | // generated. If the result is not a smi and heap number allocation is not |
| 2629 | // requested the code falls through. If number allocation is requested but a |
| 2630 | // heap number cannot be allocated the code jumps to the lable gc_required. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2631 | void BinaryOpStub::GenerateSmiCode( |
| 2632 | MacroAssembler* masm, |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2633 | Label* use_runtime, |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2634 | Label* gc_required, |
| 2635 | SmiCodeGenerateHeapNumberResults allow_heapnumber_results) { |
| 2636 | Label not_smis; |
| 2637 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2638 | Register left = r1; |
| 2639 | Register right = r0; |
| 2640 | Register scratch1 = r7; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2641 | |
| 2642 | // Perform combined smi check on both operands. |
| 2643 | __ orr(scratch1, left, Operand(right)); |
| 2644 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2645 | __ JumpIfNotSmi(scratch1, ¬_smis); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2646 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2647 | // If the smi-smi operation results in a smi return is generated. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2648 | GenerateSmiSmiOperation(masm); |
| 2649 | |
| 2650 | // If heap number results are possible generate the result in an allocated |
| 2651 | // heap number. |
| 2652 | if (allow_heapnumber_results == ALLOW_HEAPNUMBER_RESULTS) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2653 | GenerateFPOperation(masm, true, use_runtime, gc_required); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2654 | } |
| 2655 | __ bind(¬_smis); |
| 2656 | } |
| 2657 | |
| 2658 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2659 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2660 | Label not_smis, call_runtime; |
| 2661 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2662 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 2663 | result_type_ == BinaryOpIC::SMI) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2664 | // Only allow smi results. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2665 | GenerateSmiCode(masm, &call_runtime, NULL, NO_HEAPNUMBER_RESULTS); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2666 | } else { |
| 2667 | // Allow heap number result and don't make a transition if a heap number |
| 2668 | // cannot be allocated. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2669 | GenerateSmiCode(masm, |
| 2670 | &call_runtime, |
| 2671 | &call_runtime, |
| 2672 | ALLOW_HEAPNUMBER_RESULTS); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | // Code falls through if the result is not returned as either a smi or heap |
| 2676 | // number. |
| 2677 | GenerateTypeTransition(masm); |
| 2678 | |
| 2679 | __ bind(&call_runtime); |
| 2680 | GenerateCallRuntime(masm); |
| 2681 | } |
| 2682 | |
| 2683 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2684 | void BinaryOpStub::GenerateStringStub(MacroAssembler* masm) { |
| 2685 | ASSERT(operands_type_ == BinaryOpIC::STRING); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2686 | ASSERT(op_ == Token::ADD); |
| 2687 | // Try to add arguments as strings, otherwise, transition to the generic |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2688 | // BinaryOpIC type. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2689 | GenerateAddStrings(masm); |
| 2690 | GenerateTypeTransition(masm); |
| 2691 | } |
| 2692 | |
| 2693 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2694 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2695 | Label call_runtime; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2696 | ASSERT(operands_type_ == BinaryOpIC::BOTH_STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2697 | ASSERT(op_ == Token::ADD); |
| 2698 | // If both arguments are strings, call the string add stub. |
| 2699 | // Otherwise, do a transition. |
| 2700 | |
| 2701 | // Registers containing left and right operands respectively. |
| 2702 | Register left = r1; |
| 2703 | Register right = r0; |
| 2704 | |
| 2705 | // Test if left operand is a string. |
| 2706 | __ JumpIfSmi(left, &call_runtime); |
| 2707 | __ CompareObjectType(left, r2, r2, FIRST_NONSTRING_TYPE); |
| 2708 | __ b(ge, &call_runtime); |
| 2709 | |
| 2710 | // Test if right operand is a string. |
| 2711 | __ JumpIfSmi(right, &call_runtime); |
| 2712 | __ CompareObjectType(right, r2, r2, FIRST_NONSTRING_TYPE); |
| 2713 | __ b(ge, &call_runtime); |
| 2714 | |
| 2715 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 2716 | GenerateRegisterArgsPush(masm); |
| 2717 | __ TailCallStub(&string_add_stub); |
| 2718 | |
| 2719 | __ bind(&call_runtime); |
| 2720 | GenerateTypeTransition(masm); |
| 2721 | } |
| 2722 | |
| 2723 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2724 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
| 2725 | ASSERT(operands_type_ == BinaryOpIC::INT32); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2726 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2727 | Register left = r1; |
| 2728 | Register right = r0; |
| 2729 | Register scratch1 = r7; |
| 2730 | Register scratch2 = r9; |
| 2731 | DwVfpRegister double_scratch = d0; |
| 2732 | SwVfpRegister single_scratch = s3; |
| 2733 | |
| 2734 | Register heap_number_result = no_reg; |
| 2735 | Register heap_number_map = r6; |
| 2736 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2737 | |
| 2738 | Label call_runtime; |
| 2739 | // Labels for type transition, used for wrong input or output types. |
| 2740 | // Both label are currently actually bound to the same position. We use two |
| 2741 | // different label to differentiate the cause leading to type transition. |
| 2742 | Label transition; |
| 2743 | |
| 2744 | // Smi-smi fast case. |
| 2745 | Label skip; |
| 2746 | __ orr(scratch1, left, right); |
| 2747 | __ JumpIfNotSmi(scratch1, &skip); |
| 2748 | GenerateSmiSmiOperation(masm); |
| 2749 | // Fall through if the result is not a smi. |
| 2750 | __ bind(&skip); |
| 2751 | |
| 2752 | switch (op_) { |
| 2753 | case Token::ADD: |
| 2754 | case Token::SUB: |
| 2755 | case Token::MUL: |
| 2756 | case Token::DIV: |
| 2757 | case Token::MOD: { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2758 | // Load both operands and check that they are 32-bit integer. |
| 2759 | // Jump to type transition if they are not. The registers r0 and r1 (right |
| 2760 | // and left) are preserved for the runtime call. |
| 2761 | FloatingPointHelper::Destination destination = |
| 2762 | (CpuFeatures::IsSupported(VFP3) && op_ != Token::MOD) |
| 2763 | ? FloatingPointHelper::kVFPRegisters |
| 2764 | : FloatingPointHelper::kCoreRegisters; |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2765 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2766 | FloatingPointHelper::LoadNumberAsInt32Double(masm, |
| 2767 | right, |
| 2768 | destination, |
| 2769 | d7, |
| 2770 | r2, |
| 2771 | r3, |
| 2772 | heap_number_map, |
| 2773 | scratch1, |
| 2774 | scratch2, |
| 2775 | s0, |
| 2776 | &transition); |
| 2777 | FloatingPointHelper::LoadNumberAsInt32Double(masm, |
| 2778 | left, |
| 2779 | destination, |
| 2780 | d6, |
| 2781 | r4, |
| 2782 | r5, |
| 2783 | heap_number_map, |
| 2784 | scratch1, |
| 2785 | scratch2, |
| 2786 | s0, |
| 2787 | &transition); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2788 | |
| 2789 | if (destination == FloatingPointHelper::kVFPRegisters) { |
| 2790 | CpuFeatures::Scope scope(VFP3); |
| 2791 | Label return_heap_number; |
| 2792 | switch (op_) { |
| 2793 | case Token::ADD: |
| 2794 | __ vadd(d5, d6, d7); |
| 2795 | break; |
| 2796 | case Token::SUB: |
| 2797 | __ vsub(d5, d6, d7); |
| 2798 | break; |
| 2799 | case Token::MUL: |
| 2800 | __ vmul(d5, d6, d7); |
| 2801 | break; |
| 2802 | case Token::DIV: |
| 2803 | __ vdiv(d5, d6, d7); |
| 2804 | break; |
| 2805 | default: |
| 2806 | UNREACHABLE(); |
| 2807 | } |
| 2808 | |
| 2809 | if (op_ != Token::DIV) { |
| 2810 | // These operations produce an integer result. |
| 2811 | // Try to return a smi if we can. |
| 2812 | // Otherwise return a heap number if allowed, or jump to type |
| 2813 | // transition. |
| 2814 | |
| 2815 | __ EmitVFPTruncate(kRoundToZero, |
| 2816 | single_scratch, |
| 2817 | d5, |
| 2818 | scratch1, |
| 2819 | scratch2); |
| 2820 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2821 | if (result_type_ <= BinaryOpIC::INT32) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2822 | // If the ne condition is set, result does |
| 2823 | // not fit in a 32-bit integer. |
| 2824 | __ b(ne, &transition); |
| 2825 | } |
| 2826 | |
| 2827 | // Check if the result fits in a smi. |
| 2828 | __ vmov(scratch1, single_scratch); |
| 2829 | __ add(scratch2, scratch1, Operand(0x40000000), SetCC); |
| 2830 | // If not try to return a heap number. |
| 2831 | __ b(mi, &return_heap_number); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2832 | // Check for minus zero. Return heap number for minus zero. |
| 2833 | Label not_zero; |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 2834 | __ cmp(scratch1, Operand::Zero()); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2835 | __ b(ne, ¬_zero); |
| 2836 | __ vmov(scratch2, d5.high()); |
| 2837 | __ tst(scratch2, Operand(HeapNumber::kSignMask)); |
| 2838 | __ b(ne, &return_heap_number); |
| 2839 | __ bind(¬_zero); |
| 2840 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2841 | // Tag the result and return. |
| 2842 | __ SmiTag(r0, scratch1); |
| 2843 | __ Ret(); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2844 | } else { |
| 2845 | // DIV just falls through to allocating a heap number. |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2846 | } |
| 2847 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 2848 | __ bind(&return_heap_number); |
| 2849 | // Return a heap number, or fall through to type transition or runtime |
| 2850 | // call if we can't. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2851 | if (result_type_ >= ((op_ == Token::DIV) ? BinaryOpIC::HEAP_NUMBER |
| 2852 | : BinaryOpIC::INT32)) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2853 | // We are using vfp registers so r5 is available. |
| 2854 | heap_number_result = r5; |
| 2855 | GenerateHeapResultAllocation(masm, |
| 2856 | heap_number_result, |
| 2857 | heap_number_map, |
| 2858 | scratch1, |
| 2859 | scratch2, |
| 2860 | &call_runtime); |
| 2861 | __ sub(r0, heap_number_result, Operand(kHeapObjectTag)); |
| 2862 | __ vstr(d5, r0, HeapNumber::kValueOffset); |
| 2863 | __ mov(r0, heap_number_result); |
| 2864 | __ Ret(); |
| 2865 | } |
| 2866 | |
| 2867 | // A DIV operation expecting an integer result falls through |
| 2868 | // to type transition. |
| 2869 | |
| 2870 | } else { |
| 2871 | // We preserved r0 and r1 to be able to call runtime. |
| 2872 | // Save the left value on the stack. |
| 2873 | __ Push(r5, r4); |
| 2874 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2875 | Label pop_and_call_runtime; |
| 2876 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2877 | // Allocate a heap number to store the result. |
| 2878 | heap_number_result = r5; |
| 2879 | GenerateHeapResultAllocation(masm, |
| 2880 | heap_number_result, |
| 2881 | heap_number_map, |
| 2882 | scratch1, |
| 2883 | scratch2, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2884 | &pop_and_call_runtime); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2885 | |
| 2886 | // Load the left value from the value saved on the stack. |
| 2887 | __ Pop(r1, r0); |
| 2888 | |
| 2889 | // Call the C function to handle the double operation. |
| 2890 | FloatingPointHelper::CallCCodeForDoubleOperation( |
| 2891 | masm, op_, heap_number_result, scratch1); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2892 | if (FLAG_debug_code) { |
| 2893 | __ stop("Unreachable code."); |
| 2894 | } |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2895 | |
| 2896 | __ bind(&pop_and_call_runtime); |
| 2897 | __ Drop(2); |
| 2898 | __ b(&call_runtime); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | break; |
| 2902 | } |
| 2903 | |
| 2904 | case Token::BIT_OR: |
| 2905 | case Token::BIT_XOR: |
| 2906 | case Token::BIT_AND: |
| 2907 | case Token::SAR: |
| 2908 | case Token::SHR: |
| 2909 | case Token::SHL: { |
| 2910 | Label return_heap_number; |
| 2911 | Register scratch3 = r5; |
| 2912 | // Convert operands to 32-bit integers. Right in r2 and left in r3. The |
| 2913 | // registers r0 and r1 (right and left) are preserved for the runtime |
| 2914 | // call. |
| 2915 | FloatingPointHelper::LoadNumberAsInt32(masm, |
| 2916 | left, |
| 2917 | r3, |
| 2918 | heap_number_map, |
| 2919 | scratch1, |
| 2920 | scratch2, |
| 2921 | scratch3, |
| 2922 | d0, |
| 2923 | &transition); |
| 2924 | FloatingPointHelper::LoadNumberAsInt32(masm, |
| 2925 | right, |
| 2926 | r2, |
| 2927 | heap_number_map, |
| 2928 | scratch1, |
| 2929 | scratch2, |
| 2930 | scratch3, |
| 2931 | d0, |
| 2932 | &transition); |
| 2933 | |
| 2934 | // The ECMA-262 standard specifies that, for shift operations, only the |
| 2935 | // 5 least significant bits of the shift value should be used. |
| 2936 | switch (op_) { |
| 2937 | case Token::BIT_OR: |
| 2938 | __ orr(r2, r3, Operand(r2)); |
| 2939 | break; |
| 2940 | case Token::BIT_XOR: |
| 2941 | __ eor(r2, r3, Operand(r2)); |
| 2942 | break; |
| 2943 | case Token::BIT_AND: |
| 2944 | __ and_(r2, r3, Operand(r2)); |
| 2945 | break; |
| 2946 | case Token::SAR: |
| 2947 | __ and_(r2, r2, Operand(0x1f)); |
| 2948 | __ mov(r2, Operand(r3, ASR, r2)); |
| 2949 | break; |
| 2950 | case Token::SHR: |
| 2951 | __ and_(r2, r2, Operand(0x1f)); |
| 2952 | __ mov(r2, Operand(r3, LSR, r2), SetCC); |
| 2953 | // SHR is special because it is required to produce a positive answer. |
| 2954 | // We only get a negative result if the shift value (r2) is 0. |
| 2955 | // This result cannot be respresented as a signed 32-bit integer, try |
| 2956 | // to return a heap number if we can. |
| 2957 | // The non vfp3 code does not support this special case, so jump to |
| 2958 | // runtime if we don't support it. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2959 | if (CpuFeatures::IsSupported(VFP3)) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2960 | __ b(mi, (result_type_ <= BinaryOpIC::INT32) |
| 2961 | ? &transition |
| 2962 | : &return_heap_number); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2963 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2964 | __ b(mi, (result_type_ <= BinaryOpIC::INT32) |
| 2965 | ? &transition |
| 2966 | : &call_runtime); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2967 | } |
| 2968 | break; |
| 2969 | case Token::SHL: |
| 2970 | __ and_(r2, r2, Operand(0x1f)); |
| 2971 | __ mov(r2, Operand(r3, LSL, r2)); |
| 2972 | break; |
| 2973 | default: |
| 2974 | UNREACHABLE(); |
| 2975 | } |
| 2976 | |
| 2977 | // Check if the result fits in a smi. |
| 2978 | __ add(scratch1, r2, Operand(0x40000000), SetCC); |
| 2979 | // If not try to return a heap number. (We know the result is an int32.) |
| 2980 | __ b(mi, &return_heap_number); |
| 2981 | // Tag the result and return. |
| 2982 | __ SmiTag(r0, r2); |
| 2983 | __ Ret(); |
| 2984 | |
| 2985 | __ bind(&return_heap_number); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2986 | heap_number_result = r5; |
| 2987 | GenerateHeapResultAllocation(masm, |
| 2988 | heap_number_result, |
| 2989 | heap_number_map, |
| 2990 | scratch1, |
| 2991 | scratch2, |
| 2992 | &call_runtime); |
| 2993 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2994 | if (CpuFeatures::IsSupported(VFP3)) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2995 | CpuFeatures::Scope scope(VFP3); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2996 | if (op_ != Token::SHR) { |
| 2997 | // Convert the result to a floating point value. |
| 2998 | __ vmov(double_scratch.low(), r2); |
| 2999 | __ vcvt_f64_s32(double_scratch, double_scratch.low()); |
| 3000 | } else { |
| 3001 | // The result must be interpreted as an unsigned 32-bit integer. |
| 3002 | __ vmov(double_scratch.low(), r2); |
| 3003 | __ vcvt_f64_u32(double_scratch, double_scratch.low()); |
| 3004 | } |
| 3005 | |
| 3006 | // Store the result. |
| 3007 | __ sub(r0, heap_number_result, Operand(kHeapObjectTag)); |
| 3008 | __ vstr(double_scratch, r0, HeapNumber::kValueOffset); |
| 3009 | __ mov(r0, heap_number_result); |
| 3010 | __ Ret(); |
| 3011 | } else { |
| 3012 | // Tail call that writes the int32 in r2 to the heap number in r0, using |
| 3013 | // r3 as scratch. r0 is preserved and returned. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3014 | __ mov(r0, r5); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3015 | WriteInt32ToHeapNumberStub stub(r2, r0, r3); |
| 3016 | __ TailCallStub(&stub); |
| 3017 | } |
| 3018 | |
| 3019 | break; |
| 3020 | } |
| 3021 | |
| 3022 | default: |
| 3023 | UNREACHABLE(); |
| 3024 | } |
| 3025 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3026 | // We never expect DIV to yield an integer result, so we always generate |
| 3027 | // type transition code for DIV operations expecting an integer result: the |
| 3028 | // code will fall through to this type transition. |
| 3029 | if (transition.is_linked() || |
| 3030 | ((op_ == Token::DIV) && (result_type_ <= BinaryOpIC::INT32))) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3031 | __ bind(&transition); |
| 3032 | GenerateTypeTransition(masm); |
| 3033 | } |
| 3034 | |
| 3035 | __ bind(&call_runtime); |
| 3036 | GenerateCallRuntime(masm); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3040 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3041 | Label call_runtime; |
| 3042 | |
| 3043 | if (op_ == Token::ADD) { |
| 3044 | // Handle string addition here, because it is the only operation |
| 3045 | // that does not do a ToNumber conversion on the operands. |
| 3046 | GenerateAddStrings(masm); |
| 3047 | } |
| 3048 | |
| 3049 | // Convert oddball arguments to numbers. |
| 3050 | Label check, done; |
| 3051 | __ CompareRoot(r1, Heap::kUndefinedValueRootIndex); |
| 3052 | __ b(ne, &check); |
| 3053 | if (Token::IsBitOp(op_)) { |
| 3054 | __ mov(r1, Operand(Smi::FromInt(0))); |
| 3055 | } else { |
| 3056 | __ LoadRoot(r1, Heap::kNanValueRootIndex); |
| 3057 | } |
| 3058 | __ jmp(&done); |
| 3059 | __ bind(&check); |
| 3060 | __ CompareRoot(r0, Heap::kUndefinedValueRootIndex); |
| 3061 | __ b(ne, &done); |
| 3062 | if (Token::IsBitOp(op_)) { |
| 3063 | __ mov(r0, Operand(Smi::FromInt(0))); |
| 3064 | } else { |
| 3065 | __ LoadRoot(r0, Heap::kNanValueRootIndex); |
| 3066 | } |
| 3067 | __ bind(&done); |
| 3068 | |
| 3069 | GenerateHeapNumberStub(masm); |
| 3070 | } |
| 3071 | |
| 3072 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3073 | void BinaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3074 | Label call_runtime; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3075 | GenerateFPOperation(masm, false, &call_runtime, &call_runtime); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3076 | |
| 3077 | __ bind(&call_runtime); |
| 3078 | GenerateCallRuntime(masm); |
| 3079 | } |
| 3080 | |
| 3081 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3082 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3083 | Label call_runtime, call_string_add_or_runtime; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3084 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3085 | GenerateSmiCode(masm, &call_runtime, &call_runtime, ALLOW_HEAPNUMBER_RESULTS); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3086 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3087 | GenerateFPOperation(masm, false, &call_string_add_or_runtime, &call_runtime); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3088 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3089 | __ bind(&call_string_add_or_runtime); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3090 | if (op_ == Token::ADD) { |
| 3091 | GenerateAddStrings(masm); |
| 3092 | } |
| 3093 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3094 | __ bind(&call_runtime); |
| 3095 | GenerateCallRuntime(masm); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3099 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3100 | ASSERT(op_ == Token::ADD); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3101 | Label left_not_string, call_runtime; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3102 | |
| 3103 | Register left = r1; |
| 3104 | Register right = r0; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3105 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3106 | // Check if left argument is a string. |
| 3107 | __ JumpIfSmi(left, &left_not_string); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3108 | __ CompareObjectType(left, r2, r2, FIRST_NONSTRING_TYPE); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3109 | __ b(ge, &left_not_string); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3110 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3111 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 3112 | GenerateRegisterArgsPush(masm); |
| 3113 | __ TailCallStub(&string_add_left_stub); |
| 3114 | |
| 3115 | // Left operand is not a string, test right. |
| 3116 | __ bind(&left_not_string); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3117 | __ JumpIfSmi(right, &call_runtime); |
| 3118 | __ CompareObjectType(right, r2, r2, FIRST_NONSTRING_TYPE); |
| 3119 | __ b(ge, &call_runtime); |
| 3120 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3121 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3122 | GenerateRegisterArgsPush(masm); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3123 | __ TailCallStub(&string_add_right_stub); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3124 | |
| 3125 | // At least one argument is not a string. |
| 3126 | __ bind(&call_runtime); |
| 3127 | } |
| 3128 | |
| 3129 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3130 | void BinaryOpStub::GenerateCallRuntime(MacroAssembler* masm) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3131 | GenerateRegisterArgsPush(masm); |
| 3132 | switch (op_) { |
| 3133 | case Token::ADD: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3134 | __ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3135 | break; |
| 3136 | case Token::SUB: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3137 | __ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3138 | break; |
| 3139 | case Token::MUL: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3140 | __ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3141 | break; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3142 | case Token::DIV: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3143 | __ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3144 | break; |
| 3145 | case Token::MOD: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3146 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3147 | break; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3148 | case Token::BIT_OR: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3149 | __ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3150 | break; |
| 3151 | case Token::BIT_AND: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3152 | __ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3153 | break; |
| 3154 | case Token::BIT_XOR: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3155 | __ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3156 | break; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3157 | case Token::SAR: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3158 | __ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3159 | break; |
| 3160 | case Token::SHR: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3161 | __ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3162 | break; |
| 3163 | case Token::SHL: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3164 | __ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3165 | break; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3166 | default: |
| 3167 | UNREACHABLE(); |
| 3168 | } |
| 3169 | } |
| 3170 | |
| 3171 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3172 | void BinaryOpStub::GenerateHeapResultAllocation(MacroAssembler* masm, |
| 3173 | Register result, |
| 3174 | Register heap_number_map, |
| 3175 | Register scratch1, |
| 3176 | Register scratch2, |
| 3177 | Label* gc_required) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3178 | // Code below will scratch result if allocation fails. To keep both arguments |
| 3179 | // intact for the runtime call result cannot be one of these. |
| 3180 | ASSERT(!result.is(r0) && !result.is(r1)); |
| 3181 | |
| 3182 | if (mode_ == OVERWRITE_LEFT || mode_ == OVERWRITE_RIGHT) { |
| 3183 | Label skip_allocation, allocated; |
| 3184 | Register overwritable_operand = mode_ == OVERWRITE_LEFT ? r1 : r0; |
| 3185 | // If the overwritable operand is already an object, we skip the |
| 3186 | // allocation of a heap number. |
| 3187 | __ JumpIfNotSmi(overwritable_operand, &skip_allocation); |
| 3188 | // Allocate a heap number for the result. |
| 3189 | __ AllocateHeapNumber( |
| 3190 | result, scratch1, scratch2, heap_number_map, gc_required); |
| 3191 | __ b(&allocated); |
| 3192 | __ bind(&skip_allocation); |
| 3193 | // Use object holding the overwritable operand for result. |
| 3194 | __ mov(result, Operand(overwritable_operand)); |
| 3195 | __ bind(&allocated); |
| 3196 | } else { |
| 3197 | ASSERT(mode_ == NO_OVERWRITE); |
| 3198 | __ AllocateHeapNumber( |
| 3199 | result, scratch1, scratch2, heap_number_map, gc_required); |
| 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3204 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3205 | __ Push(r1, r0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3206 | } |
| 3207 | |
| 3208 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3209 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3210 | // Untagged case: double input in d2, double result goes |
| 3211 | // into d2. |
| 3212 | // Tagged case: tagged input on top of stack and in r0, |
| 3213 | // tagged result (heap number) goes into r0. |
| 3214 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3215 | Label input_not_smi; |
| 3216 | Label loaded; |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3217 | Label calculate; |
| 3218 | Label invalid_cache; |
| 3219 | const Register scratch0 = r9; |
| 3220 | const Register scratch1 = r7; |
| 3221 | const Register cache_entry = r0; |
| 3222 | const bool tagged = (argument_type_ == TAGGED); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3223 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3224 | if (CpuFeatures::IsSupported(VFP3)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3225 | CpuFeatures::Scope scope(VFP3); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3226 | if (tagged) { |
| 3227 | // Argument is a number and is on stack and in r0. |
| 3228 | // Load argument and check if it is a smi. |
| 3229 | __ JumpIfNotSmi(r0, &input_not_smi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3230 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3231 | // Input is a smi. Convert to double and load the low and high words |
| 3232 | // of the double into r2, r3. |
| 3233 | __ IntegerToDoubleConversionWithVFP3(r0, r3, r2); |
| 3234 | __ b(&loaded); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3235 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3236 | __ bind(&input_not_smi); |
| 3237 | // Check if input is a HeapNumber. |
| 3238 | __ CheckMap(r0, |
| 3239 | r1, |
| 3240 | Heap::kHeapNumberMapRootIndex, |
| 3241 | &calculate, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3242 | DONT_DO_SMI_CHECK); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3243 | // Input is a HeapNumber. Load it to a double register and store the |
| 3244 | // low and high words into r2, r3. |
| 3245 | __ vldr(d0, FieldMemOperand(r0, HeapNumber::kValueOffset)); |
| 3246 | __ vmov(r2, r3, d0); |
| 3247 | } else { |
| 3248 | // Input is untagged double in d2. Output goes to d2. |
| 3249 | __ vmov(r2, r3, d2); |
| 3250 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3251 | __ bind(&loaded); |
| 3252 | // r2 = low 32 bits of double value |
| 3253 | // r3 = high 32 bits of double value |
| 3254 | // Compute hash (the shifts are arithmetic): |
| 3255 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 3256 | __ eor(r1, r2, Operand(r3)); |
| 3257 | __ eor(r1, r1, Operand(r1, ASR, 16)); |
| 3258 | __ eor(r1, r1, Operand(r1, ASR, 8)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3259 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
| 3260 | __ And(r1, r1, Operand(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3261 | |
| 3262 | // r2 = low 32 bits of double value. |
| 3263 | // r3 = high 32 bits of double value. |
| 3264 | // r1 = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3265 | Isolate* isolate = masm->isolate(); |
| 3266 | ExternalReference cache_array = |
| 3267 | ExternalReference::transcendental_cache_array_address(isolate); |
| 3268 | __ mov(cache_entry, Operand(cache_array)); |
| 3269 | // cache_entry points to cache array. |
| 3270 | int cache_array_index |
| 3271 | = type_ * sizeof(isolate->transcendental_cache()->caches_[0]); |
| 3272 | __ ldr(cache_entry, MemOperand(cache_entry, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3273 | // r0 points to the cache for the type type_. |
| 3274 | // If NULL, the cache hasn't been initialized yet, so go through runtime. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3275 | __ cmp(cache_entry, Operand(0, RelocInfo::NONE)); |
| 3276 | __ b(eq, &invalid_cache); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3277 | |
| 3278 | #ifdef DEBUG |
| 3279 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3280 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3281 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 3282 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 3283 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 3284 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 3285 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 3286 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 3287 | CHECK_EQ(0, elem_in0 - elem_start); |
| 3288 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 3289 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 3290 | } |
| 3291 | #endif |
| 3292 | |
| 3293 | // Find the address of the r1'st entry in the cache, i.e., &r0[r1*12]. |
| 3294 | __ add(r1, r1, Operand(r1, LSL, 1)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3295 | __ add(cache_entry, cache_entry, Operand(r1, LSL, 2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3296 | // 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] | 3297 | __ ldm(ia, cache_entry, r4.bit() | r5.bit() | r6.bit()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3298 | __ cmp(r2, r4); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3299 | __ cmp(r3, r5, eq); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3300 | __ b(ne, &calculate); |
| 3301 | // Cache hit. Load result, cleanup and return. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3302 | Counters* counters = masm->isolate()->counters(); |
| 3303 | __ IncrementCounter( |
| 3304 | counters->transcendental_cache_hit(), 1, scratch0, scratch1); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3305 | if (tagged) { |
| 3306 | // Pop input value from stack and load result into r0. |
| 3307 | __ pop(); |
| 3308 | __ mov(r0, Operand(r6)); |
| 3309 | } else { |
| 3310 | // Load result into d2. |
| 3311 | __ vldr(d2, FieldMemOperand(r6, HeapNumber::kValueOffset)); |
| 3312 | } |
| 3313 | __ Ret(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3314 | } // if (CpuFeatures::IsSupported(VFP3)) |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3315 | |
| 3316 | __ bind(&calculate); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3317 | Counters* counters = masm->isolate()->counters(); |
| 3318 | __ IncrementCounter( |
| 3319 | counters->transcendental_cache_miss(), 1, scratch0, scratch1); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3320 | if (tagged) { |
| 3321 | __ bind(&invalid_cache); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3322 | ExternalReference runtime_function = |
| 3323 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 3324 | __ TailCallExternalReference(runtime_function, 1, 1); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3325 | } else { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3326 | if (!CpuFeatures::IsSupported(VFP3)) UNREACHABLE(); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3327 | CpuFeatures::Scope scope(VFP3); |
| 3328 | |
| 3329 | Label no_update; |
| 3330 | Label skip_cache; |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3331 | |
| 3332 | // Call C function to calculate the result and update the cache. |
| 3333 | // Register r0 holds precalculated cache entry address; preserve |
| 3334 | // it on the stack and pop it into register cache_entry after the |
| 3335 | // call. |
| 3336 | __ push(cache_entry); |
| 3337 | GenerateCallCFunction(masm, scratch0); |
| 3338 | __ GetCFunctionDoubleResult(d2); |
| 3339 | |
| 3340 | // Try to update the cache. If we cannot allocate a |
| 3341 | // heap number, we return the result without updating. |
| 3342 | __ pop(cache_entry); |
| 3343 | __ LoadRoot(r5, Heap::kHeapNumberMapRootIndex); |
| 3344 | __ AllocateHeapNumber(r6, scratch0, scratch1, r5, &no_update); |
| 3345 | __ vstr(d2, FieldMemOperand(r6, HeapNumber::kValueOffset)); |
| 3346 | __ stm(ia, cache_entry, r2.bit() | r3.bit() | r6.bit()); |
| 3347 | __ Ret(); |
| 3348 | |
| 3349 | __ bind(&invalid_cache); |
| 3350 | // The cache is invalid. Call runtime which will recreate the |
| 3351 | // cache. |
| 3352 | __ LoadRoot(r5, Heap::kHeapNumberMapRootIndex); |
| 3353 | __ AllocateHeapNumber(r0, scratch0, scratch1, r5, &skip_cache); |
| 3354 | __ vstr(d2, FieldMemOperand(r0, HeapNumber::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3355 | { |
| 3356 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3357 | __ push(r0); |
| 3358 | __ CallRuntime(RuntimeFunction(), 1); |
| 3359 | } |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3360 | __ vldr(d2, FieldMemOperand(r0, HeapNumber::kValueOffset)); |
| 3361 | __ Ret(); |
| 3362 | |
| 3363 | __ bind(&skip_cache); |
| 3364 | // Call C function to calculate the result and answer directly |
| 3365 | // without updating the cache. |
| 3366 | GenerateCallCFunction(masm, scratch0); |
| 3367 | __ GetCFunctionDoubleResult(d2); |
| 3368 | __ bind(&no_update); |
| 3369 | |
| 3370 | // We return the value in d2 without adding it to the cache, but |
| 3371 | // 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] | 3372 | { |
| 3373 | FrameScope scope(masm, StackFrame::INTERNAL); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3374 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3375 | // Allocate an aligned object larger than a HeapNumber. |
| 3376 | ASSERT(4 * kPointerSize >= HeapNumber::kSize); |
| 3377 | __ mov(scratch0, Operand(4 * kPointerSize)); |
| 3378 | __ push(scratch0); |
| 3379 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 3380 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3381 | __ Ret(); |
| 3382 | } |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3383 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3384 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3385 | |
| 3386 | void TranscendentalCacheStub::GenerateCallCFunction(MacroAssembler* masm, |
| 3387 | Register scratch) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3388 | Isolate* isolate = masm->isolate(); |
| 3389 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3390 | __ push(lr); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3391 | __ PrepareCallCFunction(0, 1, scratch); |
| 3392 | if (masm->use_eabi_hardfloat()) { |
| 3393 | __ vmov(d0, d2); |
| 3394 | } else { |
| 3395 | __ vmov(r0, r1, d2); |
| 3396 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3397 | AllowExternalCallThatCantCauseGC scope(masm); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3398 | switch (type_) { |
| 3399 | case TranscendentalCache::SIN: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3400 | __ CallCFunction(ExternalReference::math_sin_double_function(isolate), |
| 3401 | 0, 1); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3402 | break; |
| 3403 | case TranscendentalCache::COS: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3404 | __ CallCFunction(ExternalReference::math_cos_double_function(isolate), |
| 3405 | 0, 1); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3406 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3407 | case TranscendentalCache::TAN: |
| 3408 | __ CallCFunction(ExternalReference::math_tan_double_function(isolate), |
| 3409 | 0, 1); |
| 3410 | break; |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3411 | case TranscendentalCache::LOG: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3412 | __ CallCFunction(ExternalReference::math_log_double_function(isolate), |
| 3413 | 0, 1); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3414 | break; |
| 3415 | default: |
| 3416 | UNIMPLEMENTED(); |
| 3417 | break; |
| 3418 | } |
| 3419 | __ pop(lr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3420 | } |
| 3421 | |
| 3422 | |
| 3423 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 3424 | switch (type_) { |
| 3425 | // Add more cases when necessary. |
| 3426 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 3427 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3428 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3429 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3430 | default: |
| 3431 | UNIMPLEMENTED(); |
| 3432 | return Runtime::kAbort; |
| 3433 | } |
| 3434 | } |
| 3435 | |
| 3436 | |
| 3437 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 3438 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3442 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 3443 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 3444 | } |
| 3445 | |
| 3446 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3447 | void MathPowStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3448 | CpuFeatures::Scope vfp3_scope(VFP3); |
| 3449 | const Register base = r1; |
| 3450 | const Register exponent = r2; |
| 3451 | const Register heapnumbermap = r5; |
| 3452 | const Register heapnumber = r0; |
| 3453 | const DoubleRegister double_base = d1; |
| 3454 | const DoubleRegister double_exponent = d2; |
| 3455 | const DoubleRegister double_result = d3; |
| 3456 | const DoubleRegister double_scratch = d0; |
| 3457 | const SwVfpRegister single_scratch = s0; |
| 3458 | const Register scratch = r9; |
| 3459 | const Register scratch2 = r7; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3460 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3461 | Label call_runtime, done, int_exponent; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3462 | if (exponent_type_ == ON_STACK) { |
| 3463 | Label base_is_smi, unpack_exponent; |
| 3464 | // The exponent and base are supplied as arguments on the stack. |
| 3465 | // This can only happen if the stub is called from non-optimized code. |
| 3466 | // Load input parameters from stack to double registers. |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3467 | __ ldr(base, MemOperand(sp, 1 * kPointerSize)); |
| 3468 | __ ldr(exponent, MemOperand(sp, 0 * kPointerSize)); |
| 3469 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3470 | __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3471 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3472 | __ UntagAndJumpIfSmi(scratch, base, &base_is_smi); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3473 | __ ldr(scratch, FieldMemOperand(base, JSObject::kMapOffset)); |
| 3474 | __ cmp(scratch, heapnumbermap); |
| 3475 | __ b(ne, &call_runtime); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3476 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3477 | __ vldr(double_base, FieldMemOperand(base, HeapNumber::kValueOffset)); |
| 3478 | __ jmp(&unpack_exponent); |
| 3479 | |
| 3480 | __ bind(&base_is_smi); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3481 | __ vmov(single_scratch, scratch); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3482 | __ vcvt_f64_s32(double_base, single_scratch); |
| 3483 | __ bind(&unpack_exponent); |
| 3484 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3485 | __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3486 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3487 | __ ldr(scratch, FieldMemOperand(exponent, JSObject::kMapOffset)); |
| 3488 | __ cmp(scratch, heapnumbermap); |
| 3489 | __ b(ne, &call_runtime); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3490 | __ vldr(double_exponent, |
| 3491 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3492 | } else if (exponent_type_ == TAGGED) { |
| 3493 | // Base is already in double_base. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3494 | __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3495 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3496 | __ vldr(double_exponent, |
| 3497 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
| 3498 | } |
| 3499 | |
| 3500 | if (exponent_type_ != INTEGER) { |
| 3501 | Label int_exponent_convert; |
| 3502 | // Detect integer exponents stored as double. |
| 3503 | __ vcvt_u32_f64(single_scratch, double_exponent); |
| 3504 | // We do not check for NaN or Infinity here because comparing numbers on |
| 3505 | // ARM correctly distinguishes NaNs. We end up calling the built-in. |
| 3506 | __ vcvt_f64_u32(double_scratch, single_scratch); |
| 3507 | __ VFPCompareAndSetFlags(double_scratch, double_exponent); |
| 3508 | __ b(eq, &int_exponent_convert); |
| 3509 | |
| 3510 | if (exponent_type_ == ON_STACK) { |
| 3511 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 3512 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 3513 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 3514 | Label not_plus_half; |
| 3515 | |
| 3516 | // Test for 0.5. |
| 3517 | __ vmov(double_scratch, 0.5); |
| 3518 | __ VFPCompareAndSetFlags(double_exponent, double_scratch); |
| 3519 | __ b(ne, ¬_plus_half); |
| 3520 | |
| 3521 | // Calculates square root of base. Check for the special case of |
| 3522 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 3523 | __ vmov(double_scratch, -V8_INFINITY); |
| 3524 | __ VFPCompareAndSetFlags(double_base, double_scratch); |
| 3525 | __ vneg(double_result, double_scratch, eq); |
| 3526 | __ b(eq, &done); |
| 3527 | |
| 3528 | // Add +0 to convert -0 to +0. |
| 3529 | __ vadd(double_scratch, double_base, kDoubleRegZero); |
| 3530 | __ vsqrt(double_result, double_scratch); |
| 3531 | __ jmp(&done); |
| 3532 | |
| 3533 | __ bind(¬_plus_half); |
| 3534 | __ vmov(double_scratch, -0.5); |
| 3535 | __ VFPCompareAndSetFlags(double_exponent, double_scratch); |
| 3536 | __ b(ne, &call_runtime); |
| 3537 | |
| 3538 | // Calculates square root of base. Check for the special case of |
| 3539 | // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 3540 | __ vmov(double_scratch, -V8_INFINITY); |
| 3541 | __ VFPCompareAndSetFlags(double_base, double_scratch); |
| 3542 | __ vmov(double_result, kDoubleRegZero, eq); |
| 3543 | __ b(eq, &done); |
| 3544 | |
| 3545 | // Add +0 to convert -0 to +0. |
| 3546 | __ vadd(double_scratch, double_base, kDoubleRegZero); |
| 3547 | __ vmov(double_result, 1); |
| 3548 | __ vsqrt(double_scratch, double_scratch); |
| 3549 | __ vdiv(double_result, double_result, double_scratch); |
| 3550 | __ jmp(&done); |
| 3551 | } |
| 3552 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3553 | __ push(lr); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3554 | { |
| 3555 | AllowExternalCallThatCantCauseGC scope(masm); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3556 | __ PrepareCallCFunction(0, 2, scratch); |
| 3557 | __ SetCallCDoubleArguments(double_base, double_exponent); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3558 | __ CallCFunction( |
| 3559 | ExternalReference::power_double_double_function(masm->isolate()), |
| 3560 | 0, 2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3561 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3562 | __ pop(lr); |
| 3563 | __ GetCFunctionDoubleResult(double_result); |
| 3564 | __ jmp(&done); |
| 3565 | |
| 3566 | __ bind(&int_exponent_convert); |
| 3567 | __ vcvt_u32_f64(single_scratch, double_exponent); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3568 | __ vmov(scratch, single_scratch); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3569 | } |
| 3570 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3571 | // Calculate power with integer exponent. |
| 3572 | __ bind(&int_exponent); |
| 3573 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3574 | // Get two copies of exponent in the registers scratch and exponent. |
| 3575 | if (exponent_type_ == INTEGER) { |
| 3576 | __ mov(scratch, exponent); |
| 3577 | } else { |
| 3578 | // Exponent has previously been stored into scratch as untagged integer. |
| 3579 | __ mov(exponent, scratch); |
| 3580 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3581 | __ vmov(double_scratch, double_base); // Back up base. |
| 3582 | __ vmov(double_result, 1.0); |
| 3583 | |
| 3584 | // Get absolute value of exponent. |
| 3585 | __ cmp(scratch, Operand(0)); |
| 3586 | __ mov(scratch2, Operand(0), LeaveCC, mi); |
| 3587 | __ sub(scratch, scratch2, scratch, LeaveCC, mi); |
| 3588 | |
| 3589 | Label while_true; |
| 3590 | __ bind(&while_true); |
| 3591 | __ mov(scratch, Operand(scratch, ASR, 1), SetCC); |
| 3592 | __ vmul(double_result, double_result, double_scratch, cs); |
| 3593 | __ vmul(double_scratch, double_scratch, double_scratch, ne); |
| 3594 | __ b(ne, &while_true); |
| 3595 | |
| 3596 | __ cmp(exponent, Operand(0)); |
| 3597 | __ b(ge, &done); |
| 3598 | __ vmov(double_scratch, 1.0); |
| 3599 | __ vdiv(double_result, double_scratch, double_result); |
| 3600 | // Test whether result is zero. Bail out to check for subnormal result. |
| 3601 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 3602 | __ VFPCompareAndSetFlags(double_result, 0.0); |
| 3603 | __ b(ne, &done); |
| 3604 | // double_exponent may not containe the exponent value if the input was a |
| 3605 | // smi. We set it with exponent value before bailing out. |
| 3606 | __ vmov(single_scratch, exponent); |
| 3607 | __ vcvt_f64_s32(double_exponent, single_scratch); |
| 3608 | |
| 3609 | // Returning or bailing out. |
| 3610 | Counters* counters = masm->isolate()->counters(); |
| 3611 | if (exponent_type_ == ON_STACK) { |
| 3612 | // The arguments are still on the stack. |
| 3613 | __ bind(&call_runtime); |
| 3614 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
| 3615 | |
| 3616 | // The stub is called from non-optimized code, which expects the result |
| 3617 | // as heap number in exponent. |
| 3618 | __ bind(&done); |
| 3619 | __ AllocateHeapNumber( |
| 3620 | heapnumber, scratch, scratch2, heapnumbermap, &call_runtime); |
| 3621 | __ vstr(double_result, |
| 3622 | FieldMemOperand(heapnumber, HeapNumber::kValueOffset)); |
| 3623 | ASSERT(heapnumber.is(r0)); |
| 3624 | __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2); |
| 3625 | __ Ret(2); |
| 3626 | } else { |
| 3627 | __ push(lr); |
| 3628 | { |
| 3629 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3630 | __ PrepareCallCFunction(0, 2, scratch); |
| 3631 | __ SetCallCDoubleArguments(double_base, double_exponent); |
| 3632 | __ CallCFunction( |
| 3633 | ExternalReference::power_double_double_function(masm->isolate()), |
| 3634 | 0, 2); |
| 3635 | } |
| 3636 | __ pop(lr); |
| 3637 | __ GetCFunctionDoubleResult(double_result); |
| 3638 | |
| 3639 | __ bind(&done); |
| 3640 | __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2); |
| 3641 | __ Ret(); |
| 3642 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | |
| 3646 | bool CEntryStub::NeedsImmovableCode() { |
| 3647 | return true; |
| 3648 | } |
| 3649 | |
| 3650 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3651 | bool CEntryStub::IsPregenerated() { |
| 3652 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 3653 | result_size_ == 1; |
| 3654 | } |
| 3655 | |
| 3656 | |
| 3657 | void CodeStub::GenerateStubsAheadOfTime() { |
| 3658 | CEntryStub::GenerateAheadOfTime(); |
| 3659 | WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime(); |
| 3660 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(); |
| 3661 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(); |
| 3662 | } |
| 3663 | |
| 3664 | |
| 3665 | void CodeStub::GenerateFPStubs() { |
| 3666 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 3667 | Handle<Code> code = save_doubles.GetCode(); |
| 3668 | code->set_is_pregenerated(true); |
| 3669 | StoreBufferOverflowStub stub(kSaveFPRegs); |
| 3670 | stub.GetCode()->set_is_pregenerated(true); |
| 3671 | code->GetIsolate()->set_fp_stubs_generated(true); |
| 3672 | } |
| 3673 | |
| 3674 | |
| 3675 | void CEntryStub::GenerateAheadOfTime() { |
| 3676 | CEntryStub stub(1, kDontSaveFPRegs); |
| 3677 | Handle<Code> code = stub.GetCode(); |
| 3678 | code->set_is_pregenerated(true); |
| 3679 | } |
| 3680 | |
| 3681 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3682 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 3683 | Label* throw_normal_exception, |
| 3684 | Label* throw_termination_exception, |
| 3685 | Label* throw_out_of_memory_exception, |
| 3686 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3687 | bool always_allocate) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3688 | // r0: result parameter for PerformGC, if any |
| 3689 | // r4: number of arguments including receiver (C callee-saved) |
| 3690 | // r5: pointer to builtin function (C callee-saved) |
| 3691 | // r6: pointer to the first argument (C callee-saved) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3692 | Isolate* isolate = masm->isolate(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3693 | |
| 3694 | if (do_gc) { |
| 3695 | // Passing r0. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3696 | __ PrepareCallCFunction(1, 0, r1); |
| 3697 | __ CallCFunction(ExternalReference::perform_gc_function(isolate), |
| 3698 | 1, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3699 | } |
| 3700 | |
| 3701 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3702 | ExternalReference::heap_always_allocate_scope_depth(isolate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3703 | if (always_allocate) { |
| 3704 | __ mov(r0, Operand(scope_depth)); |
| 3705 | __ ldr(r1, MemOperand(r0)); |
| 3706 | __ add(r1, r1, Operand(1)); |
| 3707 | __ str(r1, MemOperand(r0)); |
| 3708 | } |
| 3709 | |
| 3710 | // Call C built-in. |
| 3711 | // r0 = argc, r1 = argv |
| 3712 | __ mov(r0, Operand(r4)); |
| 3713 | __ mov(r1, Operand(r6)); |
| 3714 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3715 | #if defined(V8_HOST_ARCH_ARM) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3716 | int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
| 3717 | int frame_alignment_mask = frame_alignment - 1; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3718 | if (FLAG_debug_code) { |
| 3719 | if (frame_alignment > kPointerSize) { |
| 3720 | Label alignment_as_expected; |
| 3721 | ASSERT(IsPowerOf2(frame_alignment)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3722 | __ tst(sp, Operand(frame_alignment_mask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3723 | __ b(eq, &alignment_as_expected); |
| 3724 | // Don't use Check here, as it will call Runtime_Abort re-entering here. |
| 3725 | __ stop("Unexpected alignment"); |
| 3726 | __ bind(&alignment_as_expected); |
| 3727 | } |
| 3728 | } |
| 3729 | #endif |
| 3730 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3731 | __ mov(r2, Operand(ExternalReference::isolate_address())); |
| 3732 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3733 | // To let the GC traverse the return address of the exit frames, we need to |
| 3734 | // know where the return address is. The CEntryStub is unmovable, so |
| 3735 | // we can store the address on the stack to be able to find it again and |
| 3736 | // we never have to restore it, because it will not change. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3737 | // Compute the return address in lr to return to after the jump below. Pc is |
| 3738 | // already at '+ 8' from the current instruction but return is after three |
| 3739 | // instructions so add another 4 to pc to get the return address. |
| 3740 | masm->add(lr, pc, Operand(4)); |
| 3741 | __ str(lr, MemOperand(sp, 0)); |
| 3742 | masm->Jump(r5); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3743 | |
| 3744 | if (always_allocate) { |
| 3745 | // It's okay to clobber r2 and r3 here. Don't mess with r0 and r1 |
| 3746 | // though (contain the result). |
| 3747 | __ mov(r2, Operand(scope_depth)); |
| 3748 | __ ldr(r3, MemOperand(r2)); |
| 3749 | __ sub(r3, r3, Operand(1)); |
| 3750 | __ str(r3, MemOperand(r2)); |
| 3751 | } |
| 3752 | |
| 3753 | // check for failure result |
| 3754 | Label failure_returned; |
| 3755 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 3756 | // Lower 2 bits of r2 are 0 iff r0 has failure tag. |
| 3757 | __ add(r2, r0, Operand(1)); |
| 3758 | __ tst(r2, Operand(kFailureTagMask)); |
| 3759 | __ b(eq, &failure_returned); |
| 3760 | |
| 3761 | // Exit C frame and return. |
| 3762 | // r0:r1: result |
| 3763 | // sp: stack pointer |
| 3764 | // fp: frame pointer |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3765 | // Callee-saved register r4 still holds argc. |
| 3766 | __ LeaveExitFrame(save_doubles_, r4); |
| 3767 | __ mov(pc, lr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3768 | |
| 3769 | // check if we should retry or throw exception |
| 3770 | Label retry; |
| 3771 | __ bind(&failure_returned); |
| 3772 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 3773 | __ tst(r0, Operand(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
| 3774 | __ b(eq, &retry); |
| 3775 | |
| 3776 | // Special handling of out of memory exceptions. |
| 3777 | Failure* out_of_memory = Failure::OutOfMemoryException(); |
| 3778 | __ cmp(r0, Operand(reinterpret_cast<int32_t>(out_of_memory))); |
| 3779 | __ b(eq, throw_out_of_memory_exception); |
| 3780 | |
| 3781 | // Retrieve the pending exception and clear the variable. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3782 | __ mov(r3, Operand(isolate->factory()->the_hole_value())); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3783 | __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3784 | isolate))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3785 | __ ldr(r0, MemOperand(ip)); |
| 3786 | __ str(r3, MemOperand(ip)); |
| 3787 | |
| 3788 | // Special handling of termination exceptions which are uncatchable |
| 3789 | // by javascript code. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3790 | __ cmp(r0, Operand(isolate->factory()->termination_exception())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3791 | __ b(eq, throw_termination_exception); |
| 3792 | |
| 3793 | // Handle normal exception. |
| 3794 | __ jmp(throw_normal_exception); |
| 3795 | |
| 3796 | __ bind(&retry); // pass last failure (r0) as parameter (r0) when retrying |
| 3797 | } |
| 3798 | |
| 3799 | |
| 3800 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 3801 | // Called from JavaScript; parameters are on stack as if calling JS function |
| 3802 | // r0: number of arguments including receiver |
| 3803 | // r1: pointer to builtin function |
| 3804 | // fp: frame pointer (restored after C call) |
| 3805 | // sp: stack pointer (restored as callee's sp after C call) |
| 3806 | // cp: current context (C callee-saved) |
| 3807 | |
| 3808 | // Result returned in r0 or r0+r1 by default. |
| 3809 | |
| 3810 | // NOTE: Invocations of builtins may return failure objects |
| 3811 | // instead of a proper result. The builtin entry handles |
| 3812 | // this by performing a garbage collection and retrying the |
| 3813 | // builtin once. |
| 3814 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3815 | // Compute the argv pointer in a callee-saved register. |
| 3816 | __ add(r6, sp, Operand(r0, LSL, kPointerSizeLog2)); |
| 3817 | __ sub(r6, r6, Operand(kPointerSize)); |
| 3818 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3819 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3820 | FrameScope scope(masm, StackFrame::MANUAL); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3821 | __ EnterExitFrame(save_doubles_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3822 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3823 | // Set up argc and the builtin function in callee-saved registers. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3824 | __ mov(r4, Operand(r0)); |
| 3825 | __ mov(r5, Operand(r1)); |
| 3826 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3827 | // r4: number of arguments (C callee-saved) |
| 3828 | // r5: pointer to builtin function (C callee-saved) |
| 3829 | // r6: pointer to first argument (C callee-saved) |
| 3830 | |
| 3831 | Label throw_normal_exception; |
| 3832 | Label throw_termination_exception; |
| 3833 | Label throw_out_of_memory_exception; |
| 3834 | |
| 3835 | // Call into the runtime system. |
| 3836 | GenerateCore(masm, |
| 3837 | &throw_normal_exception, |
| 3838 | &throw_termination_exception, |
| 3839 | &throw_out_of_memory_exception, |
| 3840 | false, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3841 | false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3842 | |
| 3843 | // Do space-specific GC and retry runtime call. |
| 3844 | GenerateCore(masm, |
| 3845 | &throw_normal_exception, |
| 3846 | &throw_termination_exception, |
| 3847 | &throw_out_of_memory_exception, |
| 3848 | true, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3849 | false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3850 | |
| 3851 | // Do full GC and retry runtime call one final time. |
| 3852 | Failure* failure = Failure::InternalError(); |
| 3853 | __ mov(r0, Operand(reinterpret_cast<int32_t>(failure))); |
| 3854 | GenerateCore(masm, |
| 3855 | &throw_normal_exception, |
| 3856 | &throw_termination_exception, |
| 3857 | &throw_out_of_memory_exception, |
| 3858 | true, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3859 | true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3860 | |
| 3861 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 3862 | // Set external caught exception to false. |
| 3863 | Isolate* isolate = masm->isolate(); |
| 3864 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 3865 | isolate); |
| 3866 | __ mov(r0, Operand(false, RelocInfo::NONE)); |
| 3867 | __ mov(r2, Operand(external_caught)); |
| 3868 | __ str(r0, MemOperand(r2)); |
| 3869 | |
| 3870 | // Set pending exception and r0 to out of memory exception. |
| 3871 | Failure* out_of_memory = Failure::OutOfMemoryException(); |
| 3872 | __ mov(r0, Operand(reinterpret_cast<int32_t>(out_of_memory))); |
| 3873 | __ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
| 3874 | isolate))); |
| 3875 | __ str(r0, MemOperand(r2)); |
| 3876 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3877 | |
| 3878 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 3879 | __ ThrowUncatchable(r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3880 | |
| 3881 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 3882 | __ Throw(r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3883 | } |
| 3884 | |
| 3885 | |
| 3886 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
| 3887 | // r0: code entry |
| 3888 | // r1: function |
| 3889 | // r2: receiver |
| 3890 | // r3: argc |
| 3891 | // [sp+0]: argv |
| 3892 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 3893 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3894 | |
| 3895 | // Called from C, so do not pop argc and args on exit (preserve sp) |
| 3896 | // No need to save register-passed args |
| 3897 | // Save callee-saved registers (incl. cp and fp), sp, and lr |
| 3898 | __ stm(db_w, sp, kCalleeSaved | lr.bit()); |
| 3899 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 3900 | if (CpuFeatures::IsSupported(VFP3)) { |
| 3901 | CpuFeatures::Scope scope(VFP3); |
| 3902 | // Save callee-saved vfp registers. |
| 3903 | __ vstm(db_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3904 | // Set up the reserved register for 0.0. |
| 3905 | __ vmov(kDoubleRegZero, 0.0); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 3906 | } |
| 3907 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3908 | // Get address of argv, see stm above. |
| 3909 | // r0: code entry |
| 3910 | // r1: function |
| 3911 | // r2: receiver |
| 3912 | // r3: argc |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 3913 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3914 | // Set up argv in r4. |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 3915 | int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize; |
| 3916 | if (CpuFeatures::IsSupported(VFP3)) { |
| 3917 | offset_to_argv += kNumDoubleCalleeSaved * kDoubleSize; |
| 3918 | } |
| 3919 | __ ldr(r4, MemOperand(sp, offset_to_argv)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3920 | |
| 3921 | // Push a frame with special values setup to mark it as an entry frame. |
| 3922 | // r0: code entry |
| 3923 | // r1: function |
| 3924 | // r2: receiver |
| 3925 | // r3: argc |
| 3926 | // r4: argv |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3927 | Isolate* isolate = masm->isolate(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3928 | __ mov(r8, Operand(-1)); // Push a bad frame pointer to fail if it is used. |
| 3929 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 3930 | __ mov(r7, Operand(Smi::FromInt(marker))); |
| 3931 | __ mov(r6, Operand(Smi::FromInt(marker))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3932 | __ mov(r5, |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3933 | Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3934 | __ ldr(r5, MemOperand(r5)); |
| 3935 | __ Push(r8, r7, r6, r5); |
| 3936 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3937 | // Set up frame pointer for the frame to be pushed. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3938 | __ add(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset)); |
| 3939 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3940 | // 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] | 3941 | Label non_outermost_js; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3942 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3943 | __ mov(r5, Operand(ExternalReference(js_entry_sp))); |
| 3944 | __ ldr(r6, MemOperand(r5)); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3945 | __ cmp(r6, Operand::Zero()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3946 | __ b(ne, &non_outermost_js); |
| 3947 | __ str(fp, MemOperand(r5)); |
| 3948 | __ mov(ip, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 3949 | Label cont; |
| 3950 | __ b(&cont); |
| 3951 | __ bind(&non_outermost_js); |
| 3952 | __ mov(ip, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
| 3953 | __ bind(&cont); |
| 3954 | __ push(ip); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3955 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 3956 | // Jump to a faked try block that does the invoke, with a faked catch |
| 3957 | // block that sets the pending exception. |
| 3958 | __ jmp(&invoke); |
| 3959 | __ bind(&handler_entry); |
| 3960 | handler_offset_ = handler_entry.pos(); |
| 3961 | // Caught exception: Store result (exception) in the pending exception |
| 3962 | // field in the JSEnv and return a failure sentinel. Coming in here the |
| 3963 | // fp will be invalid because the PushTryHandler below sets it to 0 to |
| 3964 | // signal the existence of the JSEntry frame. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3965 | __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3966 | isolate))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3967 | __ str(r0, MemOperand(ip)); |
| 3968 | __ mov(r0, Operand(reinterpret_cast<int32_t>(Failure::Exception()))); |
| 3969 | __ b(&exit); |
| 3970 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 3971 | // Invoke: Link this frame into the handler chain. There's only one |
| 3972 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3973 | __ bind(&invoke); |
| 3974 | // Must preserve r0-r4, r5-r7 are available. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 3975 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3976 | // If an exception not caught by another handler occurs, this handler |
| 3977 | // returns control to the code after the bl(&invoke) above, which |
| 3978 | // restores all kCalleeSaved registers (including cp and fp) to their |
| 3979 | // saved values before returning a failure to C. |
| 3980 | |
| 3981 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3982 | __ mov(r5, Operand(isolate->factory()->the_hole_value())); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3983 | __ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3984 | isolate))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3985 | __ str(r5, MemOperand(ip)); |
| 3986 | |
| 3987 | // Invoke the function by calling through JS entry trampoline builtin. |
| 3988 | // Notice that we cannot store a reference to the trampoline code directly in |
| 3989 | // this stub, because runtime stubs are not traversed when doing GC. |
| 3990 | |
| 3991 | // Expected registers by Builtins::JSEntryTrampoline |
| 3992 | // r0: code entry |
| 3993 | // r1: function |
| 3994 | // r2: receiver |
| 3995 | // r3: argc |
| 3996 | // r4: argv |
| 3997 | if (is_construct) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3998 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3999 | isolate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4000 | __ mov(ip, Operand(construct_entry)); |
| 4001 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4002 | ExternalReference entry(Builtins::kJSEntryTrampoline, isolate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4003 | __ mov(ip, Operand(entry)); |
| 4004 | } |
| 4005 | __ ldr(ip, MemOperand(ip)); // deref address |
| 4006 | |
| 4007 | // Branch and link to JSEntryTrampoline. We don't use the double underscore |
| 4008 | // macro for the add instruction because we don't want the coverage tool |
| 4009 | // inserting instructions here after we read the pc. |
| 4010 | __ mov(lr, Operand(pc)); |
| 4011 | masm->add(pc, ip, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4012 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4013 | // Unlink this frame from the handler chain. |
| 4014 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4015 | |
| 4016 | __ bind(&exit); // r0 holds result |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4017 | // Check if the current stack frame is marked as the outermost JS frame. |
| 4018 | Label non_outermost_js_2; |
| 4019 | __ pop(r5); |
| 4020 | __ cmp(r5, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 4021 | __ b(ne, &non_outermost_js_2); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4022 | __ mov(r6, Operand::Zero()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4023 | __ mov(r5, Operand(ExternalReference(js_entry_sp))); |
| 4024 | __ str(r6, MemOperand(r5)); |
| 4025 | __ bind(&non_outermost_js_2); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4026 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4027 | // Restore the top frame descriptors from the stack. |
| 4028 | __ pop(r3); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4029 | __ mov(ip, |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4030 | Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4031 | __ str(r3, MemOperand(ip)); |
| 4032 | |
| 4033 | // Reset the stack to the callee saved registers. |
| 4034 | __ add(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset)); |
| 4035 | |
| 4036 | // Restore callee-saved registers and return. |
| 4037 | #ifdef DEBUG |
| 4038 | if (FLAG_debug_code) { |
| 4039 | __ mov(lr, Operand(pc)); |
| 4040 | } |
| 4041 | #endif |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4042 | |
| 4043 | if (CpuFeatures::IsSupported(VFP3)) { |
| 4044 | CpuFeatures::Scope scope(VFP3); |
| 4045 | // Restore callee-saved vfp registers. |
| 4046 | __ vldm(ia_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg); |
| 4047 | } |
| 4048 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4049 | __ ldm(ia_w, sp, kCalleeSaved | pc.bit()); |
| 4050 | } |
| 4051 | |
| 4052 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4053 | // Uses registers r0 to r4. |
| 4054 | // Expected input (depending on whether args are in registers or on the stack): |
| 4055 | // * object: r0 or at sp + 1 * kPointerSize. |
| 4056 | // * function: r1 or at sp. |
| 4057 | // |
| 4058 | // An inlined call site may have been generated before calling this stub. |
| 4059 | // In this case the offset to the inline site to patch is passed on the stack, |
| 4060 | // in the safepoint slot for register r4. |
| 4061 | // (See LCodeGen::DoInstanceOfKnownGlobal) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4062 | void InstanceofStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4063 | // Call site inlining and patching implies arguments in registers. |
| 4064 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 4065 | // ReturnTrueFalse is only implemented for inlined call sites. |
| 4066 | ASSERT(!ReturnTrueFalseObject() || HasCallSiteInlineCheck()); |
| 4067 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4068 | // Fixed register usage throughout the stub: |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 4069 | const Register object = r0; // Object (lhs). |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4070 | Register map = r3; // Map of the object. |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 4071 | const Register function = r1; // Function (rhs). |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4072 | const Register prototype = r4; // Prototype of the function. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4073 | const Register inline_site = r9; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4074 | const Register scratch = r2; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4075 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4076 | const int32_t kDeltaToLoadBoolResult = 4 * kPointerSize; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4077 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4078 | Label slow, loop, is_instance, is_not_instance, not_js_object; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4079 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4080 | if (!HasArgsInRegisters()) { |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 4081 | __ ldr(object, MemOperand(sp, 1 * kPointerSize)); |
| 4082 | __ ldr(function, MemOperand(sp, 0)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4083 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4084 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4085 | // 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] | 4086 | __ JumpIfSmi(object, ¬_js_object); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 4087 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4088 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4089 | // If there is a call site cache don't look in the global cache, but do the |
| 4090 | // real lookup and update the call site cache. |
| 4091 | if (!HasCallSiteInlineCheck()) { |
| 4092 | Label miss; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4093 | __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4094 | __ b(ne, &miss); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4095 | __ CompareRoot(map, Heap::kInstanceofCacheMapRootIndex); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4096 | __ b(ne, &miss); |
| 4097 | __ LoadRoot(r0, Heap::kInstanceofCacheAnswerRootIndex); |
| 4098 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4099 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4100 | __ bind(&miss); |
| 4101 | } |
| 4102 | |
| 4103 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4104 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4105 | |
| 4106 | // Check that the function prototype is a JS object. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4107 | __ JumpIfSmi(prototype, &slow); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4108 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4109 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4110 | // Update the global instanceof or call site inlined cache with the current |
| 4111 | // map and function. The cached answer will be set when it is known below. |
| 4112 | if (!HasCallSiteInlineCheck()) { |
| 4113 | __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex); |
| 4114 | __ StoreRoot(map, Heap::kInstanceofCacheMapRootIndex); |
| 4115 | } else { |
| 4116 | ASSERT(HasArgsInRegisters()); |
| 4117 | // Patch the (relocated) inlined map check. |
| 4118 | |
| 4119 | // The offset was stored in r4 safepoint slot. |
| 4120 | // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal) |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4121 | __ LoadFromSafepointRegisterSlot(scratch, r4); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4122 | __ sub(inline_site, lr, scratch); |
| 4123 | // Get the map location in scratch and patch it. |
| 4124 | __ GetRelocatedValueLocation(inline_site, scratch); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4125 | __ ldr(scratch, MemOperand(scratch)); |
| 4126 | __ str(map, FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4127 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4128 | |
| 4129 | // Register mapping: r3 is object map and r4 is function prototype. |
| 4130 | // Get prototype of object into r2. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4131 | __ ldr(scratch, FieldMemOperand(map, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4132 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4133 | // We don't need map any more. Use it as a scratch register. |
| 4134 | Register scratch2 = map; |
| 4135 | map = no_reg; |
| 4136 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4137 | // Loop through the prototype chain looking for the function prototype. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4138 | __ LoadRoot(scratch2, Heap::kNullValueRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4139 | __ bind(&loop); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4140 | __ cmp(scratch, Operand(prototype)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4141 | __ b(eq, &is_instance); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4142 | __ cmp(scratch, scratch2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4143 | __ b(eq, &is_not_instance); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4144 | __ ldr(scratch, FieldMemOperand(scratch, HeapObject::kMapOffset)); |
| 4145 | __ ldr(scratch, FieldMemOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4146 | __ jmp(&loop); |
| 4147 | |
| 4148 | __ bind(&is_instance); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4149 | if (!HasCallSiteInlineCheck()) { |
| 4150 | __ mov(r0, Operand(Smi::FromInt(0))); |
| 4151 | __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex); |
| 4152 | } else { |
| 4153 | // Patch the call site to return true. |
| 4154 | __ LoadRoot(r0, Heap::kTrueValueRootIndex); |
| 4155 | __ add(inline_site, inline_site, Operand(kDeltaToLoadBoolResult)); |
| 4156 | // Get the boolean result location in scratch and patch it. |
| 4157 | __ GetRelocatedValueLocation(inline_site, scratch); |
| 4158 | __ str(r0, MemOperand(scratch)); |
| 4159 | |
| 4160 | if (!ReturnTrueFalseObject()) { |
| 4161 | __ mov(r0, Operand(Smi::FromInt(0))); |
| 4162 | } |
| 4163 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4164 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4165 | |
| 4166 | __ bind(&is_not_instance); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4167 | if (!HasCallSiteInlineCheck()) { |
| 4168 | __ mov(r0, Operand(Smi::FromInt(1))); |
| 4169 | __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex); |
| 4170 | } else { |
| 4171 | // Patch the call site to return false. |
| 4172 | __ LoadRoot(r0, Heap::kFalseValueRootIndex); |
| 4173 | __ add(inline_site, inline_site, Operand(kDeltaToLoadBoolResult)); |
| 4174 | // Get the boolean result location in scratch and patch it. |
| 4175 | __ GetRelocatedValueLocation(inline_site, scratch); |
| 4176 | __ str(r0, MemOperand(scratch)); |
| 4177 | |
| 4178 | if (!ReturnTrueFalseObject()) { |
| 4179 | __ mov(r0, Operand(Smi::FromInt(1))); |
| 4180 | } |
| 4181 | } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4182 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4183 | |
| 4184 | Label object_not_null, object_not_null_or_smi; |
| 4185 | __ bind(¬_js_object); |
| 4186 | // Before null, smi and string value checks, check that the rhs is a function |
| 4187 | // 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] | 4188 | __ JumpIfSmi(function, &slow); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4189 | __ CompareObjectType(function, scratch2, scratch, JS_FUNCTION_TYPE); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4190 | __ b(ne, &slow); |
| 4191 | |
| 4192 | // Null is not instance of anything. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4193 | __ cmp(scratch, Operand(masm->isolate()->factory()->null_value())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4194 | __ b(ne, &object_not_null); |
| 4195 | __ mov(r0, Operand(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4196 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4197 | |
| 4198 | __ bind(&object_not_null); |
| 4199 | // Smi values are not instances of anything. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4200 | __ JumpIfNotSmi(object, &object_not_null_or_smi); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4201 | __ mov(r0, Operand(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4202 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4203 | |
| 4204 | __ bind(&object_not_null_or_smi); |
| 4205 | // String values are not instances of anything. |
| 4206 | __ IsObjectJSStringType(object, scratch, &slow); |
| 4207 | __ mov(r0, Operand(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4208 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4209 | |
| 4210 | // Slow-case. Tail call builtin. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4211 | __ bind(&slow); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4212 | if (!ReturnTrueFalseObject()) { |
| 4213 | if (HasArgsInRegisters()) { |
| 4214 | __ Push(r0, r1); |
| 4215 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4216 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4217 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4218 | { |
| 4219 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4220 | __ Push(r0, r1); |
| 4221 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 4222 | } |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4223 | __ cmp(r0, Operand::Zero()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4224 | __ LoadRoot(r0, Heap::kTrueValueRootIndex, eq); |
| 4225 | __ LoadRoot(r0, Heap::kFalseValueRootIndex, ne); |
| 4226 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
| 4227 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4228 | } |
| 4229 | |
| 4230 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 4231 | Register InstanceofStub::left() { return r0; } |
| 4232 | |
| 4233 | |
| 4234 | Register InstanceofStub::right() { return r1; } |
| 4235 | |
| 4236 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4237 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 4238 | // The displacement is the offset of the last parameter (if any) |
| 4239 | // relative to the frame pointer. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4240 | const int kDisplacement = |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4241 | StandardFrameConstants::kCallerSPOffset - kPointerSize; |
| 4242 | |
| 4243 | // Check that the key is a smi. |
| 4244 | Label slow; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4245 | __ JumpIfNotSmi(r1, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4246 | |
| 4247 | // Check if the calling frame is an arguments adaptor frame. |
| 4248 | Label adaptor; |
| 4249 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4250 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 4251 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4252 | __ b(eq, &adaptor); |
| 4253 | |
| 4254 | // Check index against formal parameters count limit passed in |
| 4255 | // through register r0. Use unsigned comparison to get negative |
| 4256 | // check for free. |
| 4257 | __ cmp(r1, r0); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4258 | __ b(hs, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4259 | |
| 4260 | // Read the argument from the stack and return it. |
| 4261 | __ sub(r3, r0, r1); |
| 4262 | __ add(r3, fp, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 4263 | __ ldr(r0, MemOperand(r3, kDisplacement)); |
| 4264 | __ Jump(lr); |
| 4265 | |
| 4266 | // Arguments adaptor case: Check index against actual arguments |
| 4267 | // limit found in the arguments adaptor frame. Use unsigned |
| 4268 | // comparison to get negative check for free. |
| 4269 | __ bind(&adaptor); |
| 4270 | __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4271 | __ cmp(r1, r0); |
| 4272 | __ b(cs, &slow); |
| 4273 | |
| 4274 | // Read the argument from the adaptor frame and return it. |
| 4275 | __ sub(r3, r0, r1); |
| 4276 | __ add(r3, r2, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 4277 | __ ldr(r0, MemOperand(r3, kDisplacement)); |
| 4278 | __ Jump(lr); |
| 4279 | |
| 4280 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 4281 | // by calling the runtime system. |
| 4282 | __ bind(&slow); |
| 4283 | __ push(r1); |
| 4284 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 4285 | } |
| 4286 | |
| 4287 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4288 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4289 | // sp[0] : number of parameters |
| 4290 | // sp[4] : receiver displacement |
| 4291 | // sp[8] : function |
| 4292 | |
| 4293 | // Check if the calling frame is an arguments adaptor frame. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4294 | Label runtime; |
| 4295 | __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4296 | __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset)); |
| 4297 | __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4298 | __ b(ne, &runtime); |
| 4299 | |
| 4300 | // Patch the arguments.length and the parameters pointer in the current frame. |
| 4301 | __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4302 | __ str(r2, MemOperand(sp, 0 * kPointerSize)); |
| 4303 | __ add(r3, r3, Operand(r2, LSL, 1)); |
| 4304 | __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 4305 | __ str(r3, MemOperand(sp, 1 * kPointerSize)); |
| 4306 | |
| 4307 | __ bind(&runtime); |
| 4308 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 4309 | } |
| 4310 | |
| 4311 | |
| 4312 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 4313 | // Stack layout: |
| 4314 | // sp[0] : number of parameters (tagged) |
| 4315 | // sp[4] : address of receiver argument |
| 4316 | // sp[8] : function |
| 4317 | // Registers used over whole function: |
| 4318 | // r6 : allocated object (tagged) |
| 4319 | // r9 : mapped parameter count (tagged) |
| 4320 | |
| 4321 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
| 4322 | // r1 = parameter count (tagged) |
| 4323 | |
| 4324 | // Check if the calling frame is an arguments adaptor frame. |
| 4325 | Label runtime; |
| 4326 | Label adaptor_frame, try_allocate; |
| 4327 | __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4328 | __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset)); |
| 4329 | __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4330 | __ b(eq, &adaptor_frame); |
| 4331 | |
| 4332 | // No adaptor, parameter count = argument count. |
| 4333 | __ mov(r2, r1); |
| 4334 | __ b(&try_allocate); |
| 4335 | |
| 4336 | // We have an adaptor frame. Patch the parameters pointer. |
| 4337 | __ bind(&adaptor_frame); |
| 4338 | __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4339 | __ add(r3, r3, Operand(r2, LSL, 1)); |
| 4340 | __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 4341 | __ str(r3, MemOperand(sp, 1 * kPointerSize)); |
| 4342 | |
| 4343 | // r1 = parameter count (tagged) |
| 4344 | // r2 = argument count (tagged) |
| 4345 | // Compute the mapped parameter count = min(r1, r2) in r1. |
| 4346 | __ cmp(r1, Operand(r2)); |
| 4347 | __ mov(r1, Operand(r2), LeaveCC, gt); |
| 4348 | |
| 4349 | __ bind(&try_allocate); |
| 4350 | |
| 4351 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 4352 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 4353 | const int kParameterMapHeaderSize = |
| 4354 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 4355 | // If there are no mapped parameters, we do not need the parameter_map. |
| 4356 | __ cmp(r1, Operand(Smi::FromInt(0))); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4357 | __ mov(r9, Operand::Zero(), LeaveCC, eq); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4358 | __ mov(r9, Operand(r1, LSL, 1), LeaveCC, ne); |
| 4359 | __ add(r9, r9, Operand(kParameterMapHeaderSize), LeaveCC, ne); |
| 4360 | |
| 4361 | // 2. Backing store. |
| 4362 | __ add(r9, r9, Operand(r2, LSL, 1)); |
| 4363 | __ add(r9, r9, Operand(FixedArray::kHeaderSize)); |
| 4364 | |
| 4365 | // 3. Arguments object. |
| 4366 | __ add(r9, r9, Operand(Heap::kArgumentsObjectSize)); |
| 4367 | |
| 4368 | // Do the allocation of all three objects in one go. |
| 4369 | __ AllocateInNewSpace(r9, r0, r3, r4, &runtime, TAG_OBJECT); |
| 4370 | |
| 4371 | // r0 = address of new object(s) (tagged) |
| 4372 | // r2 = argument count (tagged) |
| 4373 | // Get the arguments boilerplate from the current (global) context into r4. |
| 4374 | const int kNormalOffset = |
| 4375 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX); |
| 4376 | const int kAliasedOffset = |
| 4377 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX); |
| 4378 | |
| 4379 | __ ldr(r4, MemOperand(r8, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 4380 | __ ldr(r4, FieldMemOperand(r4, GlobalObject::kGlobalContextOffset)); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4381 | __ cmp(r1, Operand::Zero()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4382 | __ ldr(r4, MemOperand(r4, kNormalOffset), eq); |
| 4383 | __ ldr(r4, MemOperand(r4, kAliasedOffset), ne); |
| 4384 | |
| 4385 | // r0 = address of new object (tagged) |
| 4386 | // r1 = mapped parameter count (tagged) |
| 4387 | // r2 = argument count (tagged) |
| 4388 | // r4 = address of boilerplate object (tagged) |
| 4389 | // Copy the JS object part. |
| 4390 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 4391 | __ ldr(r3, FieldMemOperand(r4, i)); |
| 4392 | __ str(r3, FieldMemOperand(r0, i)); |
| 4393 | } |
| 4394 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4395 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4396 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 4397 | __ ldr(r3, MemOperand(sp, 2 * kPointerSize)); |
| 4398 | const int kCalleeOffset = JSObject::kHeaderSize + |
| 4399 | Heap::kArgumentsCalleeIndex * kPointerSize; |
| 4400 | __ str(r3, FieldMemOperand(r0, kCalleeOffset)); |
| 4401 | |
| 4402 | // Use the length (smi tagged) and set that as an in-object property too. |
| 4403 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 4404 | const int kLengthOffset = JSObject::kHeaderSize + |
| 4405 | Heap::kArgumentsLengthIndex * kPointerSize; |
| 4406 | __ str(r2, FieldMemOperand(r0, kLengthOffset)); |
| 4407 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4408 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4409 | // If we allocated a parameter map, r4 will point there, otherwise |
| 4410 | // it will point to the backing store. |
| 4411 | __ add(r4, r0, Operand(Heap::kArgumentsObjectSize)); |
| 4412 | __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 4413 | |
| 4414 | // r0 = address of new object (tagged) |
| 4415 | // r1 = mapped parameter count (tagged) |
| 4416 | // r2 = argument count (tagged) |
| 4417 | // r4 = address of parameter map or backing store (tagged) |
| 4418 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 4419 | Label skip_parameter_map; |
| 4420 | __ cmp(r1, Operand(Smi::FromInt(0))); |
| 4421 | // Move backing store address to r3, because it is |
| 4422 | // expected there when filling in the unmapped arguments. |
| 4423 | __ mov(r3, r4, LeaveCC, eq); |
| 4424 | __ b(eq, &skip_parameter_map); |
| 4425 | |
| 4426 | __ LoadRoot(r6, Heap::kNonStrictArgumentsElementsMapRootIndex); |
| 4427 | __ str(r6, FieldMemOperand(r4, FixedArray::kMapOffset)); |
| 4428 | __ add(r6, r1, Operand(Smi::FromInt(2))); |
| 4429 | __ str(r6, FieldMemOperand(r4, FixedArray::kLengthOffset)); |
| 4430 | __ str(r8, FieldMemOperand(r4, FixedArray::kHeaderSize + 0 * kPointerSize)); |
| 4431 | __ add(r6, r4, Operand(r1, LSL, 1)); |
| 4432 | __ add(r6, r6, Operand(kParameterMapHeaderSize)); |
| 4433 | __ str(r6, FieldMemOperand(r4, FixedArray::kHeaderSize + 1 * kPointerSize)); |
| 4434 | |
| 4435 | // Copy the parameter slots and the holes in the arguments. |
| 4436 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 4437 | // where parameters are stored in reverse order, at |
| 4438 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 4439 | // The mapped parameter thus need to get indices |
| 4440 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 4441 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 4442 | // We loop from right to left. |
| 4443 | Label parameters_loop, parameters_test; |
| 4444 | __ mov(r6, r1); |
| 4445 | __ ldr(r9, MemOperand(sp, 0 * kPointerSize)); |
| 4446 | __ add(r9, r9, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 4447 | __ sub(r9, r9, Operand(r1)); |
| 4448 | __ LoadRoot(r7, Heap::kTheHoleValueRootIndex); |
| 4449 | __ add(r3, r4, Operand(r6, LSL, 1)); |
| 4450 | __ add(r3, r3, Operand(kParameterMapHeaderSize)); |
| 4451 | |
| 4452 | // r6 = loop variable (tagged) |
| 4453 | // r1 = mapping index (tagged) |
| 4454 | // r3 = address of backing store (tagged) |
| 4455 | // r4 = address of parameter map (tagged) |
| 4456 | // r5 = temporary scratch (a.o., for address calculation) |
| 4457 | // r7 = the hole value |
| 4458 | __ jmp(¶meters_test); |
| 4459 | |
| 4460 | __ bind(¶meters_loop); |
| 4461 | __ sub(r6, r6, Operand(Smi::FromInt(1))); |
| 4462 | __ mov(r5, Operand(r6, LSL, 1)); |
| 4463 | __ add(r5, r5, Operand(kParameterMapHeaderSize - kHeapObjectTag)); |
| 4464 | __ str(r9, MemOperand(r4, r5)); |
| 4465 | __ sub(r5, r5, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize)); |
| 4466 | __ str(r7, MemOperand(r3, r5)); |
| 4467 | __ add(r9, r9, Operand(Smi::FromInt(1))); |
| 4468 | __ bind(¶meters_test); |
| 4469 | __ cmp(r6, Operand(Smi::FromInt(0))); |
| 4470 | __ b(ne, ¶meters_loop); |
| 4471 | |
| 4472 | __ bind(&skip_parameter_map); |
| 4473 | // r2 = argument count (tagged) |
| 4474 | // r3 = address of backing store (tagged) |
| 4475 | // r5 = scratch |
| 4476 | // Copy arguments header and remaining slots (if there are any). |
| 4477 | __ LoadRoot(r5, Heap::kFixedArrayMapRootIndex); |
| 4478 | __ str(r5, FieldMemOperand(r3, FixedArray::kMapOffset)); |
| 4479 | __ str(r2, FieldMemOperand(r3, FixedArray::kLengthOffset)); |
| 4480 | |
| 4481 | Label arguments_loop, arguments_test; |
| 4482 | __ mov(r9, r1); |
| 4483 | __ ldr(r4, MemOperand(sp, 1 * kPointerSize)); |
| 4484 | __ sub(r4, r4, Operand(r9, LSL, 1)); |
| 4485 | __ jmp(&arguments_test); |
| 4486 | |
| 4487 | __ bind(&arguments_loop); |
| 4488 | __ sub(r4, r4, Operand(kPointerSize)); |
| 4489 | __ ldr(r6, MemOperand(r4, 0)); |
| 4490 | __ add(r5, r3, Operand(r9, LSL, 1)); |
| 4491 | __ str(r6, FieldMemOperand(r5, FixedArray::kHeaderSize)); |
| 4492 | __ add(r9, r9, Operand(Smi::FromInt(1))); |
| 4493 | |
| 4494 | __ bind(&arguments_test); |
| 4495 | __ cmp(r9, Operand(r2)); |
| 4496 | __ b(lt, &arguments_loop); |
| 4497 | |
| 4498 | // Return and remove the on-stack parameters. |
| 4499 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 4500 | __ Ret(); |
| 4501 | |
| 4502 | // Do the runtime call to allocate the arguments object. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4503 | // r2 = argument count (tagged) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4504 | __ bind(&runtime); |
| 4505 | __ str(r2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count. |
| 4506 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 4507 | } |
| 4508 | |
| 4509 | |
| 4510 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 4511 | // sp[0] : number of parameters |
| 4512 | // sp[4] : receiver displacement |
| 4513 | // sp[8] : function |
| 4514 | // Check if the calling frame is an arguments adaptor frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4515 | Label adaptor_frame, try_allocate, runtime; |
| 4516 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4517 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 4518 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4519 | __ b(eq, &adaptor_frame); |
| 4520 | |
| 4521 | // Get the length from the frame. |
| 4522 | __ ldr(r1, MemOperand(sp, 0)); |
| 4523 | __ b(&try_allocate); |
| 4524 | |
| 4525 | // Patch the arguments.length and the parameters pointer. |
| 4526 | __ bind(&adaptor_frame); |
| 4527 | __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4528 | __ str(r1, MemOperand(sp, 0)); |
| 4529 | __ add(r3, r2, Operand(r1, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 4530 | __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 4531 | __ str(r3, MemOperand(sp, 1 * kPointerSize)); |
| 4532 | |
| 4533 | // Try the new space allocation. Start out with computing the size |
| 4534 | // of the arguments object and the elements array in words. |
| 4535 | Label add_arguments_object; |
| 4536 | __ bind(&try_allocate); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 4537 | __ cmp(r1, Operand(0, RelocInfo::NONE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4538 | __ b(eq, &add_arguments_object); |
| 4539 | __ mov(r1, Operand(r1, LSR, kSmiTagSize)); |
| 4540 | __ add(r1, r1, Operand(FixedArray::kHeaderSize / kPointerSize)); |
| 4541 | __ bind(&add_arguments_object); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4542 | __ add(r1, r1, Operand(Heap::kArgumentsObjectSizeStrict / kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4543 | |
| 4544 | // Do the allocation of both objects in one go. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4545 | __ AllocateInNewSpace(r1, |
| 4546 | r0, |
| 4547 | r2, |
| 4548 | r3, |
| 4549 | &runtime, |
| 4550 | static_cast<AllocationFlags>(TAG_OBJECT | |
| 4551 | SIZE_IN_WORDS)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4552 | |
| 4553 | // Get the arguments boilerplate from the current (global) context. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4554 | __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 4555 | __ ldr(r4, FieldMemOperand(r4, GlobalObject::kGlobalContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4556 | __ ldr(r4, MemOperand(r4, Context::SlotOffset( |
| 4557 | Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4558 | |
| 4559 | // Copy the JS object part. |
| 4560 | __ CopyFields(r0, r4, r3.bit(), JSObject::kHeaderSize / kPointerSize); |
| 4561 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4562 | // 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] | 4563 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4564 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4565 | __ str(r1, FieldMemOperand(r0, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4566 | Heap::kArgumentsLengthIndex * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4567 | |
| 4568 | // If there are no actual arguments, we're done. |
| 4569 | Label done; |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 4570 | __ cmp(r1, Operand(0, RelocInfo::NONE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4571 | __ b(eq, &done); |
| 4572 | |
| 4573 | // Get the parameters pointer from the stack. |
| 4574 | __ ldr(r2, MemOperand(sp, 1 * kPointerSize)); |
| 4575 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4576 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4577 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4578 | __ add(r4, r0, Operand(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4579 | __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 4580 | __ LoadRoot(r3, Heap::kFixedArrayMapRootIndex); |
| 4581 | __ str(r3, FieldMemOperand(r4, FixedArray::kMapOffset)); |
| 4582 | __ str(r1, FieldMemOperand(r4, FixedArray::kLengthOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4583 | // Untag the length for the loop. |
| 4584 | __ mov(r1, Operand(r1, LSR, kSmiTagSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4585 | |
| 4586 | // Copy the fixed array slots. |
| 4587 | Label loop; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4588 | // Set up r4 to point to the first array slot. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4589 | __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 4590 | __ bind(&loop); |
| 4591 | // Pre-decrement r2 with kPointerSize on each iteration. |
| 4592 | // Pre-decrement in order to skip receiver. |
| 4593 | __ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex)); |
| 4594 | // Post-increment r4 with kPointerSize on each iteration. |
| 4595 | __ str(r3, MemOperand(r4, kPointerSize, PostIndex)); |
| 4596 | __ sub(r1, r1, Operand(1)); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 4597 | __ cmp(r1, Operand(0, RelocInfo::NONE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4598 | __ b(ne, &loop); |
| 4599 | |
| 4600 | // Return and remove the on-stack parameters. |
| 4601 | __ bind(&done); |
| 4602 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 4603 | __ Ret(); |
| 4604 | |
| 4605 | // Do the runtime call to allocate the arguments object. |
| 4606 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4607 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4608 | } |
| 4609 | |
| 4610 | |
| 4611 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 4612 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 4613 | // time or if regexp entry in generated code is turned off runtime switch or |
| 4614 | // at compilation. |
| 4615 | #ifdef V8_INTERPRETED_REGEXP |
| 4616 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4617 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4618 | |
| 4619 | // Stack frame on entry. |
| 4620 | // sp[0]: last_match_info (expected JSArray) |
| 4621 | // sp[4]: previous index |
| 4622 | // sp[8]: subject string |
| 4623 | // sp[12]: JSRegExp object |
| 4624 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4625 | const int kLastMatchInfoOffset = 0 * kPointerSize; |
| 4626 | const int kPreviousIndexOffset = 1 * kPointerSize; |
| 4627 | const int kSubjectOffset = 2 * kPointerSize; |
| 4628 | const int kJSRegExpOffset = 3 * kPointerSize; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4629 | |
| 4630 | Label runtime, invoke_regexp; |
| 4631 | |
| 4632 | // Allocation of registers for this function. These are in callee save |
| 4633 | // registers and will be preserved by the call to the native RegExp code, as |
| 4634 | // this code is called using the normal C calling convention. When calling |
| 4635 | // directly from generated code the native RegExp code will not do a GC and |
| 4636 | // therefore the content of these registers are safe to use after the call. |
| 4637 | Register subject = r4; |
| 4638 | Register regexp_data = r5; |
| 4639 | Register last_match_info_elements = r6; |
| 4640 | |
| 4641 | // Ensure that a RegExp stack is allocated. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4642 | Isolate* isolate = masm->isolate(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4643 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4644 | ExternalReference::address_of_regexp_stack_memory_address(isolate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4645 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4646 | ExternalReference::address_of_regexp_stack_memory_size(isolate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4647 | __ mov(r0, Operand(address_of_regexp_stack_memory_size)); |
| 4648 | __ ldr(r0, MemOperand(r0, 0)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4649 | __ cmp(r0, Operand(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4650 | __ b(eq, &runtime); |
| 4651 | |
| 4652 | // Check that the first argument is a JSRegExp object. |
| 4653 | __ ldr(r0, MemOperand(sp, kJSRegExpOffset)); |
| 4654 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4655 | __ JumpIfSmi(r0, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4656 | __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE); |
| 4657 | __ b(ne, &runtime); |
| 4658 | |
| 4659 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 4660 | __ ldr(regexp_data, FieldMemOperand(r0, JSRegExp::kDataOffset)); |
| 4661 | if (FLAG_debug_code) { |
| 4662 | __ tst(regexp_data, Operand(kSmiTagMask)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4663 | __ Check(ne, "Unexpected type for RegExp data, FixedArray expected"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4664 | __ CompareObjectType(regexp_data, r0, r0, FIXED_ARRAY_TYPE); |
| 4665 | __ Check(eq, "Unexpected type for RegExp data, FixedArray expected"); |
| 4666 | } |
| 4667 | |
| 4668 | // regexp_data: RegExp data (FixedArray) |
| 4669 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 4670 | __ ldr(r0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset)); |
| 4671 | __ cmp(r0, Operand(Smi::FromInt(JSRegExp::IRREGEXP))); |
| 4672 | __ b(ne, &runtime); |
| 4673 | |
| 4674 | // regexp_data: RegExp data (FixedArray) |
| 4675 | // Check that the number of captures fit in the static offsets vector buffer. |
| 4676 | __ ldr(r2, |
| 4677 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 4678 | // Calculate number of capture registers (number_of_captures + 1) * 2. This |
| 4679 | // uses the asumption that smis are 2 * their untagged value. |
| 4680 | STATIC_ASSERT(kSmiTag == 0); |
| 4681 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 4682 | __ add(r2, r2, Operand(2)); // r2 was a smi. |
| 4683 | // Check that the static offsets vector buffer is large enough. |
| 4684 | __ cmp(r2, Operand(OffsetsVector::kStaticOffsetsVectorSize)); |
| 4685 | __ b(hi, &runtime); |
| 4686 | |
| 4687 | // r2: Number of capture registers |
| 4688 | // regexp_data: RegExp data (FixedArray) |
| 4689 | // Check that the second argument is a string. |
| 4690 | __ ldr(subject, MemOperand(sp, kSubjectOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4691 | __ JumpIfSmi(subject, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4692 | Condition is_string = masm->IsObjectStringType(subject, r0); |
| 4693 | __ b(NegateCondition(is_string), &runtime); |
| 4694 | // Get the length of the string to r3. |
| 4695 | __ ldr(r3, FieldMemOperand(subject, String::kLengthOffset)); |
| 4696 | |
| 4697 | // r2: Number of capture registers |
| 4698 | // r3: Length of subject string as a smi |
| 4699 | // subject: Subject string |
| 4700 | // regexp_data: RegExp data (FixedArray) |
| 4701 | // Check that the third argument is a positive smi less than the subject |
| 4702 | // string length. A negative value will be greater (unsigned comparison). |
| 4703 | __ ldr(r0, MemOperand(sp, kPreviousIndexOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4704 | __ JumpIfNotSmi(r0, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4705 | __ cmp(r3, Operand(r0)); |
| 4706 | __ b(ls, &runtime); |
| 4707 | |
| 4708 | // r2: Number of capture registers |
| 4709 | // subject: Subject string |
| 4710 | // regexp_data: RegExp data (FixedArray) |
| 4711 | // Check that the fourth object is a JSArray object. |
| 4712 | __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4713 | __ JumpIfSmi(r0, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4714 | __ CompareObjectType(r0, r1, r1, JS_ARRAY_TYPE); |
| 4715 | __ b(ne, &runtime); |
| 4716 | // Check that the JSArray is in fast case. |
| 4717 | __ ldr(last_match_info_elements, |
| 4718 | FieldMemOperand(r0, JSArray::kElementsOffset)); |
| 4719 | __ ldr(r0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4720 | __ CompareRoot(r0, Heap::kFixedArrayMapRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4721 | __ b(ne, &runtime); |
| 4722 | // Check that the last match info has space for the capture registers and the |
| 4723 | // additional information. |
| 4724 | __ ldr(r0, |
| 4725 | FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset)); |
| 4726 | __ add(r2, r2, Operand(RegExpImpl::kLastMatchOverhead)); |
| 4727 | __ cmp(r2, Operand(r0, ASR, kSmiTagSize)); |
| 4728 | __ b(gt, &runtime); |
| 4729 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4730 | // Reset offset for possibly sliced string. |
| 4731 | __ mov(r9, Operand(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4732 | // subject: Subject string |
| 4733 | // regexp_data: RegExp data (FixedArray) |
| 4734 | // Check the representation and encoding of the subject string. |
| 4735 | Label seq_string; |
| 4736 | __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 4737 | __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4738 | // First check for flat string. None of the following string type tests will |
| 4739 | // succeed if subject is not a string or a short external string. |
| 4740 | __ and_(r1, |
| 4741 | r0, |
| 4742 | Operand(kIsNotStringMask | |
| 4743 | kStringRepresentationMask | |
| 4744 | kShortExternalStringMask), |
| 4745 | SetCC); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4746 | STATIC_ASSERT((kStringTag | kSeqStringTag) == 0); |
| 4747 | __ b(eq, &seq_string); |
| 4748 | |
| 4749 | // subject: Subject string |
| 4750 | // regexp_data: RegExp data (FixedArray) |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4751 | // 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] | 4752 | // Check for flat cons string or sliced string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4753 | // A flat cons string is a cons string where the second part is the empty |
| 4754 | // string. In that case the subject string is just the first part of the cons |
| 4755 | // string. Also in this case the first part of the cons string is known to be |
| 4756 | // a sequential string or an external string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4757 | // 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] | 4758 | Label cons_string, external_string, check_encoding; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4759 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 4760 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4761 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 4762 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4763 | __ cmp(r1, Operand(kExternalStringTag)); |
| 4764 | __ b(lt, &cons_string); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4765 | __ b(eq, &external_string); |
| 4766 | |
| 4767 | // Catch non-string subject or short external string. |
| 4768 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 4769 | __ tst(r1, Operand(kIsNotStringMask | kShortExternalStringMask)); |
| 4770 | __ b(ne, &runtime); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4771 | |
| 4772 | // String is sliced. |
| 4773 | __ ldr(r9, FieldMemOperand(subject, SlicedString::kOffsetOffset)); |
| 4774 | __ mov(r9, Operand(r9, ASR, kSmiTagSize)); |
| 4775 | __ ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset)); |
| 4776 | // r9: offset of sliced string, smi-tagged. |
| 4777 | __ jmp(&check_encoding); |
| 4778 | // String is a cons string, check whether it is flat. |
| 4779 | __ bind(&cons_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4780 | __ ldr(r0, FieldMemOperand(subject, ConsString::kSecondOffset)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4781 | __ CompareRoot(r0, Heap::kEmptyStringRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4782 | __ b(ne, &runtime); |
| 4783 | __ ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4784 | // Is first part of cons or parent of slice a flat string? |
| 4785 | __ bind(&check_encoding); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4786 | __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 4787 | __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4788 | STATIC_ASSERT(kSeqStringTag == 0); |
| 4789 | __ tst(r0, Operand(kStringRepresentationMask)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4790 | __ b(ne, &external_string); |
| 4791 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4792 | __ bind(&seq_string); |
| 4793 | // subject: Subject string |
| 4794 | // regexp_data: RegExp data (FixedArray) |
| 4795 | // r0: Instance type of subject string |
| 4796 | STATIC_ASSERT(4 == kAsciiStringTag); |
| 4797 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 4798 | // Find the code object based on the assumptions above. |
| 4799 | __ and_(r0, r0, Operand(kStringEncodingMask)); |
| 4800 | __ mov(r3, Operand(r0, ASR, 2), SetCC); |
| 4801 | __ ldr(r7, FieldMemOperand(regexp_data, JSRegExp::kDataAsciiCodeOffset), ne); |
| 4802 | __ ldr(r7, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset), eq); |
| 4803 | |
| 4804 | // Check that the irregexp code has been generated for the actual string |
| 4805 | // 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] | 4806 | // a smi (code flushing support). |
| 4807 | __ JumpIfSmi(r7, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4808 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4809 | // 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] | 4810 | // r7: code |
| 4811 | // subject: Subject string |
| 4812 | // regexp_data: RegExp data (FixedArray) |
| 4813 | // Load used arguments before starting to push arguments for call to native |
| 4814 | // RegExp code to avoid handling changing stack height. |
| 4815 | __ ldr(r1, MemOperand(sp, kPreviousIndexOffset)); |
| 4816 | __ mov(r1, Operand(r1, ASR, kSmiTagSize)); |
| 4817 | |
| 4818 | // r1: previous index |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4819 | // 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] | 4820 | // r7: code |
| 4821 | // subject: Subject string |
| 4822 | // regexp_data: RegExp data (FixedArray) |
| 4823 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4824 | __ IncrementCounter(isolate->counters()->regexp_entry_native(), 1, r0, r2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4825 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4826 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4827 | const int kRegExpExecuteArguments = 9; |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4828 | const int kParameterRegisters = 4; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4829 | __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4830 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4831 | // Stack pointer now points to cell where return address is to be written. |
| 4832 | // Arguments are before that on the stack or in registers. |
| 4833 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4834 | // Argument 9 (sp[20]): Pass current isolate address. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4835 | __ mov(r0, Operand(ExternalReference::isolate_address())); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4836 | __ str(r0, MemOperand(sp, 5 * kPointerSize)); |
| 4837 | |
| 4838 | // Argument 8 (sp[16]): Indicate that this is a direct call from JavaScript. |
| 4839 | __ mov(r0, Operand(1)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4840 | __ str(r0, MemOperand(sp, 4 * kPointerSize)); |
| 4841 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4842 | // 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] | 4843 | __ mov(r0, Operand(address_of_regexp_stack_memory_address)); |
| 4844 | __ ldr(r0, MemOperand(r0, 0)); |
| 4845 | __ mov(r2, Operand(address_of_regexp_stack_memory_size)); |
| 4846 | __ ldr(r2, MemOperand(r2, 0)); |
| 4847 | __ add(r0, r0, Operand(r2)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4848 | __ str(r0, MemOperand(sp, 3 * kPointerSize)); |
| 4849 | |
| 4850 | // Argument 6: Set the number of capture registers to zero to force global |
| 4851 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 4852 | __ mov(r0, Operand(0)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4853 | __ str(r0, MemOperand(sp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4854 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4855 | // Argument 5 (sp[4]): static offsets vector buffer. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4856 | __ mov(r0, |
| 4857 | Operand(ExternalReference::address_of_static_offsets_vector(isolate))); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4858 | __ str(r0, MemOperand(sp, 1 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4859 | |
| 4860 | // For arguments 4 and 3 get string length, calculate start of string data and |
| 4861 | // 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] | 4862 | __ add(r8, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4863 | __ eor(r3, r3, Operand(1)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4864 | // Load the length from the original subject string from the previous stack |
| 4865 | // frame. Therefore we have to use fp, which points exactly to two pointer |
| 4866 | // sizes below the previous sp. (Because creating a new stack frame pushes |
| 4867 | // 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] | 4868 | __ ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4869 | // If slice offset is not 0, load the length from the original sliced string. |
| 4870 | // Argument 4, r3: End of string data |
| 4871 | // Argument 3, r2: Start of string data |
| 4872 | // Prepare start and end index of the input. |
| 4873 | __ add(r9, r8, Operand(r9, LSL, r3)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4874 | __ add(r2, r9, Operand(r1, LSL, r3)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4875 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4876 | __ ldr(r8, FieldMemOperand(subject, String::kLengthOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4877 | __ mov(r8, Operand(r8, ASR, kSmiTagSize)); |
| 4878 | __ add(r3, r9, Operand(r8, LSL, r3)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4879 | |
| 4880 | // Argument 2 (r1): Previous index. |
| 4881 | // Already there |
| 4882 | |
| 4883 | // Argument 1 (r0): Subject string. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4884 | __ mov(r0, subject); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4885 | |
| 4886 | // Locate the code entry and call it. |
| 4887 | __ add(r7, r7, Operand(Code::kHeaderSize - kHeapObjectTag)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4888 | DirectCEntryStub stub; |
| 4889 | stub.GenerateCall(masm, r7); |
| 4890 | |
| 4891 | __ LeaveExitFrame(false, no_reg); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4892 | |
| 4893 | // r0: result |
| 4894 | // subject: subject string (callee saved) |
| 4895 | // regexp_data: RegExp data (callee saved) |
| 4896 | // last_match_info_elements: Last match info elements (callee saved) |
| 4897 | |
| 4898 | // Check the result. |
| 4899 | Label success; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4900 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 4901 | __ cmp(r0, Operand(1)); |
| 4902 | // We expect exactly one result since we force the called regexp to behave |
| 4903 | // as non-global. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4904 | __ b(eq, &success); |
| 4905 | Label failure; |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4906 | __ cmp(r0, Operand(NativeRegExpMacroAssembler::FAILURE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4907 | __ b(eq, &failure); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4908 | __ cmp(r0, Operand(NativeRegExpMacroAssembler::EXCEPTION)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4909 | // If not exception it can only be retry. Handle that in the runtime system. |
| 4910 | __ b(ne, &runtime); |
| 4911 | // Result must now be exception. If there is no pending exception already a |
| 4912 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 4913 | // haven't created the exception yet. Handle that in the runtime system. |
| 4914 | // 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] | 4915 | __ mov(r1, Operand(isolate->factory()->the_hole_value())); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4916 | __ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4917 | isolate))); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4918 | __ ldr(r0, MemOperand(r2, 0)); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4919 | __ cmp(r0, r1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4920 | __ b(eq, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4921 | |
| 4922 | __ str(r1, MemOperand(r2, 0)); // Clear pending exception. |
| 4923 | |
| 4924 | // 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] | 4925 | __ CompareRoot(r0, Heap::kTerminationExceptionRootIndex); |
| 4926 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4927 | Label termination_exception; |
| 4928 | __ b(eq, &termination_exception); |
| 4929 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4930 | __ Throw(r0); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4931 | |
| 4932 | __ bind(&termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4933 | __ ThrowUncatchable(r0); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4934 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4935 | __ bind(&failure); |
| 4936 | // For failure and exception return null. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4937 | __ mov(r0, Operand(masm->isolate()->factory()->null_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4938 | __ add(sp, sp, Operand(4 * kPointerSize)); |
| 4939 | __ Ret(); |
| 4940 | |
| 4941 | // Process the result from the native regexp code. |
| 4942 | __ bind(&success); |
| 4943 | __ ldr(r1, |
| 4944 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 4945 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 4946 | STATIC_ASSERT(kSmiTag == 0); |
| 4947 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 4948 | __ add(r1, r1, Operand(2)); // r1 was a smi. |
| 4949 | |
| 4950 | // r1: number of capture registers |
| 4951 | // r4: subject string |
| 4952 | // Store the capture count. |
| 4953 | __ mov(r2, Operand(r1, LSL, kSmiTagSize + kSmiShiftSize)); // To smi. |
| 4954 | __ str(r2, FieldMemOperand(last_match_info_elements, |
| 4955 | RegExpImpl::kLastCaptureCountOffset)); |
| 4956 | // Store last subject and last input. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4957 | __ str(subject, |
| 4958 | FieldMemOperand(last_match_info_elements, |
| 4959 | RegExpImpl::kLastSubjectOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4960 | __ mov(r2, subject); |
| 4961 | __ RecordWriteField(last_match_info_elements, |
| 4962 | RegExpImpl::kLastSubjectOffset, |
| 4963 | r2, |
| 4964 | r7, |
| 4965 | kLRHasNotBeenSaved, |
| 4966 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4967 | __ str(subject, |
| 4968 | FieldMemOperand(last_match_info_elements, |
| 4969 | RegExpImpl::kLastInputOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4970 | __ RecordWriteField(last_match_info_elements, |
| 4971 | RegExpImpl::kLastInputOffset, |
| 4972 | subject, |
| 4973 | r7, |
| 4974 | kLRHasNotBeenSaved, |
| 4975 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4976 | |
| 4977 | // Get the static offsets vector filled by the native regexp code. |
| 4978 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4979 | ExternalReference::address_of_static_offsets_vector(isolate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4980 | __ mov(r2, Operand(address_of_static_offsets_vector)); |
| 4981 | |
| 4982 | // r1: number of capture registers |
| 4983 | // r2: offsets vector |
| 4984 | Label next_capture, done; |
| 4985 | // Capture register counter starts from number of capture registers and |
| 4986 | // counts down until wraping after zero. |
| 4987 | __ add(r0, |
| 4988 | last_match_info_elements, |
| 4989 | Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag)); |
| 4990 | __ bind(&next_capture); |
| 4991 | __ sub(r1, r1, Operand(1), SetCC); |
| 4992 | __ b(mi, &done); |
| 4993 | // Read the value from the static offsets vector buffer. |
| 4994 | __ ldr(r3, MemOperand(r2, kPointerSize, PostIndex)); |
| 4995 | // Store the smi value in the last match info. |
| 4996 | __ mov(r3, Operand(r3, LSL, kSmiTagSize)); |
| 4997 | __ str(r3, MemOperand(r0, kPointerSize, PostIndex)); |
| 4998 | __ jmp(&next_capture); |
| 4999 | __ bind(&done); |
| 5000 | |
| 5001 | // Return last match info. |
| 5002 | __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset)); |
| 5003 | __ add(sp, sp, Operand(4 * kPointerSize)); |
| 5004 | __ Ret(); |
| 5005 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5006 | // External string. Short external strings have already been ruled out. |
| 5007 | // r0: scratch |
| 5008 | __ bind(&external_string); |
| 5009 | __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 5010 | __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset)); |
| 5011 | if (FLAG_debug_code) { |
| 5012 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 5013 | // Sequential strings have already been ruled out. |
| 5014 | __ tst(r0, Operand(kIsIndirectStringMask)); |
| 5015 | __ Assert(eq, "external string expected, but not found"); |
| 5016 | } |
| 5017 | __ ldr(subject, |
| 5018 | FieldMemOperand(subject, ExternalString::kResourceDataOffset)); |
| 5019 | // Move the pointer so that offset-wise, it looks like a sequential string. |
| 5020 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); |
| 5021 | __ sub(subject, |
| 5022 | subject, |
| 5023 | Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5024 | __ jmp(&seq_string); |
| 5025 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5026 | // Do the runtime call to execute the regexp. |
| 5027 | __ bind(&runtime); |
| 5028 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 5029 | #endif // V8_INTERPRETED_REGEXP |
| 5030 | } |
| 5031 | |
| 5032 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5033 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 5034 | const int kMaxInlineLength = 100; |
| 5035 | Label slowcase; |
| 5036 | Label done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 5037 | Factory* factory = masm->isolate()->factory(); |
| 5038 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5039 | __ ldr(r1, MemOperand(sp, kPointerSize * 2)); |
| 5040 | STATIC_ASSERT(kSmiTag == 0); |
| 5041 | STATIC_ASSERT(kSmiTagSize == 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5042 | __ JumpIfNotSmi(r1, &slowcase); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5043 | __ cmp(r1, Operand(Smi::FromInt(kMaxInlineLength))); |
| 5044 | __ b(hi, &slowcase); |
| 5045 | // Smi-tagging is equivalent to multiplying by 2. |
| 5046 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 5047 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 5048 | // Elements: [Map][Length][..elements..] |
| 5049 | // Size of JSArray with two in-object properties and the header of a |
| 5050 | // FixedArray. |
| 5051 | int objects_size = |
| 5052 | (JSRegExpResult::kSize + FixedArray::kHeaderSize) / kPointerSize; |
| 5053 | __ mov(r5, Operand(r1, LSR, kSmiTagSize + kSmiShiftSize)); |
| 5054 | __ add(r2, r5, Operand(objects_size)); |
| 5055 | __ AllocateInNewSpace( |
| 5056 | r2, // In: Size, in words. |
| 5057 | r0, // Out: Start of allocation (tagged). |
| 5058 | r3, // Scratch register. |
| 5059 | r4, // Scratch register. |
| 5060 | &slowcase, |
| 5061 | static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS)); |
| 5062 | // r0: Start of allocated area, object-tagged. |
| 5063 | // r1: Number of elements in array, as smi. |
| 5064 | // r5: Number of elements, untagged. |
| 5065 | |
| 5066 | // Set JSArray map to global.regexp_result_map(). |
| 5067 | // Set empty properties FixedArray. |
| 5068 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 5069 | // Interleave operations for better latency. |
| 5070 | __ ldr(r2, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 5071 | __ add(r3, r0, Operand(JSRegExpResult::kSize)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 5072 | __ mov(r4, Operand(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5073 | __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalContextOffset)); |
| 5074 | __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 5075 | __ ldr(r2, ContextOperand(r2, Context::REGEXP_RESULT_MAP_INDEX)); |
| 5076 | __ str(r4, FieldMemOperand(r0, JSObject::kPropertiesOffset)); |
| 5077 | __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5078 | |
| 5079 | // Set input, index and length fields from arguments. |
| 5080 | __ ldr(r1, MemOperand(sp, kPointerSize * 0)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5081 | __ ldr(r2, MemOperand(sp, kPointerSize * 1)); |
| 5082 | __ ldr(r6, MemOperand(sp, kPointerSize * 2)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5083 | __ str(r1, FieldMemOperand(r0, JSRegExpResult::kInputOffset)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5084 | __ str(r2, FieldMemOperand(r0, JSRegExpResult::kIndexOffset)); |
| 5085 | __ str(r6, FieldMemOperand(r0, JSArray::kLengthOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5086 | |
| 5087 | // Fill out the elements FixedArray. |
| 5088 | // r0: JSArray, tagged. |
| 5089 | // r3: FixedArray, tagged. |
| 5090 | // r5: Number of elements in array, untagged. |
| 5091 | |
| 5092 | // Set map. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 5093 | __ mov(r2, Operand(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5094 | __ str(r2, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 5095 | // Set FixedArray length. |
| 5096 | __ mov(r6, Operand(r5, LSL, kSmiTagSize)); |
| 5097 | __ str(r6, FieldMemOperand(r3, FixedArray::kLengthOffset)); |
| 5098 | // Fill contents of fixed-array with the-hole. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 5099 | __ mov(r2, Operand(factory->the_hole_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5100 | __ add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5101 | // Fill fixed array elements with hole. |
| 5102 | // r0: JSArray, tagged. |
| 5103 | // r2: the hole. |
| 5104 | // r3: Start of elements in FixedArray. |
| 5105 | // r5: Number of elements to fill. |
| 5106 | Label loop; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5107 | __ cmp(r5, Operand(0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5108 | __ bind(&loop); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5109 | __ b(le, &done); // Jump if r5 is negative or zero. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5110 | __ sub(r5, r5, Operand(1), SetCC); |
| 5111 | __ str(r2, MemOperand(r3, r5, LSL, kPointerSizeLog2)); |
| 5112 | __ jmp(&loop); |
| 5113 | |
| 5114 | __ bind(&done); |
| 5115 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 5116 | __ Ret(); |
| 5117 | |
| 5118 | __ bind(&slowcase); |
| 5119 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 5120 | } |
| 5121 | |
| 5122 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5123 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 5124 | // Cache the called function in a global property cell. Cache states |
| 5125 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 5126 | // megamorphic. |
| 5127 | // r1 : the function to call |
| 5128 | // r2 : cache cell for call target |
| 5129 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5130 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5131 | ASSERT_EQ(*TypeFeedbackCells::MegamorphicSentinel(masm->isolate()), |
| 5132 | masm->isolate()->heap()->undefined_value()); |
| 5133 | ASSERT_EQ(*TypeFeedbackCells::UninitializedSentinel(masm->isolate()), |
| 5134 | masm->isolate()->heap()->the_hole_value()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5135 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5136 | // Load the cache state into r3. |
| 5137 | __ ldr(r3, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5138 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5139 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 5140 | // function without changing the state. |
| 5141 | __ cmp(r3, r1); |
| 5142 | __ b(eq, &done); |
| 5143 | __ CompareRoot(r3, Heap::kUndefinedValueRootIndex); |
| 5144 | __ b(eq, &done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5145 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5146 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 5147 | // megamorphic. |
| 5148 | __ CompareRoot(r3, Heap::kTheHoleValueRootIndex); |
| 5149 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 5150 | // write-barrier is needed. |
| 5151 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex, ne); |
| 5152 | __ str(ip, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset), ne); |
| 5153 | |
| 5154 | // An uninitialized cache is patched with the function. |
| 5155 | __ str(r1, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset), eq); |
| 5156 | // No need for a write barrier here - cells are rescanned. |
| 5157 | |
| 5158 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5159 | } |
| 5160 | |
| 5161 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5162 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5163 | // r1 : the function to call |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5164 | // r2 : cache cell for call target |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5165 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5166 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5167 | // The receiver might implicitly be the global object. This is |
| 5168 | // indicated by passing the hole as the receiver to the call |
| 5169 | // function stub. |
| 5170 | if (ReceiverMightBeImplicit()) { |
| 5171 | Label call; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5172 | // Get the receiver from the stack. |
| 5173 | // function, receiver [, arguments] |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5174 | __ ldr(r4, MemOperand(sp, argc_ * kPointerSize)); |
| 5175 | // Call as function is indicated with the hole. |
| 5176 | __ CompareRoot(r4, Heap::kTheHoleValueRootIndex); |
| 5177 | __ b(ne, &call); |
| 5178 | // Patch the receiver on the stack with the global receiver object. |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 5179 | __ ldr(r3, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 5180 | __ ldr(r3, FieldMemOperand(r3, GlobalObject::kGlobalReceiverOffset)); |
| 5181 | __ str(r3, MemOperand(sp, argc_ * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5182 | __ bind(&call); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5183 | } |
| 5184 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5185 | // Check that the function is really a JavaScript function. |
| 5186 | // r1: pushed function (to be verified) |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5187 | __ JumpIfSmi(r1, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5188 | // Get the map of the function object. |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 5189 | __ CompareObjectType(r1, r3, r3, JS_FUNCTION_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5190 | __ b(ne, &slow); |
| 5191 | |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 5192 | if (RecordCallTarget()) { |
| 5193 | GenerateRecordCallTarget(masm); |
| 5194 | } |
| 5195 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5196 | // Fast-case: Invoke the function now. |
| 5197 | // r1: pushed function |
| 5198 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5199 | |
| 5200 | if (ReceiverMightBeImplicit()) { |
| 5201 | Label call_as_function; |
| 5202 | __ CompareRoot(r4, Heap::kTheHoleValueRootIndex); |
| 5203 | __ b(eq, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5204 | __ InvokeFunction(r1, |
| 5205 | actual, |
| 5206 | JUMP_FUNCTION, |
| 5207 | NullCallWrapper(), |
| 5208 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5209 | __ bind(&call_as_function); |
| 5210 | } |
| 5211 | __ InvokeFunction(r1, |
| 5212 | actual, |
| 5213 | JUMP_FUNCTION, |
| 5214 | NullCallWrapper(), |
| 5215 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5216 | |
| 5217 | // Slow-case: Non-function called. |
| 5218 | __ bind(&slow); |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 5219 | if (RecordCallTarget()) { |
| 5220 | // If there is a call target cache, mark it megamorphic in the |
| 5221 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 5222 | // object (undefined) so no write barrier is needed. |
| 5223 | ASSERT_EQ(*TypeFeedbackCells::MegamorphicSentinel(masm->isolate()), |
| 5224 | masm->isolate()->heap()->undefined_value()); |
| 5225 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 5226 | __ str(ip, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset)); |
| 5227 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5228 | // Check for function proxy. |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 5229 | __ cmp(r3, Operand(JS_FUNCTION_PROXY_TYPE)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5230 | __ b(ne, &non_function); |
| 5231 | __ push(r1); // put proxy as additional argument |
| 5232 | __ mov(r0, Operand(argc_ + 1, RelocInfo::NONE)); |
| 5233 | __ mov(r2, Operand(0, RelocInfo::NONE)); |
| 5234 | __ GetBuiltinEntry(r3, Builtins::CALL_FUNCTION_PROXY); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5235 | __ SetCallKind(r5, CALL_AS_METHOD); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5236 | { |
| 5237 | Handle<Code> adaptor = |
| 5238 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 5239 | __ Jump(adaptor, RelocInfo::CODE_TARGET); |
| 5240 | } |
| 5241 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5242 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 5243 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5244 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5245 | __ str(r1, MemOperand(sp, argc_ * kPointerSize)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5246 | __ mov(r0, Operand(argc_)); // Set up the number of arguments. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 5247 | __ mov(r2, Operand(0, RelocInfo::NONE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5248 | __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 5249 | __ SetCallKind(r5, CALL_AS_METHOD); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5250 | __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5251 | RelocInfo::CODE_TARGET); |
| 5252 | } |
| 5253 | |
| 5254 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5255 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 5256 | // r0 : number of arguments |
| 5257 | // r1 : the function to call |
| 5258 | // r2 : cache cell for call target |
| 5259 | Label slow, non_function_call; |
| 5260 | |
| 5261 | // Check that the function is not a smi. |
| 5262 | __ JumpIfSmi(r1, &non_function_call); |
| 5263 | // Check that the function is a JSFunction. |
| 5264 | __ CompareObjectType(r1, r3, r3, JS_FUNCTION_TYPE); |
| 5265 | __ b(ne, &slow); |
| 5266 | |
| 5267 | if (RecordCallTarget()) { |
| 5268 | GenerateRecordCallTarget(masm); |
| 5269 | } |
| 5270 | |
| 5271 | // Jump to the function-specific construct stub. |
| 5272 | __ ldr(r2, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 5273 | __ ldr(r2, FieldMemOperand(r2, SharedFunctionInfo::kConstructStubOffset)); |
| 5274 | __ add(pc, r2, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 5275 | |
| 5276 | // r0: number of arguments |
| 5277 | // r1: called object |
| 5278 | // r3: object type |
| 5279 | Label do_call; |
| 5280 | __ bind(&slow); |
| 5281 | __ cmp(r3, Operand(JS_FUNCTION_PROXY_TYPE)); |
| 5282 | __ b(ne, &non_function_call); |
| 5283 | __ GetBuiltinEntry(r3, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 5284 | __ jmp(&do_call); |
| 5285 | |
| 5286 | __ bind(&non_function_call); |
| 5287 | __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 5288 | __ bind(&do_call); |
| 5289 | // Set expected number of arguments to zero (not changing r0). |
| 5290 | __ mov(r2, Operand(0, RelocInfo::NONE)); |
| 5291 | __ SetCallKind(r5, CALL_AS_METHOD); |
| 5292 | __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 5293 | RelocInfo::CODE_TARGET); |
| 5294 | } |
| 5295 | |
| 5296 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5297 | // Unfortunately you have to run without snapshots to see most of these |
| 5298 | // names in the profile since most compare stubs end up in the snapshot. |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 5299 | void CompareStub::PrintName(StringStream* stream) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5300 | ASSERT((lhs_.is(r0) && rhs_.is(r1)) || |
| 5301 | (lhs_.is(r1) && rhs_.is(r0))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5302 | const char* cc_name; |
| 5303 | switch (cc_) { |
| 5304 | case lt: cc_name = "LT"; break; |
| 5305 | case gt: cc_name = "GT"; break; |
| 5306 | case le: cc_name = "LE"; break; |
| 5307 | case ge: cc_name = "GE"; break; |
| 5308 | case eq: cc_name = "EQ"; break; |
| 5309 | case ne: cc_name = "NE"; break; |
| 5310 | default: cc_name = "UnknownCondition"; break; |
| 5311 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 5312 | bool is_equality = cc_ == eq || cc_ == ne; |
| 5313 | stream->Add("CompareStub_%s", cc_name); |
| 5314 | stream->Add(lhs_.is(r0) ? "_r0" : "_r1"); |
| 5315 | stream->Add(rhs_.is(r0) ? "_r0" : "_r1"); |
| 5316 | if (strict_ && is_equality) stream->Add("_STRICT"); |
| 5317 | if (never_nan_nan_ && is_equality) stream->Add("_NO_NAN"); |
| 5318 | if (!include_number_compare_) stream->Add("_NO_NUMBER"); |
| 5319 | if (!include_smi_compare_) stream->Add("_NO_SMI"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5320 | } |
| 5321 | |
| 5322 | |
| 5323 | int CompareStub::MinorKey() { |
| 5324 | // Encode the three parameters in a unique 16 bit value. To avoid duplicate |
| 5325 | // stubs the never NaN NaN condition is only taken into account if the |
| 5326 | // condition is equals. |
| 5327 | ASSERT((static_cast<unsigned>(cc_) >> 28) < (1 << 12)); |
| 5328 | ASSERT((lhs_.is(r0) && rhs_.is(r1)) || |
| 5329 | (lhs_.is(r1) && rhs_.is(r0))); |
| 5330 | return ConditionField::encode(static_cast<unsigned>(cc_) >> 28) |
| 5331 | | RegisterField::encode(lhs_.is(r0)) |
| 5332 | | StrictField::encode(strict_) |
| 5333 | | NeverNanNanField::encode(cc_ == eq ? never_nan_nan_ : false) |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5334 | | IncludeNumberCompareField::encode(include_number_compare_) |
| 5335 | | IncludeSmiCompareField::encode(include_smi_compare_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | |
| 5339 | // StringCharCodeAtGenerator |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5340 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 5341 | Label flat_string; |
| 5342 | Label ascii_string; |
| 5343 | Label got_char_code; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5344 | Label sliced_string; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5345 | |
| 5346 | // If the receiver is a smi trigger the non-string case. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 5347 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5348 | |
| 5349 | // Fetch the instance type of the receiver into result register. |
| 5350 | __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 5351 | __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 5352 | // If the receiver is not a string trigger the non-string case. |
| 5353 | __ tst(result_, Operand(kIsNotStringMask)); |
| 5354 | __ b(ne, receiver_not_string_); |
| 5355 | |
| 5356 | // If the index is non-smi trigger the non-smi case. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 5357 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5358 | __ bind(&got_smi_index_); |
| 5359 | |
| 5360 | // Check for index out of range. |
| 5361 | __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5362 | __ cmp(ip, Operand(index_)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5363 | __ b(ls, index_out_of_range_); |
| 5364 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5365 | __ mov(index_, Operand(index_, ASR, kSmiTagSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5366 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5367 | StringCharLoadGenerator::Generate(masm, |
| 5368 | object_, |
| 5369 | index_, |
| 5370 | result_, |
| 5371 | &call_runtime_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5372 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5373 | __ mov(result_, Operand(result_, LSL, kSmiTagSize)); |
| 5374 | __ bind(&exit_); |
| 5375 | } |
| 5376 | |
| 5377 | |
| 5378 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5379 | MacroAssembler* masm, |
| 5380 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5381 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5382 | |
| 5383 | // Index is not a smi. |
| 5384 | __ bind(&index_not_smi_); |
| 5385 | // If index is a heap number, try converting it to an integer. |
| 5386 | __ CheckMap(index_, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5387 | result_, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5388 | Heap::kHeapNumberMapRootIndex, |
| 5389 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5390 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5391 | call_helper.BeforeCall(masm); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5392 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5393 | __ push(index_); // Consumed by runtime conversion function. |
| 5394 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5395 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5396 | } else { |
| 5397 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5398 | // NumberToSmi discards numbers that are not exact integers. |
| 5399 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5400 | } |
| 5401 | // Save the conversion result before the pop instructions below |
| 5402 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5403 | __ Move(index_, r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5404 | __ pop(object_); |
| 5405 | // Reload the instance type. |
| 5406 | __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 5407 | __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 5408 | call_helper.AfterCall(masm); |
| 5409 | // 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] | 5410 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5411 | // Otherwise, return to the fast path. |
| 5412 | __ jmp(&got_smi_index_); |
| 5413 | |
| 5414 | // Call runtime. We get here when the receiver is a string and the |
| 5415 | // index is a number, but the code of getting the actual character |
| 5416 | // is too complex (e.g., when the string needs to be flattened). |
| 5417 | __ bind(&call_runtime_); |
| 5418 | call_helper.BeforeCall(masm); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5419 | __ mov(index_, Operand(index_, LSL, kSmiTagSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5420 | __ Push(object_, index_); |
| 5421 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5422 | __ Move(result_, r0); |
| 5423 | call_helper.AfterCall(masm); |
| 5424 | __ jmp(&exit_); |
| 5425 | |
| 5426 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5427 | } |
| 5428 | |
| 5429 | |
| 5430 | // ------------------------------------------------------------------------- |
| 5431 | // StringCharFromCodeGenerator |
| 5432 | |
| 5433 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5434 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5435 | STATIC_ASSERT(kSmiTag == 0); |
| 5436 | STATIC_ASSERT(kSmiShiftSize == 0); |
| 5437 | ASSERT(IsPowerOf2(String::kMaxAsciiCharCode + 1)); |
| 5438 | __ tst(code_, |
| 5439 | Operand(kSmiTagMask | |
| 5440 | ((~String::kMaxAsciiCharCode) << kSmiTagSize))); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 5441 | __ b(ne, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5442 | |
| 5443 | __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5444 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5445 | STATIC_ASSERT(kSmiTag == 0); |
| 5446 | __ add(result_, result_, Operand(code_, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5447 | __ ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5448 | __ CompareRoot(result_, Heap::kUndefinedValueRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5449 | __ b(eq, &slow_case_); |
| 5450 | __ bind(&exit_); |
| 5451 | } |
| 5452 | |
| 5453 | |
| 5454 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5455 | MacroAssembler* masm, |
| 5456 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5457 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5458 | |
| 5459 | __ bind(&slow_case_); |
| 5460 | call_helper.BeforeCall(masm); |
| 5461 | __ push(code_); |
| 5462 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5463 | __ Move(result_, r0); |
| 5464 | call_helper.AfterCall(masm); |
| 5465 | __ jmp(&exit_); |
| 5466 | |
| 5467 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5468 | } |
| 5469 | |
| 5470 | |
| 5471 | // ------------------------------------------------------------------------- |
| 5472 | // StringCharAtGenerator |
| 5473 | |
| 5474 | void StringCharAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 5475 | char_code_at_generator_.GenerateFast(masm); |
| 5476 | char_from_code_generator_.GenerateFast(masm); |
| 5477 | } |
| 5478 | |
| 5479 | |
| 5480 | void StringCharAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5481 | MacroAssembler* masm, |
| 5482 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5483 | char_code_at_generator_.GenerateSlow(masm, call_helper); |
| 5484 | char_from_code_generator_.GenerateSlow(masm, call_helper); |
| 5485 | } |
| 5486 | |
| 5487 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5488 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5489 | Register dest, |
| 5490 | Register src, |
| 5491 | Register count, |
| 5492 | Register scratch, |
| 5493 | bool ascii) { |
| 5494 | Label loop; |
| 5495 | Label done; |
| 5496 | // This loop just copies one character at a time, as it is only used for very |
| 5497 | // short strings. |
| 5498 | if (!ascii) { |
| 5499 | __ add(count, count, Operand(count), SetCC); |
| 5500 | } else { |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 5501 | __ cmp(count, Operand(0, RelocInfo::NONE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5502 | } |
| 5503 | __ b(eq, &done); |
| 5504 | |
| 5505 | __ bind(&loop); |
| 5506 | __ ldrb(scratch, MemOperand(src, 1, PostIndex)); |
| 5507 | // Perform sub between load and dependent store to get the load time to |
| 5508 | // complete. |
| 5509 | __ sub(count, count, Operand(1), SetCC); |
| 5510 | __ strb(scratch, MemOperand(dest, 1, PostIndex)); |
| 5511 | // last iteration. |
| 5512 | __ b(gt, &loop); |
| 5513 | |
| 5514 | __ bind(&done); |
| 5515 | } |
| 5516 | |
| 5517 | |
| 5518 | enum CopyCharactersFlags { |
| 5519 | COPY_ASCII = 1, |
| 5520 | DEST_ALWAYS_ALIGNED = 2 |
| 5521 | }; |
| 5522 | |
| 5523 | |
| 5524 | void StringHelper::GenerateCopyCharactersLong(MacroAssembler* masm, |
| 5525 | Register dest, |
| 5526 | Register src, |
| 5527 | Register count, |
| 5528 | Register scratch1, |
| 5529 | Register scratch2, |
| 5530 | Register scratch3, |
| 5531 | Register scratch4, |
| 5532 | Register scratch5, |
| 5533 | int flags) { |
| 5534 | bool ascii = (flags & COPY_ASCII) != 0; |
| 5535 | bool dest_always_aligned = (flags & DEST_ALWAYS_ALIGNED) != 0; |
| 5536 | |
| 5537 | if (dest_always_aligned && FLAG_debug_code) { |
| 5538 | // Check that destination is actually word aligned if the flag says |
| 5539 | // that it is. |
| 5540 | __ tst(dest, Operand(kPointerAlignmentMask)); |
| 5541 | __ Check(eq, "Destination of copy not aligned."); |
| 5542 | } |
| 5543 | |
| 5544 | const int kReadAlignment = 4; |
| 5545 | const int kReadAlignmentMask = kReadAlignment - 1; |
| 5546 | // Ensure that reading an entire aligned word containing the last character |
| 5547 | // of a string will not read outside the allocated area (because we pad up |
| 5548 | // to kObjectAlignment). |
| 5549 | STATIC_ASSERT(kObjectAlignment >= kReadAlignment); |
| 5550 | // Assumes word reads and writes are little endian. |
| 5551 | // Nothing to do for zero characters. |
| 5552 | Label done; |
| 5553 | if (!ascii) { |
| 5554 | __ add(count, count, Operand(count), SetCC); |
| 5555 | } else { |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 5556 | __ cmp(count, Operand(0, RelocInfo::NONE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5557 | } |
| 5558 | __ b(eq, &done); |
| 5559 | |
| 5560 | // Assume that you cannot read (or write) unaligned. |
| 5561 | Label byte_loop; |
| 5562 | // Must copy at least eight bytes, otherwise just do it one byte at a time. |
| 5563 | __ cmp(count, Operand(8)); |
| 5564 | __ add(count, dest, Operand(count)); |
| 5565 | Register limit = count; // Read until src equals this. |
| 5566 | __ b(lt, &byte_loop); |
| 5567 | |
| 5568 | if (!dest_always_aligned) { |
| 5569 | // Align dest by byte copying. Copies between zero and three bytes. |
| 5570 | __ and_(scratch4, dest, Operand(kReadAlignmentMask), SetCC); |
| 5571 | Label dest_aligned; |
| 5572 | __ b(eq, &dest_aligned); |
| 5573 | __ cmp(scratch4, Operand(2)); |
| 5574 | __ ldrb(scratch1, MemOperand(src, 1, PostIndex)); |
| 5575 | __ ldrb(scratch2, MemOperand(src, 1, PostIndex), le); |
| 5576 | __ ldrb(scratch3, MemOperand(src, 1, PostIndex), lt); |
| 5577 | __ strb(scratch1, MemOperand(dest, 1, PostIndex)); |
| 5578 | __ strb(scratch2, MemOperand(dest, 1, PostIndex), le); |
| 5579 | __ strb(scratch3, MemOperand(dest, 1, PostIndex), lt); |
| 5580 | __ bind(&dest_aligned); |
| 5581 | } |
| 5582 | |
| 5583 | Label simple_loop; |
| 5584 | |
| 5585 | __ sub(scratch4, dest, Operand(src)); |
| 5586 | __ and_(scratch4, scratch4, Operand(0x03), SetCC); |
| 5587 | __ b(eq, &simple_loop); |
| 5588 | // Shift register is number of bits in a source word that |
| 5589 | // must be combined with bits in the next source word in order |
| 5590 | // to create a destination word. |
| 5591 | |
| 5592 | // Complex loop for src/dst that are not aligned the same way. |
| 5593 | { |
| 5594 | Label loop; |
| 5595 | __ mov(scratch4, Operand(scratch4, LSL, 3)); |
| 5596 | Register left_shift = scratch4; |
| 5597 | __ and_(src, src, Operand(~3)); // Round down to load previous word. |
| 5598 | __ ldr(scratch1, MemOperand(src, 4, PostIndex)); |
| 5599 | // Store the "shift" most significant bits of scratch in the least |
| 5600 | // signficant bits (i.e., shift down by (32-shift)). |
| 5601 | __ rsb(scratch2, left_shift, Operand(32)); |
| 5602 | Register right_shift = scratch2; |
| 5603 | __ mov(scratch1, Operand(scratch1, LSR, right_shift)); |
| 5604 | |
| 5605 | __ bind(&loop); |
| 5606 | __ ldr(scratch3, MemOperand(src, 4, PostIndex)); |
| 5607 | __ sub(scratch5, limit, Operand(dest)); |
| 5608 | __ orr(scratch1, scratch1, Operand(scratch3, LSL, left_shift)); |
| 5609 | __ str(scratch1, MemOperand(dest, 4, PostIndex)); |
| 5610 | __ mov(scratch1, Operand(scratch3, LSR, right_shift)); |
| 5611 | // Loop if four or more bytes left to copy. |
| 5612 | // Compare to eight, because we did the subtract before increasing dst. |
| 5613 | __ sub(scratch5, scratch5, Operand(8), SetCC); |
| 5614 | __ b(ge, &loop); |
| 5615 | } |
| 5616 | // There is now between zero and three bytes left to copy (negative that |
| 5617 | // number is in scratch5), and between one and three bytes already read into |
| 5618 | // scratch1 (eight times that number in scratch4). We may have read past |
| 5619 | // the end of the string, but because objects are aligned, we have not read |
| 5620 | // past the end of the object. |
| 5621 | // Find the minimum of remaining characters to move and preloaded characters |
| 5622 | // and write those as bytes. |
| 5623 | __ add(scratch5, scratch5, Operand(4), SetCC); |
| 5624 | __ b(eq, &done); |
| 5625 | __ cmp(scratch4, Operand(scratch5, LSL, 3), ne); |
| 5626 | // Move minimum of bytes read and bytes left to copy to scratch4. |
| 5627 | __ mov(scratch5, Operand(scratch4, LSR, 3), LeaveCC, lt); |
| 5628 | // Between one and three (value in scratch5) characters already read into |
| 5629 | // scratch ready to write. |
| 5630 | __ cmp(scratch5, Operand(2)); |
| 5631 | __ strb(scratch1, MemOperand(dest, 1, PostIndex)); |
| 5632 | __ mov(scratch1, Operand(scratch1, LSR, 8), LeaveCC, ge); |
| 5633 | __ strb(scratch1, MemOperand(dest, 1, PostIndex), ge); |
| 5634 | __ mov(scratch1, Operand(scratch1, LSR, 8), LeaveCC, gt); |
| 5635 | __ strb(scratch1, MemOperand(dest, 1, PostIndex), gt); |
| 5636 | // Copy any remaining bytes. |
| 5637 | __ b(&byte_loop); |
| 5638 | |
| 5639 | // Simple loop. |
| 5640 | // Copy words from src to dst, until less than four bytes left. |
| 5641 | // Both src and dest are word aligned. |
| 5642 | __ bind(&simple_loop); |
| 5643 | { |
| 5644 | Label loop; |
| 5645 | __ bind(&loop); |
| 5646 | __ ldr(scratch1, MemOperand(src, 4, PostIndex)); |
| 5647 | __ sub(scratch3, limit, Operand(dest)); |
| 5648 | __ str(scratch1, MemOperand(dest, 4, PostIndex)); |
| 5649 | // Compare to 8, not 4, because we do the substraction before increasing |
| 5650 | // dest. |
| 5651 | __ cmp(scratch3, Operand(8)); |
| 5652 | __ b(ge, &loop); |
| 5653 | } |
| 5654 | |
| 5655 | // Copy bytes from src to dst until dst hits limit. |
| 5656 | __ bind(&byte_loop); |
| 5657 | __ cmp(dest, Operand(limit)); |
| 5658 | __ ldrb(scratch1, MemOperand(src, 1, PostIndex), lt); |
| 5659 | __ b(ge, &done); |
| 5660 | __ strb(scratch1, MemOperand(dest, 1, PostIndex)); |
| 5661 | __ b(&byte_loop); |
| 5662 | |
| 5663 | __ bind(&done); |
| 5664 | } |
| 5665 | |
| 5666 | |
| 5667 | void StringHelper::GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 5668 | Register c1, |
| 5669 | Register c2, |
| 5670 | Register scratch1, |
| 5671 | Register scratch2, |
| 5672 | Register scratch3, |
| 5673 | Register scratch4, |
| 5674 | Register scratch5, |
| 5675 | Label* not_found) { |
| 5676 | // Register scratch3 is the general scratch register in this function. |
| 5677 | Register scratch = scratch3; |
| 5678 | |
| 5679 | // Make sure that both characters are not digits as such strings has a |
| 5680 | // different hash algorithm. Don't try to look for these in the symbol table. |
| 5681 | Label not_array_index; |
| 5682 | __ sub(scratch, c1, Operand(static_cast<int>('0'))); |
| 5683 | __ cmp(scratch, Operand(static_cast<int>('9' - '0'))); |
| 5684 | __ b(hi, ¬_array_index); |
| 5685 | __ sub(scratch, c2, Operand(static_cast<int>('0'))); |
| 5686 | __ cmp(scratch, Operand(static_cast<int>('9' - '0'))); |
| 5687 | |
| 5688 | // If check failed combine both characters into single halfword. |
| 5689 | // This is required by the contract of the method: code at the |
| 5690 | // not_found branch expects this combination in c1 register |
| 5691 | __ orr(c1, c1, Operand(c2, LSL, kBitsPerByte), LeaveCC, ls); |
| 5692 | __ b(ls, not_found); |
| 5693 | |
| 5694 | __ bind(¬_array_index); |
| 5695 | // Calculate the two character string hash. |
| 5696 | Register hash = scratch1; |
| 5697 | StringHelper::GenerateHashInit(masm, hash, c1); |
| 5698 | StringHelper::GenerateHashAddCharacter(masm, hash, c2); |
| 5699 | StringHelper::GenerateHashGetHash(masm, hash); |
| 5700 | |
| 5701 | // Collect the two characters in a register. |
| 5702 | Register chars = c1; |
| 5703 | __ orr(chars, chars, Operand(c2, LSL, kBitsPerByte)); |
| 5704 | |
| 5705 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5706 | // hash: hash of two character string. |
| 5707 | |
| 5708 | // Load symbol table |
| 5709 | // Load address of first element of the symbol table. |
| 5710 | Register symbol_table = c2; |
| 5711 | __ LoadRoot(symbol_table, Heap::kSymbolTableRootIndex); |
| 5712 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5713 | Register undefined = scratch4; |
| 5714 | __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex); |
| 5715 | |
| 5716 | // Calculate capacity mask from the symbol table capacity. |
| 5717 | Register mask = scratch2; |
| 5718 | __ ldr(mask, FieldMemOperand(symbol_table, SymbolTable::kCapacityOffset)); |
| 5719 | __ mov(mask, Operand(mask, ASR, 1)); |
| 5720 | __ sub(mask, mask, Operand(1)); |
| 5721 | |
| 5722 | // Calculate untagged address of the first element of the symbol table. |
| 5723 | Register first_symbol_table_element = symbol_table; |
| 5724 | __ add(first_symbol_table_element, symbol_table, |
| 5725 | Operand(SymbolTable::kElementsStartOffset - kHeapObjectTag)); |
| 5726 | |
| 5727 | // Registers |
| 5728 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5729 | // hash: hash of two character string |
| 5730 | // mask: capacity mask |
| 5731 | // first_symbol_table_element: address of the first element of |
| 5732 | // the symbol table |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5733 | // undefined: the undefined object |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5734 | // scratch: - |
| 5735 | |
| 5736 | // Perform a number of probes in the symbol table. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5737 | const int kProbes = 4; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5738 | Label found_in_symbol_table; |
| 5739 | Label next_probe[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5740 | Register candidate = scratch5; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5741 | for (int i = 0; i < kProbes; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5742 | // Calculate entry in symbol table. |
| 5743 | if (i > 0) { |
| 5744 | __ add(candidate, hash, Operand(SymbolTable::GetProbeOffset(i))); |
| 5745 | } else { |
| 5746 | __ mov(candidate, hash); |
| 5747 | } |
| 5748 | |
| 5749 | __ and_(candidate, candidate, Operand(mask)); |
| 5750 | |
| 5751 | // Load the entry from the symble table. |
| 5752 | STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
| 5753 | __ ldr(candidate, |
| 5754 | MemOperand(first_symbol_table_element, |
| 5755 | candidate, |
| 5756 | LSL, |
| 5757 | kPointerSizeLog2)); |
| 5758 | |
| 5759 | // 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] | 5760 | Label is_string; |
| 5761 | __ CompareObjectType(candidate, scratch, scratch, ODDBALL_TYPE); |
| 5762 | __ b(ne, &is_string); |
| 5763 | |
| 5764 | __ cmp(undefined, candidate); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5765 | __ b(eq, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5766 | // Must be the hole (deleted entry). |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5767 | if (FLAG_debug_code) { |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5768 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5769 | __ cmp(ip, candidate); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5770 | __ 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] | 5771 | } |
| 5772 | __ jmp(&next_probe[i]); |
| 5773 | |
| 5774 | __ bind(&is_string); |
| 5775 | |
| 5776 | // Check that the candidate is a non-external ASCII string. The instance |
| 5777 | // type is still in the scratch register from the CompareObjectType |
| 5778 | // operation. |
| 5779 | __ JumpIfInstanceTypeIsNotSequentialAscii(scratch, scratch, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5780 | |
| 5781 | // If length is not 2 the string is not a candidate. |
| 5782 | __ ldr(scratch, FieldMemOperand(candidate, String::kLengthOffset)); |
| 5783 | __ cmp(scratch, Operand(Smi::FromInt(2))); |
| 5784 | __ b(ne, &next_probe[i]); |
| 5785 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5786 | // Check if the two characters match. |
| 5787 | // Assumes that word load is little endian. |
| 5788 | __ ldrh(scratch, FieldMemOperand(candidate, SeqAsciiString::kHeaderSize)); |
| 5789 | __ cmp(chars, scratch); |
| 5790 | __ b(eq, &found_in_symbol_table); |
| 5791 | __ bind(&next_probe[i]); |
| 5792 | } |
| 5793 | |
| 5794 | // No matching 2 character string found by probing. |
| 5795 | __ jmp(not_found); |
| 5796 | |
| 5797 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5798 | Register result = candidate; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5799 | __ bind(&found_in_symbol_table); |
| 5800 | __ Move(r0, result); |
| 5801 | } |
| 5802 | |
| 5803 | |
| 5804 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 5805 | Register hash, |
| 5806 | Register character) { |
| 5807 | // hash = character + (character << 10); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5808 | __ LoadRoot(hash, Heap::kHashSeedRootIndex); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5809 | // Untag smi seed and add the character. |
| 5810 | __ add(hash, character, Operand(hash, LSR, kSmiTagSize)); |
| 5811 | // hash += hash << 10; |
| 5812 | __ add(hash, hash, Operand(hash, LSL, 10)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5813 | // hash ^= hash >> 6; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5814 | __ eor(hash, hash, Operand(hash, LSR, 6)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5815 | } |
| 5816 | |
| 5817 | |
| 5818 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 5819 | Register hash, |
| 5820 | Register character) { |
| 5821 | // hash += character; |
| 5822 | __ add(hash, hash, Operand(character)); |
| 5823 | // hash += hash << 10; |
| 5824 | __ add(hash, hash, Operand(hash, LSL, 10)); |
| 5825 | // hash ^= hash >> 6; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5826 | __ eor(hash, hash, Operand(hash, LSR, 6)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5827 | } |
| 5828 | |
| 5829 | |
| 5830 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 5831 | Register hash) { |
| 5832 | // hash += hash << 3; |
| 5833 | __ add(hash, hash, Operand(hash, LSL, 3)); |
| 5834 | // hash ^= hash >> 11; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5835 | __ eor(hash, hash, Operand(hash, LSR, 11)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5836 | // hash += hash << 15; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5837 | __ add(hash, hash, Operand(hash, LSL, 15)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5838 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5839 | __ and_(hash, hash, Operand(String::kHashBitMask), SetCC); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5840 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5841 | // if (hash == 0) hash = 27; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5842 | __ mov(hash, Operand(StringHasher::kZeroHash), LeaveCC, eq); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5843 | } |
| 5844 | |
| 5845 | |
| 5846 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 5847 | Label runtime; |
| 5848 | |
| 5849 | // Stack frame on entry. |
| 5850 | // lr: return address |
| 5851 | // sp[0]: to |
| 5852 | // sp[4]: from |
| 5853 | // sp[8]: string |
| 5854 | |
| 5855 | // This stub is called from the native-call %_SubString(...), so |
| 5856 | // nothing can be assumed about the arguments. It is tested that: |
| 5857 | // "string" is a sequential string, |
| 5858 | // both "from" and "to" are smis, and |
| 5859 | // 0 <= from <= to <= string.length. |
| 5860 | // If any of these assumptions fail, we call the runtime system. |
| 5861 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5862 | const int kToOffset = 0 * kPointerSize; |
| 5863 | const int kFromOffset = 1 * kPointerSize; |
| 5864 | const int kStringOffset = 2 * kPointerSize; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5865 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5866 | __ Ldrd(r2, r3, MemOperand(sp, kToOffset)); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5867 | STATIC_ASSERT(kFromOffset == kToOffset + 4); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5868 | STATIC_ASSERT(kSmiTag == 0); |
| 5869 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5870 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5871 | // I.e., arithmetic shift right by one un-smi-tags. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5872 | __ mov(r2, Operand(r2, ASR, 1), SetCC); |
| 5873 | __ mov(r3, Operand(r3, ASR, 1), SetCC, cc); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5874 | // If either to or from had the smi tag bit set, then carry is set now. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5875 | __ b(cs, &runtime); // Either "from" or "to" is not a smi. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5876 | // We want to bailout to runtime here if From is negative. In that case, the |
| 5877 | // next instruction is not executed and we fall through to bailing out to |
| 5878 | // runtime. pl is the opposite of mi. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5879 | // Both r2 and r3 are untagged integers. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5880 | __ sub(r2, r2, Operand(r3), SetCC, pl); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5881 | __ b(mi, &runtime); // Fail if from > to. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5882 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5883 | // Make sure first argument is a string. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5884 | __ ldr(r0, MemOperand(sp, kStringOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5885 | STATIC_ASSERT(kSmiTag == 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5886 | __ JumpIfSmi(r0, &runtime); |
| 5887 | Condition is_string = masm->IsObjectStringType(r0, r1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5888 | __ b(NegateCondition(is_string), &runtime); |
| 5889 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5890 | // Short-cut for the case of trivial substring. |
| 5891 | Label return_r0; |
| 5892 | // r0: original string |
| 5893 | // r2: result string length |
| 5894 | __ ldr(r4, FieldMemOperand(r0, String::kLengthOffset)); |
| 5895 | __ cmp(r2, Operand(r4, ASR, 1)); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5896 | // Return original string. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5897 | __ b(eq, &return_r0); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5898 | // Longer than original string's length or negative: unsafe arguments. |
| 5899 | __ b(hi, &runtime); |
| 5900 | // Shorter than original string's length: an actual substring. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5901 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5902 | // Deal with different string types: update the index if necessary |
| 5903 | // and put the underlying string into r5. |
| 5904 | // r0: original string |
| 5905 | // r1: instance type |
| 5906 | // r2: length |
| 5907 | // r3: from index (untagged) |
| 5908 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 5909 | // If the string is not indirect, it can only be sequential or external. |
| 5910 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 5911 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 5912 | __ tst(r1, Operand(kIsIndirectStringMask)); |
| 5913 | __ b(eq, &seq_or_external_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5914 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5915 | __ tst(r1, Operand(kSlicedNotConsMask)); |
| 5916 | __ b(ne, &sliced_string); |
| 5917 | // Cons string. Check whether it is flat, then fetch first part. |
| 5918 | __ ldr(r5, FieldMemOperand(r0, ConsString::kSecondOffset)); |
| 5919 | __ CompareRoot(r5, Heap::kEmptyStringRootIndex); |
| 5920 | __ b(ne, &runtime); |
| 5921 | __ ldr(r5, FieldMemOperand(r0, ConsString::kFirstOffset)); |
| 5922 | // Update instance type. |
| 5923 | __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset)); |
| 5924 | __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset)); |
| 5925 | __ jmp(&underlying_unpacked); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5926 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5927 | __ bind(&sliced_string); |
| 5928 | // Sliced string. Fetch parent and correct start index by offset. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5929 | __ ldr(r5, FieldMemOperand(r0, SlicedString::kParentOffset)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 5930 | __ ldr(r4, FieldMemOperand(r0, SlicedString::kOffsetOffset)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5931 | __ add(r3, r3, Operand(r4, ASR, 1)); // Add offset to index. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5932 | // Update instance type. |
| 5933 | __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset)); |
| 5934 | __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset)); |
| 5935 | __ jmp(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5936 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5937 | __ bind(&seq_or_external_string); |
| 5938 | // Sequential or external string. Just move string to the expected register. |
| 5939 | __ mov(r5, r0); |
| 5940 | |
| 5941 | __ bind(&underlying_unpacked); |
| 5942 | |
| 5943 | if (FLAG_string_slices) { |
| 5944 | Label copy_routine; |
| 5945 | // r5: underlying subject string |
| 5946 | // r1: instance type of underlying subject string |
| 5947 | // r2: length |
| 5948 | // r3: adjusted start index (untagged) |
| 5949 | __ cmp(r2, Operand(SlicedString::kMinLength)); |
| 5950 | // Short slice. Copy instead of slicing. |
| 5951 | __ b(lt, ©_routine); |
| 5952 | // Allocate new sliced string. At this point we do not reload the instance |
| 5953 | // type including the string encoding because we simply rely on the info |
| 5954 | // provided by the original string. It does not matter if the original |
| 5955 | // string's encoding is wrong because we always have to recheck encoding of |
| 5956 | // the newly created string's parent anyways due to externalized strings. |
| 5957 | Label two_byte_slice, set_slice_header; |
| 5958 | STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
| 5959 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5960 | __ tst(r1, Operand(kStringEncodingMask)); |
| 5961 | __ b(eq, &two_byte_slice); |
| 5962 | __ AllocateAsciiSlicedString(r0, r2, r6, r7, &runtime); |
| 5963 | __ jmp(&set_slice_header); |
| 5964 | __ bind(&two_byte_slice); |
| 5965 | __ AllocateTwoByteSlicedString(r0, r2, r6, r7, &runtime); |
| 5966 | __ bind(&set_slice_header); |
| 5967 | __ mov(r3, Operand(r3, LSL, 1)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5968 | __ str(r5, FieldMemOperand(r0, SlicedString::kParentOffset)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 5969 | __ str(r3, FieldMemOperand(r0, SlicedString::kOffsetOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5970 | __ jmp(&return_r0); |
| 5971 | |
| 5972 | __ bind(©_routine); |
| 5973 | } |
| 5974 | |
| 5975 | // r5: underlying subject string |
| 5976 | // r1: instance type of underlying subject string |
| 5977 | // r2: length |
| 5978 | // r3: adjusted start index (untagged) |
| 5979 | Label two_byte_sequential, sequential_string, allocate_result; |
| 5980 | STATIC_ASSERT(kExternalStringTag != 0); |
| 5981 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5982 | __ tst(r1, Operand(kExternalStringTag)); |
| 5983 | __ b(eq, &sequential_string); |
| 5984 | |
| 5985 | // Handle external string. |
| 5986 | // Rule out short external strings. |
| 5987 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 5988 | __ tst(r1, Operand(kShortExternalStringTag)); |
| 5989 | __ b(ne, &runtime); |
| 5990 | __ ldr(r5, FieldMemOperand(r5, ExternalString::kResourceDataOffset)); |
| 5991 | // r5 already points to the first character of underlying string. |
| 5992 | __ jmp(&allocate_result); |
| 5993 | |
| 5994 | __ bind(&sequential_string); |
| 5995 | // Locate first character of underlying subject string. |
| 5996 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); |
| 5997 | __ add(r5, r5, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 5998 | |
| 5999 | __ bind(&allocate_result); |
| 6000 | // Sequential acii string. Allocate the result. |
| 6001 | STATIC_ASSERT((kAsciiStringTag & kStringEncodingMask) != 0); |
| 6002 | __ tst(r1, Operand(kStringEncodingMask)); |
| 6003 | __ b(eq, &two_byte_sequential); |
| 6004 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6005 | // Allocate and copy the resulting ASCII string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6006 | __ AllocateAsciiString(r0, r2, r4, r6, r7, &runtime); |
| 6007 | |
| 6008 | // Locate first character of substring to copy. |
| 6009 | __ add(r5, r5, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6010 | // Locate first character of result. |
| 6011 | __ add(r1, r0, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6012 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6013 | // r0: result string |
| 6014 | // r1: first character of result string |
| 6015 | // r2: result string length |
| 6016 | // r5: first character of substring to copy |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6017 | STATIC_ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 6018 | StringHelper::GenerateCopyCharactersLong(masm, r1, r5, r2, r3, r4, r6, r7, r9, |
| 6019 | COPY_ASCII | DEST_ALWAYS_ALIGNED); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6020 | __ jmp(&return_r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6021 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6022 | // Allocate and copy the resulting two-byte string. |
| 6023 | __ bind(&two_byte_sequential); |
| 6024 | __ AllocateTwoByteString(r0, r2, r4, r6, r7, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6025 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6026 | // Locate first character of substring to copy. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6027 | STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6028 | __ add(r5, r5, Operand(r3, LSL, 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6029 | // Locate first character of result. |
| 6030 | __ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6031 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6032 | // r0: result string. |
| 6033 | // r1: first character of result. |
| 6034 | // r2: result length. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6035 | // r5: first character of substring to copy. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6036 | STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 6037 | StringHelper::GenerateCopyCharactersLong( |
| 6038 | 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] | 6039 | |
| 6040 | __ bind(&return_r0); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6041 | Counters* counters = masm->isolate()->counters(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6042 | __ IncrementCounter(counters->sub_string_native(), 1, r3, r4); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6043 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 6044 | __ Ret(); |
| 6045 | |
| 6046 | // Just jump to runtime to create the sub string. |
| 6047 | __ bind(&runtime); |
| 6048 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
| 6049 | } |
| 6050 | |
| 6051 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6052 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6053 | Register left, |
| 6054 | Register right, |
| 6055 | Register scratch1, |
| 6056 | Register scratch2, |
| 6057 | Register scratch3) { |
| 6058 | Register length = scratch1; |
| 6059 | |
| 6060 | // Compare lengths. |
| 6061 | Label strings_not_equal, check_zero_length; |
| 6062 | __ ldr(length, FieldMemOperand(left, String::kLengthOffset)); |
| 6063 | __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 6064 | __ cmp(length, scratch2); |
| 6065 | __ b(eq, &check_zero_length); |
| 6066 | __ bind(&strings_not_equal); |
| 6067 | __ mov(r0, Operand(Smi::FromInt(NOT_EQUAL))); |
| 6068 | __ Ret(); |
| 6069 | |
| 6070 | // Check if the length is zero. |
| 6071 | Label compare_chars; |
| 6072 | __ bind(&check_zero_length); |
| 6073 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 6074 | __ cmp(length, Operand(0)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6075 | __ b(ne, &compare_chars); |
| 6076 | __ mov(r0, Operand(Smi::FromInt(EQUAL))); |
| 6077 | __ Ret(); |
| 6078 | |
| 6079 | // Compare characters. |
| 6080 | __ bind(&compare_chars); |
| 6081 | GenerateAsciiCharsCompareLoop(masm, |
| 6082 | left, right, length, scratch2, scratch3, |
| 6083 | &strings_not_equal); |
| 6084 | |
| 6085 | // Characters are equal. |
| 6086 | __ mov(r0, Operand(Smi::FromInt(EQUAL))); |
| 6087 | __ Ret(); |
| 6088 | } |
| 6089 | |
| 6090 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6091 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6092 | Register left, |
| 6093 | Register right, |
| 6094 | Register scratch1, |
| 6095 | Register scratch2, |
| 6096 | Register scratch3, |
| 6097 | Register scratch4) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6098 | Label result_not_equal, compare_lengths; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6099 | // Find minimum length and length difference. |
| 6100 | __ ldr(scratch1, FieldMemOperand(left, String::kLengthOffset)); |
| 6101 | __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 6102 | __ sub(scratch3, scratch1, Operand(scratch2), SetCC); |
| 6103 | Register length_delta = scratch3; |
| 6104 | __ mov(scratch1, scratch2, LeaveCC, gt); |
| 6105 | Register min_length = scratch1; |
| 6106 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 6107 | __ cmp(min_length, Operand(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6108 | __ b(eq, &compare_lengths); |
| 6109 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6110 | // Compare loop. |
| 6111 | GenerateAsciiCharsCompareLoop(masm, |
| 6112 | left, right, min_length, scratch2, scratch4, |
| 6113 | &result_not_equal); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6114 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6115 | // Compare lengths - strings up to min-length are equal. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6116 | __ bind(&compare_lengths); |
| 6117 | ASSERT(Smi::FromInt(EQUAL) == static_cast<Smi*>(0)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6118 | // Use length_delta as result if it's zero. |
| 6119 | __ mov(r0, Operand(length_delta), SetCC); |
| 6120 | __ bind(&result_not_equal); |
| 6121 | // Conditionally update the result based either on length_delta or |
| 6122 | // the last comparion performed in the loop above. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6123 | __ mov(r0, Operand(Smi::FromInt(GREATER)), LeaveCC, gt); |
| 6124 | __ mov(r0, Operand(Smi::FromInt(LESS)), LeaveCC, lt); |
| 6125 | __ Ret(); |
| 6126 | } |
| 6127 | |
| 6128 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6129 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6130 | MacroAssembler* masm, |
| 6131 | Register left, |
| 6132 | Register right, |
| 6133 | Register length, |
| 6134 | Register scratch1, |
| 6135 | Register scratch2, |
| 6136 | Label* chars_not_equal) { |
| 6137 | // Change index to run from -length to -1 by adding length to string |
| 6138 | // start. This means that loop ends when index reaches zero, which |
| 6139 | // doesn't need an additional compare. |
| 6140 | __ SmiUntag(length); |
| 6141 | __ add(scratch1, length, |
| 6142 | Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 6143 | __ add(left, left, Operand(scratch1)); |
| 6144 | __ add(right, right, Operand(scratch1)); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 6145 | __ rsb(length, length, Operand::Zero()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6146 | Register index = length; // index = -length; |
| 6147 | |
| 6148 | // Compare loop. |
| 6149 | Label loop; |
| 6150 | __ bind(&loop); |
| 6151 | __ ldrb(scratch1, MemOperand(left, index)); |
| 6152 | __ ldrb(scratch2, MemOperand(right, index)); |
| 6153 | __ cmp(scratch1, scratch2); |
| 6154 | __ b(ne, chars_not_equal); |
| 6155 | __ add(index, index, Operand(1), SetCC); |
| 6156 | __ b(ne, &loop); |
| 6157 | } |
| 6158 | |
| 6159 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6160 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6161 | Label runtime; |
| 6162 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6163 | Counters* counters = masm->isolate()->counters(); |
| 6164 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6165 | // Stack frame on entry. |
| 6166 | // sp[0]: right string |
| 6167 | // sp[4]: left string |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 6168 | __ 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] | 6169 | |
| 6170 | Label not_same; |
| 6171 | __ cmp(r0, r1); |
| 6172 | __ b(ne, ¬_same); |
| 6173 | STATIC_ASSERT(EQUAL == 0); |
| 6174 | STATIC_ASSERT(kSmiTag == 0); |
| 6175 | __ mov(r0, Operand(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6176 | __ IncrementCounter(counters->string_compare_native(), 1, r1, r2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6177 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6178 | __ Ret(); |
| 6179 | |
| 6180 | __ bind(¬_same); |
| 6181 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6182 | // Check that both objects are sequential ASCII strings. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 6183 | __ JumpIfNotBothSequentialAsciiStrings(r1, r0, r2, r3, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6184 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6185 | // Compare flat ASCII strings natively. Remove arguments from stack first. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6186 | __ IncrementCounter(counters->string_compare_native(), 1, r2, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6187 | __ add(sp, sp, Operand(2 * kPointerSize)); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 6188 | GenerateCompareFlatAsciiStrings(masm, r1, r0, r2, r3, r4, r5); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6189 | |
| 6190 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6191 | // tagged as a small integer. |
| 6192 | __ bind(&runtime); |
| 6193 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6194 | } |
| 6195 | |
| 6196 | |
| 6197 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6198 | Label call_runtime, call_builtin; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6199 | Builtins::JavaScript builtin_id = Builtins::ADD; |
| 6200 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6201 | Counters* counters = masm->isolate()->counters(); |
| 6202 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6203 | // Stack on entry: |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6204 | // sp[0]: second argument (right). |
| 6205 | // sp[4]: first argument (left). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6206 | |
| 6207 | // Load the two arguments. |
| 6208 | __ ldr(r0, MemOperand(sp, 1 * kPointerSize)); // First argument. |
| 6209 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); // Second argument. |
| 6210 | |
| 6211 | // 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] | 6212 | if (flags_ == NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6213 | __ JumpIfEitherSmi(r0, r1, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6214 | // Load instance types. |
| 6215 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 6216 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 6217 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 6218 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 6219 | STATIC_ASSERT(kStringTag == 0); |
| 6220 | // If either is not a string, go to runtime. |
| 6221 | __ tst(r4, Operand(kIsNotStringMask)); |
| 6222 | __ tst(r5, Operand(kIsNotStringMask), eq); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6223 | __ b(ne, &call_runtime); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6224 | } else { |
| 6225 | // Here at least one of the arguments is definitely a string. |
| 6226 | // We convert the one that is not known to be a string. |
| 6227 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 6228 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 6229 | GenerateConvertArgument( |
| 6230 | masm, 1 * kPointerSize, r0, r2, r3, r4, r5, &call_builtin); |
| 6231 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 6232 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 6233 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 6234 | GenerateConvertArgument( |
| 6235 | masm, 0 * kPointerSize, r1, r2, r3, r4, r5, &call_builtin); |
| 6236 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 6237 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6238 | } |
| 6239 | |
| 6240 | // Both arguments are strings. |
| 6241 | // r0: first string |
| 6242 | // r1: second string |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6243 | // r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 6244 | // r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6245 | { |
| 6246 | Label strings_not_empty; |
| 6247 | // Check if either of the strings are empty. In that case return the other. |
| 6248 | __ ldr(r2, FieldMemOperand(r0, String::kLengthOffset)); |
| 6249 | __ ldr(r3, FieldMemOperand(r1, String::kLengthOffset)); |
| 6250 | STATIC_ASSERT(kSmiTag == 0); |
| 6251 | __ cmp(r2, Operand(Smi::FromInt(0))); // Test if first string is empty. |
| 6252 | __ mov(r0, Operand(r1), LeaveCC, eq); // If first is empty, return second. |
| 6253 | STATIC_ASSERT(kSmiTag == 0); |
| 6254 | // Else test if second string is empty. |
| 6255 | __ cmp(r3, Operand(Smi::FromInt(0)), ne); |
| 6256 | __ b(ne, &strings_not_empty); // If either string was empty, return r0. |
| 6257 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6258 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6259 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6260 | __ Ret(); |
| 6261 | |
| 6262 | __ bind(&strings_not_empty); |
| 6263 | } |
| 6264 | |
| 6265 | __ mov(r2, Operand(r2, ASR, kSmiTagSize)); |
| 6266 | __ mov(r3, Operand(r3, ASR, kSmiTagSize)); |
| 6267 | // Both strings are non-empty. |
| 6268 | // r0: first string |
| 6269 | // r1: second string |
| 6270 | // r2: length of first string |
| 6271 | // r3: length of second string |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6272 | // r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 6273 | // r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6274 | // Look at the length of the result of adding the two strings. |
| 6275 | Label string_add_flat_result, longer_than_two; |
| 6276 | // Adding two lengths can't overflow. |
| 6277 | STATIC_ASSERT(String::kMaxLength < String::kMaxLength * 2); |
| 6278 | __ add(r6, r2, Operand(r3)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6279 | // Use the symbol table when adding two one character strings, as it |
| 6280 | // helps later optimizations to return a symbol here. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6281 | __ cmp(r6, Operand(2)); |
| 6282 | __ b(ne, &longer_than_two); |
| 6283 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6284 | // Check that both strings are non-external ASCII strings. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6285 | if (flags_ != NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6286 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 6287 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 6288 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 6289 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 6290 | } |
| 6291 | __ JumpIfBothInstanceTypesAreNotSequentialAscii(r4, r5, r6, r7, |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6292 | &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6293 | |
| 6294 | // Get the two characters forming the sub string. |
| 6295 | __ ldrb(r2, FieldMemOperand(r0, SeqAsciiString::kHeaderSize)); |
| 6296 | __ ldrb(r3, FieldMemOperand(r1, SeqAsciiString::kHeaderSize)); |
| 6297 | |
| 6298 | // Try to lookup two character string in symbol table. If it is not found |
| 6299 | // just allocate a new one. |
| 6300 | Label make_two_character_string; |
| 6301 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
| 6302 | 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] | 6303 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6304 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6305 | __ Ret(); |
| 6306 | |
| 6307 | __ bind(&make_two_character_string); |
| 6308 | // Resulting string has length 2 and first chars of two strings |
| 6309 | // are combined into single halfword in r2 register. |
| 6310 | // So we can fill resulting string without two loops by a single |
| 6311 | // halfword store instruction (which assumes that processor is |
| 6312 | // in a little endian mode) |
| 6313 | __ mov(r6, Operand(2)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6314 | __ AllocateAsciiString(r0, r6, r4, r5, r9, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6315 | __ strh(r2, FieldMemOperand(r0, SeqAsciiString::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6316 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6317 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6318 | __ Ret(); |
| 6319 | |
| 6320 | __ bind(&longer_than_two); |
| 6321 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6322 | __ cmp(r6, Operand(ConsString::kMinLength)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6323 | __ b(lt, &string_add_flat_result); |
| 6324 | // Handle exceptionally long strings in the runtime system. |
| 6325 | STATIC_ASSERT((String::kMaxLength & 0x80000000) == 0); |
| 6326 | ASSERT(IsPowerOf2(String::kMaxLength + 1)); |
| 6327 | // kMaxLength + 1 is representable as shifted literal, kMaxLength is not. |
| 6328 | __ cmp(r6, Operand(String::kMaxLength + 1)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6329 | __ b(hs, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6330 | |
| 6331 | // 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] | 6332 | // 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] | 6333 | if (flags_ != NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6334 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 6335 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 6336 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 6337 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 6338 | } |
| 6339 | Label non_ascii, allocated, ascii_data; |
| 6340 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 6341 | __ tst(r4, Operand(kStringEncodingMask)); |
| 6342 | __ tst(r5, Operand(kStringEncodingMask), ne); |
| 6343 | __ b(eq, &non_ascii); |
| 6344 | |
| 6345 | // Allocate an ASCII cons string. |
| 6346 | __ bind(&ascii_data); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6347 | __ AllocateAsciiConsString(r7, r6, r4, r5, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6348 | __ bind(&allocated); |
| 6349 | // Fill the fields of the cons string. |
| 6350 | __ str(r0, FieldMemOperand(r7, ConsString::kFirstOffset)); |
| 6351 | __ str(r1, FieldMemOperand(r7, ConsString::kSecondOffset)); |
| 6352 | __ mov(r0, Operand(r7)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6353 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6354 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6355 | __ Ret(); |
| 6356 | |
| 6357 | __ bind(&non_ascii); |
| 6358 | // 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] | 6359 | // to contain only ASCII characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6360 | // r4: first instance type. |
| 6361 | // r5: second instance type. |
| 6362 | __ tst(r4, Operand(kAsciiDataHintMask)); |
| 6363 | __ tst(r5, Operand(kAsciiDataHintMask), ne); |
| 6364 | __ b(ne, &ascii_data); |
| 6365 | __ eor(r4, r4, Operand(r5)); |
| 6366 | STATIC_ASSERT(kAsciiStringTag != 0 && kAsciiDataHintTag != 0); |
| 6367 | __ and_(r4, r4, Operand(kAsciiStringTag | kAsciiDataHintTag)); |
| 6368 | __ cmp(r4, Operand(kAsciiStringTag | kAsciiDataHintTag)); |
| 6369 | __ b(eq, &ascii_data); |
| 6370 | |
| 6371 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6372 | __ AllocateTwoByteConsString(r7, r6, r4, r5, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6373 | __ jmp(&allocated); |
| 6374 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6375 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6376 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6377 | // Handle creating a flat result from either external or sequential strings. |
| 6378 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6379 | // r0: first string |
| 6380 | // r1: second string |
| 6381 | // r2: length of first string |
| 6382 | // r3: length of second string |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6383 | // r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 6384 | // r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6385 | // r6: sum of lengths. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6386 | Label first_prepared, second_prepared; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6387 | __ bind(&string_add_flat_result); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6388 | if (flags_ != NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6389 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 6390 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 6391 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 6392 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 6393 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6394 | |
| 6395 | // Check whether both strings have same encoding |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6396 | __ eor(r7, r4, Operand(r5)); |
| 6397 | __ tst(r7, Operand(kStringEncodingMask)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6398 | __ b(ne, &call_runtime); |
| 6399 | |
| 6400 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6401 | __ tst(r4, Operand(kStringRepresentationMask)); |
| 6402 | STATIC_ASSERT(SeqAsciiString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
| 6403 | __ add(r7, |
| 6404 | r0, |
| 6405 | Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag), |
| 6406 | LeaveCC, |
| 6407 | eq); |
| 6408 | __ b(eq, &first_prepared); |
| 6409 | // External string: rule out short external string and load string resource. |
| 6410 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 6411 | __ tst(r4, Operand(kShortExternalStringMask)); |
| 6412 | __ b(ne, &call_runtime); |
| 6413 | __ ldr(r7, FieldMemOperand(r0, ExternalString::kResourceDataOffset)); |
| 6414 | __ bind(&first_prepared); |
| 6415 | |
| 6416 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6417 | __ tst(r5, Operand(kStringRepresentationMask)); |
| 6418 | STATIC_ASSERT(SeqAsciiString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
| 6419 | __ add(r1, |
| 6420 | r1, |
| 6421 | Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag), |
| 6422 | LeaveCC, |
| 6423 | eq); |
| 6424 | __ b(eq, &second_prepared); |
| 6425 | // External string: rule out short external string and load string resource. |
| 6426 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 6427 | __ tst(r5, Operand(kShortExternalStringMask)); |
| 6428 | __ b(ne, &call_runtime); |
| 6429 | __ ldr(r1, FieldMemOperand(r1, ExternalString::kResourceDataOffset)); |
| 6430 | __ bind(&second_prepared); |
| 6431 | |
| 6432 | Label non_ascii_string_add_flat_result; |
| 6433 | // r7: first character of first string |
| 6434 | // r1: first character of second string |
| 6435 | // r2: length of first string. |
| 6436 | // r3: length of second string. |
| 6437 | // r6: sum of lengths. |
| 6438 | // Both strings have the same encoding. |
| 6439 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 6440 | __ tst(r5, Operand(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6441 | __ b(eq, &non_ascii_string_add_flat_result); |
| 6442 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6443 | __ AllocateAsciiString(r0, r6, r4, r5, r9, &call_runtime); |
| 6444 | __ add(r6, r0, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 6445 | // r0: result string. |
| 6446 | // r7: first character of first string. |
| 6447 | // r1: first character of second string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6448 | // r2: length of first string. |
| 6449 | // r3: length of second string. |
| 6450 | // r6: first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6451 | StringHelper::GenerateCopyCharacters(masm, r6, r7, r2, r4, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6452 | // r6: next character of result. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6453 | StringHelper::GenerateCopyCharacters(masm, r6, r1, r3, r4, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6454 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6455 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6456 | __ Ret(); |
| 6457 | |
| 6458 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6459 | __ AllocateTwoByteString(r0, r6, r4, r5, r9, &call_runtime); |
| 6460 | __ add(r6, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6461 | // r0: result string. |
| 6462 | // r7: first character of first string. |
| 6463 | // r1: first character of second string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6464 | // r2: length of first string. |
| 6465 | // r3: length of second string. |
| 6466 | // r6: first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6467 | StringHelper::GenerateCopyCharacters(masm, r6, r7, r2, r4, false); |
| 6468 | // r6: next character of result. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6469 | StringHelper::GenerateCopyCharacters(masm, r6, r1, r3, r4, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6470 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6471 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6472 | __ Ret(); |
| 6473 | |
| 6474 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6475 | __ bind(&call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6476 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6477 | |
| 6478 | if (call_builtin.is_linked()) { |
| 6479 | __ bind(&call_builtin); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 6480 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 6481 | } |
| 6482 | } |
| 6483 | |
| 6484 | |
| 6485 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 6486 | int stack_offset, |
| 6487 | Register arg, |
| 6488 | Register scratch1, |
| 6489 | Register scratch2, |
| 6490 | Register scratch3, |
| 6491 | Register scratch4, |
| 6492 | Label* slow) { |
| 6493 | // First check if the argument is already a string. |
| 6494 | Label not_string, done; |
| 6495 | __ JumpIfSmi(arg, ¬_string); |
| 6496 | __ CompareObjectType(arg, scratch1, scratch1, FIRST_NONSTRING_TYPE); |
| 6497 | __ b(lt, &done); |
| 6498 | |
| 6499 | // Check the number to string cache. |
| 6500 | Label not_cached; |
| 6501 | __ bind(¬_string); |
| 6502 | // Puts the cached result into scratch1. |
| 6503 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 6504 | arg, |
| 6505 | scratch1, |
| 6506 | scratch2, |
| 6507 | scratch3, |
| 6508 | scratch4, |
| 6509 | false, |
| 6510 | ¬_cached); |
| 6511 | __ mov(arg, scratch1); |
| 6512 | __ str(arg, MemOperand(sp, stack_offset)); |
| 6513 | __ jmp(&done); |
| 6514 | |
| 6515 | // Check if the argument is a safe string wrapper. |
| 6516 | __ bind(¬_cached); |
| 6517 | __ JumpIfSmi(arg, slow); |
| 6518 | __ CompareObjectType( |
| 6519 | arg, scratch1, scratch2, JS_VALUE_TYPE); // map -> scratch1. |
| 6520 | __ b(ne, slow); |
| 6521 | __ ldrb(scratch2, FieldMemOperand(scratch1, Map::kBitField2Offset)); |
| 6522 | __ and_(scratch2, |
| 6523 | scratch2, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 6524 | __ cmp(scratch2, |
| 6525 | Operand(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 6526 | __ b(ne, slow); |
| 6527 | __ ldr(arg, FieldMemOperand(arg, JSValue::kValueOffset)); |
| 6528 | __ str(arg, MemOperand(sp, stack_offset)); |
| 6529 | |
| 6530 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6531 | } |
| 6532 | |
| 6533 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6534 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
| 6535 | ASSERT(state_ == CompareIC::SMIS); |
| 6536 | Label miss; |
| 6537 | __ orr(r2, r1, r0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6538 | __ JumpIfNotSmi(r2, &miss); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6539 | |
| 6540 | if (GetCondition() == eq) { |
| 6541 | // For equality we do not care about the sign of the result. |
| 6542 | __ sub(r0, r0, r1, SetCC); |
| 6543 | } else { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 6544 | // Untag before subtracting to avoid handling overflow. |
| 6545 | __ SmiUntag(r1); |
| 6546 | __ sub(r0, r1, SmiUntagOperand(r0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6547 | } |
| 6548 | __ Ret(); |
| 6549 | |
| 6550 | __ bind(&miss); |
| 6551 | GenerateMiss(masm); |
| 6552 | } |
| 6553 | |
| 6554 | |
| 6555 | void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) { |
| 6556 | ASSERT(state_ == CompareIC::HEAP_NUMBERS); |
| 6557 | |
| 6558 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6559 | Label unordered, maybe_undefined1, maybe_undefined2; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6560 | Label miss; |
| 6561 | __ and_(r2, r1, Operand(r0)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6562 | __ JumpIfSmi(r2, &generic_stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6563 | |
| 6564 | __ CompareObjectType(r0, r2, r2, HEAP_NUMBER_TYPE); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6565 | __ b(ne, &maybe_undefined1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6566 | __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6567 | __ b(ne, &maybe_undefined2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6568 | |
| 6569 | // Inlining the double comparison and falling back to the general compare |
| 6570 | // stub if NaN is involved or VFP3 is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6571 | if (CpuFeatures::IsSupported(VFP3)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6572 | CpuFeatures::Scope scope(VFP3); |
| 6573 | |
| 6574 | // Load left and right operand |
| 6575 | __ sub(r2, r1, Operand(kHeapObjectTag)); |
| 6576 | __ vldr(d0, r2, HeapNumber::kValueOffset); |
| 6577 | __ sub(r2, r0, Operand(kHeapObjectTag)); |
| 6578 | __ vldr(d1, r2, HeapNumber::kValueOffset); |
| 6579 | |
| 6580 | // Compare operands |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 6581 | __ VFPCompareAndSetFlags(d0, d1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6582 | |
| 6583 | // Don't base result on status bits when a NaN is involved. |
| 6584 | __ b(vs, &unordered); |
| 6585 | |
| 6586 | // Return a result of -1, 0, or 1, based on status bits. |
| 6587 | __ mov(r0, Operand(EQUAL), LeaveCC, eq); |
| 6588 | __ mov(r0, Operand(LESS), LeaveCC, lt); |
| 6589 | __ mov(r0, Operand(GREATER), LeaveCC, gt); |
| 6590 | __ Ret(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6591 | } |
| 6592 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6593 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6594 | CompareStub stub(GetCondition(), strict(), NO_COMPARE_FLAGS, r1, r0); |
| 6595 | __ bind(&generic_stub); |
| 6596 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 6597 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6598 | __ bind(&maybe_undefined1); |
| 6599 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6600 | __ CompareRoot(r0, Heap::kUndefinedValueRootIndex); |
| 6601 | __ b(ne, &miss); |
| 6602 | __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE); |
| 6603 | __ b(ne, &maybe_undefined2); |
| 6604 | __ jmp(&unordered); |
| 6605 | } |
| 6606 | |
| 6607 | __ bind(&maybe_undefined2); |
| 6608 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6609 | __ CompareRoot(r1, Heap::kUndefinedValueRootIndex); |
| 6610 | __ b(eq, &unordered); |
| 6611 | } |
| 6612 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6613 | __ bind(&miss); |
| 6614 | GenerateMiss(masm); |
| 6615 | } |
| 6616 | |
| 6617 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6618 | void ICCompareStub::GenerateSymbols(MacroAssembler* masm) { |
| 6619 | ASSERT(state_ == CompareIC::SYMBOLS); |
| 6620 | Label miss; |
| 6621 | |
| 6622 | // Registers containing left and right operands respectively. |
| 6623 | Register left = r1; |
| 6624 | Register right = r0; |
| 6625 | Register tmp1 = r2; |
| 6626 | Register tmp2 = r3; |
| 6627 | |
| 6628 | // Check that both operands are heap objects. |
| 6629 | __ JumpIfEitherSmi(left, right, &miss); |
| 6630 | |
| 6631 | // Check that both operands are symbols. |
| 6632 | __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 6633 | __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 6634 | __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6635 | __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6636 | STATIC_ASSERT(kSymbolTag != 0); |
| 6637 | __ and_(tmp1, tmp1, Operand(tmp2)); |
| 6638 | __ tst(tmp1, Operand(kIsSymbolMask)); |
| 6639 | __ b(eq, &miss); |
| 6640 | |
| 6641 | // Symbols are compared by identity. |
| 6642 | __ cmp(left, right); |
| 6643 | // Make sure r0 is non-zero. At this point input operands are |
| 6644 | // guaranteed to be non-zero. |
| 6645 | ASSERT(right.is(r0)); |
| 6646 | STATIC_ASSERT(EQUAL == 0); |
| 6647 | STATIC_ASSERT(kSmiTag == 0); |
| 6648 | __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq); |
| 6649 | __ Ret(); |
| 6650 | |
| 6651 | __ bind(&miss); |
| 6652 | GenerateMiss(masm); |
| 6653 | } |
| 6654 | |
| 6655 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6656 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
| 6657 | ASSERT(state_ == CompareIC::STRINGS); |
| 6658 | Label miss; |
| 6659 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6660 | bool equality = Token::IsEqualityOp(op_); |
| 6661 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6662 | // Registers containing left and right operands respectively. |
| 6663 | Register left = r1; |
| 6664 | Register right = r0; |
| 6665 | Register tmp1 = r2; |
| 6666 | Register tmp2 = r3; |
| 6667 | Register tmp3 = r4; |
| 6668 | Register tmp4 = r5; |
| 6669 | |
| 6670 | // Check that both operands are heap objects. |
| 6671 | __ JumpIfEitherSmi(left, right, &miss); |
| 6672 | |
| 6673 | // Check that both operands are strings. This leaves the instance |
| 6674 | // types loaded in tmp1 and tmp2. |
| 6675 | __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 6676 | __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 6677 | __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6678 | __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6679 | STATIC_ASSERT(kNotStringTag != 0); |
| 6680 | __ orr(tmp3, tmp1, tmp2); |
| 6681 | __ tst(tmp3, Operand(kIsNotStringMask)); |
| 6682 | __ b(ne, &miss); |
| 6683 | |
| 6684 | // Fast check for identical strings. |
| 6685 | __ cmp(left, right); |
| 6686 | STATIC_ASSERT(EQUAL == 0); |
| 6687 | STATIC_ASSERT(kSmiTag == 0); |
| 6688 | __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq); |
| 6689 | __ Ret(eq); |
| 6690 | |
| 6691 | // Handle not identical strings. |
| 6692 | |
| 6693 | // Check that both strings are symbols. If they are, we're done |
| 6694 | // because we already know they are not identical. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6695 | if (equality) { |
| 6696 | ASSERT(GetCondition() == eq); |
| 6697 | STATIC_ASSERT(kSymbolTag != 0); |
| 6698 | __ and_(tmp3, tmp1, Operand(tmp2)); |
| 6699 | __ tst(tmp3, Operand(kIsSymbolMask)); |
| 6700 | // Make sure r0 is non-zero. At this point input operands are |
| 6701 | // guaranteed to be non-zero. |
| 6702 | ASSERT(right.is(r0)); |
| 6703 | __ Ret(ne); |
| 6704 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6705 | |
| 6706 | // Check that both strings are sequential ASCII. |
| 6707 | Label runtime; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6708 | __ JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 6709 | tmp1, tmp2, tmp3, tmp4, &runtime); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6710 | |
| 6711 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6712 | if (equality) { |
| 6713 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6714 | masm, left, right, tmp1, tmp2, tmp3); |
| 6715 | } else { |
| 6716 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 6717 | masm, left, right, tmp1, tmp2, tmp3, tmp4); |
| 6718 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6719 | |
| 6720 | // Handle more complex cases in runtime. |
| 6721 | __ bind(&runtime); |
| 6722 | __ Push(left, right); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6723 | if (equality) { |
| 6724 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6725 | } else { |
| 6726 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6727 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6728 | |
| 6729 | __ bind(&miss); |
| 6730 | GenerateMiss(masm); |
| 6731 | } |
| 6732 | |
| 6733 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6734 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
| 6735 | ASSERT(state_ == CompareIC::OBJECTS); |
| 6736 | Label miss; |
| 6737 | __ and_(r2, r1, Operand(r0)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6738 | __ JumpIfSmi(r2, &miss); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6739 | |
| 6740 | __ CompareObjectType(r0, r2, r2, JS_OBJECT_TYPE); |
| 6741 | __ b(ne, &miss); |
| 6742 | __ CompareObjectType(r1, r2, r2, JS_OBJECT_TYPE); |
| 6743 | __ b(ne, &miss); |
| 6744 | |
| 6745 | ASSERT(GetCondition() == eq); |
| 6746 | __ sub(r0, r0, Operand(r1)); |
| 6747 | __ Ret(); |
| 6748 | |
| 6749 | __ bind(&miss); |
| 6750 | GenerateMiss(masm); |
| 6751 | } |
| 6752 | |
| 6753 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6754 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 6755 | Label miss; |
| 6756 | __ and_(r2, r1, Operand(r0)); |
| 6757 | __ JumpIfSmi(r2, &miss); |
| 6758 | __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 6759 | __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 6760 | __ cmp(r2, Operand(known_map_)); |
| 6761 | __ b(ne, &miss); |
| 6762 | __ cmp(r3, Operand(known_map_)); |
| 6763 | __ b(ne, &miss); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6764 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6765 | __ sub(r0, r0, Operand(r1)); |
| 6766 | __ Ret(); |
| 6767 | |
| 6768 | __ bind(&miss); |
| 6769 | GenerateMiss(masm); |
| 6770 | } |
| 6771 | |
| 6772 | |
| 6773 | |
| 6774 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6775 | { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6776 | // Call the runtime system in a fresh internal frame. |
| 6777 | ExternalReference miss = |
| 6778 | ExternalReference(IC_Utility(IC::kCompareIC_Miss), masm->isolate()); |
| 6779 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6780 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 6781 | __ Push(r1, r0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6782 | __ push(lr); |
| 6783 | __ Push(r1, r0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6784 | __ mov(ip, Operand(Smi::FromInt(op_))); |
| 6785 | __ push(ip); |
| 6786 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6787 | // Compute the entry point of the rewritten stub. |
| 6788 | __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 6789 | // Restore registers. |
| 6790 | __ pop(lr); |
| 6791 | __ pop(r0); |
| 6792 | __ pop(r1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6793 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6794 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6795 | __ Jump(r2); |
| 6796 | } |
| 6797 | |
| 6798 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 6799 | void DirectCEntryStub::Generate(MacroAssembler* masm) { |
| 6800 | __ ldr(pc, MemOperand(sp, 0)); |
| 6801 | } |
| 6802 | |
| 6803 | |
| 6804 | void DirectCEntryStub::GenerateCall(MacroAssembler* masm, |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 6805 | ExternalReference function) { |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 6806 | __ mov(r2, Operand(function)); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 6807 | GenerateCall(masm, r2); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 6808 | } |
| 6809 | |
| 6810 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 6811 | void DirectCEntryStub::GenerateCall(MacroAssembler* masm, |
| 6812 | Register target) { |
| 6813 | __ mov(lr, Operand(reinterpret_cast<intptr_t>(GetCode().location()), |
| 6814 | RelocInfo::CODE_TARGET)); |
| 6815 | // Push return address (accessible to GC through exit frame pc). |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 6816 | // Note that using pc with str is deprecated. |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 6817 | Label start; |
| 6818 | __ bind(&start); |
| 6819 | __ add(ip, pc, Operand(Assembler::kInstrSize)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 6820 | __ str(ip, MemOperand(sp, 0)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 6821 | __ Jump(target); // Call the C++ function. |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 6822 | ASSERT_EQ(Assembler::kInstrSize + Assembler::kPcLoadDelta, |
| 6823 | masm->SizeOfCodeGeneratedSince(&start)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 6824 | } |
| 6825 | |
| 6826 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6827 | void StringDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 6828 | Label* miss, |
| 6829 | Label* done, |
| 6830 | Register receiver, |
| 6831 | Register properties, |
| 6832 | Handle<String> name, |
| 6833 | Register scratch0) { |
| 6834 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6835 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6836 | // undefined value), it guarantees the hash table doesn't contain the |
| 6837 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6838 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6839 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6840 | // scratch0 points to properties hash. |
| 6841 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6842 | Register index = scratch0; |
| 6843 | // Capacity is smi 2^n. |
| 6844 | __ ldr(index, FieldMemOperand(properties, kCapacityOffset)); |
| 6845 | __ sub(index, index, Operand(1)); |
| 6846 | __ and_(index, index, Operand( |
| 6847 | Smi::FromInt(name->Hash() + StringDictionary::GetProbeOffset(i)))); |
| 6848 | |
| 6849 | // Scale the index by multiplying by the entry size. |
| 6850 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6851 | __ add(index, index, Operand(index, LSL, 1)); // index *= 3. |
| 6852 | |
| 6853 | Register entity_name = scratch0; |
| 6854 | // Having undefined at this place means the name is not contained. |
| 6855 | ASSERT_EQ(kSmiTagSize, 1); |
| 6856 | Register tmp = properties; |
| 6857 | __ add(tmp, properties, Operand(index, LSL, 1)); |
| 6858 | __ ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset)); |
| 6859 | |
| 6860 | ASSERT(!tmp.is(entity_name)); |
| 6861 | __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex); |
| 6862 | __ cmp(entity_name, tmp); |
| 6863 | __ b(eq, done); |
| 6864 | |
| 6865 | if (i != kInlinedProbes - 1) { |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6866 | // Load the hole ready for use below: |
| 6867 | __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex); |
| 6868 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6869 | // Stop if found the property. |
| 6870 | __ cmp(entity_name, Operand(Handle<String>(name))); |
| 6871 | __ b(eq, miss); |
| 6872 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6873 | Label the_hole; |
| 6874 | __ cmp(entity_name, tmp); |
| 6875 | __ b(eq, &the_hole); |
| 6876 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6877 | // Check if the entry name is not a symbol. |
| 6878 | __ ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset)); |
| 6879 | __ ldrb(entity_name, |
| 6880 | FieldMemOperand(entity_name, Map::kInstanceTypeOffset)); |
| 6881 | __ tst(entity_name, Operand(kIsSymbolMask)); |
| 6882 | __ b(eq, miss); |
| 6883 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6884 | __ bind(&the_hole); |
| 6885 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6886 | // Restore the properties. |
| 6887 | __ ldr(properties, |
| 6888 | FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 6889 | } |
| 6890 | } |
| 6891 | |
| 6892 | const int spill_mask = |
| 6893 | (lr.bit() | r6.bit() | r5.bit() | r4.bit() | r3.bit() | |
| 6894 | r2.bit() | r1.bit() | r0.bit()); |
| 6895 | |
| 6896 | __ stm(db_w, sp, spill_mask); |
| 6897 | __ ldr(r0, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 6898 | __ mov(r1, Operand(Handle<String>(name))); |
| 6899 | StringDictionaryLookupStub stub(NEGATIVE_LOOKUP); |
| 6900 | __ CallStub(&stub); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 6901 | __ cmp(r0, Operand(0)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6902 | __ ldm(ia_w, sp, spill_mask); |
| 6903 | |
| 6904 | __ b(eq, done); |
| 6905 | __ b(ne, miss); |
| 6906 | } |
| 6907 | |
| 6908 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6909 | // Probe the string dictionary in the |elements| register. Jump to the |
| 6910 | // |done| label if a property with the given name is found. Jump to |
| 6911 | // the |miss| label otherwise. |
| 6912 | // If lookup was successful |scratch2| will be equal to elements + 4 * index. |
| 6913 | void StringDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 6914 | Label* miss, |
| 6915 | Label* done, |
| 6916 | Register elements, |
| 6917 | Register name, |
| 6918 | Register scratch1, |
| 6919 | Register scratch2) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 6920 | ASSERT(!elements.is(scratch1)); |
| 6921 | ASSERT(!elements.is(scratch2)); |
| 6922 | ASSERT(!name.is(scratch1)); |
| 6923 | ASSERT(!name.is(scratch2)); |
| 6924 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6925 | // Assert that name contains a string. |
| 6926 | if (FLAG_debug_code) __ AbortIfNotString(name); |
| 6927 | |
| 6928 | // Compute the capacity mask. |
| 6929 | __ ldr(scratch1, FieldMemOperand(elements, kCapacityOffset)); |
| 6930 | __ mov(scratch1, Operand(scratch1, ASR, kSmiTagSize)); // convert smi to int |
| 6931 | __ sub(scratch1, scratch1, Operand(1)); |
| 6932 | |
| 6933 | // Generate an unrolled loop that performs a few probes before |
| 6934 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 6935 | // cover ~93% of loads from dictionaries. |
| 6936 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6937 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6938 | __ ldr(scratch2, FieldMemOperand(name, String::kHashFieldOffset)); |
| 6939 | if (i > 0) { |
| 6940 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 6941 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 6942 | // shifted in the following and instruction. |
| 6943 | ASSERT(StringDictionary::GetProbeOffset(i) < |
| 6944 | 1 << (32 - String::kHashFieldOffset)); |
| 6945 | __ add(scratch2, scratch2, Operand( |
| 6946 | StringDictionary::GetProbeOffset(i) << String::kHashShift)); |
| 6947 | } |
| 6948 | __ and_(scratch2, scratch1, Operand(scratch2, LSR, String::kHashShift)); |
| 6949 | |
| 6950 | // Scale the index by multiplying by the element size. |
| 6951 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6952 | // scratch2 = scratch2 * 3. |
| 6953 | __ add(scratch2, scratch2, Operand(scratch2, LSL, 1)); |
| 6954 | |
| 6955 | // Check if the key is identical to the name. |
| 6956 | __ add(scratch2, elements, Operand(scratch2, LSL, 2)); |
| 6957 | __ ldr(ip, FieldMemOperand(scratch2, kElementsStartOffset)); |
| 6958 | __ cmp(name, Operand(ip)); |
| 6959 | __ b(eq, done); |
| 6960 | } |
| 6961 | |
| 6962 | const int spill_mask = |
| 6963 | (lr.bit() | r6.bit() | r5.bit() | r4.bit() | |
| 6964 | r3.bit() | r2.bit() | r1.bit() | r0.bit()) & |
| 6965 | ~(scratch1.bit() | scratch2.bit()); |
| 6966 | |
| 6967 | __ stm(db_w, sp, spill_mask); |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 6968 | if (name.is(r0)) { |
| 6969 | ASSERT(!elements.is(r1)); |
| 6970 | __ Move(r1, name); |
| 6971 | __ Move(r0, elements); |
| 6972 | } else { |
| 6973 | __ Move(r0, elements); |
| 6974 | __ Move(r1, name); |
| 6975 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6976 | StringDictionaryLookupStub stub(POSITIVE_LOOKUP); |
| 6977 | __ CallStub(&stub); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 6978 | __ cmp(r0, Operand(0)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6979 | __ mov(scratch2, Operand(r2)); |
| 6980 | __ ldm(ia_w, sp, spill_mask); |
| 6981 | |
| 6982 | __ b(ne, done); |
| 6983 | __ b(eq, miss); |
| 6984 | } |
| 6985 | |
| 6986 | |
| 6987 | void StringDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6988 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 6989 | // 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] | 6990 | // Registers: |
| 6991 | // result: StringDictionary to probe |
| 6992 | // r1: key |
| 6993 | // : StringDictionary to probe. |
| 6994 | // index_: will hold an index of entry if lookup is successful. |
| 6995 | // might alias with result_. |
| 6996 | // Returns: |
| 6997 | // result_ is zero if lookup failed, non zero otherwise. |
| 6998 | |
| 6999 | Register result = r0; |
| 7000 | Register dictionary = r0; |
| 7001 | Register key = r1; |
| 7002 | Register index = r2; |
| 7003 | Register mask = r3; |
| 7004 | Register hash = r4; |
| 7005 | Register undefined = r5; |
| 7006 | Register entry_key = r6; |
| 7007 | |
| 7008 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 7009 | |
| 7010 | __ ldr(mask, FieldMemOperand(dictionary, kCapacityOffset)); |
| 7011 | __ mov(mask, Operand(mask, ASR, kSmiTagSize)); |
| 7012 | __ sub(mask, mask, Operand(1)); |
| 7013 | |
| 7014 | __ ldr(hash, FieldMemOperand(key, String::kHashFieldOffset)); |
| 7015 | |
| 7016 | __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex); |
| 7017 | |
| 7018 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 7019 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7020 | // Capacity is smi 2^n. |
| 7021 | if (i > 0) { |
| 7022 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 7023 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 7024 | // shifted in the following and instruction. |
| 7025 | ASSERT(StringDictionary::GetProbeOffset(i) < |
| 7026 | 1 << (32 - String::kHashFieldOffset)); |
| 7027 | __ add(index, hash, Operand( |
| 7028 | StringDictionary::GetProbeOffset(i) << String::kHashShift)); |
| 7029 | } else { |
| 7030 | __ mov(index, Operand(hash)); |
| 7031 | } |
| 7032 | __ and_(index, mask, Operand(index, LSR, String::kHashShift)); |
| 7033 | |
| 7034 | // Scale the index by multiplying by the entry size. |
| 7035 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7036 | __ add(index, index, Operand(index, LSL, 1)); // index *= 3. |
| 7037 | |
| 7038 | ASSERT_EQ(kSmiTagSize, 1); |
| 7039 | __ add(index, dictionary, Operand(index, LSL, 2)); |
| 7040 | __ ldr(entry_key, FieldMemOperand(index, kElementsStartOffset)); |
| 7041 | |
| 7042 | // Having undefined at this place means the name is not contained. |
| 7043 | __ cmp(entry_key, Operand(undefined)); |
| 7044 | __ b(eq, ¬_in_dictionary); |
| 7045 | |
| 7046 | // Stop if found the property. |
| 7047 | __ cmp(entry_key, Operand(key)); |
| 7048 | __ b(eq, &in_dictionary); |
| 7049 | |
| 7050 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
| 7051 | // Check if the entry name is not a symbol. |
| 7052 | __ ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset)); |
| 7053 | __ ldrb(entry_key, |
| 7054 | FieldMemOperand(entry_key, Map::kInstanceTypeOffset)); |
| 7055 | __ tst(entry_key, Operand(kIsSymbolMask)); |
| 7056 | __ b(eq, &maybe_in_dictionary); |
| 7057 | } |
| 7058 | } |
| 7059 | |
| 7060 | __ bind(&maybe_in_dictionary); |
| 7061 | // If we are doing negative lookup then probing failure should be |
| 7062 | // treated as a lookup success. For positive lookup probing failure |
| 7063 | // should be treated as lookup failure. |
| 7064 | if (mode_ == POSITIVE_LOOKUP) { |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 7065 | __ mov(result, Operand::Zero()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7066 | __ Ret(); |
| 7067 | } |
| 7068 | |
| 7069 | __ bind(&in_dictionary); |
| 7070 | __ mov(result, Operand(1)); |
| 7071 | __ Ret(); |
| 7072 | |
| 7073 | __ bind(¬_in_dictionary); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 7074 | __ mov(result, Operand::Zero()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7075 | __ Ret(); |
| 7076 | } |
| 7077 | |
| 7078 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7079 | struct AheadOfTimeWriteBarrierStubList { |
| 7080 | Register object, value, address; |
| 7081 | RememberedSetAction action; |
| 7082 | }; |
| 7083 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7084 | #define REG(Name) { kRegister_ ## Name ## _Code } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7085 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7086 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7087 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7088 | { REG(r6), REG(r4), REG(r7), EMIT_REMEMBERED_SET }, |
| 7089 | { REG(r6), REG(r2), REG(r7), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7090 | // Used in CompileArrayPushCall. |
| 7091 | // Also used in StoreIC::GenerateNormal via GenerateDictionaryStore. |
| 7092 | // Also used in KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7093 | { REG(r3), REG(r4), REG(r5), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7094 | // Used in CompileStoreGlobal. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7095 | { REG(r4), REG(r1), REG(r2), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7096 | // Used in StoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7097 | { REG(r1), REG(r2), REG(r3), EMIT_REMEMBERED_SET }, |
| 7098 | { REG(r3), REG(r2), REG(r1), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7099 | // Used in KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7100 | { REG(r2), REG(r1), REG(r3), EMIT_REMEMBERED_SET }, |
| 7101 | { REG(r3), REG(r1), REG(r2), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7102 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7103 | { REG(r3), REG(r2), REG(r4), EMIT_REMEMBERED_SET }, |
| 7104 | { REG(r2), REG(r3), REG(r4), EMIT_REMEMBERED_SET }, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame^] | 7105 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7106 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7107 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7108 | { REG(r2), REG(r3), REG(r9), EMIT_REMEMBERED_SET }, |
| 7109 | { REG(r2), REG(r3), REG(r9), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7110 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7111 | { REG(r6), REG(r2), REG(r0), EMIT_REMEMBERED_SET }, |
| 7112 | { REG(r2), REG(r6), REG(r9), EMIT_REMEMBERED_SET }, |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7113 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7114 | { REG(r5), REG(r0), REG(r6), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7115 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7116 | { 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] | 7117 | }; |
| 7118 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7119 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7120 | |
| 7121 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7122 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7123 | !entry->object.is(no_reg); |
| 7124 | entry++) { |
| 7125 | if (object_.is(entry->object) && |
| 7126 | value_.is(entry->value) && |
| 7127 | address_.is(entry->address) && |
| 7128 | remembered_set_action_ == entry->action && |
| 7129 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7130 | return true; |
| 7131 | } |
| 7132 | } |
| 7133 | return false; |
| 7134 | } |
| 7135 | |
| 7136 | |
| 7137 | bool StoreBufferOverflowStub::IsPregenerated() { |
| 7138 | return save_doubles_ == kDontSaveFPRegs || ISOLATE->fp_stubs_generated(); |
| 7139 | } |
| 7140 | |
| 7141 | |
| 7142 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime() { |
| 7143 | StoreBufferOverflowStub stub1(kDontSaveFPRegs); |
| 7144 | stub1.GetCode()->set_is_pregenerated(true); |
| 7145 | } |
| 7146 | |
| 7147 | |
| 7148 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7149 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7150 | !entry->object.is(no_reg); |
| 7151 | entry++) { |
| 7152 | RecordWriteStub stub(entry->object, |
| 7153 | entry->value, |
| 7154 | entry->address, |
| 7155 | entry->action, |
| 7156 | kDontSaveFPRegs); |
| 7157 | stub.GetCode()->set_is_pregenerated(true); |
| 7158 | } |
| 7159 | } |
| 7160 | |
| 7161 | |
| 7162 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7163 | // the value has just been written into the object, now this stub makes sure |
| 7164 | // we keep the GC informed. The word in the object where the value has been |
| 7165 | // written is in the address register. |
| 7166 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7167 | Label skip_to_incremental_noncompacting; |
| 7168 | Label skip_to_incremental_compacting; |
| 7169 | |
| 7170 | // The first two instructions are generated with labels so as to get the |
| 7171 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7172 | // forth between a compare instructions (a nop in this position) and the |
| 7173 | // real branch when we start and stop incremental heap marking. |
| 7174 | // See RecordWriteStub::Patch for details. |
| 7175 | __ b(&skip_to_incremental_noncompacting); |
| 7176 | __ b(&skip_to_incremental_compacting); |
| 7177 | |
| 7178 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7179 | __ RememberedSetHelper(object_, |
| 7180 | address_, |
| 7181 | value_, |
| 7182 | save_fp_regs_mode_, |
| 7183 | MacroAssembler::kReturnAtEnd); |
| 7184 | } |
| 7185 | __ Ret(); |
| 7186 | |
| 7187 | __ bind(&skip_to_incremental_noncompacting); |
| 7188 | GenerateIncremental(masm, INCREMENTAL); |
| 7189 | |
| 7190 | __ bind(&skip_to_incremental_compacting); |
| 7191 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7192 | |
| 7193 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7194 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7195 | ASSERT(Assembler::GetBranchOffset(masm->instr_at(0)) < (1 << 12)); |
| 7196 | ASSERT(Assembler::GetBranchOffset(masm->instr_at(4)) < (1 << 12)); |
| 7197 | PatchBranchIntoNop(masm, 0); |
| 7198 | PatchBranchIntoNop(masm, Assembler::kInstrSize); |
| 7199 | } |
| 7200 | |
| 7201 | |
| 7202 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7203 | regs_.Save(masm); |
| 7204 | |
| 7205 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7206 | Label dont_need_remembered_set; |
| 7207 | |
| 7208 | __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0)); |
| 7209 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7210 | regs_.scratch0(), |
| 7211 | &dont_need_remembered_set); |
| 7212 | |
| 7213 | __ CheckPageFlag(regs_.object(), |
| 7214 | regs_.scratch0(), |
| 7215 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7216 | ne, |
| 7217 | &dont_need_remembered_set); |
| 7218 | |
| 7219 | // First notify the incremental marker if necessary, then update the |
| 7220 | // remembered set. |
| 7221 | CheckNeedsToInformIncrementalMarker( |
| 7222 | masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode); |
| 7223 | InformIncrementalMarker(masm, mode); |
| 7224 | regs_.Restore(masm); |
| 7225 | __ RememberedSetHelper(object_, |
| 7226 | address_, |
| 7227 | value_, |
| 7228 | save_fp_regs_mode_, |
| 7229 | MacroAssembler::kReturnAtEnd); |
| 7230 | |
| 7231 | __ bind(&dont_need_remembered_set); |
| 7232 | } |
| 7233 | |
| 7234 | CheckNeedsToInformIncrementalMarker( |
| 7235 | masm, kReturnOnNoNeedToInformIncrementalMarker, mode); |
| 7236 | InformIncrementalMarker(masm, mode); |
| 7237 | regs_.Restore(masm); |
| 7238 | __ Ret(); |
| 7239 | } |
| 7240 | |
| 7241 | |
| 7242 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7243 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7244 | int argument_count = 3; |
| 7245 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7246 | Register address = |
| 7247 | r0.is(regs_.address()) ? regs_.scratch0() : regs_.address(); |
| 7248 | ASSERT(!address.is(regs_.object())); |
| 7249 | ASSERT(!address.is(r0)); |
| 7250 | __ Move(address, regs_.address()); |
| 7251 | __ Move(r0, regs_.object()); |
| 7252 | if (mode == INCREMENTAL_COMPACTION) { |
| 7253 | __ Move(r1, address); |
| 7254 | } else { |
| 7255 | ASSERT(mode == INCREMENTAL); |
| 7256 | __ ldr(r1, MemOperand(address, 0)); |
| 7257 | } |
| 7258 | __ mov(r2, Operand(ExternalReference::isolate_address())); |
| 7259 | |
| 7260 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7261 | if (mode == INCREMENTAL_COMPACTION) { |
| 7262 | __ CallCFunction( |
| 7263 | ExternalReference::incremental_evacuation_record_write_function( |
| 7264 | masm->isolate()), |
| 7265 | argument_count); |
| 7266 | } else { |
| 7267 | ASSERT(mode == INCREMENTAL); |
| 7268 | __ CallCFunction( |
| 7269 | ExternalReference::incremental_marking_record_write_function( |
| 7270 | masm->isolate()), |
| 7271 | argument_count); |
| 7272 | } |
| 7273 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7274 | } |
| 7275 | |
| 7276 | |
| 7277 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7278 | MacroAssembler* masm, |
| 7279 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7280 | Mode mode) { |
| 7281 | Label on_black; |
| 7282 | Label need_incremental; |
| 7283 | Label need_incremental_pop_scratch; |
| 7284 | |
| 7285 | // Let's look at the color of the object: If it is not black we don't have |
| 7286 | // to inform the incremental marker. |
| 7287 | __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black); |
| 7288 | |
| 7289 | regs_.Restore(masm); |
| 7290 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7291 | __ RememberedSetHelper(object_, |
| 7292 | address_, |
| 7293 | value_, |
| 7294 | save_fp_regs_mode_, |
| 7295 | MacroAssembler::kReturnAtEnd); |
| 7296 | } else { |
| 7297 | __ Ret(); |
| 7298 | } |
| 7299 | |
| 7300 | __ bind(&on_black); |
| 7301 | |
| 7302 | // Get the value from the slot. |
| 7303 | __ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0)); |
| 7304 | |
| 7305 | if (mode == INCREMENTAL_COMPACTION) { |
| 7306 | Label ensure_not_white; |
| 7307 | |
| 7308 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7309 | regs_.scratch1(), // Scratch. |
| 7310 | MemoryChunk::kEvacuationCandidateMask, |
| 7311 | eq, |
| 7312 | &ensure_not_white); |
| 7313 | |
| 7314 | __ CheckPageFlag(regs_.object(), |
| 7315 | regs_.scratch1(), // Scratch. |
| 7316 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7317 | eq, |
| 7318 | &need_incremental); |
| 7319 | |
| 7320 | __ bind(&ensure_not_white); |
| 7321 | } |
| 7322 | |
| 7323 | // We need extra registers for this, so we push the object and the address |
| 7324 | // register temporarily. |
| 7325 | __ Push(regs_.object(), regs_.address()); |
| 7326 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7327 | regs_.scratch1(), // Scratch. |
| 7328 | regs_.object(), // Scratch. |
| 7329 | regs_.address(), // Scratch. |
| 7330 | &need_incremental_pop_scratch); |
| 7331 | __ Pop(regs_.object(), regs_.address()); |
| 7332 | |
| 7333 | regs_.Restore(masm); |
| 7334 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7335 | __ RememberedSetHelper(object_, |
| 7336 | address_, |
| 7337 | value_, |
| 7338 | save_fp_regs_mode_, |
| 7339 | MacroAssembler::kReturnAtEnd); |
| 7340 | } else { |
| 7341 | __ Ret(); |
| 7342 | } |
| 7343 | |
| 7344 | __ bind(&need_incremental_pop_scratch); |
| 7345 | __ Pop(regs_.object(), regs_.address()); |
| 7346 | |
| 7347 | __ bind(&need_incremental); |
| 7348 | |
| 7349 | // Fall through when we need to inform the incremental marker. |
| 7350 | } |
| 7351 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7352 | |
| 7353 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7354 | // ----------- S t a t e ------------- |
| 7355 | // -- r0 : element value to store |
| 7356 | // -- r1 : array literal |
| 7357 | // -- r2 : map of array literal |
| 7358 | // -- r3 : element index as smi |
| 7359 | // -- r4 : array literal index in function as smi |
| 7360 | // ----------------------------------- |
| 7361 | |
| 7362 | Label element_done; |
| 7363 | Label double_elements; |
| 7364 | Label smi_element; |
| 7365 | Label slow_elements; |
| 7366 | Label fast_elements; |
| 7367 | |
| 7368 | __ CheckFastElements(r2, r5, &double_elements); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame^] | 7369 | // FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7370 | __ JumpIfSmi(r0, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame^] | 7371 | __ CheckFastSmiElements(r2, r5, &fast_elements); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7372 | |
| 7373 | // Store into the array literal requires a elements transition. Call into |
| 7374 | // the runtime. |
| 7375 | __ bind(&slow_elements); |
| 7376 | // call. |
| 7377 | __ Push(r1, r3, r0); |
| 7378 | __ ldr(r5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7379 | __ ldr(r5, FieldMemOperand(r5, JSFunction::kLiteralsOffset)); |
| 7380 | __ Push(r5, r4); |
| 7381 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7382 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame^] | 7383 | // 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] | 7384 | __ bind(&fast_elements); |
| 7385 | __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 7386 | __ add(r6, r5, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 7387 | __ add(r6, r6, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 7388 | __ str(r0, MemOperand(r6, 0)); |
| 7389 | // Update the write barrier for the array store. |
| 7390 | __ RecordWrite(r5, r6, r0, kLRHasNotBeenSaved, kDontSaveFPRegs, |
| 7391 | EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); |
| 7392 | __ Ret(); |
| 7393 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame^] | 7394 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7395 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7396 | __ bind(&smi_element); |
| 7397 | __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 7398 | __ add(r6, r5, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 7399 | __ str(r0, FieldMemOperand(r6, FixedArray::kHeaderSize)); |
| 7400 | __ Ret(); |
| 7401 | |
| 7402 | // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS. |
| 7403 | __ bind(&double_elements); |
| 7404 | __ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset)); |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 7405 | __ StoreNumberToDoubleElements(r0, r3, r1, r5, r6, r7, r9, r2, |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7406 | &slow_elements); |
| 7407 | __ Ret(); |
| 7408 | } |
| 7409 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7410 | #undef __ |
| 7411 | |
| 7412 | } } // namespace v8::internal |
| 7413 | |
| 7414 | #endif // V8_TARGET_ARCH_ARM |