danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +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_MIPS) |
| 31 | |
| 32 | #include "bootstrapper.h" |
| 33 | #include "code-stubs.h" |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 34 | #include "codegen.h" |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 35 | #include "regexp-macro-assembler.h" |
| 36 | |
| 37 | namespace v8 { |
| 38 | namespace internal { |
| 39 | |
| 40 | |
| 41 | #define __ ACCESS_MASM(masm) |
| 42 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 43 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, |
| 44 | Label* slow, |
| 45 | Condition cc, |
| 46 | bool never_nan_nan); |
| 47 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 48 | Register lhs, |
| 49 | Register rhs, |
| 50 | Label* rhs_not_nan, |
| 51 | Label* slow, |
| 52 | bool strict); |
| 53 | static void EmitTwoNonNanDoubleComparison(MacroAssembler* masm, Condition cc); |
| 54 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 55 | Register lhs, |
| 56 | Register rhs); |
| 57 | |
| 58 | |
| 59 | // Check if the operand is a heap number. |
| 60 | static void EmitCheckForHeapNumber(MacroAssembler* masm, Register operand, |
| 61 | Register scratch1, Register scratch2, |
| 62 | Label* not_a_heap_number) { |
| 63 | __ lw(scratch1, FieldMemOperand(operand, HeapObject::kMapOffset)); |
| 64 | __ LoadRoot(scratch2, Heap::kHeapNumberMapRootIndex); |
| 65 | __ Branch(not_a_heap_number, ne, scratch1, Operand(scratch2)); |
| 66 | } |
| 67 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 68 | |
| 69 | void ToNumberStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 70 | // The ToNumber stub takes one argument in a0. |
| 71 | Label check_heap_number, call_builtin; |
| 72 | __ JumpIfNotSmi(a0, &check_heap_number); |
| 73 | __ mov(v0, a0); |
| 74 | __ Ret(); |
| 75 | |
| 76 | __ bind(&check_heap_number); |
| 77 | EmitCheckForHeapNumber(masm, a0, a1, t0, &call_builtin); |
| 78 | __ mov(v0, a0); |
| 79 | __ Ret(); |
| 80 | |
| 81 | __ bind(&call_builtin); |
| 82 | __ push(a0); |
| 83 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | |
| 87 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 88 | // Create a new closure from the given function info in new |
| 89 | // space. Set the context to the current context in cp. |
| 90 | Label gc; |
| 91 | |
| 92 | // Pop the function info from the stack. |
| 93 | __ pop(a3); |
| 94 | |
| 95 | // Attempt to allocate new JSFunction in new space. |
| 96 | __ AllocateInNewSpace(JSFunction::kSize, |
| 97 | v0, |
| 98 | a1, |
| 99 | a2, |
| 100 | &gc, |
| 101 | TAG_OBJECT); |
| 102 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 103 | int map_index = (language_mode_ == CLASSIC_MODE) |
| 104 | ? Context::FUNCTION_MAP_INDEX |
| 105 | : Context::STRICT_MODE_FUNCTION_MAP_INDEX; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 106 | |
| 107 | // Compute the function map in the current global context and set that |
| 108 | // as the map of the allocated object. |
| 109 | __ lw(a2, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 110 | __ lw(a2, FieldMemOperand(a2, GlobalObject::kGlobalContextOffset)); |
| 111 | __ lw(a2, MemOperand(a2, Context::SlotOffset(map_index))); |
| 112 | __ sw(a2, FieldMemOperand(v0, HeapObject::kMapOffset)); |
| 113 | |
| 114 | // Initialize the rest of the function. We don't have to update the |
| 115 | // write barrier because the allocated object is in new space. |
| 116 | __ LoadRoot(a1, Heap::kEmptyFixedArrayRootIndex); |
| 117 | __ LoadRoot(a2, Heap::kTheHoleValueRootIndex); |
| 118 | __ LoadRoot(t0, Heap::kUndefinedValueRootIndex); |
| 119 | __ sw(a1, FieldMemOperand(v0, JSObject::kPropertiesOffset)); |
| 120 | __ sw(a1, FieldMemOperand(v0, JSObject::kElementsOffset)); |
| 121 | __ sw(a2, FieldMemOperand(v0, JSFunction::kPrototypeOrInitialMapOffset)); |
| 122 | __ sw(a3, FieldMemOperand(v0, JSFunction::kSharedFunctionInfoOffset)); |
| 123 | __ sw(cp, FieldMemOperand(v0, JSFunction::kContextOffset)); |
| 124 | __ sw(a1, FieldMemOperand(v0, JSFunction::kLiteralsOffset)); |
| 125 | __ sw(t0, FieldMemOperand(v0, JSFunction::kNextFunctionLinkOffset)); |
| 126 | |
| 127 | // Initialize the code pointer in the function to be the one |
| 128 | // found in the shared function info object. |
| 129 | __ lw(a3, FieldMemOperand(a3, SharedFunctionInfo::kCodeOffset)); |
| 130 | __ Addu(a3, a3, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 131 | __ sw(a3, FieldMemOperand(v0, JSFunction::kCodeEntryOffset)); |
| 132 | |
| 133 | // Return result. The argument function info has been popped already. |
| 134 | __ Ret(); |
| 135 | |
| 136 | // Create a new closure through the slower runtime call. |
| 137 | __ bind(&gc); |
| 138 | __ LoadRoot(t0, Heap::kFalseValueRootIndex); |
| 139 | __ Push(cp, a3, t0); |
| 140 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
| 144 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 145 | // Try to allocate the context in new space. |
| 146 | Label gc; |
| 147 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 148 | |
| 149 | // Attempt to allocate the context in new space. |
| 150 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
| 151 | v0, |
| 152 | a1, |
| 153 | a2, |
| 154 | &gc, |
| 155 | TAG_OBJECT); |
| 156 | |
| 157 | // Load the function from the stack. |
| 158 | __ lw(a3, MemOperand(sp, 0)); |
| 159 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 160 | // Set up the object header. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 161 | __ LoadRoot(a1, Heap::kFunctionContextMapRootIndex); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 162 | __ li(a2, Operand(Smi::FromInt(length))); |
| 163 | __ sw(a2, FieldMemOperand(v0, FixedArray::kLengthOffset)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 164 | __ sw(a1, FieldMemOperand(v0, HeapObject::kMapOffset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 165 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 166 | // Set up the fixed slots, copy the global object from the previous context. |
| 167 | __ lw(a2, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 168 | __ li(a1, Operand(Smi::FromInt(0))); |
| 169 | __ sw(a3, MemOperand(v0, Context::SlotOffset(Context::CLOSURE_INDEX))); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 170 | __ sw(cp, MemOperand(v0, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 171 | __ sw(a1, MemOperand(v0, Context::SlotOffset(Context::EXTENSION_INDEX))); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 172 | __ sw(a2, MemOperand(v0, Context::SlotOffset(Context::GLOBAL_INDEX))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 173 | |
| 174 | // Initialize the rest of the slots to undefined. |
| 175 | __ LoadRoot(a1, Heap::kUndefinedValueRootIndex); |
| 176 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
| 177 | __ sw(a1, MemOperand(v0, Context::SlotOffset(i))); |
| 178 | } |
| 179 | |
| 180 | // Remove the on-stack argument and return. |
| 181 | __ mov(cp, v0); |
| 182 | __ Pop(); |
| 183 | __ Ret(); |
| 184 | |
| 185 | // Need to collect. Call into runtime system. |
| 186 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 187 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 191 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 192 | // Stack layout on entry: |
| 193 | // |
| 194 | // [sp]: function. |
| 195 | // [sp + kPointerSize]: serialized scope info |
| 196 | |
| 197 | // Try to allocate the context in new space. |
| 198 | Label gc; |
| 199 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 200 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
| 201 | v0, a1, a2, &gc, TAG_OBJECT); |
| 202 | |
| 203 | // Load the function from the stack. |
| 204 | __ lw(a3, MemOperand(sp, 0)); |
| 205 | |
| 206 | // Load the serialized scope info from the stack. |
| 207 | __ lw(a1, MemOperand(sp, 1 * kPointerSize)); |
| 208 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 209 | // Set up the object header. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 210 | __ LoadRoot(a2, Heap::kBlockContextMapRootIndex); |
| 211 | __ sw(a2, FieldMemOperand(v0, HeapObject::kMapOffset)); |
| 212 | __ li(a2, Operand(Smi::FromInt(length))); |
| 213 | __ sw(a2, FieldMemOperand(v0, FixedArray::kLengthOffset)); |
| 214 | |
| 215 | // If this block context is nested in the global context we get a smi |
| 216 | // sentinel instead of a function. The block context should get the |
| 217 | // canonical empty function of the global context as its closure which |
| 218 | // we still have to look up. |
| 219 | Label after_sentinel; |
| 220 | __ JumpIfNotSmi(a3, &after_sentinel); |
| 221 | if (FLAG_debug_code) { |
| 222 | const char* message = "Expected 0 as a Smi sentinel"; |
| 223 | __ Assert(eq, message, a3, Operand(zero_reg)); |
| 224 | } |
| 225 | __ lw(a3, GlobalObjectOperand()); |
| 226 | __ lw(a3, FieldMemOperand(a3, GlobalObject::kGlobalContextOffset)); |
| 227 | __ lw(a3, ContextOperand(a3, Context::CLOSURE_INDEX)); |
| 228 | __ bind(&after_sentinel); |
| 229 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 230 | // Set up the fixed slots, copy the global object from the previous context. |
| 231 | __ lw(a2, ContextOperand(cp, Context::GLOBAL_INDEX)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 232 | __ sw(a3, ContextOperand(v0, Context::CLOSURE_INDEX)); |
| 233 | __ sw(cp, ContextOperand(v0, Context::PREVIOUS_INDEX)); |
| 234 | __ sw(a1, ContextOperand(v0, Context::EXTENSION_INDEX)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 235 | __ sw(a2, ContextOperand(v0, Context::GLOBAL_INDEX)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 236 | |
| 237 | // Initialize the rest of the slots to the hole value. |
| 238 | __ LoadRoot(a1, Heap::kTheHoleValueRootIndex); |
| 239 | for (int i = 0; i < slots_; i++) { |
| 240 | __ sw(a1, ContextOperand(v0, i + Context::MIN_CONTEXT_SLOTS)); |
| 241 | } |
| 242 | |
| 243 | // Remove the on-stack argument and return. |
| 244 | __ mov(cp, v0); |
| 245 | __ Addu(sp, sp, Operand(2 * kPointerSize)); |
| 246 | __ Ret(); |
| 247 | |
| 248 | // Need to collect. Call into runtime system. |
| 249 | __ bind(&gc); |
| 250 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 251 | } |
| 252 | |
| 253 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 254 | static void GenerateFastCloneShallowArrayCommon( |
| 255 | MacroAssembler* masm, |
| 256 | int length, |
| 257 | FastCloneShallowArrayStub::Mode mode, |
| 258 | Label* fail) { |
| 259 | // Registers on entry: |
| 260 | // a3: boilerplate literal array. |
| 261 | ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +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; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +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 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 270 | int size = JSArray::kSize + elements_size; |
| 271 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +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 | v0, |
| 276 | a1, |
| 277 | a2, |
| 278 | fail, |
| 279 | TAG_OBJECT); |
| 280 | |
| 281 | // Copy the JS array part. |
| 282 | for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
| 283 | if ((i != JSArray::kElementsOffset) || (length == 0)) { |
| 284 | __ lw(a1, FieldMemOperand(a3, i)); |
| 285 | __ sw(a1, FieldMemOperand(v0, i)); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | if (length > 0) { |
| 290 | // Get hold of the elements array of the boilerplate and setup the |
| 291 | // elements pointer in the resulting object. |
| 292 | __ lw(a3, FieldMemOperand(a3, JSArray::kElementsOffset)); |
| 293 | __ Addu(a2, v0, Operand(JSArray::kSize)); |
| 294 | __ sw(a2, FieldMemOperand(v0, JSArray::kElementsOffset)); |
| 295 | |
| 296 | // Copy the elements array. |
| 297 | ASSERT((elements_size % kPointerSize) == 0); |
| 298 | __ CopyFields(a2, a3, a1.bit(), elements_size / kPointerSize); |
| 299 | } |
| 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 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 309 | // Load boilerplate object into r3 and check if we need to create a |
| 310 | // boilerplate. |
| 311 | Label slow_case; |
| 312 | __ lw(a3, MemOperand(sp, 2 * kPointerSize)); |
| 313 | __ lw(a0, MemOperand(sp, 1 * kPointerSize)); |
| 314 | __ Addu(a3, a3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 315 | __ sll(t0, a0, kPointerSizeLog2 - kSmiTagSize); |
| 316 | __ Addu(t0, a3, t0); |
| 317 | __ lw(a3, MemOperand(t0)); |
| 318 | __ LoadRoot(t1, Heap::kUndefinedValueRootIndex); |
| 319 | __ Branch(&slow_case, eq, a3, Operand(t1)); |
| 320 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 321 | FastCloneShallowArrayStub::Mode mode = mode_; |
| 322 | if (mode == CLONE_ANY_ELEMENTS) { |
| 323 | Label double_elements, check_fast_elements; |
| 324 | __ lw(v0, FieldMemOperand(a3, JSArray::kElementsOffset)); |
| 325 | __ lw(v0, FieldMemOperand(v0, HeapObject::kMapOffset)); |
| 326 | __ LoadRoot(t1, Heap::kFixedCOWArrayMapRootIndex); |
| 327 | __ Branch(&check_fast_elements, ne, v0, Operand(t1)); |
| 328 | GenerateFastCloneShallowArrayCommon(masm, 0, |
| 329 | COPY_ON_WRITE_ELEMENTS, &slow_case); |
| 330 | // Return and remove the on-stack parameters. |
| 331 | __ DropAndRet(3); |
| 332 | |
| 333 | __ bind(&check_fast_elements); |
| 334 | __ LoadRoot(t1, Heap::kFixedArrayMapRootIndex); |
| 335 | __ Branch(&double_elements, ne, v0, Operand(t1)); |
| 336 | GenerateFastCloneShallowArrayCommon(masm, length_, |
| 337 | CLONE_ELEMENTS, &slow_case); |
| 338 | // Return and remove the on-stack parameters. |
| 339 | __ DropAndRet(3); |
| 340 | |
| 341 | __ bind(&double_elements); |
| 342 | mode = CLONE_DOUBLE_ELEMENTS; |
| 343 | // Fall through to generate the code to handle double elements. |
| 344 | } |
| 345 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 346 | if (FLAG_debug_code) { |
| 347 | const char* message; |
| 348 | Heap::RootListIndex expected_map_index; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 349 | if (mode == CLONE_ELEMENTS) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 350 | message = "Expected (writable) fixed array"; |
| 351 | expected_map_index = Heap::kFixedArrayMapRootIndex; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 352 | } else if (mode == CLONE_DOUBLE_ELEMENTS) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 353 | message = "Expected (writable) fixed double array"; |
| 354 | expected_map_index = Heap::kFixedDoubleArrayMapRootIndex; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 355 | } else { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 356 | ASSERT(mode == COPY_ON_WRITE_ELEMENTS); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 357 | message = "Expected copy-on-write fixed array"; |
| 358 | expected_map_index = Heap::kFixedCOWArrayMapRootIndex; |
| 359 | } |
| 360 | __ push(a3); |
| 361 | __ lw(a3, FieldMemOperand(a3, JSArray::kElementsOffset)); |
| 362 | __ lw(a3, FieldMemOperand(a3, HeapObject::kMapOffset)); |
| 363 | __ LoadRoot(at, expected_map_index); |
| 364 | __ Assert(eq, message, a3, Operand(at)); |
| 365 | __ pop(a3); |
| 366 | } |
| 367 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 368 | GenerateFastCloneShallowArrayCommon(masm, length_, mode, &slow_case); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 369 | |
| 370 | // Return and remove the on-stack parameters. |
| 371 | __ Addu(sp, sp, Operand(3 * kPointerSize)); |
| 372 | __ Ret(); |
| 373 | |
| 374 | __ bind(&slow_case); |
| 375 | __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +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 a3 and check if we need to create a |
| 388 | // boilerplate. |
| 389 | Label slow_case; |
| 390 | __ lw(a3, MemOperand(sp, 3 * kPointerSize)); |
| 391 | __ lw(a0, MemOperand(sp, 2 * kPointerSize)); |
| 392 | __ Addu(a3, a3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 393 | __ sll(t0, a0, kPointerSizeLog2 - kSmiTagSize); |
| 394 | __ Addu(a3, t0, a3); |
| 395 | __ lw(a3, MemOperand(a3)); |
| 396 | __ LoadRoot(t0, Heap::kUndefinedValueRootIndex); |
| 397 | __ Branch(&slow_case, eq, a3, Operand(t0)); |
| 398 | |
| 399 | // Check that the boilerplate contains only fast properties and we can |
| 400 | // statically determine the instance size. |
| 401 | int size = JSObject::kHeaderSize + length_ * kPointerSize; |
| 402 | __ lw(a0, FieldMemOperand(a3, HeapObject::kMapOffset)); |
| 403 | __ lbu(a0, FieldMemOperand(a0, Map::kInstanceSizeOffset)); |
| 404 | __ Branch(&slow_case, ne, a0, Operand(size >> kPointerSizeLog2)); |
| 405 | |
| 406 | // Allocate the JS object and copy header together with all in-object |
| 407 | // properties from the boilerplate. |
| 408 | __ AllocateInNewSpace(size, a0, a1, a2, &slow_case, TAG_OBJECT); |
| 409 | for (int i = 0; i < size; i += kPointerSize) { |
| 410 | __ lw(a1, FieldMemOperand(a3, i)); |
| 411 | __ sw(a1, FieldMemOperand(a0, i)); |
| 412 | } |
| 413 | |
| 414 | // Return and remove the on-stack parameters. |
| 415 | __ Drop(4); |
| 416 | __ Ret(USE_DELAY_SLOT); |
| 417 | __ mov(v0, a0); |
| 418 | |
| 419 | __ bind(&slow_case); |
| 420 | __ TailCallRuntime(Runtime::kCreateObjectLiteralShallow, 4, 1); |
| 421 | } |
| 422 | |
| 423 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 424 | // Takes a Smi and converts to an IEEE 64 bit floating point value in two |
| 425 | // registers. The format is 1 sign bit, 11 exponent bits (biased 1023) and |
| 426 | // 52 fraction bits (20 in the first word, 32 in the second). Zeros is a |
| 427 | // scratch register. Destroys the source register. No GC occurs during this |
| 428 | // stub so you don't have to set up the frame. |
| 429 | class ConvertToDoubleStub : public CodeStub { |
| 430 | public: |
| 431 | ConvertToDoubleStub(Register result_reg_1, |
| 432 | Register result_reg_2, |
| 433 | Register source_reg, |
| 434 | Register scratch_reg) |
| 435 | : result1_(result_reg_1), |
| 436 | result2_(result_reg_2), |
| 437 | source_(source_reg), |
| 438 | zeros_(scratch_reg) { } |
| 439 | |
| 440 | private: |
| 441 | Register result1_; |
| 442 | Register result2_; |
| 443 | Register source_; |
| 444 | Register zeros_; |
| 445 | |
| 446 | // Minor key encoding in 16 bits. |
| 447 | class ModeBits: public BitField<OverwriteMode, 0, 2> {}; |
| 448 | class OpBits: public BitField<Token::Value, 2, 14> {}; |
| 449 | |
| 450 | Major MajorKey() { return ConvertToDouble; } |
| 451 | int MinorKey() { |
| 452 | // Encode the parameters in a unique 16 bit value. |
| 453 | return result1_.code() + |
| 454 | (result2_.code() << 4) + |
| 455 | (source_.code() << 8) + |
| 456 | (zeros_.code() << 12); |
| 457 | } |
| 458 | |
| 459 | void Generate(MacroAssembler* masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 460 | }; |
| 461 | |
| 462 | |
| 463 | void ConvertToDoubleStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 464 | #ifndef BIG_ENDIAN_FLOATING_POINT |
| 465 | Register exponent = result1_; |
| 466 | Register mantissa = result2_; |
| 467 | #else |
| 468 | Register exponent = result2_; |
| 469 | Register mantissa = result1_; |
| 470 | #endif |
| 471 | Label not_special; |
| 472 | // Convert from Smi to integer. |
| 473 | __ sra(source_, source_, kSmiTagSize); |
| 474 | // Move sign bit from source to destination. This works because the sign bit |
| 475 | // in the exponent word of the double has the same position and polarity as |
| 476 | // the 2's complement sign bit in a Smi. |
| 477 | STATIC_ASSERT(HeapNumber::kSignMask == 0x80000000u); |
| 478 | __ And(exponent, source_, Operand(HeapNumber::kSignMask)); |
| 479 | // Subtract from 0 if source was negative. |
| 480 | __ subu(at, zero_reg, source_); |
| 481 | __ movn(source_, at, exponent); |
| 482 | |
| 483 | // We have -1, 0 or 1, which we treat specially. Register source_ contains |
| 484 | // absolute value: it is either equal to 1 (special case of -1 and 1), |
| 485 | // greater than 1 (not a special case) or less than 1 (special case of 0). |
| 486 | __ Branch(¬_special, gt, source_, Operand(1)); |
| 487 | |
| 488 | // For 1 or -1 we need to or in the 0 exponent (biased to 1023). |
| 489 | static const uint32_t exponent_word_for_1 = |
| 490 | HeapNumber::kExponentBias << HeapNumber::kExponentShift; |
| 491 | // Safe to use 'at' as dest reg here. |
| 492 | __ Or(at, exponent, Operand(exponent_word_for_1)); |
| 493 | __ movn(exponent, at, source_); // Write exp when source not 0. |
| 494 | // 1, 0 and -1 all have 0 for the second word. |
| 495 | __ mov(mantissa, zero_reg); |
| 496 | __ Ret(); |
| 497 | |
| 498 | __ bind(¬_special); |
| 499 | // Count leading zeros. |
| 500 | // Gets the wrong answer for 0, but we already checked for that case above. |
| 501 | __ clz(zeros_, source_); |
| 502 | // Compute exponent and or it into the exponent register. |
| 503 | // We use mantissa as a scratch register here. |
| 504 | __ li(mantissa, Operand(31 + HeapNumber::kExponentBias)); |
| 505 | __ subu(mantissa, mantissa, zeros_); |
| 506 | __ sll(mantissa, mantissa, HeapNumber::kExponentShift); |
| 507 | __ Or(exponent, exponent, mantissa); |
| 508 | |
| 509 | // Shift up the source chopping the top bit off. |
| 510 | __ Addu(zeros_, zeros_, Operand(1)); |
| 511 | // This wouldn't work for 1.0 or -1.0 as the shift would be 32 which means 0. |
| 512 | __ sllv(source_, source_, zeros_); |
| 513 | // Compute lower part of fraction (last 12 bits). |
| 514 | __ sll(mantissa, source_, HeapNumber::kMantissaBitsInTopWord); |
| 515 | // And the top (top 20 bits). |
| 516 | __ srl(source_, source_, 32 - HeapNumber::kMantissaBitsInTopWord); |
| 517 | __ or_(exponent, exponent, source_); |
| 518 | |
| 519 | __ Ret(); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 523 | void FloatingPointHelper::LoadSmis(MacroAssembler* masm, |
| 524 | FloatingPointHelper::Destination destination, |
| 525 | Register scratch1, |
| 526 | Register scratch2) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 527 | if (CpuFeatures::IsSupported(FPU)) { |
| 528 | CpuFeatures::Scope scope(FPU); |
| 529 | __ sra(scratch1, a0, kSmiTagSize); |
| 530 | __ mtc1(scratch1, f14); |
| 531 | __ cvt_d_w(f14, f14); |
| 532 | __ sra(scratch1, a1, kSmiTagSize); |
| 533 | __ mtc1(scratch1, f12); |
| 534 | __ cvt_d_w(f12, f12); |
| 535 | if (destination == kCoreRegisters) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 536 | __ Move(a2, a3, f14); |
| 537 | __ Move(a0, a1, f12); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 538 | } |
| 539 | } else { |
| 540 | ASSERT(destination == kCoreRegisters); |
| 541 | // Write Smi from a0 to a3 and a2 in double format. |
| 542 | __ mov(scratch1, a0); |
| 543 | ConvertToDoubleStub stub1(a3, a2, scratch1, scratch2); |
| 544 | __ push(ra); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 545 | __ Call(stub1.GetCode()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 546 | // Write Smi from a1 to a1 and a0 in double format. |
| 547 | __ mov(scratch1, a1); |
| 548 | ConvertToDoubleStub stub2(a1, a0, scratch1, scratch2); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 549 | __ Call(stub2.GetCode()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 550 | __ pop(ra); |
| 551 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | |
| 555 | void FloatingPointHelper::LoadOperands( |
| 556 | MacroAssembler* masm, |
| 557 | FloatingPointHelper::Destination destination, |
| 558 | Register heap_number_map, |
| 559 | Register scratch1, |
| 560 | Register scratch2, |
| 561 | Label* slow) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 562 | |
| 563 | // Load right operand (a0) to f12 or a2/a3. |
| 564 | LoadNumber(masm, destination, |
| 565 | a0, f14, a2, a3, heap_number_map, scratch1, scratch2, slow); |
| 566 | |
| 567 | // Load left operand (a1) to f14 or a0/a1. |
| 568 | LoadNumber(masm, destination, |
| 569 | a1, f12, a0, a1, heap_number_map, scratch1, scratch2, slow); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | |
| 573 | void FloatingPointHelper::LoadNumber(MacroAssembler* masm, |
| 574 | Destination destination, |
| 575 | Register object, |
| 576 | FPURegister dst, |
| 577 | Register dst1, |
| 578 | Register dst2, |
| 579 | Register heap_number_map, |
| 580 | Register scratch1, |
| 581 | Register scratch2, |
| 582 | Label* not_number) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 583 | if (FLAG_debug_code) { |
| 584 | __ AbortIfNotRootValue(heap_number_map, |
| 585 | Heap::kHeapNumberMapRootIndex, |
| 586 | "HeapNumberMap register clobbered."); |
| 587 | } |
| 588 | |
| 589 | Label is_smi, done; |
| 590 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 591 | // Smi-check |
| 592 | __ UntagAndJumpIfSmi(scratch1, object, &is_smi); |
| 593 | // Heap number check |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 594 | __ JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_number); |
| 595 | |
| 596 | // Handle loading a double from a heap number. |
| 597 | if (CpuFeatures::IsSupported(FPU) && |
| 598 | destination == kFPURegisters) { |
| 599 | CpuFeatures::Scope scope(FPU); |
| 600 | // Load the double from tagged HeapNumber to double register. |
| 601 | |
| 602 | // ARM uses a workaround here because of the unaligned HeapNumber |
| 603 | // kValueOffset. On MIPS this workaround is built into ldc1 so there's no |
| 604 | // point in generating even more instructions. |
| 605 | __ ldc1(dst, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 606 | } else { |
| 607 | ASSERT(destination == kCoreRegisters); |
| 608 | // Load the double from heap number to dst1 and dst2 in double format. |
| 609 | __ lw(dst1, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 610 | __ lw(dst2, FieldMemOperand(object, |
| 611 | HeapNumber::kValueOffset + kPointerSize)); |
| 612 | } |
| 613 | __ Branch(&done); |
| 614 | |
| 615 | // Handle loading a double from a smi. |
| 616 | __ bind(&is_smi); |
| 617 | if (CpuFeatures::IsSupported(FPU)) { |
| 618 | CpuFeatures::Scope scope(FPU); |
| 619 | // Convert smi to double using FPU instructions. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 620 | __ mtc1(scratch1, dst); |
| 621 | __ cvt_d_w(dst, dst); |
| 622 | if (destination == kCoreRegisters) { |
| 623 | // Load the converted smi to dst1 and dst2 in double format. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 624 | __ Move(dst1, dst2, dst); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 625 | } |
| 626 | } else { |
| 627 | ASSERT(destination == kCoreRegisters); |
| 628 | // Write smi to dst1 and dst2 double format. |
| 629 | __ mov(scratch1, object); |
| 630 | ConvertToDoubleStub stub(dst2, dst1, scratch1, scratch2); |
| 631 | __ push(ra); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 632 | __ Call(stub.GetCode()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 633 | __ pop(ra); |
| 634 | } |
| 635 | |
| 636 | __ bind(&done); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 640 | void FloatingPointHelper::ConvertNumberToInt32(MacroAssembler* masm, |
| 641 | Register object, |
| 642 | Register dst, |
| 643 | Register heap_number_map, |
| 644 | Register scratch1, |
| 645 | Register scratch2, |
| 646 | Register scratch3, |
| 647 | FPURegister double_scratch, |
| 648 | Label* not_number) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 649 | if (FLAG_debug_code) { |
| 650 | __ AbortIfNotRootValue(heap_number_map, |
| 651 | Heap::kHeapNumberMapRootIndex, |
| 652 | "HeapNumberMap register clobbered."); |
| 653 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 654 | Label done; |
| 655 | Label not_in_int32_range; |
| 656 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 657 | __ UntagAndJumpIfSmi(dst, object, &done); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 658 | __ lw(scratch1, FieldMemOperand(object, HeapNumber::kMapOffset)); |
| 659 | __ Branch(not_number, ne, scratch1, Operand(heap_number_map)); |
| 660 | __ ConvertToInt32(object, |
| 661 | dst, |
| 662 | scratch1, |
| 663 | scratch2, |
| 664 | double_scratch, |
| 665 | ¬_in_int32_range); |
| 666 | __ jmp(&done); |
| 667 | |
| 668 | __ bind(¬_in_int32_range); |
| 669 | __ lw(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 670 | __ lw(scratch2, FieldMemOperand(object, HeapNumber::kMantissaOffset)); |
| 671 | |
| 672 | __ EmitOutOfInt32RangeTruncate(dst, |
| 673 | scratch1, |
| 674 | scratch2, |
| 675 | scratch3); |
| 676 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 677 | __ bind(&done); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | |
| 681 | void FloatingPointHelper::ConvertIntToDouble(MacroAssembler* masm, |
| 682 | Register int_scratch, |
| 683 | Destination destination, |
| 684 | FPURegister double_dst, |
| 685 | Register dst1, |
| 686 | Register dst2, |
| 687 | Register scratch2, |
| 688 | FPURegister single_scratch) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 689 | ASSERT(!int_scratch.is(scratch2)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 690 | ASSERT(!int_scratch.is(dst1)); |
| 691 | ASSERT(!int_scratch.is(dst2)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 692 | |
| 693 | Label done; |
| 694 | |
| 695 | if (CpuFeatures::IsSupported(FPU)) { |
| 696 | CpuFeatures::Scope scope(FPU); |
| 697 | __ mtc1(int_scratch, single_scratch); |
| 698 | __ cvt_d_w(double_dst, single_scratch); |
| 699 | if (destination == kCoreRegisters) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 700 | __ Move(dst1, dst2, double_dst); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 701 | } |
| 702 | } else { |
| 703 | Label fewer_than_20_useful_bits; |
| 704 | // Expected output: |
| 705 | // | dst2 | dst1 | |
| 706 | // | s | exp | mantissa | |
| 707 | |
| 708 | // Check for zero. |
| 709 | __ mov(dst2, int_scratch); |
| 710 | __ mov(dst1, int_scratch); |
| 711 | __ Branch(&done, eq, int_scratch, Operand(zero_reg)); |
| 712 | |
| 713 | // Preload the sign of the value. |
| 714 | __ And(dst2, int_scratch, Operand(HeapNumber::kSignMask)); |
| 715 | // Get the absolute value of the object (as an unsigned integer). |
| 716 | Label skip_sub; |
| 717 | __ Branch(&skip_sub, ge, dst2, Operand(zero_reg)); |
| 718 | __ Subu(int_scratch, zero_reg, int_scratch); |
| 719 | __ bind(&skip_sub); |
| 720 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 721 | // Get mantissa[51:20]. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 722 | |
| 723 | // Get the position of the first set bit. |
| 724 | __ clz(dst1, int_scratch); |
| 725 | __ li(scratch2, 31); |
| 726 | __ Subu(dst1, scratch2, dst1); |
| 727 | |
| 728 | // Set the exponent. |
| 729 | __ Addu(scratch2, dst1, Operand(HeapNumber::kExponentBias)); |
| 730 | __ Ins(dst2, scratch2, |
| 731 | HeapNumber::kExponentShift, HeapNumber::kExponentBits); |
| 732 | |
| 733 | // Clear the first non null bit. |
| 734 | __ li(scratch2, Operand(1)); |
| 735 | __ sllv(scratch2, scratch2, dst1); |
| 736 | __ li(at, -1); |
| 737 | __ Xor(scratch2, scratch2, at); |
| 738 | __ And(int_scratch, int_scratch, scratch2); |
| 739 | |
| 740 | // Get the number of bits to set in the lower part of the mantissa. |
| 741 | __ Subu(scratch2, dst1, Operand(HeapNumber::kMantissaBitsInTopWord)); |
| 742 | __ Branch(&fewer_than_20_useful_bits, lt, scratch2, Operand(zero_reg)); |
| 743 | // Set the higher 20 bits of the mantissa. |
| 744 | __ srlv(at, int_scratch, scratch2); |
| 745 | __ or_(dst2, dst2, at); |
| 746 | __ li(at, 32); |
| 747 | __ subu(scratch2, at, scratch2); |
| 748 | __ sllv(dst1, int_scratch, scratch2); |
| 749 | __ Branch(&done); |
| 750 | |
| 751 | __ bind(&fewer_than_20_useful_bits); |
| 752 | __ li(at, HeapNumber::kMantissaBitsInTopWord); |
| 753 | __ subu(scratch2, at, dst1); |
| 754 | __ sllv(scratch2, int_scratch, scratch2); |
| 755 | __ Or(dst2, dst2, scratch2); |
| 756 | // Set dst1 to 0. |
| 757 | __ mov(dst1, zero_reg); |
| 758 | } |
| 759 | __ bind(&done); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | |
| 763 | void FloatingPointHelper::LoadNumberAsInt32Double(MacroAssembler* masm, |
| 764 | Register object, |
| 765 | Destination destination, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 766 | DoubleRegister double_dst, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 767 | Register dst1, |
| 768 | Register dst2, |
| 769 | Register heap_number_map, |
| 770 | Register scratch1, |
| 771 | Register scratch2, |
| 772 | FPURegister single_scratch, |
| 773 | Label* not_int32) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 774 | ASSERT(!scratch1.is(object) && !scratch2.is(object)); |
| 775 | ASSERT(!scratch1.is(scratch2)); |
| 776 | ASSERT(!heap_number_map.is(object) && |
| 777 | !heap_number_map.is(scratch1) && |
| 778 | !heap_number_map.is(scratch2)); |
| 779 | |
| 780 | Label done, obj_is_not_smi; |
| 781 | |
| 782 | __ JumpIfNotSmi(object, &obj_is_not_smi); |
| 783 | __ SmiUntag(scratch1, object); |
| 784 | ConvertIntToDouble(masm, scratch1, destination, double_dst, dst1, dst2, |
| 785 | scratch2, single_scratch); |
| 786 | __ Branch(&done); |
| 787 | |
| 788 | __ bind(&obj_is_not_smi); |
| 789 | if (FLAG_debug_code) { |
| 790 | __ AbortIfNotRootValue(heap_number_map, |
| 791 | Heap::kHeapNumberMapRootIndex, |
| 792 | "HeapNumberMap register clobbered."); |
| 793 | } |
| 794 | __ JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_int32); |
| 795 | |
| 796 | // Load the number. |
| 797 | if (CpuFeatures::IsSupported(FPU)) { |
| 798 | CpuFeatures::Scope scope(FPU); |
| 799 | // Load the double value. |
| 800 | __ ldc1(double_dst, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 801 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 802 | Register except_flag = scratch2; |
| 803 | __ EmitFPUTruncate(kRoundToZero, |
| 804 | single_scratch, |
| 805 | double_dst, |
| 806 | scratch1, |
| 807 | except_flag, |
| 808 | kCheckForInexactConversion); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 809 | |
| 810 | // Jump to not_int32 if the operation did not succeed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 811 | __ Branch(not_int32, ne, except_flag, Operand(zero_reg)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 812 | |
| 813 | if (destination == kCoreRegisters) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 814 | __ Move(dst1, dst2, double_dst); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | } else { |
| 818 | ASSERT(!scratch1.is(object) && !scratch2.is(object)); |
| 819 | // Load the double value in the destination registers. |
| 820 | __ lw(dst2, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 821 | __ lw(dst1, FieldMemOperand(object, HeapNumber::kMantissaOffset)); |
| 822 | |
| 823 | // Check for 0 and -0. |
| 824 | __ And(scratch1, dst1, Operand(~HeapNumber::kSignMask)); |
| 825 | __ Or(scratch1, scratch1, Operand(dst2)); |
| 826 | __ Branch(&done, eq, scratch1, Operand(zero_reg)); |
| 827 | |
| 828 | // Check that the value can be exactly represented by a 32-bit integer. |
| 829 | // Jump to not_int32 if that's not the case. |
| 830 | DoubleIs32BitInteger(masm, dst1, dst2, scratch1, scratch2, not_int32); |
| 831 | |
| 832 | // dst1 and dst2 were trashed. Reload the double value. |
| 833 | __ lw(dst2, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 834 | __ lw(dst1, FieldMemOperand(object, HeapNumber::kMantissaOffset)); |
| 835 | } |
| 836 | |
| 837 | __ bind(&done); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | |
| 841 | void FloatingPointHelper::LoadNumberAsInt32(MacroAssembler* masm, |
| 842 | Register object, |
| 843 | Register dst, |
| 844 | Register heap_number_map, |
| 845 | Register scratch1, |
| 846 | Register scratch2, |
| 847 | Register scratch3, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 848 | DoubleRegister double_scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 849 | Label* not_int32) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 850 | ASSERT(!dst.is(object)); |
| 851 | ASSERT(!scratch1.is(object) && !scratch2.is(object) && !scratch3.is(object)); |
| 852 | ASSERT(!scratch1.is(scratch2) && |
| 853 | !scratch1.is(scratch3) && |
| 854 | !scratch2.is(scratch3)); |
| 855 | |
| 856 | Label done; |
| 857 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 858 | __ UntagAndJumpIfSmi(dst, object, &done); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 859 | |
| 860 | if (FLAG_debug_code) { |
| 861 | __ AbortIfNotRootValue(heap_number_map, |
| 862 | Heap::kHeapNumberMapRootIndex, |
| 863 | "HeapNumberMap register clobbered."); |
| 864 | } |
| 865 | __ JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_int32); |
| 866 | |
| 867 | // Object is a heap number. |
| 868 | // Convert the floating point value to a 32-bit integer. |
| 869 | if (CpuFeatures::IsSupported(FPU)) { |
| 870 | CpuFeatures::Scope scope(FPU); |
| 871 | // Load the double value. |
| 872 | __ ldc1(double_scratch, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 873 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 874 | FPURegister single_scratch = double_scratch.low(); |
| 875 | Register except_flag = scratch2; |
| 876 | __ EmitFPUTruncate(kRoundToZero, |
| 877 | single_scratch, |
| 878 | double_scratch, |
| 879 | scratch1, |
| 880 | except_flag, |
| 881 | kCheckForInexactConversion); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 882 | |
| 883 | // Jump to not_int32 if the operation did not succeed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 884 | __ Branch(not_int32, ne, except_flag, Operand(zero_reg)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 885 | // Get the result in the destination register. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 886 | __ mfc1(dst, single_scratch); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 887 | |
| 888 | } else { |
| 889 | // Load the double value in the destination registers. |
| 890 | __ lw(scratch2, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 891 | __ lw(scratch1, FieldMemOperand(object, HeapNumber::kMantissaOffset)); |
| 892 | |
| 893 | // Check for 0 and -0. |
| 894 | __ And(dst, scratch1, Operand(~HeapNumber::kSignMask)); |
| 895 | __ Or(dst, scratch2, Operand(dst)); |
| 896 | __ Branch(&done, eq, dst, Operand(zero_reg)); |
| 897 | |
| 898 | DoubleIs32BitInteger(masm, scratch1, scratch2, dst, scratch3, not_int32); |
| 899 | |
| 900 | // Registers state after DoubleIs32BitInteger. |
| 901 | // dst: mantissa[51:20]. |
| 902 | // scratch2: 1 |
| 903 | |
| 904 | // Shift back the higher bits of the mantissa. |
| 905 | __ srlv(dst, dst, scratch3); |
| 906 | // Set the implicit first bit. |
| 907 | __ li(at, 32); |
| 908 | __ subu(scratch3, at, scratch3); |
| 909 | __ sllv(scratch2, scratch2, scratch3); |
| 910 | __ Or(dst, dst, scratch2); |
| 911 | // Set the sign. |
| 912 | __ lw(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 913 | __ And(scratch1, scratch1, Operand(HeapNumber::kSignMask)); |
| 914 | Label skip_sub; |
| 915 | __ Branch(&skip_sub, ge, scratch1, Operand(zero_reg)); |
| 916 | __ Subu(dst, zero_reg, dst); |
| 917 | __ bind(&skip_sub); |
| 918 | } |
| 919 | |
| 920 | __ bind(&done); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | |
| 924 | void FloatingPointHelper::DoubleIs32BitInteger(MacroAssembler* masm, |
| 925 | Register src1, |
| 926 | Register src2, |
| 927 | Register dst, |
| 928 | Register scratch, |
| 929 | Label* not_int32) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 930 | // Get exponent alone in scratch. |
| 931 | __ Ext(scratch, |
| 932 | src1, |
| 933 | HeapNumber::kExponentShift, |
| 934 | HeapNumber::kExponentBits); |
| 935 | |
| 936 | // Substract the bias from the exponent. |
| 937 | __ Subu(scratch, scratch, Operand(HeapNumber::kExponentBias)); |
| 938 | |
| 939 | // src1: higher (exponent) part of the double value. |
| 940 | // src2: lower (mantissa) part of the double value. |
| 941 | // scratch: unbiased exponent. |
| 942 | |
| 943 | // Fast cases. Check for obvious non 32-bit integer values. |
| 944 | // Negative exponent cannot yield 32-bit integers. |
| 945 | __ Branch(not_int32, lt, scratch, Operand(zero_reg)); |
| 946 | // Exponent greater than 31 cannot yield 32-bit integers. |
| 947 | // Also, a positive value with an exponent equal to 31 is outside of the |
| 948 | // signed 32-bit integer range. |
| 949 | // Another way to put it is that if (exponent - signbit) > 30 then the |
| 950 | // number cannot be represented as an int32. |
| 951 | Register tmp = dst; |
| 952 | __ srl(at, src1, 31); |
| 953 | __ subu(tmp, scratch, at); |
| 954 | __ Branch(not_int32, gt, tmp, Operand(30)); |
| 955 | // - Bits [21:0] in the mantissa are not null. |
| 956 | __ And(tmp, src2, 0x3fffff); |
| 957 | __ Branch(not_int32, ne, tmp, Operand(zero_reg)); |
| 958 | |
| 959 | // Otherwise the exponent needs to be big enough to shift left all the |
| 960 | // non zero bits left. So we need the (30 - exponent) last bits of the |
| 961 | // 31 higher bits of the mantissa to be null. |
| 962 | // 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] | 963 | // (32 - exponent) last bits of the 32 higher bits of the mantissa are null. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 964 | |
| 965 | // Get the 32 higher bits of the mantissa in dst. |
| 966 | __ Ext(dst, |
| 967 | src2, |
| 968 | HeapNumber::kMantissaBitsInTopWord, |
| 969 | 32 - HeapNumber::kMantissaBitsInTopWord); |
| 970 | __ sll(at, src1, HeapNumber::kNonMantissaBitsInTopWord); |
| 971 | __ or_(dst, dst, at); |
| 972 | |
| 973 | // Create the mask and test the lower bits (of the higher bits). |
| 974 | __ li(at, 32); |
| 975 | __ subu(scratch, at, scratch); |
| 976 | __ li(src2, 1); |
| 977 | __ sllv(src1, src2, scratch); |
| 978 | __ Subu(src1, src1, Operand(1)); |
| 979 | __ And(src1, dst, src1); |
| 980 | __ Branch(not_int32, ne, src1, Operand(zero_reg)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | |
| 984 | void FloatingPointHelper::CallCCodeForDoubleOperation( |
| 985 | MacroAssembler* masm, |
| 986 | Token::Value op, |
| 987 | Register heap_number_result, |
| 988 | Register scratch) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 989 | // Using core registers: |
| 990 | // a0: Left value (least significant part of mantissa). |
| 991 | // a1: Left value (sign, exponent, top of mantissa). |
| 992 | // a2: Right value (least significant part of mantissa). |
| 993 | // a3: Right value (sign, exponent, top of mantissa). |
| 994 | |
| 995 | // Assert that heap_number_result is saved. |
| 996 | // We currently always use s0 to pass it. |
| 997 | ASSERT(heap_number_result.is(s0)); |
| 998 | |
| 999 | // Push the current return address before the C call. |
| 1000 | __ push(ra); |
| 1001 | __ PrepareCallCFunction(4, scratch); // Two doubles are 4 arguments. |
| 1002 | if (!IsMipsSoftFloatABI) { |
| 1003 | CpuFeatures::Scope scope(FPU); |
| 1004 | // We are not using MIPS FPU instructions, and parameters for the runtime |
| 1005 | // function call are prepaired in a0-a3 registers, but function we are |
| 1006 | // calling is compiled with hard-float flag and expecting hard float ABI |
| 1007 | // (parameters in f12/f14 registers). We need to copy parameters from |
| 1008 | // a0-a3 registers to f12/f14 register pairs. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1009 | __ Move(f12, a0, a1); |
| 1010 | __ Move(f14, a2, a3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1011 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1012 | { |
| 1013 | AllowExternalCallThatCantCauseGC scope(masm); |
| 1014 | __ CallCFunction( |
| 1015 | ExternalReference::double_fp_operation(op, masm->isolate()), 0, 2); |
| 1016 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1017 | // Store answer in the overwritable heap number. |
| 1018 | if (!IsMipsSoftFloatABI) { |
| 1019 | CpuFeatures::Scope scope(FPU); |
| 1020 | // Double returned in register f0. |
| 1021 | __ sdc1(f0, FieldMemOperand(heap_number_result, HeapNumber::kValueOffset)); |
| 1022 | } else { |
| 1023 | // Double returned in registers v0 and v1. |
| 1024 | __ sw(v1, FieldMemOperand(heap_number_result, HeapNumber::kExponentOffset)); |
| 1025 | __ sw(v0, FieldMemOperand(heap_number_result, HeapNumber::kMantissaOffset)); |
| 1026 | } |
| 1027 | // Place heap_number_result in v0 and return to the pushed return address. |
| 1028 | __ mov(v0, heap_number_result); |
| 1029 | __ pop(ra); |
| 1030 | __ Ret(); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1034 | bool WriteInt32ToHeapNumberStub::IsPregenerated() { |
| 1035 | // These variants are compiled ahead of time. See next method. |
| 1036 | if (the_int_.is(a1) && |
| 1037 | the_heap_number_.is(v0) && |
| 1038 | scratch_.is(a2) && |
| 1039 | sign_.is(a3)) { |
| 1040 | return true; |
| 1041 | } |
| 1042 | if (the_int_.is(a2) && |
| 1043 | the_heap_number_.is(v0) && |
| 1044 | scratch_.is(a3) && |
| 1045 | sign_.is(a0)) { |
| 1046 | return true; |
| 1047 | } |
| 1048 | // Other register combinations are generated as and when they are needed, |
| 1049 | // so it is unsafe to call them from stubs (we can't generate a stub while |
| 1050 | // we are generating a stub). |
| 1051 | return false; |
| 1052 | } |
| 1053 | |
| 1054 | |
| 1055 | void WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime() { |
| 1056 | WriteInt32ToHeapNumberStub stub1(a1, v0, a2, a3); |
| 1057 | WriteInt32ToHeapNumberStub stub2(a2, v0, a3, a0); |
| 1058 | stub1.GetCode()->set_is_pregenerated(true); |
| 1059 | stub2.GetCode()->set_is_pregenerated(true); |
| 1060 | } |
| 1061 | |
| 1062 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1063 | // See comment for class, this does NOT work for int32's that are in Smi range. |
| 1064 | void WriteInt32ToHeapNumberStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1065 | Label max_negative_int; |
| 1066 | // the_int_ has the answer which is a signed int32 but not a Smi. |
| 1067 | // We test for the special value that has a different exponent. |
| 1068 | STATIC_ASSERT(HeapNumber::kSignMask == 0x80000000u); |
| 1069 | // Test sign, and save for later conditionals. |
| 1070 | __ And(sign_, the_int_, Operand(0x80000000u)); |
| 1071 | __ Branch(&max_negative_int, eq, the_int_, Operand(0x80000000u)); |
| 1072 | |
| 1073 | // Set up the correct exponent in scratch_. All non-Smi int32s have the same. |
| 1074 | // A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased). |
| 1075 | uint32_t non_smi_exponent = |
| 1076 | (HeapNumber::kExponentBias + 30) << HeapNumber::kExponentShift; |
| 1077 | __ li(scratch_, Operand(non_smi_exponent)); |
| 1078 | // Set the sign bit in scratch_ if the value was negative. |
| 1079 | __ or_(scratch_, scratch_, sign_); |
| 1080 | // Subtract from 0 if the value was negative. |
| 1081 | __ subu(at, zero_reg, the_int_); |
| 1082 | __ movn(the_int_, at, sign_); |
| 1083 | // We should be masking the implict first digit of the mantissa away here, |
| 1084 | // but it just ends up combining harmlessly with the last digit of the |
| 1085 | // exponent that happens to be 1. The sign bit is 0 so we shift 10 to get |
| 1086 | // the most significant 1 to hit the last bit of the 12 bit sign and exponent. |
| 1087 | ASSERT(((1 << HeapNumber::kExponentShift) & non_smi_exponent) != 0); |
| 1088 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 1089 | __ srl(at, the_int_, shift_distance); |
| 1090 | __ or_(scratch_, scratch_, at); |
| 1091 | __ sw(scratch_, FieldMemOperand(the_heap_number_, |
| 1092 | HeapNumber::kExponentOffset)); |
| 1093 | __ sll(scratch_, the_int_, 32 - shift_distance); |
| 1094 | __ sw(scratch_, FieldMemOperand(the_heap_number_, |
| 1095 | HeapNumber::kMantissaOffset)); |
| 1096 | __ Ret(); |
| 1097 | |
| 1098 | __ bind(&max_negative_int); |
| 1099 | // The max negative int32 is stored as a positive number in the mantissa of |
| 1100 | // a double because it uses a sign bit instead of using two's complement. |
| 1101 | // The actual mantissa bits stored are all 0 because the implicit most |
| 1102 | // significant 1 bit is not stored. |
| 1103 | non_smi_exponent += 1 << HeapNumber::kExponentShift; |
| 1104 | __ li(scratch_, Operand(HeapNumber::kSignMask | non_smi_exponent)); |
| 1105 | __ sw(scratch_, |
| 1106 | FieldMemOperand(the_heap_number_, HeapNumber::kExponentOffset)); |
| 1107 | __ mov(scratch_, zero_reg); |
| 1108 | __ sw(scratch_, |
| 1109 | FieldMemOperand(the_heap_number_, HeapNumber::kMantissaOffset)); |
| 1110 | __ Ret(); |
| 1111 | } |
| 1112 | |
| 1113 | |
| 1114 | // Handle the case where the lhs and rhs are the same object. |
| 1115 | // Equality is almost reflexive (everything but NaN), so this is a test |
| 1116 | // for "identity and not NaN". |
| 1117 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, |
| 1118 | Label* slow, |
| 1119 | Condition cc, |
| 1120 | bool never_nan_nan) { |
| 1121 | Label not_identical; |
| 1122 | Label heap_number, return_equal; |
| 1123 | Register exp_mask_reg = t5; |
| 1124 | |
| 1125 | __ Branch(¬_identical, ne, a0, Operand(a1)); |
| 1126 | |
| 1127 | // The two objects are identical. If we know that one of them isn't NaN then |
| 1128 | // we now know they test equal. |
| 1129 | if (cc != eq || !never_nan_nan) { |
| 1130 | __ li(exp_mask_reg, Operand(HeapNumber::kExponentMask)); |
| 1131 | |
| 1132 | // Test for NaN. Sadly, we can't just compare to factory->nan_value(), |
| 1133 | // so we do the second best thing - test it ourselves. |
| 1134 | // They are both equal and they are not both Smis so both of them are not |
| 1135 | // Smis. If it's not a heap number, then return equal. |
| 1136 | if (cc == less || cc == greater) { |
| 1137 | __ GetObjectType(a0, t4, t4); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1138 | __ Branch(slow, greater, t4, Operand(FIRST_SPEC_OBJECT_TYPE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1139 | } else { |
| 1140 | __ GetObjectType(a0, t4, t4); |
| 1141 | __ Branch(&heap_number, eq, t4, Operand(HEAP_NUMBER_TYPE)); |
| 1142 | // Comparing JS objects with <=, >= is complicated. |
| 1143 | if (cc != eq) { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1144 | __ Branch(slow, greater, t4, Operand(FIRST_SPEC_OBJECT_TYPE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1145 | // Normally here we fall through to return_equal, but undefined is |
| 1146 | // special: (undefined == undefined) == true, but |
| 1147 | // (undefined <= undefined) == false! See ECMAScript 11.8.5. |
| 1148 | if (cc == less_equal || cc == greater_equal) { |
| 1149 | __ Branch(&return_equal, ne, t4, Operand(ODDBALL_TYPE)); |
| 1150 | __ LoadRoot(t2, Heap::kUndefinedValueRootIndex); |
| 1151 | __ Branch(&return_equal, ne, a0, Operand(t2)); |
| 1152 | if (cc == le) { |
| 1153 | // undefined <= undefined should fail. |
| 1154 | __ li(v0, Operand(GREATER)); |
| 1155 | } else { |
| 1156 | // undefined >= undefined should fail. |
| 1157 | __ li(v0, Operand(LESS)); |
| 1158 | } |
| 1159 | __ Ret(); |
| 1160 | } |
| 1161 | } |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | __ bind(&return_equal); |
| 1166 | if (cc == less) { |
| 1167 | __ li(v0, Operand(GREATER)); // Things aren't less than themselves. |
| 1168 | } else if (cc == greater) { |
| 1169 | __ li(v0, Operand(LESS)); // Things aren't greater than themselves. |
| 1170 | } else { |
| 1171 | __ mov(v0, zero_reg); // Things are <=, >=, ==, === themselves. |
| 1172 | } |
| 1173 | __ Ret(); |
| 1174 | |
| 1175 | if (cc != eq || !never_nan_nan) { |
| 1176 | // For less and greater we don't have to check for NaN since the result of |
| 1177 | // x < x is false regardless. For the others here is some code to check |
| 1178 | // for NaN. |
| 1179 | if (cc != lt && cc != gt) { |
| 1180 | __ bind(&heap_number); |
| 1181 | // It is a heap number, so return non-equal if it's NaN and equal if it's |
| 1182 | // not NaN. |
| 1183 | |
| 1184 | // The representation of NaN values has all exponent bits (52..62) set, |
| 1185 | // and not all mantissa bits (0..51) clear. |
| 1186 | // Read top bits of double representation (second word of value). |
| 1187 | __ lw(t2, FieldMemOperand(a0, HeapNumber::kExponentOffset)); |
| 1188 | // Test that exponent bits are all set. |
| 1189 | __ And(t3, t2, Operand(exp_mask_reg)); |
| 1190 | // If all bits not set (ne cond), then not a NaN, objects are equal. |
| 1191 | __ Branch(&return_equal, ne, t3, Operand(exp_mask_reg)); |
| 1192 | |
| 1193 | // Shift out flag and all exponent bits, retaining only mantissa. |
| 1194 | __ sll(t2, t2, HeapNumber::kNonMantissaBitsInTopWord); |
| 1195 | // Or with all low-bits of mantissa. |
| 1196 | __ lw(t3, FieldMemOperand(a0, HeapNumber::kMantissaOffset)); |
| 1197 | __ Or(v0, t3, Operand(t2)); |
| 1198 | // For equal we already have the right value in v0: Return zero (equal) |
| 1199 | // if all bits in mantissa are zero (it's an Infinity) and non-zero if |
| 1200 | // not (it's a NaN). For <= and >= we need to load v0 with the failing |
| 1201 | // value if it's a NaN. |
| 1202 | if (cc != eq) { |
| 1203 | // All-zero means Infinity means equal. |
| 1204 | __ Ret(eq, v0, Operand(zero_reg)); |
| 1205 | if (cc == le) { |
| 1206 | __ li(v0, Operand(GREATER)); // NaN <= NaN should fail. |
| 1207 | } else { |
| 1208 | __ li(v0, Operand(LESS)); // NaN >= NaN should fail. |
| 1209 | } |
| 1210 | } |
| 1211 | __ Ret(); |
| 1212 | } |
| 1213 | // No fall through here. |
| 1214 | } |
| 1215 | |
| 1216 | __ bind(¬_identical); |
| 1217 | } |
| 1218 | |
| 1219 | |
| 1220 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 1221 | Register lhs, |
| 1222 | Register rhs, |
| 1223 | Label* both_loaded_as_doubles, |
| 1224 | Label* slow, |
| 1225 | bool strict) { |
| 1226 | ASSERT((lhs.is(a0) && rhs.is(a1)) || |
| 1227 | (lhs.is(a1) && rhs.is(a0))); |
| 1228 | |
| 1229 | Label lhs_is_smi; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1230 | __ JumpIfSmi(lhs, &lhs_is_smi); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1231 | // Rhs is a Smi. |
| 1232 | // Check whether the non-smi is a heap number. |
| 1233 | __ GetObjectType(lhs, t4, t4); |
| 1234 | if (strict) { |
| 1235 | // If lhs was not a number and rhs was a Smi then strict equality cannot |
| 1236 | // succeed. Return non-equal (lhs is already not zero). |
| 1237 | __ mov(v0, lhs); |
| 1238 | __ Ret(ne, t4, Operand(HEAP_NUMBER_TYPE)); |
| 1239 | } else { |
| 1240 | // Smi compared non-strictly with a non-Smi non-heap-number. Call |
| 1241 | // the runtime. |
| 1242 | __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE)); |
| 1243 | } |
| 1244 | |
| 1245 | // Rhs is a smi, lhs is a number. |
| 1246 | // Convert smi rhs to double. |
| 1247 | if (CpuFeatures::IsSupported(FPU)) { |
| 1248 | CpuFeatures::Scope scope(FPU); |
| 1249 | __ sra(at, rhs, kSmiTagSize); |
| 1250 | __ mtc1(at, f14); |
| 1251 | __ cvt_d_w(f14, f14); |
| 1252 | __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 1253 | } else { |
| 1254 | // Load lhs to a double in a2, a3. |
| 1255 | __ lw(a3, FieldMemOperand(lhs, HeapNumber::kValueOffset + 4)); |
| 1256 | __ lw(a2, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 1257 | |
| 1258 | // Write Smi from rhs to a1 and a0 in double format. t5 is scratch. |
| 1259 | __ mov(t6, rhs); |
| 1260 | ConvertToDoubleStub stub1(a1, a0, t6, t5); |
| 1261 | __ push(ra); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1262 | __ Call(stub1.GetCode()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1263 | |
| 1264 | __ pop(ra); |
| 1265 | } |
| 1266 | |
| 1267 | // We now have both loaded as doubles. |
| 1268 | __ jmp(both_loaded_as_doubles); |
| 1269 | |
| 1270 | __ bind(&lhs_is_smi); |
| 1271 | // Lhs is a Smi. Check whether the non-smi is a heap number. |
| 1272 | __ GetObjectType(rhs, t4, t4); |
| 1273 | if (strict) { |
| 1274 | // If lhs was not a number and rhs was a Smi then strict equality cannot |
| 1275 | // succeed. Return non-equal. |
| 1276 | __ li(v0, Operand(1)); |
| 1277 | __ Ret(ne, t4, Operand(HEAP_NUMBER_TYPE)); |
| 1278 | } else { |
| 1279 | // Smi compared non-strictly with a non-Smi non-heap-number. Call |
| 1280 | // the runtime. |
| 1281 | __ Branch(slow, ne, t4, Operand(HEAP_NUMBER_TYPE)); |
| 1282 | } |
| 1283 | |
| 1284 | // Lhs is a smi, rhs is a number. |
| 1285 | // Convert smi lhs to double. |
| 1286 | if (CpuFeatures::IsSupported(FPU)) { |
| 1287 | CpuFeatures::Scope scope(FPU); |
| 1288 | __ sra(at, lhs, kSmiTagSize); |
| 1289 | __ mtc1(at, f12); |
| 1290 | __ cvt_d_w(f12, f12); |
| 1291 | __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 1292 | } else { |
| 1293 | // Convert lhs to a double format. t5 is scratch. |
| 1294 | __ mov(t6, lhs); |
| 1295 | ConvertToDoubleStub stub2(a3, a2, t6, t5); |
| 1296 | __ push(ra); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1297 | __ Call(stub2.GetCode()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1298 | __ pop(ra); |
| 1299 | // Load rhs to a double in a1, a0. |
| 1300 | if (rhs.is(a0)) { |
| 1301 | __ lw(a1, FieldMemOperand(rhs, HeapNumber::kValueOffset + 4)); |
| 1302 | __ lw(a0, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 1303 | } else { |
| 1304 | __ lw(a0, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 1305 | __ lw(a1, FieldMemOperand(rhs, HeapNumber::kValueOffset + 4)); |
| 1306 | } |
| 1307 | } |
| 1308 | // Fall through to both_loaded_as_doubles. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | |
| 1312 | void EmitNanCheck(MacroAssembler* masm, Condition cc) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1313 | bool exp_first = (HeapNumber::kExponentOffset == HeapNumber::kValueOffset); |
| 1314 | if (CpuFeatures::IsSupported(FPU)) { |
| 1315 | CpuFeatures::Scope scope(FPU); |
| 1316 | // Lhs and rhs are already loaded to f12 and f14 register pairs. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1317 | __ Move(t0, t1, f14); |
| 1318 | __ Move(t2, t3, f12); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1319 | } else { |
| 1320 | // Lhs and rhs are already loaded to GP registers. |
| 1321 | __ mov(t0, a0); // a0 has LS 32 bits of rhs. |
| 1322 | __ mov(t1, a1); // a1 has MS 32 bits of rhs. |
| 1323 | __ mov(t2, a2); // a2 has LS 32 bits of lhs. |
| 1324 | __ mov(t3, a3); // a3 has MS 32 bits of lhs. |
| 1325 | } |
| 1326 | Register rhs_exponent = exp_first ? t0 : t1; |
| 1327 | Register lhs_exponent = exp_first ? t2 : t3; |
| 1328 | Register rhs_mantissa = exp_first ? t1 : t0; |
| 1329 | Register lhs_mantissa = exp_first ? t3 : t2; |
| 1330 | Label one_is_nan, neither_is_nan; |
| 1331 | Label lhs_not_nan_exp_mask_is_loaded; |
| 1332 | |
| 1333 | Register exp_mask_reg = t4; |
| 1334 | __ li(exp_mask_reg, HeapNumber::kExponentMask); |
| 1335 | __ and_(t5, lhs_exponent, exp_mask_reg); |
| 1336 | __ Branch(&lhs_not_nan_exp_mask_is_loaded, ne, t5, Operand(exp_mask_reg)); |
| 1337 | |
| 1338 | __ sll(t5, lhs_exponent, HeapNumber::kNonMantissaBitsInTopWord); |
| 1339 | __ Branch(&one_is_nan, ne, t5, Operand(zero_reg)); |
| 1340 | |
| 1341 | __ Branch(&one_is_nan, ne, lhs_mantissa, Operand(zero_reg)); |
| 1342 | |
| 1343 | __ li(exp_mask_reg, HeapNumber::kExponentMask); |
| 1344 | __ bind(&lhs_not_nan_exp_mask_is_loaded); |
| 1345 | __ and_(t5, rhs_exponent, exp_mask_reg); |
| 1346 | |
| 1347 | __ Branch(&neither_is_nan, ne, t5, Operand(exp_mask_reg)); |
| 1348 | |
| 1349 | __ sll(t5, rhs_exponent, HeapNumber::kNonMantissaBitsInTopWord); |
| 1350 | __ Branch(&one_is_nan, ne, t5, Operand(zero_reg)); |
| 1351 | |
| 1352 | __ Branch(&neither_is_nan, eq, rhs_mantissa, Operand(zero_reg)); |
| 1353 | |
| 1354 | __ bind(&one_is_nan); |
| 1355 | // NaN comparisons always fail. |
| 1356 | // Load whatever we need in v0 to make the comparison fail. |
| 1357 | if (cc == lt || cc == le) { |
| 1358 | __ li(v0, Operand(GREATER)); |
| 1359 | } else { |
| 1360 | __ li(v0, Operand(LESS)); |
| 1361 | } |
| 1362 | __ Ret(); // Return. |
| 1363 | |
| 1364 | __ bind(&neither_is_nan); |
| 1365 | } |
| 1366 | |
| 1367 | |
| 1368 | static void EmitTwoNonNanDoubleComparison(MacroAssembler* masm, Condition cc) { |
| 1369 | // f12 and f14 have the two doubles. Neither is a NaN. |
| 1370 | // Call a native function to do a comparison between two non-NaNs. |
| 1371 | // Call C routine that may not cause GC or other trouble. |
| 1372 | // We use a call_was and return manually because we need arguments slots to |
| 1373 | // be freed. |
| 1374 | |
| 1375 | Label return_result_not_equal, return_result_equal; |
| 1376 | if (cc == eq) { |
| 1377 | // Doubles are not equal unless they have the same bit pattern. |
| 1378 | // Exception: 0 and -0. |
| 1379 | bool exp_first = (HeapNumber::kExponentOffset == HeapNumber::kValueOffset); |
| 1380 | if (CpuFeatures::IsSupported(FPU)) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1381 | CpuFeatures::Scope scope(FPU); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1382 | // Lhs and rhs are already loaded to f12 and f14 register pairs. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1383 | __ Move(t0, t1, f14); |
| 1384 | __ Move(t2, t3, f12); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1385 | } else { |
| 1386 | // Lhs and rhs are already loaded to GP registers. |
| 1387 | __ mov(t0, a0); // a0 has LS 32 bits of rhs. |
| 1388 | __ mov(t1, a1); // a1 has MS 32 bits of rhs. |
| 1389 | __ mov(t2, a2); // a2 has LS 32 bits of lhs. |
| 1390 | __ mov(t3, a3); // a3 has MS 32 bits of lhs. |
| 1391 | } |
| 1392 | Register rhs_exponent = exp_first ? t0 : t1; |
| 1393 | Register lhs_exponent = exp_first ? t2 : t3; |
| 1394 | Register rhs_mantissa = exp_first ? t1 : t0; |
| 1395 | Register lhs_mantissa = exp_first ? t3 : t2; |
| 1396 | |
| 1397 | __ xor_(v0, rhs_mantissa, lhs_mantissa); |
| 1398 | __ Branch(&return_result_not_equal, ne, v0, Operand(zero_reg)); |
| 1399 | |
| 1400 | __ subu(v0, rhs_exponent, lhs_exponent); |
| 1401 | __ Branch(&return_result_equal, eq, v0, Operand(zero_reg)); |
| 1402 | // 0, -0 case. |
| 1403 | __ sll(rhs_exponent, rhs_exponent, kSmiTagSize); |
| 1404 | __ sll(lhs_exponent, lhs_exponent, kSmiTagSize); |
| 1405 | __ or_(t4, rhs_exponent, lhs_exponent); |
| 1406 | __ or_(t4, t4, rhs_mantissa); |
| 1407 | |
| 1408 | __ Branch(&return_result_not_equal, ne, t4, Operand(zero_reg)); |
| 1409 | |
| 1410 | __ bind(&return_result_equal); |
| 1411 | __ li(v0, Operand(EQUAL)); |
| 1412 | __ Ret(); |
| 1413 | } |
| 1414 | |
| 1415 | __ bind(&return_result_not_equal); |
| 1416 | |
| 1417 | if (!CpuFeatures::IsSupported(FPU)) { |
| 1418 | __ push(ra); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1419 | __ PrepareCallCFunction(0, 2, t4); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1420 | if (!IsMipsSoftFloatABI) { |
| 1421 | // We are not using MIPS FPU instructions, and parameters for the runtime |
| 1422 | // function call are prepaired in a0-a3 registers, but function we are |
| 1423 | // calling is compiled with hard-float flag and expecting hard float ABI |
| 1424 | // (parameters in f12/f14 registers). We need to copy parameters from |
| 1425 | // a0-a3 registers to f12/f14 register pairs. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1426 | __ Move(f12, a0, a1); |
| 1427 | __ Move(f14, a2, a3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1428 | } |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1429 | |
| 1430 | AllowExternalCallThatCantCauseGC scope(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1431 | __ CallCFunction(ExternalReference::compare_doubles(masm->isolate()), |
| 1432 | 0, 2); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1433 | __ pop(ra); // Because this function returns int, result is in v0. |
| 1434 | __ Ret(); |
| 1435 | } else { |
| 1436 | CpuFeatures::Scope scope(FPU); |
| 1437 | Label equal, less_than; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1438 | __ BranchF(&equal, NULL, eq, f12, f14); |
| 1439 | __ BranchF(&less_than, NULL, lt, f12, f14); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1440 | |
| 1441 | // Not equal, not less, not NaN, must be greater. |
| 1442 | __ li(v0, Operand(GREATER)); |
| 1443 | __ Ret(); |
| 1444 | |
| 1445 | __ bind(&equal); |
| 1446 | __ li(v0, Operand(EQUAL)); |
| 1447 | __ Ret(); |
| 1448 | |
| 1449 | __ bind(&less_than); |
| 1450 | __ li(v0, Operand(LESS)); |
| 1451 | __ Ret(); |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | |
| 1456 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 1457 | Register lhs, |
| 1458 | Register rhs) { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1459 | // If either operand is a JS object or an oddball value, then they are |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1460 | // not equal since their pointers are different. |
| 1461 | // There is no test for undetectability in strict equality. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1462 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1463 | Label first_non_object; |
| 1464 | // Get the type of the first operand into a2 and compare it with |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1465 | // FIRST_SPEC_OBJECT_TYPE. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1466 | __ GetObjectType(lhs, a2, a2); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1467 | __ Branch(&first_non_object, less, a2, Operand(FIRST_SPEC_OBJECT_TYPE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1468 | |
| 1469 | // Return non-zero. |
| 1470 | Label return_not_equal; |
| 1471 | __ bind(&return_not_equal); |
| 1472 | __ li(v0, Operand(1)); |
| 1473 | __ Ret(); |
| 1474 | |
| 1475 | __ bind(&first_non_object); |
| 1476 | // Check for oddballs: true, false, null, undefined. |
| 1477 | __ Branch(&return_not_equal, eq, a2, Operand(ODDBALL_TYPE)); |
| 1478 | |
| 1479 | __ GetObjectType(rhs, a3, a3); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1480 | __ Branch(&return_not_equal, greater, a3, Operand(FIRST_SPEC_OBJECT_TYPE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1481 | |
| 1482 | // Check for oddballs: true, false, null, undefined. |
| 1483 | __ Branch(&return_not_equal, eq, a3, Operand(ODDBALL_TYPE)); |
| 1484 | |
| 1485 | // Now that we have the types we might as well check for symbol-symbol. |
| 1486 | // Ensure that no non-strings have the symbol bit set. |
| 1487 | STATIC_ASSERT(LAST_TYPE < kNotStringTag + kIsSymbolMask); |
| 1488 | STATIC_ASSERT(kSymbolTag != 0); |
| 1489 | __ And(t2, a2, Operand(a3)); |
| 1490 | __ And(t0, t2, Operand(kIsSymbolMask)); |
| 1491 | __ Branch(&return_not_equal, ne, t0, Operand(zero_reg)); |
| 1492 | } |
| 1493 | |
| 1494 | |
| 1495 | static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm, |
| 1496 | Register lhs, |
| 1497 | Register rhs, |
| 1498 | Label* both_loaded_as_doubles, |
| 1499 | Label* not_heap_numbers, |
| 1500 | Label* slow) { |
| 1501 | __ GetObjectType(lhs, a3, a2); |
| 1502 | __ Branch(not_heap_numbers, ne, a2, Operand(HEAP_NUMBER_TYPE)); |
| 1503 | __ lw(a2, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 1504 | // If first was a heap number & second wasn't, go to slow case. |
| 1505 | __ Branch(slow, ne, a3, Operand(a2)); |
| 1506 | |
| 1507 | // Both are heap numbers. Load them up then jump to the code we have |
| 1508 | // for that. |
| 1509 | if (CpuFeatures::IsSupported(FPU)) { |
| 1510 | CpuFeatures::Scope scope(FPU); |
| 1511 | __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 1512 | __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 1513 | } else { |
| 1514 | __ lw(a2, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 1515 | __ lw(a3, FieldMemOperand(lhs, HeapNumber::kValueOffset + 4)); |
| 1516 | if (rhs.is(a0)) { |
| 1517 | __ lw(a1, FieldMemOperand(rhs, HeapNumber::kValueOffset + 4)); |
| 1518 | __ lw(a0, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 1519 | } else { |
| 1520 | __ lw(a0, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 1521 | __ lw(a1, FieldMemOperand(rhs, HeapNumber::kValueOffset + 4)); |
| 1522 | } |
| 1523 | } |
| 1524 | __ jmp(both_loaded_as_doubles); |
| 1525 | } |
| 1526 | |
| 1527 | |
| 1528 | // Fast negative check for symbol-to-symbol equality. |
| 1529 | static void EmitCheckForSymbolsOrObjects(MacroAssembler* masm, |
| 1530 | Register lhs, |
| 1531 | Register rhs, |
| 1532 | Label* possible_strings, |
| 1533 | Label* not_both_strings) { |
| 1534 | ASSERT((lhs.is(a0) && rhs.is(a1)) || |
| 1535 | (lhs.is(a1) && rhs.is(a0))); |
| 1536 | |
| 1537 | // a2 is object type of lhs. |
| 1538 | // Ensure that no non-strings have the symbol bit set. |
| 1539 | Label object_test; |
| 1540 | STATIC_ASSERT(kSymbolTag != 0); |
| 1541 | __ And(at, a2, Operand(kIsNotStringMask)); |
| 1542 | __ Branch(&object_test, ne, at, Operand(zero_reg)); |
| 1543 | __ And(at, a2, Operand(kIsSymbolMask)); |
| 1544 | __ Branch(possible_strings, eq, at, Operand(zero_reg)); |
| 1545 | __ GetObjectType(rhs, a3, a3); |
| 1546 | __ Branch(not_both_strings, ge, a3, Operand(FIRST_NONSTRING_TYPE)); |
| 1547 | __ And(at, a3, Operand(kIsSymbolMask)); |
| 1548 | __ Branch(possible_strings, eq, at, Operand(zero_reg)); |
| 1549 | |
| 1550 | // Both are symbols. We already checked they weren't the same pointer |
| 1551 | // so they are not equal. |
| 1552 | __ li(v0, Operand(1)); // Non-zero indicates not equal. |
| 1553 | __ Ret(); |
| 1554 | |
| 1555 | __ bind(&object_test); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1556 | __ Branch(not_both_strings, lt, a2, Operand(FIRST_SPEC_OBJECT_TYPE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1557 | __ GetObjectType(rhs, a2, a3); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1558 | __ Branch(not_both_strings, lt, a3, Operand(FIRST_SPEC_OBJECT_TYPE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1559 | |
| 1560 | // If both objects are undetectable, they are equal. Otherwise, they |
| 1561 | // are not equal, since they are different objects and an object is not |
| 1562 | // equal to undefined. |
| 1563 | __ lw(a3, FieldMemOperand(lhs, HeapObject::kMapOffset)); |
| 1564 | __ lbu(a2, FieldMemOperand(a2, Map::kBitFieldOffset)); |
| 1565 | __ lbu(a3, FieldMemOperand(a3, Map::kBitFieldOffset)); |
| 1566 | __ and_(a0, a2, a3); |
| 1567 | __ And(a0, a0, Operand(1 << Map::kIsUndetectable)); |
| 1568 | __ Xor(v0, a0, Operand(1 << Map::kIsUndetectable)); |
| 1569 | __ Ret(); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | |
| 1573 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 1574 | Register object, |
| 1575 | Register result, |
| 1576 | Register scratch1, |
| 1577 | Register scratch2, |
| 1578 | Register scratch3, |
| 1579 | bool object_is_smi, |
| 1580 | Label* not_found) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1581 | // Use of registers. Register result is used as a temporary. |
| 1582 | Register number_string_cache = result; |
| 1583 | Register mask = scratch3; |
| 1584 | |
| 1585 | // Load the number string cache. |
| 1586 | __ LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex); |
| 1587 | |
| 1588 | // Make the hash mask from the length of the number string cache. It |
| 1589 | // contains two elements (number and string) for each cache entry. |
| 1590 | __ lw(mask, FieldMemOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 1591 | // Divide length by two (length is a smi). |
| 1592 | __ sra(mask, mask, kSmiTagSize + 1); |
| 1593 | __ Addu(mask, mask, -1); // Make mask. |
| 1594 | |
| 1595 | // Calculate the entry in the number string cache. The hash value in the |
| 1596 | // number string cache for smis is just the smi value, and the hash for |
| 1597 | // doubles is the xor of the upper and lower words. See |
| 1598 | // Heap::GetNumberStringCache. |
| 1599 | Isolate* isolate = masm->isolate(); |
| 1600 | Label is_smi; |
| 1601 | Label load_result_from_cache; |
| 1602 | if (!object_is_smi) { |
| 1603 | __ JumpIfSmi(object, &is_smi); |
| 1604 | if (CpuFeatures::IsSupported(FPU)) { |
| 1605 | CpuFeatures::Scope scope(FPU); |
| 1606 | __ CheckMap(object, |
| 1607 | scratch1, |
| 1608 | Heap::kHeapNumberMapRootIndex, |
| 1609 | not_found, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1610 | DONT_DO_SMI_CHECK); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1611 | |
| 1612 | STATIC_ASSERT(8 == kDoubleSize); |
| 1613 | __ Addu(scratch1, |
| 1614 | object, |
| 1615 | Operand(HeapNumber::kValueOffset - kHeapObjectTag)); |
| 1616 | __ lw(scratch2, MemOperand(scratch1, kPointerSize)); |
| 1617 | __ lw(scratch1, MemOperand(scratch1, 0)); |
| 1618 | __ Xor(scratch1, scratch1, Operand(scratch2)); |
| 1619 | __ And(scratch1, scratch1, Operand(mask)); |
| 1620 | |
| 1621 | // Calculate address of entry in string cache: each entry consists |
| 1622 | // of two pointer sized fields. |
| 1623 | __ sll(scratch1, scratch1, kPointerSizeLog2 + 1); |
| 1624 | __ Addu(scratch1, number_string_cache, scratch1); |
| 1625 | |
| 1626 | Register probe = mask; |
| 1627 | __ lw(probe, |
| 1628 | FieldMemOperand(scratch1, FixedArray::kHeaderSize)); |
| 1629 | __ JumpIfSmi(probe, not_found); |
| 1630 | __ ldc1(f12, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 1631 | __ ldc1(f14, FieldMemOperand(probe, HeapNumber::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1632 | __ BranchF(&load_result_from_cache, NULL, eq, f12, f14); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1633 | __ Branch(not_found); |
| 1634 | } else { |
| 1635 | // Note that there is no cache check for non-FPU case, even though |
| 1636 | // it seems there could be. May be a tiny opimization for non-FPU |
| 1637 | // cores. |
| 1638 | __ Branch(not_found); |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | __ bind(&is_smi); |
| 1643 | Register scratch = scratch1; |
| 1644 | __ sra(scratch, object, 1); // Shift away the tag. |
| 1645 | __ And(scratch, mask, Operand(scratch)); |
| 1646 | |
| 1647 | // Calculate address of entry in string cache: each entry consists |
| 1648 | // of two pointer sized fields. |
| 1649 | __ sll(scratch, scratch, kPointerSizeLog2 + 1); |
| 1650 | __ Addu(scratch, number_string_cache, scratch); |
| 1651 | |
| 1652 | // Check if the entry is the smi we are looking for. |
| 1653 | Register probe = mask; |
| 1654 | __ lw(probe, FieldMemOperand(scratch, FixedArray::kHeaderSize)); |
| 1655 | __ Branch(not_found, ne, object, Operand(probe)); |
| 1656 | |
| 1657 | // Get the result from the cache. |
| 1658 | __ bind(&load_result_from_cache); |
| 1659 | __ lw(result, |
| 1660 | FieldMemOperand(scratch, FixedArray::kHeaderSize + kPointerSize)); |
| 1661 | |
| 1662 | __ IncrementCounter(isolate->counters()->number_to_string_native(), |
| 1663 | 1, |
| 1664 | scratch1, |
| 1665 | scratch2); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | |
| 1669 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1670 | Label runtime; |
| 1671 | |
| 1672 | __ lw(a1, MemOperand(sp, 0)); |
| 1673 | |
| 1674 | // Generate code to lookup number in the number string cache. |
| 1675 | GenerateLookupNumberStringCache(masm, a1, v0, a2, a3, t0, false, &runtime); |
| 1676 | __ Addu(sp, sp, Operand(1 * kPointerSize)); |
| 1677 | __ Ret(); |
| 1678 | |
| 1679 | __ bind(&runtime); |
| 1680 | // Handle number to string in the runtime system if not found in the cache. |
| 1681 | __ TailCallRuntime(Runtime::kNumberToString, 1, 1); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | |
| 1685 | // On entry lhs_ (lhs) and rhs_ (rhs) are the things to be compared. |
| 1686 | // On exit, v0 is 0, positive, or negative (smi) to indicate the result |
| 1687 | // of the comparison. |
| 1688 | void CompareStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1689 | Label slow; // Call builtin. |
| 1690 | Label not_smis, both_loaded_as_doubles; |
| 1691 | |
| 1692 | |
| 1693 | if (include_smi_compare_) { |
| 1694 | Label not_two_smis, smi_done; |
| 1695 | __ Or(a2, a1, a0); |
| 1696 | __ JumpIfNotSmi(a2, ¬_two_smis); |
| 1697 | __ sra(a1, a1, 1); |
| 1698 | __ sra(a0, a0, 1); |
| 1699 | __ Subu(v0, a1, a0); |
| 1700 | __ Ret(); |
| 1701 | __ bind(¬_two_smis); |
| 1702 | } else if (FLAG_debug_code) { |
| 1703 | __ Or(a2, a1, a0); |
| 1704 | __ And(a2, a2, kSmiTagMask); |
| 1705 | __ Assert(ne, "CompareStub: unexpected smi operands.", |
| 1706 | a2, Operand(zero_reg)); |
| 1707 | } |
| 1708 | |
| 1709 | |
| 1710 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 1711 | // it is certain that at least one operand isn't a smi. |
| 1712 | |
| 1713 | // Handle the case where the objects are identical. Either returns the answer |
| 1714 | // or goes to slow. Only falls through if the objects were not identical. |
| 1715 | EmitIdenticalObjectComparison(masm, &slow, cc_, never_nan_nan_); |
| 1716 | |
| 1717 | // If either is a Smi (we know that not both are), then they can only |
| 1718 | // be strictly equal if the other is a HeapNumber. |
| 1719 | STATIC_ASSERT(kSmiTag == 0); |
| 1720 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 1721 | __ And(t2, lhs_, Operand(rhs_)); |
| 1722 | __ JumpIfNotSmi(t2, ¬_smis, t0); |
| 1723 | // One operand is a smi. EmitSmiNonsmiComparison generates code that can: |
| 1724 | // 1) Return the answer. |
| 1725 | // 2) Go to slow. |
| 1726 | // 3) Fall through to both_loaded_as_doubles. |
| 1727 | // 4) Jump to rhs_not_nan. |
| 1728 | // In cases 3 and 4 we have found out we were dealing with a number-number |
| 1729 | // comparison and the numbers have been loaded into f12 and f14 as doubles, |
| 1730 | // or in GP registers (a0, a1, a2, a3) depending on the presence of the FPU. |
| 1731 | EmitSmiNonsmiComparison(masm, lhs_, rhs_, |
| 1732 | &both_loaded_as_doubles, &slow, strict_); |
| 1733 | |
| 1734 | __ bind(&both_loaded_as_doubles); |
| 1735 | // f12, f14 are the double representations of the left hand side |
| 1736 | // and the right hand side if we have FPU. Otherwise a2, a3 represent |
| 1737 | // left hand side and a0, a1 represent right hand side. |
| 1738 | |
| 1739 | Isolate* isolate = masm->isolate(); |
| 1740 | if (CpuFeatures::IsSupported(FPU)) { |
| 1741 | CpuFeatures::Scope scope(FPU); |
| 1742 | Label nan; |
| 1743 | __ li(t0, Operand(LESS)); |
| 1744 | __ li(t1, Operand(GREATER)); |
| 1745 | __ li(t2, Operand(EQUAL)); |
| 1746 | |
| 1747 | // Check if either rhs or lhs is NaN. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1748 | __ BranchF(NULL, &nan, eq, f12, f14); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1749 | |
| 1750 | // Check if LESS condition is satisfied. If true, move conditionally |
| 1751 | // result to v0. |
| 1752 | __ c(OLT, D, f12, f14); |
| 1753 | __ movt(v0, t0); |
| 1754 | // Use previous check to store conditionally to v0 oposite condition |
| 1755 | // (GREATER). If rhs is equal to lhs, this will be corrected in next |
| 1756 | // check. |
| 1757 | __ movf(v0, t1); |
| 1758 | // Check if EQUAL condition is satisfied. If true, move conditionally |
| 1759 | // result to v0. |
| 1760 | __ c(EQ, D, f12, f14); |
| 1761 | __ movt(v0, t2); |
| 1762 | |
| 1763 | __ Ret(); |
| 1764 | |
| 1765 | __ bind(&nan); |
| 1766 | // NaN comparisons always fail. |
| 1767 | // Load whatever we need in v0 to make the comparison fail. |
| 1768 | if (cc_ == lt || cc_ == le) { |
| 1769 | __ li(v0, Operand(GREATER)); |
| 1770 | } else { |
| 1771 | __ li(v0, Operand(LESS)); |
| 1772 | } |
| 1773 | __ Ret(); |
| 1774 | } else { |
| 1775 | // Checks for NaN in the doubles we have loaded. Can return the answer or |
| 1776 | // fall through if neither is a NaN. Also binds rhs_not_nan. |
| 1777 | EmitNanCheck(masm, cc_); |
| 1778 | |
| 1779 | // Compares two doubles that are not NaNs. Returns the answer. |
| 1780 | // Never falls through. |
| 1781 | EmitTwoNonNanDoubleComparison(masm, cc_); |
| 1782 | } |
| 1783 | |
| 1784 | __ bind(¬_smis); |
| 1785 | // At this point we know we are dealing with two different objects, |
| 1786 | // and neither of them is a Smi. The objects are in lhs_ and rhs_. |
| 1787 | if (strict_) { |
| 1788 | // This returns non-equal for some object types, or falls through if it |
| 1789 | // was not lucky. |
| 1790 | EmitStrictTwoHeapObjectCompare(masm, lhs_, rhs_); |
| 1791 | } |
| 1792 | |
| 1793 | Label check_for_symbols; |
| 1794 | Label flat_string_check; |
| 1795 | // Check for heap-number-heap-number comparison. Can jump to slow case, |
| 1796 | // or load both doubles and jump to the code that handles |
| 1797 | // that case. If the inputs are not doubles then jumps to check_for_symbols. |
| 1798 | // In this case a2 will contain the type of lhs_. |
| 1799 | EmitCheckForTwoHeapNumbers(masm, |
| 1800 | lhs_, |
| 1801 | rhs_, |
| 1802 | &both_loaded_as_doubles, |
| 1803 | &check_for_symbols, |
| 1804 | &flat_string_check); |
| 1805 | |
| 1806 | __ bind(&check_for_symbols); |
| 1807 | if (cc_ == eq && !strict_) { |
| 1808 | // Returns an answer for two symbols or two detectable objects. |
| 1809 | // Otherwise jumps to string case or not both strings case. |
| 1810 | // Assumes that a2 is the type of lhs_ on entry. |
| 1811 | EmitCheckForSymbolsOrObjects(masm, lhs_, rhs_, &flat_string_check, &slow); |
| 1812 | } |
| 1813 | |
| 1814 | // Check for both being sequential ASCII strings, and inline if that is the |
| 1815 | // case. |
| 1816 | __ bind(&flat_string_check); |
| 1817 | |
| 1818 | __ JumpIfNonSmisNotBothSequentialAsciiStrings(lhs_, rhs_, a2, a3, &slow); |
| 1819 | |
| 1820 | __ IncrementCounter(isolate->counters()->string_compare_native(), 1, a2, a3); |
| 1821 | if (cc_ == eq) { |
| 1822 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
| 1823 | lhs_, |
| 1824 | rhs_, |
| 1825 | a2, |
| 1826 | a3, |
| 1827 | t0); |
| 1828 | } else { |
| 1829 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 1830 | lhs_, |
| 1831 | rhs_, |
| 1832 | a2, |
| 1833 | a3, |
| 1834 | t0, |
| 1835 | t1); |
| 1836 | } |
| 1837 | // Never falls through to here. |
| 1838 | |
| 1839 | __ bind(&slow); |
| 1840 | // Prepare for call to builtin. Push object pointers, a0 (lhs) first, |
| 1841 | // a1 (rhs) second. |
| 1842 | __ Push(lhs_, rhs_); |
| 1843 | // Figure out which native to call and setup the arguments. |
| 1844 | Builtins::JavaScript native; |
| 1845 | if (cc_ == eq) { |
| 1846 | native = strict_ ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
| 1847 | } else { |
| 1848 | native = Builtins::COMPARE; |
| 1849 | int ncr; // NaN compare result. |
| 1850 | if (cc_ == lt || cc_ == le) { |
| 1851 | ncr = GREATER; |
| 1852 | } else { |
| 1853 | ASSERT(cc_ == gt || cc_ == ge); // Remaining cases. |
| 1854 | ncr = LESS; |
| 1855 | } |
| 1856 | __ li(a0, Operand(Smi::FromInt(ncr))); |
| 1857 | __ push(a0); |
| 1858 | } |
| 1859 | |
| 1860 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 1861 | // tagged as a small integer. |
| 1862 | __ InvokeBuiltin(native, JUMP_FUNCTION); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1866 | // The stub expects its argument in the tos_ register and returns its result in |
| 1867 | // it, too: zero for false, and a non-zero value for true. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1868 | void ToBooleanStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1869 | // This stub uses FPU instructions. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1870 | CpuFeatures::Scope scope(FPU); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1871 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1872 | Label patch; |
| 1873 | const Register map = t5.is(tos_) ? t3 : t5; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1874 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1875 | // undefined -> false. |
| 1876 | CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1877 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1878 | // Boolean -> its value. |
| 1879 | CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); |
| 1880 | CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1881 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1882 | // 'null' -> false. |
| 1883 | CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1884 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1885 | if (types_.Contains(SMI)) { |
| 1886 | // Smis: 0 -> false, all other -> true |
| 1887 | __ And(at, tos_, kSmiTagMask); |
| 1888 | // tos_ contains the correct return value already |
| 1889 | __ Ret(eq, at, Operand(zero_reg)); |
| 1890 | } else if (types_.NeedsMap()) { |
| 1891 | // If we need a map later and have a Smi -> patch. |
| 1892 | __ JumpIfSmi(tos_, &patch); |
| 1893 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1894 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1895 | if (types_.NeedsMap()) { |
| 1896 | __ lw(map, FieldMemOperand(tos_, HeapObject::kMapOffset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1897 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1898 | if (types_.CanBeUndetectable()) { |
| 1899 | __ lbu(at, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 1900 | __ And(at, at, Operand(1 << Map::kIsUndetectable)); |
| 1901 | // Undetectable -> false. |
| 1902 | __ movn(tos_, zero_reg, at); |
| 1903 | __ Ret(ne, at, Operand(zero_reg)); |
| 1904 | } |
| 1905 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1906 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1907 | if (types_.Contains(SPEC_OBJECT)) { |
| 1908 | // Spec object -> true. |
| 1909 | __ lbu(at, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1910 | // tos_ contains the correct non-zero return value already. |
| 1911 | __ Ret(ge, at, Operand(FIRST_SPEC_OBJECT_TYPE)); |
| 1912 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1913 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1914 | if (types_.Contains(STRING)) { |
| 1915 | // String value -> false iff empty. |
| 1916 | __ lbu(at, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1917 | Label skip; |
| 1918 | __ Branch(&skip, ge, at, Operand(FIRST_NONSTRING_TYPE)); |
| 1919 | __ lw(tos_, FieldMemOperand(tos_, String::kLengthOffset)); |
| 1920 | __ Ret(); // the string length is OK as the return value |
| 1921 | __ bind(&skip); |
| 1922 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1923 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1924 | if (types_.Contains(HEAP_NUMBER)) { |
| 1925 | // Heap number -> false iff +0, -0, or NaN. |
| 1926 | Label not_heap_number; |
| 1927 | __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
| 1928 | __ Branch(¬_heap_number, ne, map, Operand(at)); |
| 1929 | Label zero_or_nan, number; |
| 1930 | __ ldc1(f2, FieldMemOperand(tos_, HeapNumber::kValueOffset)); |
| 1931 | __ BranchF(&number, &zero_or_nan, ne, f2, kDoubleRegZero); |
| 1932 | // "tos_" is a register, and contains a non zero value by default. |
| 1933 | // Hence we only need to overwrite "tos_" with zero to return false for |
| 1934 | // FP_ZERO or FP_NAN cases. Otherwise, by default it returns true. |
| 1935 | __ bind(&zero_or_nan); |
| 1936 | __ mov(tos_, zero_reg); |
| 1937 | __ bind(&number); |
| 1938 | __ Ret(); |
| 1939 | __ bind(¬_heap_number); |
| 1940 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1941 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1942 | __ bind(&patch); |
| 1943 | GenerateTypeTransition(masm); |
| 1944 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1945 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1946 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1947 | void ToBooleanStub::CheckOddball(MacroAssembler* masm, |
| 1948 | Type type, |
| 1949 | Heap::RootListIndex value, |
| 1950 | bool result) { |
| 1951 | if (types_.Contains(type)) { |
| 1952 | // If we see an expected oddball, return its ToBoolean value tos_. |
| 1953 | __ LoadRoot(at, value); |
| 1954 | __ Subu(at, at, tos_); // This is a check for equality for the movz below. |
| 1955 | // The value of a root is never NULL, so we can avoid loading a non-null |
| 1956 | // value into tos_ when we want to return 'true'. |
| 1957 | if (!result) { |
| 1958 | __ movz(tos_, zero_reg, at); |
| 1959 | } |
| 1960 | __ Ret(eq, at, Operand(zero_reg)); |
| 1961 | } |
| 1962 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1963 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1964 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1965 | void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 1966 | __ Move(a3, tos_); |
| 1967 | __ li(a2, Operand(Smi::FromInt(tos_.code()))); |
| 1968 | __ li(a1, Operand(Smi::FromInt(types_.ToByte()))); |
| 1969 | __ Push(a3, a2, a1); |
| 1970 | // Patch the caller to an appropriate specialized stub and return the |
| 1971 | // operation result to the caller of the stub. |
| 1972 | __ TailCallExternalReference( |
| 1973 | ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), |
| 1974 | 3, |
| 1975 | 1); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1979 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 1980 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 1981 | // store the registers in any particular way, but we do have to store and |
| 1982 | // restore them. |
| 1983 | __ MultiPush(kJSCallerSaved | ra.bit()); |
| 1984 | if (save_doubles_ == kSaveFPRegs) { |
| 1985 | CpuFeatures::Scope scope(FPU); |
| 1986 | __ MultiPushFPU(kCallerSavedFPU); |
| 1987 | } |
| 1988 | const int argument_count = 1; |
| 1989 | const int fp_argument_count = 0; |
| 1990 | const Register scratch = a1; |
| 1991 | |
| 1992 | AllowExternalCallThatCantCauseGC scope(masm); |
| 1993 | __ PrepareCallCFunction(argument_count, fp_argument_count, scratch); |
| 1994 | __ li(a0, Operand(ExternalReference::isolate_address())); |
| 1995 | __ CallCFunction( |
| 1996 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 1997 | argument_count); |
| 1998 | if (save_doubles_ == kSaveFPRegs) { |
| 1999 | CpuFeatures::Scope scope(FPU); |
| 2000 | __ MultiPopFPU(kCallerSavedFPU); |
| 2001 | } |
| 2002 | |
| 2003 | __ MultiPop(kJSCallerSaved | ra.bit()); |
| 2004 | __ Ret(); |
| 2005 | } |
| 2006 | |
| 2007 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 2008 | void UnaryOpStub::PrintName(StringStream* stream) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2009 | const char* op_name = Token::Name(op_); |
| 2010 | const char* overwrite_name = NULL; // Make g++ happy. |
| 2011 | switch (mode_) { |
| 2012 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 2013 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 2014 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 2015 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 2016 | op_name, |
| 2017 | overwrite_name, |
| 2018 | UnaryOpIC::GetName(operand_type_)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | |
| 2022 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2023 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2024 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2025 | case UnaryOpIC::UNINITIALIZED: |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2026 | GenerateTypeTransition(masm); |
| 2027 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2028 | case UnaryOpIC::SMI: |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2029 | GenerateSmiStub(masm); |
| 2030 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2031 | case UnaryOpIC::HEAP_NUMBER: |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2032 | GenerateHeapNumberStub(masm); |
| 2033 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2034 | case UnaryOpIC::GENERIC: |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2035 | GenerateGenericStub(masm); |
| 2036 | break; |
| 2037 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2041 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2042 | // Argument is in a0 and v0 at this point, so we can overwrite a0. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2043 | __ li(a2, Operand(Smi::FromInt(op_))); |
| 2044 | __ li(a1, Operand(Smi::FromInt(mode_))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2045 | __ li(a0, Operand(Smi::FromInt(operand_type_))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2046 | __ Push(v0, a2, a1, a0); |
| 2047 | |
| 2048 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2049 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | |
| 2053 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2054 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2055 | switch (op_) { |
| 2056 | case Token::SUB: |
| 2057 | GenerateSmiStubSub(masm); |
| 2058 | break; |
| 2059 | case Token::BIT_NOT: |
| 2060 | GenerateSmiStubBitNot(masm); |
| 2061 | break; |
| 2062 | default: |
| 2063 | UNREACHABLE(); |
| 2064 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2068 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2069 | Label non_smi, slow; |
| 2070 | GenerateSmiCodeSub(masm, &non_smi, &slow); |
| 2071 | __ bind(&non_smi); |
| 2072 | __ bind(&slow); |
| 2073 | GenerateTypeTransition(masm); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2077 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2078 | Label non_smi; |
| 2079 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 2080 | __ bind(&non_smi); |
| 2081 | GenerateTypeTransition(masm); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2085 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 2086 | Label* non_smi, |
| 2087 | Label* slow) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2088 | __ JumpIfNotSmi(a0, non_smi); |
| 2089 | |
| 2090 | // The result of negating zero or the smallest negative smi is not a smi. |
| 2091 | __ And(t0, a0, ~0x80000000); |
| 2092 | __ Branch(slow, eq, t0, Operand(zero_reg)); |
| 2093 | |
| 2094 | // Return '0 - value'. |
| 2095 | __ Subu(v0, zero_reg, a0); |
| 2096 | __ Ret(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2100 | void UnaryOpStub::GenerateSmiCodeBitNot(MacroAssembler* masm, |
| 2101 | Label* non_smi) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2102 | __ JumpIfNotSmi(a0, non_smi); |
| 2103 | |
| 2104 | // Flip bits and revert inverted smi-tag. |
| 2105 | __ Neg(v0, a0); |
| 2106 | __ And(v0, v0, ~kSmiTagMask); |
| 2107 | __ Ret(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | |
| 2111 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2112 | void UnaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2113 | switch (op_) { |
| 2114 | case Token::SUB: |
| 2115 | GenerateHeapNumberStubSub(masm); |
| 2116 | break; |
| 2117 | case Token::BIT_NOT: |
| 2118 | GenerateHeapNumberStubBitNot(masm); |
| 2119 | break; |
| 2120 | default: |
| 2121 | UNREACHABLE(); |
| 2122 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2126 | void UnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) { |
| 2127 | Label non_smi, slow, call_builtin; |
| 2128 | GenerateSmiCodeSub(masm, &non_smi, &call_builtin); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2129 | __ bind(&non_smi); |
| 2130 | GenerateHeapNumberCodeSub(masm, &slow); |
| 2131 | __ bind(&slow); |
| 2132 | GenerateTypeTransition(masm); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2133 | __ bind(&call_builtin); |
| 2134 | GenerateGenericCodeFallback(masm); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2138 | void UnaryOpStub::GenerateHeapNumberStubBitNot(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2139 | Label non_smi, slow; |
| 2140 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 2141 | __ bind(&non_smi); |
| 2142 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 2143 | __ bind(&slow); |
| 2144 | GenerateTypeTransition(masm); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2145 | } |
| 2146 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 2147 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2148 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 2149 | Label* slow) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2150 | EmitCheckForHeapNumber(masm, a0, a1, t2, slow); |
| 2151 | // a0 is a heap number. Get a new heap number in a1. |
| 2152 | if (mode_ == UNARY_OVERWRITE) { |
| 2153 | __ lw(a2, FieldMemOperand(a0, HeapNumber::kExponentOffset)); |
| 2154 | __ Xor(a2, a2, Operand(HeapNumber::kSignMask)); // Flip sign. |
| 2155 | __ sw(a2, FieldMemOperand(a0, HeapNumber::kExponentOffset)); |
| 2156 | } else { |
| 2157 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 2158 | __ AllocateHeapNumber(a1, a2, a3, t2, &slow_allocate_heapnumber); |
| 2159 | __ jmp(&heapnumber_allocated); |
| 2160 | |
| 2161 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2162 | { |
| 2163 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2164 | __ push(a0); |
| 2165 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 2166 | __ mov(a1, v0); |
| 2167 | __ pop(a0); |
| 2168 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2169 | |
| 2170 | __ bind(&heapnumber_allocated); |
| 2171 | __ lw(a3, FieldMemOperand(a0, HeapNumber::kMantissaOffset)); |
| 2172 | __ lw(a2, FieldMemOperand(a0, HeapNumber::kExponentOffset)); |
| 2173 | __ sw(a3, FieldMemOperand(a1, HeapNumber::kMantissaOffset)); |
| 2174 | __ Xor(a2, a2, Operand(HeapNumber::kSignMask)); // Flip sign. |
| 2175 | __ sw(a2, FieldMemOperand(a1, HeapNumber::kExponentOffset)); |
| 2176 | __ mov(v0, a1); |
| 2177 | } |
| 2178 | __ Ret(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2179 | } |
| 2180 | |
| 2181 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2182 | void UnaryOpStub::GenerateHeapNumberCodeBitNot( |
| 2183 | MacroAssembler* masm, |
| 2184 | Label* slow) { |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2185 | Label impossible; |
| 2186 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2187 | EmitCheckForHeapNumber(masm, a0, a1, t2, slow); |
| 2188 | // Convert the heap number in a0 to an untagged integer in a1. |
| 2189 | __ ConvertToInt32(a0, a1, a2, a3, f0, slow); |
| 2190 | |
| 2191 | // Do the bitwise operation and check if the result fits in a smi. |
| 2192 | Label try_float; |
| 2193 | __ Neg(a1, a1); |
| 2194 | __ Addu(a2, a1, Operand(0x40000000)); |
| 2195 | __ Branch(&try_float, lt, a2, Operand(zero_reg)); |
| 2196 | |
| 2197 | // Tag the result as a smi and we're done. |
| 2198 | __ SmiTag(v0, a1); |
| 2199 | __ Ret(); |
| 2200 | |
| 2201 | // Try to store the result in a heap number. |
| 2202 | __ bind(&try_float); |
| 2203 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 2204 | Label slow_allocate_heapnumber, heapnumber_allocated; |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2205 | // Allocate a new heap number without zapping v0, which we need if it fails. |
| 2206 | __ AllocateHeapNumber(a2, a3, t0, t2, &slow_allocate_heapnumber); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2207 | __ jmp(&heapnumber_allocated); |
| 2208 | |
| 2209 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2210 | { |
| 2211 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2212 | __ push(v0); // Push the heap number, not the untagged int32. |
| 2213 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 2214 | __ mov(a2, v0); // Move the new heap number into a2. |
| 2215 | // Get the heap number into v0, now that the new heap number is in a2. |
| 2216 | __ pop(v0); |
| 2217 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2218 | |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2219 | // Convert the heap number in v0 to an untagged integer in a1. |
| 2220 | // This can't go slow-case because it's the same number we already |
| 2221 | // converted once again. |
| 2222 | __ ConvertToInt32(v0, a1, a3, t0, f0, &impossible); |
| 2223 | // Negate the result. |
| 2224 | __ Xor(a1, a1, -1); |
| 2225 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2226 | __ bind(&heapnumber_allocated); |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2227 | __ mov(v0, a2); // Move newly allocated heap number to v0. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | if (CpuFeatures::IsSupported(FPU)) { |
| 2231 | // Convert the int32 in a1 to the heap number in v0. a2 is corrupted. |
| 2232 | CpuFeatures::Scope scope(FPU); |
| 2233 | __ mtc1(a1, f0); |
| 2234 | __ cvt_d_w(f0, f0); |
| 2235 | __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset)); |
| 2236 | __ Ret(); |
| 2237 | } else { |
| 2238 | // WriteInt32ToHeapNumberStub does not trigger GC, so we do not |
| 2239 | // have to set up a frame. |
| 2240 | WriteInt32ToHeapNumberStub stub(a1, v0, a2, a3); |
| 2241 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 2242 | } |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2243 | |
| 2244 | __ bind(&impossible); |
| 2245 | if (FLAG_debug_code) { |
| 2246 | __ stop("Incorrect assumption in bit-not stub"); |
| 2247 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | |
| 2251 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2252 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2253 | switch (op_) { |
| 2254 | case Token::SUB: |
| 2255 | GenerateGenericStubSub(masm); |
| 2256 | break; |
| 2257 | case Token::BIT_NOT: |
| 2258 | GenerateGenericStubBitNot(masm); |
| 2259 | break; |
| 2260 | default: |
| 2261 | UNREACHABLE(); |
| 2262 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2266 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2267 | Label non_smi, slow; |
| 2268 | GenerateSmiCodeSub(masm, &non_smi, &slow); |
| 2269 | __ bind(&non_smi); |
| 2270 | GenerateHeapNumberCodeSub(masm, &slow); |
| 2271 | __ bind(&slow); |
| 2272 | GenerateGenericCodeFallback(masm); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2276 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2277 | Label non_smi, slow; |
| 2278 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 2279 | __ bind(&non_smi); |
| 2280 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 2281 | __ bind(&slow); |
| 2282 | GenerateGenericCodeFallback(masm); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2286 | void UnaryOpStub::GenerateGenericCodeFallback( |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2287 | MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2288 | // Handle the slow case by jumping to the JavaScript builtin. |
| 2289 | __ push(a0); |
| 2290 | switch (op_) { |
| 2291 | case Token::SUB: |
| 2292 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 2293 | break; |
| 2294 | case Token::BIT_NOT: |
| 2295 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 2296 | break; |
| 2297 | default: |
| 2298 | UNREACHABLE(); |
| 2299 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2303 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2304 | Label get_result; |
| 2305 | |
| 2306 | __ Push(a1, a0); |
| 2307 | |
| 2308 | __ li(a2, Operand(Smi::FromInt(MinorKey()))); |
| 2309 | __ li(a1, Operand(Smi::FromInt(op_))); |
| 2310 | __ li(a0, Operand(Smi::FromInt(operands_type_))); |
| 2311 | __ Push(a2, a1, a0); |
| 2312 | |
| 2313 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2314 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2315 | masm->isolate()), |
| 2316 | 5, |
| 2317 | 1); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2321 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs( |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2322 | MacroAssembler* masm) { |
| 2323 | UNIMPLEMENTED(); |
| 2324 | } |
| 2325 | |
| 2326 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2327 | void BinaryOpStub::Generate(MacroAssembler* masm) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 2328 | // Explicitly allow generation of nested stubs. It is safe here because |
| 2329 | // generation code does not use any raw pointers. |
| 2330 | AllowStubCallsScope allow_stub_calls(masm, true); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2331 | switch (operands_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2332 | case BinaryOpIC::UNINITIALIZED: |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2333 | GenerateTypeTransition(masm); |
| 2334 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2335 | case BinaryOpIC::SMI: |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2336 | GenerateSmiStub(masm); |
| 2337 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2338 | case BinaryOpIC::INT32: |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2339 | GenerateInt32Stub(masm); |
| 2340 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2341 | case BinaryOpIC::HEAP_NUMBER: |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2342 | GenerateHeapNumberStub(masm); |
| 2343 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2344 | case BinaryOpIC::ODDBALL: |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2345 | GenerateOddballStub(masm); |
| 2346 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2347 | case BinaryOpIC::BOTH_STRING: |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2348 | GenerateBothStringStub(masm); |
| 2349 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2350 | case BinaryOpIC::STRING: |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2351 | GenerateStringStub(masm); |
| 2352 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2353 | case BinaryOpIC::GENERIC: |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2354 | GenerateGeneric(masm); |
| 2355 | break; |
| 2356 | default: |
| 2357 | UNREACHABLE(); |
| 2358 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 2362 | void BinaryOpStub::PrintName(StringStream* stream) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2363 | const char* op_name = Token::Name(op_); |
| 2364 | const char* overwrite_name; |
| 2365 | switch (mode_) { |
| 2366 | case NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 2367 | case OVERWRITE_RIGHT: overwrite_name = "OverwriteRight"; break; |
| 2368 | case OVERWRITE_LEFT: overwrite_name = "OverwriteLeft"; break; |
| 2369 | default: overwrite_name = "UnknownOverwrite"; break; |
| 2370 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 2371 | stream->Add("BinaryOpStub_%s_%s_%s", |
| 2372 | op_name, |
| 2373 | overwrite_name, |
| 2374 | BinaryOpIC::GetName(operands_type_)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | |
| 2378 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2379 | void BinaryOpStub::GenerateSmiSmiOperation(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2380 | Register left = a1; |
| 2381 | Register right = a0; |
| 2382 | |
| 2383 | Register scratch1 = t0; |
| 2384 | Register scratch2 = t1; |
| 2385 | |
| 2386 | ASSERT(right.is(a0)); |
| 2387 | STATIC_ASSERT(kSmiTag == 0); |
| 2388 | |
| 2389 | Label not_smi_result; |
| 2390 | switch (op_) { |
| 2391 | case Token::ADD: |
| 2392 | __ AdduAndCheckForOverflow(v0, left, right, scratch1); |
| 2393 | __ RetOnNoOverflow(scratch1); |
| 2394 | // No need to revert anything - right and left are intact. |
| 2395 | break; |
| 2396 | case Token::SUB: |
| 2397 | __ SubuAndCheckForOverflow(v0, left, right, scratch1); |
| 2398 | __ RetOnNoOverflow(scratch1); |
| 2399 | // No need to revert anything - right and left are intact. |
| 2400 | break; |
| 2401 | case Token::MUL: { |
| 2402 | // Remove tag from one of the operands. This way the multiplication result |
| 2403 | // will be a smi if it fits the smi range. |
| 2404 | __ SmiUntag(scratch1, right); |
| 2405 | // Do multiplication. |
| 2406 | // lo = lower 32 bits of scratch1 * left. |
| 2407 | // hi = higher 32 bits of scratch1 * left. |
| 2408 | __ Mult(left, scratch1); |
| 2409 | // Check for overflowing the smi range - no overflow if higher 33 bits of |
| 2410 | // the result are identical. |
| 2411 | __ mflo(scratch1); |
| 2412 | __ mfhi(scratch2); |
| 2413 | __ sra(scratch1, scratch1, 31); |
| 2414 | __ Branch(¬_smi_result, ne, scratch1, Operand(scratch2)); |
| 2415 | // Go slow on zero result to handle -0. |
| 2416 | __ mflo(v0); |
| 2417 | __ Ret(ne, v0, Operand(zero_reg)); |
| 2418 | // We need -0 if we were multiplying a negative number with 0 to get 0. |
| 2419 | // We know one of them was zero. |
| 2420 | __ Addu(scratch2, right, left); |
| 2421 | Label skip; |
| 2422 | // ARM uses the 'pl' condition, which is 'ge'. |
| 2423 | // Negating it results in 'lt'. |
| 2424 | __ Branch(&skip, lt, scratch2, Operand(zero_reg)); |
| 2425 | ASSERT(Smi::FromInt(0) == 0); |
| 2426 | __ mov(v0, zero_reg); |
| 2427 | __ Ret(); // Return smi 0 if the non-zero one was positive. |
| 2428 | __ bind(&skip); |
| 2429 | // We fall through here if we multiplied a negative number with 0, because |
| 2430 | // that would mean we should produce -0. |
| 2431 | } |
| 2432 | break; |
| 2433 | case Token::DIV: { |
| 2434 | Label done; |
| 2435 | __ SmiUntag(scratch2, right); |
| 2436 | __ SmiUntag(scratch1, left); |
| 2437 | __ Div(scratch1, scratch2); |
| 2438 | // A minor optimization: div may be calculated asynchronously, so we check |
| 2439 | // for division by zero before getting the result. |
| 2440 | __ Branch(¬_smi_result, eq, scratch2, Operand(zero_reg)); |
| 2441 | // If the result is 0, we need to make sure the dividsor (right) is |
| 2442 | // positive, otherwise it is a -0 case. |
| 2443 | // Quotient is in 'lo', remainder is in 'hi'. |
| 2444 | // Check for no remainder first. |
| 2445 | __ mfhi(scratch1); |
| 2446 | __ Branch(¬_smi_result, ne, scratch1, Operand(zero_reg)); |
| 2447 | __ mflo(scratch1); |
| 2448 | __ Branch(&done, ne, scratch1, Operand(zero_reg)); |
| 2449 | __ Branch(¬_smi_result, lt, scratch2, Operand(zero_reg)); |
| 2450 | __ bind(&done); |
| 2451 | // Check that the signed result fits in a Smi. |
| 2452 | __ Addu(scratch2, scratch1, Operand(0x40000000)); |
| 2453 | __ Branch(¬_smi_result, lt, scratch2, Operand(zero_reg)); |
| 2454 | __ SmiTag(v0, scratch1); |
| 2455 | __ Ret(); |
| 2456 | } |
| 2457 | break; |
| 2458 | case Token::MOD: { |
| 2459 | Label done; |
| 2460 | __ SmiUntag(scratch2, right); |
| 2461 | __ SmiUntag(scratch1, left); |
| 2462 | __ Div(scratch1, scratch2); |
| 2463 | // A minor optimization: div may be calculated asynchronously, so we check |
| 2464 | // for division by 0 before calling mfhi. |
| 2465 | // Check for zero on the right hand side. |
| 2466 | __ Branch(¬_smi_result, eq, scratch2, Operand(zero_reg)); |
| 2467 | // If the result is 0, we need to make sure the dividend (left) is |
| 2468 | // positive (or 0), otherwise it is a -0 case. |
| 2469 | // Remainder is in 'hi'. |
| 2470 | __ mfhi(scratch2); |
| 2471 | __ Branch(&done, ne, scratch2, Operand(zero_reg)); |
| 2472 | __ Branch(¬_smi_result, lt, scratch1, Operand(zero_reg)); |
| 2473 | __ bind(&done); |
| 2474 | // Check that the signed result fits in a Smi. |
| 2475 | __ Addu(scratch1, scratch2, Operand(0x40000000)); |
| 2476 | __ Branch(¬_smi_result, lt, scratch1, Operand(zero_reg)); |
| 2477 | __ SmiTag(v0, scratch2); |
| 2478 | __ Ret(); |
| 2479 | } |
| 2480 | break; |
| 2481 | case Token::BIT_OR: |
| 2482 | __ Or(v0, left, Operand(right)); |
| 2483 | __ Ret(); |
| 2484 | break; |
| 2485 | case Token::BIT_AND: |
| 2486 | __ And(v0, left, Operand(right)); |
| 2487 | __ Ret(); |
| 2488 | break; |
| 2489 | case Token::BIT_XOR: |
| 2490 | __ Xor(v0, left, Operand(right)); |
| 2491 | __ Ret(); |
| 2492 | break; |
| 2493 | case Token::SAR: |
| 2494 | // Remove tags from right operand. |
| 2495 | __ GetLeastBitsFromSmi(scratch1, right, 5); |
| 2496 | __ srav(scratch1, left, scratch1); |
| 2497 | // Smi tag result. |
| 2498 | __ And(v0, scratch1, Operand(~kSmiTagMask)); |
| 2499 | __ Ret(); |
| 2500 | break; |
| 2501 | case Token::SHR: |
| 2502 | // Remove tags from operands. We can't do this on a 31 bit number |
| 2503 | // because then the 0s get shifted into bit 30 instead of bit 31. |
| 2504 | __ SmiUntag(scratch1, left); |
| 2505 | __ GetLeastBitsFromSmi(scratch2, right, 5); |
| 2506 | __ srlv(v0, scratch1, scratch2); |
| 2507 | // Unsigned shift is not allowed to produce a negative number, so |
| 2508 | // check the sign bit and the sign bit after Smi tagging. |
| 2509 | __ And(scratch1, v0, Operand(0xc0000000)); |
| 2510 | __ Branch(¬_smi_result, ne, scratch1, Operand(zero_reg)); |
| 2511 | // Smi tag result. |
| 2512 | __ SmiTag(v0); |
| 2513 | __ Ret(); |
| 2514 | break; |
| 2515 | case Token::SHL: |
| 2516 | // Remove tags from operands. |
| 2517 | __ SmiUntag(scratch1, left); |
| 2518 | __ GetLeastBitsFromSmi(scratch2, right, 5); |
| 2519 | __ sllv(scratch1, scratch1, scratch2); |
| 2520 | // Check that the signed result fits in a Smi. |
| 2521 | __ Addu(scratch2, scratch1, Operand(0x40000000)); |
| 2522 | __ Branch(¬_smi_result, lt, scratch2, Operand(zero_reg)); |
| 2523 | __ SmiTag(v0, scratch1); |
| 2524 | __ Ret(); |
| 2525 | break; |
| 2526 | default: |
| 2527 | UNREACHABLE(); |
| 2528 | } |
| 2529 | __ bind(¬_smi_result); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2533 | void BinaryOpStub::GenerateFPOperation(MacroAssembler* masm, |
| 2534 | bool smi_operands, |
| 2535 | Label* not_numbers, |
| 2536 | Label* gc_required) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2537 | Register left = a1; |
| 2538 | Register right = a0; |
| 2539 | Register scratch1 = t3; |
| 2540 | Register scratch2 = t5; |
| 2541 | Register scratch3 = t0; |
| 2542 | |
| 2543 | ASSERT(smi_operands || (not_numbers != NULL)); |
| 2544 | if (smi_operands && FLAG_debug_code) { |
| 2545 | __ AbortIfNotSmi(left); |
| 2546 | __ AbortIfNotSmi(right); |
| 2547 | } |
| 2548 | |
| 2549 | Register heap_number_map = t2; |
| 2550 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2551 | |
| 2552 | switch (op_) { |
| 2553 | case Token::ADD: |
| 2554 | case Token::SUB: |
| 2555 | case Token::MUL: |
| 2556 | case Token::DIV: |
| 2557 | case Token::MOD: { |
| 2558 | // Load left and right operands into f12 and f14 or a0/a1 and a2/a3 |
| 2559 | // depending on whether FPU is available or not. |
| 2560 | FloatingPointHelper::Destination destination = |
| 2561 | CpuFeatures::IsSupported(FPU) && |
| 2562 | op_ != Token::MOD ? |
| 2563 | FloatingPointHelper::kFPURegisters : |
| 2564 | FloatingPointHelper::kCoreRegisters; |
| 2565 | |
| 2566 | // Allocate new heap number for result. |
| 2567 | Register result = s0; |
| 2568 | GenerateHeapResultAllocation( |
| 2569 | masm, result, heap_number_map, scratch1, scratch2, gc_required); |
| 2570 | |
| 2571 | // Load the operands. |
| 2572 | if (smi_operands) { |
| 2573 | FloatingPointHelper::LoadSmis(masm, destination, scratch1, scratch2); |
| 2574 | } else { |
| 2575 | FloatingPointHelper::LoadOperands(masm, |
| 2576 | destination, |
| 2577 | heap_number_map, |
| 2578 | scratch1, |
| 2579 | scratch2, |
| 2580 | not_numbers); |
| 2581 | } |
| 2582 | |
| 2583 | // Calculate the result. |
| 2584 | if (destination == FloatingPointHelper::kFPURegisters) { |
| 2585 | // Using FPU registers: |
| 2586 | // f12: Left value. |
| 2587 | // f14: Right value. |
| 2588 | CpuFeatures::Scope scope(FPU); |
| 2589 | switch (op_) { |
| 2590 | case Token::ADD: |
| 2591 | __ add_d(f10, f12, f14); |
| 2592 | break; |
| 2593 | case Token::SUB: |
| 2594 | __ sub_d(f10, f12, f14); |
| 2595 | break; |
| 2596 | case Token::MUL: |
| 2597 | __ mul_d(f10, f12, f14); |
| 2598 | break; |
| 2599 | case Token::DIV: |
| 2600 | __ div_d(f10, f12, f14); |
| 2601 | break; |
| 2602 | default: |
| 2603 | UNREACHABLE(); |
| 2604 | } |
| 2605 | |
| 2606 | // ARM uses a workaround here because of the unaligned HeapNumber |
| 2607 | // kValueOffset. On MIPS this workaround is built into sdc1 so |
| 2608 | // there's no point in generating even more instructions. |
| 2609 | __ sdc1(f10, FieldMemOperand(result, HeapNumber::kValueOffset)); |
| 2610 | __ mov(v0, result); |
| 2611 | __ Ret(); |
| 2612 | } else { |
| 2613 | // Call the C function to handle the double operation. |
| 2614 | FloatingPointHelper::CallCCodeForDoubleOperation(masm, |
| 2615 | op_, |
| 2616 | result, |
| 2617 | scratch1); |
| 2618 | if (FLAG_debug_code) { |
| 2619 | __ stop("Unreachable code."); |
| 2620 | } |
| 2621 | } |
| 2622 | break; |
| 2623 | } |
| 2624 | case Token::BIT_OR: |
| 2625 | case Token::BIT_XOR: |
| 2626 | case Token::BIT_AND: |
| 2627 | case Token::SAR: |
| 2628 | case Token::SHR: |
| 2629 | case Token::SHL: { |
| 2630 | if (smi_operands) { |
| 2631 | __ SmiUntag(a3, left); |
| 2632 | __ SmiUntag(a2, right); |
| 2633 | } else { |
| 2634 | // Convert operands to 32-bit integers. Right in a2 and left in a3. |
| 2635 | FloatingPointHelper::ConvertNumberToInt32(masm, |
| 2636 | left, |
| 2637 | a3, |
| 2638 | heap_number_map, |
| 2639 | scratch1, |
| 2640 | scratch2, |
| 2641 | scratch3, |
| 2642 | f0, |
| 2643 | not_numbers); |
| 2644 | FloatingPointHelper::ConvertNumberToInt32(masm, |
| 2645 | right, |
| 2646 | a2, |
| 2647 | heap_number_map, |
| 2648 | scratch1, |
| 2649 | scratch2, |
| 2650 | scratch3, |
| 2651 | f0, |
| 2652 | not_numbers); |
| 2653 | } |
| 2654 | Label result_not_a_smi; |
| 2655 | switch (op_) { |
| 2656 | case Token::BIT_OR: |
| 2657 | __ Or(a2, a3, Operand(a2)); |
| 2658 | break; |
| 2659 | case Token::BIT_XOR: |
| 2660 | __ Xor(a2, a3, Operand(a2)); |
| 2661 | break; |
| 2662 | case Token::BIT_AND: |
| 2663 | __ And(a2, a3, Operand(a2)); |
| 2664 | break; |
| 2665 | case Token::SAR: |
| 2666 | // Use only the 5 least significant bits of the shift count. |
| 2667 | __ GetLeastBitsFromInt32(a2, a2, 5); |
| 2668 | __ srav(a2, a3, a2); |
| 2669 | break; |
| 2670 | case Token::SHR: |
| 2671 | // Use only the 5 least significant bits of the shift count. |
| 2672 | __ GetLeastBitsFromInt32(a2, a2, 5); |
| 2673 | __ srlv(a2, a3, a2); |
| 2674 | // SHR is special because it is required to produce a positive answer. |
| 2675 | // The code below for writing into heap numbers isn't capable of |
| 2676 | // writing the register as an unsigned int so we go to slow case if we |
| 2677 | // hit this case. |
| 2678 | if (CpuFeatures::IsSupported(FPU)) { |
| 2679 | __ Branch(&result_not_a_smi, lt, a2, Operand(zero_reg)); |
| 2680 | } else { |
| 2681 | __ Branch(not_numbers, lt, a2, Operand(zero_reg)); |
| 2682 | } |
| 2683 | break; |
| 2684 | case Token::SHL: |
| 2685 | // Use only the 5 least significant bits of the shift count. |
| 2686 | __ GetLeastBitsFromInt32(a2, a2, 5); |
| 2687 | __ sllv(a2, a3, a2); |
| 2688 | break; |
| 2689 | default: |
| 2690 | UNREACHABLE(); |
| 2691 | } |
| 2692 | // Check that the *signed* result fits in a smi. |
| 2693 | __ Addu(a3, a2, Operand(0x40000000)); |
| 2694 | __ Branch(&result_not_a_smi, lt, a3, Operand(zero_reg)); |
| 2695 | __ SmiTag(v0, a2); |
| 2696 | __ Ret(); |
| 2697 | |
| 2698 | // Allocate new heap number for result. |
| 2699 | __ bind(&result_not_a_smi); |
| 2700 | Register result = t1; |
| 2701 | if (smi_operands) { |
| 2702 | __ AllocateHeapNumber( |
| 2703 | result, scratch1, scratch2, heap_number_map, gc_required); |
| 2704 | } else { |
| 2705 | GenerateHeapResultAllocation( |
| 2706 | masm, result, heap_number_map, scratch1, scratch2, gc_required); |
| 2707 | } |
| 2708 | |
| 2709 | // a2: Answer as signed int32. |
| 2710 | // t1: Heap number to write answer into. |
| 2711 | |
| 2712 | // Nothing can go wrong now, so move the heap number to v0, which is the |
| 2713 | // result. |
| 2714 | __ mov(v0, t1); |
| 2715 | |
| 2716 | if (CpuFeatures::IsSupported(FPU)) { |
| 2717 | // Convert the int32 in a2 to the heap number in a0. As |
| 2718 | // mentioned above SHR needs to always produce a positive result. |
| 2719 | CpuFeatures::Scope scope(FPU); |
| 2720 | __ mtc1(a2, f0); |
| 2721 | if (op_ == Token::SHR) { |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2722 | __ Cvt_d_uw(f0, f0, f22); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2723 | } else { |
| 2724 | __ cvt_d_w(f0, f0); |
| 2725 | } |
| 2726 | // ARM uses a workaround here because of the unaligned HeapNumber |
| 2727 | // kValueOffset. On MIPS this workaround is built into sdc1 so |
| 2728 | // there's no point in generating even more instructions. |
| 2729 | __ sdc1(f0, FieldMemOperand(v0, HeapNumber::kValueOffset)); |
| 2730 | __ Ret(); |
| 2731 | } else { |
| 2732 | // Tail call that writes the int32 in a2 to the heap number in v0, using |
| 2733 | // a3 and a0 as scratch. v0 is preserved and returned. |
| 2734 | WriteInt32ToHeapNumberStub stub(a2, v0, a3, a0); |
| 2735 | __ TailCallStub(&stub); |
| 2736 | } |
| 2737 | break; |
| 2738 | } |
| 2739 | default: |
| 2740 | UNREACHABLE(); |
| 2741 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | |
| 2745 | // Generate the smi code. If the operation on smis are successful this return is |
| 2746 | // generated. If the result is not a smi and heap number allocation is not |
| 2747 | // requested the code falls through. If number allocation is requested but a |
| 2748 | // 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] | 2749 | void BinaryOpStub::GenerateSmiCode( |
| 2750 | MacroAssembler* masm, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2751 | Label* use_runtime, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2752 | Label* gc_required, |
| 2753 | SmiCodeGenerateHeapNumberResults allow_heapnumber_results) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2754 | Label not_smis; |
| 2755 | |
| 2756 | Register left = a1; |
| 2757 | Register right = a0; |
| 2758 | Register scratch1 = t3; |
| 2759 | Register scratch2 = t5; |
| 2760 | |
| 2761 | // Perform combined smi check on both operands. |
| 2762 | __ Or(scratch1, left, Operand(right)); |
| 2763 | STATIC_ASSERT(kSmiTag == 0); |
| 2764 | __ JumpIfNotSmi(scratch1, ¬_smis); |
| 2765 | |
| 2766 | // If the smi-smi operation results in a smi return is generated. |
| 2767 | GenerateSmiSmiOperation(masm); |
| 2768 | |
| 2769 | // If heap number results are possible generate the result in an allocated |
| 2770 | // heap number. |
| 2771 | if (allow_heapnumber_results == ALLOW_HEAPNUMBER_RESULTS) { |
| 2772 | GenerateFPOperation(masm, true, use_runtime, gc_required); |
| 2773 | } |
| 2774 | __ bind(¬_smis); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2775 | } |
| 2776 | |
| 2777 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2778 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2779 | Label not_smis, call_runtime; |
| 2780 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2781 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 2782 | result_type_ == BinaryOpIC::SMI) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2783 | // Only allow smi results. |
| 2784 | GenerateSmiCode(masm, &call_runtime, NULL, NO_HEAPNUMBER_RESULTS); |
| 2785 | } else { |
| 2786 | // Allow heap number result and don't make a transition if a heap number |
| 2787 | // cannot be allocated. |
| 2788 | GenerateSmiCode(masm, |
| 2789 | &call_runtime, |
| 2790 | &call_runtime, |
| 2791 | ALLOW_HEAPNUMBER_RESULTS); |
| 2792 | } |
| 2793 | |
| 2794 | // Code falls through if the result is not returned as either a smi or heap |
| 2795 | // number. |
| 2796 | GenerateTypeTransition(masm); |
| 2797 | |
| 2798 | __ bind(&call_runtime); |
| 2799 | GenerateCallRuntime(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2803 | void BinaryOpStub::GenerateStringStub(MacroAssembler* masm) { |
| 2804 | ASSERT(operands_type_ == BinaryOpIC::STRING); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2805 | // Try to add arguments as strings, otherwise, transition to the generic |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2806 | // BinaryOpIC type. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2807 | GenerateAddStrings(masm); |
| 2808 | GenerateTypeTransition(masm); |
| 2809 | } |
| 2810 | |
| 2811 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2812 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2813 | Label call_runtime; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2814 | ASSERT(operands_type_ == BinaryOpIC::BOTH_STRING); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2815 | ASSERT(op_ == Token::ADD); |
| 2816 | // If both arguments are strings, call the string add stub. |
| 2817 | // Otherwise, do a transition. |
| 2818 | |
| 2819 | // Registers containing left and right operands respectively. |
| 2820 | Register left = a1; |
| 2821 | Register right = a0; |
| 2822 | |
| 2823 | // Test if left operand is a string. |
| 2824 | __ JumpIfSmi(left, &call_runtime); |
| 2825 | __ GetObjectType(left, a2, a2); |
| 2826 | __ Branch(&call_runtime, ge, a2, Operand(FIRST_NONSTRING_TYPE)); |
| 2827 | |
| 2828 | // Test if right operand is a string. |
| 2829 | __ JumpIfSmi(right, &call_runtime); |
| 2830 | __ GetObjectType(right, a2, a2); |
| 2831 | __ Branch(&call_runtime, ge, a2, Operand(FIRST_NONSTRING_TYPE)); |
| 2832 | |
| 2833 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 2834 | GenerateRegisterArgsPush(masm); |
| 2835 | __ TailCallStub(&string_add_stub); |
| 2836 | |
| 2837 | __ bind(&call_runtime); |
| 2838 | GenerateTypeTransition(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2842 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
| 2843 | ASSERT(operands_type_ == BinaryOpIC::INT32); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2844 | |
| 2845 | Register left = a1; |
| 2846 | Register right = a0; |
| 2847 | Register scratch1 = t3; |
| 2848 | Register scratch2 = t5; |
| 2849 | FPURegister double_scratch = f0; |
| 2850 | FPURegister single_scratch = f6; |
| 2851 | |
| 2852 | Register heap_number_result = no_reg; |
| 2853 | Register heap_number_map = t2; |
| 2854 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2855 | |
| 2856 | Label call_runtime; |
| 2857 | // Labels for type transition, used for wrong input or output types. |
| 2858 | // Both label are currently actually bound to the same position. We use two |
| 2859 | // different label to differentiate the cause leading to type transition. |
| 2860 | Label transition; |
| 2861 | |
| 2862 | // Smi-smi fast case. |
| 2863 | Label skip; |
| 2864 | __ Or(scratch1, left, right); |
| 2865 | __ JumpIfNotSmi(scratch1, &skip); |
| 2866 | GenerateSmiSmiOperation(masm); |
| 2867 | // Fall through if the result is not a smi. |
| 2868 | __ bind(&skip); |
| 2869 | |
| 2870 | switch (op_) { |
| 2871 | case Token::ADD: |
| 2872 | case Token::SUB: |
| 2873 | case Token::MUL: |
| 2874 | case Token::DIV: |
| 2875 | case Token::MOD: { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2876 | // Load both operands and check that they are 32-bit integer. |
| 2877 | // Jump to type transition if they are not. The registers a0 and a1 (right |
| 2878 | // and left) are preserved for the runtime call. |
| 2879 | FloatingPointHelper::Destination destination = |
| 2880 | (CpuFeatures::IsSupported(FPU) && op_ != Token::MOD) |
| 2881 | ? FloatingPointHelper::kFPURegisters |
| 2882 | : FloatingPointHelper::kCoreRegisters; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2883 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2884 | FloatingPointHelper::LoadNumberAsInt32Double(masm, |
| 2885 | right, |
| 2886 | destination, |
| 2887 | f14, |
| 2888 | a2, |
| 2889 | a3, |
| 2890 | heap_number_map, |
| 2891 | scratch1, |
| 2892 | scratch2, |
| 2893 | f2, |
| 2894 | &transition); |
| 2895 | FloatingPointHelper::LoadNumberAsInt32Double(masm, |
| 2896 | left, |
| 2897 | destination, |
| 2898 | f12, |
| 2899 | t0, |
| 2900 | t1, |
| 2901 | heap_number_map, |
| 2902 | scratch1, |
| 2903 | scratch2, |
| 2904 | f2, |
| 2905 | &transition); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2906 | |
| 2907 | if (destination == FloatingPointHelper::kFPURegisters) { |
| 2908 | CpuFeatures::Scope scope(FPU); |
| 2909 | Label return_heap_number; |
| 2910 | switch (op_) { |
| 2911 | case Token::ADD: |
| 2912 | __ add_d(f10, f12, f14); |
| 2913 | break; |
| 2914 | case Token::SUB: |
| 2915 | __ sub_d(f10, f12, f14); |
| 2916 | break; |
| 2917 | case Token::MUL: |
| 2918 | __ mul_d(f10, f12, f14); |
| 2919 | break; |
| 2920 | case Token::DIV: |
| 2921 | __ div_d(f10, f12, f14); |
| 2922 | break; |
| 2923 | default: |
| 2924 | UNREACHABLE(); |
| 2925 | } |
| 2926 | |
| 2927 | if (op_ != Token::DIV) { |
| 2928 | // These operations produce an integer result. |
| 2929 | // Try to return a smi if we can. |
| 2930 | // Otherwise return a heap number if allowed, or jump to type |
| 2931 | // transition. |
| 2932 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2933 | Register except_flag = scratch2; |
| 2934 | __ EmitFPUTruncate(kRoundToZero, |
| 2935 | single_scratch, |
| 2936 | f10, |
| 2937 | scratch1, |
| 2938 | except_flag); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2939 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2940 | if (result_type_ <= BinaryOpIC::INT32) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2941 | // If except_flag != 0, result does not fit in a 32-bit integer. |
| 2942 | __ Branch(&transition, ne, except_flag, Operand(zero_reg)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | // Check if the result fits in a smi. |
| 2946 | __ mfc1(scratch1, single_scratch); |
| 2947 | __ Addu(scratch2, scratch1, Operand(0x40000000)); |
| 2948 | // If not try to return a heap number. |
| 2949 | __ Branch(&return_heap_number, lt, scratch2, Operand(zero_reg)); |
| 2950 | // Check for minus zero. Return heap number for minus zero. |
| 2951 | Label not_zero; |
| 2952 | __ Branch(¬_zero, ne, scratch1, Operand(zero_reg)); |
| 2953 | __ mfc1(scratch2, f11); |
| 2954 | __ And(scratch2, scratch2, HeapNumber::kSignMask); |
| 2955 | __ Branch(&return_heap_number, ne, scratch2, Operand(zero_reg)); |
| 2956 | __ bind(¬_zero); |
| 2957 | |
| 2958 | // Tag the result and return. |
| 2959 | __ SmiTag(v0, scratch1); |
| 2960 | __ Ret(); |
| 2961 | } else { |
| 2962 | // DIV just falls through to allocating a heap number. |
| 2963 | } |
| 2964 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 2965 | __ bind(&return_heap_number); |
| 2966 | // Return a heap number, or fall through to type transition or runtime |
| 2967 | // call if we can't. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2968 | if (result_type_ >= ((op_ == Token::DIV) ? BinaryOpIC::HEAP_NUMBER |
| 2969 | : BinaryOpIC::INT32)) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2970 | // We are using FPU registers so s0 is available. |
| 2971 | heap_number_result = s0; |
| 2972 | GenerateHeapResultAllocation(masm, |
| 2973 | heap_number_result, |
| 2974 | heap_number_map, |
| 2975 | scratch1, |
| 2976 | scratch2, |
| 2977 | &call_runtime); |
| 2978 | __ mov(v0, heap_number_result); |
| 2979 | __ sdc1(f10, FieldMemOperand(v0, HeapNumber::kValueOffset)); |
| 2980 | __ Ret(); |
| 2981 | } |
| 2982 | |
| 2983 | // A DIV operation expecting an integer result falls through |
| 2984 | // to type transition. |
| 2985 | |
| 2986 | } else { |
| 2987 | // We preserved a0 and a1 to be able to call runtime. |
| 2988 | // Save the left value on the stack. |
| 2989 | __ Push(t1, t0); |
| 2990 | |
| 2991 | Label pop_and_call_runtime; |
| 2992 | |
| 2993 | // Allocate a heap number to store the result. |
| 2994 | heap_number_result = s0; |
| 2995 | GenerateHeapResultAllocation(masm, |
| 2996 | heap_number_result, |
| 2997 | heap_number_map, |
| 2998 | scratch1, |
| 2999 | scratch2, |
| 3000 | &pop_and_call_runtime); |
| 3001 | |
| 3002 | // Load the left value from the value saved on the stack. |
| 3003 | __ Pop(a1, a0); |
| 3004 | |
| 3005 | // Call the C function to handle the double operation. |
| 3006 | FloatingPointHelper::CallCCodeForDoubleOperation( |
| 3007 | masm, op_, heap_number_result, scratch1); |
| 3008 | if (FLAG_debug_code) { |
| 3009 | __ stop("Unreachable code."); |
| 3010 | } |
| 3011 | |
| 3012 | __ bind(&pop_and_call_runtime); |
| 3013 | __ Drop(2); |
| 3014 | __ Branch(&call_runtime); |
| 3015 | } |
| 3016 | |
| 3017 | break; |
| 3018 | } |
| 3019 | |
| 3020 | case Token::BIT_OR: |
| 3021 | case Token::BIT_XOR: |
| 3022 | case Token::BIT_AND: |
| 3023 | case Token::SAR: |
| 3024 | case Token::SHR: |
| 3025 | case Token::SHL: { |
| 3026 | Label return_heap_number; |
| 3027 | Register scratch3 = t1; |
| 3028 | // Convert operands to 32-bit integers. Right in a2 and left in a3. The |
| 3029 | // registers a0 and a1 (right and left) are preserved for the runtime |
| 3030 | // call. |
| 3031 | FloatingPointHelper::LoadNumberAsInt32(masm, |
| 3032 | left, |
| 3033 | a3, |
| 3034 | heap_number_map, |
| 3035 | scratch1, |
| 3036 | scratch2, |
| 3037 | scratch3, |
| 3038 | f0, |
| 3039 | &transition); |
| 3040 | FloatingPointHelper::LoadNumberAsInt32(masm, |
| 3041 | right, |
| 3042 | a2, |
| 3043 | heap_number_map, |
| 3044 | scratch1, |
| 3045 | scratch2, |
| 3046 | scratch3, |
| 3047 | f0, |
| 3048 | &transition); |
| 3049 | |
| 3050 | // The ECMA-262 standard specifies that, for shift operations, only the |
| 3051 | // 5 least significant bits of the shift value should be used. |
| 3052 | switch (op_) { |
| 3053 | case Token::BIT_OR: |
| 3054 | __ Or(a2, a3, Operand(a2)); |
| 3055 | break; |
| 3056 | case Token::BIT_XOR: |
| 3057 | __ Xor(a2, a3, Operand(a2)); |
| 3058 | break; |
| 3059 | case Token::BIT_AND: |
| 3060 | __ And(a2, a3, Operand(a2)); |
| 3061 | break; |
| 3062 | case Token::SAR: |
| 3063 | __ And(a2, a2, Operand(0x1f)); |
| 3064 | __ srav(a2, a3, a2); |
| 3065 | break; |
| 3066 | case Token::SHR: |
| 3067 | __ And(a2, a2, Operand(0x1f)); |
| 3068 | __ srlv(a2, a3, a2); |
| 3069 | // SHR is special because it is required to produce a positive answer. |
| 3070 | // We only get a negative result if the shift value (a2) is 0. |
| 3071 | // This result cannot be respresented as a signed 32-bit integer, try |
| 3072 | // to return a heap number if we can. |
| 3073 | // The non FPU code does not support this special case, so jump to |
| 3074 | // runtime if we don't support it. |
| 3075 | if (CpuFeatures::IsSupported(FPU)) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3076 | __ Branch((result_type_ <= BinaryOpIC::INT32) |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3077 | ? &transition |
| 3078 | : &return_heap_number, |
| 3079 | lt, |
| 3080 | a2, |
| 3081 | Operand(zero_reg)); |
| 3082 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3083 | __ Branch((result_type_ <= BinaryOpIC::INT32) |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3084 | ? &transition |
| 3085 | : &call_runtime, |
| 3086 | lt, |
| 3087 | a2, |
| 3088 | Operand(zero_reg)); |
| 3089 | } |
| 3090 | break; |
| 3091 | case Token::SHL: |
| 3092 | __ And(a2, a2, Operand(0x1f)); |
| 3093 | __ sllv(a2, a3, a2); |
| 3094 | break; |
| 3095 | default: |
| 3096 | UNREACHABLE(); |
| 3097 | } |
| 3098 | |
| 3099 | // Check if the result fits in a smi. |
| 3100 | __ Addu(scratch1, a2, Operand(0x40000000)); |
| 3101 | // If not try to return a heap number. (We know the result is an int32.) |
| 3102 | __ Branch(&return_heap_number, lt, scratch1, Operand(zero_reg)); |
| 3103 | // Tag the result and return. |
| 3104 | __ SmiTag(v0, a2); |
| 3105 | __ Ret(); |
| 3106 | |
| 3107 | __ bind(&return_heap_number); |
| 3108 | heap_number_result = t1; |
| 3109 | GenerateHeapResultAllocation(masm, |
| 3110 | heap_number_result, |
| 3111 | heap_number_map, |
| 3112 | scratch1, |
| 3113 | scratch2, |
| 3114 | &call_runtime); |
| 3115 | |
| 3116 | if (CpuFeatures::IsSupported(FPU)) { |
| 3117 | CpuFeatures::Scope scope(FPU); |
| 3118 | |
| 3119 | if (op_ != Token::SHR) { |
| 3120 | // Convert the result to a floating point value. |
| 3121 | __ mtc1(a2, double_scratch); |
| 3122 | __ cvt_d_w(double_scratch, double_scratch); |
| 3123 | } else { |
| 3124 | // The result must be interpreted as an unsigned 32-bit integer. |
| 3125 | __ mtc1(a2, double_scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3126 | __ Cvt_d_uw(double_scratch, double_scratch, single_scratch); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3127 | } |
| 3128 | |
| 3129 | // Store the result. |
| 3130 | __ mov(v0, heap_number_result); |
| 3131 | __ sdc1(double_scratch, FieldMemOperand(v0, HeapNumber::kValueOffset)); |
| 3132 | __ Ret(); |
| 3133 | } else { |
| 3134 | // Tail call that writes the int32 in a2 to the heap number in v0, using |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3135 | // a3 and a0 as scratch. v0 is preserved and returned. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3136 | __ mov(a0, t1); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3137 | WriteInt32ToHeapNumberStub stub(a2, v0, a3, a0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3138 | __ TailCallStub(&stub); |
| 3139 | } |
| 3140 | |
| 3141 | break; |
| 3142 | } |
| 3143 | |
| 3144 | default: |
| 3145 | UNREACHABLE(); |
| 3146 | } |
| 3147 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 3148 | // We never expect DIV to yield an integer result, so we always generate |
| 3149 | // type transition code for DIV operations expecting an integer result: the |
| 3150 | // code will fall through to this type transition. |
| 3151 | if (transition.is_linked() || |
| 3152 | ((op_ == Token::DIV) && (result_type_ <= BinaryOpIC::INT32))) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3153 | __ bind(&transition); |
| 3154 | GenerateTypeTransition(masm); |
| 3155 | } |
| 3156 | |
| 3157 | __ bind(&call_runtime); |
| 3158 | GenerateCallRuntime(masm); |
| 3159 | } |
| 3160 | |
| 3161 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3162 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3163 | Label call_runtime; |
| 3164 | |
| 3165 | if (op_ == Token::ADD) { |
| 3166 | // Handle string addition here, because it is the only operation |
| 3167 | // that does not do a ToNumber conversion on the operands. |
| 3168 | GenerateAddStrings(masm); |
| 3169 | } |
| 3170 | |
| 3171 | // Convert oddball arguments to numbers. |
| 3172 | Label check, done; |
| 3173 | __ LoadRoot(t0, Heap::kUndefinedValueRootIndex); |
| 3174 | __ Branch(&check, ne, a1, Operand(t0)); |
| 3175 | if (Token::IsBitOp(op_)) { |
| 3176 | __ li(a1, Operand(Smi::FromInt(0))); |
| 3177 | } else { |
| 3178 | __ LoadRoot(a1, Heap::kNanValueRootIndex); |
| 3179 | } |
| 3180 | __ jmp(&done); |
| 3181 | __ bind(&check); |
| 3182 | __ LoadRoot(t0, Heap::kUndefinedValueRootIndex); |
| 3183 | __ Branch(&done, ne, a0, Operand(t0)); |
| 3184 | if (Token::IsBitOp(op_)) { |
| 3185 | __ li(a0, Operand(Smi::FromInt(0))); |
| 3186 | } else { |
| 3187 | __ LoadRoot(a0, Heap::kNanValueRootIndex); |
| 3188 | } |
| 3189 | __ bind(&done); |
| 3190 | |
| 3191 | GenerateHeapNumberStub(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3195 | void BinaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3196 | Label call_runtime; |
| 3197 | GenerateFPOperation(masm, false, &call_runtime, &call_runtime); |
| 3198 | |
| 3199 | __ bind(&call_runtime); |
| 3200 | GenerateCallRuntime(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3204 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3205 | Label call_runtime, call_string_add_or_runtime; |
| 3206 | |
| 3207 | GenerateSmiCode(masm, &call_runtime, &call_runtime, ALLOW_HEAPNUMBER_RESULTS); |
| 3208 | |
| 3209 | GenerateFPOperation(masm, false, &call_string_add_or_runtime, &call_runtime); |
| 3210 | |
| 3211 | __ bind(&call_string_add_or_runtime); |
| 3212 | if (op_ == Token::ADD) { |
| 3213 | GenerateAddStrings(masm); |
| 3214 | } |
| 3215 | |
| 3216 | __ bind(&call_runtime); |
| 3217 | GenerateCallRuntime(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3221 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3222 | ASSERT(op_ == Token::ADD); |
| 3223 | Label left_not_string, call_runtime; |
| 3224 | |
| 3225 | Register left = a1; |
| 3226 | Register right = a0; |
| 3227 | |
| 3228 | // Check if left argument is a string. |
| 3229 | __ JumpIfSmi(left, &left_not_string); |
| 3230 | __ GetObjectType(left, a2, a2); |
| 3231 | __ Branch(&left_not_string, ge, a2, Operand(FIRST_NONSTRING_TYPE)); |
| 3232 | |
| 3233 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 3234 | GenerateRegisterArgsPush(masm); |
| 3235 | __ TailCallStub(&string_add_left_stub); |
| 3236 | |
| 3237 | // Left operand is not a string, test right. |
| 3238 | __ bind(&left_not_string); |
| 3239 | __ JumpIfSmi(right, &call_runtime); |
| 3240 | __ GetObjectType(right, a2, a2); |
| 3241 | __ Branch(&call_runtime, ge, a2, Operand(FIRST_NONSTRING_TYPE)); |
| 3242 | |
| 3243 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
| 3244 | GenerateRegisterArgsPush(masm); |
| 3245 | __ TailCallStub(&string_add_right_stub); |
| 3246 | |
| 3247 | // At least one argument is not a string. |
| 3248 | __ bind(&call_runtime); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3252 | void BinaryOpStub::GenerateCallRuntime(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3253 | GenerateRegisterArgsPush(masm); |
| 3254 | switch (op_) { |
| 3255 | case Token::ADD: |
| 3256 | __ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION); |
| 3257 | break; |
| 3258 | case Token::SUB: |
| 3259 | __ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION); |
| 3260 | break; |
| 3261 | case Token::MUL: |
| 3262 | __ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION); |
| 3263 | break; |
| 3264 | case Token::DIV: |
| 3265 | __ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION); |
| 3266 | break; |
| 3267 | case Token::MOD: |
| 3268 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 3269 | break; |
| 3270 | case Token::BIT_OR: |
| 3271 | __ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION); |
| 3272 | break; |
| 3273 | case Token::BIT_AND: |
| 3274 | __ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION); |
| 3275 | break; |
| 3276 | case Token::BIT_XOR: |
| 3277 | __ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION); |
| 3278 | break; |
| 3279 | case Token::SAR: |
| 3280 | __ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION); |
| 3281 | break; |
| 3282 | case Token::SHR: |
| 3283 | __ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION); |
| 3284 | break; |
| 3285 | case Token::SHL: |
| 3286 | __ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION); |
| 3287 | break; |
| 3288 | default: |
| 3289 | UNREACHABLE(); |
| 3290 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3291 | } |
| 3292 | |
| 3293 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3294 | void BinaryOpStub::GenerateHeapResultAllocation( |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3295 | MacroAssembler* masm, |
| 3296 | Register result, |
| 3297 | Register heap_number_map, |
| 3298 | Register scratch1, |
| 3299 | Register scratch2, |
| 3300 | Label* gc_required) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3301 | |
| 3302 | // Code below will scratch result if allocation fails. To keep both arguments |
| 3303 | // intact for the runtime call result cannot be one of these. |
| 3304 | ASSERT(!result.is(a0) && !result.is(a1)); |
| 3305 | |
| 3306 | if (mode_ == OVERWRITE_LEFT || mode_ == OVERWRITE_RIGHT) { |
| 3307 | Label skip_allocation, allocated; |
| 3308 | Register overwritable_operand = mode_ == OVERWRITE_LEFT ? a1 : a0; |
| 3309 | // If the overwritable operand is already an object, we skip the |
| 3310 | // allocation of a heap number. |
| 3311 | __ JumpIfNotSmi(overwritable_operand, &skip_allocation); |
| 3312 | // Allocate a heap number for the result. |
| 3313 | __ AllocateHeapNumber( |
| 3314 | result, scratch1, scratch2, heap_number_map, gc_required); |
| 3315 | __ Branch(&allocated); |
| 3316 | __ bind(&skip_allocation); |
| 3317 | // Use object holding the overwritable operand for result. |
| 3318 | __ mov(result, overwritable_operand); |
| 3319 | __ bind(&allocated); |
| 3320 | } else { |
| 3321 | ASSERT(mode_ == NO_OVERWRITE); |
| 3322 | __ AllocateHeapNumber( |
| 3323 | result, scratch1, scratch2, heap_number_map, gc_required); |
| 3324 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3328 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3329 | __ Push(a1, a0); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3330 | } |
| 3331 | |
| 3332 | |
| 3333 | |
| 3334 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3335 | // Untagged case: double input in f4, double result goes |
| 3336 | // into f4. |
| 3337 | // Tagged case: tagged input on top of stack and in a0, |
| 3338 | // tagged result (heap number) goes into v0. |
| 3339 | |
| 3340 | Label input_not_smi; |
| 3341 | Label loaded; |
| 3342 | Label calculate; |
| 3343 | Label invalid_cache; |
| 3344 | const Register scratch0 = t5; |
| 3345 | const Register scratch1 = t3; |
| 3346 | const Register cache_entry = a0; |
| 3347 | const bool tagged = (argument_type_ == TAGGED); |
| 3348 | |
| 3349 | if (CpuFeatures::IsSupported(FPU)) { |
| 3350 | CpuFeatures::Scope scope(FPU); |
| 3351 | |
| 3352 | if (tagged) { |
| 3353 | // Argument is a number and is on stack and in a0. |
| 3354 | // Load argument and check if it is a smi. |
| 3355 | __ JumpIfNotSmi(a0, &input_not_smi); |
| 3356 | |
| 3357 | // Input is a smi. Convert to double and load the low and high words |
| 3358 | // of the double into a2, a3. |
| 3359 | __ sra(t0, a0, kSmiTagSize); |
| 3360 | __ mtc1(t0, f4); |
| 3361 | __ cvt_d_w(f4, f4); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3362 | __ Move(a2, a3, f4); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3363 | __ Branch(&loaded); |
| 3364 | |
| 3365 | __ bind(&input_not_smi); |
| 3366 | // Check if input is a HeapNumber. |
| 3367 | __ CheckMap(a0, |
| 3368 | a1, |
| 3369 | Heap::kHeapNumberMapRootIndex, |
| 3370 | &calculate, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3371 | DONT_DO_SMI_CHECK); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3372 | // Input is a HeapNumber. Store the |
| 3373 | // low and high words into a2, a3. |
| 3374 | __ lw(a2, FieldMemOperand(a0, HeapNumber::kValueOffset)); |
| 3375 | __ lw(a3, FieldMemOperand(a0, HeapNumber::kValueOffset + 4)); |
| 3376 | } else { |
| 3377 | // Input is untagged double in f4. Output goes to f4. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3378 | __ Move(a2, a3, f4); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3379 | } |
| 3380 | __ bind(&loaded); |
| 3381 | // a2 = low 32 bits of double value. |
| 3382 | // a3 = high 32 bits of double value. |
| 3383 | // Compute hash (the shifts are arithmetic): |
| 3384 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 3385 | __ Xor(a1, a2, a3); |
| 3386 | __ sra(t0, a1, 16); |
| 3387 | __ Xor(a1, a1, t0); |
| 3388 | __ sra(t0, a1, 8); |
| 3389 | __ Xor(a1, a1, t0); |
| 3390 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
| 3391 | __ And(a1, a1, Operand(TranscendentalCache::SubCache::kCacheSize - 1)); |
| 3392 | |
| 3393 | // a2 = low 32 bits of double value. |
| 3394 | // a3 = high 32 bits of double value. |
| 3395 | // a1 = TranscendentalCache::hash(double value). |
| 3396 | __ li(cache_entry, Operand( |
| 3397 | ExternalReference::transcendental_cache_array_address( |
| 3398 | masm->isolate()))); |
| 3399 | // a0 points to cache array. |
| 3400 | __ lw(cache_entry, MemOperand(cache_entry, type_ * sizeof( |
| 3401 | Isolate::Current()->transcendental_cache()->caches_[0]))); |
| 3402 | // a0 points to the cache for the type type_. |
| 3403 | // If NULL, the cache hasn't been initialized yet, so go through runtime. |
| 3404 | __ Branch(&invalid_cache, eq, cache_entry, Operand(zero_reg)); |
| 3405 | |
| 3406 | #ifdef DEBUG |
| 3407 | // Check that the layout of cache elements match expectations. |
| 3408 | { TranscendentalCache::SubCache::Element test_elem[2]; |
| 3409 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 3410 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 3411 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 3412 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 3413 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 3414 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 3415 | CHECK_EQ(0, elem_in0 - elem_start); |
| 3416 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 3417 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 3418 | } |
| 3419 | #endif |
| 3420 | |
| 3421 | // Find the address of the a1'st entry in the cache, i.e., &a0[a1*12]. |
| 3422 | __ sll(t0, a1, 1); |
| 3423 | __ Addu(a1, a1, t0); |
| 3424 | __ sll(t0, a1, 2); |
| 3425 | __ Addu(cache_entry, cache_entry, t0); |
| 3426 | |
| 3427 | // Check if cache matches: Double value is stored in uint32_t[2] array. |
| 3428 | __ lw(t0, MemOperand(cache_entry, 0)); |
| 3429 | __ lw(t1, MemOperand(cache_entry, 4)); |
| 3430 | __ lw(t2, MemOperand(cache_entry, 8)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3431 | __ Branch(&calculate, ne, a2, Operand(t0)); |
| 3432 | __ Branch(&calculate, ne, a3, Operand(t1)); |
| 3433 | // Cache hit. Load result, cleanup and return. |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 3434 | Counters* counters = masm->isolate()->counters(); |
| 3435 | __ IncrementCounter( |
| 3436 | counters->transcendental_cache_hit(), 1, scratch0, scratch1); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3437 | if (tagged) { |
| 3438 | // Pop input value from stack and load result into v0. |
| 3439 | __ Drop(1); |
| 3440 | __ mov(v0, t2); |
| 3441 | } else { |
| 3442 | // Load result into f4. |
| 3443 | __ ldc1(f4, FieldMemOperand(t2, HeapNumber::kValueOffset)); |
| 3444 | } |
| 3445 | __ Ret(); |
| 3446 | } // if (CpuFeatures::IsSupported(FPU)) |
| 3447 | |
| 3448 | __ bind(&calculate); |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 3449 | Counters* counters = masm->isolate()->counters(); |
| 3450 | __ IncrementCounter( |
| 3451 | counters->transcendental_cache_miss(), 1, scratch0, scratch1); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3452 | if (tagged) { |
| 3453 | __ bind(&invalid_cache); |
| 3454 | __ TailCallExternalReference(ExternalReference(RuntimeFunction(), |
| 3455 | masm->isolate()), |
| 3456 | 1, |
| 3457 | 1); |
| 3458 | } else { |
| 3459 | if (!CpuFeatures::IsSupported(FPU)) UNREACHABLE(); |
| 3460 | CpuFeatures::Scope scope(FPU); |
| 3461 | |
| 3462 | Label no_update; |
| 3463 | Label skip_cache; |
| 3464 | const Register heap_number_map = t2; |
| 3465 | |
| 3466 | // Call C function to calculate the result and update the cache. |
| 3467 | // Register a0 holds precalculated cache entry address; preserve |
| 3468 | // it on the stack and pop it into register cache_entry after the |
| 3469 | // call. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3470 | __ Push(cache_entry, a2, a3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3471 | GenerateCallCFunction(masm, scratch0); |
| 3472 | __ GetCFunctionDoubleResult(f4); |
| 3473 | |
| 3474 | // Try to update the cache. If we cannot allocate a |
| 3475 | // heap number, we return the result without updating. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3476 | __ Pop(cache_entry, a2, a3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3477 | __ LoadRoot(t1, Heap::kHeapNumberMapRootIndex); |
| 3478 | __ AllocateHeapNumber(t2, scratch0, scratch1, t1, &no_update); |
| 3479 | __ sdc1(f4, FieldMemOperand(t2, HeapNumber::kValueOffset)); |
| 3480 | |
| 3481 | __ sw(a2, MemOperand(cache_entry, 0 * kPointerSize)); |
| 3482 | __ sw(a3, MemOperand(cache_entry, 1 * kPointerSize)); |
| 3483 | __ sw(t2, MemOperand(cache_entry, 2 * kPointerSize)); |
| 3484 | |
| 3485 | __ mov(v0, cache_entry); |
| 3486 | __ Ret(); |
| 3487 | |
| 3488 | __ bind(&invalid_cache); |
| 3489 | // The cache is invalid. Call runtime which will recreate the |
| 3490 | // cache. |
| 3491 | __ LoadRoot(t1, Heap::kHeapNumberMapRootIndex); |
| 3492 | __ AllocateHeapNumber(a0, scratch0, scratch1, t1, &skip_cache); |
| 3493 | __ sdc1(f4, FieldMemOperand(a0, HeapNumber::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3494 | { |
| 3495 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3496 | __ push(a0); |
| 3497 | __ CallRuntime(RuntimeFunction(), 1); |
| 3498 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3499 | __ ldc1(f4, FieldMemOperand(v0, HeapNumber::kValueOffset)); |
| 3500 | __ Ret(); |
| 3501 | |
| 3502 | __ bind(&skip_cache); |
| 3503 | // Call C function to calculate the result and answer directly |
| 3504 | // without updating the cache. |
| 3505 | GenerateCallCFunction(masm, scratch0); |
| 3506 | __ GetCFunctionDoubleResult(f4); |
| 3507 | __ bind(&no_update); |
| 3508 | |
| 3509 | // We return the value in f4 without adding it to the cache, but |
| 3510 | // 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] | 3511 | { |
| 3512 | FrameScope scope(masm, StackFrame::INTERNAL); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3513 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3514 | // Allocate an aligned object larger than a HeapNumber. |
| 3515 | ASSERT(4 * kPointerSize >= HeapNumber::kSize); |
| 3516 | __ li(scratch0, Operand(4 * kPointerSize)); |
| 3517 | __ push(scratch0); |
| 3518 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 3519 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3520 | __ Ret(); |
| 3521 | } |
| 3522 | } |
| 3523 | |
| 3524 | |
| 3525 | void TranscendentalCacheStub::GenerateCallCFunction(MacroAssembler* masm, |
| 3526 | Register scratch) { |
| 3527 | __ push(ra); |
| 3528 | __ PrepareCallCFunction(2, scratch); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3529 | if (IsMipsSoftFloatABI) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3530 | __ Move(a0, a1, f4); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3531 | } else { |
| 3532 | __ mov_d(f12, f4); |
| 3533 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3534 | AllowExternalCallThatCantCauseGC scope(masm); |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 3535 | Isolate* isolate = masm->isolate(); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3536 | switch (type_) { |
| 3537 | case TranscendentalCache::SIN: |
| 3538 | __ CallCFunction( |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 3539 | ExternalReference::math_sin_double_function(isolate), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3540 | 0, 1); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3541 | break; |
| 3542 | case TranscendentalCache::COS: |
| 3543 | __ CallCFunction( |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 3544 | ExternalReference::math_cos_double_function(isolate), |
| 3545 | 0, 1); |
| 3546 | break; |
| 3547 | case TranscendentalCache::TAN: |
| 3548 | __ CallCFunction(ExternalReference::math_tan_double_function(isolate), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3549 | 0, 1); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3550 | break; |
| 3551 | case TranscendentalCache::LOG: |
| 3552 | __ CallCFunction( |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 3553 | ExternalReference::math_log_double_function(isolate), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3554 | 0, 1); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3555 | break; |
| 3556 | default: |
| 3557 | UNIMPLEMENTED(); |
| 3558 | break; |
| 3559 | } |
| 3560 | __ pop(ra); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3561 | } |
| 3562 | |
| 3563 | |
| 3564 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3565 | switch (type_) { |
| 3566 | // Add more cases when necessary. |
| 3567 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 3568 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 3569 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3570 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
| 3571 | default: |
| 3572 | UNIMPLEMENTED(); |
| 3573 | return Runtime::kAbort; |
| 3574 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | |
| 3578 | void StackCheckStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3579 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3580 | } |
| 3581 | |
| 3582 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3583 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 3584 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 3585 | } |
| 3586 | |
| 3587 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3588 | void MathPowStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3589 | CpuFeatures::Scope fpu_scope(FPU); |
| 3590 | const Register base = a1; |
| 3591 | const Register exponent = a2; |
| 3592 | const Register heapnumbermap = t1; |
| 3593 | const Register heapnumber = v0; |
| 3594 | const DoubleRegister double_base = f2; |
| 3595 | const DoubleRegister double_exponent = f4; |
| 3596 | const DoubleRegister double_result = f0; |
| 3597 | const DoubleRegister double_scratch = f6; |
| 3598 | const FPURegister single_scratch = f8; |
| 3599 | const Register scratch = t5; |
| 3600 | const Register scratch2 = t3; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3601 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3602 | Label call_runtime, done, int_exponent; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3603 | if (exponent_type_ == ON_STACK) { |
| 3604 | Label base_is_smi, unpack_exponent; |
| 3605 | // The exponent and base are supplied as arguments on the stack. |
| 3606 | // This can only happen if the stub is called from non-optimized code. |
| 3607 | // Load input parameters from stack to double registers. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3608 | __ lw(base, MemOperand(sp, 1 * kPointerSize)); |
| 3609 | __ lw(exponent, MemOperand(sp, 0 * kPointerSize)); |
| 3610 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3611 | __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3612 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3613 | __ UntagAndJumpIfSmi(scratch, base, &base_is_smi); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3614 | __ lw(scratch, FieldMemOperand(base, JSObject::kMapOffset)); |
| 3615 | __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3616 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3617 | __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset)); |
| 3618 | __ jmp(&unpack_exponent); |
| 3619 | |
| 3620 | __ bind(&base_is_smi); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3621 | __ mtc1(scratch, single_scratch); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3622 | __ cvt_d_w(double_base, single_scratch); |
| 3623 | __ bind(&unpack_exponent); |
| 3624 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3625 | __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3626 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3627 | __ lw(scratch, FieldMemOperand(exponent, JSObject::kMapOffset)); |
| 3628 | __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3629 | __ ldc1(double_exponent, |
| 3630 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3631 | } else if (exponent_type_ == TAGGED) { |
| 3632 | // Base is already in double_base. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3633 | __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3634 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3635 | __ ldc1(double_exponent, |
| 3636 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3637 | } |
| 3638 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3639 | if (exponent_type_ != INTEGER) { |
| 3640 | Label int_exponent_convert; |
| 3641 | // Detect integer exponents stored as double. |
| 3642 | __ EmitFPUTruncate(kRoundToMinusInf, |
| 3643 | single_scratch, |
| 3644 | double_exponent, |
| 3645 | scratch, |
| 3646 | scratch2, |
| 3647 | kCheckForInexactConversion); |
| 3648 | // scratch2 == 0 means there was no conversion error. |
| 3649 | __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg)); |
| 3650 | |
| 3651 | if (exponent_type_ == ON_STACK) { |
| 3652 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 3653 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 3654 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 3655 | Label not_plus_half; |
| 3656 | |
| 3657 | // Test for 0.5. |
| 3658 | __ Move(double_scratch, 0.5); |
| 3659 | __ BranchF(USE_DELAY_SLOT, |
| 3660 | ¬_plus_half, |
| 3661 | NULL, |
| 3662 | ne, |
| 3663 | double_exponent, |
| 3664 | double_scratch); |
| 3665 | |
| 3666 | // Calculates square root of base. Check for the special case of |
| 3667 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 3668 | __ Move(double_scratch, -V8_INFINITY); |
| 3669 | __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch); |
| 3670 | __ neg_d(double_result, double_scratch); |
| 3671 | |
| 3672 | // Add +0 to convert -0 to +0. |
| 3673 | __ add_d(double_scratch, double_base, kDoubleRegZero); |
| 3674 | __ sqrt_d(double_result, double_scratch); |
| 3675 | __ jmp(&done); |
| 3676 | |
| 3677 | __ bind(¬_plus_half); |
| 3678 | __ Move(double_scratch, -0.5); |
| 3679 | __ BranchF(USE_DELAY_SLOT, |
| 3680 | &call_runtime, |
| 3681 | NULL, |
| 3682 | ne, |
| 3683 | double_exponent, |
| 3684 | double_scratch); |
| 3685 | |
| 3686 | // Calculates square root of base. Check for the special case of |
| 3687 | // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 3688 | __ Move(double_scratch, -V8_INFINITY); |
| 3689 | __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch); |
| 3690 | __ Move(double_result, kDoubleRegZero); |
| 3691 | |
| 3692 | // Add +0 to convert -0 to +0. |
| 3693 | __ add_d(double_scratch, double_base, kDoubleRegZero); |
| 3694 | __ Move(double_result, 1); |
| 3695 | __ sqrt_d(double_scratch, double_scratch); |
| 3696 | __ div_d(double_result, double_result, double_scratch); |
| 3697 | __ jmp(&done); |
| 3698 | } |
| 3699 | |
| 3700 | __ push(ra); |
| 3701 | { |
| 3702 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3703 | __ PrepareCallCFunction(0, 2, scratch); |
| 3704 | __ SetCallCDoubleArguments(double_base, double_exponent); |
| 3705 | __ CallCFunction( |
| 3706 | ExternalReference::power_double_double_function(masm->isolate()), |
| 3707 | 0, 2); |
| 3708 | } |
| 3709 | __ pop(ra); |
| 3710 | __ GetCFunctionDoubleResult(double_result); |
| 3711 | __ jmp(&done); |
| 3712 | |
| 3713 | __ bind(&int_exponent_convert); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3714 | __ mfc1(scratch, single_scratch); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3715 | } |
| 3716 | |
| 3717 | // Calculate power with integer exponent. |
| 3718 | __ bind(&int_exponent); |
| 3719 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3720 | // Get two copies of exponent in the registers scratch and exponent. |
| 3721 | if (exponent_type_ == INTEGER) { |
| 3722 | __ mov(scratch, exponent); |
| 3723 | } else { |
| 3724 | // Exponent has previously been stored into scratch as untagged integer. |
| 3725 | __ mov(exponent, scratch); |
| 3726 | } |
| 3727 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3728 | __ mov_d(double_scratch, double_base); // Back up base. |
| 3729 | __ Move(double_result, 1.0); |
| 3730 | |
| 3731 | // Get absolute value of exponent. |
| 3732 | Label positive_exponent; |
| 3733 | __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg)); |
| 3734 | __ Subu(scratch, zero_reg, scratch); |
| 3735 | __ bind(&positive_exponent); |
| 3736 | |
| 3737 | Label while_true, no_carry, loop_end; |
| 3738 | __ bind(&while_true); |
| 3739 | |
| 3740 | __ And(scratch2, scratch, 1); |
| 3741 | |
| 3742 | __ Branch(&no_carry, eq, scratch2, Operand(zero_reg)); |
| 3743 | __ mul_d(double_result, double_result, double_scratch); |
| 3744 | __ bind(&no_carry); |
| 3745 | |
| 3746 | __ sra(scratch, scratch, 1); |
| 3747 | |
| 3748 | __ Branch(&loop_end, eq, scratch, Operand(zero_reg)); |
| 3749 | __ mul_d(double_scratch, double_scratch, double_scratch); |
| 3750 | |
| 3751 | __ Branch(&while_true); |
| 3752 | |
| 3753 | __ bind(&loop_end); |
| 3754 | |
| 3755 | __ Branch(&done, ge, exponent, Operand(zero_reg)); |
| 3756 | __ Move(double_scratch, 1.0); |
| 3757 | __ div_d(double_result, double_scratch, double_result); |
| 3758 | // Test whether result is zero. Bail out to check for subnormal result. |
| 3759 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 3760 | __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero); |
| 3761 | |
| 3762 | // double_exponent may not contain the exponent value if the input was a |
| 3763 | // smi. We set it with exponent value before bailing out. |
| 3764 | __ mtc1(exponent, single_scratch); |
| 3765 | __ cvt_d_w(double_exponent, single_scratch); |
| 3766 | |
| 3767 | // Returning or bailing out. |
| 3768 | Counters* counters = masm->isolate()->counters(); |
| 3769 | if (exponent_type_ == ON_STACK) { |
| 3770 | // The arguments are still on the stack. |
| 3771 | __ bind(&call_runtime); |
| 3772 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
| 3773 | |
| 3774 | // The stub is called from non-optimized code, which expects the result |
| 3775 | // as heap number in exponent. |
| 3776 | __ bind(&done); |
| 3777 | __ AllocateHeapNumber( |
| 3778 | heapnumber, scratch, scratch2, heapnumbermap, &call_runtime); |
| 3779 | __ sdc1(double_result, |
| 3780 | FieldMemOperand(heapnumber, HeapNumber::kValueOffset)); |
| 3781 | ASSERT(heapnumber.is(v0)); |
| 3782 | __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2); |
| 3783 | __ DropAndRet(2); |
| 3784 | } else { |
| 3785 | __ push(ra); |
| 3786 | { |
| 3787 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3788 | __ PrepareCallCFunction(0, 2, scratch); |
| 3789 | __ SetCallCDoubleArguments(double_base, double_exponent); |
| 3790 | __ CallCFunction( |
| 3791 | ExternalReference::power_double_double_function(masm->isolate()), |
| 3792 | 0, 2); |
| 3793 | } |
| 3794 | __ pop(ra); |
| 3795 | __ GetCFunctionDoubleResult(double_result); |
| 3796 | |
| 3797 | __ bind(&done); |
| 3798 | __ IncrementCounter(counters->math_pow(), 1, scratch, scratch2); |
| 3799 | __ Ret(); |
| 3800 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3804 | bool CEntryStub::NeedsImmovableCode() { |
| 3805 | return true; |
| 3806 | } |
| 3807 | |
| 3808 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3809 | bool CEntryStub::IsPregenerated() { |
| 3810 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 3811 | result_size_ == 1; |
| 3812 | } |
| 3813 | |
| 3814 | |
| 3815 | void CodeStub::GenerateStubsAheadOfTime() { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3816 | CEntryStub::GenerateAheadOfTime(); |
| 3817 | WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime(); |
| 3818 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(); |
| 3819 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3820 | } |
| 3821 | |
| 3822 | |
| 3823 | void CodeStub::GenerateFPStubs() { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3824 | CEntryStub save_doubles(1, kSaveFPRegs); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3825 | Handle<Code> code = save_doubles.GetCode(); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3826 | code->set_is_pregenerated(true); |
| 3827 | StoreBufferOverflowStub stub(kSaveFPRegs); |
| 3828 | stub.GetCode()->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3829 | code->GetIsolate()->set_fp_stubs_generated(true); |
| 3830 | } |
| 3831 | |
| 3832 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3833 | void CEntryStub::GenerateAheadOfTime() { |
| 3834 | CEntryStub stub(1, kDontSaveFPRegs); |
| 3835 | Handle<Code> code = stub.GetCode(); |
| 3836 | code->set_is_pregenerated(true); |
| 3837 | } |
| 3838 | |
| 3839 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3840 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 3841 | Label* throw_normal_exception, |
| 3842 | Label* throw_termination_exception, |
| 3843 | Label* throw_out_of_memory_exception, |
| 3844 | bool do_gc, |
| 3845 | bool always_allocate) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3846 | // v0: result parameter for PerformGC, if any |
| 3847 | // s0: number of arguments including receiver (C callee-saved) |
| 3848 | // s1: pointer to the first argument (C callee-saved) |
| 3849 | // s2: pointer to builtin function (C callee-saved) |
| 3850 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3851 | Isolate* isolate = masm->isolate(); |
| 3852 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3853 | if (do_gc) { |
| 3854 | // Move result passed in v0 into a0 to call PerformGC. |
| 3855 | __ mov(a0, v0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3856 | __ PrepareCallCFunction(1, 0, a1); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3857 | __ CallCFunction(ExternalReference::perform_gc_function(isolate), 1, 0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | ExternalReference scope_depth = |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3861 | ExternalReference::heap_always_allocate_scope_depth(isolate); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3862 | if (always_allocate) { |
| 3863 | __ li(a0, Operand(scope_depth)); |
| 3864 | __ lw(a1, MemOperand(a0)); |
| 3865 | __ Addu(a1, a1, Operand(1)); |
| 3866 | __ sw(a1, MemOperand(a0)); |
| 3867 | } |
| 3868 | |
| 3869 | // Prepare arguments for C routine: a0 = argc, a1 = argv |
| 3870 | __ mov(a0, s0); |
| 3871 | __ mov(a1, s1); |
| 3872 | |
| 3873 | // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We |
| 3874 | // also need to reserve the 4 argument slots on the stack. |
| 3875 | |
| 3876 | __ AssertStackIsAligned(); |
| 3877 | |
| 3878 | __ li(a2, Operand(ExternalReference::isolate_address())); |
| 3879 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 3880 | // To let the GC traverse the return address of the exit frames, we need to |
| 3881 | // know where the return address is. The CEntryStub is unmovable, so |
| 3882 | // we can store the address on the stack to be able to find it again and |
| 3883 | // we never have to restore it, because it will not change. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3884 | { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm); |
| 3885 | // This branch-and-link sequence is needed to find the current PC on mips, |
| 3886 | // saved to the ra register. |
| 3887 | // Use masm-> here instead of the double-underscore macro since extra |
| 3888 | // coverage code can interfere with the proper calculation of ra. |
| 3889 | Label find_ra; |
| 3890 | masm->bal(&find_ra); // bal exposes branch delay slot. |
| 3891 | masm->nop(); // Branch delay slot nop. |
| 3892 | masm->bind(&find_ra); |
| 3893 | |
| 3894 | // Adjust the value in ra to point to the correct return location, 2nd |
| 3895 | // instruction past the real call into C code (the jalr(t9)), and push it. |
| 3896 | // This is the return address of the exit frame. |
| 3897 | const int kNumInstructionsToJump = 6; |
| 3898 | masm->Addu(ra, ra, kNumInstructionsToJump * kPointerSize); |
| 3899 | masm->sw(ra, MemOperand(sp)); // This spot was reserved in EnterExitFrame. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 3900 | masm->Subu(sp, sp, kCArgsSlotsSize); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3901 | // Stack is still aligned. |
| 3902 | |
| 3903 | // Call the C routine. |
| 3904 | masm->mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC. |
| 3905 | masm->jalr(t9); |
| 3906 | masm->nop(); // Branch delay slot nop. |
| 3907 | // Make sure the stored 'ra' points to this position. |
| 3908 | ASSERT_EQ(kNumInstructionsToJump, |
| 3909 | masm->InstructionsGeneratedSince(&find_ra)); |
| 3910 | } |
| 3911 | |
| 3912 | // Restore stack (remove arg slots). |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 3913 | __ Addu(sp, sp, kCArgsSlotsSize); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3914 | |
| 3915 | if (always_allocate) { |
| 3916 | // It's okay to clobber a2 and a3 here. v0 & v1 contain result. |
| 3917 | __ li(a2, Operand(scope_depth)); |
| 3918 | __ lw(a3, MemOperand(a2)); |
| 3919 | __ Subu(a3, a3, Operand(1)); |
| 3920 | __ sw(a3, MemOperand(a2)); |
| 3921 | } |
| 3922 | |
| 3923 | // Check for failure result. |
| 3924 | Label failure_returned; |
| 3925 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 3926 | __ addiu(a2, v0, 1); |
| 3927 | __ andi(t0, a2, kFailureTagMask); |
| 3928 | __ Branch(&failure_returned, eq, t0, Operand(zero_reg)); |
| 3929 | |
| 3930 | // Exit C frame and return. |
| 3931 | // v0:v1: result |
| 3932 | // sp: stack pointer |
| 3933 | // fp: frame pointer |
| 3934 | __ LeaveExitFrame(save_doubles_, s0); |
| 3935 | __ Ret(); |
| 3936 | |
| 3937 | // Check if we should retry or throw exception. |
| 3938 | Label retry; |
| 3939 | __ bind(&failure_returned); |
| 3940 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 3941 | __ andi(t0, v0, ((1 << kFailureTypeTagSize) - 1) << kFailureTagSize); |
| 3942 | __ Branch(&retry, eq, t0, Operand(zero_reg)); |
| 3943 | |
| 3944 | // Special handling of out of memory exceptions. |
| 3945 | Failure* out_of_memory = Failure::OutOfMemoryException(); |
| 3946 | __ Branch(throw_out_of_memory_exception, eq, |
| 3947 | v0, Operand(reinterpret_cast<int32_t>(out_of_memory))); |
| 3948 | |
| 3949 | // Retrieve the pending exception and clear the variable. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3950 | __ li(a3, Operand(isolate->factory()->the_hole_value())); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3951 | __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3952 | isolate))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3953 | __ lw(v0, MemOperand(t0)); |
| 3954 | __ sw(a3, MemOperand(t0)); |
| 3955 | |
| 3956 | // Special handling of termination exceptions which are uncatchable |
| 3957 | // by javascript code. |
| 3958 | __ Branch(throw_termination_exception, eq, |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3959 | v0, Operand(isolate->factory()->termination_exception())); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3960 | |
| 3961 | // Handle normal exception. |
| 3962 | __ jmp(throw_normal_exception); |
| 3963 | |
| 3964 | __ bind(&retry); |
| 3965 | // Last failure (v0) will be moved to (a0) for parameter when retrying. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3966 | } |
| 3967 | |
| 3968 | |
| 3969 | void CEntryStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3970 | // Called from JavaScript; parameters are on stack as if calling JS function |
| 3971 | // a0: number of arguments including receiver |
| 3972 | // a1: pointer to builtin function |
| 3973 | // fp: frame pointer (restored after C call) |
| 3974 | // sp: stack pointer (restored as callee's sp after C call) |
| 3975 | // cp: current context (C callee-saved) |
| 3976 | |
| 3977 | // NOTE: Invocations of builtins may return failure objects |
| 3978 | // instead of a proper result. The builtin entry handles |
| 3979 | // this by performing a garbage collection and retrying the |
| 3980 | // builtin once. |
| 3981 | |
| 3982 | // Compute the argv pointer in a callee-saved register. |
| 3983 | __ sll(s1, a0, kPointerSizeLog2); |
| 3984 | __ Addu(s1, sp, s1); |
| 3985 | __ Subu(s1, s1, Operand(kPointerSize)); |
| 3986 | |
| 3987 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3988 | FrameScope scope(masm, StackFrame::MANUAL); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3989 | __ EnterExitFrame(save_doubles_); |
| 3990 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3991 | // Set up argc and the builtin function in callee-saved registers. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3992 | __ mov(s0, a0); |
| 3993 | __ mov(s2, a1); |
| 3994 | |
| 3995 | // s0: number of arguments (C callee-saved) |
| 3996 | // s1: pointer to first argument (C callee-saved) |
| 3997 | // s2: pointer to builtin function (C callee-saved) |
| 3998 | |
| 3999 | Label throw_normal_exception; |
| 4000 | Label throw_termination_exception; |
| 4001 | Label throw_out_of_memory_exception; |
| 4002 | |
| 4003 | // Call into the runtime system. |
| 4004 | GenerateCore(masm, |
| 4005 | &throw_normal_exception, |
| 4006 | &throw_termination_exception, |
| 4007 | &throw_out_of_memory_exception, |
| 4008 | false, |
| 4009 | false); |
| 4010 | |
| 4011 | // Do space-specific GC and retry runtime call. |
| 4012 | GenerateCore(masm, |
| 4013 | &throw_normal_exception, |
| 4014 | &throw_termination_exception, |
| 4015 | &throw_out_of_memory_exception, |
| 4016 | true, |
| 4017 | false); |
| 4018 | |
| 4019 | // Do full GC and retry runtime call one final time. |
| 4020 | Failure* failure = Failure::InternalError(); |
| 4021 | __ li(v0, Operand(reinterpret_cast<int32_t>(failure))); |
| 4022 | GenerateCore(masm, |
| 4023 | &throw_normal_exception, |
| 4024 | &throw_termination_exception, |
| 4025 | &throw_out_of_memory_exception, |
| 4026 | true, |
| 4027 | true); |
| 4028 | |
| 4029 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4030 | // Set external caught exception to false. |
| 4031 | Isolate* isolate = masm->isolate(); |
| 4032 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 4033 | isolate); |
| 4034 | __ li(a0, Operand(false, RelocInfo::NONE)); |
| 4035 | __ li(a2, Operand(external_caught)); |
| 4036 | __ sw(a0, MemOperand(a2)); |
| 4037 | |
| 4038 | // Set pending exception and v0 to out of memory exception. |
| 4039 | Failure* out_of_memory = Failure::OutOfMemoryException(); |
| 4040 | __ li(v0, Operand(reinterpret_cast<int32_t>(out_of_memory))); |
| 4041 | __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
| 4042 | isolate))); |
| 4043 | __ sw(v0, MemOperand(a2)); |
| 4044 | // Fall through to the next label. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4045 | |
| 4046 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4047 | __ ThrowUncatchable(v0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4048 | |
| 4049 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4050 | __ Throw(v0); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | |
| 4054 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 4055 | Label invoke, handler_entry, exit; |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4056 | Isolate* isolate = masm->isolate(); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4057 | |
| 4058 | // Registers: |
| 4059 | // a0: entry address |
| 4060 | // a1: function |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4061 | // a2: receiver |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4062 | // a3: argc |
| 4063 | // |
| 4064 | // Stack: |
| 4065 | // 4 args slots |
| 4066 | // args |
| 4067 | |
| 4068 | // Save callee saved registers on the stack. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4069 | __ MultiPush(kCalleeSaved | ra.bit()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4070 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4071 | if (CpuFeatures::IsSupported(FPU)) { |
| 4072 | CpuFeatures::Scope scope(FPU); |
| 4073 | // Save callee-saved FPU registers. |
| 4074 | __ MultiPushFPU(kCalleeSavedFPU); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4075 | // Set up the reserved register for 0.0. |
| 4076 | __ Move(kDoubleRegZero, 0.0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4077 | } |
| 4078 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4079 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4080 | // Load argv in s0 register. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4081 | int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize; |
| 4082 | if (CpuFeatures::IsSupported(FPU)) { |
| 4083 | offset_to_argv += kNumCalleeSavedFPU * kDoubleSize; |
| 4084 | } |
| 4085 | |
| 4086 | __ lw(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4087 | |
| 4088 | // We build an EntryFrame. |
| 4089 | __ li(t3, Operand(-1)); // Push a bad frame pointer to fail if it is used. |
| 4090 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 4091 | __ li(t2, Operand(Smi::FromInt(marker))); |
| 4092 | __ li(t1, Operand(Smi::FromInt(marker))); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4093 | __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress, |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4094 | isolate))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4095 | __ lw(t0, MemOperand(t0)); |
| 4096 | __ Push(t3, t2, t1, t0); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4097 | // Set up frame pointer for the frame to be pushed. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4098 | __ addiu(fp, sp, -EntryFrameConstants::kCallerFPOffset); |
| 4099 | |
| 4100 | // Registers: |
| 4101 | // a0: entry_address |
| 4102 | // a1: function |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4103 | // a2: receiver_pointer |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4104 | // a3: argc |
| 4105 | // s0: argv |
| 4106 | // |
| 4107 | // Stack: |
| 4108 | // caller fp | |
| 4109 | // function slot | entry frame |
| 4110 | // context slot | |
| 4111 | // bad fp (0xff...f) | |
| 4112 | // callee saved registers + ra |
| 4113 | // 4 args slots |
| 4114 | // args |
| 4115 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 4116 | // If this is the outermost JS call, set js_entry_sp value. |
| 4117 | Label non_outermost_js; |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4118 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 4119 | __ li(t1, Operand(ExternalReference(js_entry_sp))); |
| 4120 | __ lw(t2, MemOperand(t1)); |
| 4121 | __ Branch(&non_outermost_js, ne, t2, Operand(zero_reg)); |
| 4122 | __ sw(fp, MemOperand(t1)); |
| 4123 | __ li(t0, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 4124 | Label cont; |
| 4125 | __ b(&cont); |
| 4126 | __ nop(); // Branch delay slot nop. |
| 4127 | __ bind(&non_outermost_js); |
| 4128 | __ li(t0, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
| 4129 | __ bind(&cont); |
| 4130 | __ push(t0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4131 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 4132 | // Jump to a faked try block that does the invoke, with a faked catch |
| 4133 | // block that sets the pending exception. |
| 4134 | __ jmp(&invoke); |
| 4135 | __ bind(&handler_entry); |
| 4136 | handler_offset_ = handler_entry.pos(); |
| 4137 | // Caught exception: Store result (exception) in the pending exception |
| 4138 | // field in the JSEnv and return a failure sentinel. Coming in here the |
| 4139 | // fp will be invalid because the PushTryHandler below sets it to 0 to |
| 4140 | // signal the existence of the JSEntry frame. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4141 | __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4142 | isolate))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4143 | __ sw(v0, MemOperand(t0)); // We come back from 'invoke'. result is in v0. |
| 4144 | __ li(v0, Operand(reinterpret_cast<int32_t>(Failure::Exception()))); |
| 4145 | __ b(&exit); // b exposes branch delay slot. |
| 4146 | __ nop(); // Branch delay slot nop. |
| 4147 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 4148 | // Invoke: Link this frame into the handler chain. There's only one |
| 4149 | // handler block in this code object, so its index is 0. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4150 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 4151 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4152 | // If an exception not caught by another handler occurs, this handler |
| 4153 | // returns control to the code after the bal(&invoke) above, which |
| 4154 | // restores all kCalleeSaved registers (including cp and fp) to their |
| 4155 | // saved values before returning a failure to C. |
| 4156 | |
| 4157 | // Clear any pending exceptions. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4158 | __ li(t1, Operand(isolate->factory()->the_hole_value())); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4159 | __ li(t0, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4160 | isolate))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4161 | __ sw(t1, MemOperand(t0)); |
| 4162 | |
| 4163 | // Invoke the function by calling through JS entry trampoline builtin. |
| 4164 | // Notice that we cannot store a reference to the trampoline code directly in |
| 4165 | // this stub, because runtime stubs are not traversed when doing GC. |
| 4166 | |
| 4167 | // Registers: |
| 4168 | // a0: entry_address |
| 4169 | // a1: function |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4170 | // a2: receiver_pointer |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4171 | // a3: argc |
| 4172 | // s0: argv |
| 4173 | // |
| 4174 | // Stack: |
| 4175 | // handler frame |
| 4176 | // entry frame |
| 4177 | // callee saved registers + ra |
| 4178 | // 4 args slots |
| 4179 | // args |
| 4180 | |
| 4181 | if (is_construct) { |
| 4182 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4183 | isolate); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4184 | __ li(t0, Operand(construct_entry)); |
| 4185 | } else { |
| 4186 | ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate()); |
| 4187 | __ li(t0, Operand(entry)); |
| 4188 | } |
| 4189 | __ lw(t9, MemOperand(t0)); // Deref address. |
| 4190 | |
| 4191 | // Call JSEntryTrampoline. |
| 4192 | __ addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag); |
| 4193 | __ Call(t9); |
| 4194 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4195 | // Unlink this frame from the handler chain. |
| 4196 | __ PopTryHandler(); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4197 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4198 | __ bind(&exit); // v0 holds result |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 4199 | // Check if the current stack frame is marked as the outermost JS frame. |
| 4200 | Label non_outermost_js_2; |
| 4201 | __ pop(t1); |
| 4202 | __ Branch(&non_outermost_js_2, ne, t1, |
| 4203 | Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 4204 | __ li(t1, Operand(ExternalReference(js_entry_sp))); |
| 4205 | __ sw(zero_reg, MemOperand(t1)); |
| 4206 | __ bind(&non_outermost_js_2); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4207 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4208 | // Restore the top frame descriptors from the stack. |
| 4209 | __ pop(t1); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4210 | __ li(t0, Operand(ExternalReference(Isolate::kCEntryFPAddress, |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4211 | isolate))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4212 | __ sw(t1, MemOperand(t0)); |
| 4213 | |
| 4214 | // Reset the stack to the callee saved registers. |
| 4215 | __ addiu(sp, sp, -EntryFrameConstants::kCallerFPOffset); |
| 4216 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4217 | if (CpuFeatures::IsSupported(FPU)) { |
| 4218 | CpuFeatures::Scope scope(FPU); |
| 4219 | // Restore callee-saved fpu registers. |
| 4220 | __ MultiPopFPU(kCalleeSavedFPU); |
| 4221 | } |
| 4222 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4223 | // Restore callee saved registers from the stack. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4224 | __ MultiPop(kCalleeSaved | ra.bit()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4225 | // Return. |
| 4226 | __ Jump(ra); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4227 | } |
| 4228 | |
| 4229 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4230 | // Uses registers a0 to t0. |
| 4231 | // Expected input (depending on whether args are in registers or on the stack): |
| 4232 | // * object: a0 or at sp + 1 * kPointerSize. |
| 4233 | // * function: a1 or at sp. |
| 4234 | // |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4235 | // An inlined call site may have been generated before calling this stub. |
| 4236 | // In this case the offset to the inline site to patch is passed on the stack, |
| 4237 | // in the safepoint slot for register t0. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4238 | void InstanceofStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4239 | // Call site inlining and patching implies arguments in registers. |
| 4240 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 4241 | // ReturnTrueFalse is only implemented for inlined call sites. |
| 4242 | ASSERT(!ReturnTrueFalseObject() || HasCallSiteInlineCheck()); |
| 4243 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4244 | // Fixed register usage throughout the stub: |
| 4245 | const Register object = a0; // Object (lhs). |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4246 | Register map = a3; // Map of the object. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4247 | const Register function = a1; // Function (rhs). |
| 4248 | const Register prototype = t0; // Prototype of the function. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4249 | const Register inline_site = t5; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4250 | const Register scratch = a2; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4251 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 4252 | const int32_t kDeltaToLoadBoolResult = 5 * kPointerSize; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4253 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4254 | Label slow, loop, is_instance, is_not_instance, not_js_object; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4255 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4256 | if (!HasArgsInRegisters()) { |
| 4257 | __ lw(object, MemOperand(sp, 1 * kPointerSize)); |
| 4258 | __ lw(function, MemOperand(sp, 0)); |
| 4259 | } |
| 4260 | |
| 4261 | // Check that the left hand is a JS object and load map. |
| 4262 | __ JumpIfSmi(object, ¬_js_object); |
| 4263 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
| 4264 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4265 | // If there is a call site cache don't look in the global cache, but do the |
| 4266 | // real lookup and update the call site cache. |
| 4267 | if (!HasCallSiteInlineCheck()) { |
| 4268 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4269 | __ LoadRoot(at, Heap::kInstanceofCacheFunctionRootIndex); |
| 4270 | __ Branch(&miss, ne, function, Operand(at)); |
| 4271 | __ LoadRoot(at, Heap::kInstanceofCacheMapRootIndex); |
| 4272 | __ Branch(&miss, ne, map, Operand(at)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4273 | __ LoadRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); |
| 4274 | __ DropAndRet(HasArgsInRegisters() ? 0 : 2); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4275 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4276 | __ bind(&miss); |
| 4277 | } |
| 4278 | |
| 4279 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4280 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4281 | |
| 4282 | // Check that the function prototype is a JS object. |
| 4283 | __ JumpIfSmi(prototype, &slow); |
| 4284 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
| 4285 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4286 | // Update the global instanceof or call site inlined cache with the current |
| 4287 | // map and function. The cached answer will be set when it is known below. |
| 4288 | if (!HasCallSiteInlineCheck()) { |
| 4289 | __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex); |
| 4290 | __ StoreRoot(map, Heap::kInstanceofCacheMapRootIndex); |
| 4291 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4292 | ASSERT(HasArgsInRegisters()); |
| 4293 | // Patch the (relocated) inlined map check. |
| 4294 | |
| 4295 | // The offset was stored in t0 safepoint slot. |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 4296 | // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal). |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4297 | __ LoadFromSafepointRegisterSlot(scratch, t0); |
| 4298 | __ Subu(inline_site, ra, scratch); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 4299 | // Get the map location in scratch and patch it. |
| 4300 | __ GetRelocatedValue(inline_site, scratch, v1); // v1 used as scratch. |
| 4301 | __ sw(map, FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4302 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4303 | |
| 4304 | // Register mapping: a3 is object map and t0 is function prototype. |
| 4305 | // Get prototype of object into a2. |
| 4306 | __ lw(scratch, FieldMemOperand(map, Map::kPrototypeOffset)); |
| 4307 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4308 | // We don't need map any more. Use it as a scratch register. |
| 4309 | Register scratch2 = map; |
| 4310 | map = no_reg; |
| 4311 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4312 | // Loop through the prototype chain looking for the function prototype. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4313 | __ LoadRoot(scratch2, Heap::kNullValueRootIndex); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4314 | __ bind(&loop); |
| 4315 | __ Branch(&is_instance, eq, scratch, Operand(prototype)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4316 | __ Branch(&is_not_instance, eq, scratch, Operand(scratch2)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4317 | __ lw(scratch, FieldMemOperand(scratch, HeapObject::kMapOffset)); |
| 4318 | __ lw(scratch, FieldMemOperand(scratch, Map::kPrototypeOffset)); |
| 4319 | __ Branch(&loop); |
| 4320 | |
| 4321 | __ bind(&is_instance); |
| 4322 | ASSERT(Smi::FromInt(0) == 0); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4323 | if (!HasCallSiteInlineCheck()) { |
| 4324 | __ mov(v0, zero_reg); |
| 4325 | __ StoreRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); |
| 4326 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4327 | // Patch the call site to return true. |
| 4328 | __ LoadRoot(v0, Heap::kTrueValueRootIndex); |
| 4329 | __ Addu(inline_site, inline_site, Operand(kDeltaToLoadBoolResult)); |
| 4330 | // Get the boolean result location in scratch and patch it. |
| 4331 | __ PatchRelocatedValue(inline_site, scratch, v0); |
| 4332 | |
| 4333 | if (!ReturnTrueFalseObject()) { |
| 4334 | ASSERT_EQ(Smi::FromInt(0), 0); |
| 4335 | __ mov(v0, zero_reg); |
| 4336 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4337 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4338 | __ DropAndRet(HasArgsInRegisters() ? 0 : 2); |
| 4339 | |
| 4340 | __ bind(&is_not_instance); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4341 | if (!HasCallSiteInlineCheck()) { |
| 4342 | __ li(v0, Operand(Smi::FromInt(1))); |
| 4343 | __ StoreRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); |
| 4344 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4345 | // Patch the call site to return false. |
| 4346 | __ LoadRoot(v0, Heap::kFalseValueRootIndex); |
| 4347 | __ Addu(inline_site, inline_site, Operand(kDeltaToLoadBoolResult)); |
| 4348 | // Get the boolean result location in scratch and patch it. |
| 4349 | __ PatchRelocatedValue(inline_site, scratch, v0); |
| 4350 | |
| 4351 | if (!ReturnTrueFalseObject()) { |
| 4352 | __ li(v0, Operand(Smi::FromInt(1))); |
| 4353 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4354 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4355 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4356 | __ DropAndRet(HasArgsInRegisters() ? 0 : 2); |
| 4357 | |
| 4358 | Label object_not_null, object_not_null_or_smi; |
| 4359 | __ bind(¬_js_object); |
| 4360 | // Before null, smi and string value checks, check that the rhs is a function |
| 4361 | // as for a non-function rhs an exception needs to be thrown. |
| 4362 | __ JumpIfSmi(function, &slow); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4363 | __ GetObjectType(function, scratch2, scratch); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4364 | __ Branch(&slow, ne, scratch, Operand(JS_FUNCTION_TYPE)); |
| 4365 | |
| 4366 | // Null is not instance of anything. |
| 4367 | __ Branch(&object_not_null, ne, scratch, |
| 4368 | Operand(masm->isolate()->factory()->null_value())); |
| 4369 | __ li(v0, Operand(Smi::FromInt(1))); |
| 4370 | __ DropAndRet(HasArgsInRegisters() ? 0 : 2); |
| 4371 | |
| 4372 | __ bind(&object_not_null); |
| 4373 | // Smi values are not instances of anything. |
| 4374 | __ JumpIfNotSmi(object, &object_not_null_or_smi); |
| 4375 | __ li(v0, Operand(Smi::FromInt(1))); |
| 4376 | __ DropAndRet(HasArgsInRegisters() ? 0 : 2); |
| 4377 | |
| 4378 | __ bind(&object_not_null_or_smi); |
| 4379 | // String values are not instances of anything. |
| 4380 | __ IsObjectJSStringType(object, scratch, &slow); |
| 4381 | __ li(v0, Operand(Smi::FromInt(1))); |
| 4382 | __ DropAndRet(HasArgsInRegisters() ? 0 : 2); |
| 4383 | |
| 4384 | // Slow-case. Tail call builtin. |
| 4385 | __ bind(&slow); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4386 | if (!ReturnTrueFalseObject()) { |
| 4387 | if (HasArgsInRegisters()) { |
| 4388 | __ Push(a0, a1); |
| 4389 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4390 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4391 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4392 | { |
| 4393 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4394 | __ Push(a0, a1); |
| 4395 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 4396 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4397 | __ mov(a0, v0); |
| 4398 | __ LoadRoot(v0, Heap::kTrueValueRootIndex); |
| 4399 | __ DropAndRet(HasArgsInRegisters() ? 0 : 2, eq, a0, Operand(zero_reg)); |
| 4400 | __ LoadRoot(v0, Heap::kFalseValueRootIndex); |
| 4401 | __ DropAndRet(HasArgsInRegisters() ? 0 : 2); |
| 4402 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4403 | } |
| 4404 | |
| 4405 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4406 | Register InstanceofStub::left() { return a0; } |
| 4407 | |
| 4408 | |
| 4409 | Register InstanceofStub::right() { return a1; } |
| 4410 | |
| 4411 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4412 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4413 | // The displacement is the offset of the last parameter (if any) |
| 4414 | // relative to the frame pointer. |
| 4415 | static const int kDisplacement = |
| 4416 | StandardFrameConstants::kCallerSPOffset - kPointerSize; |
| 4417 | |
| 4418 | // Check that the key is a smiGenerateReadElement. |
| 4419 | Label slow; |
| 4420 | __ JumpIfNotSmi(a1, &slow); |
| 4421 | |
| 4422 | // Check if the calling frame is an arguments adaptor frame. |
| 4423 | Label adaptor; |
| 4424 | __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4425 | __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset)); |
| 4426 | __ Branch(&adaptor, |
| 4427 | eq, |
| 4428 | a3, |
| 4429 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4430 | |
| 4431 | // Check index (a1) against formal parameters count limit passed in |
| 4432 | // through register a0. Use unsigned comparison to get negative |
| 4433 | // check for free. |
| 4434 | __ Branch(&slow, hs, a1, Operand(a0)); |
| 4435 | |
| 4436 | // Read the argument from the stack and return it. |
| 4437 | __ subu(a3, a0, a1); |
| 4438 | __ sll(t3, a3, kPointerSizeLog2 - kSmiTagSize); |
| 4439 | __ Addu(a3, fp, Operand(t3)); |
| 4440 | __ lw(v0, MemOperand(a3, kDisplacement)); |
| 4441 | __ Ret(); |
| 4442 | |
| 4443 | // Arguments adaptor case: Check index (a1) against actual arguments |
| 4444 | // limit found in the arguments adaptor frame. Use unsigned |
| 4445 | // comparison to get negative check for free. |
| 4446 | __ bind(&adaptor); |
| 4447 | __ lw(a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4448 | __ Branch(&slow, Ugreater_equal, a1, Operand(a0)); |
| 4449 | |
| 4450 | // Read the argument from the adaptor frame and return it. |
| 4451 | __ subu(a3, a0, a1); |
| 4452 | __ sll(t3, a3, kPointerSizeLog2 - kSmiTagSize); |
| 4453 | __ Addu(a3, a2, Operand(t3)); |
| 4454 | __ lw(v0, MemOperand(a3, kDisplacement)); |
| 4455 | __ Ret(); |
| 4456 | |
| 4457 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 4458 | // by calling the runtime system. |
| 4459 | __ bind(&slow); |
| 4460 | __ push(a1); |
| 4461 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4465 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4466 | // sp[0] : number of parameters |
| 4467 | // sp[4] : receiver displacement |
| 4468 | // sp[8] : function |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4469 | // Check if the calling frame is an arguments adaptor frame. |
| 4470 | Label runtime; |
| 4471 | __ lw(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4472 | __ lw(a2, MemOperand(a3, StandardFrameConstants::kContextOffset)); |
| 4473 | __ Branch(&runtime, ne, |
| 4474 | a2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4475 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4476 | // Patch the arguments.length and the parameters pointer in the current frame. |
| 4477 | __ lw(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4478 | __ sw(a2, MemOperand(sp, 0 * kPointerSize)); |
| 4479 | __ sll(t3, a2, 1); |
| 4480 | __ Addu(a3, a3, Operand(t3)); |
| 4481 | __ addiu(a3, a3, StandardFrameConstants::kCallerSPOffset); |
| 4482 | __ sw(a3, MemOperand(sp, 1 * kPointerSize)); |
| 4483 | |
| 4484 | __ bind(&runtime); |
| 4485 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 4486 | } |
| 4487 | |
| 4488 | |
| 4489 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 4490 | // Stack layout: |
| 4491 | // sp[0] : number of parameters (tagged) |
| 4492 | // sp[4] : address of receiver argument |
| 4493 | // sp[8] : function |
| 4494 | // Registers used over whole function: |
| 4495 | // t2 : allocated object (tagged) |
| 4496 | // t5 : mapped parameter count (tagged) |
| 4497 | |
| 4498 | __ lw(a1, MemOperand(sp, 0 * kPointerSize)); |
| 4499 | // a1 = parameter count (tagged) |
| 4500 | |
| 4501 | // Check if the calling frame is an arguments adaptor frame. |
| 4502 | Label runtime; |
| 4503 | Label adaptor_frame, try_allocate; |
| 4504 | __ lw(a3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4505 | __ lw(a2, MemOperand(a3, StandardFrameConstants::kContextOffset)); |
| 4506 | __ Branch(&adaptor_frame, eq, a2, |
| 4507 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4508 | |
| 4509 | // No adaptor, parameter count = argument count. |
| 4510 | __ mov(a2, a1); |
| 4511 | __ b(&try_allocate); |
| 4512 | __ nop(); // Branch delay slot nop. |
| 4513 | |
| 4514 | // We have an adaptor frame. Patch the parameters pointer. |
| 4515 | __ bind(&adaptor_frame); |
| 4516 | __ lw(a2, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4517 | __ sll(t6, a2, 1); |
| 4518 | __ Addu(a3, a3, Operand(t6)); |
| 4519 | __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 4520 | __ sw(a3, MemOperand(sp, 1 * kPointerSize)); |
| 4521 | |
| 4522 | // a1 = parameter count (tagged) |
| 4523 | // a2 = argument count (tagged) |
| 4524 | // Compute the mapped parameter count = min(a1, a2) in a1. |
| 4525 | Label skip_min; |
| 4526 | __ Branch(&skip_min, lt, a1, Operand(a2)); |
| 4527 | __ mov(a1, a2); |
| 4528 | __ bind(&skip_min); |
| 4529 | |
| 4530 | __ bind(&try_allocate); |
| 4531 | |
| 4532 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 4533 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 4534 | const int kParameterMapHeaderSize = |
| 4535 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 4536 | // If there are no mapped parameters, we do not need the parameter_map. |
| 4537 | Label param_map_size; |
| 4538 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4539 | __ Branch(USE_DELAY_SLOT, ¶m_map_size, eq, a1, Operand(zero_reg)); |
| 4540 | __ mov(t5, zero_reg); // In delay slot: param map size = 0 when a1 == 0. |
| 4541 | __ sll(t5, a1, 1); |
| 4542 | __ addiu(t5, t5, kParameterMapHeaderSize); |
| 4543 | __ bind(¶m_map_size); |
| 4544 | |
| 4545 | // 2. Backing store. |
| 4546 | __ sll(t6, a2, 1); |
| 4547 | __ Addu(t5, t5, Operand(t6)); |
| 4548 | __ Addu(t5, t5, Operand(FixedArray::kHeaderSize)); |
| 4549 | |
| 4550 | // 3. Arguments object. |
| 4551 | __ Addu(t5, t5, Operand(Heap::kArgumentsObjectSize)); |
| 4552 | |
| 4553 | // Do the allocation of all three objects in one go. |
| 4554 | __ AllocateInNewSpace(t5, v0, a3, t0, &runtime, TAG_OBJECT); |
| 4555 | |
| 4556 | // v0 = address of new object(s) (tagged) |
| 4557 | // a2 = argument count (tagged) |
| 4558 | // Get the arguments boilerplate from the current (global) context into t0. |
| 4559 | const int kNormalOffset = |
| 4560 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX); |
| 4561 | const int kAliasedOffset = |
| 4562 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX); |
| 4563 | |
| 4564 | __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 4565 | __ lw(t0, FieldMemOperand(t0, GlobalObject::kGlobalContextOffset)); |
| 4566 | Label skip2_ne, skip2_eq; |
| 4567 | __ Branch(&skip2_ne, ne, a1, Operand(zero_reg)); |
| 4568 | __ lw(t0, MemOperand(t0, kNormalOffset)); |
| 4569 | __ bind(&skip2_ne); |
| 4570 | |
| 4571 | __ Branch(&skip2_eq, eq, a1, Operand(zero_reg)); |
| 4572 | __ lw(t0, MemOperand(t0, kAliasedOffset)); |
| 4573 | __ bind(&skip2_eq); |
| 4574 | |
| 4575 | // v0 = address of new object (tagged) |
| 4576 | // a1 = mapped parameter count (tagged) |
| 4577 | // a2 = argument count (tagged) |
| 4578 | // t0 = address of boilerplate object (tagged) |
| 4579 | // Copy the JS object part. |
| 4580 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 4581 | __ lw(a3, FieldMemOperand(t0, i)); |
| 4582 | __ sw(a3, FieldMemOperand(v0, i)); |
| 4583 | } |
| 4584 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4585 | // Set up the callee in-object property. |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4586 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 4587 | __ lw(a3, MemOperand(sp, 2 * kPointerSize)); |
| 4588 | const int kCalleeOffset = JSObject::kHeaderSize + |
| 4589 | Heap::kArgumentsCalleeIndex * kPointerSize; |
| 4590 | __ sw(a3, FieldMemOperand(v0, kCalleeOffset)); |
| 4591 | |
| 4592 | // Use the length (smi tagged) and set that as an in-object property too. |
| 4593 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 4594 | const int kLengthOffset = JSObject::kHeaderSize + |
| 4595 | Heap::kArgumentsLengthIndex * kPointerSize; |
| 4596 | __ sw(a2, FieldMemOperand(v0, kLengthOffset)); |
| 4597 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4598 | // Set up the elements pointer in the allocated arguments object. |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4599 | // If we allocated a parameter map, t0 will point there, otherwise |
| 4600 | // it will point to the backing store. |
| 4601 | __ Addu(t0, v0, Operand(Heap::kArgumentsObjectSize)); |
| 4602 | __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset)); |
| 4603 | |
| 4604 | // v0 = address of new object (tagged) |
| 4605 | // a1 = mapped parameter count (tagged) |
| 4606 | // a2 = argument count (tagged) |
| 4607 | // t0 = address of parameter map or backing store (tagged) |
| 4608 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 4609 | Label skip_parameter_map; |
| 4610 | Label skip3; |
| 4611 | __ Branch(&skip3, ne, a1, Operand(Smi::FromInt(0))); |
| 4612 | // Move backing store address to a3, because it is |
| 4613 | // expected there when filling in the unmapped arguments. |
| 4614 | __ mov(a3, t0); |
| 4615 | __ bind(&skip3); |
| 4616 | |
| 4617 | __ Branch(&skip_parameter_map, eq, a1, Operand(Smi::FromInt(0))); |
| 4618 | |
| 4619 | __ LoadRoot(t2, Heap::kNonStrictArgumentsElementsMapRootIndex); |
| 4620 | __ sw(t2, FieldMemOperand(t0, FixedArray::kMapOffset)); |
| 4621 | __ Addu(t2, a1, Operand(Smi::FromInt(2))); |
| 4622 | __ sw(t2, FieldMemOperand(t0, FixedArray::kLengthOffset)); |
| 4623 | __ sw(cp, FieldMemOperand(t0, FixedArray::kHeaderSize + 0 * kPointerSize)); |
| 4624 | __ sll(t6, a1, 1); |
| 4625 | __ Addu(t2, t0, Operand(t6)); |
| 4626 | __ Addu(t2, t2, Operand(kParameterMapHeaderSize)); |
| 4627 | __ sw(t2, FieldMemOperand(t0, FixedArray::kHeaderSize + 1 * kPointerSize)); |
| 4628 | |
| 4629 | // Copy the parameter slots and the holes in the arguments. |
| 4630 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 4631 | // where parameters are stored in reverse order, at |
| 4632 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 4633 | // The mapped parameter thus need to get indices |
| 4634 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 4635 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 4636 | // We loop from right to left. |
| 4637 | Label parameters_loop, parameters_test; |
| 4638 | __ mov(t2, a1); |
| 4639 | __ lw(t5, MemOperand(sp, 0 * kPointerSize)); |
| 4640 | __ Addu(t5, t5, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 4641 | __ Subu(t5, t5, Operand(a1)); |
| 4642 | __ LoadRoot(t3, Heap::kTheHoleValueRootIndex); |
| 4643 | __ sll(t6, t2, 1); |
| 4644 | __ Addu(a3, t0, Operand(t6)); |
| 4645 | __ Addu(a3, a3, Operand(kParameterMapHeaderSize)); |
| 4646 | |
| 4647 | // t2 = loop variable (tagged) |
| 4648 | // a1 = mapping index (tagged) |
| 4649 | // a3 = address of backing store (tagged) |
| 4650 | // t0 = address of parameter map (tagged) |
| 4651 | // t1 = temporary scratch (a.o., for address calculation) |
| 4652 | // t3 = the hole value |
| 4653 | __ jmp(¶meters_test); |
| 4654 | |
| 4655 | __ bind(¶meters_loop); |
| 4656 | __ Subu(t2, t2, Operand(Smi::FromInt(1))); |
| 4657 | __ sll(t1, t2, 1); |
| 4658 | __ Addu(t1, t1, Operand(kParameterMapHeaderSize - kHeapObjectTag)); |
| 4659 | __ Addu(t6, t0, t1); |
| 4660 | __ sw(t5, MemOperand(t6)); |
| 4661 | __ Subu(t1, t1, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize)); |
| 4662 | __ Addu(t6, a3, t1); |
| 4663 | __ sw(t3, MemOperand(t6)); |
| 4664 | __ Addu(t5, t5, Operand(Smi::FromInt(1))); |
| 4665 | __ bind(¶meters_test); |
| 4666 | __ Branch(¶meters_loop, ne, t2, Operand(Smi::FromInt(0))); |
| 4667 | |
| 4668 | __ bind(&skip_parameter_map); |
| 4669 | // a2 = argument count (tagged) |
| 4670 | // a3 = address of backing store (tagged) |
| 4671 | // t1 = scratch |
| 4672 | // Copy arguments header and remaining slots (if there are any). |
| 4673 | __ LoadRoot(t1, Heap::kFixedArrayMapRootIndex); |
| 4674 | __ sw(t1, FieldMemOperand(a3, FixedArray::kMapOffset)); |
| 4675 | __ sw(a2, FieldMemOperand(a3, FixedArray::kLengthOffset)); |
| 4676 | |
| 4677 | Label arguments_loop, arguments_test; |
| 4678 | __ mov(t5, a1); |
| 4679 | __ lw(t0, MemOperand(sp, 1 * kPointerSize)); |
| 4680 | __ sll(t6, t5, 1); |
| 4681 | __ Subu(t0, t0, Operand(t6)); |
| 4682 | __ jmp(&arguments_test); |
| 4683 | |
| 4684 | __ bind(&arguments_loop); |
| 4685 | __ Subu(t0, t0, Operand(kPointerSize)); |
| 4686 | __ lw(t2, MemOperand(t0, 0)); |
| 4687 | __ sll(t6, t5, 1); |
| 4688 | __ Addu(t1, a3, Operand(t6)); |
| 4689 | __ sw(t2, FieldMemOperand(t1, FixedArray::kHeaderSize)); |
| 4690 | __ Addu(t5, t5, Operand(Smi::FromInt(1))); |
| 4691 | |
| 4692 | __ bind(&arguments_test); |
| 4693 | __ Branch(&arguments_loop, lt, t5, Operand(a2)); |
| 4694 | |
| 4695 | // Return and remove the on-stack parameters. |
| 4696 | __ Addu(sp, sp, Operand(3 * kPointerSize)); |
| 4697 | __ Ret(); |
| 4698 | |
| 4699 | // Do the runtime call to allocate the arguments object. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4700 | // a2 = argument count (tagged) |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4701 | __ bind(&runtime); |
| 4702 | __ sw(a2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count. |
| 4703 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 4704 | } |
| 4705 | |
| 4706 | |
| 4707 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 4708 | // sp[0] : number of parameters |
| 4709 | // sp[4] : receiver displacement |
| 4710 | // sp[8] : function |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4711 | // Check if the calling frame is an arguments adaptor frame. |
| 4712 | Label adaptor_frame, try_allocate, runtime; |
| 4713 | __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4714 | __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset)); |
| 4715 | __ Branch(&adaptor_frame, |
| 4716 | eq, |
| 4717 | a3, |
| 4718 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4719 | |
| 4720 | // Get the length from the frame. |
| 4721 | __ lw(a1, MemOperand(sp, 0)); |
| 4722 | __ Branch(&try_allocate); |
| 4723 | |
| 4724 | // Patch the arguments.length and the parameters pointer. |
| 4725 | __ bind(&adaptor_frame); |
| 4726 | __ lw(a1, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4727 | __ sw(a1, MemOperand(sp, 0)); |
| 4728 | __ sll(at, a1, kPointerSizeLog2 - kSmiTagSize); |
| 4729 | __ Addu(a3, a2, Operand(at)); |
| 4730 | |
| 4731 | __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 4732 | __ sw(a3, MemOperand(sp, 1 * kPointerSize)); |
| 4733 | |
| 4734 | // Try the new space allocation. Start out with computing the size |
| 4735 | // of the arguments object and the elements array in words. |
| 4736 | Label add_arguments_object; |
| 4737 | __ bind(&try_allocate); |
| 4738 | __ Branch(&add_arguments_object, eq, a1, Operand(zero_reg)); |
| 4739 | __ srl(a1, a1, kSmiTagSize); |
| 4740 | |
| 4741 | __ Addu(a1, a1, Operand(FixedArray::kHeaderSize / kPointerSize)); |
| 4742 | __ bind(&add_arguments_object); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4743 | __ Addu(a1, a1, Operand(Heap::kArgumentsObjectSizeStrict / kPointerSize)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4744 | |
| 4745 | // Do the allocation of both objects in one go. |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4746 | __ AllocateInNewSpace(a1, |
| 4747 | v0, |
| 4748 | a2, |
| 4749 | a3, |
| 4750 | &runtime, |
| 4751 | static_cast<AllocationFlags>(TAG_OBJECT | |
| 4752 | SIZE_IN_WORDS)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4753 | |
| 4754 | // Get the arguments boilerplate from the current (global) context. |
| 4755 | __ lw(t0, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 4756 | __ lw(t0, FieldMemOperand(t0, GlobalObject::kGlobalContextOffset)); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4757 | __ lw(t0, MemOperand(t0, Context::SlotOffset( |
| 4758 | Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4759 | |
| 4760 | // Copy the JS object part. |
| 4761 | __ CopyFields(v0, t0, a3.bit(), JSObject::kHeaderSize / kPointerSize); |
| 4762 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4763 | // Get the length (smi tagged) and set that as an in-object property too. |
| 4764 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 4765 | __ lw(a1, MemOperand(sp, 0 * kPointerSize)); |
| 4766 | __ sw(a1, FieldMemOperand(v0, JSObject::kHeaderSize + |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4767 | Heap::kArgumentsLengthIndex * kPointerSize)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4768 | |
| 4769 | Label done; |
| 4770 | __ Branch(&done, eq, a1, Operand(zero_reg)); |
| 4771 | |
| 4772 | // Get the parameters pointer from the stack. |
| 4773 | __ lw(a2, MemOperand(sp, 1 * kPointerSize)); |
| 4774 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4775 | // Set up the elements pointer in the allocated arguments object and |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4776 | // initialize the header in the elements fixed array. |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4777 | __ Addu(t0, v0, Operand(Heap::kArgumentsObjectSizeStrict)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4778 | __ sw(t0, FieldMemOperand(v0, JSObject::kElementsOffset)); |
| 4779 | __ LoadRoot(a3, Heap::kFixedArrayMapRootIndex); |
| 4780 | __ sw(a3, FieldMemOperand(t0, FixedArray::kMapOffset)); |
| 4781 | __ sw(a1, FieldMemOperand(t0, FixedArray::kLengthOffset)); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4782 | // Untag the length for the loop. |
| 4783 | __ srl(a1, a1, kSmiTagSize); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4784 | |
| 4785 | // Copy the fixed array slots. |
| 4786 | Label loop; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4787 | // Set up t0 to point to the first array slot. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4788 | __ Addu(t0, t0, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 4789 | __ bind(&loop); |
| 4790 | // Pre-decrement a2 with kPointerSize on each iteration. |
| 4791 | // Pre-decrement in order to skip receiver. |
| 4792 | __ Addu(a2, a2, Operand(-kPointerSize)); |
| 4793 | __ lw(a3, MemOperand(a2)); |
| 4794 | // Post-increment t0 with kPointerSize on each iteration. |
| 4795 | __ sw(a3, MemOperand(t0)); |
| 4796 | __ Addu(t0, t0, Operand(kPointerSize)); |
| 4797 | __ Subu(a1, a1, Operand(1)); |
| 4798 | __ Branch(&loop, ne, a1, Operand(zero_reg)); |
| 4799 | |
| 4800 | // Return and remove the on-stack parameters. |
| 4801 | __ bind(&done); |
| 4802 | __ Addu(sp, sp, Operand(3 * kPointerSize)); |
| 4803 | __ Ret(); |
| 4804 | |
| 4805 | // Do the runtime call to allocate the arguments object. |
| 4806 | __ bind(&runtime); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 4807 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | |
| 4811 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4812 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 4813 | // time or if regexp entry in generated code is turned off runtime switch or |
| 4814 | // at compilation. |
| 4815 | #ifdef V8_INTERPRETED_REGEXP |
| 4816 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4817 | #else // V8_INTERPRETED_REGEXP |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4818 | |
| 4819 | // Stack frame on entry. |
| 4820 | // sp[0]: last_match_info (expected JSArray) |
| 4821 | // sp[4]: previous index |
| 4822 | // sp[8]: subject string |
| 4823 | // sp[12]: JSRegExp object |
| 4824 | |
| 4825 | static const int kLastMatchInfoOffset = 0 * kPointerSize; |
| 4826 | static const int kPreviousIndexOffset = 1 * kPointerSize; |
| 4827 | static const int kSubjectOffset = 2 * kPointerSize; |
| 4828 | static const int kJSRegExpOffset = 3 * kPointerSize; |
| 4829 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4830 | Isolate* isolate = masm->isolate(); |
| 4831 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4832 | Label runtime, invoke_regexp; |
| 4833 | |
| 4834 | // Allocation of registers for this function. These are in callee save |
| 4835 | // registers and will be preserved by the call to the native RegExp code, as |
| 4836 | // this code is called using the normal C calling convention. When calling |
| 4837 | // directly from generated code the native RegExp code will not do a GC and |
| 4838 | // therefore the content of these registers are safe to use after the call. |
| 4839 | // MIPS - using s0..s2, since we are not using CEntry Stub. |
| 4840 | Register subject = s0; |
| 4841 | Register regexp_data = s1; |
| 4842 | Register last_match_info_elements = s2; |
| 4843 | |
| 4844 | // Ensure that a RegExp stack is allocated. |
| 4845 | ExternalReference address_of_regexp_stack_memory_address = |
| 4846 | ExternalReference::address_of_regexp_stack_memory_address( |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4847 | isolate); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4848 | ExternalReference address_of_regexp_stack_memory_size = |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4849 | ExternalReference::address_of_regexp_stack_memory_size(isolate); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4850 | __ li(a0, Operand(address_of_regexp_stack_memory_size)); |
| 4851 | __ lw(a0, MemOperand(a0, 0)); |
| 4852 | __ Branch(&runtime, eq, a0, Operand(zero_reg)); |
| 4853 | |
| 4854 | // Check that the first argument is a JSRegExp object. |
| 4855 | __ lw(a0, MemOperand(sp, kJSRegExpOffset)); |
| 4856 | STATIC_ASSERT(kSmiTag == 0); |
| 4857 | __ JumpIfSmi(a0, &runtime); |
| 4858 | __ GetObjectType(a0, a1, a1); |
| 4859 | __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE)); |
| 4860 | |
| 4861 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 4862 | __ lw(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset)); |
| 4863 | if (FLAG_debug_code) { |
| 4864 | __ And(t0, regexp_data, Operand(kSmiTagMask)); |
| 4865 | __ Check(nz, |
| 4866 | "Unexpected type for RegExp data, FixedArray expected", |
| 4867 | t0, |
| 4868 | Operand(zero_reg)); |
| 4869 | __ GetObjectType(regexp_data, a0, a0); |
| 4870 | __ Check(eq, |
| 4871 | "Unexpected type for RegExp data, FixedArray expected", |
| 4872 | a0, |
| 4873 | Operand(FIXED_ARRAY_TYPE)); |
| 4874 | } |
| 4875 | |
| 4876 | // regexp_data: RegExp data (FixedArray) |
| 4877 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 4878 | __ lw(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset)); |
| 4879 | __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP))); |
| 4880 | |
| 4881 | // regexp_data: RegExp data (FixedArray) |
| 4882 | // Check that the number of captures fit in the static offsets vector buffer. |
| 4883 | __ lw(a2, |
| 4884 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 4885 | // Calculate number of capture registers (number_of_captures + 1) * 2. This |
| 4886 | // uses the asumption that smis are 2 * their untagged value. |
| 4887 | STATIC_ASSERT(kSmiTag == 0); |
| 4888 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 4889 | __ Addu(a2, a2, Operand(2)); // a2 was a smi. |
| 4890 | // Check that the static offsets vector buffer is large enough. |
| 4891 | __ Branch(&runtime, hi, a2, Operand(OffsetsVector::kStaticOffsetsVectorSize)); |
| 4892 | |
| 4893 | // a2: Number of capture registers |
| 4894 | // regexp_data: RegExp data (FixedArray) |
| 4895 | // Check that the second argument is a string. |
| 4896 | __ lw(subject, MemOperand(sp, kSubjectOffset)); |
| 4897 | __ JumpIfSmi(subject, &runtime); |
| 4898 | __ GetObjectType(subject, a0, a0); |
| 4899 | __ And(a0, a0, Operand(kIsNotStringMask)); |
| 4900 | STATIC_ASSERT(kStringTag == 0); |
| 4901 | __ Branch(&runtime, ne, a0, Operand(zero_reg)); |
| 4902 | |
| 4903 | // Get the length of the string to r3. |
| 4904 | __ lw(a3, FieldMemOperand(subject, String::kLengthOffset)); |
| 4905 | |
| 4906 | // a2: Number of capture registers |
| 4907 | // a3: Length of subject string as a smi |
| 4908 | // subject: Subject string |
| 4909 | // regexp_data: RegExp data (FixedArray) |
| 4910 | // Check that the third argument is a positive smi less than the subject |
| 4911 | // string length. A negative value will be greater (unsigned comparison). |
| 4912 | __ lw(a0, MemOperand(sp, kPreviousIndexOffset)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4913 | __ JumpIfNotSmi(a0, &runtime); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4914 | __ Branch(&runtime, ls, a3, Operand(a0)); |
| 4915 | |
| 4916 | // a2: Number of capture registers |
| 4917 | // subject: Subject string |
| 4918 | // regexp_data: RegExp data (FixedArray) |
| 4919 | // Check that the fourth object is a JSArray object. |
| 4920 | __ lw(a0, MemOperand(sp, kLastMatchInfoOffset)); |
| 4921 | __ JumpIfSmi(a0, &runtime); |
| 4922 | __ GetObjectType(a0, a1, a1); |
| 4923 | __ Branch(&runtime, ne, a1, Operand(JS_ARRAY_TYPE)); |
| 4924 | // Check that the JSArray is in fast case. |
| 4925 | __ lw(last_match_info_elements, |
| 4926 | FieldMemOperand(a0, JSArray::kElementsOffset)); |
| 4927 | __ lw(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset)); |
| 4928 | __ Branch(&runtime, ne, a0, Operand( |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4929 | isolate->factory()->fixed_array_map())); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4930 | // Check that the last match info has space for the capture registers and the |
| 4931 | // additional information. |
| 4932 | __ lw(a0, |
| 4933 | FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset)); |
| 4934 | __ Addu(a2, a2, Operand(RegExpImpl::kLastMatchOverhead)); |
| 4935 | __ sra(at, a0, kSmiTagSize); // Untag length for comparison. |
| 4936 | __ Branch(&runtime, gt, a2, Operand(at)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4937 | |
| 4938 | // Reset offset for possibly sliced string. |
| 4939 | __ mov(t0, zero_reg); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4940 | // subject: Subject string |
| 4941 | // regexp_data: RegExp data (FixedArray) |
| 4942 | // Check the representation and encoding of the subject string. |
| 4943 | Label seq_string; |
| 4944 | __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 4945 | __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset)); |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4946 | // First check for flat string. None of the following string type tests will |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4947 | // succeed if subject is not a string or a short external string. |
| 4948 | __ And(a1, |
| 4949 | a0, |
| 4950 | Operand(kIsNotStringMask | |
| 4951 | kStringRepresentationMask | |
| 4952 | kShortExternalStringMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4953 | STATIC_ASSERT((kStringTag | kSeqStringTag) == 0); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4954 | __ Branch(&seq_string, eq, a1, Operand(zero_reg)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4955 | |
| 4956 | // subject: Subject string |
| 4957 | // a0: instance type if Subject string |
| 4958 | // regexp_data: RegExp data (FixedArray) |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4959 | // a1: whether subject is a string and if yes, its string representation |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4960 | // Check for flat cons string or sliced string. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4961 | // A flat cons string is a cons string where the second part is the empty |
| 4962 | // string. In that case the subject string is just the first part of the cons |
| 4963 | // string. Also in this case the first part of the cons string is known to be |
| 4964 | // a sequential string or an external string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4965 | // In the case of a sliced string its offset has to be taken into account. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4966 | Label cons_string, external_string, check_encoding; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4967 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 4968 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4969 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4970 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4971 | __ Branch(&cons_string, lt, a1, Operand(kExternalStringTag)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4972 | __ Branch(&external_string, eq, a1, Operand(kExternalStringTag)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4973 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4974 | // Catch non-string subject or short external string. |
| 4975 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 4976 | __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask)); |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4977 | __ Branch(&runtime, ne, at, Operand(zero_reg)); |
| 4978 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4979 | // String is sliced. |
| 4980 | __ lw(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset)); |
| 4981 | __ sra(t0, t0, kSmiTagSize); |
| 4982 | __ lw(subject, FieldMemOperand(subject, SlicedString::kParentOffset)); |
| 4983 | // t5: offset of sliced string, smi-tagged. |
| 4984 | __ jmp(&check_encoding); |
| 4985 | // String is a cons string, check whether it is flat. |
| 4986 | __ bind(&cons_string); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4987 | __ lw(a0, FieldMemOperand(subject, ConsString::kSecondOffset)); |
| 4988 | __ LoadRoot(a1, Heap::kEmptyStringRootIndex); |
| 4989 | __ Branch(&runtime, ne, a0, Operand(a1)); |
| 4990 | __ lw(subject, FieldMemOperand(subject, ConsString::kFirstOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4991 | // Is first part of cons or parent of slice a flat string? |
| 4992 | __ bind(&check_encoding); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4993 | __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 4994 | __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4995 | STATIC_ASSERT(kSeqStringTag == 0); |
| 4996 | __ And(at, a0, Operand(kStringRepresentationMask)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4997 | __ Branch(&external_string, ne, at, Operand(zero_reg)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4998 | |
| 4999 | __ bind(&seq_string); |
| 5000 | // subject: Subject string |
| 5001 | // regexp_data: RegExp data (FixedArray) |
| 5002 | // a0: Instance type of subject string |
| 5003 | STATIC_ASSERT(kStringEncodingMask == 4); |
| 5004 | STATIC_ASSERT(kAsciiStringTag == 4); |
| 5005 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5006 | // Find the code object based on the assumptions above. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5007 | __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for ASCII. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5008 | __ lw(t9, FieldMemOperand(regexp_data, JSRegExp::kDataAsciiCodeOffset)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5009 | __ sra(a3, a0, 2); // a3 is 1 for ASCII, 0 for UC16 (used below). |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5010 | __ lw(t1, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset)); |
| 5011 | __ movz(t9, t1, a0); // If UC16 (a0 is 0), replace t9 w/kDataUC16CodeOffset. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5012 | |
| 5013 | // Check that the irregexp code has been generated for the actual string |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 5014 | // encoding. If it has, the field contains a code object otherwise it contains |
| 5015 | // a smi (code flushing support). |
| 5016 | __ JumpIfSmi(t9, &runtime); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5017 | |
| 5018 | // a3: encoding of subject string (1 if ASCII, 0 if two_byte); |
| 5019 | // t9: code |
| 5020 | // subject: Subject string |
| 5021 | // regexp_data: RegExp data (FixedArray) |
| 5022 | // Load used arguments before starting to push arguments for call to native |
| 5023 | // RegExp code to avoid handling changing stack height. |
| 5024 | __ lw(a1, MemOperand(sp, kPreviousIndexOffset)); |
| 5025 | __ sra(a1, a1, kSmiTagSize); // Untag the Smi. |
| 5026 | |
| 5027 | // a1: previous index |
| 5028 | // a3: encoding of subject string (1 if ASCII, 0 if two_byte); |
| 5029 | // t9: code |
| 5030 | // subject: Subject string |
| 5031 | // regexp_data: RegExp data (FixedArray) |
| 5032 | // All checks done. Now push arguments for native regexp code. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5033 | __ IncrementCounter(isolate->counters()->regexp_entry_native(), |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5034 | 1, a0, a2); |
| 5035 | |
| 5036 | // Isolates: note we add an additional parameter here (isolate pointer). |
| 5037 | static const int kRegExpExecuteArguments = 8; |
| 5038 | static const int kParameterRegisters = 4; |
| 5039 | __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters); |
| 5040 | |
| 5041 | // Stack pointer now points to cell where return address is to be written. |
| 5042 | // Arguments are before that on the stack or in registers, meaning we |
| 5043 | // treat the return address as argument 5. Thus every argument after that |
| 5044 | // needs to be shifted back by 1. Since DirectCEntryStub will handle |
| 5045 | // allocating space for the c argument slots, we don't need to calculate |
| 5046 | // that into the argument positions on the stack. This is how the stack will |
| 5047 | // look (sp meaning the value of sp at this moment): |
| 5048 | // [sp + 4] - Argument 8 |
| 5049 | // [sp + 3] - Argument 7 |
| 5050 | // [sp + 2] - Argument 6 |
| 5051 | // [sp + 1] - Argument 5 |
| 5052 | // [sp + 0] - saved ra |
| 5053 | |
| 5054 | // Argument 8: Pass current isolate address. |
| 5055 | // CFunctionArgumentOperand handles MIPS stack argument slots. |
| 5056 | __ li(a0, Operand(ExternalReference::isolate_address())); |
| 5057 | __ sw(a0, MemOperand(sp, 4 * kPointerSize)); |
| 5058 | |
| 5059 | // Argument 7: Indicate that this is a direct call from JavaScript. |
| 5060 | __ li(a0, Operand(1)); |
| 5061 | __ sw(a0, MemOperand(sp, 3 * kPointerSize)); |
| 5062 | |
| 5063 | // Argument 6: Start (high end) of backtracking stack memory area. |
| 5064 | __ li(a0, Operand(address_of_regexp_stack_memory_address)); |
| 5065 | __ lw(a0, MemOperand(a0, 0)); |
| 5066 | __ li(a2, Operand(address_of_regexp_stack_memory_size)); |
| 5067 | __ lw(a2, MemOperand(a2, 0)); |
| 5068 | __ addu(a0, a0, a2); |
| 5069 | __ sw(a0, MemOperand(sp, 2 * kPointerSize)); |
| 5070 | |
| 5071 | // Argument 5: static offsets vector buffer. |
| 5072 | __ li(a0, Operand( |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5073 | ExternalReference::address_of_static_offsets_vector(isolate))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5074 | __ sw(a0, MemOperand(sp, 1 * kPointerSize)); |
| 5075 | |
| 5076 | // For arguments 4 and 3 get string length, calculate start of string data |
| 5077 | // and 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] | 5078 | __ Addu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5079 | __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5080 | // Load the length from the original subject string from the previous stack |
| 5081 | // frame. Therefore we have to use fp, which points exactly to two pointer |
| 5082 | // sizes below the previous sp. (Because creating a new stack frame pushes |
| 5083 | // the previous fp onto the stack and moves up sp by 2 * kPointerSize.) |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 5084 | __ lw(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5085 | // If slice offset is not 0, load the length from the original sliced string. |
| 5086 | // Argument 4, a3: End of string data |
| 5087 | // Argument 3, a2: Start of string data |
| 5088 | // Prepare start and end index of the input. |
| 5089 | __ sllv(t1, t0, a3); |
| 5090 | __ addu(t0, t2, t1); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5091 | __ sllv(t1, a1, a3); |
| 5092 | __ addu(a2, t0, t1); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5093 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 5094 | __ lw(t2, FieldMemOperand(subject, String::kLengthOffset)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5095 | __ sra(t2, t2, kSmiTagSize); |
| 5096 | __ sllv(t1, t2, a3); |
| 5097 | __ addu(a3, t0, t1); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5098 | // Argument 2 (a1): Previous index. |
| 5099 | // Already there |
| 5100 | |
| 5101 | // Argument 1 (a0): Subject string. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 5102 | __ mov(a0, subject); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5103 | |
| 5104 | // Locate the code entry and call it. |
| 5105 | __ Addu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 5106 | DirectCEntryStub stub; |
| 5107 | stub.GenerateCall(masm, t9); |
| 5108 | |
| 5109 | __ LeaveExitFrame(false, no_reg); |
| 5110 | |
| 5111 | // v0: result |
| 5112 | // subject: subject string (callee saved) |
| 5113 | // regexp_data: RegExp data (callee saved) |
| 5114 | // last_match_info_elements: Last match info elements (callee saved) |
| 5115 | |
| 5116 | // Check the result. |
| 5117 | |
| 5118 | Label success; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5119 | __ Branch(&success, eq, |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 5120 | v0, Operand(NativeRegExpMacroAssembler::SUCCESS)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5121 | Label failure; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5122 | __ Branch(&failure, eq, |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 5123 | v0, Operand(NativeRegExpMacroAssembler::FAILURE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5124 | // If not exception it can only be retry. Handle that in the runtime system. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5125 | __ Branch(&runtime, ne, |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 5126 | v0, Operand(NativeRegExpMacroAssembler::EXCEPTION)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5127 | // Result must now be exception. If there is no pending exception already a |
| 5128 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 5129 | // haven't created the exception yet. Handle that in the runtime system. |
| 5130 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5131 | __ li(a1, Operand(isolate->factory()->the_hole_value())); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5132 | __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5133 | isolate))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5134 | __ lw(v0, MemOperand(a2, 0)); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 5135 | __ Branch(&runtime, eq, v0, Operand(a1)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5136 | |
| 5137 | __ sw(a1, MemOperand(a2, 0)); // Clear pending exception. |
| 5138 | |
| 5139 | // Check if the exception is a termination. If so, throw as uncatchable. |
| 5140 | __ LoadRoot(a0, Heap::kTerminationExceptionRootIndex); |
| 5141 | Label termination_exception; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 5142 | __ Branch(&termination_exception, eq, v0, Operand(a0)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5143 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5144 | __ Throw(v0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5145 | |
| 5146 | __ bind(&termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5147 | __ ThrowUncatchable(v0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5148 | |
| 5149 | __ bind(&failure); |
| 5150 | // For failure and exception return null. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5151 | __ li(v0, Operand(isolate->factory()->null_value())); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5152 | __ Addu(sp, sp, Operand(4 * kPointerSize)); |
| 5153 | __ Ret(); |
| 5154 | |
| 5155 | // Process the result from the native regexp code. |
| 5156 | __ bind(&success); |
| 5157 | __ lw(a1, |
| 5158 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 5159 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 5160 | STATIC_ASSERT(kSmiTag == 0); |
| 5161 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 5162 | __ Addu(a1, a1, Operand(2)); // a1 was a smi. |
| 5163 | |
| 5164 | // a1: number of capture registers |
| 5165 | // subject: subject string |
| 5166 | // Store the capture count. |
| 5167 | __ sll(a2, a1, kSmiTagSize + kSmiShiftSize); // To smi. |
| 5168 | __ sw(a2, FieldMemOperand(last_match_info_elements, |
| 5169 | RegExpImpl::kLastCaptureCountOffset)); |
| 5170 | // Store last subject and last input. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5171 | __ sw(subject, |
| 5172 | FieldMemOperand(last_match_info_elements, |
| 5173 | RegExpImpl::kLastSubjectOffset)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5174 | __ mov(a2, subject); |
| 5175 | __ RecordWriteField(last_match_info_elements, |
| 5176 | RegExpImpl::kLastSubjectOffset, |
| 5177 | a2, |
| 5178 | t3, |
| 5179 | kRAHasNotBeenSaved, |
| 5180 | kDontSaveFPRegs); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5181 | __ sw(subject, |
| 5182 | FieldMemOperand(last_match_info_elements, |
| 5183 | RegExpImpl::kLastInputOffset)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5184 | __ RecordWriteField(last_match_info_elements, |
| 5185 | RegExpImpl::kLastInputOffset, |
| 5186 | subject, |
| 5187 | t3, |
| 5188 | kRAHasNotBeenSaved, |
| 5189 | kDontSaveFPRegs); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5190 | |
| 5191 | // Get the static offsets vector filled by the native regexp code. |
| 5192 | ExternalReference address_of_static_offsets_vector = |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5193 | ExternalReference::address_of_static_offsets_vector(isolate); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5194 | __ li(a2, Operand(address_of_static_offsets_vector)); |
| 5195 | |
| 5196 | // a1: number of capture registers |
| 5197 | // a2: offsets vector |
| 5198 | Label next_capture, done; |
| 5199 | // Capture register counter starts from number of capture registers and |
| 5200 | // counts down until wrapping after zero. |
| 5201 | __ Addu(a0, |
| 5202 | last_match_info_elements, |
| 5203 | Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag)); |
| 5204 | __ bind(&next_capture); |
| 5205 | __ Subu(a1, a1, Operand(1)); |
| 5206 | __ Branch(&done, lt, a1, Operand(zero_reg)); |
| 5207 | // Read the value from the static offsets vector buffer. |
| 5208 | __ lw(a3, MemOperand(a2, 0)); |
| 5209 | __ addiu(a2, a2, kPointerSize); |
| 5210 | // Store the smi value in the last match info. |
| 5211 | __ sll(a3, a3, kSmiTagSize); // Convert to Smi. |
| 5212 | __ sw(a3, MemOperand(a0, 0)); |
| 5213 | __ Branch(&next_capture, USE_DELAY_SLOT); |
| 5214 | __ addiu(a0, a0, kPointerSize); // In branch delay slot. |
| 5215 | |
| 5216 | __ bind(&done); |
| 5217 | |
| 5218 | // Return last match info. |
| 5219 | __ lw(v0, MemOperand(sp, kLastMatchInfoOffset)); |
| 5220 | __ Addu(sp, sp, Operand(4 * kPointerSize)); |
| 5221 | __ Ret(); |
| 5222 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5223 | // External string. Short external strings have already been ruled out. |
| 5224 | // a0: scratch |
| 5225 | __ bind(&external_string); |
| 5226 | __ lw(a0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 5227 | __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset)); |
| 5228 | if (FLAG_debug_code) { |
| 5229 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 5230 | // Sequential strings have already been ruled out. |
| 5231 | __ And(at, a0, Operand(kIsIndirectStringMask)); |
| 5232 | __ Assert(eq, |
| 5233 | "external string expected, but not found", |
| 5234 | at, |
| 5235 | Operand(zero_reg)); |
| 5236 | } |
| 5237 | __ lw(subject, |
| 5238 | FieldMemOperand(subject, ExternalString::kResourceDataOffset)); |
| 5239 | // Move the pointer so that offset-wise, it looks like a sequential string. |
| 5240 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); |
| 5241 | __ Subu(subject, |
| 5242 | subject, |
| 5243 | SeqTwoByteString::kHeaderSize - kHeapObjectTag); |
| 5244 | __ jmp(&seq_string); |
| 5245 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5246 | // Do the runtime call to execute the regexp. |
| 5247 | __ bind(&runtime); |
| 5248 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 5249 | #endif // V8_INTERPRETED_REGEXP |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5250 | } |
| 5251 | |
| 5252 | |
| 5253 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5254 | const int kMaxInlineLength = 100; |
| 5255 | Label slowcase; |
| 5256 | Label done; |
| 5257 | __ lw(a1, MemOperand(sp, kPointerSize * 2)); |
| 5258 | STATIC_ASSERT(kSmiTag == 0); |
| 5259 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5260 | __ JumpIfNotSmi(a1, &slowcase); |
| 5261 | __ Branch(&slowcase, hi, a1, Operand(Smi::FromInt(kMaxInlineLength))); |
| 5262 | // Smi-tagging is equivalent to multiplying by 2. |
| 5263 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 5264 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 5265 | // Elements: [Map][Length][..elements..] |
| 5266 | // Size of JSArray with two in-object properties and the header of a |
| 5267 | // FixedArray. |
| 5268 | int objects_size = |
| 5269 | (JSRegExpResult::kSize + FixedArray::kHeaderSize) / kPointerSize; |
| 5270 | __ srl(t1, a1, kSmiTagSize + kSmiShiftSize); |
| 5271 | __ Addu(a2, t1, Operand(objects_size)); |
| 5272 | __ AllocateInNewSpace( |
| 5273 | a2, // In: Size, in words. |
| 5274 | v0, // Out: Start of allocation (tagged). |
| 5275 | a3, // Scratch register. |
| 5276 | t0, // Scratch register. |
| 5277 | &slowcase, |
| 5278 | static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS)); |
| 5279 | // v0: Start of allocated area, object-tagged. |
| 5280 | // a1: Number of elements in array, as smi. |
| 5281 | // t1: Number of elements, untagged. |
| 5282 | |
| 5283 | // Set JSArray map to global.regexp_result_map(). |
| 5284 | // Set empty properties FixedArray. |
| 5285 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 5286 | // Interleave operations for better latency. |
| 5287 | __ lw(a2, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 5288 | __ Addu(a3, v0, Operand(JSRegExpResult::kSize)); |
| 5289 | __ li(t0, Operand(masm->isolate()->factory()->empty_fixed_array())); |
| 5290 | __ lw(a2, FieldMemOperand(a2, GlobalObject::kGlobalContextOffset)); |
| 5291 | __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset)); |
| 5292 | __ lw(a2, ContextOperand(a2, Context::REGEXP_RESULT_MAP_INDEX)); |
| 5293 | __ sw(t0, FieldMemOperand(v0, JSObject::kPropertiesOffset)); |
| 5294 | __ sw(a2, FieldMemOperand(v0, HeapObject::kMapOffset)); |
| 5295 | |
| 5296 | // Set input, index and length fields from arguments. |
| 5297 | __ lw(a1, MemOperand(sp, kPointerSize * 0)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5298 | __ lw(a2, MemOperand(sp, kPointerSize * 1)); |
| 5299 | __ lw(t2, MemOperand(sp, kPointerSize * 2)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5300 | __ sw(a1, FieldMemOperand(v0, JSRegExpResult::kInputOffset)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5301 | __ sw(a2, FieldMemOperand(v0, JSRegExpResult::kIndexOffset)); |
| 5302 | __ sw(t2, FieldMemOperand(v0, JSArray::kLengthOffset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5303 | |
| 5304 | // Fill out the elements FixedArray. |
| 5305 | // v0: JSArray, tagged. |
| 5306 | // a3: FixedArray, tagged. |
| 5307 | // t1: Number of elements in array, untagged. |
| 5308 | |
| 5309 | // Set map. |
| 5310 | __ li(a2, Operand(masm->isolate()->factory()->fixed_array_map())); |
| 5311 | __ sw(a2, FieldMemOperand(a3, HeapObject::kMapOffset)); |
| 5312 | // Set FixedArray length. |
| 5313 | __ sll(t2, t1, kSmiTagSize); |
| 5314 | __ sw(t2, FieldMemOperand(a3, FixedArray::kLengthOffset)); |
| 5315 | // Fill contents of fixed-array with the-hole. |
| 5316 | __ li(a2, Operand(masm->isolate()->factory()->the_hole_value())); |
| 5317 | __ Addu(a3, a3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5318 | // Fill fixed array elements with hole. |
| 5319 | // v0: JSArray, tagged. |
| 5320 | // a2: the hole. |
| 5321 | // a3: Start of elements in FixedArray. |
| 5322 | // t1: Number of elements to fill. |
| 5323 | Label loop; |
| 5324 | __ sll(t1, t1, kPointerSizeLog2); // Convert num elements to num bytes. |
| 5325 | __ addu(t1, t1, a3); // Point past last element to store. |
| 5326 | __ bind(&loop); |
| 5327 | __ Branch(&done, ge, a3, Operand(t1)); // Break when a3 past end of elem. |
| 5328 | __ sw(a2, MemOperand(a3)); |
| 5329 | __ Branch(&loop, USE_DELAY_SLOT); |
| 5330 | __ addiu(a3, a3, kPointerSize); // In branch delay slot. |
| 5331 | |
| 5332 | __ bind(&done); |
| 5333 | __ Addu(sp, sp, Operand(3 * kPointerSize)); |
| 5334 | __ Ret(); |
| 5335 | |
| 5336 | __ bind(&slowcase); |
| 5337 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5338 | } |
| 5339 | |
| 5340 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5341 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 5342 | // Cache the called function in a global property cell. Cache states |
| 5343 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 5344 | // megamorphic. |
| 5345 | // a1 : the function to call |
| 5346 | // a2 : cache cell for call target |
| 5347 | Label done; |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5348 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5349 | ASSERT_EQ(*TypeFeedbackCells::MegamorphicSentinel(masm->isolate()), |
| 5350 | masm->isolate()->heap()->undefined_value()); |
| 5351 | ASSERT_EQ(*TypeFeedbackCells::UninitializedSentinel(masm->isolate()), |
| 5352 | masm->isolate()->heap()->the_hole_value()); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5353 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5354 | // Load the cache state into a3. |
| 5355 | __ lw(a3, FieldMemOperand(a2, JSGlobalPropertyCell::kValueOffset)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5356 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5357 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 5358 | // function without changing the state. |
| 5359 | __ Branch(&done, eq, a3, Operand(a1)); |
| 5360 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 5361 | __ Branch(&done, eq, a3, Operand(at)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5362 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5363 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 5364 | // megamorphic. |
| 5365 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5366 | |
| 5367 | __ Branch(USE_DELAY_SLOT, &done, eq, a3, Operand(at)); |
| 5368 | // An uninitialized cache is patched with the function. |
| 5369 | // Store a1 in the delay slot. This may or may not get overwritten depending |
| 5370 | // on the result of the comparison. |
| 5371 | __ sw(a1, FieldMemOperand(a2, JSGlobalPropertyCell::kValueOffset)); |
| 5372 | // No need for a write barrier here - cells are rescanned. |
| 5373 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5374 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 5375 | // write-barrier is needed. |
| 5376 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 5377 | __ sw(at, FieldMemOperand(a2, JSGlobalPropertyCell::kValueOffset)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5378 | |
| 5379 | __ bind(&done); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5383 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5384 | // a1 : the function to call |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5385 | // a2 : cache cell for call target |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5386 | Label slow, non_function; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5387 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5388 | // The receiver might implicitly be the global object. This is |
| 5389 | // indicated by passing the hole as the receiver to the call |
| 5390 | // function stub. |
| 5391 | if (ReceiverMightBeImplicit()) { |
| 5392 | Label call; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5393 | // Get the receiver from the stack. |
| 5394 | // function, receiver [, arguments] |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5395 | __ lw(t0, MemOperand(sp, argc_ * kPointerSize)); |
| 5396 | // Call as function is indicated with the hole. |
| 5397 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 5398 | __ Branch(&call, ne, t0, Operand(at)); |
| 5399 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5400 | __ lw(a2, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 5401 | __ lw(a2, FieldMemOperand(a2, GlobalObject::kGlobalReceiverOffset)); |
| 5402 | __ sw(a2, MemOperand(sp, argc_ * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5403 | __ bind(&call); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5404 | } |
| 5405 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5406 | // Check that the function is really a JavaScript function. |
| 5407 | // a1: pushed function (to be verified) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5408 | __ JumpIfSmi(a1, &non_function); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5409 | // Get the map of the function object. |
| 5410 | __ GetObjectType(a1, a2, a2); |
| 5411 | __ Branch(&slow, ne, a2, Operand(JS_FUNCTION_TYPE)); |
| 5412 | |
| 5413 | // Fast-case: Invoke the function now. |
| 5414 | // a1: pushed function |
| 5415 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5416 | |
| 5417 | if (ReceiverMightBeImplicit()) { |
| 5418 | Label call_as_function; |
| 5419 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 5420 | __ Branch(&call_as_function, eq, t0, Operand(at)); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 5421 | __ InvokeFunction(a1, |
| 5422 | actual, |
| 5423 | JUMP_FUNCTION, |
| 5424 | NullCallWrapper(), |
| 5425 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5426 | __ bind(&call_as_function); |
| 5427 | } |
| 5428 | __ InvokeFunction(a1, |
| 5429 | actual, |
| 5430 | JUMP_FUNCTION, |
| 5431 | NullCallWrapper(), |
| 5432 | CALL_AS_FUNCTION); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5433 | |
| 5434 | // Slow-case: Non-function called. |
| 5435 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5436 | // Check for function proxy. |
| 5437 | __ Branch(&non_function, ne, a2, Operand(JS_FUNCTION_PROXY_TYPE)); |
| 5438 | __ push(a1); // Put proxy as additional argument. |
| 5439 | __ li(a0, Operand(argc_ + 1, RelocInfo::NONE)); |
| 5440 | __ li(a2, Operand(0, RelocInfo::NONE)); |
| 5441 | __ GetBuiltinEntry(a3, Builtins::CALL_FUNCTION_PROXY); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5442 | __ SetCallKind(t1, CALL_AS_METHOD); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5443 | { |
| 5444 | Handle<Code> adaptor = |
| 5445 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 5446 | __ Jump(adaptor, RelocInfo::CODE_TARGET); |
| 5447 | } |
| 5448 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5449 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 5450 | // of the original receiver from the call site). |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5451 | __ bind(&non_function); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5452 | __ sw(a1, MemOperand(sp, argc_ * kPointerSize)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5453 | __ li(a0, Operand(argc_)); // Set up the number of arguments. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5454 | __ mov(a2, zero_reg); |
| 5455 | __ GetBuiltinEntry(a3, Builtins::CALL_NON_FUNCTION); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 5456 | __ SetCallKind(t1, CALL_AS_METHOD); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5457 | __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 5458 | RelocInfo::CODE_TARGET); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5459 | } |
| 5460 | |
| 5461 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5462 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 5463 | // a0 : number of arguments |
| 5464 | // a1 : the function to call |
| 5465 | // a2 : cache cell for call target |
| 5466 | Label slow, non_function_call; |
| 5467 | |
| 5468 | // Check that the function is not a smi. |
| 5469 | __ JumpIfSmi(a1, &non_function_call); |
| 5470 | // Check that the function is a JSFunction. |
| 5471 | __ GetObjectType(a1, a3, a3); |
| 5472 | __ Branch(&slow, ne, a3, Operand(JS_FUNCTION_TYPE)); |
| 5473 | |
| 5474 | if (RecordCallTarget()) { |
| 5475 | GenerateRecordCallTarget(masm); |
| 5476 | } |
| 5477 | |
| 5478 | // Jump to the function-specific construct stub. |
| 5479 | __ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 5480 | __ lw(a2, FieldMemOperand(a2, SharedFunctionInfo::kConstructStubOffset)); |
| 5481 | __ Addu(at, a2, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 5482 | __ Jump(at); |
| 5483 | |
| 5484 | // a0: number of arguments |
| 5485 | // a1: called object |
| 5486 | // a3: object type |
| 5487 | Label do_call; |
| 5488 | __ bind(&slow); |
| 5489 | __ Branch(&non_function_call, ne, a3, Operand(JS_FUNCTION_PROXY_TYPE)); |
| 5490 | __ GetBuiltinEntry(a3, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 5491 | __ jmp(&do_call); |
| 5492 | |
| 5493 | __ bind(&non_function_call); |
| 5494 | __ GetBuiltinEntry(a3, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 5495 | __ bind(&do_call); |
| 5496 | // Set expected number of arguments to zero (not changing r0). |
| 5497 | __ li(a2, Operand(0, RelocInfo::NONE)); |
| 5498 | __ SetCallKind(t1, CALL_AS_METHOD); |
| 5499 | __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 5500 | RelocInfo::CODE_TARGET); |
| 5501 | } |
| 5502 | |
| 5503 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5504 | // Unfortunately you have to run without snapshots to see most of these |
| 5505 | // 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] | 5506 | void CompareStub::PrintName(StringStream* stream) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5507 | ASSERT((lhs_.is(a0) && rhs_.is(a1)) || |
| 5508 | (lhs_.is(a1) && rhs_.is(a0))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5509 | const char* cc_name; |
| 5510 | switch (cc_) { |
| 5511 | case lt: cc_name = "LT"; break; |
| 5512 | case gt: cc_name = "GT"; break; |
| 5513 | case le: cc_name = "LE"; break; |
| 5514 | case ge: cc_name = "GE"; break; |
| 5515 | case eq: cc_name = "EQ"; break; |
| 5516 | case ne: cc_name = "NE"; break; |
| 5517 | default: cc_name = "UnknownCondition"; break; |
| 5518 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 5519 | bool is_equality = cc_ == eq || cc_ == ne; |
| 5520 | stream->Add("CompareStub_%s", cc_name); |
| 5521 | stream->Add(lhs_.is(a0) ? "_a0" : "_a1"); |
| 5522 | stream->Add(rhs_.is(a0) ? "_a0" : "_a1"); |
| 5523 | if (strict_ && is_equality) stream->Add("_STRICT"); |
| 5524 | if (never_nan_nan_ && is_equality) stream->Add("_NO_NAN"); |
| 5525 | if (!include_number_compare_) stream->Add("_NO_NUMBER"); |
| 5526 | if (!include_smi_compare_) stream->Add("_NO_SMI"); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5527 | } |
| 5528 | |
| 5529 | |
| 5530 | int CompareStub::MinorKey() { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5531 | // Encode the two parameters in a unique 16 bit value. |
| 5532 | ASSERT(static_cast<unsigned>(cc_) < (1 << 14)); |
| 5533 | ASSERT((lhs_.is(a0) && rhs_.is(a1)) || |
| 5534 | (lhs_.is(a1) && rhs_.is(a0))); |
| 5535 | return ConditionField::encode(static_cast<unsigned>(cc_)) |
| 5536 | | RegisterField::encode(lhs_.is(a0)) |
| 5537 | | StrictField::encode(strict_) |
| 5538 | | NeverNanNanField::encode(cc_ == eq ? never_nan_nan_ : false) |
| 5539 | | IncludeSmiCompareField::encode(include_smi_compare_); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5540 | } |
| 5541 | |
| 5542 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5543 | // StringCharCodeAtGenerator. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5544 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5545 | Label flat_string; |
| 5546 | Label ascii_string; |
| 5547 | Label got_char_code; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5548 | Label sliced_string; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5549 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5550 | ASSERT(!t0.is(index_)); |
| 5551 | ASSERT(!t0.is(result_)); |
| 5552 | ASSERT(!t0.is(object_)); |
| 5553 | |
| 5554 | // If the receiver is a smi trigger the non-string case. |
| 5555 | __ JumpIfSmi(object_, receiver_not_string_); |
| 5556 | |
| 5557 | // Fetch the instance type of the receiver into result register. |
| 5558 | __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 5559 | __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 5560 | // If the receiver is not a string trigger the non-string case. |
| 5561 | __ And(t0, result_, Operand(kIsNotStringMask)); |
| 5562 | __ Branch(receiver_not_string_, ne, t0, Operand(zero_reg)); |
| 5563 | |
| 5564 | // If the index is non-smi trigger the non-smi case. |
| 5565 | __ JumpIfNotSmi(index_, &index_not_smi_); |
| 5566 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5567 | __ bind(&got_smi_index_); |
| 5568 | |
| 5569 | // Check for index out of range. |
| 5570 | __ lw(t0, FieldMemOperand(object_, String::kLengthOffset)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5571 | __ Branch(index_out_of_range_, ls, t0, Operand(index_)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5572 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5573 | __ sra(index_, index_, kSmiTagSize); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5574 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5575 | StringCharLoadGenerator::Generate(masm, |
| 5576 | object_, |
| 5577 | index_, |
| 5578 | result_, |
| 5579 | &call_runtime_); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5580 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5581 | __ sll(result_, result_, kSmiTagSize); |
| 5582 | __ bind(&exit_); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5583 | } |
| 5584 | |
| 5585 | |
| 5586 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5587 | MacroAssembler* masm, |
| 5588 | const RuntimeCallHelper& call_helper) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5589 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5590 | |
| 5591 | // Index is not a smi. |
| 5592 | __ bind(&index_not_smi_); |
| 5593 | // If index is a heap number, try converting it to an integer. |
| 5594 | __ CheckMap(index_, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5595 | result_, |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5596 | Heap::kHeapNumberMapRootIndex, |
| 5597 | index_not_number_, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5598 | DONT_DO_SMI_CHECK); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5599 | call_helper.BeforeCall(masm); |
| 5600 | // Consumed by runtime conversion function: |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5601 | __ Push(object_, index_); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5602 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5603 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5604 | } else { |
| 5605 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5606 | // NumberToSmi discards numbers that are not exact integers. |
| 5607 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5608 | } |
| 5609 | |
| 5610 | // Save the conversion result before the pop instructions below |
| 5611 | // have a chance to overwrite it. |
| 5612 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5613 | __ Move(index_, v0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5614 | __ pop(object_); |
| 5615 | // Reload the instance type. |
| 5616 | __ lw(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 5617 | __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 5618 | call_helper.AfterCall(masm); |
| 5619 | // 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] | 5620 | __ JumpIfNotSmi(index_, index_out_of_range_); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5621 | // Otherwise, return to the fast path. |
| 5622 | __ Branch(&got_smi_index_); |
| 5623 | |
| 5624 | // Call runtime. We get here when the receiver is a string and the |
| 5625 | // index is a number, but the code of getting the actual character |
| 5626 | // is too complex (e.g., when the string needs to be flattened). |
| 5627 | __ bind(&call_runtime_); |
| 5628 | call_helper.BeforeCall(masm); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5629 | __ sll(index_, index_, kSmiTagSize); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5630 | __ Push(object_, index_); |
| 5631 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5632 | |
| 5633 | __ Move(result_, v0); |
| 5634 | |
| 5635 | call_helper.AfterCall(masm); |
| 5636 | __ jmp(&exit_); |
| 5637 | |
| 5638 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5639 | } |
| 5640 | |
| 5641 | |
| 5642 | // ------------------------------------------------------------------------- |
| 5643 | // StringCharFromCodeGenerator |
| 5644 | |
| 5645 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5646 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5647 | |
| 5648 | ASSERT(!t0.is(result_)); |
| 5649 | ASSERT(!t0.is(code_)); |
| 5650 | |
| 5651 | STATIC_ASSERT(kSmiTag == 0); |
| 5652 | STATIC_ASSERT(kSmiShiftSize == 0); |
| 5653 | ASSERT(IsPowerOf2(String::kMaxAsciiCharCode + 1)); |
| 5654 | __ And(t0, |
| 5655 | code_, |
| 5656 | Operand(kSmiTagMask | |
| 5657 | ((~String::kMaxAsciiCharCode) << kSmiTagSize))); |
| 5658 | __ Branch(&slow_case_, ne, t0, Operand(zero_reg)); |
| 5659 | |
| 5660 | __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex); |
| 5661 | // At this point code register contains smi tagged ASCII char code. |
| 5662 | STATIC_ASSERT(kSmiTag == 0); |
| 5663 | __ sll(t0, code_, kPointerSizeLog2 - kSmiTagSize); |
| 5664 | __ Addu(result_, result_, t0); |
| 5665 | __ lw(result_, FieldMemOperand(result_, FixedArray::kHeaderSize)); |
| 5666 | __ LoadRoot(t0, Heap::kUndefinedValueRootIndex); |
| 5667 | __ Branch(&slow_case_, eq, result_, Operand(t0)); |
| 5668 | __ bind(&exit_); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | |
| 5672 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5673 | MacroAssembler* masm, |
| 5674 | const RuntimeCallHelper& call_helper) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5675 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5676 | |
| 5677 | __ bind(&slow_case_); |
| 5678 | call_helper.BeforeCall(masm); |
| 5679 | __ push(code_); |
| 5680 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5681 | __ Move(result_, v0); |
| 5682 | |
| 5683 | call_helper.AfterCall(masm); |
| 5684 | __ Branch(&exit_); |
| 5685 | |
| 5686 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5687 | } |
| 5688 | |
| 5689 | |
| 5690 | // ------------------------------------------------------------------------- |
| 5691 | // StringCharAtGenerator |
| 5692 | |
| 5693 | void StringCharAtGenerator::GenerateFast(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5694 | char_code_at_generator_.GenerateFast(masm); |
| 5695 | char_from_code_generator_.GenerateFast(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | |
| 5699 | void StringCharAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5700 | MacroAssembler* masm, |
| 5701 | const RuntimeCallHelper& call_helper) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5702 | char_code_at_generator_.GenerateSlow(masm, call_helper); |
| 5703 | char_from_code_generator_.GenerateSlow(masm, call_helper); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5704 | } |
| 5705 | |
| 5706 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5707 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5708 | Register dest, |
| 5709 | Register src, |
| 5710 | Register count, |
| 5711 | Register scratch, |
| 5712 | bool ascii) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5713 | Label loop; |
| 5714 | Label done; |
| 5715 | // This loop just copies one character at a time, as it is only used for |
| 5716 | // very short strings. |
| 5717 | if (!ascii) { |
| 5718 | __ addu(count, count, count); |
| 5719 | } |
| 5720 | __ Branch(&done, eq, count, Operand(zero_reg)); |
| 5721 | __ addu(count, dest, count); // Count now points to the last dest byte. |
| 5722 | |
| 5723 | __ bind(&loop); |
| 5724 | __ lbu(scratch, MemOperand(src)); |
| 5725 | __ addiu(src, src, 1); |
| 5726 | __ sb(scratch, MemOperand(dest)); |
| 5727 | __ addiu(dest, dest, 1); |
| 5728 | __ Branch(&loop, lt, dest, Operand(count)); |
| 5729 | |
| 5730 | __ bind(&done); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5731 | } |
| 5732 | |
| 5733 | |
| 5734 | enum CopyCharactersFlags { |
| 5735 | COPY_ASCII = 1, |
| 5736 | DEST_ALWAYS_ALIGNED = 2 |
| 5737 | }; |
| 5738 | |
| 5739 | |
| 5740 | void StringHelper::GenerateCopyCharactersLong(MacroAssembler* masm, |
| 5741 | Register dest, |
| 5742 | Register src, |
| 5743 | Register count, |
| 5744 | Register scratch1, |
| 5745 | Register scratch2, |
| 5746 | Register scratch3, |
| 5747 | Register scratch4, |
| 5748 | Register scratch5, |
| 5749 | int flags) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5750 | bool ascii = (flags & COPY_ASCII) != 0; |
| 5751 | bool dest_always_aligned = (flags & DEST_ALWAYS_ALIGNED) != 0; |
| 5752 | |
| 5753 | if (dest_always_aligned && FLAG_debug_code) { |
| 5754 | // Check that destination is actually word aligned if the flag says |
| 5755 | // that it is. |
| 5756 | __ And(scratch4, dest, Operand(kPointerAlignmentMask)); |
| 5757 | __ Check(eq, |
| 5758 | "Destination of copy not aligned.", |
| 5759 | scratch4, |
| 5760 | Operand(zero_reg)); |
| 5761 | } |
| 5762 | |
| 5763 | const int kReadAlignment = 4; |
| 5764 | const int kReadAlignmentMask = kReadAlignment - 1; |
| 5765 | // Ensure that reading an entire aligned word containing the last character |
| 5766 | // of a string will not read outside the allocated area (because we pad up |
| 5767 | // to kObjectAlignment). |
| 5768 | STATIC_ASSERT(kObjectAlignment >= kReadAlignment); |
| 5769 | // Assumes word reads and writes are little endian. |
| 5770 | // Nothing to do for zero characters. |
| 5771 | Label done; |
| 5772 | |
| 5773 | if (!ascii) { |
| 5774 | __ addu(count, count, count); |
| 5775 | } |
| 5776 | __ Branch(&done, eq, count, Operand(zero_reg)); |
| 5777 | |
| 5778 | Label byte_loop; |
| 5779 | // Must copy at least eight bytes, otherwise just do it one byte at a time. |
| 5780 | __ Subu(scratch1, count, Operand(8)); |
| 5781 | __ Addu(count, dest, Operand(count)); |
| 5782 | Register limit = count; // Read until src equals this. |
| 5783 | __ Branch(&byte_loop, lt, scratch1, Operand(zero_reg)); |
| 5784 | |
| 5785 | if (!dest_always_aligned) { |
| 5786 | // Align dest by byte copying. Copies between zero and three bytes. |
| 5787 | __ And(scratch4, dest, Operand(kReadAlignmentMask)); |
| 5788 | Label dest_aligned; |
| 5789 | __ Branch(&dest_aligned, eq, scratch4, Operand(zero_reg)); |
| 5790 | Label aligned_loop; |
| 5791 | __ bind(&aligned_loop); |
| 5792 | __ lbu(scratch1, MemOperand(src)); |
| 5793 | __ addiu(src, src, 1); |
| 5794 | __ sb(scratch1, MemOperand(dest)); |
| 5795 | __ addiu(dest, dest, 1); |
| 5796 | __ addiu(scratch4, scratch4, 1); |
| 5797 | __ Branch(&aligned_loop, le, scratch4, Operand(kReadAlignmentMask)); |
| 5798 | __ bind(&dest_aligned); |
| 5799 | } |
| 5800 | |
| 5801 | Label simple_loop; |
| 5802 | |
| 5803 | __ And(scratch4, src, Operand(kReadAlignmentMask)); |
| 5804 | __ Branch(&simple_loop, eq, scratch4, Operand(zero_reg)); |
| 5805 | |
| 5806 | // Loop for src/dst that are not aligned the same way. |
| 5807 | // This loop uses lwl and lwr instructions. These instructions |
| 5808 | // depend on the endianness, and the implementation assumes little-endian. |
| 5809 | { |
| 5810 | Label loop; |
| 5811 | __ bind(&loop); |
| 5812 | __ lwr(scratch1, MemOperand(src)); |
| 5813 | __ Addu(src, src, Operand(kReadAlignment)); |
| 5814 | __ lwl(scratch1, MemOperand(src, -1)); |
| 5815 | __ sw(scratch1, MemOperand(dest)); |
| 5816 | __ Addu(dest, dest, Operand(kReadAlignment)); |
| 5817 | __ Subu(scratch2, limit, dest); |
| 5818 | __ Branch(&loop, ge, scratch2, Operand(kReadAlignment)); |
| 5819 | } |
| 5820 | |
| 5821 | __ Branch(&byte_loop); |
| 5822 | |
| 5823 | // Simple loop. |
| 5824 | // Copy words from src to dest, until less than four bytes left. |
| 5825 | // Both src and dest are word aligned. |
| 5826 | __ bind(&simple_loop); |
| 5827 | { |
| 5828 | Label loop; |
| 5829 | __ bind(&loop); |
| 5830 | __ lw(scratch1, MemOperand(src)); |
| 5831 | __ Addu(src, src, Operand(kReadAlignment)); |
| 5832 | __ sw(scratch1, MemOperand(dest)); |
| 5833 | __ Addu(dest, dest, Operand(kReadAlignment)); |
| 5834 | __ Subu(scratch2, limit, dest); |
| 5835 | __ Branch(&loop, ge, scratch2, Operand(kReadAlignment)); |
| 5836 | } |
| 5837 | |
| 5838 | // Copy bytes from src to dest until dest hits limit. |
| 5839 | __ bind(&byte_loop); |
| 5840 | // Test if dest has already reached the limit. |
| 5841 | __ Branch(&done, ge, dest, Operand(limit)); |
| 5842 | __ lbu(scratch1, MemOperand(src)); |
| 5843 | __ addiu(src, src, 1); |
| 5844 | __ sb(scratch1, MemOperand(dest)); |
| 5845 | __ addiu(dest, dest, 1); |
| 5846 | __ Branch(&byte_loop); |
| 5847 | |
| 5848 | __ bind(&done); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5849 | } |
| 5850 | |
| 5851 | |
| 5852 | void StringHelper::GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 5853 | Register c1, |
| 5854 | Register c2, |
| 5855 | Register scratch1, |
| 5856 | Register scratch2, |
| 5857 | Register scratch3, |
| 5858 | Register scratch4, |
| 5859 | Register scratch5, |
| 5860 | Label* not_found) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5861 | // Register scratch3 is the general scratch register in this function. |
| 5862 | Register scratch = scratch3; |
| 5863 | |
| 5864 | // Make sure that both characters are not digits as such strings has a |
| 5865 | // different hash algorithm. Don't try to look for these in the symbol table. |
| 5866 | Label not_array_index; |
| 5867 | __ Subu(scratch, c1, Operand(static_cast<int>('0'))); |
| 5868 | __ Branch(¬_array_index, |
| 5869 | Ugreater, |
| 5870 | scratch, |
| 5871 | Operand(static_cast<int>('9' - '0'))); |
| 5872 | __ Subu(scratch, c2, Operand(static_cast<int>('0'))); |
| 5873 | |
| 5874 | // If check failed combine both characters into single halfword. |
| 5875 | // This is required by the contract of the method: code at the |
| 5876 | // not_found branch expects this combination in c1 register. |
| 5877 | Label tmp; |
| 5878 | __ sll(scratch1, c2, kBitsPerByte); |
| 5879 | __ Branch(&tmp, Ugreater, scratch, Operand(static_cast<int>('9' - '0'))); |
| 5880 | __ Or(c1, c1, scratch1); |
| 5881 | __ bind(&tmp); |
| 5882 | __ Branch(not_found, |
| 5883 | Uless_equal, |
| 5884 | scratch, |
| 5885 | Operand(static_cast<int>('9' - '0'))); |
| 5886 | |
| 5887 | __ bind(¬_array_index); |
| 5888 | // Calculate the two character string hash. |
| 5889 | Register hash = scratch1; |
| 5890 | StringHelper::GenerateHashInit(masm, hash, c1); |
| 5891 | StringHelper::GenerateHashAddCharacter(masm, hash, c2); |
| 5892 | StringHelper::GenerateHashGetHash(masm, hash); |
| 5893 | |
| 5894 | // Collect the two characters in a register. |
| 5895 | Register chars = c1; |
| 5896 | __ sll(scratch, c2, kBitsPerByte); |
| 5897 | __ Or(chars, chars, scratch); |
| 5898 | |
| 5899 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5900 | // hash: hash of two character string. |
| 5901 | |
| 5902 | // Load symbol table. |
| 5903 | // Load address of first element of the symbol table. |
| 5904 | Register symbol_table = c2; |
| 5905 | __ LoadRoot(symbol_table, Heap::kSymbolTableRootIndex); |
| 5906 | |
| 5907 | Register undefined = scratch4; |
| 5908 | __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex); |
| 5909 | |
| 5910 | // Calculate capacity mask from the symbol table capacity. |
| 5911 | Register mask = scratch2; |
| 5912 | __ lw(mask, FieldMemOperand(symbol_table, SymbolTable::kCapacityOffset)); |
| 5913 | __ sra(mask, mask, 1); |
| 5914 | __ Addu(mask, mask, -1); |
| 5915 | |
| 5916 | // Calculate untagged address of the first element of the symbol table. |
| 5917 | Register first_symbol_table_element = symbol_table; |
| 5918 | __ Addu(first_symbol_table_element, symbol_table, |
| 5919 | Operand(SymbolTable::kElementsStartOffset - kHeapObjectTag)); |
| 5920 | |
| 5921 | // Registers. |
| 5922 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5923 | // hash: hash of two character string |
| 5924 | // mask: capacity mask |
| 5925 | // first_symbol_table_element: address of the first element of |
| 5926 | // the symbol table |
| 5927 | // undefined: the undefined object |
| 5928 | // scratch: - |
| 5929 | |
| 5930 | // Perform a number of probes in the symbol table. |
| 5931 | static const int kProbes = 4; |
| 5932 | Label found_in_symbol_table; |
| 5933 | Label next_probe[kProbes]; |
| 5934 | Register candidate = scratch5; // Scratch register contains candidate. |
| 5935 | for (int i = 0; i < kProbes; i++) { |
| 5936 | // Calculate entry in symbol table. |
| 5937 | if (i > 0) { |
| 5938 | __ Addu(candidate, hash, Operand(SymbolTable::GetProbeOffset(i))); |
| 5939 | } else { |
| 5940 | __ mov(candidate, hash); |
| 5941 | } |
| 5942 | |
| 5943 | __ And(candidate, candidate, Operand(mask)); |
| 5944 | |
| 5945 | // Load the entry from the symble table. |
| 5946 | STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
| 5947 | __ sll(scratch, candidate, kPointerSizeLog2); |
| 5948 | __ Addu(scratch, scratch, first_symbol_table_element); |
| 5949 | __ lw(candidate, MemOperand(scratch)); |
| 5950 | |
| 5951 | // If entry is undefined no string with this hash can be found. |
| 5952 | Label is_string; |
| 5953 | __ GetObjectType(candidate, scratch, scratch); |
| 5954 | __ Branch(&is_string, ne, scratch, Operand(ODDBALL_TYPE)); |
| 5955 | |
| 5956 | __ Branch(not_found, eq, undefined, Operand(candidate)); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5957 | // Must be the hole (deleted entry). |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5958 | if (FLAG_debug_code) { |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5959 | __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); |
| 5960 | __ Assert(eq, "oddball in symbol table is not undefined or the hole", |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5961 | scratch, Operand(candidate)); |
| 5962 | } |
| 5963 | __ jmp(&next_probe[i]); |
| 5964 | |
| 5965 | __ bind(&is_string); |
| 5966 | |
| 5967 | // Check that the candidate is a non-external ASCII string. The instance |
| 5968 | // type is still in the scratch register from the CompareObjectType |
| 5969 | // operation. |
| 5970 | __ JumpIfInstanceTypeIsNotSequentialAscii(scratch, scratch, &next_probe[i]); |
| 5971 | |
| 5972 | // If length is not 2 the string is not a candidate. |
| 5973 | __ lw(scratch, FieldMemOperand(candidate, String::kLengthOffset)); |
| 5974 | __ Branch(&next_probe[i], ne, scratch, Operand(Smi::FromInt(2))); |
| 5975 | |
| 5976 | // Check if the two characters match. |
| 5977 | // Assumes that word load is little endian. |
| 5978 | __ lhu(scratch, FieldMemOperand(candidate, SeqAsciiString::kHeaderSize)); |
| 5979 | __ Branch(&found_in_symbol_table, eq, chars, Operand(scratch)); |
| 5980 | __ bind(&next_probe[i]); |
| 5981 | } |
| 5982 | |
| 5983 | // No matching 2 character string found by probing. |
| 5984 | __ jmp(not_found); |
| 5985 | |
| 5986 | // Scratch register contains result when we fall through to here. |
| 5987 | Register result = candidate; |
| 5988 | __ bind(&found_in_symbol_table); |
| 5989 | __ mov(v0, result); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5990 | } |
| 5991 | |
| 5992 | |
| 5993 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5994 | Register hash, |
| 5995 | Register character) { |
| 5996 | // hash = seed + character + ((seed + character) << 10); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5997 | __ LoadRoot(hash, Heap::kHashSeedRootIndex); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5998 | // Untag smi seed and add the character. |
| 5999 | __ SmiUntag(hash); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6000 | __ addu(hash, hash, character); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6001 | __ sll(at, hash, 10); |
| 6002 | __ addu(hash, hash, at); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6003 | // hash ^= hash >> 6; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6004 | __ srl(at, hash, 6); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6005 | __ xor_(hash, hash, at); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6006 | } |
| 6007 | |
| 6008 | |
| 6009 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6010 | Register hash, |
| 6011 | Register character) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6012 | // hash += character; |
| 6013 | __ addu(hash, hash, character); |
| 6014 | // hash += hash << 10; |
| 6015 | __ sll(at, hash, 10); |
| 6016 | __ addu(hash, hash, at); |
| 6017 | // hash ^= hash >> 6; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6018 | __ srl(at, hash, 6); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6019 | __ xor_(hash, hash, at); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | |
| 6023 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6024 | Register hash) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6025 | // hash += hash << 3; |
| 6026 | __ sll(at, hash, 3); |
| 6027 | __ addu(hash, hash, at); |
| 6028 | // hash ^= hash >> 11; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6029 | __ srl(at, hash, 11); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6030 | __ xor_(hash, hash, at); |
| 6031 | // hash += hash << 15; |
| 6032 | __ sll(at, hash, 15); |
| 6033 | __ addu(hash, hash, at); |
| 6034 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6035 | __ li(at, Operand(String::kHashBitMask)); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6036 | __ and_(hash, hash, at); |
| 6037 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6038 | // if (hash == 0) hash = 27; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6039 | __ ori(at, zero_reg, StringHasher::kZeroHash); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6040 | __ movz(hash, at, hash); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6041 | } |
| 6042 | |
| 6043 | |
| 6044 | void SubStringStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6045 | Label runtime; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6046 | // Stack frame on entry. |
| 6047 | // ra: return address |
| 6048 | // sp[0]: to |
| 6049 | // sp[4]: from |
| 6050 | // sp[8]: string |
| 6051 | |
| 6052 | // This stub is called from the native-call %_SubString(...), so |
| 6053 | // nothing can be assumed about the arguments. It is tested that: |
| 6054 | // "string" is a sequential string, |
| 6055 | // both "from" and "to" are smis, and |
| 6056 | // 0 <= from <= to <= string.length. |
| 6057 | // If any of these assumptions fail, we call the runtime system. |
| 6058 | |
| 6059 | static const int kToOffset = 0 * kPointerSize; |
| 6060 | static const int kFromOffset = 1 * kPointerSize; |
| 6061 | static const int kStringOffset = 2 * kPointerSize; |
| 6062 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6063 | __ lw(a2, MemOperand(sp, kToOffset)); |
| 6064 | __ lw(a3, MemOperand(sp, kFromOffset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6065 | STATIC_ASSERT(kFromOffset == kToOffset + 4); |
| 6066 | STATIC_ASSERT(kSmiTag == 0); |
| 6067 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 6068 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6069 | // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is |
| 6070 | // safe in this case. |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 6071 | __ UntagAndJumpIfNotSmi(a2, a2, &runtime); |
| 6072 | __ UntagAndJumpIfNotSmi(a3, a3, &runtime); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6073 | // Both a2 and a3 are untagged integers. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6074 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6075 | __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6076 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 6077 | __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to. |
| 6078 | __ Subu(a2, a2, a3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6079 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6080 | // Make sure first argument is a string. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6081 | __ lw(v0, MemOperand(sp, kStringOffset)); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 6082 | __ JumpIfSmi(v0, &runtime); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6083 | __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6084 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 6085 | __ And(t0, a1, Operand(kIsNotStringMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6086 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 6087 | __ Branch(&runtime, ne, t0, Operand(zero_reg)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6088 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6089 | // Short-cut for the case of trivial substring. |
| 6090 | Label return_v0; |
| 6091 | // v0: original string |
| 6092 | // a2: result string length |
| 6093 | __ lw(t0, FieldMemOperand(v0, String::kLengthOffset)); |
| 6094 | __ sra(t0, t0, 1); |
| 6095 | __ Branch(&return_v0, eq, a2, Operand(t0)); |
| 6096 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6097 | |
| 6098 | Label result_longer_than_two; |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6099 | // Check for special case of two character ASCII string, in which case |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6100 | // we do a lookup in the symbol table first. |
| 6101 | __ li(t0, 2); |
| 6102 | __ Branch(&result_longer_than_two, gt, a2, Operand(t0)); |
| 6103 | __ Branch(&runtime, lt, a2, Operand(t0)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6104 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6105 | __ JumpIfInstanceTypeIsNotSequentialAscii(a1, a1, &runtime); |
| 6106 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6107 | // Get the two characters forming the sub string. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6108 | __ Addu(v0, v0, Operand(a3)); |
| 6109 | __ lbu(a3, FieldMemOperand(v0, SeqAsciiString::kHeaderSize)); |
| 6110 | __ lbu(t0, FieldMemOperand(v0, SeqAsciiString::kHeaderSize + 1)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6111 | |
| 6112 | // Try to lookup two character string in symbol table. |
| 6113 | Label make_two_character_string; |
| 6114 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
| 6115 | masm, a3, t0, a1, t1, t2, t3, t4, &make_two_character_string); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6116 | __ jmp(&return_v0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6117 | |
| 6118 | // a2: result string length. |
| 6119 | // a3: two characters combined into halfword in little endian byte order. |
| 6120 | __ bind(&make_two_character_string); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6121 | __ AllocateAsciiString(v0, a2, t0, t1, t4, &runtime); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6122 | __ sh(a3, FieldMemOperand(v0, SeqAsciiString::kHeaderSize)); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6123 | __ jmp(&return_v0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6124 | |
| 6125 | __ bind(&result_longer_than_two); |
| 6126 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6127 | // Deal with different string types: update the index if necessary |
| 6128 | // and put the underlying string into t1. |
| 6129 | // v0: original string |
| 6130 | // a1: instance type |
| 6131 | // a2: length |
| 6132 | // a3: from index (untagged) |
| 6133 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6134 | // If the string is not indirect, it can only be sequential or external. |
| 6135 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6136 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6137 | __ And(t0, a1, Operand(kIsIndirectStringMask)); |
| 6138 | __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, t0, Operand(zero_reg)); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6139 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6140 | __ And(t0, a1, Operand(kSlicedNotConsMask)); |
| 6141 | __ Branch(&sliced_string, ne, t0, Operand(zero_reg)); |
| 6142 | // Cons string. Check whether it is flat, then fetch first part. |
| 6143 | __ lw(t1, FieldMemOperand(v0, ConsString::kSecondOffset)); |
| 6144 | __ LoadRoot(t0, Heap::kEmptyStringRootIndex); |
| 6145 | __ Branch(&runtime, ne, t1, Operand(t0)); |
| 6146 | __ lw(t1, FieldMemOperand(v0, ConsString::kFirstOffset)); |
| 6147 | // Update instance type. |
| 6148 | __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset)); |
| 6149 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
| 6150 | __ jmp(&underlying_unpacked); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6151 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6152 | __ bind(&sliced_string); |
| 6153 | // Sliced string. Fetch parent and correct start index by offset. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6154 | __ lw(t1, FieldMemOperand(v0, SlicedString::kParentOffset)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 6155 | __ lw(t0, FieldMemOperand(v0, SlicedString::kOffsetOffset)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 6156 | __ sra(t0, t0, 1); // Add offset to index. |
| 6157 | __ Addu(a3, a3, t0); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6158 | // Update instance type. |
| 6159 | __ lw(a1, FieldMemOperand(t1, HeapObject::kMapOffset)); |
| 6160 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
| 6161 | __ jmp(&underlying_unpacked); |
| 6162 | |
| 6163 | __ bind(&seq_or_external_string); |
| 6164 | // Sequential or external string. Just move string to the expected register. |
| 6165 | __ mov(t1, v0); |
| 6166 | |
| 6167 | __ bind(&underlying_unpacked); |
| 6168 | |
| 6169 | if (FLAG_string_slices) { |
| 6170 | Label copy_routine; |
| 6171 | // t1: underlying subject string |
| 6172 | // a1: instance type of underlying subject string |
| 6173 | // a2: length |
| 6174 | // a3: adjusted start index (untagged) |
| 6175 | // Short slice. Copy instead of slicing. |
| 6176 | __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength)); |
| 6177 | // Allocate new sliced string. At this point we do not reload the instance |
| 6178 | // type including the string encoding because we simply rely on the info |
| 6179 | // provided by the original string. It does not matter if the original |
| 6180 | // string's encoding is wrong because we always have to recheck encoding of |
| 6181 | // the newly created string's parent anyways due to externalized strings. |
| 6182 | Label two_byte_slice, set_slice_header; |
| 6183 | STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
| 6184 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6185 | __ And(t0, a1, Operand(kStringEncodingMask)); |
| 6186 | __ Branch(&two_byte_slice, eq, t0, Operand(zero_reg)); |
| 6187 | __ AllocateAsciiSlicedString(v0, a2, t2, t3, &runtime); |
| 6188 | __ jmp(&set_slice_header); |
| 6189 | __ bind(&two_byte_slice); |
| 6190 | __ AllocateTwoByteSlicedString(v0, a2, t2, t3, &runtime); |
| 6191 | __ bind(&set_slice_header); |
| 6192 | __ sll(a3, a3, 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6193 | __ sw(t1, FieldMemOperand(v0, SlicedString::kParentOffset)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame^] | 6194 | __ sw(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6195 | __ jmp(&return_v0); |
| 6196 | |
| 6197 | __ bind(©_routine); |
| 6198 | } |
| 6199 | |
| 6200 | // t1: underlying subject string |
| 6201 | // a1: instance type of underlying subject string |
| 6202 | // a2: length |
| 6203 | // a3: adjusted start index (untagged) |
| 6204 | Label two_byte_sequential, sequential_string, allocate_result; |
| 6205 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6206 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6207 | __ And(t0, a1, Operand(kExternalStringTag)); |
| 6208 | __ Branch(&sequential_string, eq, t0, Operand(zero_reg)); |
| 6209 | |
| 6210 | // Handle external string. |
| 6211 | // Rule out short external strings. |
| 6212 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6213 | __ And(t0, a1, Operand(kShortExternalStringTag)); |
| 6214 | __ Branch(&runtime, ne, t0, Operand(zero_reg)); |
| 6215 | __ lw(t1, FieldMemOperand(t1, ExternalString::kResourceDataOffset)); |
| 6216 | // t1 already points to the first character of underlying string. |
| 6217 | __ jmp(&allocate_result); |
| 6218 | |
| 6219 | __ bind(&sequential_string); |
| 6220 | // Locate first character of underlying subject string. |
| 6221 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); |
| 6222 | __ Addu(t1, t1, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 6223 | |
| 6224 | __ bind(&allocate_result); |
| 6225 | // Sequential acii string. Allocate the result. |
| 6226 | STATIC_ASSERT((kAsciiStringTag & kStringEncodingMask) != 0); |
| 6227 | __ And(t0, a1, Operand(kStringEncodingMask)); |
| 6228 | __ Branch(&two_byte_sequential, eq, t0, Operand(zero_reg)); |
| 6229 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6230 | // Allocate and copy the resulting ASCII string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6231 | __ AllocateAsciiString(v0, a2, t0, t2, t3, &runtime); |
| 6232 | |
| 6233 | // Locate first character of substring to copy. |
| 6234 | __ Addu(t1, t1, a3); |
| 6235 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6236 | // Locate first character of result. |
| 6237 | __ Addu(a1, v0, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6238 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6239 | // v0: result string |
| 6240 | // a1: first character of result string |
| 6241 | // a2: result string length |
| 6242 | // t1: first character of substring to copy |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6243 | STATIC_ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 6244 | StringHelper::GenerateCopyCharactersLong( |
| 6245 | masm, a1, t1, a2, a3, t0, t2, t3, t4, COPY_ASCII | DEST_ALWAYS_ALIGNED); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6246 | __ jmp(&return_v0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6247 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6248 | // Allocate and copy the resulting two-byte string. |
| 6249 | __ bind(&two_byte_sequential); |
| 6250 | __ AllocateTwoByteString(v0, a2, t0, t2, t3, &runtime); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6251 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6252 | // Locate first character of substring to copy. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6253 | STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6254 | __ sll(t0, a3, 1); |
| 6255 | __ Addu(t1, t1, t0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6256 | // Locate first character of result. |
| 6257 | __ Addu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6258 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6259 | // v0: result string. |
| 6260 | // a1: first character of result. |
| 6261 | // a2: result length. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6262 | // t1: first character of substring to copy. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6263 | STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 6264 | StringHelper::GenerateCopyCharactersLong( |
| 6265 | masm, a1, t1, a2, a3, t0, t2, t3, t4, DEST_ALWAYS_ALIGNED); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6266 | |
| 6267 | __ bind(&return_v0); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6268 | Counters* counters = masm->isolate()->counters(); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6269 | __ IncrementCounter(counters->sub_string_native(), 1, a3, t0); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6270 | __ DropAndRet(3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6271 | |
| 6272 | // Just jump to runtime to create the sub string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6273 | __ bind(&runtime); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6274 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
| 6275 | } |
| 6276 | |
| 6277 | |
| 6278 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6279 | Register left, |
| 6280 | Register right, |
| 6281 | Register scratch1, |
| 6282 | Register scratch2, |
| 6283 | Register scratch3) { |
| 6284 | Register length = scratch1; |
| 6285 | |
| 6286 | // Compare lengths. |
| 6287 | Label strings_not_equal, check_zero_length; |
| 6288 | __ lw(length, FieldMemOperand(left, String::kLengthOffset)); |
| 6289 | __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 6290 | __ Branch(&check_zero_length, eq, length, Operand(scratch2)); |
| 6291 | __ bind(&strings_not_equal); |
| 6292 | __ li(v0, Operand(Smi::FromInt(NOT_EQUAL))); |
| 6293 | __ Ret(); |
| 6294 | |
| 6295 | // Check if the length is zero. |
| 6296 | Label compare_chars; |
| 6297 | __ bind(&check_zero_length); |
| 6298 | STATIC_ASSERT(kSmiTag == 0); |
| 6299 | __ Branch(&compare_chars, ne, length, Operand(zero_reg)); |
| 6300 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
| 6301 | __ Ret(); |
| 6302 | |
| 6303 | // Compare characters. |
| 6304 | __ bind(&compare_chars); |
| 6305 | |
| 6306 | GenerateAsciiCharsCompareLoop(masm, |
| 6307 | left, right, length, scratch2, scratch3, v0, |
| 6308 | &strings_not_equal); |
| 6309 | |
| 6310 | // Characters are equal. |
| 6311 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
| 6312 | __ Ret(); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6313 | } |
| 6314 | |
| 6315 | |
| 6316 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6317 | Register left, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6318 | Register right, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6319 | Register scratch1, |
| 6320 | Register scratch2, |
| 6321 | Register scratch3, |
| 6322 | Register scratch4) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6323 | Label result_not_equal, compare_lengths; |
| 6324 | // Find minimum length and length difference. |
| 6325 | __ lw(scratch1, FieldMemOperand(left, String::kLengthOffset)); |
| 6326 | __ lw(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 6327 | __ Subu(scratch3, scratch1, Operand(scratch2)); |
| 6328 | Register length_delta = scratch3; |
| 6329 | __ slt(scratch4, scratch2, scratch1); |
| 6330 | __ movn(scratch1, scratch2, scratch4); |
| 6331 | Register min_length = scratch1; |
| 6332 | STATIC_ASSERT(kSmiTag == 0); |
| 6333 | __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg)); |
| 6334 | |
| 6335 | // Compare loop. |
| 6336 | GenerateAsciiCharsCompareLoop(masm, |
| 6337 | left, right, min_length, scratch2, scratch4, v0, |
| 6338 | &result_not_equal); |
| 6339 | |
| 6340 | // Compare lengths - strings up to min-length are equal. |
| 6341 | __ bind(&compare_lengths); |
| 6342 | ASSERT(Smi::FromInt(EQUAL) == static_cast<Smi*>(0)); |
| 6343 | // Use length_delta as result if it's zero. |
| 6344 | __ mov(scratch2, length_delta); |
| 6345 | __ mov(scratch4, zero_reg); |
| 6346 | __ mov(v0, zero_reg); |
| 6347 | |
| 6348 | __ bind(&result_not_equal); |
| 6349 | // Conditionally update the result based either on length_delta or |
| 6350 | // the last comparion performed in the loop above. |
| 6351 | Label ret; |
| 6352 | __ Branch(&ret, eq, scratch2, Operand(scratch4)); |
| 6353 | __ li(v0, Operand(Smi::FromInt(GREATER))); |
| 6354 | __ Branch(&ret, gt, scratch2, Operand(scratch4)); |
| 6355 | __ li(v0, Operand(Smi::FromInt(LESS))); |
| 6356 | __ bind(&ret); |
| 6357 | __ Ret(); |
| 6358 | } |
| 6359 | |
| 6360 | |
| 6361 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6362 | MacroAssembler* masm, |
| 6363 | Register left, |
| 6364 | Register right, |
| 6365 | Register length, |
| 6366 | Register scratch1, |
| 6367 | Register scratch2, |
| 6368 | Register scratch3, |
| 6369 | Label* chars_not_equal) { |
| 6370 | // Change index to run from -length to -1 by adding length to string |
| 6371 | // start. This means that loop ends when index reaches zero, which |
| 6372 | // doesn't need an additional compare. |
| 6373 | __ SmiUntag(length); |
| 6374 | __ Addu(scratch1, length, |
| 6375 | Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 6376 | __ Addu(left, left, Operand(scratch1)); |
| 6377 | __ Addu(right, right, Operand(scratch1)); |
| 6378 | __ Subu(length, zero_reg, length); |
| 6379 | Register index = length; // index = -length; |
| 6380 | |
| 6381 | |
| 6382 | // Compare loop. |
| 6383 | Label loop; |
| 6384 | __ bind(&loop); |
| 6385 | __ Addu(scratch3, left, index); |
| 6386 | __ lbu(scratch1, MemOperand(scratch3)); |
| 6387 | __ Addu(scratch3, right, index); |
| 6388 | __ lbu(scratch2, MemOperand(scratch3)); |
| 6389 | __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2)); |
| 6390 | __ Addu(index, index, 1); |
| 6391 | __ Branch(&loop, ne, index, Operand(zero_reg)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6392 | } |
| 6393 | |
| 6394 | |
| 6395 | void StringCompareStub::Generate(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6396 | Label runtime; |
| 6397 | |
| 6398 | Counters* counters = masm->isolate()->counters(); |
| 6399 | |
| 6400 | // Stack frame on entry. |
| 6401 | // sp[0]: right string |
| 6402 | // sp[4]: left string |
| 6403 | __ lw(a1, MemOperand(sp, 1 * kPointerSize)); // Left. |
| 6404 | __ lw(a0, MemOperand(sp, 0 * kPointerSize)); // Right. |
| 6405 | |
| 6406 | Label not_same; |
| 6407 | __ Branch(¬_same, ne, a0, Operand(a1)); |
| 6408 | STATIC_ASSERT(EQUAL == 0); |
| 6409 | STATIC_ASSERT(kSmiTag == 0); |
| 6410 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
| 6411 | __ IncrementCounter(counters->string_compare_native(), 1, a1, a2); |
| 6412 | __ Addu(sp, sp, Operand(2 * kPointerSize)); |
| 6413 | __ Ret(); |
| 6414 | |
| 6415 | __ bind(¬_same); |
| 6416 | |
| 6417 | // Check that both objects are sequential ASCII strings. |
| 6418 | __ JumpIfNotBothSequentialAsciiStrings(a1, a0, a2, a3, &runtime); |
| 6419 | |
| 6420 | // Compare flat ASCII strings natively. Remove arguments from stack first. |
| 6421 | __ IncrementCounter(counters->string_compare_native(), 1, a2, a3); |
| 6422 | __ Addu(sp, sp, Operand(2 * kPointerSize)); |
| 6423 | GenerateCompareFlatAsciiStrings(masm, a1, a0, a2, a3, t0, t1); |
| 6424 | |
| 6425 | __ bind(&runtime); |
| 6426 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6427 | } |
| 6428 | |
| 6429 | |
| 6430 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6431 | Label call_runtime, call_builtin; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6432 | Builtins::JavaScript builtin_id = Builtins::ADD; |
| 6433 | |
| 6434 | Counters* counters = masm->isolate()->counters(); |
| 6435 | |
| 6436 | // Stack on entry: |
| 6437 | // sp[0]: second argument (right). |
| 6438 | // sp[4]: first argument (left). |
| 6439 | |
| 6440 | // Load the two arguments. |
| 6441 | __ lw(a0, MemOperand(sp, 1 * kPointerSize)); // First argument. |
| 6442 | __ lw(a1, MemOperand(sp, 0 * kPointerSize)); // Second argument. |
| 6443 | |
| 6444 | // Make sure that both arguments are strings if not known in advance. |
| 6445 | if (flags_ == NO_STRING_ADD_FLAGS) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6446 | __ JumpIfEitherSmi(a0, a1, &call_runtime); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6447 | // Load instance types. |
| 6448 | __ lw(t0, FieldMemOperand(a0, HeapObject::kMapOffset)); |
| 6449 | __ lw(t1, FieldMemOperand(a1, HeapObject::kMapOffset)); |
| 6450 | __ lbu(t0, FieldMemOperand(t0, Map::kInstanceTypeOffset)); |
| 6451 | __ lbu(t1, FieldMemOperand(t1, Map::kInstanceTypeOffset)); |
| 6452 | STATIC_ASSERT(kStringTag == 0); |
| 6453 | // If either is not a string, go to runtime. |
| 6454 | __ Or(t4, t0, Operand(t1)); |
| 6455 | __ And(t4, t4, Operand(kIsNotStringMask)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6456 | __ Branch(&call_runtime, ne, t4, Operand(zero_reg)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6457 | } else { |
| 6458 | // Here at least one of the arguments is definitely a string. |
| 6459 | // We convert the one that is not known to be a string. |
| 6460 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 6461 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 6462 | GenerateConvertArgument( |
| 6463 | masm, 1 * kPointerSize, a0, a2, a3, t0, t1, &call_builtin); |
| 6464 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 6465 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 6466 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 6467 | GenerateConvertArgument( |
| 6468 | masm, 0 * kPointerSize, a1, a2, a3, t0, t1, &call_builtin); |
| 6469 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 6470 | } |
| 6471 | } |
| 6472 | |
| 6473 | // Both arguments are strings. |
| 6474 | // a0: first string |
| 6475 | // a1: second string |
| 6476 | // t0: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 6477 | // t1: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 6478 | { |
| 6479 | Label strings_not_empty; |
| 6480 | // Check if either of the strings are empty. In that case return the other. |
| 6481 | // These tests use zero-length check on string-length whch is an Smi. |
| 6482 | // Assert that Smi::FromInt(0) is really 0. |
| 6483 | STATIC_ASSERT(kSmiTag == 0); |
| 6484 | ASSERT(Smi::FromInt(0) == 0); |
| 6485 | __ lw(a2, FieldMemOperand(a0, String::kLengthOffset)); |
| 6486 | __ lw(a3, FieldMemOperand(a1, String::kLengthOffset)); |
| 6487 | __ mov(v0, a0); // Assume we'll return first string (from a0). |
| 6488 | __ movz(v0, a1, a2); // If first is empty, return second (from a1). |
| 6489 | __ slt(t4, zero_reg, a2); // if (a2 > 0) t4 = 1. |
| 6490 | __ slt(t5, zero_reg, a3); // if (a3 > 0) t5 = 1. |
| 6491 | __ and_(t4, t4, t5); // Branch if both strings were non-empty. |
| 6492 | __ Branch(&strings_not_empty, ne, t4, Operand(zero_reg)); |
| 6493 | |
| 6494 | __ IncrementCounter(counters->string_add_native(), 1, a2, a3); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6495 | __ DropAndRet(2); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6496 | |
| 6497 | __ bind(&strings_not_empty); |
| 6498 | } |
| 6499 | |
| 6500 | // Untag both string-lengths. |
| 6501 | __ sra(a2, a2, kSmiTagSize); |
| 6502 | __ sra(a3, a3, kSmiTagSize); |
| 6503 | |
| 6504 | // Both strings are non-empty. |
| 6505 | // a0: first string |
| 6506 | // a1: second string |
| 6507 | // a2: length of first string |
| 6508 | // a3: length of second string |
| 6509 | // t0: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 6510 | // t1: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 6511 | // Look at the length of the result of adding the two strings. |
| 6512 | Label string_add_flat_result, longer_than_two; |
| 6513 | // Adding two lengths can't overflow. |
| 6514 | STATIC_ASSERT(String::kMaxLength < String::kMaxLength * 2); |
| 6515 | __ Addu(t2, a2, Operand(a3)); |
| 6516 | // Use the symbol table when adding two one character strings, as it |
| 6517 | // helps later optimizations to return a symbol here. |
| 6518 | __ Branch(&longer_than_two, ne, t2, Operand(2)); |
| 6519 | |
| 6520 | // Check that both strings are non-external ASCII strings. |
| 6521 | if (flags_ != NO_STRING_ADD_FLAGS) { |
| 6522 | __ lw(t0, FieldMemOperand(a0, HeapObject::kMapOffset)); |
| 6523 | __ lw(t1, FieldMemOperand(a1, HeapObject::kMapOffset)); |
| 6524 | __ lbu(t0, FieldMemOperand(t0, Map::kInstanceTypeOffset)); |
| 6525 | __ lbu(t1, FieldMemOperand(t1, Map::kInstanceTypeOffset)); |
| 6526 | } |
| 6527 | __ JumpIfBothInstanceTypesAreNotSequentialAscii(t0, t1, t2, t3, |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6528 | &call_runtime); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6529 | |
| 6530 | // Get the two characters forming the sub string. |
| 6531 | __ lbu(a2, FieldMemOperand(a0, SeqAsciiString::kHeaderSize)); |
| 6532 | __ lbu(a3, FieldMemOperand(a1, SeqAsciiString::kHeaderSize)); |
| 6533 | |
| 6534 | // Try to lookup two character string in symbol table. If it is not found |
| 6535 | // just allocate a new one. |
| 6536 | Label make_two_character_string; |
| 6537 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6538 | masm, a2, a3, t2, t3, t0, t1, t5, &make_two_character_string); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6539 | __ IncrementCounter(counters->string_add_native(), 1, a2, a3); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6540 | __ DropAndRet(2); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6541 | |
| 6542 | __ bind(&make_two_character_string); |
| 6543 | // Resulting string has length 2 and first chars of two strings |
| 6544 | // are combined into single halfword in a2 register. |
| 6545 | // So we can fill resulting string without two loops by a single |
| 6546 | // halfword store instruction (which assumes that processor is |
| 6547 | // in a little endian mode). |
| 6548 | __ li(t2, Operand(2)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6549 | __ AllocateAsciiString(v0, t2, t0, t1, t5, &call_runtime); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6550 | __ sh(a2, FieldMemOperand(v0, SeqAsciiString::kHeaderSize)); |
| 6551 | __ IncrementCounter(counters->string_add_native(), 1, a2, a3); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6552 | __ DropAndRet(2); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6553 | |
| 6554 | __ bind(&longer_than_two); |
| 6555 | // Check if resulting string will be flat. |
| 6556 | __ Branch(&string_add_flat_result, lt, t2, |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6557 | Operand(ConsString::kMinLength)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6558 | // Handle exceptionally long strings in the runtime system. |
| 6559 | STATIC_ASSERT((String::kMaxLength & 0x80000000) == 0); |
| 6560 | ASSERT(IsPowerOf2(String::kMaxLength + 1)); |
| 6561 | // kMaxLength + 1 is representable as shifted literal, kMaxLength is not. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6562 | __ Branch(&call_runtime, hs, t2, Operand(String::kMaxLength + 1)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6563 | |
| 6564 | // If result is not supposed to be flat, allocate a cons string object. |
| 6565 | // If both strings are ASCII the result is an ASCII cons string. |
| 6566 | if (flags_ != NO_STRING_ADD_FLAGS) { |
| 6567 | __ lw(t0, FieldMemOperand(a0, HeapObject::kMapOffset)); |
| 6568 | __ lw(t1, FieldMemOperand(a1, HeapObject::kMapOffset)); |
| 6569 | __ lbu(t0, FieldMemOperand(t0, Map::kInstanceTypeOffset)); |
| 6570 | __ lbu(t1, FieldMemOperand(t1, Map::kInstanceTypeOffset)); |
| 6571 | } |
| 6572 | Label non_ascii, allocated, ascii_data; |
| 6573 | STATIC_ASSERT(kTwoByteStringTag == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6574 | // Branch to non_ascii if either string-encoding field is zero (non-ASCII). |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6575 | __ And(t4, t0, Operand(t1)); |
| 6576 | __ And(t4, t4, Operand(kStringEncodingMask)); |
| 6577 | __ Branch(&non_ascii, eq, t4, Operand(zero_reg)); |
| 6578 | |
| 6579 | // Allocate an ASCII cons string. |
| 6580 | __ bind(&ascii_data); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6581 | __ AllocateAsciiConsString(v0, t2, t0, t1, &call_runtime); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6582 | __ bind(&allocated); |
| 6583 | // Fill the fields of the cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6584 | __ sw(a0, FieldMemOperand(v0, ConsString::kFirstOffset)); |
| 6585 | __ sw(a1, FieldMemOperand(v0, ConsString::kSecondOffset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6586 | __ IncrementCounter(counters->string_add_native(), 1, a2, a3); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6587 | __ DropAndRet(2); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6588 | |
| 6589 | __ bind(&non_ascii); |
| 6590 | // At least one of the strings is two-byte. Check whether it happens |
| 6591 | // to contain only ASCII characters. |
| 6592 | // t0: first instance type. |
| 6593 | // t1: second instance type. |
| 6594 | // Branch to if _both_ instances have kAsciiDataHintMask set. |
| 6595 | __ And(at, t0, Operand(kAsciiDataHintMask)); |
| 6596 | __ and_(at, at, t1); |
| 6597 | __ Branch(&ascii_data, ne, at, Operand(zero_reg)); |
| 6598 | |
| 6599 | __ xor_(t0, t0, t1); |
| 6600 | STATIC_ASSERT(kAsciiStringTag != 0 && kAsciiDataHintTag != 0); |
| 6601 | __ And(t0, t0, Operand(kAsciiStringTag | kAsciiDataHintTag)); |
| 6602 | __ Branch(&ascii_data, eq, t0, Operand(kAsciiStringTag | kAsciiDataHintTag)); |
| 6603 | |
| 6604 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6605 | __ AllocateTwoByteConsString(v0, t2, t0, t1, &call_runtime); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6606 | __ Branch(&allocated); |
| 6607 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6608 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6609 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6610 | // Handle creating a flat result from either external or sequential strings. |
| 6611 | // Locate the first characters' locations. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6612 | // a0: first string |
| 6613 | // a1: second string |
| 6614 | // a2: length of first string |
| 6615 | // a3: length of second string |
| 6616 | // t0: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 6617 | // t1: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 6618 | // t2: sum of lengths. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6619 | Label first_prepared, second_prepared; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6620 | __ bind(&string_add_flat_result); |
| 6621 | if (flags_ != NO_STRING_ADD_FLAGS) { |
| 6622 | __ lw(t0, FieldMemOperand(a0, HeapObject::kMapOffset)); |
| 6623 | __ lw(t1, FieldMemOperand(a1, HeapObject::kMapOffset)); |
| 6624 | __ lbu(t0, FieldMemOperand(t0, Map::kInstanceTypeOffset)); |
| 6625 | __ lbu(t1, FieldMemOperand(t1, Map::kInstanceTypeOffset)); |
| 6626 | } |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6627 | // Check whether both strings have same encoding |
| 6628 | __ Xor(t3, t0, Operand(t1)); |
| 6629 | __ And(t3, t3, Operand(kStringEncodingMask)); |
| 6630 | __ Branch(&call_runtime, ne, t3, Operand(zero_reg)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6631 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6632 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6633 | __ And(t4, t0, Operand(kStringRepresentationMask)); |
| 6634 | |
| 6635 | STATIC_ASSERT(SeqAsciiString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
| 6636 | Label skip_first_add; |
| 6637 | __ Branch(&skip_first_add, ne, t4, Operand(zero_reg)); |
| 6638 | __ Branch(USE_DELAY_SLOT, &first_prepared); |
| 6639 | __ addiu(t3, a0, SeqAsciiString::kHeaderSize - kHeapObjectTag); |
| 6640 | __ bind(&skip_first_add); |
| 6641 | // External string: rule out short external string and load string resource. |
| 6642 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 6643 | __ And(t4, t0, Operand(kShortExternalStringMask)); |
| 6644 | __ Branch(&call_runtime, ne, t4, Operand(zero_reg)); |
| 6645 | __ lw(t3, FieldMemOperand(a0, ExternalString::kResourceDataOffset)); |
| 6646 | __ bind(&first_prepared); |
| 6647 | |
| 6648 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6649 | __ And(t4, t1, Operand(kStringRepresentationMask)); |
| 6650 | STATIC_ASSERT(SeqAsciiString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
| 6651 | Label skip_second_add; |
| 6652 | __ Branch(&skip_second_add, ne, t4, Operand(zero_reg)); |
| 6653 | __ Branch(USE_DELAY_SLOT, &second_prepared); |
| 6654 | __ addiu(a1, a1, SeqAsciiString::kHeaderSize - kHeapObjectTag); |
| 6655 | __ bind(&skip_second_add); |
| 6656 | // External string: rule out short external string and load string resource. |
| 6657 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 6658 | __ And(t4, t1, Operand(kShortExternalStringMask)); |
| 6659 | __ Branch(&call_runtime, ne, t4, Operand(zero_reg)); |
| 6660 | __ lw(a1, FieldMemOperand(a1, ExternalString::kResourceDataOffset)); |
| 6661 | __ bind(&second_prepared); |
| 6662 | |
| 6663 | Label non_ascii_string_add_flat_result; |
| 6664 | // t3: first character of first string |
| 6665 | // a1: first character of second string |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6666 | // a2: length of first string |
| 6667 | // a3: length of second string |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6668 | // t2: sum of lengths. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6669 | // Both strings have the same encoding. |
| 6670 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 6671 | __ And(t4, t1, Operand(kStringEncodingMask)); |
| 6672 | __ Branch(&non_ascii_string_add_flat_result, eq, t4, Operand(zero_reg)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6673 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6674 | __ AllocateAsciiString(v0, t2, t0, t1, t5, &call_runtime); |
| 6675 | __ Addu(t2, v0, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 6676 | // v0: result string. |
| 6677 | // t3: first character of first string. |
| 6678 | // a1: first character of second string |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6679 | // a2: length of first string. |
| 6680 | // a3: length of second string. |
| 6681 | // t2: first character of result. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6682 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6683 | StringHelper::GenerateCopyCharacters(masm, t2, t3, a2, t0, true); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6684 | // t2: next character of result. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6685 | StringHelper::GenerateCopyCharacters(masm, t2, a1, a3, t0, true); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6686 | __ IncrementCounter(counters->string_add_native(), 1, a2, a3); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6687 | __ DropAndRet(2); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6688 | |
| 6689 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6690 | __ AllocateTwoByteString(v0, t2, t0, t1, t5, &call_runtime); |
| 6691 | __ Addu(t2, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6692 | // v0: result string. |
| 6693 | // t3: first character of first string. |
| 6694 | // a1: first character of second string. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6695 | // a2: length of first string. |
| 6696 | // a3: length of second string. |
| 6697 | // t2: first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6698 | StringHelper::GenerateCopyCharacters(masm, t2, t3, a2, t0, false); |
| 6699 | // t2: next character of result. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6700 | StringHelper::GenerateCopyCharacters(masm, t2, a1, a3, t0, false); |
| 6701 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6702 | __ IncrementCounter(counters->string_add_native(), 1, a2, a3); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6703 | __ DropAndRet(2); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6704 | |
| 6705 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6706 | __ bind(&call_runtime); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6707 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
| 6708 | |
| 6709 | if (call_builtin.is_linked()) { |
| 6710 | __ bind(&call_builtin); |
| 6711 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 6712 | } |
| 6713 | } |
| 6714 | |
| 6715 | |
| 6716 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 6717 | int stack_offset, |
| 6718 | Register arg, |
| 6719 | Register scratch1, |
| 6720 | Register scratch2, |
| 6721 | Register scratch3, |
| 6722 | Register scratch4, |
| 6723 | Label* slow) { |
| 6724 | // First check if the argument is already a string. |
| 6725 | Label not_string, done; |
| 6726 | __ JumpIfSmi(arg, ¬_string); |
| 6727 | __ GetObjectType(arg, scratch1, scratch1); |
| 6728 | __ Branch(&done, lt, scratch1, Operand(FIRST_NONSTRING_TYPE)); |
| 6729 | |
| 6730 | // Check the number to string cache. |
| 6731 | Label not_cached; |
| 6732 | __ bind(¬_string); |
| 6733 | // Puts the cached result into scratch1. |
| 6734 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 6735 | arg, |
| 6736 | scratch1, |
| 6737 | scratch2, |
| 6738 | scratch3, |
| 6739 | scratch4, |
| 6740 | false, |
| 6741 | ¬_cached); |
| 6742 | __ mov(arg, scratch1); |
| 6743 | __ sw(arg, MemOperand(sp, stack_offset)); |
| 6744 | __ jmp(&done); |
| 6745 | |
| 6746 | // Check if the argument is a safe string wrapper. |
| 6747 | __ bind(¬_cached); |
| 6748 | __ JumpIfSmi(arg, slow); |
| 6749 | __ GetObjectType(arg, scratch1, scratch2); // map -> scratch1. |
| 6750 | __ Branch(slow, ne, scratch2, Operand(JS_VALUE_TYPE)); |
| 6751 | __ lbu(scratch2, FieldMemOperand(scratch1, Map::kBitField2Offset)); |
| 6752 | __ li(scratch4, 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 6753 | __ And(scratch2, scratch2, scratch4); |
| 6754 | __ Branch(slow, ne, scratch2, Operand(scratch4)); |
| 6755 | __ lw(arg, FieldMemOperand(arg, JSValue::kValueOffset)); |
| 6756 | __ sw(arg, MemOperand(sp, stack_offset)); |
| 6757 | |
| 6758 | __ bind(&done); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6759 | } |
| 6760 | |
| 6761 | |
| 6762 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6763 | ASSERT(state_ == CompareIC::SMIS); |
| 6764 | Label miss; |
| 6765 | __ Or(a2, a1, a0); |
| 6766 | __ JumpIfNotSmi(a2, &miss); |
| 6767 | |
| 6768 | if (GetCondition() == eq) { |
| 6769 | // For equality we do not care about the sign of the result. |
| 6770 | __ Subu(v0, a0, a1); |
| 6771 | } else { |
| 6772 | // Untag before subtracting to avoid handling overflow. |
| 6773 | __ SmiUntag(a1); |
| 6774 | __ SmiUntag(a0); |
| 6775 | __ Subu(v0, a1, a0); |
| 6776 | } |
| 6777 | __ Ret(); |
| 6778 | |
| 6779 | __ bind(&miss); |
| 6780 | GenerateMiss(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6781 | } |
| 6782 | |
| 6783 | |
| 6784 | void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6785 | ASSERT(state_ == CompareIC::HEAP_NUMBERS); |
| 6786 | |
| 6787 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6788 | Label unordered, maybe_undefined1, maybe_undefined2; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6789 | Label miss; |
| 6790 | __ And(a2, a1, Operand(a0)); |
| 6791 | __ JumpIfSmi(a2, &generic_stub); |
| 6792 | |
| 6793 | __ GetObjectType(a0, a2, a2); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6794 | __ Branch(&maybe_undefined1, ne, a2, Operand(HEAP_NUMBER_TYPE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6795 | __ GetObjectType(a1, a2, a2); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6796 | __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6797 | |
| 6798 | // Inlining the double comparison and falling back to the general compare |
| 6799 | // stub if NaN is involved or FPU is unsupported. |
| 6800 | if (CpuFeatures::IsSupported(FPU)) { |
| 6801 | CpuFeatures::Scope scope(FPU); |
| 6802 | |
| 6803 | // Load left and right operand. |
| 6804 | __ Subu(a2, a1, Operand(kHeapObjectTag)); |
| 6805 | __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset)); |
| 6806 | __ Subu(a2, a0, Operand(kHeapObjectTag)); |
| 6807 | __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset)); |
| 6808 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6809 | // Return a result of -1, 0, or 1, or use CompareStub for NaNs. |
| 6810 | Label fpu_eq, fpu_lt; |
| 6811 | // Test if equal, and also handle the unordered/NaN case. |
| 6812 | __ BranchF(&fpu_eq, &unordered, eq, f0, f2); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6813 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6814 | // Test if less (unordered case is already handled). |
| 6815 | __ BranchF(&fpu_lt, NULL, lt, f0, f2); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6816 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6817 | // Otherwise it's greater, so just fall thru, and return. |
| 6818 | __ Ret(USE_DELAY_SLOT); |
| 6819 | __ li(v0, Operand(GREATER)); // In delay slot. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6820 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6821 | __ bind(&fpu_eq); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6822 | __ Ret(USE_DELAY_SLOT); |
| 6823 | __ li(v0, Operand(EQUAL)); // In delay slot. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6824 | |
| 6825 | __ bind(&fpu_lt); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6826 | __ Ret(USE_DELAY_SLOT); |
| 6827 | __ li(v0, Operand(LESS)); // In delay slot. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6828 | } |
| 6829 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6830 | __ bind(&unordered); |
| 6831 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6832 | CompareStub stub(GetCondition(), strict(), NO_COMPARE_FLAGS, a1, a0); |
| 6833 | __ bind(&generic_stub); |
| 6834 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 6835 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6836 | __ bind(&maybe_undefined1); |
| 6837 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6838 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 6839 | __ Branch(&miss, ne, a0, Operand(at)); |
| 6840 | __ GetObjectType(a1, a2, a2); |
| 6841 | __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE)); |
| 6842 | __ jmp(&unordered); |
| 6843 | } |
| 6844 | |
| 6845 | __ bind(&maybe_undefined2); |
| 6846 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6847 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 6848 | __ Branch(&unordered, eq, a1, Operand(at)); |
| 6849 | } |
| 6850 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6851 | __ bind(&miss); |
| 6852 | GenerateMiss(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6853 | } |
| 6854 | |
| 6855 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6856 | void ICCompareStub::GenerateSymbols(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6857 | ASSERT(state_ == CompareIC::SYMBOLS); |
| 6858 | Label miss; |
| 6859 | |
| 6860 | // Registers containing left and right operands respectively. |
| 6861 | Register left = a1; |
| 6862 | Register right = a0; |
| 6863 | Register tmp1 = a2; |
| 6864 | Register tmp2 = a3; |
| 6865 | |
| 6866 | // Check that both operands are heap objects. |
| 6867 | __ JumpIfEitherSmi(left, right, &miss); |
| 6868 | |
| 6869 | // Check that both operands are symbols. |
| 6870 | __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 6871 | __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 6872 | __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6873 | __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6874 | STATIC_ASSERT(kSymbolTag != 0); |
| 6875 | __ And(tmp1, tmp1, Operand(tmp2)); |
| 6876 | __ And(tmp1, tmp1, kIsSymbolMask); |
| 6877 | __ Branch(&miss, eq, tmp1, Operand(zero_reg)); |
| 6878 | // Make sure a0 is non-zero. At this point input operands are |
| 6879 | // guaranteed to be non-zero. |
| 6880 | ASSERT(right.is(a0)); |
| 6881 | STATIC_ASSERT(EQUAL == 0); |
| 6882 | STATIC_ASSERT(kSmiTag == 0); |
| 6883 | __ mov(v0, right); |
| 6884 | // Symbols are compared by identity. |
| 6885 | __ Ret(ne, left, Operand(right)); |
| 6886 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
| 6887 | __ Ret(); |
| 6888 | |
| 6889 | __ bind(&miss); |
| 6890 | GenerateMiss(masm); |
| 6891 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6892 | |
| 6893 | |
| 6894 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6895 | ASSERT(state_ == CompareIC::STRINGS); |
| 6896 | Label miss; |
| 6897 | |
| 6898 | // Registers containing left and right operands respectively. |
| 6899 | Register left = a1; |
| 6900 | Register right = a0; |
| 6901 | Register tmp1 = a2; |
| 6902 | Register tmp2 = a3; |
| 6903 | Register tmp3 = t0; |
| 6904 | Register tmp4 = t1; |
| 6905 | Register tmp5 = t2; |
| 6906 | |
| 6907 | // Check that both operands are heap objects. |
| 6908 | __ JumpIfEitherSmi(left, right, &miss); |
| 6909 | |
| 6910 | // Check that both operands are strings. This leaves the instance |
| 6911 | // types loaded in tmp1 and tmp2. |
| 6912 | __ lw(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 6913 | __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 6914 | __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6915 | __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6916 | STATIC_ASSERT(kNotStringTag != 0); |
| 6917 | __ Or(tmp3, tmp1, tmp2); |
| 6918 | __ And(tmp5, tmp3, Operand(kIsNotStringMask)); |
| 6919 | __ Branch(&miss, ne, tmp5, Operand(zero_reg)); |
| 6920 | |
| 6921 | // Fast check for identical strings. |
| 6922 | Label left_ne_right; |
| 6923 | STATIC_ASSERT(EQUAL == 0); |
| 6924 | STATIC_ASSERT(kSmiTag == 0); |
| 6925 | __ Branch(&left_ne_right, ne, left, Operand(right), USE_DELAY_SLOT); |
| 6926 | __ mov(v0, zero_reg); // In the delay slot. |
| 6927 | __ Ret(); |
| 6928 | __ bind(&left_ne_right); |
| 6929 | |
| 6930 | // Handle not identical strings. |
| 6931 | |
| 6932 | // Check that both strings are symbols. If they are, we're done |
| 6933 | // because we already know they are not identical. |
| 6934 | ASSERT(GetCondition() == eq); |
| 6935 | STATIC_ASSERT(kSymbolTag != 0); |
| 6936 | __ And(tmp3, tmp1, Operand(tmp2)); |
| 6937 | __ And(tmp5, tmp3, Operand(kIsSymbolMask)); |
| 6938 | Label is_symbol; |
| 6939 | __ Branch(&is_symbol, eq, tmp5, Operand(zero_reg), USE_DELAY_SLOT); |
| 6940 | __ mov(v0, a0); // In the delay slot. |
| 6941 | // Make sure a0 is non-zero. At this point input operands are |
| 6942 | // guaranteed to be non-zero. |
| 6943 | ASSERT(right.is(a0)); |
| 6944 | __ Ret(); |
| 6945 | __ bind(&is_symbol); |
| 6946 | |
| 6947 | // Check that both strings are sequential ASCII. |
| 6948 | Label runtime; |
| 6949 | __ JumpIfBothInstanceTypesAreNotSequentialAscii(tmp1, tmp2, tmp3, tmp4, |
| 6950 | &runtime); |
| 6951 | |
| 6952 | // Compare flat ASCII strings. Returns when done. |
| 6953 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6954 | masm, left, right, tmp1, tmp2, tmp3); |
| 6955 | |
| 6956 | // Handle more complex cases in runtime. |
| 6957 | __ bind(&runtime); |
| 6958 | __ Push(left, right); |
| 6959 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6960 | |
| 6961 | __ bind(&miss); |
| 6962 | GenerateMiss(masm); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6963 | } |
| 6964 | |
| 6965 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6966 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6967 | ASSERT(state_ == CompareIC::OBJECTS); |
| 6968 | Label miss; |
| 6969 | __ And(a2, a1, Operand(a0)); |
| 6970 | __ JumpIfSmi(a2, &miss); |
| 6971 | |
| 6972 | __ GetObjectType(a0, a2, a2); |
| 6973 | __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE)); |
| 6974 | __ GetObjectType(a1, a2, a2); |
| 6975 | __ Branch(&miss, ne, a2, Operand(JS_OBJECT_TYPE)); |
| 6976 | |
| 6977 | ASSERT(GetCondition() == eq); |
| 6978 | __ Subu(v0, a0, Operand(a1)); |
| 6979 | __ Ret(); |
| 6980 | |
| 6981 | __ bind(&miss); |
| 6982 | GenerateMiss(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6983 | } |
| 6984 | |
| 6985 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6986 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 6987 | Label miss; |
| 6988 | __ And(a2, a1, a0); |
| 6989 | __ JumpIfSmi(a2, &miss); |
| 6990 | __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset)); |
| 6991 | __ lw(a3, FieldMemOperand(a1, HeapObject::kMapOffset)); |
| 6992 | __ Branch(&miss, ne, a2, Operand(known_map_)); |
| 6993 | __ Branch(&miss, ne, a3, Operand(known_map_)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6994 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6995 | __ Ret(USE_DELAY_SLOT); |
| 6996 | __ subu(v0, a0, a1); |
| 6997 | |
| 6998 | __ bind(&miss); |
| 6999 | GenerateMiss(masm); |
| 7000 | } |
| 7001 | |
| 7002 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7003 | { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7004 | // Call the runtime system in a fresh internal frame. |
| 7005 | ExternalReference miss = |
| 7006 | ExternalReference(IC_Utility(IC::kCompareIC_Miss), masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7007 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 7008 | __ Push(a1, a0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7009 | __ push(ra); |
| 7010 | __ Push(a1, a0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7011 | __ li(t0, Operand(Smi::FromInt(op_))); |
| 7012 | __ push(t0); |
| 7013 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7014 | // Compute the entry point of the rewritten stub. |
| 7015 | __ Addu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 7016 | // Restore registers. |
| 7017 | __ Pop(a1, a0, ra); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7018 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7019 | __ Jump(a2); |
| 7020 | } |
| 7021 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 7022 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7023 | void DirectCEntryStub::Generate(MacroAssembler* masm) { |
| 7024 | // No need to pop or drop anything, LeaveExitFrame will restore the old |
| 7025 | // stack, thus dropping the allocated space for the return value. |
| 7026 | // The saved ra is after the reserved stack space for the 4 args. |
| 7027 | __ lw(t9, MemOperand(sp, kCArgsSlotsSize)); |
| 7028 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7029 | if (FLAG_debug_code && FLAG_enable_slow_asserts) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7030 | // In case of an error the return address may point to a memory area |
| 7031 | // filled with kZapValue by the GC. |
| 7032 | // Dereference the address and check for this. |
| 7033 | __ lw(t0, MemOperand(t9)); |
| 7034 | __ Assert(ne, "Received invalid return address.", t0, |
| 7035 | Operand(reinterpret_cast<uint32_t>(kZapValue))); |
| 7036 | } |
| 7037 | __ Jump(t9); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 7038 | } |
| 7039 | |
| 7040 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7041 | void DirectCEntryStub::GenerateCall(MacroAssembler* masm, |
| 7042 | ExternalReference function) { |
| 7043 | __ li(t9, Operand(function)); |
| 7044 | this->GenerateCall(masm, t9); |
| 7045 | } |
| 7046 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 7047 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7048 | void DirectCEntryStub::GenerateCall(MacroAssembler* masm, |
| 7049 | Register target) { |
| 7050 | __ Move(t9, target); |
| 7051 | __ AssertStackIsAligned(); |
| 7052 | // Allocate space for arg slots. |
| 7053 | __ Subu(sp, sp, kCArgsSlotsSize); |
| 7054 | |
| 7055 | // Block the trampoline pool through the whole function to make sure the |
| 7056 | // number of generated instructions is constant. |
| 7057 | Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm); |
| 7058 | |
| 7059 | // We need to get the current 'pc' value, which is not available on MIPS. |
| 7060 | Label find_ra; |
| 7061 | masm->bal(&find_ra); // ra = pc + 8. |
| 7062 | masm->nop(); // Branch delay slot nop. |
| 7063 | masm->bind(&find_ra); |
| 7064 | |
| 7065 | const int kNumInstructionsToJump = 6; |
| 7066 | masm->addiu(ra, ra, kNumInstructionsToJump * kPointerSize); |
| 7067 | // Push return address (accessible to GC through exit frame pc). |
| 7068 | // This spot for ra was reserved in EnterExitFrame. |
| 7069 | masm->sw(ra, MemOperand(sp, kCArgsSlotsSize)); |
| 7070 | masm->li(ra, Operand(reinterpret_cast<intptr_t>(GetCode().location()), |
| 7071 | RelocInfo::CODE_TARGET), true); |
| 7072 | // Call the function. |
| 7073 | masm->Jump(t9); |
| 7074 | // Make sure the stored 'ra' points to this position. |
| 7075 | ASSERT_EQ(kNumInstructionsToJump, masm->InstructionsGeneratedSince(&find_ra)); |
| 7076 | } |
| 7077 | |
| 7078 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7079 | void StringDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 7080 | Label* miss, |
| 7081 | Label* done, |
| 7082 | Register receiver, |
| 7083 | Register properties, |
| 7084 | Handle<String> name, |
| 7085 | Register scratch0) { |
| 7086 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7087 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7088 | // undefined value), it guarantees the hash table doesn't contain the |
| 7089 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7090 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7091 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7092 | // scratch0 points to properties hash. |
| 7093 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7094 | Register index = scratch0; |
| 7095 | // Capacity is smi 2^n. |
| 7096 | __ lw(index, FieldMemOperand(properties, kCapacityOffset)); |
| 7097 | __ Subu(index, index, Operand(1)); |
| 7098 | __ And(index, index, Operand( |
| 7099 | Smi::FromInt(name->Hash() + StringDictionary::GetProbeOffset(i)))); |
| 7100 | |
| 7101 | // Scale the index by multiplying by the entry size. |
| 7102 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7103 | __ sll(at, index, 1); |
| 7104 | __ Addu(index, index, at); |
| 7105 | |
| 7106 | Register entity_name = scratch0; |
| 7107 | // Having undefined at this place means the name is not contained. |
| 7108 | ASSERT_EQ(kSmiTagSize, 1); |
| 7109 | Register tmp = properties; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7110 | __ sll(scratch0, index, 1); |
| 7111 | __ Addu(tmp, properties, scratch0); |
| 7112 | __ lw(entity_name, FieldMemOperand(tmp, kElementsStartOffset)); |
| 7113 | |
| 7114 | ASSERT(!tmp.is(entity_name)); |
| 7115 | __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex); |
| 7116 | __ Branch(done, eq, entity_name, Operand(tmp)); |
| 7117 | |
| 7118 | if (i != kInlinedProbes - 1) { |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7119 | // Load the hole ready for use below: |
| 7120 | __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex); |
| 7121 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7122 | // Stop if found the property. |
| 7123 | __ Branch(miss, eq, entity_name, Operand(Handle<String>(name))); |
| 7124 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7125 | Label the_hole; |
| 7126 | __ Branch(&the_hole, eq, entity_name, Operand(tmp)); |
| 7127 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7128 | // Check if the entry name is not a symbol. |
| 7129 | __ lw(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset)); |
| 7130 | __ lbu(entity_name, |
| 7131 | FieldMemOperand(entity_name, Map::kInstanceTypeOffset)); |
| 7132 | __ And(scratch0, entity_name, Operand(kIsSymbolMask)); |
| 7133 | __ Branch(miss, eq, scratch0, Operand(zero_reg)); |
| 7134 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7135 | __ bind(&the_hole); |
| 7136 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7137 | // Restore the properties. |
| 7138 | __ lw(properties, |
| 7139 | FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 7140 | } |
| 7141 | } |
| 7142 | |
| 7143 | const int spill_mask = |
| 7144 | (ra.bit() | t2.bit() | t1.bit() | t0.bit() | a3.bit() | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7145 | a2.bit() | a1.bit() | a0.bit() | v0.bit()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7146 | |
| 7147 | __ MultiPush(spill_mask); |
| 7148 | __ lw(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 7149 | __ li(a1, Operand(Handle<String>(name))); |
| 7150 | StringDictionaryLookupStub stub(NEGATIVE_LOOKUP); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7151 | __ CallStub(&stub); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7152 | __ mov(at, v0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7153 | __ MultiPop(spill_mask); |
| 7154 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7155 | __ Branch(done, eq, at, Operand(zero_reg)); |
| 7156 | __ Branch(miss, ne, at, Operand(zero_reg)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7157 | } |
| 7158 | |
| 7159 | |
| 7160 | // Probe the string dictionary in the |elements| register. Jump to the |
| 7161 | // |done| label if a property with the given name is found. Jump to |
| 7162 | // the |miss| label otherwise. |
| 7163 | // If lookup was successful |scratch2| will be equal to elements + 4 * index. |
| 7164 | void StringDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 7165 | Label* miss, |
| 7166 | Label* done, |
| 7167 | Register elements, |
| 7168 | Register name, |
| 7169 | Register scratch1, |
| 7170 | Register scratch2) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7171 | ASSERT(!elements.is(scratch1)); |
| 7172 | ASSERT(!elements.is(scratch2)); |
| 7173 | ASSERT(!name.is(scratch1)); |
| 7174 | ASSERT(!name.is(scratch2)); |
| 7175 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7176 | // Assert that name contains a string. |
| 7177 | if (FLAG_debug_code) __ AbortIfNotString(name); |
| 7178 | |
| 7179 | // Compute the capacity mask. |
| 7180 | __ lw(scratch1, FieldMemOperand(elements, kCapacityOffset)); |
| 7181 | __ sra(scratch1, scratch1, kSmiTagSize); // convert smi to int |
| 7182 | __ Subu(scratch1, scratch1, Operand(1)); |
| 7183 | |
| 7184 | // Generate an unrolled loop that performs a few probes before |
| 7185 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 7186 | // cover ~93% of loads from dictionaries. |
| 7187 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7188 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7189 | __ lw(scratch2, FieldMemOperand(name, String::kHashFieldOffset)); |
| 7190 | if (i > 0) { |
| 7191 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 7192 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 7193 | // shifted in the following and instruction. |
| 7194 | ASSERT(StringDictionary::GetProbeOffset(i) < |
| 7195 | 1 << (32 - String::kHashFieldOffset)); |
| 7196 | __ Addu(scratch2, scratch2, Operand( |
| 7197 | StringDictionary::GetProbeOffset(i) << String::kHashShift)); |
| 7198 | } |
| 7199 | __ srl(scratch2, scratch2, String::kHashShift); |
| 7200 | __ And(scratch2, scratch1, scratch2); |
| 7201 | |
| 7202 | // Scale the index by multiplying by the element size. |
| 7203 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7204 | // scratch2 = scratch2 * 3. |
| 7205 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7206 | __ sll(at, scratch2, 1); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7207 | __ Addu(scratch2, scratch2, at); |
| 7208 | |
| 7209 | // Check if the key is identical to the name. |
| 7210 | __ sll(at, scratch2, 2); |
| 7211 | __ Addu(scratch2, elements, at); |
| 7212 | __ lw(at, FieldMemOperand(scratch2, kElementsStartOffset)); |
| 7213 | __ Branch(done, eq, name, Operand(at)); |
| 7214 | } |
| 7215 | |
| 7216 | const int spill_mask = |
| 7217 | (ra.bit() | t2.bit() | t1.bit() | t0.bit() | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7218 | a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) & |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7219 | ~(scratch1.bit() | scratch2.bit()); |
| 7220 | |
| 7221 | __ MultiPush(spill_mask); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7222 | if (name.is(a0)) { |
| 7223 | ASSERT(!elements.is(a1)); |
| 7224 | __ Move(a1, name); |
| 7225 | __ Move(a0, elements); |
| 7226 | } else { |
| 7227 | __ Move(a0, elements); |
| 7228 | __ Move(a1, name); |
| 7229 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7230 | StringDictionaryLookupStub stub(POSITIVE_LOOKUP); |
| 7231 | __ CallStub(&stub); |
| 7232 | __ mov(scratch2, a2); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7233 | __ mov(at, v0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7234 | __ MultiPop(spill_mask); |
| 7235 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7236 | __ Branch(done, ne, at, Operand(zero_reg)); |
| 7237 | __ Branch(miss, eq, at, Operand(zero_reg)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7238 | } |
| 7239 | |
| 7240 | |
| 7241 | void StringDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7242 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 7243 | // we cannot call anything that could cause a GC from this stub. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7244 | // Registers: |
| 7245 | // result: StringDictionary to probe |
| 7246 | // a1: key |
| 7247 | // : StringDictionary to probe. |
| 7248 | // index_: will hold an index of entry if lookup is successful. |
| 7249 | // might alias with result_. |
| 7250 | // Returns: |
| 7251 | // result_ is zero if lookup failed, non zero otherwise. |
| 7252 | |
| 7253 | Register result = v0; |
| 7254 | Register dictionary = a0; |
| 7255 | Register key = a1; |
| 7256 | Register index = a2; |
| 7257 | Register mask = a3; |
| 7258 | Register hash = t0; |
| 7259 | Register undefined = t1; |
| 7260 | Register entry_key = t2; |
| 7261 | |
| 7262 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 7263 | |
| 7264 | __ lw(mask, FieldMemOperand(dictionary, kCapacityOffset)); |
| 7265 | __ sra(mask, mask, kSmiTagSize); |
| 7266 | __ Subu(mask, mask, Operand(1)); |
| 7267 | |
| 7268 | __ lw(hash, FieldMemOperand(key, String::kHashFieldOffset)); |
| 7269 | |
| 7270 | __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex); |
| 7271 | |
| 7272 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 7273 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7274 | // Capacity is smi 2^n. |
| 7275 | if (i > 0) { |
| 7276 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 7277 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 7278 | // shifted in the following and instruction. |
| 7279 | ASSERT(StringDictionary::GetProbeOffset(i) < |
| 7280 | 1 << (32 - String::kHashFieldOffset)); |
| 7281 | __ Addu(index, hash, Operand( |
| 7282 | StringDictionary::GetProbeOffset(i) << String::kHashShift)); |
| 7283 | } else { |
| 7284 | __ mov(index, hash); |
| 7285 | } |
| 7286 | __ srl(index, index, String::kHashShift); |
| 7287 | __ And(index, mask, index); |
| 7288 | |
| 7289 | // Scale the index by multiplying by the entry size. |
| 7290 | ASSERT(StringDictionary::kEntrySize == 3); |
| 7291 | // index *= 3. |
| 7292 | __ mov(at, index); |
| 7293 | __ sll(index, index, 1); |
| 7294 | __ Addu(index, index, at); |
| 7295 | |
| 7296 | |
| 7297 | ASSERT_EQ(kSmiTagSize, 1); |
| 7298 | __ sll(index, index, 2); |
| 7299 | __ Addu(index, index, dictionary); |
| 7300 | __ lw(entry_key, FieldMemOperand(index, kElementsStartOffset)); |
| 7301 | |
| 7302 | // Having undefined at this place means the name is not contained. |
| 7303 | __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined)); |
| 7304 | |
| 7305 | // Stop if found the property. |
| 7306 | __ Branch(&in_dictionary, eq, entry_key, Operand(key)); |
| 7307 | |
| 7308 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
| 7309 | // Check if the entry name is not a symbol. |
| 7310 | __ lw(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset)); |
| 7311 | __ lbu(entry_key, |
| 7312 | FieldMemOperand(entry_key, Map::kInstanceTypeOffset)); |
| 7313 | __ And(result, entry_key, Operand(kIsSymbolMask)); |
| 7314 | __ Branch(&maybe_in_dictionary, eq, result, Operand(zero_reg)); |
| 7315 | } |
| 7316 | } |
| 7317 | |
| 7318 | __ bind(&maybe_in_dictionary); |
| 7319 | // If we are doing negative lookup then probing failure should be |
| 7320 | // treated as a lookup success. For positive lookup probing failure |
| 7321 | // should be treated as lookup failure. |
| 7322 | if (mode_ == POSITIVE_LOOKUP) { |
| 7323 | __ mov(result, zero_reg); |
| 7324 | __ Ret(); |
| 7325 | } |
| 7326 | |
| 7327 | __ bind(&in_dictionary); |
| 7328 | __ li(result, 1); |
| 7329 | __ Ret(); |
| 7330 | |
| 7331 | __ bind(¬_in_dictionary); |
| 7332 | __ mov(result, zero_reg); |
| 7333 | __ Ret(); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 7334 | } |
| 7335 | |
| 7336 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 7337 | struct AheadOfTimeWriteBarrierStubList { |
| 7338 | Register object, value, address; |
| 7339 | RememberedSetAction action; |
| 7340 | }; |
| 7341 | |
| 7342 | |
| 7343 | struct AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
| 7344 | // Used in RegExpExecStub. |
| 7345 | { s2, s0, t3, EMIT_REMEMBERED_SET }, |
| 7346 | { s2, a2, t3, EMIT_REMEMBERED_SET }, |
| 7347 | // Used in CompileArrayPushCall. |
| 7348 | // Also used in StoreIC::GenerateNormal via GenerateDictionaryStore. |
| 7349 | // Also used in KeyedStoreIC::GenerateGeneric. |
| 7350 | { a3, t0, t1, EMIT_REMEMBERED_SET }, |
| 7351 | // Used in CompileStoreGlobal. |
| 7352 | { t0, a1, a2, OMIT_REMEMBERED_SET }, |
| 7353 | // Used in StoreStubCompiler::CompileStoreField via GenerateStoreField. |
| 7354 | { a1, a2, a3, EMIT_REMEMBERED_SET }, |
| 7355 | { a3, a2, a1, EMIT_REMEMBERED_SET }, |
| 7356 | // Used in KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
| 7357 | { a2, a1, a3, EMIT_REMEMBERED_SET }, |
| 7358 | { a3, a1, a2, EMIT_REMEMBERED_SET }, |
| 7359 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 7360 | { a3, a2, t0, EMIT_REMEMBERED_SET }, |
| 7361 | { a2, a3, t0, EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7362 | // ElementsTransitionGenerator::GenerateSmiOnlyToObject |
| 7363 | // and ElementsTransitionGenerator::GenerateSmiOnlyToDouble |
| 7364 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
| 7365 | { a2, a3, t5, EMIT_REMEMBERED_SET }, |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 7366 | { a2, a3, t5, OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7367 | // ElementsTransitionGenerator::GenerateDoubleToObject |
| 7368 | { t2, a2, a0, EMIT_REMEMBERED_SET }, |
| 7369 | { a2, t2, t5, EMIT_REMEMBERED_SET }, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7370 | // StoreArrayLiteralElementStub::Generate |
| 7371 | { t1, a0, t2, EMIT_REMEMBERED_SET }, |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 7372 | // Null termination. |
| 7373 | { no_reg, no_reg, no_reg, EMIT_REMEMBERED_SET} |
| 7374 | }; |
| 7375 | |
| 7376 | |
| 7377 | bool RecordWriteStub::IsPregenerated() { |
| 7378 | for (AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
| 7379 | !entry->object.is(no_reg); |
| 7380 | entry++) { |
| 7381 | if (object_.is(entry->object) && |
| 7382 | value_.is(entry->value) && |
| 7383 | address_.is(entry->address) && |
| 7384 | remembered_set_action_ == entry->action && |
| 7385 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7386 | return true; |
| 7387 | } |
| 7388 | } |
| 7389 | return false; |
| 7390 | } |
| 7391 | |
| 7392 | |
| 7393 | bool StoreBufferOverflowStub::IsPregenerated() { |
| 7394 | return save_doubles_ == kDontSaveFPRegs || ISOLATE->fp_stubs_generated(); |
| 7395 | } |
| 7396 | |
| 7397 | |
| 7398 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime() { |
| 7399 | StoreBufferOverflowStub stub1(kDontSaveFPRegs); |
| 7400 | stub1.GetCode()->set_is_pregenerated(true); |
| 7401 | } |
| 7402 | |
| 7403 | |
| 7404 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime() { |
| 7405 | for (AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
| 7406 | !entry->object.is(no_reg); |
| 7407 | entry++) { |
| 7408 | RecordWriteStub stub(entry->object, |
| 7409 | entry->value, |
| 7410 | entry->address, |
| 7411 | entry->action, |
| 7412 | kDontSaveFPRegs); |
| 7413 | stub.GetCode()->set_is_pregenerated(true); |
| 7414 | } |
| 7415 | } |
| 7416 | |
| 7417 | |
| 7418 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7419 | // the value has just been written into the object, now this stub makes sure |
| 7420 | // we keep the GC informed. The word in the object where the value has been |
| 7421 | // written is in the address register. |
| 7422 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7423 | Label skip_to_incremental_noncompacting; |
| 7424 | Label skip_to_incremental_compacting; |
| 7425 | |
| 7426 | // The first two branch+nop instructions are generated with labels so as to |
| 7427 | // get the offset fixed up correctly by the bind(Label*) call. We patch it |
| 7428 | // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this |
| 7429 | // position) and the "beq zero_reg, zero_reg, ..." when we start and stop |
| 7430 | // incremental heap marking. |
| 7431 | // See RecordWriteStub::Patch for details. |
| 7432 | __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting); |
| 7433 | __ nop(); |
| 7434 | __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting); |
| 7435 | __ nop(); |
| 7436 | |
| 7437 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7438 | __ RememberedSetHelper(object_, |
| 7439 | address_, |
| 7440 | value_, |
| 7441 | save_fp_regs_mode_, |
| 7442 | MacroAssembler::kReturnAtEnd); |
| 7443 | } |
| 7444 | __ Ret(); |
| 7445 | |
| 7446 | __ bind(&skip_to_incremental_noncompacting); |
| 7447 | GenerateIncremental(masm, INCREMENTAL); |
| 7448 | |
| 7449 | __ bind(&skip_to_incremental_compacting); |
| 7450 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7451 | |
| 7452 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7453 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7454 | |
| 7455 | PatchBranchIntoNop(masm, 0); |
| 7456 | PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize); |
| 7457 | } |
| 7458 | |
| 7459 | |
| 7460 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7461 | regs_.Save(masm); |
| 7462 | |
| 7463 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7464 | Label dont_need_remembered_set; |
| 7465 | |
| 7466 | __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0)); |
| 7467 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7468 | regs_.scratch0(), |
| 7469 | &dont_need_remembered_set); |
| 7470 | |
| 7471 | __ CheckPageFlag(regs_.object(), |
| 7472 | regs_.scratch0(), |
| 7473 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7474 | ne, |
| 7475 | &dont_need_remembered_set); |
| 7476 | |
| 7477 | // First notify the incremental marker if necessary, then update the |
| 7478 | // remembered set. |
| 7479 | CheckNeedsToInformIncrementalMarker( |
| 7480 | masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode); |
| 7481 | InformIncrementalMarker(masm, mode); |
| 7482 | regs_.Restore(masm); |
| 7483 | __ RememberedSetHelper(object_, |
| 7484 | address_, |
| 7485 | value_, |
| 7486 | save_fp_regs_mode_, |
| 7487 | MacroAssembler::kReturnAtEnd); |
| 7488 | |
| 7489 | __ bind(&dont_need_remembered_set); |
| 7490 | } |
| 7491 | |
| 7492 | CheckNeedsToInformIncrementalMarker( |
| 7493 | masm, kReturnOnNoNeedToInformIncrementalMarker, mode); |
| 7494 | InformIncrementalMarker(masm, mode); |
| 7495 | regs_.Restore(masm); |
| 7496 | __ Ret(); |
| 7497 | } |
| 7498 | |
| 7499 | |
| 7500 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7501 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7502 | int argument_count = 3; |
| 7503 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7504 | Register address = |
| 7505 | a0.is(regs_.address()) ? regs_.scratch0() : regs_.address(); |
| 7506 | ASSERT(!address.is(regs_.object())); |
| 7507 | ASSERT(!address.is(a0)); |
| 7508 | __ Move(address, regs_.address()); |
| 7509 | __ Move(a0, regs_.object()); |
| 7510 | if (mode == INCREMENTAL_COMPACTION) { |
| 7511 | __ Move(a1, address); |
| 7512 | } else { |
| 7513 | ASSERT(mode == INCREMENTAL); |
| 7514 | __ lw(a1, MemOperand(address, 0)); |
| 7515 | } |
| 7516 | __ li(a2, Operand(ExternalReference::isolate_address())); |
| 7517 | |
| 7518 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7519 | if (mode == INCREMENTAL_COMPACTION) { |
| 7520 | __ CallCFunction( |
| 7521 | ExternalReference::incremental_evacuation_record_write_function( |
| 7522 | masm->isolate()), |
| 7523 | argument_count); |
| 7524 | } else { |
| 7525 | ASSERT(mode == INCREMENTAL); |
| 7526 | __ CallCFunction( |
| 7527 | ExternalReference::incremental_marking_record_write_function( |
| 7528 | masm->isolate()), |
| 7529 | argument_count); |
| 7530 | } |
| 7531 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7532 | } |
| 7533 | |
| 7534 | |
| 7535 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7536 | MacroAssembler* masm, |
| 7537 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7538 | Mode mode) { |
| 7539 | Label on_black; |
| 7540 | Label need_incremental; |
| 7541 | Label need_incremental_pop_scratch; |
| 7542 | |
| 7543 | // Let's look at the color of the object: If it is not black we don't have |
| 7544 | // to inform the incremental marker. |
| 7545 | __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black); |
| 7546 | |
| 7547 | regs_.Restore(masm); |
| 7548 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7549 | __ RememberedSetHelper(object_, |
| 7550 | address_, |
| 7551 | value_, |
| 7552 | save_fp_regs_mode_, |
| 7553 | MacroAssembler::kReturnAtEnd); |
| 7554 | } else { |
| 7555 | __ Ret(); |
| 7556 | } |
| 7557 | |
| 7558 | __ bind(&on_black); |
| 7559 | |
| 7560 | // Get the value from the slot. |
| 7561 | __ lw(regs_.scratch0(), MemOperand(regs_.address(), 0)); |
| 7562 | |
| 7563 | if (mode == INCREMENTAL_COMPACTION) { |
| 7564 | Label ensure_not_white; |
| 7565 | |
| 7566 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7567 | regs_.scratch1(), // Scratch. |
| 7568 | MemoryChunk::kEvacuationCandidateMask, |
| 7569 | eq, |
| 7570 | &ensure_not_white); |
| 7571 | |
| 7572 | __ CheckPageFlag(regs_.object(), |
| 7573 | regs_.scratch1(), // Scratch. |
| 7574 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7575 | eq, |
| 7576 | &need_incremental); |
| 7577 | |
| 7578 | __ bind(&ensure_not_white); |
| 7579 | } |
| 7580 | |
| 7581 | // We need extra registers for this, so we push the object and the address |
| 7582 | // register temporarily. |
| 7583 | __ Push(regs_.object(), regs_.address()); |
| 7584 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7585 | regs_.scratch1(), // Scratch. |
| 7586 | regs_.object(), // Scratch. |
| 7587 | regs_.address(), // Scratch. |
| 7588 | &need_incremental_pop_scratch); |
| 7589 | __ Pop(regs_.object(), regs_.address()); |
| 7590 | |
| 7591 | regs_.Restore(masm); |
| 7592 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7593 | __ RememberedSetHelper(object_, |
| 7594 | address_, |
| 7595 | value_, |
| 7596 | save_fp_regs_mode_, |
| 7597 | MacroAssembler::kReturnAtEnd); |
| 7598 | } else { |
| 7599 | __ Ret(); |
| 7600 | } |
| 7601 | |
| 7602 | __ bind(&need_incremental_pop_scratch); |
| 7603 | __ Pop(regs_.object(), regs_.address()); |
| 7604 | |
| 7605 | __ bind(&need_incremental); |
| 7606 | |
| 7607 | // Fall through when we need to inform the incremental marker. |
| 7608 | } |
| 7609 | |
| 7610 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7611 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7612 | // ----------- S t a t e ------------- |
| 7613 | // -- a0 : element value to store |
| 7614 | // -- a1 : array literal |
| 7615 | // -- a2 : map of array literal |
| 7616 | // -- a3 : element index as smi |
| 7617 | // -- t0 : array literal index in function as smi |
| 7618 | // ----------------------------------- |
| 7619 | |
| 7620 | Label element_done; |
| 7621 | Label double_elements; |
| 7622 | Label smi_element; |
| 7623 | Label slow_elements; |
| 7624 | Label fast_elements; |
| 7625 | |
| 7626 | __ CheckFastElements(a2, t1, &double_elements); |
| 7627 | // FAST_SMI_ONLY_ELEMENTS or FAST_ELEMENTS |
| 7628 | __ JumpIfSmi(a0, &smi_element); |
| 7629 | __ CheckFastSmiOnlyElements(a2, t1, &fast_elements); |
| 7630 | |
| 7631 | // Store into the array literal requires a elements transition. Call into |
| 7632 | // the runtime. |
| 7633 | __ bind(&slow_elements); |
| 7634 | // call. |
| 7635 | __ Push(a1, a3, a0); |
| 7636 | __ lw(t1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7637 | __ lw(t1, FieldMemOperand(t1, JSFunction::kLiteralsOffset)); |
| 7638 | __ Push(t1, t0); |
| 7639 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7640 | |
| 7641 | // Array literal has ElementsKind of FAST_ELEMENTS and value is an object. |
| 7642 | __ bind(&fast_elements); |
| 7643 | __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset)); |
| 7644 | __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize); |
| 7645 | __ Addu(t2, t1, t2); |
| 7646 | __ Addu(t2, t2, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 7647 | __ sw(a0, MemOperand(t2, 0)); |
| 7648 | // Update the write barrier for the array store. |
| 7649 | __ RecordWrite(t1, t2, a0, kRAHasNotBeenSaved, kDontSaveFPRegs, |
| 7650 | EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7651 | __ Ret(USE_DELAY_SLOT); |
| 7652 | __ mov(v0, a0); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7653 | |
| 7654 | // Array literal has ElementsKind of FAST_SMI_ONLY_ELEMENTS or |
| 7655 | // FAST_ELEMENTS, and value is Smi. |
| 7656 | __ bind(&smi_element); |
| 7657 | __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset)); |
| 7658 | __ sll(t2, a3, kPointerSizeLog2 - kSmiTagSize); |
| 7659 | __ Addu(t2, t1, t2); |
| 7660 | __ sw(a0, FieldMemOperand(t2, FixedArray::kHeaderSize)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7661 | __ Ret(USE_DELAY_SLOT); |
| 7662 | __ mov(v0, a0); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7663 | |
| 7664 | // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS. |
| 7665 | __ bind(&double_elements); |
| 7666 | __ lw(t1, FieldMemOperand(a1, JSObject::kElementsOffset)); |
| 7667 | __ StoreNumberToDoubleElements(a0, a3, a1, t1, t2, t3, t5, t6, |
| 7668 | &slow_elements); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7669 | __ Ret(USE_DELAY_SLOT); |
| 7670 | __ mov(v0, a0); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7671 | } |
| 7672 | |
| 7673 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 7674 | #undef __ |
| 7675 | |
| 7676 | } } // namespace v8::internal |
| 7677 | |
| 7678 | #endif // V8_TARGET_ARCH_MIPS |