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