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