Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #if V8_TARGET_ARCH_MIPS64 |
| 6 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7 | #include "src/code-stubs.h" |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 8 | #include "src/api-arguments.h" |
| 9 | #include "src/bootstrapper.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10 | #include "src/codegen.h" |
| 11 | #include "src/ic/handler-compiler.h" |
| 12 | #include "src/ic/ic.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 13 | #include "src/ic/stub-cache.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 14 | #include "src/isolate.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 15 | #include "src/mips64/code-stubs-mips64.h" |
| 16 | #include "src/regexp/jsregexp.h" |
| 17 | #include "src/regexp/regexp-macro-assembler.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 18 | #include "src/runtime/runtime.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 19 | |
| 20 | namespace v8 { |
| 21 | namespace internal { |
| 22 | |
| 23 | |
| 24 | static void InitializeArrayConstructorDescriptor( |
| 25 | Isolate* isolate, CodeStubDescriptor* descriptor, |
| 26 | int constant_stack_parameter_count) { |
| 27 | Address deopt_handler = Runtime::FunctionForId( |
| 28 | Runtime::kArrayConstructor)->entry; |
| 29 | |
| 30 | if (constant_stack_parameter_count == 0) { |
| 31 | descriptor->Initialize(deopt_handler, constant_stack_parameter_count, |
| 32 | JS_FUNCTION_STUB_MODE); |
| 33 | } else { |
| 34 | descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 35 | JS_FUNCTION_STUB_MODE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
| 39 | |
| 40 | static void InitializeInternalArrayConstructorDescriptor( |
| 41 | Isolate* isolate, CodeStubDescriptor* descriptor, |
| 42 | int constant_stack_parameter_count) { |
| 43 | Address deopt_handler = Runtime::FunctionForId( |
| 44 | Runtime::kInternalArrayConstructor)->entry; |
| 45 | |
| 46 | if (constant_stack_parameter_count == 0) { |
| 47 | descriptor->Initialize(deopt_handler, constant_stack_parameter_count, |
| 48 | JS_FUNCTION_STUB_MODE); |
| 49 | } else { |
| 50 | descriptor->Initialize(a0, deopt_handler, constant_stack_parameter_count, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 51 | JS_FUNCTION_STUB_MODE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | |
| 55 | |
| 56 | void ArrayNoArgumentConstructorStub::InitializeDescriptor( |
| 57 | CodeStubDescriptor* descriptor) { |
| 58 | InitializeArrayConstructorDescriptor(isolate(), descriptor, 0); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | void ArraySingleArgumentConstructorStub::InitializeDescriptor( |
| 63 | CodeStubDescriptor* descriptor) { |
| 64 | InitializeArrayConstructorDescriptor(isolate(), descriptor, 1); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | void ArrayNArgumentsConstructorStub::InitializeDescriptor( |
| 69 | CodeStubDescriptor* descriptor) { |
| 70 | InitializeArrayConstructorDescriptor(isolate(), descriptor, -1); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | void InternalArrayNoArgumentConstructorStub::InitializeDescriptor( |
| 75 | CodeStubDescriptor* descriptor) { |
| 76 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0); |
| 77 | } |
| 78 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 79 | void FastArrayPushStub::InitializeDescriptor(CodeStubDescriptor* descriptor) { |
| 80 | Address deopt_handler = Runtime::FunctionForId(Runtime::kArrayPush)->entry; |
| 81 | descriptor->Initialize(a0, deopt_handler, -1, JS_FUNCTION_STUB_MODE); |
| 82 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 83 | |
| 84 | void InternalArraySingleArgumentConstructorStub::InitializeDescriptor( |
| 85 | CodeStubDescriptor* descriptor) { |
| 86 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | void InternalArrayNArgumentsConstructorStub::InitializeDescriptor( |
| 91 | CodeStubDescriptor* descriptor) { |
| 92 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | #define __ ACCESS_MASM(masm) |
| 97 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 98 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 99 | Condition cc); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 100 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 101 | Register lhs, |
| 102 | Register rhs, |
| 103 | Label* rhs_not_nan, |
| 104 | Label* slow, |
| 105 | bool strict); |
| 106 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 107 | Register lhs, |
| 108 | Register rhs); |
| 109 | |
| 110 | |
| 111 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm, |
| 112 | ExternalReference miss) { |
| 113 | // Update the static counter each time a new code stub is generated. |
| 114 | isolate()->counters()->code_stubs()->Increment(); |
| 115 | |
| 116 | CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 117 | int param_count = descriptor.GetRegisterParameterCount(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 118 | { |
| 119 | // Call the runtime system in a fresh internal frame. |
| 120 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 121 | DCHECK((param_count == 0) || |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 122 | a0.is(descriptor.GetRegisterParameter(param_count - 1))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 123 | // Push arguments, adjust sp. |
| 124 | __ Dsubu(sp, sp, Operand(param_count * kPointerSize)); |
| 125 | for (int i = 0; i < param_count; ++i) { |
| 126 | // Store argument to stack. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 127 | __ sd(descriptor.GetRegisterParameter(i), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 128 | MemOperand(sp, (param_count - 1 - i) * kPointerSize)); |
| 129 | } |
| 130 | __ CallExternalReference(miss, param_count); |
| 131 | } |
| 132 | |
| 133 | __ Ret(); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 138 | Label out_of_range, only_low, negate, done; |
| 139 | Register input_reg = source(); |
| 140 | Register result_reg = destination(); |
| 141 | |
| 142 | int double_offset = offset(); |
| 143 | // Account for saved regs if input is sp. |
| 144 | if (input_reg.is(sp)) double_offset += 3 * kPointerSize; |
| 145 | |
| 146 | Register scratch = |
| 147 | GetRegisterThatIsNotOneOf(input_reg, result_reg); |
| 148 | Register scratch2 = |
| 149 | GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch); |
| 150 | Register scratch3 = |
| 151 | GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch2); |
| 152 | DoubleRegister double_scratch = kLithiumScratchDouble; |
| 153 | |
| 154 | __ Push(scratch, scratch2, scratch3); |
| 155 | if (!skip_fastpath()) { |
| 156 | // Load double input. |
| 157 | __ ldc1(double_scratch, MemOperand(input_reg, double_offset)); |
| 158 | |
| 159 | // Clear cumulative exception flags and save the FCSR. |
| 160 | __ cfc1(scratch2, FCSR); |
| 161 | __ ctc1(zero_reg, FCSR); |
| 162 | |
| 163 | // Try a conversion to a signed integer. |
| 164 | __ Trunc_w_d(double_scratch, double_scratch); |
| 165 | // Move the converted value into the result register. |
| 166 | __ mfc1(scratch3, double_scratch); |
| 167 | |
| 168 | // Retrieve and restore the FCSR. |
| 169 | __ cfc1(scratch, FCSR); |
| 170 | __ ctc1(scratch2, FCSR); |
| 171 | |
| 172 | // Check for overflow and NaNs. |
| 173 | __ And( |
| 174 | scratch, scratch, |
| 175 | kFCSROverflowFlagMask | kFCSRUnderflowFlagMask |
| 176 | | kFCSRInvalidOpFlagMask); |
| 177 | // If we had no exceptions then set result_reg and we are done. |
| 178 | Label error; |
| 179 | __ Branch(&error, ne, scratch, Operand(zero_reg)); |
| 180 | __ Move(result_reg, scratch3); |
| 181 | __ Branch(&done); |
| 182 | __ bind(&error); |
| 183 | } |
| 184 | |
| 185 | // Load the double value and perform a manual truncation. |
| 186 | Register input_high = scratch2; |
| 187 | Register input_low = scratch3; |
| 188 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 189 | __ lw(input_low, |
| 190 | MemOperand(input_reg, double_offset + Register::kMantissaOffset)); |
| 191 | __ lw(input_high, |
| 192 | MemOperand(input_reg, double_offset + Register::kExponentOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 193 | |
| 194 | Label normal_exponent, restore_sign; |
| 195 | // Extract the biased exponent in result. |
| 196 | __ Ext(result_reg, |
| 197 | input_high, |
| 198 | HeapNumber::kExponentShift, |
| 199 | HeapNumber::kExponentBits); |
| 200 | |
| 201 | // Check for Infinity and NaNs, which should return 0. |
| 202 | __ Subu(scratch, result_reg, HeapNumber::kExponentMask); |
| 203 | __ Movz(result_reg, zero_reg, scratch); |
| 204 | __ Branch(&done, eq, scratch, Operand(zero_reg)); |
| 205 | |
| 206 | // Express exponent as delta to (number of mantissa bits + 31). |
| 207 | __ Subu(result_reg, |
| 208 | result_reg, |
| 209 | Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31)); |
| 210 | |
| 211 | // If the delta is strictly positive, all bits would be shifted away, |
| 212 | // which means that we can return 0. |
| 213 | __ Branch(&normal_exponent, le, result_reg, Operand(zero_reg)); |
| 214 | __ mov(result_reg, zero_reg); |
| 215 | __ Branch(&done); |
| 216 | |
| 217 | __ bind(&normal_exponent); |
| 218 | const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 219 | // Calculate shift. |
| 220 | __ Addu(scratch, result_reg, Operand(kShiftBase + HeapNumber::kMantissaBits)); |
| 221 | |
| 222 | // Save the sign. |
| 223 | Register sign = result_reg; |
| 224 | result_reg = no_reg; |
| 225 | __ And(sign, input_high, Operand(HeapNumber::kSignMask)); |
| 226 | |
| 227 | // On ARM shifts > 31 bits are valid and will result in zero. On MIPS we need |
| 228 | // to check for this specific case. |
| 229 | Label high_shift_needed, high_shift_done; |
| 230 | __ Branch(&high_shift_needed, lt, scratch, Operand(32)); |
| 231 | __ mov(input_high, zero_reg); |
| 232 | __ Branch(&high_shift_done); |
| 233 | __ bind(&high_shift_needed); |
| 234 | |
| 235 | // Set the implicit 1 before the mantissa part in input_high. |
| 236 | __ Or(input_high, |
| 237 | input_high, |
| 238 | Operand(1 << HeapNumber::kMantissaBitsInTopWord)); |
| 239 | // Shift the mantissa bits to the correct position. |
| 240 | // We don't need to clear non-mantissa bits as they will be shifted away. |
| 241 | // If they weren't, it would mean that the answer is in the 32bit range. |
| 242 | __ sllv(input_high, input_high, scratch); |
| 243 | |
| 244 | __ bind(&high_shift_done); |
| 245 | |
| 246 | // Replace the shifted bits with bits from the lower mantissa word. |
| 247 | Label pos_shift, shift_done; |
| 248 | __ li(at, 32); |
| 249 | __ subu(scratch, at, scratch); |
| 250 | __ Branch(&pos_shift, ge, scratch, Operand(zero_reg)); |
| 251 | |
| 252 | // Negate scratch. |
| 253 | __ Subu(scratch, zero_reg, scratch); |
| 254 | __ sllv(input_low, input_low, scratch); |
| 255 | __ Branch(&shift_done); |
| 256 | |
| 257 | __ bind(&pos_shift); |
| 258 | __ srlv(input_low, input_low, scratch); |
| 259 | |
| 260 | __ bind(&shift_done); |
| 261 | __ Or(input_high, input_high, Operand(input_low)); |
| 262 | // Restore sign if necessary. |
| 263 | __ mov(scratch, sign); |
| 264 | result_reg = sign; |
| 265 | sign = no_reg; |
| 266 | __ Subu(result_reg, zero_reg, input_high); |
| 267 | __ Movz(result_reg, input_high, scratch); |
| 268 | |
| 269 | __ bind(&done); |
| 270 | |
| 271 | __ Pop(scratch, scratch2, scratch3); |
| 272 | __ Ret(); |
| 273 | } |
| 274 | |
| 275 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 276 | // Handle the case where the lhs and rhs are the same object. |
| 277 | // Equality is almost reflexive (everything but NaN), so this is a test |
| 278 | // for "identity and not NaN". |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 279 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 280 | Condition cc) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 281 | Label not_identical; |
| 282 | Label heap_number, return_equal; |
| 283 | Register exp_mask_reg = t1; |
| 284 | |
| 285 | __ Branch(¬_identical, ne, a0, Operand(a1)); |
| 286 | |
| 287 | __ li(exp_mask_reg, Operand(HeapNumber::kExponentMask)); |
| 288 | |
| 289 | // Test for NaN. Sadly, we can't just compare to Factory::nan_value(), |
| 290 | // so we do the second best thing - test it ourselves. |
| 291 | // They are both equal and they are not both Smis so both of them are not |
| 292 | // Smis. If it's not a heap number, then return equal. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 293 | __ GetObjectType(a0, t0, t0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 294 | if (cc == less || cc == greater) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 295 | // Call runtime on identical JSObjects. |
| 296 | __ Branch(slow, greater, t0, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 297 | // Call runtime on identical symbols since we need to throw a TypeError. |
| 298 | __ Branch(slow, eq, t0, Operand(SYMBOL_TYPE)); |
| 299 | // Call runtime on identical SIMD values since we must throw a TypeError. |
| 300 | __ Branch(slow, eq, t0, Operand(SIMD128_VALUE_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 301 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 302 | __ Branch(&heap_number, eq, t0, Operand(HEAP_NUMBER_TYPE)); |
| 303 | // Comparing JS objects with <=, >= is complicated. |
| 304 | if (cc != eq) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 305 | __ Branch(slow, greater, t0, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 306 | // Call runtime on identical symbols since we need to throw a TypeError. |
| 307 | __ Branch(slow, eq, t0, Operand(SYMBOL_TYPE)); |
| 308 | // Call runtime on identical SIMD values since we must throw a TypeError. |
| 309 | __ Branch(slow, eq, t0, Operand(SIMD128_VALUE_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 310 | // Normally here we fall through to return_equal, but undefined is |
| 311 | // special: (undefined == undefined) == true, but |
| 312 | // (undefined <= undefined) == false! See ECMAScript 11.8.5. |
| 313 | if (cc == less_equal || cc == greater_equal) { |
| 314 | __ Branch(&return_equal, ne, t0, Operand(ODDBALL_TYPE)); |
| 315 | __ LoadRoot(a6, Heap::kUndefinedValueRootIndex); |
| 316 | __ Branch(&return_equal, ne, a0, Operand(a6)); |
| 317 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 318 | __ Ret(USE_DELAY_SLOT); |
| 319 | if (cc == le) { |
| 320 | // undefined <= undefined should fail. |
| 321 | __ li(v0, Operand(GREATER)); |
| 322 | } else { |
| 323 | // undefined >= undefined should fail. |
| 324 | __ li(v0, Operand(LESS)); |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | __ bind(&return_equal); |
| 331 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 332 | __ Ret(USE_DELAY_SLOT); |
| 333 | if (cc == less) { |
| 334 | __ li(v0, Operand(GREATER)); // Things aren't less than themselves. |
| 335 | } else if (cc == greater) { |
| 336 | __ li(v0, Operand(LESS)); // Things aren't greater than themselves. |
| 337 | } else { |
| 338 | __ mov(v0, zero_reg); // Things are <=, >=, ==, === themselves. |
| 339 | } |
| 340 | // For less and greater we don't have to check for NaN since the result of |
| 341 | // x < x is false regardless. For the others here is some code to check |
| 342 | // for NaN. |
| 343 | if (cc != lt && cc != gt) { |
| 344 | __ bind(&heap_number); |
| 345 | // It is a heap number, so return non-equal if it's NaN and equal if it's |
| 346 | // not NaN. |
| 347 | |
| 348 | // The representation of NaN values has all exponent bits (52..62) set, |
| 349 | // and not all mantissa bits (0..51) clear. |
| 350 | // Read top bits of double representation (second word of value). |
| 351 | __ lwu(a6, FieldMemOperand(a0, HeapNumber::kExponentOffset)); |
| 352 | // Test that exponent bits are all set. |
| 353 | __ And(a7, a6, Operand(exp_mask_reg)); |
| 354 | // If all bits not set (ne cond), then not a NaN, objects are equal. |
| 355 | __ Branch(&return_equal, ne, a7, Operand(exp_mask_reg)); |
| 356 | |
| 357 | // Shift out flag and all exponent bits, retaining only mantissa. |
| 358 | __ sll(a6, a6, HeapNumber::kNonMantissaBitsInTopWord); |
| 359 | // Or with all low-bits of mantissa. |
| 360 | __ lwu(a7, FieldMemOperand(a0, HeapNumber::kMantissaOffset)); |
| 361 | __ Or(v0, a7, Operand(a6)); |
| 362 | // For equal we already have the right value in v0: Return zero (equal) |
| 363 | // if all bits in mantissa are zero (it's an Infinity) and non-zero if |
| 364 | // not (it's a NaN). For <= and >= we need to load v0 with the failing |
| 365 | // value if it's a NaN. |
| 366 | if (cc != eq) { |
| 367 | // All-zero means Infinity means equal. |
| 368 | __ Ret(eq, v0, Operand(zero_reg)); |
| 369 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 370 | __ Ret(USE_DELAY_SLOT); |
| 371 | if (cc == le) { |
| 372 | __ li(v0, Operand(GREATER)); // NaN <= NaN should fail. |
| 373 | } else { |
| 374 | __ li(v0, Operand(LESS)); // NaN >= NaN should fail. |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | // No fall through here. |
| 379 | |
| 380 | __ bind(¬_identical); |
| 381 | } |
| 382 | |
| 383 | |
| 384 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 385 | Register lhs, |
| 386 | Register rhs, |
| 387 | Label* both_loaded_as_doubles, |
| 388 | Label* slow, |
| 389 | bool strict) { |
| 390 | DCHECK((lhs.is(a0) && rhs.is(a1)) || |
| 391 | (lhs.is(a1) && rhs.is(a0))); |
| 392 | |
| 393 | Label lhs_is_smi; |
| 394 | __ JumpIfSmi(lhs, &lhs_is_smi); |
| 395 | // Rhs is a Smi. |
| 396 | // Check whether the non-smi is a heap number. |
| 397 | __ GetObjectType(lhs, t0, t0); |
| 398 | if (strict) { |
| 399 | // If lhs was not a number and rhs was a Smi then strict equality cannot |
| 400 | // succeed. Return non-equal (lhs is already not zero). |
| 401 | __ Ret(USE_DELAY_SLOT, ne, t0, Operand(HEAP_NUMBER_TYPE)); |
| 402 | __ mov(v0, lhs); |
| 403 | } else { |
| 404 | // Smi compared non-strictly with a non-Smi non-heap-number. Call |
| 405 | // the runtime. |
| 406 | __ Branch(slow, ne, t0, Operand(HEAP_NUMBER_TYPE)); |
| 407 | } |
| 408 | // Rhs is a smi, lhs is a number. |
| 409 | // Convert smi rhs to double. |
| 410 | __ SmiUntag(at, rhs); |
| 411 | __ mtc1(at, f14); |
| 412 | __ cvt_d_w(f14, f14); |
| 413 | __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 414 | |
| 415 | // We now have both loaded as doubles. |
| 416 | __ jmp(both_loaded_as_doubles); |
| 417 | |
| 418 | __ bind(&lhs_is_smi); |
| 419 | // Lhs is a Smi. Check whether the non-smi is a heap number. |
| 420 | __ GetObjectType(rhs, t0, t0); |
| 421 | if (strict) { |
| 422 | // If lhs was not a number and rhs was a Smi then strict equality cannot |
| 423 | // succeed. Return non-equal. |
| 424 | __ Ret(USE_DELAY_SLOT, ne, t0, Operand(HEAP_NUMBER_TYPE)); |
| 425 | __ li(v0, Operand(1)); |
| 426 | } else { |
| 427 | // Smi compared non-strictly with a non-Smi non-heap-number. Call |
| 428 | // the runtime. |
| 429 | __ Branch(slow, ne, t0, Operand(HEAP_NUMBER_TYPE)); |
| 430 | } |
| 431 | |
| 432 | // Lhs is a smi, rhs is a number. |
| 433 | // Convert smi lhs to double. |
| 434 | __ SmiUntag(at, lhs); |
| 435 | __ mtc1(at, f12); |
| 436 | __ cvt_d_w(f12, f12); |
| 437 | __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 438 | // Fall through to both_loaded_as_doubles. |
| 439 | } |
| 440 | |
| 441 | |
| 442 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 443 | Register lhs, |
| 444 | Register rhs) { |
| 445 | // If either operand is a JS object or an oddball value, then they are |
| 446 | // not equal since their pointers are different. |
| 447 | // There is no test for undetectability in strict equality. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 448 | STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 449 | Label first_non_object; |
| 450 | // Get the type of the first operand into a2 and compare it with |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 451 | // FIRST_JS_RECEIVER_TYPE. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 452 | __ GetObjectType(lhs, a2, a2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 453 | __ Branch(&first_non_object, less, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 454 | |
| 455 | // Return non-zero. |
| 456 | Label return_not_equal; |
| 457 | __ bind(&return_not_equal); |
| 458 | __ Ret(USE_DELAY_SLOT); |
| 459 | __ li(v0, Operand(1)); |
| 460 | |
| 461 | __ bind(&first_non_object); |
| 462 | // Check for oddballs: true, false, null, undefined. |
| 463 | __ Branch(&return_not_equal, eq, a2, Operand(ODDBALL_TYPE)); |
| 464 | |
| 465 | __ GetObjectType(rhs, a3, a3); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 466 | __ Branch(&return_not_equal, greater, a3, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 467 | |
| 468 | // Check for oddballs: true, false, null, undefined. |
| 469 | __ Branch(&return_not_equal, eq, a3, Operand(ODDBALL_TYPE)); |
| 470 | |
| 471 | // Now that we have the types we might as well check for |
| 472 | // internalized-internalized. |
| 473 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 474 | __ Or(a2, a2, Operand(a3)); |
| 475 | __ And(at, a2, Operand(kIsNotStringMask | kIsNotInternalizedMask)); |
| 476 | __ Branch(&return_not_equal, eq, at, Operand(zero_reg)); |
| 477 | } |
| 478 | |
| 479 | |
| 480 | static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm, |
| 481 | Register lhs, |
| 482 | Register rhs, |
| 483 | Label* both_loaded_as_doubles, |
| 484 | Label* not_heap_numbers, |
| 485 | Label* slow) { |
| 486 | __ GetObjectType(lhs, a3, a2); |
| 487 | __ Branch(not_heap_numbers, ne, a2, Operand(HEAP_NUMBER_TYPE)); |
| 488 | __ ld(a2, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 489 | // If first was a heap number & second wasn't, go to slow case. |
| 490 | __ Branch(slow, ne, a3, Operand(a2)); |
| 491 | |
| 492 | // Both are heap numbers. Load them up then jump to the code we have |
| 493 | // for that. |
| 494 | __ ldc1(f12, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 495 | __ ldc1(f14, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 496 | |
| 497 | __ jmp(both_loaded_as_doubles); |
| 498 | } |
| 499 | |
| 500 | |
| 501 | // Fast negative check for internalized-to-internalized equality. |
| 502 | static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 503 | Register lhs, Register rhs, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 504 | Label* possible_strings, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 505 | Label* runtime_call) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 506 | DCHECK((lhs.is(a0) && rhs.is(a1)) || |
| 507 | (lhs.is(a1) && rhs.is(a0))); |
| 508 | |
| 509 | // a2 is object type of rhs. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 510 | Label object_test, return_equal, return_unequal, undetectable; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 511 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 512 | __ And(at, a2, Operand(kIsNotStringMask)); |
| 513 | __ Branch(&object_test, ne, at, Operand(zero_reg)); |
| 514 | __ And(at, a2, Operand(kIsNotInternalizedMask)); |
| 515 | __ Branch(possible_strings, ne, at, Operand(zero_reg)); |
| 516 | __ GetObjectType(rhs, a3, a3); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 517 | __ Branch(runtime_call, ge, a3, Operand(FIRST_NONSTRING_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 518 | __ And(at, a3, Operand(kIsNotInternalizedMask)); |
| 519 | __ Branch(possible_strings, ne, at, Operand(zero_reg)); |
| 520 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 521 | // Both are internalized. We already checked they weren't the same pointer so |
| 522 | // they are not equal. Return non-equal by returning the non-zero object |
| 523 | // pointer in v0. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 524 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 525 | __ mov(v0, a0); // In delay slot. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 526 | |
| 527 | __ bind(&object_test); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 528 | __ ld(a2, FieldMemOperand(lhs, HeapObject::kMapOffset)); |
| 529 | __ ld(a3, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 530 | __ lbu(t0, FieldMemOperand(a2, Map::kBitFieldOffset)); |
| 531 | __ lbu(t1, FieldMemOperand(a3, Map::kBitFieldOffset)); |
| 532 | __ And(at, t0, Operand(1 << Map::kIsUndetectable)); |
| 533 | __ Branch(&undetectable, ne, at, Operand(zero_reg)); |
| 534 | __ And(at, t1, Operand(1 << Map::kIsUndetectable)); |
| 535 | __ Branch(&return_unequal, ne, at, Operand(zero_reg)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 536 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 537 | __ GetInstanceType(a2, a2); |
| 538 | __ Branch(runtime_call, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 539 | __ GetInstanceType(a3, a3); |
| 540 | __ Branch(runtime_call, lt, a3, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 541 | |
| 542 | __ bind(&return_unequal); |
| 543 | // Return non-equal by returning the non-zero object pointer in v0. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 544 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 545 | __ mov(v0, a0); // In delay slot. |
| 546 | |
| 547 | __ bind(&undetectable); |
| 548 | __ And(at, t1, Operand(1 << Map::kIsUndetectable)); |
| 549 | __ Branch(&return_unequal, eq, at, Operand(zero_reg)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 550 | |
| 551 | // If both sides are JSReceivers, then the result is false according to |
| 552 | // the HTML specification, which says that only comparisons with null or |
| 553 | // undefined are affected by special casing for document.all. |
| 554 | __ GetInstanceType(a2, a2); |
| 555 | __ Branch(&return_equal, eq, a2, Operand(ODDBALL_TYPE)); |
| 556 | __ GetInstanceType(a3, a3); |
| 557 | __ Branch(&return_unequal, ne, a3, Operand(ODDBALL_TYPE)); |
| 558 | |
| 559 | __ bind(&return_equal); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 560 | __ Ret(USE_DELAY_SLOT); |
| 561 | __ li(v0, Operand(EQUAL)); // In delay slot. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | |
| 565 | static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input, |
| 566 | Register scratch, |
| 567 | CompareICState::State expected, |
| 568 | Label* fail) { |
| 569 | Label ok; |
| 570 | if (expected == CompareICState::SMI) { |
| 571 | __ JumpIfNotSmi(input, fail); |
| 572 | } else if (expected == CompareICState::NUMBER) { |
| 573 | __ JumpIfSmi(input, &ok); |
| 574 | __ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail, |
| 575 | DONT_DO_SMI_CHECK); |
| 576 | } |
| 577 | // We could be strict about internalized/string here, but as long as |
| 578 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 579 | __ bind(&ok); |
| 580 | } |
| 581 | |
| 582 | |
| 583 | // On entry a1 and a2 are the values to be compared. |
| 584 | // On exit a0 is 0, positive or negative to indicate the result of |
| 585 | // the comparison. |
| 586 | void CompareICStub::GenerateGeneric(MacroAssembler* masm) { |
| 587 | Register lhs = a1; |
| 588 | Register rhs = a0; |
| 589 | Condition cc = GetCondition(); |
| 590 | |
| 591 | Label miss; |
| 592 | CompareICStub_CheckInputType(masm, lhs, a2, left(), &miss); |
| 593 | CompareICStub_CheckInputType(masm, rhs, a3, right(), &miss); |
| 594 | |
| 595 | Label slow; // Call builtin. |
| 596 | Label not_smis, both_loaded_as_doubles; |
| 597 | |
| 598 | Label not_two_smis, smi_done; |
| 599 | __ Or(a2, a1, a0); |
| 600 | __ JumpIfNotSmi(a2, ¬_two_smis); |
| 601 | __ SmiUntag(a1); |
| 602 | __ SmiUntag(a0); |
| 603 | |
| 604 | __ Ret(USE_DELAY_SLOT); |
| 605 | __ dsubu(v0, a1, a0); |
| 606 | __ bind(¬_two_smis); |
| 607 | |
| 608 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 609 | // it is certain that at least one operand isn't a smi. |
| 610 | |
| 611 | // Handle the case where the objects are identical. Either returns the answer |
| 612 | // or goes to slow. Only falls through if the objects were not identical. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 613 | EmitIdenticalObjectComparison(masm, &slow, cc); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 614 | |
| 615 | // If either is a Smi (we know that not both are), then they can only |
| 616 | // be strictly equal if the other is a HeapNumber. |
| 617 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 618 | DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 619 | __ And(a6, lhs, Operand(rhs)); |
| 620 | __ JumpIfNotSmi(a6, ¬_smis, a4); |
| 621 | // One operand is a smi. EmitSmiNonsmiComparison generates code that can: |
| 622 | // 1) Return the answer. |
| 623 | // 2) Go to slow. |
| 624 | // 3) Fall through to both_loaded_as_doubles. |
| 625 | // 4) Jump to rhs_not_nan. |
| 626 | // In cases 3 and 4 we have found out we were dealing with a number-number |
| 627 | // comparison and the numbers have been loaded into f12 and f14 as doubles, |
| 628 | // or in GP registers (a0, a1, a2, a3) depending on the presence of the FPU. |
| 629 | EmitSmiNonsmiComparison(masm, lhs, rhs, |
| 630 | &both_loaded_as_doubles, &slow, strict()); |
| 631 | |
| 632 | __ bind(&both_loaded_as_doubles); |
| 633 | // f12, f14 are the double representations of the left hand side |
| 634 | // and the right hand side if we have FPU. Otherwise a2, a3 represent |
| 635 | // left hand side and a0, a1 represent right hand side. |
| 636 | |
| 637 | Label nan; |
| 638 | __ li(a4, Operand(LESS)); |
| 639 | __ li(a5, Operand(GREATER)); |
| 640 | __ li(a6, Operand(EQUAL)); |
| 641 | |
| 642 | // Check if either rhs or lhs is NaN. |
| 643 | __ BranchF(NULL, &nan, eq, f12, f14); |
| 644 | |
| 645 | // Check if LESS condition is satisfied. If true, move conditionally |
| 646 | // result to v0. |
| 647 | if (kArchVariant != kMips64r6) { |
| 648 | __ c(OLT, D, f12, f14); |
| 649 | __ Movt(v0, a4); |
| 650 | // Use previous check to store conditionally to v0 oposite condition |
| 651 | // (GREATER). If rhs is equal to lhs, this will be corrected in next |
| 652 | // check. |
| 653 | __ Movf(v0, a5); |
| 654 | // Check if EQUAL condition is satisfied. If true, move conditionally |
| 655 | // result to v0. |
| 656 | __ c(EQ, D, f12, f14); |
| 657 | __ Movt(v0, a6); |
| 658 | } else { |
| 659 | Label skip; |
| 660 | __ BranchF(USE_DELAY_SLOT, &skip, NULL, lt, f12, f14); |
| 661 | __ mov(v0, a4); // Return LESS as result. |
| 662 | |
| 663 | __ BranchF(USE_DELAY_SLOT, &skip, NULL, eq, f12, f14); |
| 664 | __ mov(v0, a6); // Return EQUAL as result. |
| 665 | |
| 666 | __ mov(v0, a5); // Return GREATER as result. |
| 667 | __ bind(&skip); |
| 668 | } |
| 669 | __ Ret(); |
| 670 | |
| 671 | __ bind(&nan); |
| 672 | // NaN comparisons always fail. |
| 673 | // Load whatever we need in v0 to make the comparison fail. |
| 674 | DCHECK(is_int16(GREATER) && is_int16(LESS)); |
| 675 | __ Ret(USE_DELAY_SLOT); |
| 676 | if (cc == lt || cc == le) { |
| 677 | __ li(v0, Operand(GREATER)); |
| 678 | } else { |
| 679 | __ li(v0, Operand(LESS)); |
| 680 | } |
| 681 | |
| 682 | |
| 683 | __ bind(¬_smis); |
| 684 | // At this point we know we are dealing with two different objects, |
| 685 | // and neither of them is a Smi. The objects are in lhs_ and rhs_. |
| 686 | if (strict()) { |
| 687 | // This returns non-equal for some object types, or falls through if it |
| 688 | // was not lucky. |
| 689 | EmitStrictTwoHeapObjectCompare(masm, lhs, rhs); |
| 690 | } |
| 691 | |
| 692 | Label check_for_internalized_strings; |
| 693 | Label flat_string_check; |
| 694 | // Check for heap-number-heap-number comparison. Can jump to slow case, |
| 695 | // or load both doubles and jump to the code that handles |
| 696 | // that case. If the inputs are not doubles then jumps to |
| 697 | // check_for_internalized_strings. |
| 698 | // In this case a2 will contain the type of lhs_. |
| 699 | EmitCheckForTwoHeapNumbers(masm, |
| 700 | lhs, |
| 701 | rhs, |
| 702 | &both_loaded_as_doubles, |
| 703 | &check_for_internalized_strings, |
| 704 | &flat_string_check); |
| 705 | |
| 706 | __ bind(&check_for_internalized_strings); |
| 707 | if (cc == eq && !strict()) { |
| 708 | // Returns an answer for two internalized strings or two |
| 709 | // detectable objects. |
| 710 | // Otherwise jumps to string case or not both strings case. |
| 711 | // Assumes that a2 is the type of lhs_ on entry. |
| 712 | EmitCheckForInternalizedStringsOrObjects( |
| 713 | masm, lhs, rhs, &flat_string_check, &slow); |
| 714 | } |
| 715 | |
| 716 | // Check for both being sequential one-byte strings, |
| 717 | // and inline if that is the case. |
| 718 | __ bind(&flat_string_check); |
| 719 | |
| 720 | __ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, a2, a3, &slow); |
| 721 | |
| 722 | __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2, |
| 723 | a3); |
| 724 | if (cc == eq) { |
| 725 | StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, a2, a3, a4); |
| 726 | } else { |
| 727 | StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, a2, a3, a4, |
| 728 | a5); |
| 729 | } |
| 730 | // Never falls through to here. |
| 731 | |
| 732 | __ bind(&slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 733 | if (cc == eq) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 734 | { |
| 735 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 736 | __ Push(lhs, rhs); |
| 737 | __ CallRuntime(strict() ? Runtime::kStrictEqual : Runtime::kEqual); |
| 738 | } |
| 739 | // Turn true into 0 and false into some non-zero value. |
| 740 | STATIC_ASSERT(EQUAL == 0); |
| 741 | __ LoadRoot(a0, Heap::kTrueValueRootIndex); |
| 742 | __ Ret(USE_DELAY_SLOT); |
| 743 | __ subu(v0, v0, a0); // In delay slot. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 744 | } else { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 745 | // Prepare for call to builtin. Push object pointers, a0 (lhs) first, |
| 746 | // a1 (rhs) second. |
| 747 | __ Push(lhs, rhs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 748 | int ncr; // NaN compare result. |
| 749 | if (cc == lt || cc == le) { |
| 750 | ncr = GREATER; |
| 751 | } else { |
| 752 | DCHECK(cc == gt || cc == ge); // Remaining cases. |
| 753 | ncr = LESS; |
| 754 | } |
| 755 | __ li(a0, Operand(Smi::FromInt(ncr))); |
| 756 | __ push(a0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 757 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 758 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 759 | // tagged as a small integer. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 760 | __ TailCallRuntime(Runtime::kCompare); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 761 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 762 | |
| 763 | __ bind(&miss); |
| 764 | GenerateMiss(masm); |
| 765 | } |
| 766 | |
| 767 | |
| 768 | void StoreRegistersStateStub::Generate(MacroAssembler* masm) { |
| 769 | __ mov(t9, ra); |
| 770 | __ pop(ra); |
| 771 | __ PushSafepointRegisters(); |
| 772 | __ Jump(t9); |
| 773 | } |
| 774 | |
| 775 | |
| 776 | void RestoreRegistersStateStub::Generate(MacroAssembler* masm) { |
| 777 | __ mov(t9, ra); |
| 778 | __ pop(ra); |
| 779 | __ PopSafepointRegisters(); |
| 780 | __ Jump(t9); |
| 781 | } |
| 782 | |
| 783 | |
| 784 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 785 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 786 | // store the registers in any particular way, but we do have to store and |
| 787 | // restore them. |
| 788 | __ MultiPush(kJSCallerSaved | ra.bit()); |
| 789 | if (save_doubles()) { |
| 790 | __ MultiPushFPU(kCallerSavedFPU); |
| 791 | } |
| 792 | const int argument_count = 1; |
| 793 | const int fp_argument_count = 0; |
| 794 | const Register scratch = a1; |
| 795 | |
| 796 | AllowExternalCallThatCantCauseGC scope(masm); |
| 797 | __ PrepareCallCFunction(argument_count, fp_argument_count, scratch); |
| 798 | __ li(a0, Operand(ExternalReference::isolate_address(isolate()))); |
| 799 | __ CallCFunction( |
| 800 | ExternalReference::store_buffer_overflow_function(isolate()), |
| 801 | argument_count); |
| 802 | if (save_doubles()) { |
| 803 | __ MultiPopFPU(kCallerSavedFPU); |
| 804 | } |
| 805 | |
| 806 | __ MultiPop(kJSCallerSaved | ra.bit()); |
| 807 | __ Ret(); |
| 808 | } |
| 809 | |
| 810 | |
| 811 | void MathPowStub::Generate(MacroAssembler* masm) { |
| 812 | const Register base = a1; |
| 813 | const Register exponent = MathPowTaggedDescriptor::exponent(); |
| 814 | DCHECK(exponent.is(a2)); |
| 815 | const Register heapnumbermap = a5; |
| 816 | const Register heapnumber = v0; |
| 817 | const DoubleRegister double_base = f2; |
| 818 | const DoubleRegister double_exponent = f4; |
| 819 | const DoubleRegister double_result = f0; |
| 820 | const DoubleRegister double_scratch = f6; |
| 821 | const FPURegister single_scratch = f8; |
| 822 | const Register scratch = t1; |
| 823 | const Register scratch2 = a7; |
| 824 | |
| 825 | Label call_runtime, done, int_exponent; |
| 826 | if (exponent_type() == ON_STACK) { |
| 827 | Label base_is_smi, unpack_exponent; |
| 828 | // The exponent and base are supplied as arguments on the stack. |
| 829 | // This can only happen if the stub is called from non-optimized code. |
| 830 | // Load input parameters from stack to double registers. |
| 831 | __ ld(base, MemOperand(sp, 1 * kPointerSize)); |
| 832 | __ ld(exponent, MemOperand(sp, 0 * kPointerSize)); |
| 833 | |
| 834 | __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex); |
| 835 | |
| 836 | __ UntagAndJumpIfSmi(scratch, base, &base_is_smi); |
| 837 | __ ld(scratch, FieldMemOperand(base, JSObject::kMapOffset)); |
| 838 | __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap)); |
| 839 | |
| 840 | __ ldc1(double_base, FieldMemOperand(base, HeapNumber::kValueOffset)); |
| 841 | __ jmp(&unpack_exponent); |
| 842 | |
| 843 | __ bind(&base_is_smi); |
| 844 | __ mtc1(scratch, single_scratch); |
| 845 | __ cvt_d_w(double_base, single_scratch); |
| 846 | __ bind(&unpack_exponent); |
| 847 | |
| 848 | __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent); |
| 849 | |
| 850 | __ ld(scratch, FieldMemOperand(exponent, JSObject::kMapOffset)); |
| 851 | __ Branch(&call_runtime, ne, scratch, Operand(heapnumbermap)); |
| 852 | __ ldc1(double_exponent, |
| 853 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
| 854 | } else if (exponent_type() == TAGGED) { |
| 855 | // Base is already in double_base. |
| 856 | __ UntagAndJumpIfSmi(scratch, exponent, &int_exponent); |
| 857 | |
| 858 | __ ldc1(double_exponent, |
| 859 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
| 860 | } |
| 861 | |
| 862 | if (exponent_type() != INTEGER) { |
| 863 | Label int_exponent_convert; |
| 864 | // Detect integer exponents stored as double. |
| 865 | __ EmitFPUTruncate(kRoundToMinusInf, |
| 866 | scratch, |
| 867 | double_exponent, |
| 868 | at, |
| 869 | double_scratch, |
| 870 | scratch2, |
| 871 | kCheckForInexactConversion); |
| 872 | // scratch2 == 0 means there was no conversion error. |
| 873 | __ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg)); |
| 874 | |
| 875 | if (exponent_type() == ON_STACK) { |
| 876 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 877 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 878 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 879 | Label not_plus_half; |
| 880 | |
| 881 | // Test for 0.5. |
| 882 | __ Move(double_scratch, 0.5); |
| 883 | __ BranchF(USE_DELAY_SLOT, |
| 884 | ¬_plus_half, |
| 885 | NULL, |
| 886 | ne, |
| 887 | double_exponent, |
| 888 | double_scratch); |
| 889 | // double_scratch can be overwritten in the delay slot. |
| 890 | // Calculates square root of base. Check for the special case of |
| 891 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 892 | __ Move(double_scratch, static_cast<double>(-V8_INFINITY)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 893 | __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch); |
| 894 | __ neg_d(double_result, double_scratch); |
| 895 | |
| 896 | // Add +0 to convert -0 to +0. |
| 897 | __ add_d(double_scratch, double_base, kDoubleRegZero); |
| 898 | __ sqrt_d(double_result, double_scratch); |
| 899 | __ jmp(&done); |
| 900 | |
| 901 | __ bind(¬_plus_half); |
| 902 | __ Move(double_scratch, -0.5); |
| 903 | __ BranchF(USE_DELAY_SLOT, |
| 904 | &call_runtime, |
| 905 | NULL, |
| 906 | ne, |
| 907 | double_exponent, |
| 908 | double_scratch); |
| 909 | // double_scratch can be overwritten in the delay slot. |
| 910 | // Calculates square root of base. Check for the special case of |
| 911 | // Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 912 | __ Move(double_scratch, static_cast<double>(-V8_INFINITY)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 913 | __ BranchF(USE_DELAY_SLOT, &done, NULL, eq, double_base, double_scratch); |
| 914 | __ Move(double_result, kDoubleRegZero); |
| 915 | |
| 916 | // Add +0 to convert -0 to +0. |
| 917 | __ add_d(double_scratch, double_base, kDoubleRegZero); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 918 | __ Move(double_result, 1.); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 919 | __ sqrt_d(double_scratch, double_scratch); |
| 920 | __ div_d(double_result, double_result, double_scratch); |
| 921 | __ jmp(&done); |
| 922 | } |
| 923 | |
| 924 | __ push(ra); |
| 925 | { |
| 926 | AllowExternalCallThatCantCauseGC scope(masm); |
| 927 | __ PrepareCallCFunction(0, 2, scratch2); |
| 928 | __ MovToFloatParameters(double_base, double_exponent); |
| 929 | __ CallCFunction( |
| 930 | ExternalReference::power_double_double_function(isolate()), |
| 931 | 0, 2); |
| 932 | } |
| 933 | __ pop(ra); |
| 934 | __ MovFromFloatResult(double_result); |
| 935 | __ jmp(&done); |
| 936 | |
| 937 | __ bind(&int_exponent_convert); |
| 938 | } |
| 939 | |
| 940 | // Calculate power with integer exponent. |
| 941 | __ bind(&int_exponent); |
| 942 | |
| 943 | // Get two copies of exponent in the registers scratch and exponent. |
| 944 | if (exponent_type() == INTEGER) { |
| 945 | __ mov(scratch, exponent); |
| 946 | } else { |
| 947 | // Exponent has previously been stored into scratch as untagged integer. |
| 948 | __ mov(exponent, scratch); |
| 949 | } |
| 950 | |
| 951 | __ mov_d(double_scratch, double_base); // Back up base. |
| 952 | __ Move(double_result, 1.0); |
| 953 | |
| 954 | // Get absolute value of exponent. |
| 955 | Label positive_exponent; |
| 956 | __ Branch(&positive_exponent, ge, scratch, Operand(zero_reg)); |
| 957 | __ Dsubu(scratch, zero_reg, scratch); |
| 958 | __ bind(&positive_exponent); |
| 959 | |
| 960 | Label while_true, no_carry, loop_end; |
| 961 | __ bind(&while_true); |
| 962 | |
| 963 | __ And(scratch2, scratch, 1); |
| 964 | |
| 965 | __ Branch(&no_carry, eq, scratch2, Operand(zero_reg)); |
| 966 | __ mul_d(double_result, double_result, double_scratch); |
| 967 | __ bind(&no_carry); |
| 968 | |
| 969 | __ dsra(scratch, scratch, 1); |
| 970 | |
| 971 | __ Branch(&loop_end, eq, scratch, Operand(zero_reg)); |
| 972 | __ mul_d(double_scratch, double_scratch, double_scratch); |
| 973 | |
| 974 | __ Branch(&while_true); |
| 975 | |
| 976 | __ bind(&loop_end); |
| 977 | |
| 978 | __ Branch(&done, ge, exponent, Operand(zero_reg)); |
| 979 | __ Move(double_scratch, 1.0); |
| 980 | __ div_d(double_result, double_scratch, double_result); |
| 981 | // Test whether result is zero. Bail out to check for subnormal result. |
| 982 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 983 | __ BranchF(&done, NULL, ne, double_result, kDoubleRegZero); |
| 984 | |
| 985 | // double_exponent may not contain the exponent value if the input was a |
| 986 | // smi. We set it with exponent value before bailing out. |
| 987 | __ mtc1(exponent, single_scratch); |
| 988 | __ cvt_d_w(double_exponent, single_scratch); |
| 989 | |
| 990 | // Returning or bailing out. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 991 | if (exponent_type() == ON_STACK) { |
| 992 | // The arguments are still on the stack. |
| 993 | __ bind(&call_runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 994 | __ TailCallRuntime(Runtime::kMathPowRT); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 995 | |
| 996 | // The stub is called from non-optimized code, which expects the result |
| 997 | // as heap number in exponent. |
| 998 | __ bind(&done); |
| 999 | __ AllocateHeapNumber( |
| 1000 | heapnumber, scratch, scratch2, heapnumbermap, &call_runtime); |
| 1001 | __ sdc1(double_result, |
| 1002 | FieldMemOperand(heapnumber, HeapNumber::kValueOffset)); |
| 1003 | DCHECK(heapnumber.is(v0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1004 | __ DropAndRet(2); |
| 1005 | } else { |
| 1006 | __ push(ra); |
| 1007 | { |
| 1008 | AllowExternalCallThatCantCauseGC scope(masm); |
| 1009 | __ PrepareCallCFunction(0, 2, scratch); |
| 1010 | __ MovToFloatParameters(double_base, double_exponent); |
| 1011 | __ CallCFunction( |
| 1012 | ExternalReference::power_double_double_function(isolate()), |
| 1013 | 0, 2); |
| 1014 | } |
| 1015 | __ pop(ra); |
| 1016 | __ MovFromFloatResult(double_result); |
| 1017 | |
| 1018 | __ bind(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1019 | __ Ret(); |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | |
| 1024 | bool CEntryStub::NeedsImmovableCode() { |
| 1025 | return true; |
| 1026 | } |
| 1027 | |
| 1028 | |
| 1029 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 1030 | CEntryStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1031 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
| 1032 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
| 1033 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
| 1034 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1035 | CreateWeakCellStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1036 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
| 1037 | StoreRegistersStateStub::GenerateAheadOfTime(isolate); |
| 1038 | RestoreRegistersStateStub::GenerateAheadOfTime(isolate); |
| 1039 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1040 | StoreFastElementStub::GenerateAheadOfTime(isolate); |
| 1041 | TypeofStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | |
| 1045 | void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1046 | StoreRegistersStateStub stub(isolate); |
| 1047 | stub.GetCode(); |
| 1048 | } |
| 1049 | |
| 1050 | |
| 1051 | void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1052 | RestoreRegistersStateStub stub(isolate); |
| 1053 | stub.GetCode(); |
| 1054 | } |
| 1055 | |
| 1056 | |
| 1057 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
| 1058 | // Generate if not already in cache. |
| 1059 | SaveFPRegsMode mode = kSaveFPRegs; |
| 1060 | CEntryStub(isolate, 1, mode).GetCode(); |
| 1061 | StoreBufferOverflowStub(isolate, mode).GetCode(); |
| 1062 | isolate->set_fp_stubs_generated(true); |
| 1063 | } |
| 1064 | |
| 1065 | |
| 1066 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1067 | CEntryStub stub(isolate, 1, kDontSaveFPRegs); |
| 1068 | stub.GetCode(); |
| 1069 | } |
| 1070 | |
| 1071 | |
| 1072 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 1073 | // Called from JavaScript; parameters are on stack as if calling JS function |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1074 | // a0: number of arguments including receiver |
| 1075 | // a1: pointer to builtin function |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1076 | // fp: frame pointer (restored after C call) |
| 1077 | // sp: stack pointer (restored as callee's sp after C call) |
| 1078 | // cp: current context (C callee-saved) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1079 | // |
| 1080 | // If argv_in_register(): |
| 1081 | // a2: pointer to the first argument |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1082 | |
| 1083 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 1084 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1085 | if (argv_in_register()) { |
| 1086 | // Move argv into the correct register. |
| 1087 | __ mov(s1, a2); |
| 1088 | } else { |
| 1089 | // Compute the argv pointer in a callee-saved register. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1090 | __ Dlsa(s1, sp, a0, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1091 | __ Dsubu(s1, s1, kPointerSize); |
| 1092 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1093 | |
| 1094 | // Enter the exit frame that transitions from JavaScript to C++. |
| 1095 | FrameScope scope(masm, StackFrame::MANUAL); |
| 1096 | __ EnterExitFrame(save_doubles()); |
| 1097 | |
| 1098 | // s0: number of arguments including receiver (C callee-saved) |
| 1099 | // s1: pointer to first argument (C callee-saved) |
| 1100 | // s2: pointer to builtin function (C callee-saved) |
| 1101 | |
| 1102 | // Prepare arguments for C routine. |
| 1103 | // a0 = argc |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1104 | __ mov(s0, a0); |
| 1105 | __ mov(s2, a1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1106 | |
| 1107 | // We are calling compiled C/C++ code. a0 and a1 hold our two arguments. We |
| 1108 | // also need to reserve the 4 argument slots on the stack. |
| 1109 | |
| 1110 | __ AssertStackIsAligned(); |
| 1111 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1112 | int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
| 1113 | int frame_alignment_mask = frame_alignment - 1; |
| 1114 | int result_stack_size; |
| 1115 | if (result_size() <= 2) { |
| 1116 | // a0 = argc, a1 = argv, a2 = isolate |
| 1117 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
| 1118 | __ mov(a1, s1); |
| 1119 | result_stack_size = 0; |
| 1120 | } else { |
| 1121 | DCHECK_EQ(3, result_size()); |
| 1122 | // Allocate additional space for the result. |
| 1123 | result_stack_size = |
| 1124 | ((result_size() * kPointerSize) + frame_alignment_mask) & |
| 1125 | ~frame_alignment_mask; |
| 1126 | __ Dsubu(sp, sp, Operand(result_stack_size)); |
| 1127 | |
| 1128 | // a0 = hidden result argument, a1 = argc, a2 = argv, a3 = isolate. |
| 1129 | __ li(a3, Operand(ExternalReference::isolate_address(isolate()))); |
| 1130 | __ mov(a2, s1); |
| 1131 | __ mov(a1, a0); |
| 1132 | __ mov(a0, sp); |
| 1133 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1134 | |
| 1135 | // To let the GC traverse the return address of the exit frames, we need to |
| 1136 | // know where the return address is. The CEntryStub is unmovable, so |
| 1137 | // we can store the address on the stack to be able to find it again and |
| 1138 | // we never have to restore it, because it will not change. |
| 1139 | { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1140 | int kNumInstructionsToJump = 4; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1141 | Label find_ra; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1142 | // Adjust the value in ra to point to the correct return location, 2nd |
| 1143 | // instruction past the real call into C code (the jalr(t9)), and push it. |
| 1144 | // This is the return address of the exit frame. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1145 | if (kArchVariant >= kMips64r6) { |
| 1146 | __ addiupc(ra, kNumInstructionsToJump + 1); |
| 1147 | } else { |
| 1148 | // This branch-and-link sequence is needed to find the current PC on mips |
| 1149 | // before r6, saved to the ra register. |
| 1150 | __ bal(&find_ra); // bal exposes branch delay slot. |
| 1151 | __ Daddu(ra, ra, kNumInstructionsToJump * Instruction::kInstrSize); |
| 1152 | } |
| 1153 | __ bind(&find_ra); |
| 1154 | |
| 1155 | // This spot was reserved in EnterExitFrame. |
| 1156 | __ sd(ra, MemOperand(sp, result_stack_size)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1157 | // Stack space reservation moved to the branch delay slot below. |
| 1158 | // Stack is still aligned. |
| 1159 | |
| 1160 | // Call the C routine. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1161 | __ mov(t9, s2); // Function pointer to t9 to conform to ABI for PIC. |
| 1162 | __ jalr(t9); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1163 | // Set up sp in the delay slot. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1164 | __ daddiu(sp, sp, -kCArgsSlotsSize); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1165 | // Make sure the stored 'ra' points to this position. |
| 1166 | DCHECK_EQ(kNumInstructionsToJump, |
| 1167 | masm->InstructionsGeneratedSince(&find_ra)); |
| 1168 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1169 | if (result_size() > 2) { |
| 1170 | DCHECK_EQ(3, result_size()); |
| 1171 | // Read result values stored on stack. |
| 1172 | __ ld(a0, MemOperand(v0, 2 * kPointerSize)); |
| 1173 | __ ld(v1, MemOperand(v0, 1 * kPointerSize)); |
| 1174 | __ ld(v0, MemOperand(v0, 0 * kPointerSize)); |
| 1175 | } |
| 1176 | // Result returned in v0, v1:v0 or a0:v1:v0 - do not destroy these registers! |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1177 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1178 | // Check result for exception sentinel. |
| 1179 | Label exception_returned; |
| 1180 | __ LoadRoot(a4, Heap::kExceptionRootIndex); |
| 1181 | __ Branch(&exception_returned, eq, a4, Operand(v0)); |
| 1182 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1183 | // Check that there is no pending exception, otherwise we |
| 1184 | // should have returned the exception sentinel. |
| 1185 | if (FLAG_debug_code) { |
| 1186 | Label okay; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1187 | ExternalReference pending_exception_address( |
| 1188 | Isolate::kPendingExceptionAddress, isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1189 | __ li(a2, Operand(pending_exception_address)); |
| 1190 | __ ld(a2, MemOperand(a2)); |
| 1191 | __ LoadRoot(a4, Heap::kTheHoleValueRootIndex); |
| 1192 | // Cannot use check here as it attempts to generate call into runtime. |
| 1193 | __ Branch(&okay, eq, a4, Operand(a2)); |
| 1194 | __ stop("Unexpected pending exception"); |
| 1195 | __ bind(&okay); |
| 1196 | } |
| 1197 | |
| 1198 | // Exit C frame and return. |
| 1199 | // v0:v1: result |
| 1200 | // sp: stack pointer |
| 1201 | // fp: frame pointer |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1202 | Register argc; |
| 1203 | if (argv_in_register()) { |
| 1204 | // We don't want to pop arguments so set argc to no_reg. |
| 1205 | argc = no_reg; |
| 1206 | } else { |
| 1207 | // s0: still holds argc (callee-saved). |
| 1208 | argc = s0; |
| 1209 | } |
| 1210 | __ LeaveExitFrame(save_doubles(), argc, true, EMIT_RETURN); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1211 | |
| 1212 | // Handling of exception. |
| 1213 | __ bind(&exception_returned); |
| 1214 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1215 | ExternalReference pending_handler_context_address( |
| 1216 | Isolate::kPendingHandlerContextAddress, isolate()); |
| 1217 | ExternalReference pending_handler_code_address( |
| 1218 | Isolate::kPendingHandlerCodeAddress, isolate()); |
| 1219 | ExternalReference pending_handler_offset_address( |
| 1220 | Isolate::kPendingHandlerOffsetAddress, isolate()); |
| 1221 | ExternalReference pending_handler_fp_address( |
| 1222 | Isolate::kPendingHandlerFPAddress, isolate()); |
| 1223 | ExternalReference pending_handler_sp_address( |
| 1224 | Isolate::kPendingHandlerSPAddress, isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1225 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1226 | // Ask the runtime for help to determine the handler. This will set v0 to |
| 1227 | // contain the current pending exception, don't clobber it. |
| 1228 | ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler, |
| 1229 | isolate()); |
| 1230 | { |
| 1231 | FrameScope scope(masm, StackFrame::MANUAL); |
| 1232 | __ PrepareCallCFunction(3, 0, a0); |
| 1233 | __ mov(a0, zero_reg); |
| 1234 | __ mov(a1, zero_reg); |
| 1235 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
| 1236 | __ CallCFunction(find_handler, 3); |
| 1237 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1238 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1239 | // Retrieve the handler context, SP and FP. |
| 1240 | __ li(cp, Operand(pending_handler_context_address)); |
| 1241 | __ ld(cp, MemOperand(cp)); |
| 1242 | __ li(sp, Operand(pending_handler_sp_address)); |
| 1243 | __ ld(sp, MemOperand(sp)); |
| 1244 | __ li(fp, Operand(pending_handler_fp_address)); |
| 1245 | __ ld(fp, MemOperand(fp)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1246 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1247 | // If the handler is a JS frame, restore the context to the frame. Note that |
| 1248 | // the context will be set to (cp == 0) for non-JS frames. |
| 1249 | Label zero; |
| 1250 | __ Branch(&zero, eq, cp, Operand(zero_reg)); |
| 1251 | __ sd(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 1252 | __ bind(&zero); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1253 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1254 | // Compute the handler entry address and jump to it. |
| 1255 | __ li(a1, Operand(pending_handler_code_address)); |
| 1256 | __ ld(a1, MemOperand(a1)); |
| 1257 | __ li(a2, Operand(pending_handler_offset_address)); |
| 1258 | __ ld(a2, MemOperand(a2)); |
| 1259 | __ Daddu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 1260 | __ Daddu(t9, a1, a2); |
| 1261 | __ Jump(t9); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | |
| 1265 | void JSEntryStub::Generate(MacroAssembler* masm) { |
| 1266 | Label invoke, handler_entry, exit; |
| 1267 | Isolate* isolate = masm->isolate(); |
| 1268 | |
| 1269 | // TODO(plind): unify the ABI description here. |
| 1270 | // Registers: |
| 1271 | // a0: entry address |
| 1272 | // a1: function |
| 1273 | // a2: receiver |
| 1274 | // a3: argc |
| 1275 | // a4 (a4): on mips64 |
| 1276 | |
| 1277 | // Stack: |
| 1278 | // 0 arg slots on mips64 (4 args slots on mips) |
| 1279 | // args -- in a4/a4 on mips64, on stack on mips |
| 1280 | |
| 1281 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 1282 | |
| 1283 | // Save callee saved registers on the stack. |
| 1284 | __ MultiPush(kCalleeSaved | ra.bit()); |
| 1285 | |
| 1286 | // Save callee-saved FPU registers. |
| 1287 | __ MultiPushFPU(kCalleeSavedFPU); |
| 1288 | // Set up the reserved register for 0.0. |
| 1289 | __ Move(kDoubleRegZero, 0.0); |
| 1290 | |
| 1291 | // Load argv in s0 register. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1292 | __ mov(s0, a4); // 5th parameter in mips64 a4 (a4) register. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1293 | |
| 1294 | __ InitializeRootRegister(); |
| 1295 | |
| 1296 | // We build an EntryFrame. |
| 1297 | __ li(a7, Operand(-1)); // Push a bad frame pointer to fail if it is used. |
| 1298 | int marker = type(); |
| 1299 | __ li(a6, Operand(Smi::FromInt(marker))); |
| 1300 | __ li(a5, Operand(Smi::FromInt(marker))); |
| 1301 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, isolate); |
| 1302 | __ li(a4, Operand(c_entry_fp)); |
| 1303 | __ ld(a4, MemOperand(a4)); |
| 1304 | __ Push(a7, a6, a5, a4); |
| 1305 | // Set up frame pointer for the frame to be pushed. |
| 1306 | __ daddiu(fp, sp, -EntryFrameConstants::kCallerFPOffset); |
| 1307 | |
| 1308 | // Registers: |
| 1309 | // a0: entry_address |
| 1310 | // a1: function |
| 1311 | // a2: receiver_pointer |
| 1312 | // a3: argc |
| 1313 | // s0: argv |
| 1314 | // |
| 1315 | // Stack: |
| 1316 | // caller fp | |
| 1317 | // function slot | entry frame |
| 1318 | // context slot | |
| 1319 | // bad fp (0xff...f) | |
| 1320 | // callee saved registers + ra |
| 1321 | // [ O32: 4 args slots] |
| 1322 | // args |
| 1323 | |
| 1324 | // If this is the outermost JS call, set js_entry_sp value. |
| 1325 | Label non_outermost_js; |
| 1326 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate); |
| 1327 | __ li(a5, Operand(ExternalReference(js_entry_sp))); |
| 1328 | __ ld(a6, MemOperand(a5)); |
| 1329 | __ Branch(&non_outermost_js, ne, a6, Operand(zero_reg)); |
| 1330 | __ sd(fp, MemOperand(a5)); |
| 1331 | __ li(a4, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 1332 | Label cont; |
| 1333 | __ b(&cont); |
| 1334 | __ nop(); // Branch delay slot nop. |
| 1335 | __ bind(&non_outermost_js); |
| 1336 | __ li(a4, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
| 1337 | __ bind(&cont); |
| 1338 | __ push(a4); |
| 1339 | |
| 1340 | // Jump to a faked try block that does the invoke, with a faked catch |
| 1341 | // block that sets the pending exception. |
| 1342 | __ jmp(&invoke); |
| 1343 | __ bind(&handler_entry); |
| 1344 | handler_offset_ = handler_entry.pos(); |
| 1345 | // Caught exception: Store result (exception) in the pending exception |
| 1346 | // field in the JSEnv and return a failure sentinel. Coming in here the |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1347 | // fp will be invalid because the PushStackHandler below sets it to 0 to |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1348 | // signal the existence of the JSEntry frame. |
| 1349 | __ li(a4, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
| 1350 | isolate))); |
| 1351 | __ sd(v0, MemOperand(a4)); // We come back from 'invoke'. result is in v0. |
| 1352 | __ LoadRoot(v0, Heap::kExceptionRootIndex); |
| 1353 | __ b(&exit); // b exposes branch delay slot. |
| 1354 | __ nop(); // Branch delay slot nop. |
| 1355 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1356 | // Invoke: Link this frame into the handler chain. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1357 | __ bind(&invoke); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1358 | __ PushStackHandler(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1359 | // If an exception not caught by another handler occurs, this handler |
| 1360 | // returns control to the code after the bal(&invoke) above, which |
| 1361 | // restores all kCalleeSaved registers (including cp and fp) to their |
| 1362 | // saved values before returning a failure to C. |
| 1363 | |
| 1364 | // Clear any pending exceptions. |
| 1365 | __ LoadRoot(a5, Heap::kTheHoleValueRootIndex); |
| 1366 | __ li(a4, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
| 1367 | isolate))); |
| 1368 | __ sd(a5, MemOperand(a4)); |
| 1369 | |
| 1370 | // Invoke the function by calling through JS entry trampoline builtin. |
| 1371 | // Notice that we cannot store a reference to the trampoline code directly in |
| 1372 | // this stub, because runtime stubs are not traversed when doing GC. |
| 1373 | |
| 1374 | // Registers: |
| 1375 | // a0: entry_address |
| 1376 | // a1: function |
| 1377 | // a2: receiver_pointer |
| 1378 | // a3: argc |
| 1379 | // s0: argv |
| 1380 | // |
| 1381 | // Stack: |
| 1382 | // handler frame |
| 1383 | // entry frame |
| 1384 | // callee saved registers + ra |
| 1385 | // [ O32: 4 args slots] |
| 1386 | // args |
| 1387 | |
| 1388 | if (type() == StackFrame::ENTRY_CONSTRUCT) { |
| 1389 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 1390 | isolate); |
| 1391 | __ li(a4, Operand(construct_entry)); |
| 1392 | } else { |
| 1393 | ExternalReference entry(Builtins::kJSEntryTrampoline, masm->isolate()); |
| 1394 | __ li(a4, Operand(entry)); |
| 1395 | } |
| 1396 | __ ld(t9, MemOperand(a4)); // Deref address. |
| 1397 | // Call JSEntryTrampoline. |
| 1398 | __ daddiu(t9, t9, Code::kHeaderSize - kHeapObjectTag); |
| 1399 | __ Call(t9); |
| 1400 | |
| 1401 | // Unlink this frame from the handler chain. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1402 | __ PopStackHandler(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1403 | |
| 1404 | __ bind(&exit); // v0 holds result |
| 1405 | // Check if the current stack frame is marked as the outermost JS frame. |
| 1406 | Label non_outermost_js_2; |
| 1407 | __ pop(a5); |
| 1408 | __ Branch(&non_outermost_js_2, |
| 1409 | ne, |
| 1410 | a5, |
| 1411 | Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 1412 | __ li(a5, Operand(ExternalReference(js_entry_sp))); |
| 1413 | __ sd(zero_reg, MemOperand(a5)); |
| 1414 | __ bind(&non_outermost_js_2); |
| 1415 | |
| 1416 | // Restore the top frame descriptors from the stack. |
| 1417 | __ pop(a5); |
| 1418 | __ li(a4, Operand(ExternalReference(Isolate::kCEntryFPAddress, |
| 1419 | isolate))); |
| 1420 | __ sd(a5, MemOperand(a4)); |
| 1421 | |
| 1422 | // Reset the stack to the callee saved registers. |
| 1423 | __ daddiu(sp, sp, -EntryFrameConstants::kCallerFPOffset); |
| 1424 | |
| 1425 | // Restore callee-saved fpu registers. |
| 1426 | __ MultiPopFPU(kCalleeSavedFPU); |
| 1427 | |
| 1428 | // Restore callee saved registers from the stack. |
| 1429 | __ MultiPop(kCalleeSaved | ra.bit()); |
| 1430 | // Return. |
| 1431 | __ Jump(ra); |
| 1432 | } |
| 1433 | |
| 1434 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1435 | void LoadIndexedStringStub::Generate(MacroAssembler* masm) { |
| 1436 | // Return address is in ra. |
| 1437 | Label miss; |
| 1438 | |
| 1439 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 1440 | Register index = LoadDescriptor::NameRegister(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1441 | Register scratch = a5; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1442 | Register result = v0; |
| 1443 | DCHECK(!scratch.is(receiver) && !scratch.is(index)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1444 | DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1445 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1446 | StringCharAtGenerator char_at_generator(receiver, index, scratch, result, |
| 1447 | &miss, // When not a string. |
| 1448 | &miss, // When not a number. |
| 1449 | &miss, // When index out of range. |
| 1450 | STRING_INDEX_IS_ARRAY_INDEX, |
| 1451 | RECEIVER_IS_STRING); |
| 1452 | char_at_generator.GenerateFast(masm); |
| 1453 | __ Ret(); |
| 1454 | |
| 1455 | StubRuntimeCallHelper call_helper; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1456 | char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1457 | |
| 1458 | __ bind(&miss); |
| 1459 | PropertyAccessCompiler::TailCallBuiltin( |
| 1460 | masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC)); |
| 1461 | } |
| 1462 | |
| 1463 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1464 | void InstanceOfStub::Generate(MacroAssembler* masm) { |
| 1465 | Register const object = a1; // Object (lhs). |
| 1466 | Register const function = a0; // Function (rhs). |
| 1467 | Register const object_map = a2; // Map of {object}. |
| 1468 | Register const function_map = a3; // Map of {function}. |
| 1469 | Register const function_prototype = a4; // Prototype of {function}. |
| 1470 | Register const scratch = a5; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1471 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1472 | DCHECK(object.is(InstanceOfDescriptor::LeftRegister())); |
| 1473 | DCHECK(function.is(InstanceOfDescriptor::RightRegister())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1474 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1475 | // Check if {object} is a smi. |
| 1476 | Label object_is_smi; |
| 1477 | __ JumpIfSmi(object, &object_is_smi); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1478 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1479 | // Lookup the {function} and the {object} map in the global instanceof cache. |
| 1480 | // Note: This is safe because we clear the global instanceof cache whenever |
| 1481 | // we change the prototype of any object. |
| 1482 | Label fast_case, slow_case; |
| 1483 | __ ld(object_map, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1484 | __ LoadRoot(at, Heap::kInstanceofCacheFunctionRootIndex); |
| 1485 | __ Branch(&fast_case, ne, function, Operand(at)); |
| 1486 | __ LoadRoot(at, Heap::kInstanceofCacheMapRootIndex); |
| 1487 | __ Branch(&fast_case, ne, object_map, Operand(at)); |
| 1488 | __ Ret(USE_DELAY_SLOT); |
| 1489 | __ LoadRoot(v0, Heap::kInstanceofCacheAnswerRootIndex); // In delay slot. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1490 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1491 | // If {object} is a smi we can safely return false if {function} is a JS |
| 1492 | // function, otherwise we have to miss to the runtime and throw an exception. |
| 1493 | __ bind(&object_is_smi); |
| 1494 | __ JumpIfSmi(function, &slow_case); |
| 1495 | __ GetObjectType(function, function_map, scratch); |
| 1496 | __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE)); |
| 1497 | __ Ret(USE_DELAY_SLOT); |
| 1498 | __ LoadRoot(v0, Heap::kFalseValueRootIndex); // In delay slot. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1499 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1500 | // Fast-case: The {function} must be a valid JSFunction. |
| 1501 | __ bind(&fast_case); |
| 1502 | __ JumpIfSmi(function, &slow_case); |
| 1503 | __ GetObjectType(function, function_map, scratch); |
| 1504 | __ Branch(&slow_case, ne, scratch, Operand(JS_FUNCTION_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1505 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1506 | // Go to the runtime if the function is not a constructor. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1507 | __ lbu(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1508 | __ And(at, scratch, Operand(1 << Map::kIsConstructor)); |
| 1509 | __ Branch(&slow_case, eq, at, Operand(zero_reg)); |
| 1510 | |
| 1511 | // Ensure that {function} has an instance prototype. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1512 | __ And(at, scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
| 1513 | __ Branch(&slow_case, ne, at, Operand(zero_reg)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1514 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1515 | // Get the "prototype" (or initial map) of the {function}. |
| 1516 | __ ld(function_prototype, |
| 1517 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1518 | __ AssertNotSmi(function_prototype); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1519 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1520 | // Resolve the prototype if the {function} has an initial map. Afterwards the |
| 1521 | // {function_prototype} will be either the JSReceiver prototype object or the |
| 1522 | // hole value, which means that no instances of the {function} were created so |
| 1523 | // far and hence we should return false. |
| 1524 | Label function_prototype_valid; |
| 1525 | __ GetObjectType(function_prototype, scratch, scratch); |
| 1526 | __ Branch(&function_prototype_valid, ne, scratch, Operand(MAP_TYPE)); |
| 1527 | __ ld(function_prototype, |
| 1528 | FieldMemOperand(function_prototype, Map::kPrototypeOffset)); |
| 1529 | __ bind(&function_prototype_valid); |
| 1530 | __ AssertNotSmi(function_prototype); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1531 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1532 | // Update the global instanceof cache with the current {object} map and |
| 1533 | // {function}. The cached answer will be set when it is known below. |
| 1534 | __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex); |
| 1535 | __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1536 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1537 | // Loop through the prototype chain looking for the {function} prototype. |
| 1538 | // Assume true, and change to false if not found. |
| 1539 | Register const object_instance_type = function_map; |
| 1540 | Register const map_bit_field = function_map; |
| 1541 | Register const null = scratch; |
| 1542 | Register const result = v0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1543 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1544 | Label done, loop, fast_runtime_fallback; |
| 1545 | __ LoadRoot(result, Heap::kTrueValueRootIndex); |
| 1546 | __ LoadRoot(null, Heap::kNullValueRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1547 | __ bind(&loop); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1548 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1549 | // Check if the object needs to be access checked. |
| 1550 | __ lbu(map_bit_field, FieldMemOperand(object_map, Map::kBitFieldOffset)); |
| 1551 | __ And(map_bit_field, map_bit_field, Operand(1 << Map::kIsAccessCheckNeeded)); |
| 1552 | __ Branch(&fast_runtime_fallback, ne, map_bit_field, Operand(zero_reg)); |
| 1553 | // Check if the current object is a Proxy. |
| 1554 | __ lbu(object_instance_type, |
| 1555 | FieldMemOperand(object_map, Map::kInstanceTypeOffset)); |
| 1556 | __ Branch(&fast_runtime_fallback, eq, object_instance_type, |
| 1557 | Operand(JS_PROXY_TYPE)); |
| 1558 | |
| 1559 | __ ld(object, FieldMemOperand(object_map, Map::kPrototypeOffset)); |
| 1560 | __ Branch(&done, eq, object, Operand(function_prototype)); |
| 1561 | __ Branch(USE_DELAY_SLOT, &loop, ne, object, Operand(null)); |
| 1562 | __ ld(object_map, |
| 1563 | FieldMemOperand(object, HeapObject::kMapOffset)); // In delay slot. |
| 1564 | __ LoadRoot(result, Heap::kFalseValueRootIndex); |
| 1565 | __ bind(&done); |
| 1566 | __ Ret(USE_DELAY_SLOT); |
| 1567 | __ StoreRoot(result, |
| 1568 | Heap::kInstanceofCacheAnswerRootIndex); // In delay slot. |
| 1569 | |
| 1570 | // Found Proxy or access check needed: Call the runtime |
| 1571 | __ bind(&fast_runtime_fallback); |
| 1572 | __ Push(object, function_prototype); |
| 1573 | // Invalidate the instanceof cache. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1574 | DCHECK(Smi::FromInt(0) == 0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1575 | __ StoreRoot(zero_reg, Heap::kInstanceofCacheFunctionRootIndex); |
| 1576 | __ TailCallRuntime(Runtime::kHasInPrototypeChain); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1577 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1578 | // Slow-case: Call the %InstanceOf runtime function. |
| 1579 | __ bind(&slow_case); |
| 1580 | __ Push(object, function); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1581 | __ TailCallRuntime(is_es6_instanceof() ? Runtime::kOrdinaryHasInstance |
| 1582 | : Runtime::kInstanceOf); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | |
| 1586 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 1587 | Label miss; |
| 1588 | Register receiver = LoadDescriptor::ReceiverRegister(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1589 | // Ensure that the vector and slot registers won't be clobbered before |
| 1590 | // calling the miss handler. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1591 | DCHECK(!AreAliased(a4, a5, LoadWithVectorDescriptor::VectorRegister(), |
| 1592 | LoadWithVectorDescriptor::SlotRegister())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1593 | |
| 1594 | NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, a4, |
| 1595 | a5, &miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1596 | __ bind(&miss); |
| 1597 | PropertyAccessCompiler::TailCallBuiltin( |
| 1598 | masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC)); |
| 1599 | } |
| 1600 | |
| 1601 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1602 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 1603 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 1604 | // time or if regexp entry in generated code is turned off runtime switch or |
| 1605 | // at compilation. |
| 1606 | #ifdef V8_INTERPRETED_REGEXP |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1607 | __ TailCallRuntime(Runtime::kRegExpExec); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1608 | #else // V8_INTERPRETED_REGEXP |
| 1609 | |
| 1610 | // Stack frame on entry. |
| 1611 | // sp[0]: last_match_info (expected JSArray) |
| 1612 | // sp[4]: previous index |
| 1613 | // sp[8]: subject string |
| 1614 | // sp[12]: JSRegExp object |
| 1615 | |
| 1616 | const int kLastMatchInfoOffset = 0 * kPointerSize; |
| 1617 | const int kPreviousIndexOffset = 1 * kPointerSize; |
| 1618 | const int kSubjectOffset = 2 * kPointerSize; |
| 1619 | const int kJSRegExpOffset = 3 * kPointerSize; |
| 1620 | |
| 1621 | Label runtime; |
| 1622 | // Allocation of registers for this function. These are in callee save |
| 1623 | // registers and will be preserved by the call to the native RegExp code, as |
| 1624 | // this code is called using the normal C calling convention. When calling |
| 1625 | // directly from generated code the native RegExp code will not do a GC and |
| 1626 | // therefore the content of these registers are safe to use after the call. |
| 1627 | // MIPS - using s0..s2, since we are not using CEntry Stub. |
| 1628 | Register subject = s0; |
| 1629 | Register regexp_data = s1; |
| 1630 | Register last_match_info_elements = s2; |
| 1631 | |
| 1632 | // Ensure that a RegExp stack is allocated. |
| 1633 | ExternalReference address_of_regexp_stack_memory_address = |
| 1634 | ExternalReference::address_of_regexp_stack_memory_address( |
| 1635 | isolate()); |
| 1636 | ExternalReference address_of_regexp_stack_memory_size = |
| 1637 | ExternalReference::address_of_regexp_stack_memory_size(isolate()); |
| 1638 | __ li(a0, Operand(address_of_regexp_stack_memory_size)); |
| 1639 | __ ld(a0, MemOperand(a0, 0)); |
| 1640 | __ Branch(&runtime, eq, a0, Operand(zero_reg)); |
| 1641 | |
| 1642 | // Check that the first argument is a JSRegExp object. |
| 1643 | __ ld(a0, MemOperand(sp, kJSRegExpOffset)); |
| 1644 | STATIC_ASSERT(kSmiTag == 0); |
| 1645 | __ JumpIfSmi(a0, &runtime); |
| 1646 | __ GetObjectType(a0, a1, a1); |
| 1647 | __ Branch(&runtime, ne, a1, Operand(JS_REGEXP_TYPE)); |
| 1648 | |
| 1649 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 1650 | __ ld(regexp_data, FieldMemOperand(a0, JSRegExp::kDataOffset)); |
| 1651 | if (FLAG_debug_code) { |
| 1652 | __ SmiTst(regexp_data, a4); |
| 1653 | __ Check(nz, |
| 1654 | kUnexpectedTypeForRegExpDataFixedArrayExpected, |
| 1655 | a4, |
| 1656 | Operand(zero_reg)); |
| 1657 | __ GetObjectType(regexp_data, a0, a0); |
| 1658 | __ Check(eq, |
| 1659 | kUnexpectedTypeForRegExpDataFixedArrayExpected, |
| 1660 | a0, |
| 1661 | Operand(FIXED_ARRAY_TYPE)); |
| 1662 | } |
| 1663 | |
| 1664 | // regexp_data: RegExp data (FixedArray) |
| 1665 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 1666 | __ ld(a0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset)); |
| 1667 | __ Branch(&runtime, ne, a0, Operand(Smi::FromInt(JSRegExp::IRREGEXP))); |
| 1668 | |
| 1669 | // regexp_data: RegExp data (FixedArray) |
| 1670 | // Check that the number of captures fit in the static offsets vector buffer. |
| 1671 | __ ld(a2, |
| 1672 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 1673 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 1674 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 1675 | // Or number_of_captures <= offsets vector size / 2 - 1 |
| 1676 | // Multiplying by 2 comes for free since a2 is smi-tagged. |
| 1677 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 1678 | int temp = Isolate::kJSRegexpStaticOffsetsVectorSize / 2 - 1; |
| 1679 | __ Branch(&runtime, hi, a2, Operand(Smi::FromInt(temp))); |
| 1680 | |
| 1681 | // Reset offset for possibly sliced string. |
| 1682 | __ mov(t0, zero_reg); |
| 1683 | __ ld(subject, MemOperand(sp, kSubjectOffset)); |
| 1684 | __ JumpIfSmi(subject, &runtime); |
| 1685 | __ mov(a3, subject); // Make a copy of the original subject string. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1686 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1687 | // subject: subject string |
| 1688 | // a3: subject string |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1689 | // regexp_data: RegExp data (FixedArray) |
| 1690 | // Handle subject string according to its encoding and representation: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1691 | // (1) Sequential string? If yes, go to (4). |
| 1692 | // (2) Sequential or cons? If not, go to (5). |
| 1693 | // (3) Cons string. If the string is flat, replace subject with first string |
| 1694 | // and go to (1). Otherwise bail out to runtime. |
| 1695 | // (4) Sequential string. Load regexp code according to encoding. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1696 | // (E) Carry on. |
| 1697 | /// [...] |
| 1698 | |
| 1699 | // Deferred code at the end of the stub: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1700 | // (5) Long external string? If not, go to (7). |
| 1701 | // (6) External string. Make it, offset-wise, look like a sequential string. |
| 1702 | // Go to (4). |
| 1703 | // (7) Short external string or not a string? If yes, bail out to runtime. |
| 1704 | // (8) Sliced string. Replace subject with parent. Go to (1). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1705 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1706 | Label check_underlying; // (1) |
| 1707 | Label seq_string; // (4) |
| 1708 | Label not_seq_nor_cons; // (5) |
| 1709 | Label external_string; // (6) |
| 1710 | Label not_long_external; // (7) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1711 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1712 | __ bind(&check_underlying); |
| 1713 | __ ld(a2, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 1714 | __ lbu(a0, FieldMemOperand(a2, Map::kInstanceTypeOffset)); |
| 1715 | |
| 1716 | // (1) Sequential string? If yes, go to (4). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1717 | __ And(a1, |
| 1718 | a0, |
| 1719 | Operand(kIsNotStringMask | |
| 1720 | kStringRepresentationMask | |
| 1721 | kShortExternalStringMask)); |
| 1722 | STATIC_ASSERT((kStringTag | kSeqStringTag) == 0); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1723 | __ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (4). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1724 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1725 | // (2) Sequential or cons? If not, go to (5). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1726 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 1727 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
| 1728 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 1729 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1730 | // Go to (5). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1731 | __ Branch(¬_seq_nor_cons, ge, a1, Operand(kExternalStringTag)); |
| 1732 | |
| 1733 | // (3) Cons string. Check that it's flat. |
| 1734 | // Replace subject with first string and reload instance type. |
| 1735 | __ ld(a0, FieldMemOperand(subject, ConsString::kSecondOffset)); |
| 1736 | __ LoadRoot(a1, Heap::kempty_stringRootIndex); |
| 1737 | __ Branch(&runtime, ne, a0, Operand(a1)); |
| 1738 | __ ld(subject, FieldMemOperand(subject, ConsString::kFirstOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1739 | __ jmp(&check_underlying); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1740 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1741 | // (4) Sequential string. Load regexp code according to encoding. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1742 | __ bind(&seq_string); |
| 1743 | // subject: sequential subject string (or look-alike, external string) |
| 1744 | // a3: original subject string |
| 1745 | // Load previous index and check range before a3 is overwritten. We have to |
| 1746 | // use a3 instead of subject here because subject might have been only made |
| 1747 | // to look like a sequential string when it actually is an external string. |
| 1748 | __ ld(a1, MemOperand(sp, kPreviousIndexOffset)); |
| 1749 | __ JumpIfNotSmi(a1, &runtime); |
| 1750 | __ ld(a3, FieldMemOperand(a3, String::kLengthOffset)); |
| 1751 | __ Branch(&runtime, ls, a3, Operand(a1)); |
| 1752 | __ SmiUntag(a1); |
| 1753 | |
| 1754 | STATIC_ASSERT(kStringEncodingMask == 4); |
| 1755 | STATIC_ASSERT(kOneByteStringTag == 4); |
| 1756 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 1757 | __ And(a0, a0, Operand(kStringEncodingMask)); // Non-zero for one_byte. |
| 1758 | __ ld(t9, FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset)); |
| 1759 | __ dsra(a3, a0, 2); // a3 is 1 for one_byte, 0 for UC16 (used below). |
| 1760 | __ ld(a5, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset)); |
| 1761 | __ Movz(t9, a5, a0); // If UC16 (a0 is 0), replace t9 w/kDataUC16CodeOffset. |
| 1762 | |
| 1763 | // (E) Carry on. String handling is done. |
| 1764 | // t9: irregexp code |
| 1765 | // Check that the irregexp code has been generated for the actual string |
| 1766 | // encoding. If it has, the field contains a code object otherwise it contains |
| 1767 | // a smi (code flushing support). |
| 1768 | __ JumpIfSmi(t9, &runtime); |
| 1769 | |
| 1770 | // a1: previous index |
| 1771 | // a3: encoding of subject string (1 if one_byte, 0 if two_byte); |
| 1772 | // t9: code |
| 1773 | // subject: Subject string |
| 1774 | // regexp_data: RegExp data (FixedArray) |
| 1775 | // All checks done. Now push arguments for native regexp code. |
| 1776 | __ IncrementCounter(isolate()->counters()->regexp_entry_native(), |
| 1777 | 1, a0, a2); |
| 1778 | |
| 1779 | // Isolates: note we add an additional parameter here (isolate pointer). |
| 1780 | const int kRegExpExecuteArguments = 9; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1781 | const int kParameterRegisters = 8; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1782 | __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters); |
| 1783 | |
| 1784 | // Stack pointer now points to cell where return address is to be written. |
| 1785 | // Arguments are before that on the stack or in registers, meaning we |
| 1786 | // treat the return address as argument 5. Thus every argument after that |
| 1787 | // needs to be shifted back by 1. Since DirectCEntryStub will handle |
| 1788 | // allocating space for the c argument slots, we don't need to calculate |
| 1789 | // that into the argument positions on the stack. This is how the stack will |
| 1790 | // look (sp meaning the value of sp at this moment): |
| 1791 | // Abi n64: |
| 1792 | // [sp + 1] - Argument 9 |
| 1793 | // [sp + 0] - saved ra |
| 1794 | // Abi O32: |
| 1795 | // [sp + 5] - Argument 9 |
| 1796 | // [sp + 4] - Argument 8 |
| 1797 | // [sp + 3] - Argument 7 |
| 1798 | // [sp + 2] - Argument 6 |
| 1799 | // [sp + 1] - Argument 5 |
| 1800 | // [sp + 0] - saved ra |
| 1801 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1802 | // Argument 9: Pass current isolate address. |
| 1803 | __ li(a0, Operand(ExternalReference::isolate_address(isolate()))); |
| 1804 | __ sd(a0, MemOperand(sp, 1 * kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1805 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1806 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 1807 | __ li(a7, Operand(1)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1808 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1809 | // Argument 7: Start (high end) of backtracking stack memory area. |
| 1810 | __ li(a0, Operand(address_of_regexp_stack_memory_address)); |
| 1811 | __ ld(a0, MemOperand(a0, 0)); |
| 1812 | __ li(a2, Operand(address_of_regexp_stack_memory_size)); |
| 1813 | __ ld(a2, MemOperand(a2, 0)); |
| 1814 | __ daddu(a6, a0, a2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1815 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1816 | // Argument 6: Set the number of capture registers to zero to force global |
| 1817 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 1818 | __ mov(a5, zero_reg); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1819 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1820 | // Argument 5: static offsets vector buffer. |
| 1821 | __ li( |
| 1822 | a4, |
| 1823 | Operand(ExternalReference::address_of_static_offsets_vector(isolate()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1824 | |
| 1825 | // For arguments 4 and 3 get string length, calculate start of string data |
| 1826 | // and calculate the shift of the index (0 for one_byte and 1 for two byte). |
| 1827 | __ Daddu(t2, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag)); |
| 1828 | __ Xor(a3, a3, Operand(1)); // 1 for 2-byte str, 0 for 1-byte. |
| 1829 | // Load the length from the original subject string from the previous stack |
| 1830 | // frame. Therefore we have to use fp, which points exactly to two pointer |
| 1831 | // sizes below the previous sp. (Because creating a new stack frame pushes |
| 1832 | // the previous fp onto the stack and moves up sp by 2 * kPointerSize.) |
| 1833 | __ ld(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize)); |
| 1834 | // If slice offset is not 0, load the length from the original sliced string. |
| 1835 | // Argument 4, a3: End of string data |
| 1836 | // Argument 3, a2: Start of string data |
| 1837 | // Prepare start and end index of the input. |
| 1838 | __ dsllv(t1, t0, a3); |
| 1839 | __ daddu(t0, t2, t1); |
| 1840 | __ dsllv(t1, a1, a3); |
| 1841 | __ daddu(a2, t0, t1); |
| 1842 | |
| 1843 | __ ld(t2, FieldMemOperand(subject, String::kLengthOffset)); |
| 1844 | |
| 1845 | __ SmiUntag(t2); |
| 1846 | __ dsllv(t1, t2, a3); |
| 1847 | __ daddu(a3, t0, t1); |
| 1848 | // Argument 2 (a1): Previous index. |
| 1849 | // Already there |
| 1850 | |
| 1851 | // Argument 1 (a0): Subject string. |
| 1852 | __ mov(a0, subject); |
| 1853 | |
| 1854 | // Locate the code entry and call it. |
| 1855 | __ Daddu(t9, t9, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 1856 | DirectCEntryStub stub(isolate()); |
| 1857 | stub.GenerateCall(masm, t9); |
| 1858 | |
| 1859 | __ LeaveExitFrame(false, no_reg, true); |
| 1860 | |
| 1861 | // v0: result |
| 1862 | // subject: subject string (callee saved) |
| 1863 | // regexp_data: RegExp data (callee saved) |
| 1864 | // last_match_info_elements: Last match info elements (callee saved) |
| 1865 | // Check the result. |
| 1866 | Label success; |
| 1867 | __ Branch(&success, eq, v0, Operand(1)); |
| 1868 | // We expect exactly one result since we force the called regexp to behave |
| 1869 | // as non-global. |
| 1870 | Label failure; |
| 1871 | __ Branch(&failure, eq, v0, Operand(NativeRegExpMacroAssembler::FAILURE)); |
| 1872 | // If not exception it can only be retry. Handle that in the runtime system. |
| 1873 | __ Branch(&runtime, ne, v0, Operand(NativeRegExpMacroAssembler::EXCEPTION)); |
| 1874 | // Result must now be exception. If there is no pending exception already a |
| 1875 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 1876 | // haven't created the exception yet. Handle that in the runtime system. |
| 1877 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
| 1878 | __ li(a1, Operand(isolate()->factory()->the_hole_value())); |
| 1879 | __ li(a2, Operand(ExternalReference(Isolate::kPendingExceptionAddress, |
| 1880 | isolate()))); |
| 1881 | __ ld(v0, MemOperand(a2, 0)); |
| 1882 | __ Branch(&runtime, eq, v0, Operand(a1)); |
| 1883 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1884 | // For exception, throw the exception again. |
| 1885 | __ TailCallRuntime(Runtime::kRegExpExecReThrow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1886 | |
| 1887 | __ bind(&failure); |
| 1888 | // For failure and exception return null. |
| 1889 | __ li(v0, Operand(isolate()->factory()->null_value())); |
| 1890 | __ DropAndRet(4); |
| 1891 | |
| 1892 | // Process the result from the native regexp code. |
| 1893 | __ bind(&success); |
| 1894 | |
| 1895 | __ lw(a1, UntagSmiFieldMemOperand( |
| 1896 | regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 1897 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 1898 | __ Daddu(a1, a1, Operand(1)); |
| 1899 | __ dsll(a1, a1, 1); // Multiply by 2. |
| 1900 | |
| 1901 | __ ld(a0, MemOperand(sp, kLastMatchInfoOffset)); |
| 1902 | __ JumpIfSmi(a0, &runtime); |
| 1903 | __ GetObjectType(a0, a2, a2); |
| 1904 | __ Branch(&runtime, ne, a2, Operand(JS_ARRAY_TYPE)); |
| 1905 | // Check that the JSArray is in fast case. |
| 1906 | __ ld(last_match_info_elements, |
| 1907 | FieldMemOperand(a0, JSArray::kElementsOffset)); |
| 1908 | __ ld(a0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset)); |
| 1909 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 1910 | __ Branch(&runtime, ne, a0, Operand(at)); |
| 1911 | // Check that the last match info has space for the capture registers and the |
| 1912 | // additional information. |
| 1913 | __ ld(a0, |
| 1914 | FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset)); |
| 1915 | __ Daddu(a2, a1, Operand(RegExpImpl::kLastMatchOverhead)); |
| 1916 | |
| 1917 | __ SmiUntag(at, a0); |
| 1918 | __ Branch(&runtime, gt, a2, Operand(at)); |
| 1919 | |
| 1920 | // a1: number of capture registers |
| 1921 | // subject: subject string |
| 1922 | // Store the capture count. |
| 1923 | __ SmiTag(a2, a1); // To smi. |
| 1924 | __ sd(a2, FieldMemOperand(last_match_info_elements, |
| 1925 | RegExpImpl::kLastCaptureCountOffset)); |
| 1926 | // Store last subject and last input. |
| 1927 | __ sd(subject, |
| 1928 | FieldMemOperand(last_match_info_elements, |
| 1929 | RegExpImpl::kLastSubjectOffset)); |
| 1930 | __ mov(a2, subject); |
| 1931 | __ RecordWriteField(last_match_info_elements, |
| 1932 | RegExpImpl::kLastSubjectOffset, |
| 1933 | subject, |
| 1934 | a7, |
| 1935 | kRAHasNotBeenSaved, |
| 1936 | kDontSaveFPRegs); |
| 1937 | __ mov(subject, a2); |
| 1938 | __ sd(subject, |
| 1939 | FieldMemOperand(last_match_info_elements, |
| 1940 | RegExpImpl::kLastInputOffset)); |
| 1941 | __ RecordWriteField(last_match_info_elements, |
| 1942 | RegExpImpl::kLastInputOffset, |
| 1943 | subject, |
| 1944 | a7, |
| 1945 | kRAHasNotBeenSaved, |
| 1946 | kDontSaveFPRegs); |
| 1947 | |
| 1948 | // Get the static offsets vector filled by the native regexp code. |
| 1949 | ExternalReference address_of_static_offsets_vector = |
| 1950 | ExternalReference::address_of_static_offsets_vector(isolate()); |
| 1951 | __ li(a2, Operand(address_of_static_offsets_vector)); |
| 1952 | |
| 1953 | // a1: number of capture registers |
| 1954 | // a2: offsets vector |
| 1955 | Label next_capture, done; |
| 1956 | // Capture register counter starts from number of capture registers and |
| 1957 | // counts down until wrapping after zero. |
| 1958 | __ Daddu(a0, |
| 1959 | last_match_info_elements, |
| 1960 | Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag)); |
| 1961 | __ bind(&next_capture); |
| 1962 | __ Dsubu(a1, a1, Operand(1)); |
| 1963 | __ Branch(&done, lt, a1, Operand(zero_reg)); |
| 1964 | // Read the value from the static offsets vector buffer. |
| 1965 | __ lw(a3, MemOperand(a2, 0)); |
| 1966 | __ daddiu(a2, a2, kIntSize); |
| 1967 | // Store the smi value in the last match info. |
| 1968 | __ SmiTag(a3); |
| 1969 | __ sd(a3, MemOperand(a0, 0)); |
| 1970 | __ Branch(&next_capture, USE_DELAY_SLOT); |
| 1971 | __ daddiu(a0, a0, kPointerSize); // In branch delay slot. |
| 1972 | |
| 1973 | __ bind(&done); |
| 1974 | |
| 1975 | // Return last match info. |
| 1976 | __ ld(v0, MemOperand(sp, kLastMatchInfoOffset)); |
| 1977 | __ DropAndRet(4); |
| 1978 | |
| 1979 | // Do the runtime call to execute the regexp. |
| 1980 | __ bind(&runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1981 | __ TailCallRuntime(Runtime::kRegExpExec); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1982 | |
| 1983 | // Deferred code for string handling. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1984 | // (5) Long external string? If not, go to (7). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1985 | __ bind(¬_seq_nor_cons); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1986 | // Go to (7). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1987 | __ Branch(¬_long_external, gt, a1, Operand(kExternalStringTag)); |
| 1988 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1989 | // (6) External string. Make it, offset-wise, look like a sequential string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1990 | __ bind(&external_string); |
| 1991 | __ ld(a0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 1992 | __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset)); |
| 1993 | if (FLAG_debug_code) { |
| 1994 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 1995 | // Sequential strings have already been ruled out. |
| 1996 | __ And(at, a0, Operand(kIsIndirectStringMask)); |
| 1997 | __ Assert(eq, |
| 1998 | kExternalStringExpectedButNotFound, |
| 1999 | at, |
| 2000 | Operand(zero_reg)); |
| 2001 | } |
| 2002 | __ ld(subject, |
| 2003 | FieldMemOperand(subject, ExternalString::kResourceDataOffset)); |
| 2004 | // Move the pointer so that offset-wise, it looks like a sequential string. |
| 2005 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
| 2006 | __ Dsubu(subject, |
| 2007 | subject, |
| 2008 | SeqTwoByteString::kHeaderSize - kHeapObjectTag); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2009 | __ jmp(&seq_string); // Go to (4). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2010 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2011 | // (7) Short external string or not a string? If yes, bail out to runtime. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2012 | __ bind(¬_long_external); |
| 2013 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 2014 | __ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask)); |
| 2015 | __ Branch(&runtime, ne, at, Operand(zero_reg)); |
| 2016 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2017 | // (8) Sliced string. Replace subject with parent. Go to (4). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2018 | // Load offset into t0 and replace subject string with parent. |
| 2019 | __ ld(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset)); |
| 2020 | __ SmiUntag(t0); |
| 2021 | __ ld(subject, FieldMemOperand(subject, SlicedString::kParentOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2022 | __ jmp(&check_underlying); // Go to (1). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2023 | #endif // V8_INTERPRETED_REGEXP |
| 2024 | } |
| 2025 | |
| 2026 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2027 | static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) { |
| 2028 | // a0 : number of arguments to the construct function |
| 2029 | // a2 : feedback vector |
| 2030 | // a3 : slot in feedback vector (Smi) |
| 2031 | // a1 : the function to call |
| 2032 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2033 | const RegList kSavedRegs = 1 << 4 | // a0 |
| 2034 | 1 << 5 | // a1 |
| 2035 | 1 << 6 | // a2 |
| 2036 | 1 << 7; // a3 |
| 2037 | |
| 2038 | |
| 2039 | // Number-of-arguments register must be smi-tagged to call out. |
| 2040 | __ SmiTag(a0); |
| 2041 | __ MultiPush(kSavedRegs); |
| 2042 | |
| 2043 | __ CallStub(stub); |
| 2044 | |
| 2045 | __ MultiPop(kSavedRegs); |
| 2046 | __ SmiUntag(a0); |
| 2047 | } |
| 2048 | |
| 2049 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2050 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 2051 | // Cache the called function in a feedback vector slot. Cache states |
| 2052 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 2053 | // megamorphic. |
| 2054 | // a0 : number of arguments to the construct function |
| 2055 | // a1 : the function to call |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2056 | // a2 : feedback vector |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2057 | // a3 : slot in feedback vector (Smi) |
| 2058 | Label initialize, done, miss, megamorphic, not_array_function; |
| 2059 | |
| 2060 | DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()), |
| 2061 | masm->isolate()->heap()->megamorphic_symbol()); |
| 2062 | DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()), |
| 2063 | masm->isolate()->heap()->uninitialized_symbol()); |
| 2064 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2065 | // Load the cache state into a5. |
| 2066 | __ dsrl(a5, a3, 32 - kPointerSizeLog2); |
| 2067 | __ Daddu(a5, a2, Operand(a5)); |
| 2068 | __ ld(a5, FieldMemOperand(a5, FixedArray::kHeaderSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2069 | |
| 2070 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 2071 | // function without changing the state. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2072 | // We don't know if a5 is a WeakCell or a Symbol, but it's harmless to read at |
| 2073 | // this position in a symbol (see static asserts in type-feedback-vector.h). |
| 2074 | Label check_allocation_site; |
| 2075 | Register feedback_map = a6; |
| 2076 | Register weak_value = t0; |
| 2077 | __ ld(weak_value, FieldMemOperand(a5, WeakCell::kValueOffset)); |
| 2078 | __ Branch(&done, eq, a1, Operand(weak_value)); |
| 2079 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 2080 | __ Branch(&done, eq, a5, Operand(at)); |
| 2081 | __ ld(feedback_map, FieldMemOperand(a5, HeapObject::kMapOffset)); |
| 2082 | __ LoadRoot(at, Heap::kWeakCellMapRootIndex); |
| 2083 | __ Branch(&check_allocation_site, ne, feedback_map, Operand(at)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2084 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2085 | // If the weak cell is cleared, we have a new chance to become monomorphic. |
| 2086 | __ JumpIfSmi(weak_value, &initialize); |
| 2087 | __ jmp(&megamorphic); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2088 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2089 | __ bind(&check_allocation_site); |
| 2090 | // If we came here, we need to see if we are the array function. |
| 2091 | // If we didn't have a matching function, and we didn't find the megamorph |
| 2092 | // sentinel, then we have in the slot either some other function or an |
| 2093 | // AllocationSite. |
| 2094 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 2095 | __ Branch(&miss, ne, feedback_map, Operand(at)); |
| 2096 | |
| 2097 | // Make sure the function is the Array() function |
| 2098 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, a5); |
| 2099 | __ Branch(&megamorphic, ne, a1, Operand(a5)); |
| 2100 | __ jmp(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2101 | |
| 2102 | __ bind(&miss); |
| 2103 | |
| 2104 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 2105 | // megamorphic. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2106 | __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2107 | __ Branch(&initialize, eq, a5, Operand(at)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2108 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 2109 | // write-barrier is needed. |
| 2110 | __ bind(&megamorphic); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2111 | __ dsrl(a5, a3, 32 - kPointerSizeLog2); |
| 2112 | __ Daddu(a5, a2, Operand(a5)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2113 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2114 | __ sd(at, FieldMemOperand(a5, FixedArray::kHeaderSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2115 | __ jmp(&done); |
| 2116 | |
| 2117 | // An uninitialized cache is patched with the function. |
| 2118 | __ bind(&initialize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2119 | // Make sure the function is the Array() function. |
| 2120 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, a5); |
| 2121 | __ Branch(¬_array_function, ne, a1, Operand(a5)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2122 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2123 | // The target function is the Array constructor, |
| 2124 | // Create an AllocationSite if we don't already have it, store it in the |
| 2125 | // slot. |
| 2126 | CreateAllocationSiteStub create_stub(masm->isolate()); |
| 2127 | CallStubInRecordCallTarget(masm, &create_stub); |
| 2128 | __ Branch(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2129 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2130 | __ bind(¬_array_function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2131 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2132 | CreateWeakCellStub weak_cell_stub(masm->isolate()); |
| 2133 | CallStubInRecordCallTarget(masm, &weak_cell_stub); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2134 | __ bind(&done); |
| 2135 | } |
| 2136 | |
| 2137 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2138 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 2139 | // a0 : number of arguments |
| 2140 | // a1 : the function to call |
| 2141 | // a2 : feedback vector |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2142 | // a3 : slot in feedback vector (Smi, for RecordCallTarget) |
| 2143 | |
| 2144 | Label non_function; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2145 | // Check that the function is not a smi. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2146 | __ JumpIfSmi(a1, &non_function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2147 | // Check that the function is a JSFunction. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2148 | __ GetObjectType(a1, a5, a5); |
| 2149 | __ Branch(&non_function, ne, a5, Operand(JS_FUNCTION_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2150 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2151 | GenerateRecordCallTarget(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2152 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2153 | __ dsrl(at, a3, 32 - kPointerSizeLog2); |
| 2154 | __ Daddu(a5, a2, at); |
| 2155 | Label feedback_register_initialized; |
| 2156 | // Put the AllocationSite from the feedback vector into a2, or undefined. |
| 2157 | __ ld(a2, FieldMemOperand(a5, FixedArray::kHeaderSize)); |
| 2158 | __ ld(a5, FieldMemOperand(a2, AllocationSite::kMapOffset)); |
| 2159 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 2160 | __ Branch(&feedback_register_initialized, eq, a5, Operand(at)); |
| 2161 | __ LoadRoot(a2, Heap::kUndefinedValueRootIndex); |
| 2162 | __ bind(&feedback_register_initialized); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2163 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2164 | __ AssertUndefinedOrAllocationSite(a2, a5); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2165 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2166 | // Pass function as new target. |
| 2167 | __ mov(a3, a1); |
| 2168 | |
| 2169 | // Tail call to the function-specific construct stub (still in the caller |
| 2170 | // context at this point). |
| 2171 | __ ld(a4, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 2172 | __ ld(a4, FieldMemOperand(a4, SharedFunctionInfo::kConstructStubOffset)); |
| 2173 | __ Daddu(at, a4, Operand(Code::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2174 | __ Jump(at); |
| 2175 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2176 | __ bind(&non_function); |
| 2177 | __ mov(a3, a1); |
| 2178 | __ Jump(isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2179 | } |
| 2180 | |
| 2181 | |
| 2182 | // StringCharCodeAtGenerator. |
| 2183 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 2184 | DCHECK(!a4.is(index_)); |
| 2185 | DCHECK(!a4.is(result_)); |
| 2186 | DCHECK(!a4.is(object_)); |
| 2187 | |
| 2188 | // If the receiver is a smi trigger the non-string case. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2189 | if (check_mode_ == RECEIVER_IS_UNKNOWN) { |
| 2190 | __ JumpIfSmi(object_, receiver_not_string_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2191 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2192 | // Fetch the instance type of the receiver into result register. |
| 2193 | __ ld(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 2194 | __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 2195 | // If the receiver is not a string trigger the non-string case. |
| 2196 | __ And(a4, result_, Operand(kIsNotStringMask)); |
| 2197 | __ Branch(receiver_not_string_, ne, a4, Operand(zero_reg)); |
| 2198 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2199 | |
| 2200 | // If the index is non-smi trigger the non-smi case. |
| 2201 | __ JumpIfNotSmi(index_, &index_not_smi_); |
| 2202 | |
| 2203 | __ bind(&got_smi_index_); |
| 2204 | |
| 2205 | // Check for index out of range. |
| 2206 | __ ld(a4, FieldMemOperand(object_, String::kLengthOffset)); |
| 2207 | __ Branch(index_out_of_range_, ls, a4, Operand(index_)); |
| 2208 | |
| 2209 | __ SmiUntag(index_); |
| 2210 | |
| 2211 | StringCharLoadGenerator::Generate(masm, |
| 2212 | object_, |
| 2213 | index_, |
| 2214 | result_, |
| 2215 | &call_runtime_); |
| 2216 | |
| 2217 | __ SmiTag(result_); |
| 2218 | __ bind(&exit_); |
| 2219 | } |
| 2220 | |
| 2221 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2222 | void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2223 | // a1 - function |
| 2224 | // a3 - slot id |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2225 | // a2 - vector |
| 2226 | // a4 - allocation site (loaded from vector[slot]) |
| 2227 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, at); |
| 2228 | __ Branch(miss, ne, a1, Operand(at)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2229 | |
| 2230 | __ li(a0, Operand(arg_count())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2231 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2232 | // Increment the call count for monomorphic function calls. |
| 2233 | __ dsrl(t0, a3, 32 - kPointerSizeLog2); |
| 2234 | __ Daddu(a3, a2, Operand(t0)); |
| 2235 | __ ld(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize)); |
| 2236 | __ Daddu(t0, t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement))); |
| 2237 | __ sd(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2238 | |
| 2239 | __ mov(a2, a4); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2240 | __ mov(a3, a1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2241 | ArrayConstructorStub stub(masm->isolate(), arg_count()); |
| 2242 | __ TailCallStub(&stub); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2243 | } |
| 2244 | |
| 2245 | |
| 2246 | void CallICStub::Generate(MacroAssembler* masm) { |
| 2247 | // a1 - function |
| 2248 | // a3 - slot id (Smi) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2249 | // a2 - vector |
| 2250 | Label extra_checks_or_miss, call, call_function; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2251 | int argc = arg_count(); |
| 2252 | ParameterCount actual(argc); |
| 2253 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2254 | // The checks. First, does r1 match the recorded monomorphic target? |
| 2255 | __ dsrl(a4, a3, 32 - kPointerSizeLog2); |
| 2256 | __ Daddu(a4, a2, Operand(a4)); |
| 2257 | __ ld(a4, FieldMemOperand(a4, FixedArray::kHeaderSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2258 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2259 | // We don't know that we have a weak cell. We might have a private symbol |
| 2260 | // or an AllocationSite, but the memory is safe to examine. |
| 2261 | // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to |
| 2262 | // FixedArray. |
| 2263 | // WeakCell::kValueOffset - contains a JSFunction or Smi(0) |
| 2264 | // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not |
| 2265 | // computed, meaning that it can't appear to be a pointer. If the low bit is |
| 2266 | // 0, then hash is computed, but the 0 bit prevents the field from appearing |
| 2267 | // to be a pointer. |
| 2268 | STATIC_ASSERT(WeakCell::kSize >= kPointerSize); |
| 2269 | STATIC_ASSERT(AllocationSite::kTransitionInfoOffset == |
| 2270 | WeakCell::kValueOffset && |
| 2271 | WeakCell::kValueOffset == Symbol::kHashFieldSlot); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2272 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2273 | __ ld(a5, FieldMemOperand(a4, WeakCell::kValueOffset)); |
| 2274 | __ Branch(&extra_checks_or_miss, ne, a1, Operand(a5)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2275 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2276 | // The compare above could have been a SMI/SMI comparison. Guard against this |
| 2277 | // convincing us that we have a monomorphic JSFunction. |
| 2278 | __ JumpIfSmi(a1, &extra_checks_or_miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2279 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2280 | // Increment the call count for monomorphic function calls. |
| 2281 | __ dsrl(t0, a3, 32 - kPointerSizeLog2); |
| 2282 | __ Daddu(a3, a2, Operand(t0)); |
| 2283 | __ ld(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize)); |
| 2284 | __ Daddu(t0, t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement))); |
| 2285 | __ sd(t0, FieldMemOperand(a3, FixedArray::kHeaderSize + kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2286 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2287 | __ bind(&call_function); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2288 | __ Jump(masm->isolate()->builtins()->CallFunction(convert_mode(), |
| 2289 | tail_call_mode()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2290 | RelocInfo::CODE_TARGET, al, zero_reg, Operand(zero_reg), |
| 2291 | USE_DELAY_SLOT); |
| 2292 | __ li(a0, Operand(argc)); // In delay slot. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2293 | |
| 2294 | __ bind(&extra_checks_or_miss); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2295 | Label uninitialized, miss, not_allocation_site; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2296 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2297 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2298 | __ Branch(&call, eq, a4, Operand(at)); |
| 2299 | |
| 2300 | // Verify that a4 contains an AllocationSite |
| 2301 | __ ld(a5, FieldMemOperand(a4, HeapObject::kMapOffset)); |
| 2302 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 2303 | __ Branch(¬_allocation_site, ne, a5, Operand(at)); |
| 2304 | |
| 2305 | HandleArrayCase(masm, &miss); |
| 2306 | |
| 2307 | __ bind(¬_allocation_site); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2308 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2309 | // The following cases attempt to handle MISS cases without going to the |
| 2310 | // runtime. |
| 2311 | if (FLAG_trace_ic) { |
| 2312 | __ Branch(&miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2315 | __ LoadRoot(at, Heap::kuninitialized_symbolRootIndex); |
| 2316 | __ Branch(&uninitialized, eq, a4, Operand(at)); |
| 2317 | |
| 2318 | // We are going megamorphic. If the feedback is a JSFunction, it is fine |
| 2319 | // to handle it here. More complex cases are dealt with in the runtime. |
| 2320 | __ AssertNotSmi(a4); |
| 2321 | __ GetObjectType(a4, a5, a5); |
| 2322 | __ Branch(&miss, ne, a5, Operand(JS_FUNCTION_TYPE)); |
| 2323 | __ dsrl(a4, a3, 32 - kPointerSizeLog2); |
| 2324 | __ Daddu(a4, a2, Operand(a4)); |
| 2325 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 2326 | __ sd(at, FieldMemOperand(a4, FixedArray::kHeaderSize)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2327 | |
| 2328 | __ bind(&call); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2329 | __ Jump(masm->isolate()->builtins()->Call(convert_mode(), tail_call_mode()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2330 | RelocInfo::CODE_TARGET, al, zero_reg, Operand(zero_reg), |
| 2331 | USE_DELAY_SLOT); |
| 2332 | __ li(a0, Operand(argc)); // In delay slot. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2333 | |
| 2334 | __ bind(&uninitialized); |
| 2335 | |
| 2336 | // We are going monomorphic, provided we actually have a JSFunction. |
| 2337 | __ JumpIfSmi(a1, &miss); |
| 2338 | |
| 2339 | // Goto miss case if we do not have a function. |
| 2340 | __ GetObjectType(a1, a4, a4); |
| 2341 | __ Branch(&miss, ne, a4, Operand(JS_FUNCTION_TYPE)); |
| 2342 | |
| 2343 | // Make sure the function is not the Array() function, which requires special |
| 2344 | // behavior on MISS. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2345 | __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, a4); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2346 | __ Branch(&miss, eq, a1, Operand(a4)); |
| 2347 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2348 | // Make sure the function belongs to the same native context. |
| 2349 | __ ld(t0, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 2350 | __ ld(t0, ContextMemOperand(t0, Context::NATIVE_CONTEXT_INDEX)); |
| 2351 | __ ld(t1, NativeContextMemOperand()); |
| 2352 | __ Branch(&miss, ne, t0, Operand(t1)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2353 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2354 | // Initialize the call counter. |
| 2355 | __ dsrl(at, a3, 32 - kPointerSizeLog2); |
| 2356 | __ Daddu(at, a2, Operand(at)); |
| 2357 | __ li(t0, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement))); |
| 2358 | __ sd(t0, FieldMemOperand(at, FixedArray::kHeaderSize + kPointerSize)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2359 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2360 | // Store the function. Use a stub since we need a frame for allocation. |
| 2361 | // a2 - vector |
| 2362 | // a3 - slot |
| 2363 | // a1 - function |
| 2364 | { |
| 2365 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2366 | CreateWeakCellStub create_stub(masm->isolate()); |
| 2367 | __ Push(a1); |
| 2368 | __ CallStub(&create_stub); |
| 2369 | __ Pop(a1); |
| 2370 | } |
| 2371 | |
| 2372 | __ Branch(&call_function); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2373 | |
| 2374 | // We are here because tracing is on or we encountered a MISS case we can't |
| 2375 | // handle here. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2376 | __ bind(&miss); |
| 2377 | GenerateMiss(masm); |
| 2378 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2379 | __ Branch(&call); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | |
| 2383 | void CallICStub::GenerateMiss(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2384 | FrameScope scope(masm, StackFrame::INTERNAL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2385 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2386 | // Push the receiver and the function and feedback info. |
| 2387 | __ Push(a1, a2, a3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2388 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2389 | // Call the entry. |
| 2390 | __ CallRuntime(Runtime::kCallIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2391 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2392 | // Move result to a1 and exit the internal frame. |
| 2393 | __ mov(a1, v0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2394 | } |
| 2395 | |
| 2396 | |
| 2397 | void StringCharCodeAtGenerator::GenerateSlow( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2398 | MacroAssembler* masm, EmbedMode embed_mode, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2399 | const RuntimeCallHelper& call_helper) { |
| 2400 | __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase); |
| 2401 | |
| 2402 | // Index is not a smi. |
| 2403 | __ bind(&index_not_smi_); |
| 2404 | // If index is a heap number, try converting it to an integer. |
| 2405 | __ CheckMap(index_, |
| 2406 | result_, |
| 2407 | Heap::kHeapNumberMapRootIndex, |
| 2408 | index_not_number_, |
| 2409 | DONT_DO_SMI_CHECK); |
| 2410 | call_helper.BeforeCall(masm); |
| 2411 | // Consumed by runtime conversion function: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2412 | if (embed_mode == PART_OF_IC_HANDLER) { |
| 2413 | __ Push(LoadWithVectorDescriptor::VectorRegister(), |
| 2414 | LoadWithVectorDescriptor::SlotRegister(), object_, index_); |
| 2415 | } else { |
| 2416 | __ Push(object_, index_); |
| 2417 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2418 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2419 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2420 | } else { |
| 2421 | DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 2422 | // NumberToSmi discards numbers that are not exact integers. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2423 | __ CallRuntime(Runtime::kNumberToSmi); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | // Save the conversion result before the pop instructions below |
| 2427 | // have a chance to overwrite it. |
| 2428 | |
| 2429 | __ Move(index_, v0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2430 | if (embed_mode == PART_OF_IC_HANDLER) { |
| 2431 | __ Pop(LoadWithVectorDescriptor::VectorRegister(), |
| 2432 | LoadWithVectorDescriptor::SlotRegister(), object_); |
| 2433 | } else { |
| 2434 | __ pop(object_); |
| 2435 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2436 | // Reload the instance type. |
| 2437 | __ ld(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 2438 | __ lbu(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 2439 | call_helper.AfterCall(masm); |
| 2440 | // If index is still not a smi, it must be out of range. |
| 2441 | __ JumpIfNotSmi(index_, index_out_of_range_); |
| 2442 | // Otherwise, return to the fast path. |
| 2443 | __ Branch(&got_smi_index_); |
| 2444 | |
| 2445 | // Call runtime. We get here when the receiver is a string and the |
| 2446 | // index is a number, but the code of getting the actual character |
| 2447 | // is too complex (e.g., when the string needs to be flattened). |
| 2448 | __ bind(&call_runtime_); |
| 2449 | call_helper.BeforeCall(masm); |
| 2450 | __ SmiTag(index_); |
| 2451 | __ Push(object_, index_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2452 | __ CallRuntime(Runtime::kStringCharCodeAtRT); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2453 | |
| 2454 | __ Move(result_, v0); |
| 2455 | |
| 2456 | call_helper.AfterCall(masm); |
| 2457 | __ jmp(&exit_); |
| 2458 | |
| 2459 | __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase); |
| 2460 | } |
| 2461 | |
| 2462 | |
| 2463 | // ------------------------------------------------------------------------- |
| 2464 | // StringCharFromCodeGenerator |
| 2465 | |
| 2466 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 2467 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2468 | __ JumpIfNotSmi(code_, &slow_case_); |
| 2469 | __ Branch(&slow_case_, hi, code_, |
| 2470 | Operand(Smi::FromInt(String::kMaxOneByteCharCode))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2471 | |
| 2472 | __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex); |
| 2473 | // At this point code register contains smi tagged one_byte char code. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2474 | __ SmiScale(at, code_, kPointerSizeLog2); |
| 2475 | __ Daddu(result_, result_, at); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2476 | __ ld(result_, FieldMemOperand(result_, FixedArray::kHeaderSize)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2477 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 2478 | __ Branch(&slow_case_, eq, result_, Operand(at)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2479 | __ bind(&exit_); |
| 2480 | } |
| 2481 | |
| 2482 | |
| 2483 | void StringCharFromCodeGenerator::GenerateSlow( |
| 2484 | MacroAssembler* masm, |
| 2485 | const RuntimeCallHelper& call_helper) { |
| 2486 | __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase); |
| 2487 | |
| 2488 | __ bind(&slow_case_); |
| 2489 | call_helper.BeforeCall(masm); |
| 2490 | __ push(code_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2491 | __ CallRuntime(Runtime::kStringCharFromCode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2492 | __ Move(result_, v0); |
| 2493 | |
| 2494 | call_helper.AfterCall(masm); |
| 2495 | __ Branch(&exit_); |
| 2496 | |
| 2497 | __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase); |
| 2498 | } |
| 2499 | |
| 2500 | |
| 2501 | enum CopyCharactersFlags { COPY_ONE_BYTE = 1, DEST_ALWAYS_ALIGNED = 2 }; |
| 2502 | |
| 2503 | |
| 2504 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 2505 | Register dest, |
| 2506 | Register src, |
| 2507 | Register count, |
| 2508 | Register scratch, |
| 2509 | String::Encoding encoding) { |
| 2510 | if (FLAG_debug_code) { |
| 2511 | // Check that destination is word aligned. |
| 2512 | __ And(scratch, dest, Operand(kPointerAlignmentMask)); |
| 2513 | __ Check(eq, |
| 2514 | kDestinationOfCopyNotAligned, |
| 2515 | scratch, |
| 2516 | Operand(zero_reg)); |
| 2517 | } |
| 2518 | |
| 2519 | // Assumes word reads and writes are little endian. |
| 2520 | // Nothing to do for zero characters. |
| 2521 | Label done; |
| 2522 | |
| 2523 | if (encoding == String::TWO_BYTE_ENCODING) { |
| 2524 | __ Daddu(count, count, count); |
| 2525 | } |
| 2526 | |
| 2527 | Register limit = count; // Read until dest equals this. |
| 2528 | __ Daddu(limit, dest, Operand(count)); |
| 2529 | |
| 2530 | Label loop_entry, loop; |
| 2531 | // Copy bytes from src to dest until dest hits limit. |
| 2532 | __ Branch(&loop_entry); |
| 2533 | __ bind(&loop); |
| 2534 | __ lbu(scratch, MemOperand(src)); |
| 2535 | __ daddiu(src, src, 1); |
| 2536 | __ sb(scratch, MemOperand(dest)); |
| 2537 | __ daddiu(dest, dest, 1); |
| 2538 | __ bind(&loop_entry); |
| 2539 | __ Branch(&loop, lt, dest, Operand(limit)); |
| 2540 | |
| 2541 | __ bind(&done); |
| 2542 | } |
| 2543 | |
| 2544 | |
| 2545 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 2546 | Label runtime; |
| 2547 | // Stack frame on entry. |
| 2548 | // ra: return address |
| 2549 | // sp[0]: to |
| 2550 | // sp[4]: from |
| 2551 | // sp[8]: string |
| 2552 | |
| 2553 | // This stub is called from the native-call %_SubString(...), so |
| 2554 | // nothing can be assumed about the arguments. It is tested that: |
| 2555 | // "string" is a sequential string, |
| 2556 | // both "from" and "to" are smis, and |
| 2557 | // 0 <= from <= to <= string.length. |
| 2558 | // If any of these assumptions fail, we call the runtime system. |
| 2559 | |
| 2560 | const int kToOffset = 0 * kPointerSize; |
| 2561 | const int kFromOffset = 1 * kPointerSize; |
| 2562 | const int kStringOffset = 2 * kPointerSize; |
| 2563 | |
| 2564 | __ ld(a2, MemOperand(sp, kToOffset)); |
| 2565 | __ ld(a3, MemOperand(sp, kFromOffset)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2566 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2567 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2568 | |
| 2569 | // Utilize delay slots. SmiUntag doesn't emit a jump, everything else is |
| 2570 | // safe in this case. |
| 2571 | __ JumpIfNotSmi(a2, &runtime); |
| 2572 | __ JumpIfNotSmi(a3, &runtime); |
| 2573 | // Both a2 and a3 are untagged integers. |
| 2574 | |
| 2575 | __ SmiUntag(a2, a2); |
| 2576 | __ SmiUntag(a3, a3); |
| 2577 | __ Branch(&runtime, lt, a3, Operand(zero_reg)); // From < 0. |
| 2578 | |
| 2579 | __ Branch(&runtime, gt, a3, Operand(a2)); // Fail if from > to. |
| 2580 | __ Dsubu(a2, a2, a3); |
| 2581 | |
| 2582 | // Make sure first argument is a string. |
| 2583 | __ ld(v0, MemOperand(sp, kStringOffset)); |
| 2584 | __ JumpIfSmi(v0, &runtime); |
| 2585 | __ ld(a1, FieldMemOperand(v0, HeapObject::kMapOffset)); |
| 2586 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
| 2587 | __ And(a4, a1, Operand(kIsNotStringMask)); |
| 2588 | |
| 2589 | __ Branch(&runtime, ne, a4, Operand(zero_reg)); |
| 2590 | |
| 2591 | Label single_char; |
| 2592 | __ Branch(&single_char, eq, a2, Operand(1)); |
| 2593 | |
| 2594 | // Short-cut for the case of trivial substring. |
| 2595 | Label return_v0; |
| 2596 | // v0: original string |
| 2597 | // a2: result string length |
| 2598 | __ ld(a4, FieldMemOperand(v0, String::kLengthOffset)); |
| 2599 | __ SmiUntag(a4); |
| 2600 | // Return original string. |
| 2601 | __ Branch(&return_v0, eq, a2, Operand(a4)); |
| 2602 | // Longer than original string's length or negative: unsafe arguments. |
| 2603 | __ Branch(&runtime, hi, a2, Operand(a4)); |
| 2604 | // Shorter than original string's length: an actual substring. |
| 2605 | |
| 2606 | // Deal with different string types: update the index if necessary |
| 2607 | // and put the underlying string into a5. |
| 2608 | // v0: original string |
| 2609 | // a1: instance type |
| 2610 | // a2: length |
| 2611 | // a3: from index (untagged) |
| 2612 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 2613 | // If the string is not indirect, it can only be sequential or external. |
| 2614 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 2615 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 2616 | __ And(a4, a1, Operand(kIsIndirectStringMask)); |
| 2617 | __ Branch(USE_DELAY_SLOT, &seq_or_external_string, eq, a4, Operand(zero_reg)); |
| 2618 | // a4 is used as a scratch register and can be overwritten in either case. |
| 2619 | __ And(a4, a1, Operand(kSlicedNotConsMask)); |
| 2620 | __ Branch(&sliced_string, ne, a4, Operand(zero_reg)); |
| 2621 | // Cons string. Check whether it is flat, then fetch first part. |
| 2622 | __ ld(a5, FieldMemOperand(v0, ConsString::kSecondOffset)); |
| 2623 | __ LoadRoot(a4, Heap::kempty_stringRootIndex); |
| 2624 | __ Branch(&runtime, ne, a5, Operand(a4)); |
| 2625 | __ ld(a5, FieldMemOperand(v0, ConsString::kFirstOffset)); |
| 2626 | // Update instance type. |
| 2627 | __ ld(a1, FieldMemOperand(a5, HeapObject::kMapOffset)); |
| 2628 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
| 2629 | __ jmp(&underlying_unpacked); |
| 2630 | |
| 2631 | __ bind(&sliced_string); |
| 2632 | // Sliced string. Fetch parent and correct start index by offset. |
| 2633 | __ ld(a5, FieldMemOperand(v0, SlicedString::kParentOffset)); |
| 2634 | __ ld(a4, FieldMemOperand(v0, SlicedString::kOffsetOffset)); |
| 2635 | __ SmiUntag(a4); // Add offset to index. |
| 2636 | __ Daddu(a3, a3, a4); |
| 2637 | // Update instance type. |
| 2638 | __ ld(a1, FieldMemOperand(a5, HeapObject::kMapOffset)); |
| 2639 | __ lbu(a1, FieldMemOperand(a1, Map::kInstanceTypeOffset)); |
| 2640 | __ jmp(&underlying_unpacked); |
| 2641 | |
| 2642 | __ bind(&seq_or_external_string); |
| 2643 | // Sequential or external string. Just move string to the expected register. |
| 2644 | __ mov(a5, v0); |
| 2645 | |
| 2646 | __ bind(&underlying_unpacked); |
| 2647 | |
| 2648 | if (FLAG_string_slices) { |
| 2649 | Label copy_routine; |
| 2650 | // a5: underlying subject string |
| 2651 | // a1: instance type of underlying subject string |
| 2652 | // a2: length |
| 2653 | // a3: adjusted start index (untagged) |
| 2654 | // Short slice. Copy instead of slicing. |
| 2655 | __ Branch(©_routine, lt, a2, Operand(SlicedString::kMinLength)); |
| 2656 | // Allocate new sliced string. At this point we do not reload the instance |
| 2657 | // type including the string encoding because we simply rely on the info |
| 2658 | // provided by the original string. It does not matter if the original |
| 2659 | // string's encoding is wrong because we always have to recheck encoding of |
| 2660 | // the newly created string's parent anyways due to externalized strings. |
| 2661 | Label two_byte_slice, set_slice_header; |
| 2662 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
| 2663 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 2664 | __ And(a4, a1, Operand(kStringEncodingMask)); |
| 2665 | __ Branch(&two_byte_slice, eq, a4, Operand(zero_reg)); |
| 2666 | __ AllocateOneByteSlicedString(v0, a2, a6, a7, &runtime); |
| 2667 | __ jmp(&set_slice_header); |
| 2668 | __ bind(&two_byte_slice); |
| 2669 | __ AllocateTwoByteSlicedString(v0, a2, a6, a7, &runtime); |
| 2670 | __ bind(&set_slice_header); |
| 2671 | __ SmiTag(a3); |
| 2672 | __ sd(a5, FieldMemOperand(v0, SlicedString::kParentOffset)); |
| 2673 | __ sd(a3, FieldMemOperand(v0, SlicedString::kOffsetOffset)); |
| 2674 | __ jmp(&return_v0); |
| 2675 | |
| 2676 | __ bind(©_routine); |
| 2677 | } |
| 2678 | |
| 2679 | // a5: underlying subject string |
| 2680 | // a1: instance type of underlying subject string |
| 2681 | // a2: length |
| 2682 | // a3: adjusted start index (untagged) |
| 2683 | Label two_byte_sequential, sequential_string, allocate_result; |
| 2684 | STATIC_ASSERT(kExternalStringTag != 0); |
| 2685 | STATIC_ASSERT(kSeqStringTag == 0); |
| 2686 | __ And(a4, a1, Operand(kExternalStringTag)); |
| 2687 | __ Branch(&sequential_string, eq, a4, Operand(zero_reg)); |
| 2688 | |
| 2689 | // Handle external string. |
| 2690 | // Rule out short external strings. |
| 2691 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 2692 | __ And(a4, a1, Operand(kShortExternalStringTag)); |
| 2693 | __ Branch(&runtime, ne, a4, Operand(zero_reg)); |
| 2694 | __ ld(a5, FieldMemOperand(a5, ExternalString::kResourceDataOffset)); |
| 2695 | // a5 already points to the first character of underlying string. |
| 2696 | __ jmp(&allocate_result); |
| 2697 | |
| 2698 | __ bind(&sequential_string); |
| 2699 | // Locate first character of underlying subject string. |
| 2700 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
| 2701 | __ Daddu(a5, a5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
| 2702 | |
| 2703 | __ bind(&allocate_result); |
| 2704 | // Sequential acii string. Allocate the result. |
| 2705 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
| 2706 | __ And(a4, a1, Operand(kStringEncodingMask)); |
| 2707 | __ Branch(&two_byte_sequential, eq, a4, Operand(zero_reg)); |
| 2708 | |
| 2709 | // Allocate and copy the resulting one_byte string. |
| 2710 | __ AllocateOneByteString(v0, a2, a4, a6, a7, &runtime); |
| 2711 | |
| 2712 | // Locate first character of substring to copy. |
| 2713 | __ Daddu(a5, a5, a3); |
| 2714 | |
| 2715 | // Locate first character of result. |
| 2716 | __ Daddu(a1, v0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
| 2717 | |
| 2718 | // v0: result string |
| 2719 | // a1: first character of result string |
| 2720 | // a2: result string length |
| 2721 | // a5: first character of substring to copy |
| 2722 | STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 2723 | StringHelper::GenerateCopyCharacters( |
| 2724 | masm, a1, a5, a2, a3, String::ONE_BYTE_ENCODING); |
| 2725 | __ jmp(&return_v0); |
| 2726 | |
| 2727 | // Allocate and copy the resulting two-byte string. |
| 2728 | __ bind(&two_byte_sequential); |
| 2729 | __ AllocateTwoByteString(v0, a2, a4, a6, a7, &runtime); |
| 2730 | |
| 2731 | // Locate first character of substring to copy. |
| 2732 | STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2733 | __ Dlsa(a5, a5, a3, 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2734 | // Locate first character of result. |
| 2735 | __ Daddu(a1, v0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 2736 | |
| 2737 | // v0: result string. |
| 2738 | // a1: first character of result. |
| 2739 | // a2: result length. |
| 2740 | // a5: first character of substring to copy. |
| 2741 | STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 2742 | StringHelper::GenerateCopyCharacters( |
| 2743 | masm, a1, a5, a2, a3, String::TWO_BYTE_ENCODING); |
| 2744 | |
| 2745 | __ bind(&return_v0); |
| 2746 | Counters* counters = isolate()->counters(); |
| 2747 | __ IncrementCounter(counters->sub_string_native(), 1, a3, a4); |
| 2748 | __ DropAndRet(3); |
| 2749 | |
| 2750 | // Just jump to runtime to create the sub string. |
| 2751 | __ bind(&runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2752 | __ TailCallRuntime(Runtime::kSubString); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2753 | |
| 2754 | __ bind(&single_char); |
| 2755 | // v0: original string |
| 2756 | // a1: instance type |
| 2757 | // a2: length |
| 2758 | // a3: from index (untagged) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2759 | __ SmiTag(a3); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2760 | StringCharAtGenerator generator(v0, a3, a2, v0, &runtime, &runtime, &runtime, |
| 2761 | STRING_INDEX_IS_NUMBER, RECEIVER_IS_STRING); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2762 | generator.GenerateFast(masm); |
| 2763 | __ DropAndRet(3); |
| 2764 | generator.SkipSlow(masm, &runtime); |
| 2765 | } |
| 2766 | |
| 2767 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2768 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 2769 | // The ToNumber stub takes one argument in a0. |
| 2770 | Label not_smi; |
| 2771 | __ JumpIfNotSmi(a0, ¬_smi); |
| 2772 | __ Ret(USE_DELAY_SLOT); |
| 2773 | __ mov(v0, a0); |
| 2774 | __ bind(¬_smi); |
| 2775 | |
| 2776 | Label not_heap_number; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2777 | __ GetObjectType(a0, a1, a1); |
| 2778 | // a0: receiver |
| 2779 | // a1: receiver instance type |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2780 | __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE)); |
| 2781 | __ Ret(USE_DELAY_SLOT); |
| 2782 | __ mov(v0, a0); |
| 2783 | __ bind(¬_heap_number); |
| 2784 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2785 | NonNumberToNumberStub stub(masm->isolate()); |
| 2786 | __ TailCallStub(&stub); |
| 2787 | } |
| 2788 | |
| 2789 | void NonNumberToNumberStub::Generate(MacroAssembler* masm) { |
| 2790 | // The NonNumberToNumber stub takes on argument in a0. |
| 2791 | __ AssertNotNumber(a0); |
| 2792 | |
| 2793 | Label not_string; |
| 2794 | __ GetObjectType(a0, a1, a1); |
| 2795 | // a0: receiver |
| 2796 | // a1: receiver instance type |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2797 | __ Branch(¬_string, hs, a1, Operand(FIRST_NONSTRING_TYPE)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2798 | StringToNumberStub stub(masm->isolate()); |
| 2799 | __ TailCallStub(&stub); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2800 | __ bind(¬_string); |
| 2801 | |
| 2802 | Label not_oddball; |
| 2803 | __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE)); |
| 2804 | __ Ret(USE_DELAY_SLOT); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2805 | __ ld(v0, FieldMemOperand(a0, Oddball::kToNumberOffset)); // In delay slot. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2806 | __ bind(¬_oddball); |
| 2807 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2808 | __ Push(a0); // Push argument. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2809 | __ TailCallRuntime(Runtime::kToNumber); |
| 2810 | } |
| 2811 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2812 | void StringToNumberStub::Generate(MacroAssembler* masm) { |
| 2813 | // The StringToNumber stub takes on argument in a0. |
| 2814 | __ AssertString(a0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2815 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2816 | // Check if string has a cached array index. |
| 2817 | Label runtime; |
| 2818 | __ lwu(a2, FieldMemOperand(a0, String::kHashFieldOffset)); |
| 2819 | __ And(at, a2, Operand(String::kContainsCachedArrayIndexMask)); |
| 2820 | __ Branch(&runtime, ne, at, Operand(zero_reg)); |
| 2821 | __ IndexFromHash(a2, v0); |
| 2822 | __ Ret(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2823 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2824 | __ bind(&runtime); |
| 2825 | __ Push(a0); // Push argument. |
| 2826 | __ TailCallRuntime(Runtime::kStringToNumber); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2829 | void ToStringStub::Generate(MacroAssembler* masm) { |
| 2830 | // The ToString stub takes on argument in a0. |
| 2831 | Label is_number; |
| 2832 | __ JumpIfSmi(a0, &is_number); |
| 2833 | |
| 2834 | Label not_string; |
| 2835 | __ GetObjectType(a0, a1, a1); |
| 2836 | // a0: receiver |
| 2837 | // a1: receiver instance type |
| 2838 | __ Branch(¬_string, ge, a1, Operand(FIRST_NONSTRING_TYPE)); |
| 2839 | __ Ret(USE_DELAY_SLOT); |
| 2840 | __ mov(v0, a0); |
| 2841 | __ bind(¬_string); |
| 2842 | |
| 2843 | Label not_heap_number; |
| 2844 | __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE)); |
| 2845 | __ bind(&is_number); |
| 2846 | NumberToStringStub stub(isolate()); |
| 2847 | __ TailCallStub(&stub); |
| 2848 | __ bind(¬_heap_number); |
| 2849 | |
| 2850 | Label not_oddball; |
| 2851 | __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE)); |
| 2852 | __ Ret(USE_DELAY_SLOT); |
| 2853 | __ ld(v0, FieldMemOperand(a0, Oddball::kToStringOffset)); |
| 2854 | __ bind(¬_oddball); |
| 2855 | |
| 2856 | __ push(a0); // Push argument. |
| 2857 | __ TailCallRuntime(Runtime::kToString); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2861 | void ToNameStub::Generate(MacroAssembler* masm) { |
| 2862 | // The ToName stub takes on argument in a0. |
| 2863 | Label is_number; |
| 2864 | __ JumpIfSmi(a0, &is_number); |
| 2865 | |
| 2866 | Label not_name; |
| 2867 | STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE); |
| 2868 | __ GetObjectType(a0, a1, a1); |
| 2869 | // a0: receiver |
| 2870 | // a1: receiver instance type |
| 2871 | __ Branch(¬_name, gt, a1, Operand(LAST_NAME_TYPE)); |
| 2872 | __ Ret(USE_DELAY_SLOT); |
| 2873 | __ mov(v0, a0); |
| 2874 | __ bind(¬_name); |
| 2875 | |
| 2876 | Label not_heap_number; |
| 2877 | __ Branch(¬_heap_number, ne, a1, Operand(HEAP_NUMBER_TYPE)); |
| 2878 | __ bind(&is_number); |
| 2879 | NumberToStringStub stub(isolate()); |
| 2880 | __ TailCallStub(&stub); |
| 2881 | __ bind(¬_heap_number); |
| 2882 | |
| 2883 | Label not_oddball; |
| 2884 | __ Branch(¬_oddball, ne, a1, Operand(ODDBALL_TYPE)); |
| 2885 | __ Ret(USE_DELAY_SLOT); |
| 2886 | __ ld(v0, FieldMemOperand(a0, Oddball::kToStringOffset)); |
| 2887 | __ bind(¬_oddball); |
| 2888 | |
| 2889 | __ push(a0); // Push argument. |
| 2890 | __ TailCallRuntime(Runtime::kToName); |
| 2891 | } |
| 2892 | |
| 2893 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2894 | void StringHelper::GenerateFlatOneByteStringEquals( |
| 2895 | MacroAssembler* masm, Register left, Register right, Register scratch1, |
| 2896 | Register scratch2, Register scratch3) { |
| 2897 | Register length = scratch1; |
| 2898 | |
| 2899 | // Compare lengths. |
| 2900 | Label strings_not_equal, check_zero_length; |
| 2901 | __ ld(length, FieldMemOperand(left, String::kLengthOffset)); |
| 2902 | __ ld(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 2903 | __ Branch(&check_zero_length, eq, length, Operand(scratch2)); |
| 2904 | __ bind(&strings_not_equal); |
| 2905 | // Can not put li in delayslot, it has multi instructions. |
| 2906 | __ li(v0, Operand(Smi::FromInt(NOT_EQUAL))); |
| 2907 | __ Ret(); |
| 2908 | |
| 2909 | // Check if the length is zero. |
| 2910 | Label compare_chars; |
| 2911 | __ bind(&check_zero_length); |
| 2912 | STATIC_ASSERT(kSmiTag == 0); |
| 2913 | __ Branch(&compare_chars, ne, length, Operand(zero_reg)); |
| 2914 | DCHECK(is_int16((intptr_t)Smi::FromInt(EQUAL))); |
| 2915 | __ Ret(USE_DELAY_SLOT); |
| 2916 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
| 2917 | |
| 2918 | // Compare characters. |
| 2919 | __ bind(&compare_chars); |
| 2920 | |
| 2921 | GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, scratch3, |
| 2922 | v0, &strings_not_equal); |
| 2923 | |
| 2924 | // Characters are equal. |
| 2925 | __ Ret(USE_DELAY_SLOT); |
| 2926 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
| 2927 | } |
| 2928 | |
| 2929 | |
| 2930 | void StringHelper::GenerateCompareFlatOneByteStrings( |
| 2931 | MacroAssembler* masm, Register left, Register right, Register scratch1, |
| 2932 | Register scratch2, Register scratch3, Register scratch4) { |
| 2933 | Label result_not_equal, compare_lengths; |
| 2934 | // Find minimum length and length difference. |
| 2935 | __ ld(scratch1, FieldMemOperand(left, String::kLengthOffset)); |
| 2936 | __ ld(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 2937 | __ Dsubu(scratch3, scratch1, Operand(scratch2)); |
| 2938 | Register length_delta = scratch3; |
| 2939 | __ slt(scratch4, scratch2, scratch1); |
| 2940 | __ Movn(scratch1, scratch2, scratch4); |
| 2941 | Register min_length = scratch1; |
| 2942 | STATIC_ASSERT(kSmiTag == 0); |
| 2943 | __ Branch(&compare_lengths, eq, min_length, Operand(zero_reg)); |
| 2944 | |
| 2945 | // Compare loop. |
| 2946 | GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2, |
| 2947 | scratch4, v0, &result_not_equal); |
| 2948 | |
| 2949 | // Compare lengths - strings up to min-length are equal. |
| 2950 | __ bind(&compare_lengths); |
| 2951 | DCHECK(Smi::FromInt(EQUAL) == static_cast<Smi*>(0)); |
| 2952 | // Use length_delta as result if it's zero. |
| 2953 | __ mov(scratch2, length_delta); |
| 2954 | __ mov(scratch4, zero_reg); |
| 2955 | __ mov(v0, zero_reg); |
| 2956 | |
| 2957 | __ bind(&result_not_equal); |
| 2958 | // Conditionally update the result based either on length_delta or |
| 2959 | // the last comparion performed in the loop above. |
| 2960 | Label ret; |
| 2961 | __ Branch(&ret, eq, scratch2, Operand(scratch4)); |
| 2962 | __ li(v0, Operand(Smi::FromInt(GREATER))); |
| 2963 | __ Branch(&ret, gt, scratch2, Operand(scratch4)); |
| 2964 | __ li(v0, Operand(Smi::FromInt(LESS))); |
| 2965 | __ bind(&ret); |
| 2966 | __ Ret(); |
| 2967 | } |
| 2968 | |
| 2969 | |
| 2970 | void StringHelper::GenerateOneByteCharsCompareLoop( |
| 2971 | MacroAssembler* masm, Register left, Register right, Register length, |
| 2972 | Register scratch1, Register scratch2, Register scratch3, |
| 2973 | Label* chars_not_equal) { |
| 2974 | // Change index to run from -length to -1 by adding length to string |
| 2975 | // start. This means that loop ends when index reaches zero, which |
| 2976 | // doesn't need an additional compare. |
| 2977 | __ SmiUntag(length); |
| 2978 | __ Daddu(scratch1, length, |
| 2979 | Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
| 2980 | __ Daddu(left, left, Operand(scratch1)); |
| 2981 | __ Daddu(right, right, Operand(scratch1)); |
| 2982 | __ Dsubu(length, zero_reg, length); |
| 2983 | Register index = length; // index = -length; |
| 2984 | |
| 2985 | |
| 2986 | // Compare loop. |
| 2987 | Label loop; |
| 2988 | __ bind(&loop); |
| 2989 | __ Daddu(scratch3, left, index); |
| 2990 | __ lbu(scratch1, MemOperand(scratch3)); |
| 2991 | __ Daddu(scratch3, right, index); |
| 2992 | __ lbu(scratch2, MemOperand(scratch3)); |
| 2993 | __ Branch(chars_not_equal, ne, scratch1, Operand(scratch2)); |
| 2994 | __ Daddu(index, index, 1); |
| 2995 | __ Branch(&loop, ne, index, Operand(zero_reg)); |
| 2996 | } |
| 2997 | |
| 2998 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2999 | void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { |
| 3000 | // ----------- S t a t e ------------- |
| 3001 | // -- a1 : left |
| 3002 | // -- a0 : right |
| 3003 | // -- ra : return address |
| 3004 | // ----------------------------------- |
| 3005 | |
| 3006 | // Load a2 with the allocation site. We stick an undefined dummy value here |
| 3007 | // and replace it with the real allocation site later when we instantiate this |
| 3008 | // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate(). |
| 3009 | __ li(a2, handle(isolate()->heap()->undefined_value())); |
| 3010 | |
| 3011 | // Make sure that we actually patched the allocation site. |
| 3012 | if (FLAG_debug_code) { |
| 3013 | __ And(at, a2, Operand(kSmiTagMask)); |
| 3014 | __ Assert(ne, kExpectedAllocationSite, at, Operand(zero_reg)); |
| 3015 | __ ld(a4, FieldMemOperand(a2, HeapObject::kMapOffset)); |
| 3016 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 3017 | __ Assert(eq, kExpectedAllocationSite, a4, Operand(at)); |
| 3018 | } |
| 3019 | |
| 3020 | // Tail call into the stub that handles binary operations with allocation |
| 3021 | // sites. |
| 3022 | BinaryOpWithAllocationSiteStub stub(isolate(), state()); |
| 3023 | __ TailCallStub(&stub); |
| 3024 | } |
| 3025 | |
| 3026 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3027 | void CompareICStub::GenerateBooleans(MacroAssembler* masm) { |
| 3028 | DCHECK_EQ(CompareICState::BOOLEAN, state()); |
| 3029 | Label miss; |
| 3030 | |
| 3031 | __ CheckMap(a1, a2, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK); |
| 3032 | __ CheckMap(a0, a3, Heap::kBooleanMapRootIndex, &miss, DO_SMI_CHECK); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3033 | if (!Token::IsEqualityOp(op())) { |
| 3034 | __ ld(a1, FieldMemOperand(a1, Oddball::kToNumberOffset)); |
| 3035 | __ AssertSmi(a1); |
| 3036 | __ ld(a0, FieldMemOperand(a0, Oddball::kToNumberOffset)); |
| 3037 | __ AssertSmi(a0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3038 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3039 | __ Ret(USE_DELAY_SLOT); |
| 3040 | __ Dsubu(v0, a1, a0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3041 | |
| 3042 | __ bind(&miss); |
| 3043 | GenerateMiss(masm); |
| 3044 | } |
| 3045 | |
| 3046 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3047 | void CompareICStub::GenerateSmis(MacroAssembler* masm) { |
| 3048 | DCHECK(state() == CompareICState::SMI); |
| 3049 | Label miss; |
| 3050 | __ Or(a2, a1, a0); |
| 3051 | __ JumpIfNotSmi(a2, &miss); |
| 3052 | |
| 3053 | if (GetCondition() == eq) { |
| 3054 | // For equality we do not care about the sign of the result. |
| 3055 | __ Ret(USE_DELAY_SLOT); |
| 3056 | __ Dsubu(v0, a0, a1); |
| 3057 | } else { |
| 3058 | // Untag before subtracting to avoid handling overflow. |
| 3059 | __ SmiUntag(a1); |
| 3060 | __ SmiUntag(a0); |
| 3061 | __ Ret(USE_DELAY_SLOT); |
| 3062 | __ Dsubu(v0, a1, a0); |
| 3063 | } |
| 3064 | |
| 3065 | __ bind(&miss); |
| 3066 | GenerateMiss(masm); |
| 3067 | } |
| 3068 | |
| 3069 | |
| 3070 | void CompareICStub::GenerateNumbers(MacroAssembler* masm) { |
| 3071 | DCHECK(state() == CompareICState::NUMBER); |
| 3072 | |
| 3073 | Label generic_stub; |
| 3074 | Label unordered, maybe_undefined1, maybe_undefined2; |
| 3075 | Label miss; |
| 3076 | |
| 3077 | if (left() == CompareICState::SMI) { |
| 3078 | __ JumpIfNotSmi(a1, &miss); |
| 3079 | } |
| 3080 | if (right() == CompareICState::SMI) { |
| 3081 | __ JumpIfNotSmi(a0, &miss); |
| 3082 | } |
| 3083 | |
| 3084 | // Inlining the double comparison and falling back to the general compare |
| 3085 | // stub if NaN is involved. |
| 3086 | // Load left and right operand. |
| 3087 | Label done, left, left_smi, right_smi; |
| 3088 | __ JumpIfSmi(a0, &right_smi); |
| 3089 | __ CheckMap(a0, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1, |
| 3090 | DONT_DO_SMI_CHECK); |
| 3091 | __ Dsubu(a2, a0, Operand(kHeapObjectTag)); |
| 3092 | __ ldc1(f2, MemOperand(a2, HeapNumber::kValueOffset)); |
| 3093 | __ Branch(&left); |
| 3094 | __ bind(&right_smi); |
| 3095 | __ SmiUntag(a2, a0); // Can't clobber a0 yet. |
| 3096 | FPURegister single_scratch = f6; |
| 3097 | __ mtc1(a2, single_scratch); |
| 3098 | __ cvt_d_w(f2, single_scratch); |
| 3099 | |
| 3100 | __ bind(&left); |
| 3101 | __ JumpIfSmi(a1, &left_smi); |
| 3102 | __ CheckMap(a1, a2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2, |
| 3103 | DONT_DO_SMI_CHECK); |
| 3104 | __ Dsubu(a2, a1, Operand(kHeapObjectTag)); |
| 3105 | __ ldc1(f0, MemOperand(a2, HeapNumber::kValueOffset)); |
| 3106 | __ Branch(&done); |
| 3107 | __ bind(&left_smi); |
| 3108 | __ SmiUntag(a2, a1); // Can't clobber a1 yet. |
| 3109 | single_scratch = f8; |
| 3110 | __ mtc1(a2, single_scratch); |
| 3111 | __ cvt_d_w(f0, single_scratch); |
| 3112 | |
| 3113 | __ bind(&done); |
| 3114 | |
| 3115 | // Return a result of -1, 0, or 1, or use CompareStub for NaNs. |
| 3116 | Label fpu_eq, fpu_lt; |
| 3117 | // Test if equal, and also handle the unordered/NaN case. |
| 3118 | __ BranchF(&fpu_eq, &unordered, eq, f0, f2); |
| 3119 | |
| 3120 | // Test if less (unordered case is already handled). |
| 3121 | __ BranchF(&fpu_lt, NULL, lt, f0, f2); |
| 3122 | |
| 3123 | // Otherwise it's greater, so just fall thru, and return. |
| 3124 | DCHECK(is_int16(GREATER) && is_int16(EQUAL) && is_int16(LESS)); |
| 3125 | __ Ret(USE_DELAY_SLOT); |
| 3126 | __ li(v0, Operand(GREATER)); |
| 3127 | |
| 3128 | __ bind(&fpu_eq); |
| 3129 | __ Ret(USE_DELAY_SLOT); |
| 3130 | __ li(v0, Operand(EQUAL)); |
| 3131 | |
| 3132 | __ bind(&fpu_lt); |
| 3133 | __ Ret(USE_DELAY_SLOT); |
| 3134 | __ li(v0, Operand(LESS)); |
| 3135 | |
| 3136 | __ bind(&unordered); |
| 3137 | __ bind(&generic_stub); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3138 | CompareICStub stub(isolate(), op(), CompareICState::GENERIC, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3139 | CompareICState::GENERIC, CompareICState::GENERIC); |
| 3140 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 3141 | |
| 3142 | __ bind(&maybe_undefined1); |
| 3143 | if (Token::IsOrderedRelationalCompareOp(op())) { |
| 3144 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 3145 | __ Branch(&miss, ne, a0, Operand(at)); |
| 3146 | __ JumpIfSmi(a1, &unordered); |
| 3147 | __ GetObjectType(a1, a2, a2); |
| 3148 | __ Branch(&maybe_undefined2, ne, a2, Operand(HEAP_NUMBER_TYPE)); |
| 3149 | __ jmp(&unordered); |
| 3150 | } |
| 3151 | |
| 3152 | __ bind(&maybe_undefined2); |
| 3153 | if (Token::IsOrderedRelationalCompareOp(op())) { |
| 3154 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 3155 | __ Branch(&unordered, eq, a1, Operand(at)); |
| 3156 | } |
| 3157 | |
| 3158 | __ bind(&miss); |
| 3159 | GenerateMiss(masm); |
| 3160 | } |
| 3161 | |
| 3162 | |
| 3163 | void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 3164 | DCHECK(state() == CompareICState::INTERNALIZED_STRING); |
| 3165 | Label miss; |
| 3166 | |
| 3167 | // Registers containing left and right operands respectively. |
| 3168 | Register left = a1; |
| 3169 | Register right = a0; |
| 3170 | Register tmp1 = a2; |
| 3171 | Register tmp2 = a3; |
| 3172 | |
| 3173 | // Check that both operands are heap objects. |
| 3174 | __ JumpIfEitherSmi(left, right, &miss); |
| 3175 | |
| 3176 | // Check that both operands are internalized strings. |
| 3177 | __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 3178 | __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 3179 | __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3180 | __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 3181 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 3182 | __ Or(tmp1, tmp1, Operand(tmp2)); |
| 3183 | __ And(at, tmp1, Operand(kIsNotStringMask | kIsNotInternalizedMask)); |
| 3184 | __ Branch(&miss, ne, at, Operand(zero_reg)); |
| 3185 | |
| 3186 | // Make sure a0 is non-zero. At this point input operands are |
| 3187 | // guaranteed to be non-zero. |
| 3188 | DCHECK(right.is(a0)); |
| 3189 | STATIC_ASSERT(EQUAL == 0); |
| 3190 | STATIC_ASSERT(kSmiTag == 0); |
| 3191 | __ mov(v0, right); |
| 3192 | // Internalized strings are compared by identity. |
| 3193 | __ Ret(ne, left, Operand(right)); |
| 3194 | DCHECK(is_int16(EQUAL)); |
| 3195 | __ Ret(USE_DELAY_SLOT); |
| 3196 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
| 3197 | |
| 3198 | __ bind(&miss); |
| 3199 | GenerateMiss(masm); |
| 3200 | } |
| 3201 | |
| 3202 | |
| 3203 | void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 3204 | DCHECK(state() == CompareICState::UNIQUE_NAME); |
| 3205 | DCHECK(GetCondition() == eq); |
| 3206 | Label miss; |
| 3207 | |
| 3208 | // Registers containing left and right operands respectively. |
| 3209 | Register left = a1; |
| 3210 | Register right = a0; |
| 3211 | Register tmp1 = a2; |
| 3212 | Register tmp2 = a3; |
| 3213 | |
| 3214 | // Check that both operands are heap objects. |
| 3215 | __ JumpIfEitherSmi(left, right, &miss); |
| 3216 | |
| 3217 | // Check that both operands are unique names. This leaves the instance |
| 3218 | // types loaded in tmp1 and tmp2. |
| 3219 | __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 3220 | __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 3221 | __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3222 | __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 3223 | |
| 3224 | __ JumpIfNotUniqueNameInstanceType(tmp1, &miss); |
| 3225 | __ JumpIfNotUniqueNameInstanceType(tmp2, &miss); |
| 3226 | |
| 3227 | // Use a0 as result |
| 3228 | __ mov(v0, a0); |
| 3229 | |
| 3230 | // Unique names are compared by identity. |
| 3231 | Label done; |
| 3232 | __ Branch(&done, ne, left, Operand(right)); |
| 3233 | // Make sure a0 is non-zero. At this point input operands are |
| 3234 | // guaranteed to be non-zero. |
| 3235 | DCHECK(right.is(a0)); |
| 3236 | STATIC_ASSERT(EQUAL == 0); |
| 3237 | STATIC_ASSERT(kSmiTag == 0); |
| 3238 | __ li(v0, Operand(Smi::FromInt(EQUAL))); |
| 3239 | __ bind(&done); |
| 3240 | __ Ret(); |
| 3241 | |
| 3242 | __ bind(&miss); |
| 3243 | GenerateMiss(masm); |
| 3244 | } |
| 3245 | |
| 3246 | |
| 3247 | void CompareICStub::GenerateStrings(MacroAssembler* masm) { |
| 3248 | DCHECK(state() == CompareICState::STRING); |
| 3249 | Label miss; |
| 3250 | |
| 3251 | bool equality = Token::IsEqualityOp(op()); |
| 3252 | |
| 3253 | // Registers containing left and right operands respectively. |
| 3254 | Register left = a1; |
| 3255 | Register right = a0; |
| 3256 | Register tmp1 = a2; |
| 3257 | Register tmp2 = a3; |
| 3258 | Register tmp3 = a4; |
| 3259 | Register tmp4 = a5; |
| 3260 | Register tmp5 = a6; |
| 3261 | |
| 3262 | // Check that both operands are heap objects. |
| 3263 | __ JumpIfEitherSmi(left, right, &miss); |
| 3264 | |
| 3265 | // Check that both operands are strings. This leaves the instance |
| 3266 | // types loaded in tmp1 and tmp2. |
| 3267 | __ ld(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 3268 | __ ld(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 3269 | __ lbu(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3270 | __ lbu(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 3271 | STATIC_ASSERT(kNotStringTag != 0); |
| 3272 | __ Or(tmp3, tmp1, tmp2); |
| 3273 | __ And(tmp5, tmp3, Operand(kIsNotStringMask)); |
| 3274 | __ Branch(&miss, ne, tmp5, Operand(zero_reg)); |
| 3275 | |
| 3276 | // Fast check for identical strings. |
| 3277 | Label left_ne_right; |
| 3278 | STATIC_ASSERT(EQUAL == 0); |
| 3279 | STATIC_ASSERT(kSmiTag == 0); |
| 3280 | __ Branch(&left_ne_right, ne, left, Operand(right)); |
| 3281 | __ Ret(USE_DELAY_SLOT); |
| 3282 | __ mov(v0, zero_reg); // In the delay slot. |
| 3283 | __ bind(&left_ne_right); |
| 3284 | |
| 3285 | // Handle not identical strings. |
| 3286 | |
| 3287 | // Check that both strings are internalized strings. If they are, we're done |
| 3288 | // because we already know they are not identical. We know they are both |
| 3289 | // strings. |
| 3290 | if (equality) { |
| 3291 | DCHECK(GetCondition() == eq); |
| 3292 | STATIC_ASSERT(kInternalizedTag == 0); |
| 3293 | __ Or(tmp3, tmp1, Operand(tmp2)); |
| 3294 | __ And(tmp5, tmp3, Operand(kIsNotInternalizedMask)); |
| 3295 | Label is_symbol; |
| 3296 | __ Branch(&is_symbol, ne, tmp5, Operand(zero_reg)); |
| 3297 | // Make sure a0 is non-zero. At this point input operands are |
| 3298 | // guaranteed to be non-zero. |
| 3299 | DCHECK(right.is(a0)); |
| 3300 | __ Ret(USE_DELAY_SLOT); |
| 3301 | __ mov(v0, a0); // In the delay slot. |
| 3302 | __ bind(&is_symbol); |
| 3303 | } |
| 3304 | |
| 3305 | // Check that both strings are sequential one_byte. |
| 3306 | Label runtime; |
| 3307 | __ JumpIfBothInstanceTypesAreNotSequentialOneByte(tmp1, tmp2, tmp3, tmp4, |
| 3308 | &runtime); |
| 3309 | |
| 3310 | // Compare flat one_byte strings. Returns when done. |
| 3311 | if (equality) { |
| 3312 | StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, tmp2, |
| 3313 | tmp3); |
| 3314 | } else { |
| 3315 | StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1, |
| 3316 | tmp2, tmp3, tmp4); |
| 3317 | } |
| 3318 | |
| 3319 | // Handle more complex cases in runtime. |
| 3320 | __ bind(&runtime); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3321 | if (equality) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3322 | { |
| 3323 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3324 | __ Push(left, right); |
| 3325 | __ CallRuntime(Runtime::kStringEqual); |
| 3326 | } |
| 3327 | __ LoadRoot(a0, Heap::kTrueValueRootIndex); |
| 3328 | __ Ret(USE_DELAY_SLOT); |
| 3329 | __ Subu(v0, v0, a0); // In delay slot. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3330 | } else { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3331 | __ Push(left, right); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3332 | __ TailCallRuntime(Runtime::kStringCompare); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | __ bind(&miss); |
| 3336 | GenerateMiss(masm); |
| 3337 | } |
| 3338 | |
| 3339 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3340 | void CompareICStub::GenerateReceivers(MacroAssembler* masm) { |
| 3341 | DCHECK_EQ(CompareICState::RECEIVER, state()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3342 | Label miss; |
| 3343 | __ And(a2, a1, Operand(a0)); |
| 3344 | __ JumpIfSmi(a2, &miss); |
| 3345 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3346 | STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3347 | __ GetObjectType(a0, a2, a2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3348 | __ Branch(&miss, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3349 | __ GetObjectType(a1, a2, a2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3350 | __ Branch(&miss, lt, a2, Operand(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3351 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3352 | DCHECK_EQ(eq, GetCondition()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3353 | __ Ret(USE_DELAY_SLOT); |
| 3354 | __ dsubu(v0, a0, a1); |
| 3355 | |
| 3356 | __ bind(&miss); |
| 3357 | GenerateMiss(masm); |
| 3358 | } |
| 3359 | |
| 3360 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3361 | void CompareICStub::GenerateKnownReceivers(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3362 | Label miss; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3363 | Handle<WeakCell> cell = Map::WeakCellForMap(known_map_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3364 | __ And(a2, a1, a0); |
| 3365 | __ JumpIfSmi(a2, &miss); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3366 | __ GetWeakValue(a4, cell); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3367 | __ ld(a2, FieldMemOperand(a0, HeapObject::kMapOffset)); |
| 3368 | __ ld(a3, FieldMemOperand(a1, HeapObject::kMapOffset)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3369 | __ Branch(&miss, ne, a2, Operand(a4)); |
| 3370 | __ Branch(&miss, ne, a3, Operand(a4)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3371 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3372 | if (Token::IsEqualityOp(op())) { |
| 3373 | __ Ret(USE_DELAY_SLOT); |
| 3374 | __ dsubu(v0, a0, a1); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3375 | } else { |
| 3376 | if (op() == Token::LT || op() == Token::LTE) { |
| 3377 | __ li(a2, Operand(Smi::FromInt(GREATER))); |
| 3378 | } else { |
| 3379 | __ li(a2, Operand(Smi::FromInt(LESS))); |
| 3380 | } |
| 3381 | __ Push(a1, a0, a2); |
| 3382 | __ TailCallRuntime(Runtime::kCompare); |
| 3383 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3384 | |
| 3385 | __ bind(&miss); |
| 3386 | GenerateMiss(masm); |
| 3387 | } |
| 3388 | |
| 3389 | |
| 3390 | void CompareICStub::GenerateMiss(MacroAssembler* masm) { |
| 3391 | { |
| 3392 | // Call the runtime system in a fresh internal frame. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3393 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3394 | __ Push(a1, a0); |
| 3395 | __ Push(ra, a1, a0); |
| 3396 | __ li(a4, Operand(Smi::FromInt(op()))); |
| 3397 | __ daddiu(sp, sp, -kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3398 | __ CallRuntime(Runtime::kCompareIC_Miss, 3, kDontSaveFPRegs, |
| 3399 | USE_DELAY_SLOT); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3400 | __ sd(a4, MemOperand(sp)); // In the delay slot. |
| 3401 | // Compute the entry point of the rewritten stub. |
| 3402 | __ Daddu(a2, v0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3403 | // Restore registers. |
| 3404 | __ Pop(a1, a0, ra); |
| 3405 | } |
| 3406 | __ Jump(a2); |
| 3407 | } |
| 3408 | |
| 3409 | |
| 3410 | void DirectCEntryStub::Generate(MacroAssembler* masm) { |
| 3411 | // Make place for arguments to fit C calling convention. Most of the callers |
| 3412 | // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame |
| 3413 | // so they handle stack restoring and we don't have to do that here. |
| 3414 | // Any caller of DirectCEntryStub::GenerateCall must take care of dropping |
| 3415 | // kCArgsSlotsSize stack space after the call. |
| 3416 | __ daddiu(sp, sp, -kCArgsSlotsSize); |
| 3417 | // Place the return address on the stack, making the call |
| 3418 | // GC safe. The RegExp backend also relies on this. |
| 3419 | __ sd(ra, MemOperand(sp, kCArgsSlotsSize)); |
| 3420 | __ Call(t9); // Call the C++ function. |
| 3421 | __ ld(t9, MemOperand(sp, kCArgsSlotsSize)); |
| 3422 | |
| 3423 | if (FLAG_debug_code && FLAG_enable_slow_asserts) { |
| 3424 | // In case of an error the return address may point to a memory area |
| 3425 | // filled with kZapValue by the GC. |
| 3426 | // Dereference the address and check for this. |
| 3427 | __ Uld(a4, MemOperand(t9)); |
| 3428 | __ Assert(ne, kReceivedInvalidReturnAddress, a4, |
| 3429 | Operand(reinterpret_cast<uint64_t>(kZapValue))); |
| 3430 | } |
| 3431 | __ Jump(t9); |
| 3432 | } |
| 3433 | |
| 3434 | |
| 3435 | void DirectCEntryStub::GenerateCall(MacroAssembler* masm, |
| 3436 | Register target) { |
| 3437 | intptr_t loc = |
| 3438 | reinterpret_cast<intptr_t>(GetCode().location()); |
| 3439 | __ Move(t9, target); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3440 | __ li(at, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE); |
| 3441 | __ Call(at); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3442 | } |
| 3443 | |
| 3444 | |
| 3445 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 3446 | Label* miss, |
| 3447 | Label* done, |
| 3448 | Register receiver, |
| 3449 | Register properties, |
| 3450 | Handle<Name> name, |
| 3451 | Register scratch0) { |
| 3452 | DCHECK(name->IsUniqueName()); |
| 3453 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 3454 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 3455 | // undefined value), it guarantees the hash table doesn't contain the |
| 3456 | // property. It's true even if some slots represent deleted properties |
| 3457 | // (their names are the hole value). |
| 3458 | for (int i = 0; i < kInlinedProbes; i++) { |
| 3459 | // scratch0 points to properties hash. |
| 3460 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3461 | Register index = scratch0; |
| 3462 | // Capacity is smi 2^n. |
| 3463 | __ SmiLoadUntag(index, FieldMemOperand(properties, kCapacityOffset)); |
| 3464 | __ Dsubu(index, index, Operand(1)); |
| 3465 | __ And(index, index, |
| 3466 | Operand(name->Hash() + NameDictionary::GetProbeOffset(i))); |
| 3467 | |
| 3468 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3469 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3470 | __ Dlsa(index, index, index, 1); // index *= 3. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3471 | |
| 3472 | Register entity_name = scratch0; |
| 3473 | // Having undefined at this place means the name is not contained. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3474 | STATIC_ASSERT(kSmiTagSize == 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3475 | Register tmp = properties; |
| 3476 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3477 | __ Dlsa(tmp, properties, index, kPointerSizeLog2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3478 | __ ld(entity_name, FieldMemOperand(tmp, kElementsStartOffset)); |
| 3479 | |
| 3480 | DCHECK(!tmp.is(entity_name)); |
| 3481 | __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex); |
| 3482 | __ Branch(done, eq, entity_name, Operand(tmp)); |
| 3483 | |
| 3484 | // Load the hole ready for use below: |
| 3485 | __ LoadRoot(tmp, Heap::kTheHoleValueRootIndex); |
| 3486 | |
| 3487 | // Stop if found the property. |
| 3488 | __ Branch(miss, eq, entity_name, Operand(Handle<Name>(name))); |
| 3489 | |
| 3490 | Label good; |
| 3491 | __ Branch(&good, eq, entity_name, Operand(tmp)); |
| 3492 | |
| 3493 | // Check if the entry name is not a unique name. |
| 3494 | __ ld(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset)); |
| 3495 | __ lbu(entity_name, |
| 3496 | FieldMemOperand(entity_name, Map::kInstanceTypeOffset)); |
| 3497 | __ JumpIfNotUniqueNameInstanceType(entity_name, miss); |
| 3498 | __ bind(&good); |
| 3499 | |
| 3500 | // Restore the properties. |
| 3501 | __ ld(properties, |
| 3502 | FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 3503 | } |
| 3504 | |
| 3505 | const int spill_mask = |
| 3506 | (ra.bit() | a6.bit() | a5.bit() | a4.bit() | a3.bit() | |
| 3507 | a2.bit() | a1.bit() | a0.bit() | v0.bit()); |
| 3508 | |
| 3509 | __ MultiPush(spill_mask); |
| 3510 | __ ld(a0, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 3511 | __ li(a1, Operand(Handle<Name>(name))); |
| 3512 | NameDictionaryLookupStub stub(masm->isolate(), NEGATIVE_LOOKUP); |
| 3513 | __ CallStub(&stub); |
| 3514 | __ mov(at, v0); |
| 3515 | __ MultiPop(spill_mask); |
| 3516 | |
| 3517 | __ Branch(done, eq, at, Operand(zero_reg)); |
| 3518 | __ Branch(miss, ne, at, Operand(zero_reg)); |
| 3519 | } |
| 3520 | |
| 3521 | |
| 3522 | // Probe the name dictionary in the |elements| register. Jump to the |
| 3523 | // |done| label if a property with the given name is found. Jump to |
| 3524 | // the |miss| label otherwise. |
| 3525 | // If lookup was successful |scratch2| will be equal to elements + 4 * index. |
| 3526 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 3527 | Label* miss, |
| 3528 | Label* done, |
| 3529 | Register elements, |
| 3530 | Register name, |
| 3531 | Register scratch1, |
| 3532 | Register scratch2) { |
| 3533 | DCHECK(!elements.is(scratch1)); |
| 3534 | DCHECK(!elements.is(scratch2)); |
| 3535 | DCHECK(!name.is(scratch1)); |
| 3536 | DCHECK(!name.is(scratch2)); |
| 3537 | |
| 3538 | __ AssertName(name); |
| 3539 | |
| 3540 | // Compute the capacity mask. |
| 3541 | __ ld(scratch1, FieldMemOperand(elements, kCapacityOffset)); |
| 3542 | __ SmiUntag(scratch1); |
| 3543 | __ Dsubu(scratch1, scratch1, Operand(1)); |
| 3544 | |
| 3545 | // Generate an unrolled loop that performs a few probes before |
| 3546 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 3547 | // cover ~93% of loads from dictionaries. |
| 3548 | for (int i = 0; i < kInlinedProbes; i++) { |
| 3549 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3550 | __ lwu(scratch2, FieldMemOperand(name, Name::kHashFieldOffset)); |
| 3551 | if (i > 0) { |
| 3552 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 3553 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 3554 | // shifted in the following and instruction. |
| 3555 | DCHECK(NameDictionary::GetProbeOffset(i) < |
| 3556 | 1 << (32 - Name::kHashFieldOffset)); |
| 3557 | __ Daddu(scratch2, scratch2, Operand( |
| 3558 | NameDictionary::GetProbeOffset(i) << Name::kHashShift)); |
| 3559 | } |
| 3560 | __ dsrl(scratch2, scratch2, Name::kHashShift); |
| 3561 | __ And(scratch2, scratch1, scratch2); |
| 3562 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3563 | // Scale the index by multiplying by the entry size. |
| 3564 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3565 | // scratch2 = scratch2 * 3. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3566 | __ Dlsa(scratch2, scratch2, scratch2, 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3567 | |
| 3568 | // Check if the key is identical to the name. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3569 | __ Dlsa(scratch2, elements, scratch2, kPointerSizeLog2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3570 | __ ld(at, FieldMemOperand(scratch2, kElementsStartOffset)); |
| 3571 | __ Branch(done, eq, name, Operand(at)); |
| 3572 | } |
| 3573 | |
| 3574 | const int spill_mask = |
| 3575 | (ra.bit() | a6.bit() | a5.bit() | a4.bit() | |
| 3576 | a3.bit() | a2.bit() | a1.bit() | a0.bit() | v0.bit()) & |
| 3577 | ~(scratch1.bit() | scratch2.bit()); |
| 3578 | |
| 3579 | __ MultiPush(spill_mask); |
| 3580 | if (name.is(a0)) { |
| 3581 | DCHECK(!elements.is(a1)); |
| 3582 | __ Move(a1, name); |
| 3583 | __ Move(a0, elements); |
| 3584 | } else { |
| 3585 | __ Move(a0, elements); |
| 3586 | __ Move(a1, name); |
| 3587 | } |
| 3588 | NameDictionaryLookupStub stub(masm->isolate(), POSITIVE_LOOKUP); |
| 3589 | __ CallStub(&stub); |
| 3590 | __ mov(scratch2, a2); |
| 3591 | __ mov(at, v0); |
| 3592 | __ MultiPop(spill_mask); |
| 3593 | |
| 3594 | __ Branch(done, ne, at, Operand(zero_reg)); |
| 3595 | __ Branch(miss, eq, at, Operand(zero_reg)); |
| 3596 | } |
| 3597 | |
| 3598 | |
| 3599 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
| 3600 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 3601 | // we cannot call anything that could cause a GC from this stub. |
| 3602 | // Registers: |
| 3603 | // result: NameDictionary to probe |
| 3604 | // a1: key |
| 3605 | // dictionary: NameDictionary to probe. |
| 3606 | // index: will hold an index of entry if lookup is successful. |
| 3607 | // might alias with result_. |
| 3608 | // Returns: |
| 3609 | // result_ is zero if lookup failed, non zero otherwise. |
| 3610 | |
| 3611 | Register result = v0; |
| 3612 | Register dictionary = a0; |
| 3613 | Register key = a1; |
| 3614 | Register index = a2; |
| 3615 | Register mask = a3; |
| 3616 | Register hash = a4; |
| 3617 | Register undefined = a5; |
| 3618 | Register entry_key = a6; |
| 3619 | |
| 3620 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 3621 | |
| 3622 | __ ld(mask, FieldMemOperand(dictionary, kCapacityOffset)); |
| 3623 | __ SmiUntag(mask); |
| 3624 | __ Dsubu(mask, mask, Operand(1)); |
| 3625 | |
| 3626 | __ lwu(hash, FieldMemOperand(key, Name::kHashFieldOffset)); |
| 3627 | |
| 3628 | __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex); |
| 3629 | |
| 3630 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 3631 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3632 | // Capacity is smi 2^n. |
| 3633 | if (i > 0) { |
| 3634 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 3635 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 3636 | // shifted in the following and instruction. |
| 3637 | DCHECK(NameDictionary::GetProbeOffset(i) < |
| 3638 | 1 << (32 - Name::kHashFieldOffset)); |
| 3639 | __ Daddu(index, hash, Operand( |
| 3640 | NameDictionary::GetProbeOffset(i) << Name::kHashShift)); |
| 3641 | } else { |
| 3642 | __ mov(index, hash); |
| 3643 | } |
| 3644 | __ dsrl(index, index, Name::kHashShift); |
| 3645 | __ And(index, mask, index); |
| 3646 | |
| 3647 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3648 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3649 | // index *= 3. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3650 | __ Dlsa(index, index, index, 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3651 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3652 | STATIC_ASSERT(kSmiTagSize == 1); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3653 | __ Dlsa(index, dictionary, index, kPointerSizeLog2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3654 | __ ld(entry_key, FieldMemOperand(index, kElementsStartOffset)); |
| 3655 | |
| 3656 | // Having undefined at this place means the name is not contained. |
| 3657 | __ Branch(¬_in_dictionary, eq, entry_key, Operand(undefined)); |
| 3658 | |
| 3659 | // Stop if found the property. |
| 3660 | __ Branch(&in_dictionary, eq, entry_key, Operand(key)); |
| 3661 | |
| 3662 | if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) { |
| 3663 | // Check if the entry name is not a unique name. |
| 3664 | __ ld(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset)); |
| 3665 | __ lbu(entry_key, |
| 3666 | FieldMemOperand(entry_key, Map::kInstanceTypeOffset)); |
| 3667 | __ JumpIfNotUniqueNameInstanceType(entry_key, &maybe_in_dictionary); |
| 3668 | } |
| 3669 | } |
| 3670 | |
| 3671 | __ bind(&maybe_in_dictionary); |
| 3672 | // If we are doing negative lookup then probing failure should be |
| 3673 | // treated as a lookup success. For positive lookup probing failure |
| 3674 | // should be treated as lookup failure. |
| 3675 | if (mode() == POSITIVE_LOOKUP) { |
| 3676 | __ Ret(USE_DELAY_SLOT); |
| 3677 | __ mov(result, zero_reg); |
| 3678 | } |
| 3679 | |
| 3680 | __ bind(&in_dictionary); |
| 3681 | __ Ret(USE_DELAY_SLOT); |
| 3682 | __ li(result, 1); |
| 3683 | |
| 3684 | __ bind(¬_in_dictionary); |
| 3685 | __ Ret(USE_DELAY_SLOT); |
| 3686 | __ mov(result, zero_reg); |
| 3687 | } |
| 3688 | |
| 3689 | |
| 3690 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 3691 | Isolate* isolate) { |
| 3692 | StoreBufferOverflowStub stub1(isolate, kDontSaveFPRegs); |
| 3693 | stub1.GetCode(); |
| 3694 | // Hydrogen code stubs need stub2 at snapshot time. |
| 3695 | StoreBufferOverflowStub stub2(isolate, kSaveFPRegs); |
| 3696 | stub2.GetCode(); |
| 3697 | } |
| 3698 | |
| 3699 | |
| 3700 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 3701 | // the value has just been written into the object, now this stub makes sure |
| 3702 | // we keep the GC informed. The word in the object where the value has been |
| 3703 | // written is in the address register. |
| 3704 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 3705 | Label skip_to_incremental_noncompacting; |
| 3706 | Label skip_to_incremental_compacting; |
| 3707 | |
| 3708 | // The first two branch+nop instructions are generated with labels so as to |
| 3709 | // get the offset fixed up correctly by the bind(Label*) call. We patch it |
| 3710 | // back and forth between a "bne zero_reg, zero_reg, ..." (a nop in this |
| 3711 | // position) and the "beq zero_reg, zero_reg, ..." when we start and stop |
| 3712 | // incremental heap marking. |
| 3713 | // See RecordWriteStub::Patch for details. |
| 3714 | __ beq(zero_reg, zero_reg, &skip_to_incremental_noncompacting); |
| 3715 | __ nop(); |
| 3716 | __ beq(zero_reg, zero_reg, &skip_to_incremental_compacting); |
| 3717 | __ nop(); |
| 3718 | |
| 3719 | if (remembered_set_action() == EMIT_REMEMBERED_SET) { |
| 3720 | __ RememberedSetHelper(object(), |
| 3721 | address(), |
| 3722 | value(), |
| 3723 | save_fp_regs_mode(), |
| 3724 | MacroAssembler::kReturnAtEnd); |
| 3725 | } |
| 3726 | __ Ret(); |
| 3727 | |
| 3728 | __ bind(&skip_to_incremental_noncompacting); |
| 3729 | GenerateIncremental(masm, INCREMENTAL); |
| 3730 | |
| 3731 | __ bind(&skip_to_incremental_compacting); |
| 3732 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 3733 | |
| 3734 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 3735 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 3736 | |
| 3737 | PatchBranchIntoNop(masm, 0); |
| 3738 | PatchBranchIntoNop(masm, 2 * Assembler::kInstrSize); |
| 3739 | } |
| 3740 | |
| 3741 | |
| 3742 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 3743 | regs_.Save(masm); |
| 3744 | |
| 3745 | if (remembered_set_action() == EMIT_REMEMBERED_SET) { |
| 3746 | Label dont_need_remembered_set; |
| 3747 | |
| 3748 | __ ld(regs_.scratch0(), MemOperand(regs_.address(), 0)); |
| 3749 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 3750 | regs_.scratch0(), |
| 3751 | &dont_need_remembered_set); |
| 3752 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3753 | __ JumpIfInNewSpace(regs_.object(), regs_.scratch0(), |
| 3754 | &dont_need_remembered_set); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3755 | |
| 3756 | // First notify the incremental marker if necessary, then update the |
| 3757 | // remembered set. |
| 3758 | CheckNeedsToInformIncrementalMarker( |
| 3759 | masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode); |
| 3760 | InformIncrementalMarker(masm); |
| 3761 | regs_.Restore(masm); |
| 3762 | __ RememberedSetHelper(object(), |
| 3763 | address(), |
| 3764 | value(), |
| 3765 | save_fp_regs_mode(), |
| 3766 | MacroAssembler::kReturnAtEnd); |
| 3767 | |
| 3768 | __ bind(&dont_need_remembered_set); |
| 3769 | } |
| 3770 | |
| 3771 | CheckNeedsToInformIncrementalMarker( |
| 3772 | masm, kReturnOnNoNeedToInformIncrementalMarker, mode); |
| 3773 | InformIncrementalMarker(masm); |
| 3774 | regs_.Restore(masm); |
| 3775 | __ Ret(); |
| 3776 | } |
| 3777 | |
| 3778 | |
| 3779 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) { |
| 3780 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode()); |
| 3781 | int argument_count = 3; |
| 3782 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 3783 | Register address = |
| 3784 | a0.is(regs_.address()) ? regs_.scratch0() : regs_.address(); |
| 3785 | DCHECK(!address.is(regs_.object())); |
| 3786 | DCHECK(!address.is(a0)); |
| 3787 | __ Move(address, regs_.address()); |
| 3788 | __ Move(a0, regs_.object()); |
| 3789 | __ Move(a1, address); |
| 3790 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
| 3791 | |
| 3792 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3793 | __ CallCFunction( |
| 3794 | ExternalReference::incremental_marking_record_write_function(isolate()), |
| 3795 | argument_count); |
| 3796 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode()); |
| 3797 | } |
| 3798 | |
| 3799 | |
| 3800 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 3801 | MacroAssembler* masm, |
| 3802 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 3803 | Mode mode) { |
| 3804 | Label on_black; |
| 3805 | Label need_incremental; |
| 3806 | Label need_incremental_pop_scratch; |
| 3807 | |
| 3808 | __ And(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask)); |
| 3809 | __ ld(regs_.scratch1(), |
| 3810 | MemOperand(regs_.scratch0(), |
| 3811 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 3812 | __ Dsubu(regs_.scratch1(), regs_.scratch1(), Operand(1)); |
| 3813 | __ sd(regs_.scratch1(), |
| 3814 | MemOperand(regs_.scratch0(), |
| 3815 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 3816 | __ Branch(&need_incremental, lt, regs_.scratch1(), Operand(zero_reg)); |
| 3817 | |
| 3818 | // Let's look at the color of the object: If it is not black we don't have |
| 3819 | // to inform the incremental marker. |
| 3820 | __ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black); |
| 3821 | |
| 3822 | regs_.Restore(masm); |
| 3823 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 3824 | __ RememberedSetHelper(object(), |
| 3825 | address(), |
| 3826 | value(), |
| 3827 | save_fp_regs_mode(), |
| 3828 | MacroAssembler::kReturnAtEnd); |
| 3829 | } else { |
| 3830 | __ Ret(); |
| 3831 | } |
| 3832 | |
| 3833 | __ bind(&on_black); |
| 3834 | |
| 3835 | // Get the value from the slot. |
| 3836 | __ ld(regs_.scratch0(), MemOperand(regs_.address(), 0)); |
| 3837 | |
| 3838 | if (mode == INCREMENTAL_COMPACTION) { |
| 3839 | Label ensure_not_white; |
| 3840 | |
| 3841 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 3842 | regs_.scratch1(), // Scratch. |
| 3843 | MemoryChunk::kEvacuationCandidateMask, |
| 3844 | eq, |
| 3845 | &ensure_not_white); |
| 3846 | |
| 3847 | __ CheckPageFlag(regs_.object(), |
| 3848 | regs_.scratch1(), // Scratch. |
| 3849 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 3850 | eq, |
| 3851 | &need_incremental); |
| 3852 | |
| 3853 | __ bind(&ensure_not_white); |
| 3854 | } |
| 3855 | |
| 3856 | // We need extra registers for this, so we push the object and the address |
| 3857 | // register temporarily. |
| 3858 | __ Push(regs_.object(), regs_.address()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3859 | __ JumpIfWhite(regs_.scratch0(), // The value. |
| 3860 | regs_.scratch1(), // Scratch. |
| 3861 | regs_.object(), // Scratch. |
| 3862 | regs_.address(), // Scratch. |
| 3863 | &need_incremental_pop_scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3864 | __ Pop(regs_.object(), regs_.address()); |
| 3865 | |
| 3866 | regs_.Restore(masm); |
| 3867 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 3868 | __ RememberedSetHelper(object(), |
| 3869 | address(), |
| 3870 | value(), |
| 3871 | save_fp_regs_mode(), |
| 3872 | MacroAssembler::kReturnAtEnd); |
| 3873 | } else { |
| 3874 | __ Ret(); |
| 3875 | } |
| 3876 | |
| 3877 | __ bind(&need_incremental_pop_scratch); |
| 3878 | __ Pop(regs_.object(), regs_.address()); |
| 3879 | |
| 3880 | __ bind(&need_incremental); |
| 3881 | |
| 3882 | // Fall through when we need to inform the incremental marker. |
| 3883 | } |
| 3884 | |
| 3885 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3886 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
| 3887 | CEntryStub ces(isolate(), 1, kSaveFPRegs); |
| 3888 | __ Call(ces.GetCode(), RelocInfo::CODE_TARGET); |
| 3889 | int parameter_count_offset = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3890 | StubFailureTrampolineFrameConstants::kArgumentsLengthOffset; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3891 | __ ld(a1, MemOperand(fp, parameter_count_offset)); |
| 3892 | if (function_mode() == JS_FUNCTION_STUB_MODE) { |
| 3893 | __ Daddu(a1, a1, Operand(1)); |
| 3894 | } |
| 3895 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 3896 | __ dsll(a1, a1, kPointerSizeLog2); |
| 3897 | __ Ret(USE_DELAY_SLOT); |
| 3898 | __ Daddu(sp, sp, a1); |
| 3899 | } |
| 3900 | |
| 3901 | |
| 3902 | void LoadICTrampolineStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3903 | __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister()); |
| 3904 | LoadICStub stub(isolate(), state()); |
| 3905 | stub.GenerateForTrampoline(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3906 | } |
| 3907 | |
| 3908 | |
| 3909 | void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3910 | __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister()); |
| 3911 | KeyedLoadICStub stub(isolate(), state()); |
| 3912 | stub.GenerateForTrampoline(masm); |
| 3913 | } |
| 3914 | |
| 3915 | |
| 3916 | void CallICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3917 | __ EmitLoadTypeFeedbackVector(a2); |
| 3918 | CallICStub stub(isolate(), state()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3919 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 3920 | } |
| 3921 | |
| 3922 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3923 | void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); } |
| 3924 | |
| 3925 | |
| 3926 | void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3927 | GenerateImpl(masm, true); |
| 3928 | } |
| 3929 | |
| 3930 | |
| 3931 | static void HandleArrayCases(MacroAssembler* masm, Register feedback, |
| 3932 | Register receiver_map, Register scratch1, |
| 3933 | Register scratch2, bool is_polymorphic, |
| 3934 | Label* miss) { |
| 3935 | // feedback initially contains the feedback array |
| 3936 | Label next_loop, prepare_next; |
| 3937 | Label start_polymorphic; |
| 3938 | |
| 3939 | Register cached_map = scratch1; |
| 3940 | |
| 3941 | __ ld(cached_map, |
| 3942 | FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(0))); |
| 3943 | __ ld(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 3944 | __ Branch(&start_polymorphic, ne, receiver_map, Operand(cached_map)); |
| 3945 | // found, now call handler. |
| 3946 | Register handler = feedback; |
| 3947 | __ ld(handler, FieldMemOperand(feedback, FixedArray::OffsetOfElementAt(1))); |
| 3948 | __ Daddu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3949 | __ Jump(t9); |
| 3950 | |
| 3951 | Register length = scratch2; |
| 3952 | __ bind(&start_polymorphic); |
| 3953 | __ ld(length, FieldMemOperand(feedback, FixedArray::kLengthOffset)); |
| 3954 | if (!is_polymorphic) { |
| 3955 | // If the IC could be monomorphic we have to make sure we don't go past the |
| 3956 | // end of the feedback array. |
| 3957 | __ Branch(miss, eq, length, Operand(Smi::FromInt(2))); |
| 3958 | } |
| 3959 | |
| 3960 | Register too_far = length; |
| 3961 | Register pointer_reg = feedback; |
| 3962 | |
| 3963 | // +-----+------+------+-----+-----+ ... ----+ |
| 3964 | // | map | len | wm0 | h0 | wm1 | hN | |
| 3965 | // +-----+------+------+-----+-----+ ... ----+ |
| 3966 | // 0 1 2 len-1 |
| 3967 | // ^ ^ |
| 3968 | // | | |
| 3969 | // pointer_reg too_far |
| 3970 | // aka feedback scratch2 |
| 3971 | // also need receiver_map |
| 3972 | // use cached_map (scratch1) to look in the weak map values. |
| 3973 | __ SmiScale(too_far, length, kPointerSizeLog2); |
| 3974 | __ Daddu(too_far, feedback, Operand(too_far)); |
| 3975 | __ Daddu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 3976 | __ Daddu(pointer_reg, feedback, |
| 3977 | Operand(FixedArray::OffsetOfElementAt(2) - kHeapObjectTag)); |
| 3978 | |
| 3979 | __ bind(&next_loop); |
| 3980 | __ ld(cached_map, MemOperand(pointer_reg)); |
| 3981 | __ ld(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 3982 | __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map)); |
| 3983 | __ ld(handler, MemOperand(pointer_reg, kPointerSize)); |
| 3984 | __ Daddu(t9, handler, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3985 | __ Jump(t9); |
| 3986 | |
| 3987 | __ bind(&prepare_next); |
| 3988 | __ Daddu(pointer_reg, pointer_reg, Operand(kPointerSize * 2)); |
| 3989 | __ Branch(&next_loop, lt, pointer_reg, Operand(too_far)); |
| 3990 | |
| 3991 | // We exhausted our array of map handler pairs. |
| 3992 | __ Branch(miss); |
| 3993 | } |
| 3994 | |
| 3995 | |
| 3996 | static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver, |
| 3997 | Register receiver_map, Register feedback, |
| 3998 | Register vector, Register slot, |
| 3999 | Register scratch, Label* compare_map, |
| 4000 | Label* load_smi_map, Label* try_array) { |
| 4001 | __ JumpIfSmi(receiver, load_smi_map); |
| 4002 | __ ld(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 4003 | __ bind(compare_map); |
| 4004 | Register cached_map = scratch; |
| 4005 | // Move the weak map into the weak_cell register. |
| 4006 | __ ld(cached_map, FieldMemOperand(feedback, WeakCell::kValueOffset)); |
| 4007 | __ Branch(try_array, ne, cached_map, Operand(receiver_map)); |
| 4008 | Register handler = feedback; |
| 4009 | __ SmiScale(handler, slot, kPointerSizeLog2); |
| 4010 | __ Daddu(handler, vector, Operand(handler)); |
| 4011 | __ ld(handler, |
| 4012 | FieldMemOperand(handler, FixedArray::kHeaderSize + kPointerSize)); |
| 4013 | __ Daddu(t9, handler, Code::kHeaderSize - kHeapObjectTag); |
| 4014 | __ Jump(t9); |
| 4015 | } |
| 4016 | |
| 4017 | |
| 4018 | void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4019 | Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1 |
| 4020 | Register name = LoadWithVectorDescriptor::NameRegister(); // a2 |
| 4021 | Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3 |
| 4022 | Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0 |
| 4023 | Register feedback = a4; |
| 4024 | Register receiver_map = a5; |
| 4025 | Register scratch1 = a6; |
| 4026 | |
| 4027 | __ SmiScale(feedback, slot, kPointerSizeLog2); |
| 4028 | __ Daddu(feedback, vector, Operand(feedback)); |
| 4029 | __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 4030 | |
| 4031 | // Try to quickly handle the monomorphic case without knowing for sure |
| 4032 | // if we have a weak cell in feedback. We do know it's safe to look |
| 4033 | // at WeakCell::kValueOffset. |
| 4034 | Label try_array, load_smi_map, compare_map; |
| 4035 | Label not_array, miss; |
| 4036 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 4037 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 4038 | |
| 4039 | // Is it a fixed array? |
| 4040 | __ bind(&try_array); |
| 4041 | __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 4042 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 4043 | __ Branch(¬_array, ne, scratch1, Operand(at)); |
| 4044 | HandleArrayCases(masm, feedback, receiver_map, scratch1, a7, true, &miss); |
| 4045 | |
| 4046 | __ bind(¬_array); |
| 4047 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 4048 | __ Branch(&miss, ne, feedback, Operand(at)); |
| 4049 | Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags( |
| 4050 | Code::ComputeHandlerFlags(Code::LOAD_IC)); |
| 4051 | masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags, |
| 4052 | receiver, name, feedback, |
| 4053 | receiver_map, scratch1, a7); |
| 4054 | |
| 4055 | __ bind(&miss); |
| 4056 | LoadIC::GenerateMiss(masm); |
| 4057 | |
| 4058 | __ bind(&load_smi_map); |
| 4059 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 4060 | __ Branch(&compare_map); |
| 4061 | } |
| 4062 | |
| 4063 | |
| 4064 | void KeyedLoadICStub::Generate(MacroAssembler* masm) { |
| 4065 | GenerateImpl(masm, false); |
| 4066 | } |
| 4067 | |
| 4068 | |
| 4069 | void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 4070 | GenerateImpl(masm, true); |
| 4071 | } |
| 4072 | |
| 4073 | |
| 4074 | void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4075 | Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // a1 |
| 4076 | Register key = LoadWithVectorDescriptor::NameRegister(); // a2 |
| 4077 | Register vector = LoadWithVectorDescriptor::VectorRegister(); // a3 |
| 4078 | Register slot = LoadWithVectorDescriptor::SlotRegister(); // a0 |
| 4079 | Register feedback = a4; |
| 4080 | Register receiver_map = a5; |
| 4081 | Register scratch1 = a6; |
| 4082 | |
| 4083 | __ SmiScale(feedback, slot, kPointerSizeLog2); |
| 4084 | __ Daddu(feedback, vector, Operand(feedback)); |
| 4085 | __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 4086 | |
| 4087 | // Try to quickly handle the monomorphic case without knowing for sure |
| 4088 | // if we have a weak cell in feedback. We do know it's safe to look |
| 4089 | // at WeakCell::kValueOffset. |
| 4090 | Label try_array, load_smi_map, compare_map; |
| 4091 | Label not_array, miss; |
| 4092 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 4093 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 4094 | |
| 4095 | __ bind(&try_array); |
| 4096 | // Is it a fixed array? |
| 4097 | __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 4098 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 4099 | __ Branch(¬_array, ne, scratch1, Operand(at)); |
| 4100 | // We have a polymorphic element handler. |
| 4101 | __ JumpIfNotSmi(key, &miss); |
| 4102 | |
| 4103 | Label polymorphic, try_poly_name; |
| 4104 | __ bind(&polymorphic); |
| 4105 | HandleArrayCases(masm, feedback, receiver_map, scratch1, a7, true, &miss); |
| 4106 | |
| 4107 | __ bind(¬_array); |
| 4108 | // Is it generic? |
| 4109 | __ LoadRoot(at, Heap::kmegamorphic_symbolRootIndex); |
| 4110 | __ Branch(&try_poly_name, ne, feedback, Operand(at)); |
| 4111 | Handle<Code> megamorphic_stub = |
| 4112 | KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState()); |
| 4113 | __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET); |
| 4114 | |
| 4115 | __ bind(&try_poly_name); |
| 4116 | // We might have a name in feedback, and a fixed array in the next slot. |
| 4117 | __ Branch(&miss, ne, key, Operand(feedback)); |
| 4118 | // If the name comparison succeeded, we know we have a fixed array with |
| 4119 | // at least one map/handler pair. |
| 4120 | __ SmiScale(feedback, slot, kPointerSizeLog2); |
| 4121 | __ Daddu(feedback, vector, Operand(feedback)); |
| 4122 | __ ld(feedback, |
| 4123 | FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize)); |
| 4124 | HandleArrayCases(masm, feedback, receiver_map, scratch1, a7, false, &miss); |
| 4125 | |
| 4126 | __ bind(&miss); |
| 4127 | KeyedLoadIC::GenerateMiss(masm); |
| 4128 | |
| 4129 | __ bind(&load_smi_map); |
| 4130 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 4131 | __ Branch(&compare_map); |
| 4132 | } |
| 4133 | |
| 4134 | |
| 4135 | void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) { |
| 4136 | __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister()); |
| 4137 | VectorStoreICStub stub(isolate(), state()); |
| 4138 | stub.GenerateForTrampoline(masm); |
| 4139 | } |
| 4140 | |
| 4141 | |
| 4142 | void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) { |
| 4143 | __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister()); |
| 4144 | VectorKeyedStoreICStub stub(isolate(), state()); |
| 4145 | stub.GenerateForTrampoline(masm); |
| 4146 | } |
| 4147 | |
| 4148 | |
| 4149 | void VectorStoreICStub::Generate(MacroAssembler* masm) { |
| 4150 | GenerateImpl(masm, false); |
| 4151 | } |
| 4152 | |
| 4153 | |
| 4154 | void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 4155 | GenerateImpl(masm, true); |
| 4156 | } |
| 4157 | |
| 4158 | |
| 4159 | void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4160 | Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1 |
| 4161 | Register key = VectorStoreICDescriptor::NameRegister(); // a2 |
| 4162 | Register vector = VectorStoreICDescriptor::VectorRegister(); // a3 |
| 4163 | Register slot = VectorStoreICDescriptor::SlotRegister(); // a4 |
| 4164 | DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0 |
| 4165 | Register feedback = a5; |
| 4166 | Register receiver_map = a6; |
| 4167 | Register scratch1 = a7; |
| 4168 | |
| 4169 | __ SmiScale(scratch1, slot, kPointerSizeLog2); |
| 4170 | __ Daddu(feedback, vector, Operand(scratch1)); |
| 4171 | __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 4172 | |
| 4173 | // Try to quickly handle the monomorphic case without knowing for sure |
| 4174 | // if we have a weak cell in feedback. We do know it's safe to look |
| 4175 | // at WeakCell::kValueOffset. |
| 4176 | Label try_array, load_smi_map, compare_map; |
| 4177 | Label not_array, miss; |
| 4178 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 4179 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 4180 | |
| 4181 | // Is it a fixed array? |
| 4182 | __ bind(&try_array); |
| 4183 | __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 4184 | __ Branch(¬_array, ne, scratch1, Heap::kFixedArrayMapRootIndex); |
| 4185 | |
| 4186 | Register scratch2 = t0; |
| 4187 | HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, true, |
| 4188 | &miss); |
| 4189 | |
| 4190 | __ bind(¬_array); |
| 4191 | __ Branch(&miss, ne, feedback, Heap::kmegamorphic_symbolRootIndex); |
| 4192 | Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags( |
| 4193 | Code::ComputeHandlerFlags(Code::STORE_IC)); |
| 4194 | masm->isolate()->stub_cache()->GenerateProbe( |
| 4195 | masm, Code::STORE_IC, code_flags, receiver, key, feedback, receiver_map, |
| 4196 | scratch1, scratch2); |
| 4197 | |
| 4198 | __ bind(&miss); |
| 4199 | StoreIC::GenerateMiss(masm); |
| 4200 | |
| 4201 | __ bind(&load_smi_map); |
| 4202 | __ Branch(USE_DELAY_SLOT, &compare_map); |
| 4203 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot. |
| 4204 | } |
| 4205 | |
| 4206 | |
| 4207 | void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) { |
| 4208 | GenerateImpl(masm, false); |
| 4209 | } |
| 4210 | |
| 4211 | |
| 4212 | void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 4213 | GenerateImpl(masm, true); |
| 4214 | } |
| 4215 | |
| 4216 | |
| 4217 | static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register feedback, |
| 4218 | Register receiver_map, Register scratch1, |
| 4219 | Register scratch2, Label* miss) { |
| 4220 | // feedback initially contains the feedback array |
| 4221 | Label next_loop, prepare_next; |
| 4222 | Label start_polymorphic; |
| 4223 | Label transition_call; |
| 4224 | |
| 4225 | Register cached_map = scratch1; |
| 4226 | Register too_far = scratch2; |
| 4227 | Register pointer_reg = feedback; |
| 4228 | |
| 4229 | __ ld(too_far, FieldMemOperand(feedback, FixedArray::kLengthOffset)); |
| 4230 | |
| 4231 | // +-----+------+------+-----+-----+-----+ ... ----+ |
| 4232 | // | map | len | wm0 | wt0 | h0 | wm1 | hN | |
| 4233 | // +-----+------+------+-----+-----+ ----+ ... ----+ |
| 4234 | // 0 1 2 len-1 |
| 4235 | // ^ ^ |
| 4236 | // | | |
| 4237 | // pointer_reg too_far |
| 4238 | // aka feedback scratch2 |
| 4239 | // also need receiver_map |
| 4240 | // use cached_map (scratch1) to look in the weak map values. |
| 4241 | __ SmiScale(too_far, too_far, kPointerSizeLog2); |
| 4242 | __ Daddu(too_far, feedback, Operand(too_far)); |
| 4243 | __ Daddu(too_far, too_far, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 4244 | __ Daddu(pointer_reg, feedback, |
| 4245 | Operand(FixedArray::OffsetOfElementAt(0) - kHeapObjectTag)); |
| 4246 | |
| 4247 | __ bind(&next_loop); |
| 4248 | __ ld(cached_map, MemOperand(pointer_reg)); |
| 4249 | __ ld(cached_map, FieldMemOperand(cached_map, WeakCell::kValueOffset)); |
| 4250 | __ Branch(&prepare_next, ne, receiver_map, Operand(cached_map)); |
| 4251 | // Is it a transitioning store? |
| 4252 | __ ld(too_far, MemOperand(pointer_reg, kPointerSize)); |
| 4253 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 4254 | __ Branch(&transition_call, ne, too_far, Operand(at)); |
| 4255 | |
| 4256 | __ ld(pointer_reg, MemOperand(pointer_reg, kPointerSize * 2)); |
| 4257 | __ Daddu(t9, pointer_reg, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4258 | __ Jump(t9); |
| 4259 | |
| 4260 | __ bind(&transition_call); |
| 4261 | __ ld(too_far, FieldMemOperand(too_far, WeakCell::kValueOffset)); |
| 4262 | __ JumpIfSmi(too_far, miss); |
| 4263 | |
| 4264 | __ ld(receiver_map, MemOperand(pointer_reg, kPointerSize * 2)); |
| 4265 | // Load the map into the correct register. |
| 4266 | DCHECK(feedback.is(VectorStoreTransitionDescriptor::MapRegister())); |
| 4267 | __ Move(feedback, too_far); |
| 4268 | __ Daddu(t9, receiver_map, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4269 | __ Jump(t9); |
| 4270 | |
| 4271 | __ bind(&prepare_next); |
| 4272 | __ Daddu(pointer_reg, pointer_reg, Operand(kPointerSize * 3)); |
| 4273 | __ Branch(&next_loop, lt, pointer_reg, Operand(too_far)); |
| 4274 | |
| 4275 | // We exhausted our array of map handler pairs. |
| 4276 | __ Branch(miss); |
| 4277 | } |
| 4278 | |
| 4279 | |
| 4280 | void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4281 | Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // a1 |
| 4282 | Register key = VectorStoreICDescriptor::NameRegister(); // a2 |
| 4283 | Register vector = VectorStoreICDescriptor::VectorRegister(); // a3 |
| 4284 | Register slot = VectorStoreICDescriptor::SlotRegister(); // a4 |
| 4285 | DCHECK(VectorStoreICDescriptor::ValueRegister().is(a0)); // a0 |
| 4286 | Register feedback = a5; |
| 4287 | Register receiver_map = a6; |
| 4288 | Register scratch1 = a7; |
| 4289 | |
| 4290 | __ SmiScale(scratch1, slot, kPointerSizeLog2); |
| 4291 | __ Daddu(feedback, vector, Operand(scratch1)); |
| 4292 | __ ld(feedback, FieldMemOperand(feedback, FixedArray::kHeaderSize)); |
| 4293 | |
| 4294 | // Try to quickly handle the monomorphic case without knowing for sure |
| 4295 | // if we have a weak cell in feedback. We do know it's safe to look |
| 4296 | // at WeakCell::kValueOffset. |
| 4297 | Label try_array, load_smi_map, compare_map; |
| 4298 | Label not_array, miss; |
| 4299 | HandleMonomorphicCase(masm, receiver, receiver_map, feedback, vector, slot, |
| 4300 | scratch1, &compare_map, &load_smi_map, &try_array); |
| 4301 | |
| 4302 | __ bind(&try_array); |
| 4303 | // Is it a fixed array? |
| 4304 | __ ld(scratch1, FieldMemOperand(feedback, HeapObject::kMapOffset)); |
| 4305 | __ Branch(¬_array, ne, scratch1, Heap::kFixedArrayMapRootIndex); |
| 4306 | |
| 4307 | // We have a polymorphic element handler. |
| 4308 | Label try_poly_name; |
| 4309 | |
| 4310 | Register scratch2 = t0; |
| 4311 | |
| 4312 | HandlePolymorphicStoreCase(masm, feedback, receiver_map, scratch1, scratch2, |
| 4313 | &miss); |
| 4314 | |
| 4315 | __ bind(¬_array); |
| 4316 | // Is it generic? |
| 4317 | __ Branch(&try_poly_name, ne, feedback, Heap::kmegamorphic_symbolRootIndex); |
| 4318 | Handle<Code> megamorphic_stub = |
| 4319 | KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState()); |
| 4320 | __ Jump(megamorphic_stub, RelocInfo::CODE_TARGET); |
| 4321 | |
| 4322 | __ bind(&try_poly_name); |
| 4323 | // We might have a name in feedback, and a fixed array in the next slot. |
| 4324 | __ Branch(&miss, ne, key, Operand(feedback)); |
| 4325 | // If the name comparison succeeded, we know we have a fixed array with |
| 4326 | // at least one map/handler pair. |
| 4327 | __ SmiScale(scratch1, slot, kPointerSizeLog2); |
| 4328 | __ Daddu(feedback, vector, Operand(scratch1)); |
| 4329 | __ ld(feedback, |
| 4330 | FieldMemOperand(feedback, FixedArray::kHeaderSize + kPointerSize)); |
| 4331 | HandleArrayCases(masm, feedback, receiver_map, scratch1, scratch2, false, |
| 4332 | &miss); |
| 4333 | |
| 4334 | __ bind(&miss); |
| 4335 | KeyedStoreIC::GenerateMiss(masm); |
| 4336 | |
| 4337 | __ bind(&load_smi_map); |
| 4338 | __ Branch(USE_DELAY_SLOT, &compare_map); |
| 4339 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); // In delay slot. |
| 4340 | } |
| 4341 | |
| 4342 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4343 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 4344 | if (masm->isolate()->function_entry_hook() != NULL) { |
| 4345 | ProfileEntryHookStub stub(masm->isolate()); |
| 4346 | __ push(ra); |
| 4347 | __ CallStub(&stub); |
| 4348 | __ pop(ra); |
| 4349 | } |
| 4350 | } |
| 4351 | |
| 4352 | |
| 4353 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 4354 | // The entry hook is a "push ra" instruction, followed by a call. |
| 4355 | // Note: on MIPS "push" is 2 instruction |
| 4356 | const int32_t kReturnAddressDistanceFromFunctionStart = |
| 4357 | Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize); |
| 4358 | |
| 4359 | // This should contain all kJSCallerSaved registers. |
| 4360 | const RegList kSavedRegs = |
| 4361 | kJSCallerSaved | // Caller saved registers. |
| 4362 | s5.bit(); // Saved stack pointer. |
| 4363 | |
| 4364 | // We also save ra, so the count here is one higher than the mask indicates. |
| 4365 | const int32_t kNumSavedRegs = kNumJSCallerSaved + 2; |
| 4366 | |
| 4367 | // Save all caller-save registers as this may be called from anywhere. |
| 4368 | __ MultiPush(kSavedRegs | ra.bit()); |
| 4369 | |
| 4370 | // Compute the function's address for the first argument. |
| 4371 | __ Dsubu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart)); |
| 4372 | |
| 4373 | // The caller's return address is above the saved temporaries. |
| 4374 | // Grab that for the second argument to the hook. |
| 4375 | __ Daddu(a1, sp, Operand(kNumSavedRegs * kPointerSize)); |
| 4376 | |
| 4377 | // Align the stack if necessary. |
| 4378 | int frame_alignment = masm->ActivationFrameAlignment(); |
| 4379 | if (frame_alignment > kPointerSize) { |
| 4380 | __ mov(s5, sp); |
| 4381 | DCHECK(base::bits::IsPowerOfTwo32(frame_alignment)); |
| 4382 | __ And(sp, sp, Operand(-frame_alignment)); |
| 4383 | } |
| 4384 | |
| 4385 | __ Dsubu(sp, sp, kCArgsSlotsSize); |
| 4386 | #if defined(V8_HOST_ARCH_MIPS) || defined(V8_HOST_ARCH_MIPS64) |
| 4387 | int64_t entry_hook = |
| 4388 | reinterpret_cast<int64_t>(isolate()->function_entry_hook()); |
| 4389 | __ li(t9, Operand(entry_hook)); |
| 4390 | #else |
| 4391 | // Under the simulator we need to indirect the entry hook through a |
| 4392 | // trampoline function at a known address. |
| 4393 | // It additionally takes an isolate as a third parameter. |
| 4394 | __ li(a2, Operand(ExternalReference::isolate_address(isolate()))); |
| 4395 | |
| 4396 | ApiFunction dispatcher(FUNCTION_ADDR(EntryHookTrampoline)); |
| 4397 | __ li(t9, Operand(ExternalReference(&dispatcher, |
| 4398 | ExternalReference::BUILTIN_CALL, |
| 4399 | isolate()))); |
| 4400 | #endif |
| 4401 | // Call C function through t9 to conform ABI for PIC. |
| 4402 | __ Call(t9); |
| 4403 | |
| 4404 | // Restore the stack pointer if needed. |
| 4405 | if (frame_alignment > kPointerSize) { |
| 4406 | __ mov(sp, s5); |
| 4407 | } else { |
| 4408 | __ Daddu(sp, sp, kCArgsSlotsSize); |
| 4409 | } |
| 4410 | |
| 4411 | // Also pop ra to get Ret(0). |
| 4412 | __ MultiPop(kSavedRegs | ra.bit()); |
| 4413 | __ Ret(); |
| 4414 | } |
| 4415 | |
| 4416 | |
| 4417 | template<class T> |
| 4418 | static void CreateArrayDispatch(MacroAssembler* masm, |
| 4419 | AllocationSiteOverrideMode mode) { |
| 4420 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 4421 | T stub(masm->isolate(), GetInitialFastElementsKind(), mode); |
| 4422 | __ TailCallStub(&stub); |
| 4423 | } else if (mode == DONT_OVERRIDE) { |
| 4424 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 4425 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4426 | for (int i = 0; i <= last_index; ++i) { |
| 4427 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4428 | T stub(masm->isolate(), kind); |
| 4429 | __ TailCallStub(&stub, eq, a3, Operand(kind)); |
| 4430 | } |
| 4431 | |
| 4432 | // If we reached this point there is a problem. |
| 4433 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 4434 | } else { |
| 4435 | UNREACHABLE(); |
| 4436 | } |
| 4437 | } |
| 4438 | |
| 4439 | |
| 4440 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm, |
| 4441 | AllocationSiteOverrideMode mode) { |
| 4442 | // a2 - allocation site (if mode != DISABLE_ALLOCATION_SITES) |
| 4443 | // a3 - kind (if mode != DISABLE_ALLOCATION_SITES) |
| 4444 | // a0 - number of arguments |
| 4445 | // a1 - constructor? |
| 4446 | // sp[0] - last argument |
| 4447 | Label normal_sequence; |
| 4448 | if (mode == DONT_OVERRIDE) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4449 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 4450 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 4451 | STATIC_ASSERT(FAST_ELEMENTS == 2); |
| 4452 | STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 4453 | STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 4454 | STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4455 | |
| 4456 | // is the low bit set? If so, we are holey and that is good. |
| 4457 | __ And(at, a3, Operand(1)); |
| 4458 | __ Branch(&normal_sequence, ne, at, Operand(zero_reg)); |
| 4459 | } |
| 4460 | // look at the first argument |
| 4461 | __ ld(a5, MemOperand(sp, 0)); |
| 4462 | __ Branch(&normal_sequence, eq, a5, Operand(zero_reg)); |
| 4463 | |
| 4464 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 4465 | ElementsKind initial = GetInitialFastElementsKind(); |
| 4466 | ElementsKind holey_initial = GetHoleyElementsKind(initial); |
| 4467 | |
| 4468 | ArraySingleArgumentConstructorStub stub_holey(masm->isolate(), |
| 4469 | holey_initial, |
| 4470 | DISABLE_ALLOCATION_SITES); |
| 4471 | __ TailCallStub(&stub_holey); |
| 4472 | |
| 4473 | __ bind(&normal_sequence); |
| 4474 | ArraySingleArgumentConstructorStub stub(masm->isolate(), |
| 4475 | initial, |
| 4476 | DISABLE_ALLOCATION_SITES); |
| 4477 | __ TailCallStub(&stub); |
| 4478 | } else if (mode == DONT_OVERRIDE) { |
| 4479 | // We are going to create a holey array, but our kind is non-holey. |
| 4480 | // Fix kind and retry (only if we have an allocation site in the slot). |
| 4481 | __ Daddu(a3, a3, Operand(1)); |
| 4482 | |
| 4483 | if (FLAG_debug_code) { |
| 4484 | __ ld(a5, FieldMemOperand(a2, 0)); |
| 4485 | __ LoadRoot(at, Heap::kAllocationSiteMapRootIndex); |
| 4486 | __ Assert(eq, kExpectedAllocationSite, a5, Operand(at)); |
| 4487 | } |
| 4488 | |
| 4489 | // Save the resulting elements kind in type info. We can't just store a3 |
| 4490 | // in the AllocationSite::transition_info field because elements kind is |
| 4491 | // restricted to a portion of the field...upper bits need to be left alone. |
| 4492 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 4493 | __ ld(a4, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset)); |
| 4494 | __ Daddu(a4, a4, Operand(Smi::FromInt(kFastElementsKindPackedToHoley))); |
| 4495 | __ sd(a4, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset)); |
| 4496 | |
| 4497 | |
| 4498 | __ bind(&normal_sequence); |
| 4499 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 4500 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4501 | for (int i = 0; i <= last_index; ++i) { |
| 4502 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4503 | ArraySingleArgumentConstructorStub stub(masm->isolate(), kind); |
| 4504 | __ TailCallStub(&stub, eq, a3, Operand(kind)); |
| 4505 | } |
| 4506 | |
| 4507 | // If we reached this point there is a problem. |
| 4508 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 4509 | } else { |
| 4510 | UNREACHABLE(); |
| 4511 | } |
| 4512 | } |
| 4513 | |
| 4514 | |
| 4515 | template<class T> |
| 4516 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 4517 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 4518 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4519 | for (int i = 0; i <= to_index; ++i) { |
| 4520 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4521 | T stub(isolate, kind); |
| 4522 | stub.GetCode(); |
| 4523 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
| 4524 | T stub1(isolate, kind, DISABLE_ALLOCATION_SITES); |
| 4525 | stub1.GetCode(); |
| 4526 | } |
| 4527 | } |
| 4528 | } |
| 4529 | |
| 4530 | |
| 4531 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4532 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 4533 | isolate); |
| 4534 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 4535 | isolate); |
| 4536 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 4537 | isolate); |
| 4538 | } |
| 4539 | |
| 4540 | |
| 4541 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 4542 | Isolate* isolate) { |
| 4543 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 4544 | for (int i = 0; i < 2; i++) { |
| 4545 | // For internal arrays we only need a few things. |
| 4546 | InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]); |
| 4547 | stubh1.GetCode(); |
| 4548 | InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]); |
| 4549 | stubh2.GetCode(); |
| 4550 | InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]); |
| 4551 | stubh3.GetCode(); |
| 4552 | } |
| 4553 | } |
| 4554 | |
| 4555 | |
| 4556 | void ArrayConstructorStub::GenerateDispatchToArrayStub( |
| 4557 | MacroAssembler* masm, |
| 4558 | AllocationSiteOverrideMode mode) { |
| 4559 | if (argument_count() == ANY) { |
| 4560 | Label not_zero_case, not_one_case; |
| 4561 | __ And(at, a0, a0); |
| 4562 | __ Branch(¬_zero_case, ne, at, Operand(zero_reg)); |
| 4563 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 4564 | |
| 4565 | __ bind(¬_zero_case); |
| 4566 | __ Branch(¬_one_case, gt, a0, Operand(1)); |
| 4567 | CreateArrayDispatchOneArgument(masm, mode); |
| 4568 | |
| 4569 | __ bind(¬_one_case); |
| 4570 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 4571 | } else if (argument_count() == NONE) { |
| 4572 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 4573 | } else if (argument_count() == ONE) { |
| 4574 | CreateArrayDispatchOneArgument(masm, mode); |
| 4575 | } else if (argument_count() == MORE_THAN_ONE) { |
| 4576 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 4577 | } else { |
| 4578 | UNREACHABLE(); |
| 4579 | } |
| 4580 | } |
| 4581 | |
| 4582 | |
| 4583 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 4584 | // ----------- S t a t e ------------- |
| 4585 | // -- a0 : argc (only if argument_count() == ANY) |
| 4586 | // -- a1 : constructor |
| 4587 | // -- a2 : AllocationSite or undefined |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4588 | // -- a3 : new target |
| 4589 | // -- sp[0] : last argument |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4590 | // ----------------------------------- |
| 4591 | |
| 4592 | if (FLAG_debug_code) { |
| 4593 | // The array construct code is only set for the global and natives |
| 4594 | // builtin Array functions which always have maps. |
| 4595 | |
| 4596 | // Initial map for the builtin Array function should be a map. |
| 4597 | __ ld(a4, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4598 | // Will both indicate a NULL and a Smi. |
| 4599 | __ SmiTst(a4, at); |
| 4600 | __ Assert(ne, kUnexpectedInitialMapForArrayFunction, |
| 4601 | at, Operand(zero_reg)); |
| 4602 | __ GetObjectType(a4, a4, a5); |
| 4603 | __ Assert(eq, kUnexpectedInitialMapForArrayFunction, |
| 4604 | a5, Operand(MAP_TYPE)); |
| 4605 | |
| 4606 | // We should either have undefined in a2 or a valid AllocationSite |
| 4607 | __ AssertUndefinedOrAllocationSite(a2, a4); |
| 4608 | } |
| 4609 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4610 | // Enter the context of the Array function. |
| 4611 | __ ld(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 4612 | |
| 4613 | Label subclassing; |
| 4614 | __ Branch(&subclassing, ne, a1, Operand(a3)); |
| 4615 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4616 | Label no_info; |
| 4617 | // Get the elements kind and case on that. |
| 4618 | __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 4619 | __ Branch(&no_info, eq, a2, Operand(at)); |
| 4620 | |
| 4621 | __ ld(a3, FieldMemOperand(a2, AllocationSite::kTransitionInfoOffset)); |
| 4622 | __ SmiUntag(a3); |
| 4623 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 4624 | __ And(a3, a3, Operand(AllocationSite::ElementsKindBits::kMask)); |
| 4625 | GenerateDispatchToArrayStub(masm, DONT_OVERRIDE); |
| 4626 | |
| 4627 | __ bind(&no_info); |
| 4628 | GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4629 | |
| 4630 | // Subclassing. |
| 4631 | __ bind(&subclassing); |
| 4632 | switch (argument_count()) { |
| 4633 | case ANY: |
| 4634 | case MORE_THAN_ONE: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4635 | __ Dlsa(at, sp, a0, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4636 | __ sd(a1, MemOperand(at)); |
| 4637 | __ li(at, Operand(3)); |
| 4638 | __ Daddu(a0, a0, at); |
| 4639 | break; |
| 4640 | case NONE: |
| 4641 | __ sd(a1, MemOperand(sp, 0 * kPointerSize)); |
| 4642 | __ li(a0, Operand(3)); |
| 4643 | break; |
| 4644 | case ONE: |
| 4645 | __ sd(a1, MemOperand(sp, 1 * kPointerSize)); |
| 4646 | __ li(a0, Operand(4)); |
| 4647 | break; |
| 4648 | } |
| 4649 | __ Push(a3, a2); |
| 4650 | __ JumpToExternalReference(ExternalReference(Runtime::kNewArray, isolate())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4651 | } |
| 4652 | |
| 4653 | |
| 4654 | void InternalArrayConstructorStub::GenerateCase( |
| 4655 | MacroAssembler* masm, ElementsKind kind) { |
| 4656 | |
| 4657 | InternalArrayNoArgumentConstructorStub stub0(isolate(), kind); |
| 4658 | __ TailCallStub(&stub0, lo, a0, Operand(1)); |
| 4659 | |
| 4660 | InternalArrayNArgumentsConstructorStub stubN(isolate(), kind); |
| 4661 | __ TailCallStub(&stubN, hi, a0, Operand(1)); |
| 4662 | |
| 4663 | if (IsFastPackedElementsKind(kind)) { |
| 4664 | // We might need to create a holey array |
| 4665 | // look at the first argument. |
| 4666 | __ ld(at, MemOperand(sp, 0)); |
| 4667 | |
| 4668 | InternalArraySingleArgumentConstructorStub |
| 4669 | stub1_holey(isolate(), GetHoleyElementsKind(kind)); |
| 4670 | __ TailCallStub(&stub1_holey, ne, at, Operand(zero_reg)); |
| 4671 | } |
| 4672 | |
| 4673 | InternalArraySingleArgumentConstructorStub stub1(isolate(), kind); |
| 4674 | __ TailCallStub(&stub1); |
| 4675 | } |
| 4676 | |
| 4677 | |
| 4678 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 4679 | // ----------- S t a t e ------------- |
| 4680 | // -- a0 : argc |
| 4681 | // -- a1 : constructor |
| 4682 | // -- sp[0] : return address |
| 4683 | // -- sp[4] : last argument |
| 4684 | // ----------------------------------- |
| 4685 | |
| 4686 | if (FLAG_debug_code) { |
| 4687 | // The array construct code is only set for the global and natives |
| 4688 | // builtin Array functions which always have maps. |
| 4689 | |
| 4690 | // Initial map for the builtin Array function should be a map. |
| 4691 | __ ld(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4692 | // Will both indicate a NULL and a Smi. |
| 4693 | __ SmiTst(a3, at); |
| 4694 | __ Assert(ne, kUnexpectedInitialMapForArrayFunction, |
| 4695 | at, Operand(zero_reg)); |
| 4696 | __ GetObjectType(a3, a3, a4); |
| 4697 | __ Assert(eq, kUnexpectedInitialMapForArrayFunction, |
| 4698 | a4, Operand(MAP_TYPE)); |
| 4699 | } |
| 4700 | |
| 4701 | // Figure out the right elements kind. |
| 4702 | __ ld(a3, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4703 | |
| 4704 | // Load the map's "bit field 2" into a3. We only need the first byte, |
| 4705 | // but the following bit field extraction takes care of that anyway. |
| 4706 | __ lbu(a3, FieldMemOperand(a3, Map::kBitField2Offset)); |
| 4707 | // Retrieve elements_kind from bit field 2. |
| 4708 | __ DecodeField<Map::ElementsKindBits>(a3); |
| 4709 | |
| 4710 | if (FLAG_debug_code) { |
| 4711 | Label done; |
| 4712 | __ Branch(&done, eq, a3, Operand(FAST_ELEMENTS)); |
| 4713 | __ Assert( |
| 4714 | eq, kInvalidElementsKindForInternalArrayOrInternalPackedArray, |
| 4715 | a3, Operand(FAST_HOLEY_ELEMENTS)); |
| 4716 | __ bind(&done); |
| 4717 | } |
| 4718 | |
| 4719 | Label fast_elements_case; |
| 4720 | __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS)); |
| 4721 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 4722 | |
| 4723 | __ bind(&fast_elements_case); |
| 4724 | GenerateCase(masm, FAST_ELEMENTS); |
| 4725 | } |
| 4726 | |
| 4727 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4728 | void FastNewObjectStub::Generate(MacroAssembler* masm) { |
| 4729 | // ----------- S t a t e ------------- |
| 4730 | // -- a1 : target |
| 4731 | // -- a3 : new target |
| 4732 | // -- cp : context |
| 4733 | // -- ra : return address |
| 4734 | // ----------------------------------- |
| 4735 | __ AssertFunction(a1); |
| 4736 | __ AssertReceiver(a3); |
| 4737 | |
| 4738 | // Verify that the new target is a JSFunction. |
| 4739 | Label new_object; |
| 4740 | __ GetObjectType(a3, a2, a2); |
| 4741 | __ Branch(&new_object, ne, a2, Operand(JS_FUNCTION_TYPE)); |
| 4742 | |
| 4743 | // Load the initial map and verify that it's in fact a map. |
| 4744 | __ ld(a2, FieldMemOperand(a3, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4745 | __ JumpIfSmi(a2, &new_object); |
| 4746 | __ GetObjectType(a2, a0, a0); |
| 4747 | __ Branch(&new_object, ne, a0, Operand(MAP_TYPE)); |
| 4748 | |
| 4749 | // Fall back to runtime if the target differs from the new target's |
| 4750 | // initial map constructor. |
| 4751 | __ ld(a0, FieldMemOperand(a2, Map::kConstructorOrBackPointerOffset)); |
| 4752 | __ Branch(&new_object, ne, a0, Operand(a1)); |
| 4753 | |
| 4754 | // Allocate the JSObject on the heap. |
| 4755 | Label allocate, done_allocate; |
| 4756 | __ lbu(a4, FieldMemOperand(a2, Map::kInstanceSizeOffset)); |
| 4757 | __ Allocate(a4, v0, a5, a0, &allocate, SIZE_IN_WORDS); |
| 4758 | __ bind(&done_allocate); |
| 4759 | |
| 4760 | // Initialize the JSObject fields. |
| 4761 | __ sd(a2, MemOperand(v0, JSObject::kMapOffset)); |
| 4762 | __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex); |
| 4763 | __ sd(a3, MemOperand(v0, JSObject::kPropertiesOffset)); |
| 4764 | __ sd(a3, MemOperand(v0, JSObject::kElementsOffset)); |
| 4765 | STATIC_ASSERT(JSObject::kHeaderSize == 3 * kPointerSize); |
| 4766 | __ Daddu(a1, v0, Operand(JSObject::kHeaderSize)); |
| 4767 | |
| 4768 | // ----------- S t a t e ------------- |
| 4769 | // -- v0 : result (untagged) |
| 4770 | // -- a1 : result fields (untagged) |
| 4771 | // -- a5 : result end (untagged) |
| 4772 | // -- a2 : initial map |
| 4773 | // -- cp : context |
| 4774 | // -- ra : return address |
| 4775 | // ----------------------------------- |
| 4776 | |
| 4777 | // Perform in-object slack tracking if requested. |
| 4778 | Label slack_tracking; |
| 4779 | STATIC_ASSERT(Map::kNoSlackTracking == 0); |
| 4780 | __ lwu(a3, FieldMemOperand(a2, Map::kBitField3Offset)); |
| 4781 | __ And(at, a3, Operand(Map::ConstructionCounter::kMask)); |
| 4782 | __ Branch(USE_DELAY_SLOT, &slack_tracking, ne, at, Operand(zero_reg)); |
| 4783 | __ LoadRoot(a0, Heap::kUndefinedValueRootIndex); // In delay slot. |
| 4784 | { |
| 4785 | // Initialize all in-object fields with undefined. |
| 4786 | __ InitializeFieldsWithFiller(a1, a5, a0); |
| 4787 | |
| 4788 | // Add the object tag to make the JSObject real. |
| 4789 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4790 | __ Ret(USE_DELAY_SLOT); |
| 4791 | __ Daddu(v0, v0, Operand(kHeapObjectTag)); // In delay slot. |
| 4792 | } |
| 4793 | __ bind(&slack_tracking); |
| 4794 | { |
| 4795 | // Decrease generous allocation count. |
| 4796 | STATIC_ASSERT(Map::ConstructionCounter::kNext == 32); |
| 4797 | __ Subu(a3, a3, Operand(1 << Map::ConstructionCounter::kShift)); |
| 4798 | __ sw(a3, FieldMemOperand(a2, Map::kBitField3Offset)); |
| 4799 | |
| 4800 | // Initialize the in-object fields with undefined. |
| 4801 | __ lbu(a4, FieldMemOperand(a2, Map::kUnusedPropertyFieldsOffset)); |
| 4802 | __ dsll(a4, a4, kPointerSizeLog2); |
| 4803 | __ Dsubu(a4, a5, a4); |
| 4804 | __ InitializeFieldsWithFiller(a1, a4, a0); |
| 4805 | |
| 4806 | // Initialize the remaining (reserved) fields with one pointer filler map. |
| 4807 | __ LoadRoot(a0, Heap::kOnePointerFillerMapRootIndex); |
| 4808 | __ InitializeFieldsWithFiller(a1, a5, a0); |
| 4809 | |
| 4810 | // Check if we can finalize the instance size. |
| 4811 | Label finalize; |
| 4812 | STATIC_ASSERT(Map::kSlackTrackingCounterEnd == 1); |
| 4813 | __ And(a3, a3, Operand(Map::ConstructionCounter::kMask)); |
| 4814 | __ Branch(USE_DELAY_SLOT, &finalize, eq, a3, Operand(zero_reg)); |
| 4815 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4816 | __ Daddu(v0, v0, Operand(kHeapObjectTag)); // In delay slot. |
| 4817 | __ Ret(); |
| 4818 | |
| 4819 | // Finalize the instance size. |
| 4820 | __ bind(&finalize); |
| 4821 | { |
| 4822 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4823 | __ Push(v0, a2); |
| 4824 | __ CallRuntime(Runtime::kFinalizeInstanceSize); |
| 4825 | __ Pop(v0); |
| 4826 | } |
| 4827 | __ Ret(); |
| 4828 | } |
| 4829 | |
| 4830 | // Fall back to %AllocateInNewSpace. |
| 4831 | __ bind(&allocate); |
| 4832 | { |
| 4833 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4834 | STATIC_ASSERT(kSmiTag == 0); |
| 4835 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4836 | __ dsll(a4, a4, kPointerSizeLog2 + kSmiShiftSize + kSmiTagSize); |
| 4837 | __ SmiTag(a4); |
| 4838 | __ Push(a2, a4); |
| 4839 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4840 | __ Pop(a2); |
| 4841 | } |
| 4842 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4843 | __ Dsubu(v0, v0, Operand(kHeapObjectTag)); |
| 4844 | __ lbu(a5, FieldMemOperand(a2, Map::kInstanceSizeOffset)); |
| 4845 | __ Dlsa(a5, v0, a5, kPointerSizeLog2); |
| 4846 | __ jmp(&done_allocate); |
| 4847 | |
| 4848 | // Fall back to %NewObject. |
| 4849 | __ bind(&new_object); |
| 4850 | __ Push(a1, a3); |
| 4851 | __ TailCallRuntime(Runtime::kNewObject); |
| 4852 | } |
| 4853 | |
| 4854 | |
| 4855 | void FastNewRestParameterStub::Generate(MacroAssembler* masm) { |
| 4856 | // ----------- S t a t e ------------- |
| 4857 | // -- a1 : function |
| 4858 | // -- cp : context |
| 4859 | // -- fp : frame pointer |
| 4860 | // -- ra : return address |
| 4861 | // ----------------------------------- |
| 4862 | __ AssertFunction(a1); |
| 4863 | |
| 4864 | // For Ignition we need to skip all possible handler/stub frames until |
| 4865 | // we reach the JavaScript frame for the function (similar to what the |
| 4866 | // runtime fallback implementation does). So make a2 point to that |
| 4867 | // JavaScript frame. |
| 4868 | { |
| 4869 | Label loop, loop_entry; |
| 4870 | __ Branch(USE_DELAY_SLOT, &loop_entry); |
| 4871 | __ mov(a2, fp); // In delay slot. |
| 4872 | __ bind(&loop); |
| 4873 | __ ld(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
| 4874 | __ bind(&loop_entry); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 4875 | __ ld(a3, MemOperand(a2, StandardFrameConstants::kFunctionOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4876 | __ Branch(&loop, ne, a1, Operand(a3)); |
| 4877 | } |
| 4878 | |
| 4879 | // Check if we have rest parameters (only possible if we have an |
| 4880 | // arguments adaptor frame below the function frame). |
| 4881 | Label no_rest_parameters; |
| 4882 | __ ld(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 4883 | __ ld(a3, MemOperand(a2, CommonFrameConstants::kContextOrFrameTypeOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4884 | __ Branch(&no_rest_parameters, ne, a3, |
| 4885 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4886 | |
| 4887 | // Check if the arguments adaptor frame contains more arguments than |
| 4888 | // specified by the function's internal formal parameter count. |
| 4889 | Label rest_parameters; |
| 4890 | __ SmiLoadUntag( |
| 4891 | a0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4892 | __ ld(a1, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 4893 | __ lw(a1, |
| 4894 | FieldMemOperand(a1, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 4895 | __ Dsubu(a0, a0, Operand(a1)); |
| 4896 | __ Branch(&rest_parameters, gt, a0, Operand(zero_reg)); |
| 4897 | |
| 4898 | // Return an empty rest parameter array. |
| 4899 | __ bind(&no_rest_parameters); |
| 4900 | { |
| 4901 | // ----------- S t a t e ------------- |
| 4902 | // -- cp : context |
| 4903 | // -- ra : return address |
| 4904 | // ----------------------------------- |
| 4905 | |
| 4906 | // Allocate an empty rest parameter array. |
| 4907 | Label allocate, done_allocate; |
| 4908 | __ Allocate(JSArray::kSize, v0, a0, a1, &allocate, TAG_OBJECT); |
| 4909 | __ bind(&done_allocate); |
| 4910 | |
| 4911 | // Setup the rest parameter array in v0. |
| 4912 | __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, a1); |
| 4913 | __ sd(a1, FieldMemOperand(v0, JSArray::kMapOffset)); |
| 4914 | __ LoadRoot(a1, Heap::kEmptyFixedArrayRootIndex); |
| 4915 | __ sd(a1, FieldMemOperand(v0, JSArray::kPropertiesOffset)); |
| 4916 | __ sd(a1, FieldMemOperand(v0, JSArray::kElementsOffset)); |
| 4917 | __ Move(a1, Smi::FromInt(0)); |
| 4918 | __ Ret(USE_DELAY_SLOT); |
| 4919 | __ sd(a1, FieldMemOperand(v0, JSArray::kLengthOffset)); // In delay slot |
| 4920 | STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize); |
| 4921 | |
| 4922 | // Fall back to %AllocateInNewSpace. |
| 4923 | __ bind(&allocate); |
| 4924 | { |
| 4925 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4926 | __ Push(Smi::FromInt(JSArray::kSize)); |
| 4927 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4928 | } |
| 4929 | __ jmp(&done_allocate); |
| 4930 | } |
| 4931 | |
| 4932 | __ bind(&rest_parameters); |
| 4933 | { |
| 4934 | // Compute the pointer to the first rest parameter (skippping the receiver). |
| 4935 | __ Dlsa(a2, a2, a0, kPointerSizeLog2); |
| 4936 | __ Daddu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset - |
| 4937 | 1 * kPointerSize)); |
| 4938 | |
| 4939 | // ----------- S t a t e ------------- |
| 4940 | // -- cp : context |
| 4941 | // -- a0 : number of rest parameters |
| 4942 | // -- a2 : pointer to first rest parameters |
| 4943 | // -- ra : return address |
| 4944 | // ----------------------------------- |
| 4945 | |
| 4946 | // Allocate space for the rest parameter array plus the backing store. |
| 4947 | Label allocate, done_allocate; |
| 4948 | __ li(a1, Operand(JSArray::kSize + FixedArray::kHeaderSize)); |
| 4949 | __ Dlsa(a1, a1, a0, kPointerSizeLog2); |
| 4950 | __ Allocate(a1, v0, a3, a4, &allocate, TAG_OBJECT); |
| 4951 | __ bind(&done_allocate); |
| 4952 | |
| 4953 | // Compute arguments.length in a4. |
| 4954 | __ SmiTag(a4, a0); |
| 4955 | |
| 4956 | // Setup the elements array in v0. |
| 4957 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 4958 | __ sd(at, FieldMemOperand(v0, FixedArray::kMapOffset)); |
| 4959 | __ sd(a4, FieldMemOperand(v0, FixedArray::kLengthOffset)); |
| 4960 | __ Daddu(a3, v0, Operand(FixedArray::kHeaderSize)); |
| 4961 | { |
| 4962 | Label loop, done_loop; |
| 4963 | __ Dlsa(a1, a3, a0, kPointerSizeLog2); |
| 4964 | __ bind(&loop); |
| 4965 | __ Branch(&done_loop, eq, a1, Operand(a3)); |
| 4966 | __ ld(at, MemOperand(a2, 0 * kPointerSize)); |
| 4967 | __ sd(at, FieldMemOperand(a3, 0 * kPointerSize)); |
| 4968 | __ Dsubu(a2, a2, Operand(1 * kPointerSize)); |
| 4969 | __ Daddu(a3, a3, Operand(1 * kPointerSize)); |
| 4970 | __ Branch(&loop); |
| 4971 | __ bind(&done_loop); |
| 4972 | } |
| 4973 | |
| 4974 | // Setup the rest parameter array in a3. |
| 4975 | __ LoadNativeContextSlot(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, at); |
| 4976 | __ sd(at, FieldMemOperand(a3, JSArray::kMapOffset)); |
| 4977 | __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex); |
| 4978 | __ sd(at, FieldMemOperand(a3, JSArray::kPropertiesOffset)); |
| 4979 | __ sd(v0, FieldMemOperand(a3, JSArray::kElementsOffset)); |
| 4980 | __ sd(a4, FieldMemOperand(a3, JSArray::kLengthOffset)); |
| 4981 | STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize); |
| 4982 | __ Ret(USE_DELAY_SLOT); |
| 4983 | __ mov(v0, a3); // In delay slot |
| 4984 | |
| 4985 | // Fall back to %AllocateInNewSpace. |
| 4986 | __ bind(&allocate); |
| 4987 | { |
| 4988 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4989 | __ SmiTag(a0); |
| 4990 | __ SmiTag(a1); |
| 4991 | __ Push(a0, a2, a1); |
| 4992 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4993 | __ Pop(a0, a2); |
| 4994 | __ SmiUntag(a0); |
| 4995 | } |
| 4996 | __ jmp(&done_allocate); |
| 4997 | } |
| 4998 | } |
| 4999 | |
| 5000 | |
| 5001 | void FastNewSloppyArgumentsStub::Generate(MacroAssembler* masm) { |
| 5002 | // ----------- S t a t e ------------- |
| 5003 | // -- a1 : function |
| 5004 | // -- cp : context |
| 5005 | // -- fp : frame pointer |
| 5006 | // -- ra : return address |
| 5007 | // ----------------------------------- |
| 5008 | __ AssertFunction(a1); |
| 5009 | |
| 5010 | // TODO(bmeurer): Cleanup to match the FastNewStrictArgumentsStub. |
| 5011 | __ ld(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 5012 | __ lw(a2, |
| 5013 | FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 5014 | __ Lsa(a3, fp, a2, kPointerSizeLog2); |
| 5015 | __ Addu(a3, a3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 5016 | __ SmiTag(a2); |
| 5017 | |
| 5018 | // a1 : function |
| 5019 | // a2 : number of parameters (tagged) |
| 5020 | // a3 : parameters pointer |
| 5021 | // Registers used over whole function: |
| 5022 | // a5 : arguments count (tagged) |
| 5023 | // a6 : mapped parameter count (tagged) |
| 5024 | |
| 5025 | // Check if the calling frame is an arguments adaptor frame. |
| 5026 | Label adaptor_frame, try_allocate, runtime; |
| 5027 | __ ld(a4, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5028 | __ ld(a0, MemOperand(a4, CommonFrameConstants::kContextOrFrameTypeOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5029 | __ Branch(&adaptor_frame, eq, a0, |
| 5030 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5031 | |
| 5032 | // No adaptor, parameter count = argument count. |
| 5033 | __ mov(a5, a2); |
| 5034 | __ Branch(USE_DELAY_SLOT, &try_allocate); |
| 5035 | __ mov(a6, a2); // In delay slot. |
| 5036 | |
| 5037 | // We have an adaptor frame. Patch the parameters pointer. |
| 5038 | __ bind(&adaptor_frame); |
| 5039 | __ ld(a5, MemOperand(a4, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 5040 | __ SmiScale(t2, a5, kPointerSizeLog2); |
| 5041 | __ Daddu(a4, a4, Operand(t2)); |
| 5042 | __ Daddu(a3, a4, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 5043 | |
| 5044 | // a5 = argument count (tagged) |
| 5045 | // a6 = parameter count (tagged) |
| 5046 | // Compute the mapped parameter count = min(a6, a5) in a6. |
| 5047 | __ mov(a6, a2); |
| 5048 | __ Branch(&try_allocate, le, a6, Operand(a5)); |
| 5049 | __ mov(a6, a5); |
| 5050 | |
| 5051 | __ bind(&try_allocate); |
| 5052 | |
| 5053 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 5054 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 5055 | const int kParameterMapHeaderSize = |
| 5056 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 5057 | // If there are no mapped parameters, we do not need the parameter_map. |
| 5058 | Label param_map_size; |
| 5059 | DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0)); |
| 5060 | __ Branch(USE_DELAY_SLOT, ¶m_map_size, eq, a6, Operand(zero_reg)); |
| 5061 | __ mov(t1, zero_reg); // In delay slot: param map size = 0 when a6 == 0. |
| 5062 | __ SmiScale(t1, a6, kPointerSizeLog2); |
| 5063 | __ daddiu(t1, t1, kParameterMapHeaderSize); |
| 5064 | __ bind(¶m_map_size); |
| 5065 | |
| 5066 | // 2. Backing store. |
| 5067 | __ SmiScale(t2, a5, kPointerSizeLog2); |
| 5068 | __ Daddu(t1, t1, Operand(t2)); |
| 5069 | __ Daddu(t1, t1, Operand(FixedArray::kHeaderSize)); |
| 5070 | |
| 5071 | // 3. Arguments object. |
| 5072 | __ Daddu(t1, t1, Operand(JSSloppyArgumentsObject::kSize)); |
| 5073 | |
| 5074 | // Do the allocation of all three objects in one go. |
| 5075 | __ Allocate(t1, v0, t1, a4, &runtime, TAG_OBJECT); |
| 5076 | |
| 5077 | // v0 = address of new object(s) (tagged) |
| 5078 | // a2 = argument count (smi-tagged) |
| 5079 | // Get the arguments boilerplate from the current native context into a4. |
| 5080 | const int kNormalOffset = |
| 5081 | Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX); |
| 5082 | const int kAliasedOffset = |
| 5083 | Context::SlotOffset(Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX); |
| 5084 | |
| 5085 | __ ld(a4, NativeContextMemOperand()); |
| 5086 | Label skip2_ne, skip2_eq; |
| 5087 | __ Branch(&skip2_ne, ne, a6, Operand(zero_reg)); |
| 5088 | __ ld(a4, MemOperand(a4, kNormalOffset)); |
| 5089 | __ bind(&skip2_ne); |
| 5090 | |
| 5091 | __ Branch(&skip2_eq, eq, a6, Operand(zero_reg)); |
| 5092 | __ ld(a4, MemOperand(a4, kAliasedOffset)); |
| 5093 | __ bind(&skip2_eq); |
| 5094 | |
| 5095 | // v0 = address of new object (tagged) |
| 5096 | // a2 = argument count (smi-tagged) |
| 5097 | // a4 = address of arguments map (tagged) |
| 5098 | // a6 = mapped parameter count (tagged) |
| 5099 | __ sd(a4, FieldMemOperand(v0, JSObject::kMapOffset)); |
| 5100 | __ LoadRoot(t1, Heap::kEmptyFixedArrayRootIndex); |
| 5101 | __ sd(t1, FieldMemOperand(v0, JSObject::kPropertiesOffset)); |
| 5102 | __ sd(t1, FieldMemOperand(v0, JSObject::kElementsOffset)); |
| 5103 | |
| 5104 | // Set up the callee in-object property. |
| 5105 | __ AssertNotSmi(a1); |
| 5106 | __ sd(a1, FieldMemOperand(v0, JSSloppyArgumentsObject::kCalleeOffset)); |
| 5107 | |
| 5108 | // Use the length (smi tagged) and set that as an in-object property too. |
| 5109 | __ AssertSmi(a5); |
| 5110 | __ sd(a5, FieldMemOperand(v0, JSSloppyArgumentsObject::kLengthOffset)); |
| 5111 | |
| 5112 | // Set up the elements pointer in the allocated arguments object. |
| 5113 | // If we allocated a parameter map, a4 will point there, otherwise |
| 5114 | // it will point to the backing store. |
| 5115 | __ Daddu(a4, v0, Operand(JSSloppyArgumentsObject::kSize)); |
| 5116 | __ sd(a4, FieldMemOperand(v0, JSObject::kElementsOffset)); |
| 5117 | |
| 5118 | // v0 = address of new object (tagged) |
| 5119 | // a2 = argument count (tagged) |
| 5120 | // a4 = address of parameter map or backing store (tagged) |
| 5121 | // a6 = mapped parameter count (tagged) |
| 5122 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 5123 | Label skip_parameter_map; |
| 5124 | Label skip3; |
| 5125 | __ Branch(&skip3, ne, a6, Operand(Smi::FromInt(0))); |
| 5126 | // Move backing store address to a1, because it is |
| 5127 | // expected there when filling in the unmapped arguments. |
| 5128 | __ mov(a1, a4); |
| 5129 | __ bind(&skip3); |
| 5130 | |
| 5131 | __ Branch(&skip_parameter_map, eq, a6, Operand(Smi::FromInt(0))); |
| 5132 | |
| 5133 | __ LoadRoot(a5, Heap::kSloppyArgumentsElementsMapRootIndex); |
| 5134 | __ sd(a5, FieldMemOperand(a4, FixedArray::kMapOffset)); |
| 5135 | __ Daddu(a5, a6, Operand(Smi::FromInt(2))); |
| 5136 | __ sd(a5, FieldMemOperand(a4, FixedArray::kLengthOffset)); |
| 5137 | __ sd(cp, FieldMemOperand(a4, FixedArray::kHeaderSize + 0 * kPointerSize)); |
| 5138 | __ SmiScale(t2, a6, kPointerSizeLog2); |
| 5139 | __ Daddu(a5, a4, Operand(t2)); |
| 5140 | __ Daddu(a5, a5, Operand(kParameterMapHeaderSize)); |
| 5141 | __ sd(a5, FieldMemOperand(a4, FixedArray::kHeaderSize + 1 * kPointerSize)); |
| 5142 | |
| 5143 | // Copy the parameter slots and the holes in the arguments. |
| 5144 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 5145 | // where parameters are stored in reverse order, at |
| 5146 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 5147 | // The mapped parameter thus need to get indices |
| 5148 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 5149 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 5150 | // We loop from right to left. |
| 5151 | Label parameters_loop, parameters_test; |
| 5152 | __ mov(a5, a6); |
| 5153 | __ Daddu(t1, a2, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 5154 | __ Dsubu(t1, t1, Operand(a6)); |
| 5155 | __ LoadRoot(a7, Heap::kTheHoleValueRootIndex); |
| 5156 | __ SmiScale(t2, a5, kPointerSizeLog2); |
| 5157 | __ Daddu(a1, a4, Operand(t2)); |
| 5158 | __ Daddu(a1, a1, Operand(kParameterMapHeaderSize)); |
| 5159 | |
| 5160 | // a1 = address of backing store (tagged) |
| 5161 | // a4 = address of parameter map (tagged) |
| 5162 | // a0 = temporary scratch (a.o., for address calculation) |
| 5163 | // t1 = loop variable (tagged) |
| 5164 | // a7 = the hole value |
| 5165 | __ jmp(¶meters_test); |
| 5166 | |
| 5167 | __ bind(¶meters_loop); |
| 5168 | __ Dsubu(a5, a5, Operand(Smi::FromInt(1))); |
| 5169 | __ SmiScale(a0, a5, kPointerSizeLog2); |
| 5170 | __ Daddu(a0, a0, Operand(kParameterMapHeaderSize - kHeapObjectTag)); |
| 5171 | __ Daddu(t2, a4, a0); |
| 5172 | __ sd(t1, MemOperand(t2)); |
| 5173 | __ Dsubu(a0, a0, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize)); |
| 5174 | __ Daddu(t2, a1, a0); |
| 5175 | __ sd(a7, MemOperand(t2)); |
| 5176 | __ Daddu(t1, t1, Operand(Smi::FromInt(1))); |
| 5177 | __ bind(¶meters_test); |
| 5178 | __ Branch(¶meters_loop, ne, a5, Operand(Smi::FromInt(0))); |
| 5179 | |
| 5180 | // Restore t1 = argument count (tagged). |
| 5181 | __ ld(a5, FieldMemOperand(v0, JSSloppyArgumentsObject::kLengthOffset)); |
| 5182 | |
| 5183 | __ bind(&skip_parameter_map); |
| 5184 | // v0 = address of new object (tagged) |
| 5185 | // a1 = address of backing store (tagged) |
| 5186 | // a5 = argument count (tagged) |
| 5187 | // a6 = mapped parameter count (tagged) |
| 5188 | // t1 = scratch |
| 5189 | // Copy arguments header and remaining slots (if there are any). |
| 5190 | __ LoadRoot(t1, Heap::kFixedArrayMapRootIndex); |
| 5191 | __ sd(t1, FieldMemOperand(a1, FixedArray::kMapOffset)); |
| 5192 | __ sd(a5, FieldMemOperand(a1, FixedArray::kLengthOffset)); |
| 5193 | |
| 5194 | Label arguments_loop, arguments_test; |
| 5195 | __ SmiScale(t2, a6, kPointerSizeLog2); |
| 5196 | __ Dsubu(a3, a3, Operand(t2)); |
| 5197 | __ jmp(&arguments_test); |
| 5198 | |
| 5199 | __ bind(&arguments_loop); |
| 5200 | __ Dsubu(a3, a3, Operand(kPointerSize)); |
| 5201 | __ ld(a4, MemOperand(a3, 0)); |
| 5202 | __ SmiScale(t2, a6, kPointerSizeLog2); |
| 5203 | __ Daddu(t1, a1, Operand(t2)); |
| 5204 | __ sd(a4, FieldMemOperand(t1, FixedArray::kHeaderSize)); |
| 5205 | __ Daddu(a6, a6, Operand(Smi::FromInt(1))); |
| 5206 | |
| 5207 | __ bind(&arguments_test); |
| 5208 | __ Branch(&arguments_loop, lt, a6, Operand(a5)); |
| 5209 | |
| 5210 | // Return. |
| 5211 | __ Ret(); |
| 5212 | |
| 5213 | // Do the runtime call to allocate the arguments object. |
| 5214 | // a5 = argument count (tagged) |
| 5215 | __ bind(&runtime); |
| 5216 | __ Push(a1, a3, a5); |
| 5217 | __ TailCallRuntime(Runtime::kNewSloppyArguments); |
| 5218 | } |
| 5219 | |
| 5220 | |
| 5221 | void FastNewStrictArgumentsStub::Generate(MacroAssembler* masm) { |
| 5222 | // ----------- S t a t e ------------- |
| 5223 | // -- a1 : function |
| 5224 | // -- cp : context |
| 5225 | // -- fp : frame pointer |
| 5226 | // -- ra : return address |
| 5227 | // ----------------------------------- |
| 5228 | __ AssertFunction(a1); |
| 5229 | |
| 5230 | // For Ignition we need to skip all possible handler/stub frames until |
| 5231 | // we reach the JavaScript frame for the function (similar to what the |
| 5232 | // runtime fallback implementation does). So make a2 point to that |
| 5233 | // JavaScript frame. |
| 5234 | { |
| 5235 | Label loop, loop_entry; |
| 5236 | __ Branch(USE_DELAY_SLOT, &loop_entry); |
| 5237 | __ mov(a2, fp); // In delay slot. |
| 5238 | __ bind(&loop); |
| 5239 | __ ld(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
| 5240 | __ bind(&loop_entry); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5241 | __ ld(a3, MemOperand(a2, StandardFrameConstants::kFunctionOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5242 | __ Branch(&loop, ne, a1, Operand(a3)); |
| 5243 | } |
| 5244 | |
| 5245 | // Check if we have an arguments adaptor frame below the function frame. |
| 5246 | Label arguments_adaptor, arguments_done; |
| 5247 | __ ld(a3, MemOperand(a2, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5248 | __ ld(a0, MemOperand(a3, CommonFrameConstants::kContextOrFrameTypeOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5249 | __ Branch(&arguments_adaptor, eq, a0, |
| 5250 | Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5251 | { |
| 5252 | __ ld(a1, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 5253 | __ lw(a0, |
| 5254 | FieldMemOperand(a1, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 5255 | __ Dlsa(a2, a2, a0, kPointerSizeLog2); |
| 5256 | __ Daddu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset - |
| 5257 | 1 * kPointerSize)); |
| 5258 | } |
| 5259 | __ Branch(&arguments_done); |
| 5260 | __ bind(&arguments_adaptor); |
| 5261 | { |
| 5262 | __ SmiLoadUntag( |
| 5263 | a0, MemOperand(a3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 5264 | __ Dlsa(a2, a3, a0, kPointerSizeLog2); |
| 5265 | __ Daddu(a2, a2, Operand(StandardFrameConstants::kCallerSPOffset - |
| 5266 | 1 * kPointerSize)); |
| 5267 | } |
| 5268 | __ bind(&arguments_done); |
| 5269 | |
| 5270 | // ----------- S t a t e ------------- |
| 5271 | // -- cp : context |
| 5272 | // -- a0 : number of rest parameters |
| 5273 | // -- a2 : pointer to first rest parameters |
| 5274 | // -- ra : return address |
| 5275 | // ----------------------------------- |
| 5276 | |
| 5277 | // Allocate space for the rest parameter array plus the backing store. |
| 5278 | Label allocate, done_allocate; |
| 5279 | __ li(a1, Operand(JSStrictArgumentsObject::kSize + FixedArray::kHeaderSize)); |
| 5280 | __ Dlsa(a1, a1, a0, kPointerSizeLog2); |
| 5281 | __ Allocate(a1, v0, a3, a4, &allocate, TAG_OBJECT); |
| 5282 | __ bind(&done_allocate); |
| 5283 | |
| 5284 | // Compute arguments.length in a4. |
| 5285 | __ SmiTag(a4, a0); |
| 5286 | |
| 5287 | // Setup the elements array in v0. |
| 5288 | __ LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 5289 | __ sd(at, FieldMemOperand(v0, FixedArray::kMapOffset)); |
| 5290 | __ sd(a4, FieldMemOperand(v0, FixedArray::kLengthOffset)); |
| 5291 | __ Daddu(a3, v0, Operand(FixedArray::kHeaderSize)); |
| 5292 | { |
| 5293 | Label loop, done_loop; |
| 5294 | __ Dlsa(a1, a3, a0, kPointerSizeLog2); |
| 5295 | __ bind(&loop); |
| 5296 | __ Branch(&done_loop, eq, a1, Operand(a3)); |
| 5297 | __ ld(at, MemOperand(a2, 0 * kPointerSize)); |
| 5298 | __ sd(at, FieldMemOperand(a3, 0 * kPointerSize)); |
| 5299 | __ Dsubu(a2, a2, Operand(1 * kPointerSize)); |
| 5300 | __ Daddu(a3, a3, Operand(1 * kPointerSize)); |
| 5301 | __ Branch(&loop); |
| 5302 | __ bind(&done_loop); |
| 5303 | } |
| 5304 | |
| 5305 | // Setup the strict arguments object in a3. |
| 5306 | __ LoadNativeContextSlot(Context::STRICT_ARGUMENTS_MAP_INDEX, at); |
| 5307 | __ sd(at, FieldMemOperand(a3, JSStrictArgumentsObject::kMapOffset)); |
| 5308 | __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex); |
| 5309 | __ sd(at, FieldMemOperand(a3, JSStrictArgumentsObject::kPropertiesOffset)); |
| 5310 | __ sd(v0, FieldMemOperand(a3, JSStrictArgumentsObject::kElementsOffset)); |
| 5311 | __ sd(a4, FieldMemOperand(a3, JSStrictArgumentsObject::kLengthOffset)); |
| 5312 | STATIC_ASSERT(JSStrictArgumentsObject::kSize == 4 * kPointerSize); |
| 5313 | __ Ret(USE_DELAY_SLOT); |
| 5314 | __ mov(v0, a3); // In delay slot |
| 5315 | |
| 5316 | // Fall back to %AllocateInNewSpace. |
| 5317 | __ bind(&allocate); |
| 5318 | { |
| 5319 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5320 | __ SmiTag(a0); |
| 5321 | __ SmiTag(a1); |
| 5322 | __ Push(a0, a2, a1); |
| 5323 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 5324 | __ Pop(a0, a2); |
| 5325 | __ SmiUntag(a0); |
| 5326 | } |
| 5327 | __ jmp(&done_allocate); |
| 5328 | } |
| 5329 | |
| 5330 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5331 | void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) { |
| 5332 | Register context_reg = cp; |
| 5333 | Register slot_reg = a2; |
| 5334 | Register result_reg = v0; |
| 5335 | Label slow_case; |
| 5336 | |
| 5337 | // Go up context chain to the script context. |
| 5338 | for (int i = 0; i < depth(); ++i) { |
| 5339 | __ ld(result_reg, ContextMemOperand(context_reg, Context::PREVIOUS_INDEX)); |
| 5340 | context_reg = result_reg; |
| 5341 | } |
| 5342 | |
| 5343 | // Load the PropertyCell value at the specified slot. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5344 | __ Dlsa(at, context_reg, slot_reg, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5345 | __ ld(result_reg, ContextMemOperand(at, 0)); |
| 5346 | __ ld(result_reg, FieldMemOperand(result_reg, PropertyCell::kValueOffset)); |
| 5347 | |
| 5348 | // Check that value is not the_hole. |
| 5349 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 5350 | __ Branch(&slow_case, eq, result_reg, Operand(at)); |
| 5351 | __ Ret(); |
| 5352 | |
| 5353 | // Fallback to the runtime. |
| 5354 | __ bind(&slow_case); |
| 5355 | __ SmiTag(slot_reg); |
| 5356 | __ Push(slot_reg); |
| 5357 | __ TailCallRuntime(Runtime::kLoadGlobalViaContext); |
| 5358 | } |
| 5359 | |
| 5360 | |
| 5361 | void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) { |
| 5362 | Register context_reg = cp; |
| 5363 | Register slot_reg = a2; |
| 5364 | Register value_reg = a0; |
| 5365 | Register cell_reg = a4; |
| 5366 | Register cell_value_reg = a5; |
| 5367 | Register cell_details_reg = a6; |
| 5368 | Label fast_heapobject_case, fast_smi_case, slow_case; |
| 5369 | |
| 5370 | if (FLAG_debug_code) { |
| 5371 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 5372 | __ Check(ne, kUnexpectedValue, value_reg, Operand(at)); |
| 5373 | } |
| 5374 | |
| 5375 | // Go up context chain to the script context. |
| 5376 | for (int i = 0; i < depth(); ++i) { |
| 5377 | __ ld(cell_reg, ContextMemOperand(context_reg, Context::PREVIOUS_INDEX)); |
| 5378 | context_reg = cell_reg; |
| 5379 | } |
| 5380 | |
| 5381 | // Load the PropertyCell at the specified slot. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5382 | __ Dlsa(at, context_reg, slot_reg, kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5383 | __ ld(cell_reg, ContextMemOperand(at, 0)); |
| 5384 | |
| 5385 | // Load PropertyDetails for the cell (actually only the cell_type and kind). |
| 5386 | __ ld(cell_details_reg, |
| 5387 | FieldMemOperand(cell_reg, PropertyCell::kDetailsOffset)); |
| 5388 | __ SmiUntag(cell_details_reg); |
| 5389 | __ And(cell_details_reg, cell_details_reg, |
| 5390 | PropertyDetails::PropertyCellTypeField::kMask | |
| 5391 | PropertyDetails::KindField::kMask | |
| 5392 | PropertyDetails::kAttributesReadOnlyMask); |
| 5393 | |
| 5394 | // Check if PropertyCell holds mutable data. |
| 5395 | Label not_mutable_data; |
| 5396 | __ Branch(¬_mutable_data, ne, cell_details_reg, |
| 5397 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5398 | PropertyCellType::kMutable) | |
| 5399 | PropertyDetails::KindField::encode(kData))); |
| 5400 | __ JumpIfSmi(value_reg, &fast_smi_case); |
| 5401 | __ bind(&fast_heapobject_case); |
| 5402 | __ sd(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5403 | __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg, |
| 5404 | cell_details_reg, kRAHasNotBeenSaved, kDontSaveFPRegs, |
| 5405 | EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); |
| 5406 | // RecordWriteField clobbers the value register, so we need to reload. |
| 5407 | __ Ret(USE_DELAY_SLOT); |
| 5408 | __ ld(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5409 | __ bind(¬_mutable_data); |
| 5410 | |
| 5411 | // Check if PropertyCell value matches the new value (relevant for Constant, |
| 5412 | // ConstantType and Undefined cells). |
| 5413 | Label not_same_value; |
| 5414 | __ ld(cell_value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5415 | __ Branch(¬_same_value, ne, value_reg, Operand(cell_value_reg)); |
| 5416 | // Make sure the PropertyCell is not marked READ_ONLY. |
| 5417 | __ And(at, cell_details_reg, PropertyDetails::kAttributesReadOnlyMask); |
| 5418 | __ Branch(&slow_case, ne, at, Operand(zero_reg)); |
| 5419 | if (FLAG_debug_code) { |
| 5420 | Label done; |
| 5421 | // This can only be true for Constant, ConstantType and Undefined cells, |
| 5422 | // because we never store the_hole via this stub. |
| 5423 | __ Branch(&done, eq, cell_details_reg, |
| 5424 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5425 | PropertyCellType::kConstant) | |
| 5426 | PropertyDetails::KindField::encode(kData))); |
| 5427 | __ Branch(&done, eq, cell_details_reg, |
| 5428 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5429 | PropertyCellType::kConstantType) | |
| 5430 | PropertyDetails::KindField::encode(kData))); |
| 5431 | __ Check(eq, kUnexpectedValue, cell_details_reg, |
| 5432 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5433 | PropertyCellType::kUndefined) | |
| 5434 | PropertyDetails::KindField::encode(kData))); |
| 5435 | __ bind(&done); |
| 5436 | } |
| 5437 | __ Ret(); |
| 5438 | __ bind(¬_same_value); |
| 5439 | |
| 5440 | // Check if PropertyCell contains data with constant type (and is not |
| 5441 | // READ_ONLY). |
| 5442 | __ Branch(&slow_case, ne, cell_details_reg, |
| 5443 | Operand(PropertyDetails::PropertyCellTypeField::encode( |
| 5444 | PropertyCellType::kConstantType) | |
| 5445 | PropertyDetails::KindField::encode(kData))); |
| 5446 | |
| 5447 | // Now either both old and new values must be SMIs or both must be heap |
| 5448 | // objects with same map. |
| 5449 | Label value_is_heap_object; |
| 5450 | __ JumpIfNotSmi(value_reg, &value_is_heap_object); |
| 5451 | __ JumpIfNotSmi(cell_value_reg, &slow_case); |
| 5452 | // Old and new values are SMIs, no need for a write barrier here. |
| 5453 | __ bind(&fast_smi_case); |
| 5454 | __ Ret(USE_DELAY_SLOT); |
| 5455 | __ sd(value_reg, FieldMemOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5456 | __ bind(&value_is_heap_object); |
| 5457 | __ JumpIfSmi(cell_value_reg, &slow_case); |
| 5458 | Register cell_value_map_reg = cell_value_reg; |
| 5459 | __ ld(cell_value_map_reg, |
| 5460 | FieldMemOperand(cell_value_reg, HeapObject::kMapOffset)); |
| 5461 | __ Branch(&fast_heapobject_case, eq, cell_value_map_reg, |
| 5462 | FieldMemOperand(value_reg, HeapObject::kMapOffset)); |
| 5463 | |
| 5464 | // Fallback to the runtime. |
| 5465 | __ bind(&slow_case); |
| 5466 | __ SmiTag(slot_reg); |
| 5467 | __ Push(slot_reg, value_reg); |
| 5468 | __ TailCallRuntime(is_strict(language_mode()) |
| 5469 | ? Runtime::kStoreGlobalViaContext_Strict |
| 5470 | : Runtime::kStoreGlobalViaContext_Sloppy); |
| 5471 | } |
| 5472 | |
| 5473 | |
| 5474 | static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { |
| 5475 | int64_t offset = (ref0.address() - ref1.address()); |
| 5476 | DCHECK(static_cast<int>(offset) == offset); |
| 5477 | return static_cast<int>(offset); |
| 5478 | } |
| 5479 | |
| 5480 | |
| 5481 | // Calls an API function. Allocates HandleScope, extracts returned value |
| 5482 | // from handle and propagates exceptions. Restores context. stack_space |
| 5483 | // - space to be unwound on exit (includes the call JS arguments space and |
| 5484 | // the additional space allocated for the fast call). |
| 5485 | static void CallApiFunctionAndReturn( |
| 5486 | MacroAssembler* masm, Register function_address, |
| 5487 | ExternalReference thunk_ref, int stack_space, int32_t stack_space_offset, |
| 5488 | MemOperand return_value_operand, MemOperand* context_restore_operand) { |
| 5489 | Isolate* isolate = masm->isolate(); |
| 5490 | ExternalReference next_address = |
| 5491 | ExternalReference::handle_scope_next_address(isolate); |
| 5492 | const int kNextOffset = 0; |
| 5493 | const int kLimitOffset = AddressOffset( |
| 5494 | ExternalReference::handle_scope_limit_address(isolate), next_address); |
| 5495 | const int kLevelOffset = AddressOffset( |
| 5496 | ExternalReference::handle_scope_level_address(isolate), next_address); |
| 5497 | |
| 5498 | DCHECK(function_address.is(a1) || function_address.is(a2)); |
| 5499 | |
| 5500 | Label profiler_disabled; |
| 5501 | Label end_profiler_check; |
| 5502 | __ li(t9, Operand(ExternalReference::is_profiling_address(isolate))); |
| 5503 | __ lb(t9, MemOperand(t9, 0)); |
| 5504 | __ Branch(&profiler_disabled, eq, t9, Operand(zero_reg)); |
| 5505 | |
| 5506 | // Additional parameter is the address of the actual callback. |
| 5507 | __ li(t9, Operand(thunk_ref)); |
| 5508 | __ jmp(&end_profiler_check); |
| 5509 | |
| 5510 | __ bind(&profiler_disabled); |
| 5511 | __ mov(t9, function_address); |
| 5512 | __ bind(&end_profiler_check); |
| 5513 | |
| 5514 | // Allocate HandleScope in callee-save registers. |
| 5515 | __ li(s3, Operand(next_address)); |
| 5516 | __ ld(s0, MemOperand(s3, kNextOffset)); |
| 5517 | __ ld(s1, MemOperand(s3, kLimitOffset)); |
| 5518 | __ lw(s2, MemOperand(s3, kLevelOffset)); |
| 5519 | __ Addu(s2, s2, Operand(1)); |
| 5520 | __ sw(s2, MemOperand(s3, kLevelOffset)); |
| 5521 | |
| 5522 | if (FLAG_log_timer_events) { |
| 5523 | FrameScope frame(masm, StackFrame::MANUAL); |
| 5524 | __ PushSafepointRegisters(); |
| 5525 | __ PrepareCallCFunction(1, a0); |
| 5526 | __ li(a0, Operand(ExternalReference::isolate_address(isolate))); |
| 5527 | __ CallCFunction(ExternalReference::log_enter_external_function(isolate), |
| 5528 | 1); |
| 5529 | __ PopSafepointRegisters(); |
| 5530 | } |
| 5531 | |
| 5532 | // Native call returns to the DirectCEntry stub which redirects to the |
| 5533 | // return address pushed on stack (could have moved after GC). |
| 5534 | // DirectCEntry stub itself is generated early and never moves. |
| 5535 | DirectCEntryStub stub(isolate); |
| 5536 | stub.GenerateCall(masm, t9); |
| 5537 | |
| 5538 | if (FLAG_log_timer_events) { |
| 5539 | FrameScope frame(masm, StackFrame::MANUAL); |
| 5540 | __ PushSafepointRegisters(); |
| 5541 | __ PrepareCallCFunction(1, a0); |
| 5542 | __ li(a0, Operand(ExternalReference::isolate_address(isolate))); |
| 5543 | __ CallCFunction(ExternalReference::log_leave_external_function(isolate), |
| 5544 | 1); |
| 5545 | __ PopSafepointRegisters(); |
| 5546 | } |
| 5547 | |
| 5548 | Label promote_scheduled_exception; |
| 5549 | Label delete_allocated_handles; |
| 5550 | Label leave_exit_frame; |
| 5551 | Label return_value_loaded; |
| 5552 | |
| 5553 | // Load value from ReturnValue. |
| 5554 | __ ld(v0, return_value_operand); |
| 5555 | __ bind(&return_value_loaded); |
| 5556 | |
| 5557 | // No more valid handles (the result handle was the last one). Restore |
| 5558 | // previous handle scope. |
| 5559 | __ sd(s0, MemOperand(s3, kNextOffset)); |
| 5560 | if (__ emit_debug_code()) { |
| 5561 | __ lw(a1, MemOperand(s3, kLevelOffset)); |
| 5562 | __ Check(eq, kUnexpectedLevelAfterReturnFromApiCall, a1, Operand(s2)); |
| 5563 | } |
| 5564 | __ Subu(s2, s2, Operand(1)); |
| 5565 | __ sw(s2, MemOperand(s3, kLevelOffset)); |
| 5566 | __ ld(at, MemOperand(s3, kLimitOffset)); |
| 5567 | __ Branch(&delete_allocated_handles, ne, s1, Operand(at)); |
| 5568 | |
| 5569 | // Leave the API exit frame. |
| 5570 | __ bind(&leave_exit_frame); |
| 5571 | |
| 5572 | bool restore_context = context_restore_operand != NULL; |
| 5573 | if (restore_context) { |
| 5574 | __ ld(cp, *context_restore_operand); |
| 5575 | } |
| 5576 | if (stack_space_offset != kInvalidStackOffset) { |
| 5577 | DCHECK(kCArgsSlotsSize == 0); |
| 5578 | __ ld(s0, MemOperand(sp, stack_space_offset)); |
| 5579 | } else { |
| 5580 | __ li(s0, Operand(stack_space)); |
| 5581 | } |
| 5582 | __ LeaveExitFrame(false, s0, !restore_context, NO_EMIT_RETURN, |
| 5583 | stack_space_offset != kInvalidStackOffset); |
| 5584 | |
| 5585 | // Check if the function scheduled an exception. |
| 5586 | __ LoadRoot(a4, Heap::kTheHoleValueRootIndex); |
| 5587 | __ li(at, Operand(ExternalReference::scheduled_exception_address(isolate))); |
| 5588 | __ ld(a5, MemOperand(at)); |
| 5589 | __ Branch(&promote_scheduled_exception, ne, a4, Operand(a5)); |
| 5590 | |
| 5591 | __ Ret(); |
| 5592 | |
| 5593 | // Re-throw by promoting a scheduled exception. |
| 5594 | __ bind(&promote_scheduled_exception); |
| 5595 | __ TailCallRuntime(Runtime::kPromoteScheduledException); |
| 5596 | |
| 5597 | // HandleScope limit has changed. Delete allocated extensions. |
| 5598 | __ bind(&delete_allocated_handles); |
| 5599 | __ sd(s1, MemOperand(s3, kLimitOffset)); |
| 5600 | __ mov(s0, v0); |
| 5601 | __ mov(a0, v0); |
| 5602 | __ PrepareCallCFunction(1, s1); |
| 5603 | __ li(a0, Operand(ExternalReference::isolate_address(isolate))); |
| 5604 | __ CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate), |
| 5605 | 1); |
| 5606 | __ mov(v0, s0); |
| 5607 | __ jmp(&leave_exit_frame); |
| 5608 | } |
| 5609 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5610 | void CallApiCallbackStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5611 | // ----------- S t a t e ------------- |
| 5612 | // -- a0 : callee |
| 5613 | // -- a4 : call_data |
| 5614 | // -- a2 : holder |
| 5615 | // -- a1 : api_function_address |
| 5616 | // -- cp : context |
| 5617 | // -- |
| 5618 | // -- sp[0] : last argument |
| 5619 | // -- ... |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5620 | // -- sp[(argc - 1)* 8] : first argument |
| 5621 | // -- sp[argc * 8] : receiver |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5622 | // ----------------------------------- |
| 5623 | |
| 5624 | Register callee = a0; |
| 5625 | Register call_data = a4; |
| 5626 | Register holder = a2; |
| 5627 | Register api_function_address = a1; |
| 5628 | Register context = cp; |
| 5629 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5630 | typedef FunctionCallbackArguments FCA; |
| 5631 | |
| 5632 | STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
| 5633 | STATIC_ASSERT(FCA::kCalleeIndex == 5); |
| 5634 | STATIC_ASSERT(FCA::kDataIndex == 4); |
| 5635 | STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
| 5636 | STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
| 5637 | STATIC_ASSERT(FCA::kIsolateIndex == 1); |
| 5638 | STATIC_ASSERT(FCA::kHolderIndex == 0); |
| 5639 | STATIC_ASSERT(FCA::kArgsLength == 7); |
| 5640 | |
| 5641 | // Save context, callee and call data. |
| 5642 | __ Push(context, callee, call_data); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5643 | if (!is_lazy()) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5644 | // Load context from callee. |
| 5645 | __ ld(context, FieldMemOperand(callee, JSFunction::kContextOffset)); |
| 5646 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5647 | |
| 5648 | Register scratch = call_data; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5649 | if (!call_data_undefined()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5650 | __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 5651 | } |
| 5652 | // Push return value and default return value. |
| 5653 | __ Push(scratch, scratch); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5654 | __ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5655 | // Push isolate and holder. |
| 5656 | __ Push(scratch, holder); |
| 5657 | |
| 5658 | // Prepare arguments. |
| 5659 | __ mov(scratch, sp); |
| 5660 | |
| 5661 | // Allocate the v8::Arguments structure in the arguments' space since |
| 5662 | // it's not controlled by GC. |
| 5663 | const int kApiStackSpace = 4; |
| 5664 | |
| 5665 | FrameScope frame_scope(masm, StackFrame::MANUAL); |
| 5666 | __ EnterExitFrame(false, kApiStackSpace); |
| 5667 | |
| 5668 | DCHECK(!api_function_address.is(a0) && !scratch.is(a0)); |
| 5669 | // a0 = FunctionCallbackInfo& |
| 5670 | // Arguments is after the return address. |
| 5671 | __ Daddu(a0, sp, Operand(1 * kPointerSize)); |
| 5672 | // FunctionCallbackInfo::implicit_args_ |
| 5673 | __ sd(scratch, MemOperand(a0, 0 * kPointerSize)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5674 | // FunctionCallbackInfo::values_ |
| 5675 | __ Daddu(at, scratch, |
| 5676 | Operand((FCA::kArgsLength - 1 + argc()) * kPointerSize)); |
| 5677 | __ sd(at, MemOperand(a0, 1 * kPointerSize)); |
| 5678 | // FunctionCallbackInfo::length_ = argc |
| 5679 | // Stored as int field, 32-bit integers within struct on stack always left |
| 5680 | // justified by n64 ABI. |
| 5681 | __ li(at, Operand(argc())); |
| 5682 | __ sw(at, MemOperand(a0, 2 * kPointerSize)); |
| 5683 | // FunctionCallbackInfo::is_construct_call_ = 0 |
| 5684 | __ sw(zero_reg, MemOperand(a0, 2 * kPointerSize + kIntSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5685 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5686 | ExternalReference thunk_ref = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5687 | ExternalReference::invoke_function_callback(masm->isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5688 | |
| 5689 | AllowExternalCallThatCantCauseGC scope(masm); |
| 5690 | MemOperand context_restore_operand( |
| 5691 | fp, (2 + FCA::kContextSaveIndex) * kPointerSize); |
| 5692 | // Stores return the first js argument. |
| 5693 | int return_value_offset = 0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5694 | if (is_store()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5695 | return_value_offset = 2 + FCA::kArgsLength; |
| 5696 | } else { |
| 5697 | return_value_offset = 2 + FCA::kReturnValueOffset; |
| 5698 | } |
| 5699 | MemOperand return_value_operand(fp, return_value_offset * kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5700 | int stack_space = 0; |
| 5701 | int32_t stack_space_offset = 4 * kPointerSize; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5702 | stack_space = argc() + FCA::kArgsLength + 1; |
| 5703 | stack_space_offset = kInvalidStackOffset; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5704 | CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, stack_space, |
| 5705 | stack_space_offset, return_value_operand, |
| 5706 | &context_restore_operand); |
| 5707 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5708 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5709 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5710 | void CallApiGetterStub::Generate(MacroAssembler* masm) { |
| 5711 | // ----------- S t a t e ------------- |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5712 | // -- sp[0] : name |
| 5713 | // -- sp[8 .. (8 + kArgsLength*8)] : v8::PropertyCallbackInfo::args_ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5714 | // -- ... |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5715 | // -- a2 : api_function_address |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5716 | // ----------------------------------- |
| 5717 | |
| 5718 | Register api_function_address = ApiGetterDescriptor::function_address(); |
| 5719 | DCHECK(api_function_address.is(a2)); |
| 5720 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5721 | // v8::PropertyCallbackInfo::args_ array and name handle. |
| 5722 | const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1; |
| 5723 | |
| 5724 | // Load address of v8::PropertyAccessorInfo::args_ array and name handle. |
| 5725 | __ mov(a0, sp); // a0 = Handle<Name> |
| 5726 | __ Daddu(a1, a0, Operand(1 * kPointerSize)); // a1 = v8::PCI::args_ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5727 | |
| 5728 | const int kApiStackSpace = 1; |
| 5729 | FrameScope frame_scope(masm, StackFrame::MANUAL); |
| 5730 | __ EnterExitFrame(false, kApiStackSpace); |
| 5731 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5732 | // Create v8::PropertyCallbackInfo object on the stack and initialize |
| 5733 | // it's args_ field. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5734 | __ sd(a1, MemOperand(sp, 1 * kPointerSize)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5735 | __ Daddu(a1, sp, Operand(1 * kPointerSize)); |
| 5736 | // a1 = v8::PropertyCallbackInfo& |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5737 | |
| 5738 | ExternalReference thunk_ref = |
| 5739 | ExternalReference::invoke_accessor_getter_callback(isolate()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5740 | |
| 5741 | // +3 is to skip prolog, return address and name handle. |
| 5742 | MemOperand return_value_operand( |
| 5743 | fp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5744 | CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, |
| 5745 | kStackUnwindSpace, kInvalidStackOffset, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5746 | return_value_operand, NULL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5747 | } |
| 5748 | |
| 5749 | |
| 5750 | #undef __ |
| 5751 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5752 | } // namespace internal |
| 5753 | } // namespace v8 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5754 | |
| 5755 | #endif // V8_TARGET_ARCH_MIPS64 |