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