blob: 3e84a2143c3417a987c63eec0834e83b64db05c6 [file] [log] [blame]
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/v8.h"
#if V8_TARGET_ARCH_PPC
#include "src/base/bits.h"
#include "src/bootstrapper.h"
#include "src/code-stubs.h"
#include "src/codegen.h"
#include "src/ic/handler-compiler.h"
#include "src/ic/ic.h"
#include "src/isolate.h"
#include "src/jsregexp.h"
#include "src/regexp-macro-assembler.h"
#include "src/runtime/runtime.h"
namespace v8 {
namespace internal {
static void InitializeArrayConstructorDescriptor(
Isolate* isolate, CodeStubDescriptor* descriptor,
int constant_stack_parameter_count) {
Address deopt_handler =
Runtime::FunctionForId(Runtime::kArrayConstructor)->entry;
if (constant_stack_parameter_count == 0) {
descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
JS_FUNCTION_STUB_MODE);
} else {
descriptor->Initialize(r3, deopt_handler, constant_stack_parameter_count,
JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS);
}
}
static void InitializeInternalArrayConstructorDescriptor(
Isolate* isolate, CodeStubDescriptor* descriptor,
int constant_stack_parameter_count) {
Address deopt_handler =
Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry;
if (constant_stack_parameter_count == 0) {
descriptor->Initialize(deopt_handler, constant_stack_parameter_count,
JS_FUNCTION_STUB_MODE);
} else {
descriptor->Initialize(r3, deopt_handler, constant_stack_parameter_count,
JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS);
}
}
void ArrayNoArgumentConstructorStub::InitializeDescriptor(
CodeStubDescriptor* descriptor) {
InitializeArrayConstructorDescriptor(isolate(), descriptor, 0);
}
void ArraySingleArgumentConstructorStub::InitializeDescriptor(
CodeStubDescriptor* descriptor) {
InitializeArrayConstructorDescriptor(isolate(), descriptor, 1);
}
void ArrayNArgumentsConstructorStub::InitializeDescriptor(
CodeStubDescriptor* descriptor) {
InitializeArrayConstructorDescriptor(isolate(), descriptor, -1);
}
void InternalArrayNoArgumentConstructorStub::InitializeDescriptor(
CodeStubDescriptor* descriptor) {
InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0);
}
void InternalArraySingleArgumentConstructorStub::InitializeDescriptor(
CodeStubDescriptor* descriptor) {
InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1);
}
void InternalArrayNArgumentsConstructorStub::InitializeDescriptor(
CodeStubDescriptor* descriptor) {
InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1);
}
#define __ ACCESS_MASM(masm)
static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
Condition cond);
static void EmitSmiNonsmiComparison(MacroAssembler* masm, Register lhs,
Register rhs, Label* lhs_not_nan,
Label* slow, bool strict);
static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, Register lhs,
Register rhs);
void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm,
ExternalReference miss) {
// Update the static counter each time a new code stub is generated.
isolate()->counters()->code_stubs()->Increment();
CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor();
int param_count = descriptor.GetEnvironmentParameterCount();
{
// Call the runtime system in a fresh internal frame.
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
DCHECK(param_count == 0 ||
r3.is(descriptor.GetEnvironmentParameterRegister(param_count - 1)));
// Push arguments
for (int i = 0; i < param_count; ++i) {
__ push(descriptor.GetEnvironmentParameterRegister(i));
}
__ CallExternalReference(miss, param_count);
}
__ Ret();
}
void DoubleToIStub::Generate(MacroAssembler* masm) {
Label out_of_range, only_low, negate, done, fastpath_done;
Register input_reg = source();
Register result_reg = destination();
DCHECK(is_truncating());
int double_offset = offset();
// Immediate values for this stub fit in instructions, so it's safe to use ip.
Register scratch = GetRegisterThatIsNotOneOf(input_reg, result_reg);
Register scratch_low =
GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch);
Register scratch_high =
GetRegisterThatIsNotOneOf(input_reg, result_reg, scratch, scratch_low);
DoubleRegister double_scratch = kScratchDoubleReg;
__ push(scratch);
// Account for saved regs if input is sp.
if (input_reg.is(sp)) double_offset += kPointerSize;
if (!skip_fastpath()) {
// Load double input.
__ lfd(double_scratch, MemOperand(input_reg, double_offset));
// Do fast-path convert from double to int.
__ ConvertDoubleToInt64(double_scratch,
#if !V8_TARGET_ARCH_PPC64
scratch,
#endif
result_reg, d0);
// Test for overflow
#if V8_TARGET_ARCH_PPC64
__ TestIfInt32(result_reg, scratch, r0);
#else
__ TestIfInt32(scratch, result_reg, r0);
#endif
__ beq(&fastpath_done);
}
__ Push(scratch_high, scratch_low);
// Account for saved regs if input is sp.
if (input_reg.is(sp)) double_offset += 2 * kPointerSize;
__ lwz(scratch_high,
MemOperand(input_reg, double_offset + Register::kExponentOffset));
__ lwz(scratch_low,
MemOperand(input_reg, double_offset + Register::kMantissaOffset));
__ ExtractBitMask(scratch, scratch_high, HeapNumber::kExponentMask);
// Load scratch with exponent - 1. This is faster than loading
// with exponent because Bias + 1 = 1024 which is a *PPC* immediate value.
STATIC_ASSERT(HeapNumber::kExponentBias + 1 == 1024);
__ subi(scratch, scratch, Operand(HeapNumber::kExponentBias + 1));
// If exponent is greater than or equal to 84, the 32 less significant
// bits are 0s (2^84 = 1, 52 significant bits, 32 uncoded bits),
// the result is 0.
// Compare exponent with 84 (compare exponent - 1 with 83).
__ cmpi(scratch, Operand(83));
__ bge(&out_of_range);
// If we reach this code, 31 <= exponent <= 83.
// So, we don't have to handle cases where 0 <= exponent <= 20 for
// which we would need to shift right the high part of the mantissa.
// Scratch contains exponent - 1.
// Load scratch with 52 - exponent (load with 51 - (exponent - 1)).
__ subfic(scratch, scratch, Operand(51));
__ cmpi(scratch, Operand::Zero());
__ ble(&only_low);
// 21 <= exponent <= 51, shift scratch_low and scratch_high
// to generate the result.
__ srw(scratch_low, scratch_low, scratch);
// Scratch contains: 52 - exponent.
// We needs: exponent - 20.
// So we use: 32 - scratch = 32 - 52 + exponent = exponent - 20.
__ subfic(scratch, scratch, Operand(32));
__ ExtractBitMask(result_reg, scratch_high, HeapNumber::kMantissaMask);
// Set the implicit 1 before the mantissa part in scratch_high.
STATIC_ASSERT(HeapNumber::kMantissaBitsInTopWord >= 16);
__ oris(result_reg, result_reg,
Operand(1 << ((HeapNumber::kMantissaBitsInTopWord) - 16)));
__ slw(r0, result_reg, scratch);
__ orx(result_reg, scratch_low, r0);
__ b(&negate);
__ bind(&out_of_range);
__ mov(result_reg, Operand::Zero());
__ b(&done);
__ bind(&only_low);
// 52 <= exponent <= 83, shift only scratch_low.
// On entry, scratch contains: 52 - exponent.
__ neg(scratch, scratch);
__ slw(result_reg, scratch_low, scratch);
__ bind(&negate);
// If input was positive, scratch_high ASR 31 equals 0 and
// scratch_high LSR 31 equals zero.
// New result = (result eor 0) + 0 = result.
// If the input was negative, we have to negate the result.
// Input_high ASR 31 equals 0xffffffff and scratch_high LSR 31 equals 1.
// New result = (result eor 0xffffffff) + 1 = 0 - result.
__ srawi(r0, scratch_high, 31);
#if V8_TARGET_ARCH_PPC64
__ srdi(r0, r0, Operand(32));
#endif
__ xor_(result_reg, result_reg, r0);
__ srwi(r0, scratch_high, Operand(31));
__ add(result_reg, result_reg, r0);
__ bind(&done);
__ Pop(scratch_high, scratch_low);
__ bind(&fastpath_done);
__ pop(scratch);
__ Ret();
}
// Handle the case where the lhs and rhs are the same object.
// Equality is almost reflexive (everything but NaN), so this is a test
// for "identity and not NaN".
static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
Condition cond) {
Label not_identical;
Label heap_number, return_equal;
__ cmp(r3, r4);
__ bne(&not_identical);
// Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
// so we do the second best thing - test it ourselves.
// They are both equal and they are not both Smis so both of them are not
// Smis. If it's not a heap number, then return equal.
if (cond == lt || cond == gt) {
__ CompareObjectType(r3, r7, r7, FIRST_SPEC_OBJECT_TYPE);
__ bge(slow);
} else {
__ CompareObjectType(r3, r7, r7, HEAP_NUMBER_TYPE);
__ beq(&heap_number);
// Comparing JS objects with <=, >= is complicated.
if (cond != eq) {
__ cmpi(r7, Operand(FIRST_SPEC_OBJECT_TYPE));
__ bge(slow);
// Normally here we fall through to return_equal, but undefined is
// special: (undefined == undefined) == true, but
// (undefined <= undefined) == false! See ECMAScript 11.8.5.
if (cond == le || cond == ge) {
__ cmpi(r7, Operand(ODDBALL_TYPE));
__ bne(&return_equal);
__ LoadRoot(r5, Heap::kUndefinedValueRootIndex);
__ cmp(r3, r5);
__ bne(&return_equal);
if (cond == le) {
// undefined <= undefined should fail.
__ li(r3, Operand(GREATER));
} else {
// undefined >= undefined should fail.
__ li(r3, Operand(LESS));
}
__ Ret();
}
}
}
__ bind(&return_equal);
if (cond == lt) {
__ li(r3, Operand(GREATER)); // Things aren't less than themselves.
} else if (cond == gt) {
__ li(r3, Operand(LESS)); // Things aren't greater than themselves.
} else {
__ li(r3, Operand(EQUAL)); // Things are <=, >=, ==, === themselves.
}
__ Ret();
// For less and greater we don't have to check for NaN since the result of
// x < x is false regardless. For the others here is some code to check
// for NaN.
if (cond != lt && cond != gt) {
__ bind(&heap_number);
// It is a heap number, so return non-equal if it's NaN and equal if it's
// not NaN.
// The representation of NaN values has all exponent bits (52..62) set,
// and not all mantissa bits (0..51) clear.
// Read top bits of double representation (second word of value).
__ lwz(r5, FieldMemOperand(r3, HeapNumber::kExponentOffset));
// Test that exponent bits are all set.
STATIC_ASSERT(HeapNumber::kExponentMask == 0x7ff00000u);
__ ExtractBitMask(r6, r5, HeapNumber::kExponentMask);
__ cmpli(r6, Operand(0x7ff));
__ bne(&return_equal);
// Shift out flag and all exponent bits, retaining only mantissa.
__ slwi(r5, r5, Operand(HeapNumber::kNonMantissaBitsInTopWord));
// Or with all low-bits of mantissa.
__ lwz(r6, FieldMemOperand(r3, HeapNumber::kMantissaOffset));
__ orx(r3, r6, r5);
__ cmpi(r3, Operand::Zero());
// For equal we already have the right value in r3: Return zero (equal)
// if all bits in mantissa are zero (it's an Infinity) and non-zero if
// not (it's a NaN). For <= and >= we need to load r0 with the failing
// value if it's a NaN.
if (cond != eq) {
Label not_equal;
__ bne(&not_equal);
// All-zero means Infinity means equal.
__ Ret();
__ bind(&not_equal);
if (cond == le) {
__ li(r3, Operand(GREATER)); // NaN <= NaN should fail.
} else {
__ li(r3, Operand(LESS)); // NaN >= NaN should fail.
}
}
__ Ret();
}
// No fall through here.
__ bind(&not_identical);
}
// See comment at call site.
static void EmitSmiNonsmiComparison(MacroAssembler* masm, Register lhs,
Register rhs, Label* lhs_not_nan,
Label* slow, bool strict) {
DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
Label rhs_is_smi;
__ JumpIfSmi(rhs, &rhs_is_smi);
// Lhs is a Smi. Check whether the rhs is a heap number.
__ CompareObjectType(rhs, r6, r7, HEAP_NUMBER_TYPE);
if (strict) {
// If rhs is not a number and lhs is a Smi then strict equality cannot
// succeed. Return non-equal
// If rhs is r3 then there is already a non zero value in it.
Label skip;
__ beq(&skip);
if (!rhs.is(r3)) {
__ mov(r3, Operand(NOT_EQUAL));
}
__ Ret();
__ bind(&skip);
} else {
// Smi compared non-strictly with a non-Smi non-heap-number. Call
// the runtime.
__ bne(slow);
}
// Lhs is a smi, rhs is a number.
// Convert lhs to a double in d7.
__ SmiToDouble(d7, lhs);
// Load the double from rhs, tagged HeapNumber r3, to d6.
__ lfd(d6, FieldMemOperand(rhs, HeapNumber::kValueOffset));
// We now have both loaded as doubles but we can skip the lhs nan check
// since it's a smi.
__ b(lhs_not_nan);
__ bind(&rhs_is_smi);
// Rhs is a smi. Check whether the non-smi lhs is a heap number.
__ CompareObjectType(lhs, r7, r7, HEAP_NUMBER_TYPE);
if (strict) {
// If lhs is not a number and rhs is a smi then strict equality cannot
// succeed. Return non-equal.
// If lhs is r3 then there is already a non zero value in it.
Label skip;
__ beq(&skip);
if (!lhs.is(r3)) {
__ mov(r3, Operand(NOT_EQUAL));
}
__ Ret();
__ bind(&skip);
} else {
// Smi compared non-strictly with a non-smi non-heap-number. Call
// the runtime.
__ bne(slow);
}
// Rhs is a smi, lhs is a heap number.
// Load the double from lhs, tagged HeapNumber r4, to d7.
__ lfd(d7, FieldMemOperand(lhs, HeapNumber::kValueOffset));
// Convert rhs to a double in d6.
__ SmiToDouble(d6, rhs);
// Fall through to both_loaded_as_doubles.
}
// See comment at call site.
static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, Register lhs,
Register rhs) {
DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
// If either operand is a JS object or an oddball value, then they are
// not equal since their pointers are different.
// There is no test for undetectability in strict equality.
STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
Label first_non_object;
// Get the type of the first operand into r5 and compare it with
// FIRST_SPEC_OBJECT_TYPE.
__ CompareObjectType(rhs, r5, r5, FIRST_SPEC_OBJECT_TYPE);
__ blt(&first_non_object);
// Return non-zero (r3 is not zero)
Label return_not_equal;
__ bind(&return_not_equal);
__ Ret();
__ bind(&first_non_object);
// Check for oddballs: true, false, null, undefined.
__ cmpi(r5, Operand(ODDBALL_TYPE));
__ beq(&return_not_equal);
__ CompareObjectType(lhs, r6, r6, FIRST_SPEC_OBJECT_TYPE);
__ bge(&return_not_equal);
// Check for oddballs: true, false, null, undefined.
__ cmpi(r6, Operand(ODDBALL_TYPE));
__ beq(&return_not_equal);
// Now that we have the types we might as well check for
// internalized-internalized.
STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
__ orx(r5, r5, r6);
__ andi(r0, r5, Operand(kIsNotStringMask | kIsNotInternalizedMask));
__ beq(&return_not_equal, cr0);
}
// See comment at call site.
static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm, Register lhs,
Register rhs,
Label* both_loaded_as_doubles,
Label* not_heap_numbers, Label* slow) {
DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
__ CompareObjectType(rhs, r6, r5, HEAP_NUMBER_TYPE);
__ bne(not_heap_numbers);
__ LoadP(r5, FieldMemOperand(lhs, HeapObject::kMapOffset));
__ cmp(r5, r6);
__ bne(slow); // First was a heap number, second wasn't. Go slow case.
// Both are heap numbers. Load them up then jump to the code we have
// for that.
__ lfd(d6, FieldMemOperand(rhs, HeapNumber::kValueOffset));
__ lfd(d7, FieldMemOperand(lhs, HeapNumber::kValueOffset));
__ b(both_loaded_as_doubles);
}
// Fast negative check for internalized-to-internalized equality.
static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
Register lhs, Register rhs,
Label* possible_strings,
Label* not_both_strings) {
DCHECK((lhs.is(r3) && rhs.is(r4)) || (lhs.is(r4) && rhs.is(r3)));
// r5 is object type of rhs.
Label object_test;
STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
__ andi(r0, r5, Operand(kIsNotStringMask));
__ bne(&object_test, cr0);
__ andi(r0, r5, Operand(kIsNotInternalizedMask));
__ bne(possible_strings, cr0);
__ CompareObjectType(lhs, r6, r6, FIRST_NONSTRING_TYPE);
__ bge(not_both_strings);
__ andi(r0, r6, Operand(kIsNotInternalizedMask));
__ bne(possible_strings, cr0);
// Both are internalized. We already checked they weren't the same pointer
// so they are not equal.
__ li(r3, Operand(NOT_EQUAL));
__ Ret();
__ bind(&object_test);
__ cmpi(r5, Operand(FIRST_SPEC_OBJECT_TYPE));
__ blt(not_both_strings);
__ CompareObjectType(lhs, r5, r6, FIRST_SPEC_OBJECT_TYPE);
__ blt(not_both_strings);
// If both objects are undetectable, they are equal. Otherwise, they
// are not equal, since they are different objects and an object is not
// equal to undefined.
__ LoadP(r6, FieldMemOperand(rhs, HeapObject::kMapOffset));
__ lbz(r5, FieldMemOperand(r5, Map::kBitFieldOffset));
__ lbz(r6, FieldMemOperand(r6, Map::kBitFieldOffset));
__ and_(r3, r5, r6);
__ andi(r3, r3, Operand(1 << Map::kIsUndetectable));
__ xori(r3, r3, Operand(1 << Map::kIsUndetectable));
__ Ret();
}
static void CompareICStub_CheckInputType(MacroAssembler* masm, Register input,
Register scratch,
CompareICState::State expected,
Label* fail) {
Label ok;
if (expected == CompareICState::SMI) {
__ JumpIfNotSmi(input, fail);
} else if (expected == CompareICState::NUMBER) {
__ JumpIfSmi(input, &ok);
__ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
DONT_DO_SMI_CHECK);
}
// We could be strict about internalized/non-internalized here, but as long as
// hydrogen doesn't care, the stub doesn't have to care either.
__ bind(&ok);
}
// On entry r4 and r5 are the values to be compared.
// On exit r3 is 0, positive or negative to indicate the result of
// the comparison.
void CompareICStub::GenerateGeneric(MacroAssembler* masm) {
Register lhs = r4;
Register rhs = r3;
Condition cc = GetCondition();
Label miss;
CompareICStub_CheckInputType(masm, lhs, r5, left(), &miss);
CompareICStub_CheckInputType(masm, rhs, r6, right(), &miss);
Label slow; // Call builtin.
Label not_smis, both_loaded_as_doubles, lhs_not_nan;
Label not_two_smis, smi_done;
__ orx(r5, r4, r3);
__ JumpIfNotSmi(r5, &not_two_smis);
__ SmiUntag(r4);
__ SmiUntag(r3);
__ sub(r3, r4, r3);
__ Ret();
__ bind(&not_two_smis);
// NOTICE! This code is only reached after a smi-fast-case check, so
// it is certain that at least one operand isn't a smi.
// Handle the case where the objects are identical. Either returns the answer
// or goes to slow. Only falls through if the objects were not identical.
EmitIdenticalObjectComparison(masm, &slow, cc);
// If either is a Smi (we know that not both are), then they can only
// be strictly equal if the other is a HeapNumber.
STATIC_ASSERT(kSmiTag == 0);
DCHECK_EQ(0, Smi::FromInt(0));
__ and_(r5, lhs, rhs);
__ JumpIfNotSmi(r5, &not_smis);
// One operand is a smi. EmitSmiNonsmiComparison generates code that can:
// 1) Return the answer.
// 2) Go to slow.
// 3) Fall through to both_loaded_as_doubles.
// 4) Jump to lhs_not_nan.
// In cases 3 and 4 we have found out we were dealing with a number-number
// comparison. The double values of the numbers have been loaded
// into d7 and d6.
EmitSmiNonsmiComparison(masm, lhs, rhs, &lhs_not_nan, &slow, strict());
__ bind(&both_loaded_as_doubles);
// The arguments have been converted to doubles and stored in d6 and d7
__ bind(&lhs_not_nan);
Label no_nan;
__ fcmpu(d7, d6);
Label nan, equal, less_than;
__ bunordered(&nan);
__ beq(&equal);
__ blt(&less_than);
__ li(r3, Operand(GREATER));
__ Ret();
__ bind(&equal);
__ li(r3, Operand(EQUAL));
__ Ret();
__ bind(&less_than);
__ li(r3, Operand(LESS));
__ Ret();
__ bind(&nan);
// If one of the sides was a NaN then the v flag is set. Load r3 with
// whatever it takes to make the comparison fail, since comparisons with NaN
// always fail.
if (cc == lt || cc == le) {
__ li(r3, Operand(GREATER));
} else {
__ li(r3, Operand(LESS));
}
__ Ret();
__ bind(&not_smis);
// At this point we know we are dealing with two different objects,
// and neither of them is a Smi. The objects are in rhs_ and lhs_.
if (strict()) {
// This returns non-equal for some object types, or falls through if it
// was not lucky.
EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
}
Label check_for_internalized_strings;
Label flat_string_check;
// Check for heap-number-heap-number comparison. Can jump to slow case,
// or load both doubles into r3, r4, r5, r6 and jump to the code that handles
// that case. If the inputs are not doubles then jumps to
// check_for_internalized_strings.
// In this case r5 will contain the type of rhs_. Never falls through.
EmitCheckForTwoHeapNumbers(masm, lhs, rhs, &both_loaded_as_doubles,
&check_for_internalized_strings,
&flat_string_check);
__ bind(&check_for_internalized_strings);
// In the strict case the EmitStrictTwoHeapObjectCompare already took care of
// internalized strings.
if (cc == eq && !strict()) {
// Returns an answer for two internalized strings or two detectable objects.
// Otherwise jumps to string case or not both strings case.
// Assumes that r5 is the type of rhs_ on entry.
EmitCheckForInternalizedStringsOrObjects(masm, lhs, rhs, &flat_string_check,
&slow);
}
// Check for both being sequential one-byte strings,
// and inline if that is the case.
__ bind(&flat_string_check);
__ JumpIfNonSmisNotBothSequentialOneByteStrings(lhs, rhs, r5, r6, &slow);
__ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r5,
r6);
if (cc == eq) {
StringHelper::GenerateFlatOneByteStringEquals(masm, lhs, rhs, r5, r6);
} else {
StringHelper::GenerateCompareFlatOneByteStrings(masm, lhs, rhs, r5, r6, r7);
}
// Never falls through to here.
__ bind(&slow);
__ Push(lhs, rhs);
// Figure out which native to call and setup the arguments.
Builtins::JavaScript native;
if (cc == eq) {
native = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
} else {
native = Builtins::COMPARE;
int ncr; // NaN compare result
if (cc == lt || cc == le) {
ncr = GREATER;
} else {
DCHECK(cc == gt || cc == ge); // remaining cases
ncr = LESS;
}
__ LoadSmiLiteral(r3, Smi::FromInt(ncr));
__ push(r3);
}
// Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
// tagged as a small integer.
__ InvokeBuiltin(native, JUMP_FUNCTION);
__ bind(&miss);
GenerateMiss(masm);
}
void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
// We don't allow a GC during a store buffer overflow so there is no need to
// store the registers in any particular way, but we do have to store and
// restore them.
__ mflr(r0);
__ MultiPush(kJSCallerSaved | r0.bit());
if (save_doubles()) {
__ SaveFPRegs(sp, 0, DoubleRegister::kNumVolatileRegisters);
}
const int argument_count = 1;
const int fp_argument_count = 0;
const Register scratch = r4;
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
__ mov(r3, Operand(ExternalReference::isolate_address(isolate())));
__ CallCFunction(ExternalReference::store_buffer_overflow_function(isolate()),
argument_count);
if (save_doubles()) {
__ RestoreFPRegs(sp, 0, DoubleRegister::kNumVolatileRegisters);
}
__ MultiPop(kJSCallerSaved | r0.bit());
__ mtlr(r0);
__ Ret();
}
void StoreRegistersStateStub::Generate(MacroAssembler* masm) {
__ PushSafepointRegisters();
__ blr();
}
void RestoreRegistersStateStub::Generate(MacroAssembler* masm) {
__ PopSafepointRegisters();
__ blr();
}
void MathPowStub::Generate(MacroAssembler* masm) {
const Register base = r4;
const Register exponent = MathPowTaggedDescriptor::exponent();
DCHECK(exponent.is(r5));
const Register heapnumbermap = r8;
const Register heapnumber = r3;
const DoubleRegister double_base = d1;
const DoubleRegister double_exponent = d2;
const DoubleRegister double_result = d3;
const DoubleRegister double_scratch = d0;
const Register scratch = r11;
const Register scratch2 = r10;
Label call_runtime, done, int_exponent;
if (exponent_type() == ON_STACK) {
Label base_is_smi, unpack_exponent;
// The exponent and base are supplied as arguments on the stack.
// This can only happen if the stub is called from non-optimized code.
// Load input parameters from stack to double registers.
__ LoadP(base, MemOperand(sp, 1 * kPointerSize));
__ LoadP(exponent, MemOperand(sp, 0 * kPointerSize));
__ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
__ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
__ LoadP(scratch, FieldMemOperand(base, JSObject::kMapOffset));
__ cmp(scratch, heapnumbermap);
__ bne(&call_runtime);
__ lfd(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
__ b(&unpack_exponent);
__ bind(&base_is_smi);
__ ConvertIntToDouble(scratch, double_base);
__ bind(&unpack_exponent);
__ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
__ LoadP(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
__ cmp(scratch, heapnumbermap);
__ bne(&call_runtime);
__ lfd(double_exponent,
FieldMemOperand(exponent, HeapNumber::kValueOffset));
} else if (exponent_type() == TAGGED) {
// Base is already in double_base.
__ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
__ lfd(double_exponent,
FieldMemOperand(exponent, HeapNumber::kValueOffset));
}
if (exponent_type() != INTEGER) {
// Detect integer exponents stored as double.
__ TryDoubleToInt32Exact(scratch, double_exponent, scratch2,
double_scratch);
__ beq(&int_exponent);
if (exponent_type() == ON_STACK) {
// Detect square root case. Crankshaft detects constant +/-0.5 at
// compile time and uses DoMathPowHalf instead. We then skip this check
// for non-constant cases of +/-0.5 as these hardly occur.
Label not_plus_half, not_minus_inf1, not_minus_inf2;
// Test for 0.5.
__ LoadDoubleLiteral(double_scratch, 0.5, scratch);
__ fcmpu(double_exponent, double_scratch);
__ bne(&not_plus_half);
// Calculates square root of base. Check for the special case of
// Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
__ LoadDoubleLiteral(double_scratch, -V8_INFINITY, scratch);
__ fcmpu(double_base, double_scratch);
__ bne(&not_minus_inf1);
__ fneg(double_result, double_scratch);
__ b(&done);
__ bind(&not_minus_inf1);
// Add +0 to convert -0 to +0.
__ fadd(double_scratch, double_base, kDoubleRegZero);
__ fsqrt(double_result, double_scratch);
__ b(&done);
__ bind(&not_plus_half);
__ LoadDoubleLiteral(double_scratch, -0.5, scratch);
__ fcmpu(double_exponent, double_scratch);
__ bne(&call_runtime);
// Calculates square root of base. Check for the special case of
// Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
__ LoadDoubleLiteral(double_scratch, -V8_INFINITY, scratch);
__ fcmpu(double_base, double_scratch);
__ bne(&not_minus_inf2);
__ fmr(double_result, kDoubleRegZero);
__ b(&done);
__ bind(&not_minus_inf2);
// Add +0 to convert -0 to +0.
__ fadd(double_scratch, double_base, kDoubleRegZero);
__ LoadDoubleLiteral(double_result, 1.0, scratch);
__ fsqrt(double_scratch, double_scratch);
__ fdiv(double_result, double_result, double_scratch);
__ b(&done);
}
__ mflr(r0);
__ push(r0);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(0, 2, scratch);
__ MovToFloatParameters(double_base, double_exponent);
__ CallCFunction(
ExternalReference::power_double_double_function(isolate()), 0, 2);
}
__ pop(r0);
__ mtlr(r0);
__ MovFromFloatResult(double_result);
__ b(&done);
}
// Calculate power with integer exponent.
__ bind(&int_exponent);
// Get two copies of exponent in the registers scratch and exponent.
if (exponent_type() == INTEGER) {
__ mr(scratch, exponent);
} else {
// Exponent has previously been stored into scratch as untagged integer.
__ mr(exponent, scratch);
}
__ fmr(double_scratch, double_base); // Back up base.
__ li(scratch2, Operand(1));
__ ConvertIntToDouble(scratch2, double_result);
// Get absolute value of exponent.
Label positive_exponent;
__ cmpi(scratch, Operand::Zero());
__ bge(&positive_exponent);
__ neg(scratch, scratch);
__ bind(&positive_exponent);
Label while_true, no_carry, loop_end;
__ bind(&while_true);
__ andi(scratch2, scratch, Operand(1));
__ beq(&no_carry, cr0);
__ fmul(double_result, double_result, double_scratch);
__ bind(&no_carry);
__ ShiftRightArithImm(scratch, scratch, 1, SetRC);
__ beq(&loop_end, cr0);
__ fmul(double_scratch, double_scratch, double_scratch);
__ b(&while_true);
__ bind(&loop_end);
__ cmpi(exponent, Operand::Zero());
__ bge(&done);
__ li(scratch2, Operand(1));
__ ConvertIntToDouble(scratch2, double_scratch);
__ fdiv(double_result, double_scratch, double_result);
// Test whether result is zero. Bail out to check for subnormal result.
// Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
__ fcmpu(double_result, kDoubleRegZero);
__ bne(&done);
// double_exponent may not containe the exponent value if the input was a
// smi. We set it with exponent value before bailing out.
__ ConvertIntToDouble(exponent, double_exponent);
// Returning or bailing out.
Counters* counters = isolate()->counters();
if (exponent_type() == ON_STACK) {
// The arguments are still on the stack.
__ bind(&call_runtime);
__ TailCallRuntime(Runtime::kMathPowRT, 2, 1);
// The stub is called from non-optimized code, which expects the result
// as heap number in exponent.
__ bind(&done);
__ AllocateHeapNumber(heapnumber, scratch, scratch2, heapnumbermap,
&call_runtime);
__ stfd(double_result,
FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
DCHECK(heapnumber.is(r3));
__ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
__ Ret(2);
} else {
__ mflr(r0);
__ push(r0);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(0, 2, scratch);
__ MovToFloatParameters(double_base, double_exponent);
__ CallCFunction(
ExternalReference::power_double_double_function(isolate()), 0, 2);
}
__ pop(r0);
__ mtlr(r0);
__ MovFromFloatResult(double_result);
__ bind(&done);
__ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
__ Ret();
}
}
bool CEntryStub::NeedsImmovableCode() { return true; }
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate);
// WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime(isolate);
StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
BinaryOpICStub::GenerateAheadOfTime(isolate);
StoreRegistersStateStub::GenerateAheadOfTime(isolate);
RestoreRegistersStateStub::GenerateAheadOfTime(isolate);
BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
}
void StoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
StoreRegistersStateStub stub(isolate);
stub.GetCode();
}
void RestoreRegistersStateStub::GenerateAheadOfTime(Isolate* isolate) {
RestoreRegistersStateStub stub(isolate);
stub.GetCode();
}
void CodeStub::GenerateFPStubs(Isolate* isolate) {
// Generate if not already in cache.
SaveFPRegsMode mode = kSaveFPRegs;
CEntryStub(isolate, 1, mode).GetCode();
StoreBufferOverflowStub(isolate, mode).GetCode();
isolate->set_fp_stubs_generated(true);
}
void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
CEntryStub stub(isolate, 1, kDontSaveFPRegs);
stub.GetCode();
}
void CEntryStub::Generate(MacroAssembler* masm) {
// Called from JavaScript; parameters are on stack as if calling JS function.
// r3: number of arguments including receiver
// r4: pointer to builtin function
// fp: frame pointer (restored after C call)
// sp: stack pointer (restored as callee's sp after C call)
// cp: current context (C callee-saved)
ProfileEntryHookStub::MaybeCallEntryHook(masm);
__ mr(r15, r4);
// Compute the argv pointer.
__ ShiftLeftImm(r4, r3, Operand(kPointerSizeLog2));
__ add(r4, r4, sp);
__ subi(r4, r4, Operand(kPointerSize));
// Enter the exit frame that transitions from JavaScript to C++.
FrameScope scope(masm, StackFrame::MANUAL);
// Need at least one extra slot for return address location.
int arg_stack_space = 1;
// PPC LINUX ABI:
#if V8_TARGET_ARCH_PPC64 && !ABI_RETURNS_OBJECT_PAIRS_IN_REGS
// Pass buffer for return value on stack if necessary
if (result_size() > 1) {
DCHECK_EQ(2, result_size());
arg_stack_space += 2;
}
#endif
__ EnterExitFrame(save_doubles(), arg_stack_space);
// Store a copy of argc in callee-saved registers for later.
__ mr(r14, r3);
// r3, r14: number of arguments including receiver (C callee-saved)
// r4: pointer to the first argument
// r15: pointer to builtin function (C callee-saved)
// Result returned in registers or stack, depending on result size and ABI.
Register isolate_reg = r5;
#if V8_TARGET_ARCH_PPC64 && !ABI_RETURNS_OBJECT_PAIRS_IN_REGS
if (result_size() > 1) {
// The return value is 16-byte non-scalar value.
// Use frame storage reserved by calling function to pass return
// buffer as implicit first argument.
__ mr(r5, r4);
__ mr(r4, r3);
__ addi(r3, sp, Operand((kStackFrameExtraParamSlot + 1) * kPointerSize));
isolate_reg = r6;
}
#endif
// Call C built-in.
__ mov(isolate_reg, Operand(ExternalReference::isolate_address(isolate())));
#if ABI_USES_FUNCTION_DESCRIPTORS && !defined(USE_SIMULATOR)
// Native AIX/PPC64 Linux use a function descriptor.
__ LoadP(ToRegister(ABI_TOC_REGISTER), MemOperand(r15, kPointerSize));
__ LoadP(ip, MemOperand(r15, 0)); // Instruction address
Register target = ip;
#elif ABI_TOC_ADDRESSABILITY_VIA_IP
__ Move(ip, r15);
Register target = ip;
#else
Register target = r15;
#endif
// To let the GC traverse the return address of the exit frames, we need to
// know where the return address is. The CEntryStub is unmovable, so
// we can store the address on the stack to be able to find it again and
// we never have to restore it, because it will not change.
// Compute the return address in lr to return to after the jump below. Pc is
// already at '+ 8' from the current instruction but return is after three
// instructions so add another 4 to pc to get the return address.
{
Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
Label here;
__ b(&here, SetLK);
__ bind(&here);
__ mflr(r8);
// Constant used below is dependent on size of Call() macro instructions
__ addi(r0, r8, Operand(20));
__ StoreP(r0, MemOperand(sp, kStackFrameExtraParamSlot * kPointerSize));
__ Call(target);
}
#if V8_TARGET_ARCH_PPC64 && !ABI_RETURNS_OBJECT_PAIRS_IN_REGS
// If return value is on the stack, pop it to registers.
if (result_size() > 1) {
__ LoadP(r4, MemOperand(r3, kPointerSize));
__ LoadP(r3, MemOperand(r3));
}
#endif
// Runtime functions should not return 'the hole'. Allowing it to escape may
// lead to crashes in the IC code later.
if (FLAG_debug_code) {
Label okay;
__ CompareRoot(r3, Heap::kTheHoleValueRootIndex);
__ bne(&okay);
__ stop("The hole escaped");
__ bind(&okay);
}
// Check result for exception sentinel.
Label exception_returned;
__ CompareRoot(r3, Heap::kExceptionRootIndex);
__ beq(&exception_returned);
ExternalReference pending_exception_address(Isolate::kPendingExceptionAddress,
isolate());
// Check that there is no pending exception, otherwise we
// should have returned the exception sentinel.
if (FLAG_debug_code) {
Label okay;
__ mov(r5, Operand(pending_exception_address));
__ LoadP(r5, MemOperand(r5));
__ CompareRoot(r5, Heap::kTheHoleValueRootIndex);
// Cannot use check here as it attempts to generate call into runtime.
__ beq(&okay);
__ stop("Unexpected pending exception");
__ bind(&okay);
}
// Exit C frame and return.
// r3:r4: result
// sp: stack pointer
// fp: frame pointer
// r14: still holds argc (callee-saved).
__ LeaveExitFrame(save_doubles(), r14, true);
__ blr();
// Handling of exception.
__ bind(&exception_returned);
// Retrieve the pending exception.
__ mov(r5, Operand(pending_exception_address));
__ LoadP(r3, MemOperand(r5));
// Clear the pending exception.
__ LoadRoot(r6, Heap::kTheHoleValueRootIndex);
__ StoreP(r6, MemOperand(r5));
// Special handling of termination exceptions which are uncatchable
// by javascript code.
Label throw_termination_exception;
__ CompareRoot(r3, Heap::kTerminationExceptionRootIndex);
__ beq(&throw_termination_exception);
// Handle normal exception.
__ Throw(r3);
__ bind(&throw_termination_exception);
__ ThrowUncatchable(r3);
}
void JSEntryStub::Generate(MacroAssembler* masm) {
// r3: code entry
// r4: function
// r5: receiver
// r6: argc
// [sp+0]: argv
Label invoke, handler_entry, exit;
// Called from C
#if ABI_USES_FUNCTION_DESCRIPTORS
__ function_descriptor();
#endif
ProfileEntryHookStub::MaybeCallEntryHook(masm);
// PPC LINUX ABI:
// preserve LR in pre-reserved slot in caller's frame
__ mflr(r0);
__ StoreP(r0, MemOperand(sp, kStackFrameLRSlot * kPointerSize));
// Save callee saved registers on the stack.
__ MultiPush(kCalleeSaved);
// Floating point regs FPR0 - FRP13 are volatile
// FPR14-FPR31 are non-volatile, but sub-calls will save them for us
// int offset_to_argv = kPointerSize * 22; // matches (22*4) above
// __ lwz(r7, MemOperand(sp, offset_to_argv));
// Push a frame with special values setup to mark it as an entry frame.
// r3: code entry
// r4: function
// r5: receiver
// r6: argc
// r7: argv
__ li(r0, Operand(-1)); // Push a bad frame pointer to fail if it is used.
__ push(r0);
#if V8_OOL_CONSTANT_POOL
__ mov(kConstantPoolRegister,
Operand(isolate()->factory()->empty_constant_pool_array()));
__ push(kConstantPoolRegister);
#endif
int marker = type();
__ LoadSmiLiteral(r0, Smi::FromInt(marker));
__ push(r0);
__ push(r0);
// Save copies of the top frame descriptor on the stack.
__ mov(r8, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
__ LoadP(r0, MemOperand(r8));
__ push(r0);
// Set up frame pointer for the frame to be pushed.
__ addi(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
// If this is the outermost JS call, set js_entry_sp value.
Label non_outermost_js;
ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate());
__ mov(r8, Operand(ExternalReference(js_entry_sp)));
__ LoadP(r9, MemOperand(r8));
__ cmpi(r9, Operand::Zero());
__ bne(&non_outermost_js);
__ StoreP(fp, MemOperand(r8));
__ LoadSmiLiteral(ip, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
Label cont;
__ b(&cont);
__ bind(&non_outermost_js);
__ LoadSmiLiteral(ip, Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME));
__ bind(&cont);
__ push(ip); // frame-type
// Jump to a faked try block that does the invoke, with a faked catch
// block that sets the pending exception.
__ b(&invoke);
__ bind(&handler_entry);
handler_offset_ = handler_entry.pos();
// Caught exception: Store result (exception) in the pending exception
// field in the JSEnv and return a failure sentinel. Coming in here the
// fp will be invalid because the PushTryHandler below sets it to 0 to
// signal the existence of the JSEntry frame.
__ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
isolate())));
__ StoreP(r3, MemOperand(ip));
__ LoadRoot(r3, Heap::kExceptionRootIndex);
__ b(&exit);
// Invoke: Link this frame into the handler chain. There's only one
// handler block in this code object, so its index is 0.
__ bind(&invoke);
// Must preserve r0-r4, r5-r7 are available. (needs update for PPC)
__ PushTryHandler(StackHandler::JS_ENTRY, 0);
// If an exception not caught by another handler occurs, this handler
// returns control to the code after the b(&invoke) above, which
// restores all kCalleeSaved registers (including cp and fp) to their
// saved values before returning a failure to C.
// Clear any pending exceptions.
__ mov(r8, Operand(isolate()->factory()->the_hole_value()));
__ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
isolate())));
__ StoreP(r8, MemOperand(ip));
// Invoke the function by calling through JS entry trampoline builtin.
// Notice that we cannot store a reference to the trampoline code directly in
// this stub, because runtime stubs are not traversed when doing GC.
// Expected registers by Builtins::JSEntryTrampoline
// r3: code entry
// r4: function
// r5: receiver
// r6: argc
// r7: argv
if (type() == StackFrame::ENTRY_CONSTRUCT) {
ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
isolate());
__ mov(ip, Operand(construct_entry));
} else {
ExternalReference entry(Builtins::kJSEntryTrampoline, isolate());
__ mov(ip, Operand(entry));
}
__ LoadP(ip, MemOperand(ip)); // deref address
// Branch and link to JSEntryTrampoline.
// the address points to the start of the code object, skip the header
__ addi(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
__ mtctr(ip);
__ bctrl(); // make the call
// Unlink this frame from the handler chain.
__ PopTryHandler();
__ bind(&exit); // r3 holds result
// Check if the current stack frame is marked as the outermost JS frame.
Label non_outermost_js_2;
__ pop(r8);
__ CmpSmiLiteral(r8, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME), r0);
__ bne(&non_outermost_js_2);
__ mov(r9, Operand::Zero());
__ mov(r8, Operand(ExternalReference(js_entry_sp)));
__ StoreP(r9, MemOperand(r8));
__ bind(&non_outermost_js_2);
// Restore the top frame descriptors from the stack.
__ pop(r6);
__ mov(ip, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate())));
__ StoreP(r6, MemOperand(ip));
// Reset the stack to the callee saved registers.
__ addi(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
// Restore callee-saved registers and return.
#ifdef DEBUG
if (FLAG_debug_code) {
Label here;
__ b(&here, SetLK);
__ bind(&here);
}
#endif
__ MultiPop(kCalleeSaved);
__ LoadP(r0, MemOperand(sp, kStackFrameLRSlot * kPointerSize));
__ mtctr(r0);
__ bctr();
}
// Uses registers r3 to r7.
// Expected input (depending on whether args are in registers or on the stack):
// * object: r3 or at sp + 1 * kPointerSize.
// * function: r4 or at sp.
//
// An inlined call site may have been generated before calling this stub.
// In this case the offset to the inline site to patch is passed in r8.
// (See LCodeGen::DoInstanceOfKnownGlobal)
void InstanceofStub::Generate(MacroAssembler* masm) {
// Call site inlining and patching implies arguments in registers.
DCHECK(HasArgsInRegisters() || !HasCallSiteInlineCheck());
// Fixed register usage throughout the stub:
const Register object = r3; // Object (lhs).
Register map = r6; // Map of the object.
const Register function = r4; // Function (rhs).
const Register prototype = r7; // Prototype of the function.
const Register inline_site = r9;
const Register scratch = r5;
Register scratch3 = no_reg;
// delta = mov + unaligned LoadP + cmp + bne
#if V8_TARGET_ARCH_PPC64
const int32_t kDeltaToLoadBoolResult =
(Assembler::kMovInstructions + 4) * Assembler::kInstrSize;
#else
const int32_t kDeltaToLoadBoolResult =
(Assembler::kMovInstructions + 3) * Assembler::kInstrSize;
#endif
Label slow, loop, is_instance, is_not_instance, not_js_object;
if (!HasArgsInRegisters()) {
__ LoadP(object, MemOperand(sp, 1 * kPointerSize));
__ LoadP(function, MemOperand(sp, 0));
}
// Check that the left hand is a JS object and load map.
__ JumpIfSmi(object, &not_js_object);
__ IsObjectJSObjectType(object, map, scratch, &not_js_object);
// If there is a call site cache don't look in the global cache, but do the
// real lookup and update the call site cache.
if (!HasCallSiteInlineCheck() && !ReturnTrueFalseObject()) {
Label miss;
__ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
__ bne(&miss);
__ CompareRoot(map, Heap::kInstanceofCacheMapRootIndex);
__ bne(&miss);
__ LoadRoot(r3, Heap::kInstanceofCacheAnswerRootIndex);
__ Ret(HasArgsInRegisters() ? 0 : 2);
__ bind(&miss);
}
// Get the prototype of the function.
__ TryGetFunctionPrototype(function, prototype, scratch, &slow, true);
// Check that the function prototype is a JS object.
__ JumpIfSmi(prototype, &slow);
__ IsObjectJSObjectType(prototype, scratch, scratch, &slow);
// Update the global instanceof or call site inlined cache with the current
// map and function. The cached answer will be set when it is known below.
if (!HasCallSiteInlineCheck()) {
__ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
__ StoreRoot(map, Heap::kInstanceofCacheMapRootIndex);
} else {
DCHECK(HasArgsInRegisters());
// Patch the (relocated) inlined map check.
// The offset was stored in r8
// (See LCodeGen::DoDeferredLInstanceOfKnownGlobal).
const Register offset = r8;
__ mflr(inline_site);
__ sub(inline_site, inline_site, offset);
// Get the map location in r8 and patch it.
__ GetRelocatedValue(inline_site, offset, scratch);
__ StoreP(map, FieldMemOperand(offset, Cell::kValueOffset), r0);
}
// Register mapping: r6 is object map and r7 is function prototype.
// Get prototype of object into r5.
__ LoadP(scratch, FieldMemOperand(map, Map::kPrototypeOffset));
// We don't need map any more. Use it as a scratch register.
scratch3 = map;
map = no_reg;
// Loop through the prototype chain looking for the function prototype.
__ LoadRoot(scratch3, Heap::kNullValueRootIndex);
__ bind(&loop);
__ cmp(scratch, prototype);
__ beq(&is_instance);
__ cmp(scratch, scratch3);
__ beq(&is_not_instance);
__ LoadP(scratch, FieldMemOperand(scratch, HeapObject::kMapOffset));
__ LoadP(scratch, FieldMemOperand(scratch, Map::kPrototypeOffset));
__ b(&loop);
Factory* factory = isolate()->factory();
__ bind(&is_instance);
if (!HasCallSiteInlineCheck()) {
__ LoadSmiLiteral(r3, Smi::FromInt(0));
__ StoreRoot(r3, Heap::kInstanceofCacheAnswerRootIndex);
if (ReturnTrueFalseObject()) {
__ Move(r3, factory->true_value());
}
} else {
// Patch the call site to return true.
__ LoadRoot(r3, Heap::kTrueValueRootIndex);
__ addi(inline_site, inline_site, Operand(kDeltaToLoadBoolResult));
// Get the boolean result location in scratch and patch it.
__ SetRelocatedValue(inline_site, scratch, r3);
if (!ReturnTrueFalseObject()) {
__ LoadSmiLiteral(r3, Smi::FromInt(0));
}
}
__ Ret(HasArgsInRegisters() ? 0 : 2);
__ bind(&is_not_instance);
if (!HasCallSiteInlineCheck()) {
__ LoadSmiLiteral(r3, Smi::FromInt(1));
__ StoreRoot(r3, Heap::kInstanceofCacheAnswerRootIndex);
if (ReturnTrueFalseObject()) {
__ Move(r3, factory->false_value());
}
} else {
// Patch the call site to return false.
__ LoadRoot(r3, Heap::kFalseValueRootIndex);
__ addi(inline_site, inline_site, Operand(kDeltaToLoadBoolResult));
// Get the boolean result location in scratch and patch it.
__ SetRelocatedValue(inline_site, scratch, r3);
if (!ReturnTrueFalseObject()) {
__ LoadSmiLiteral(r3, Smi::FromInt(1));
}
}
__ Ret(HasArgsInRegisters() ? 0 : 2);
Label object_not_null, object_not_null_or_smi;
__ bind(&not_js_object);
// Before null, smi and string value checks, check that the rhs is a function
// as for a non-function rhs an exception needs to be thrown.
__ JumpIfSmi(function, &slow);
__ CompareObjectType(function, scratch3, scratch, JS_FUNCTION_TYPE);
__ bne(&slow);
// Null is not instance of anything.
__ Cmpi(object, Operand(isolate()->factory()->null_value()), r0);
__ bne(&object_not_null);
if (ReturnTrueFalseObject()) {
__ Move(r3, factory->false_value());
} else {
__ LoadSmiLiteral(r3, Smi::FromInt(1));
}
__ Ret(HasArgsInRegisters() ? 0 : 2);
__ bind(&object_not_null);
// Smi values are not instances of anything.
__ JumpIfNotSmi(object, &object_not_null_or_smi);
if (ReturnTrueFalseObject()) {
__ Move(r3, factory->false_value());
} else {
__ LoadSmiLiteral(r3, Smi::FromInt(1));
}
__ Ret(HasArgsInRegisters() ? 0 : 2);
__ bind(&object_not_null_or_smi);
// String values are not instances of anything.
__ IsObjectJSStringType(object, scratch, &slow);
if (ReturnTrueFalseObject()) {
__ Move(r3, factory->false_value());
} else {
__ LoadSmiLiteral(r3, Smi::FromInt(1));
}
__ Ret(HasArgsInRegisters() ? 0 : 2);
// Slow-case. Tail call builtin.
__ bind(&slow);
if (!ReturnTrueFalseObject()) {
if (HasArgsInRegisters()) {
__ Push(r3, r4);
}
__ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
} else {
{
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
__ Push(r3, r4);
__ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION);
}
Label true_value, done;
__ cmpi(r3, Operand::Zero());
__ beq(&true_value);
__ LoadRoot(r3, Heap::kFalseValueRootIndex);
__ b(&done);
__ bind(&true_value);
__ LoadRoot(r3, Heap::kTrueValueRootIndex);
__ bind(&done);
__ Ret(HasArgsInRegisters() ? 0 : 2);
}
}
void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
Label miss;
Register receiver = LoadDescriptor::ReceiverRegister();
NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r6,
r7, &miss);
__ bind(&miss);
PropertyAccessCompiler::TailCallBuiltin(
masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC));
}
void LoadIndexedStringStub::Generate(MacroAssembler* masm) {
// Return address is in lr.
Label miss;
Register receiver = LoadDescriptor::ReceiverRegister();
Register index = LoadDescriptor::NameRegister();
Register scratch = r6;
Register result = r3;
DCHECK(!scratch.is(receiver) && !scratch.is(index));
StringCharAtGenerator char_at_generator(receiver, index, scratch, result,
&miss, // When not a string.
&miss, // When not a number.
&miss, // When index out of range.
STRING_INDEX_IS_ARRAY_INDEX,
RECEIVER_IS_STRING);
char_at_generator.GenerateFast(masm);
__ Ret();
StubRuntimeCallHelper call_helper;
char_at_generator.GenerateSlow(masm, call_helper);
__ bind(&miss);
PropertyAccessCompiler::TailCallBuiltin(
masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
}
void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
// The displacement is the offset of the last parameter (if any)
// relative to the frame pointer.
const int kDisplacement =
StandardFrameConstants::kCallerSPOffset - kPointerSize;
DCHECK(r4.is(ArgumentsAccessReadDescriptor::index()));
DCHECK(r3.is(ArgumentsAccessReadDescriptor::parameter_count()));
// Check that the key is a smi.
Label slow;
__ JumpIfNotSmi(r4, &slow);
// Check if the calling frame is an arguments adaptor frame.
Label adaptor;
__ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
__ LoadP(r6, MemOperand(r5, StandardFrameConstants::kContextOffset));
STATIC_ASSERT(StackFrame::ARGUMENTS_ADAPTOR < 0x3fffu);
__ CmpSmiLiteral(r6, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
__ beq(&adaptor);
// Check index against formal parameters count limit passed in
// through register r3. Use unsigned comparison to get negative
// check for free.
__ cmpl(r4, r3);
__ bge(&slow);
// Read the argument from the stack and return it.
__ sub(r6, r3, r4);
__ SmiToPtrArrayOffset(r6, r6);
__ add(r6, fp, r6);
__ LoadP(r3, MemOperand(r6, kDisplacement));
__ blr();
// Arguments adaptor case: Check index against actual arguments
// limit found in the arguments adaptor frame. Use unsigned
// comparison to get negative check for free.
__ bind(&adaptor);
__ LoadP(r3, MemOperand(r5, ArgumentsAdaptorFrameConstants::kLengthOffset));
__ cmpl(r4, r3);
__ bge(&slow);
// Read the argument from the adaptor frame and return it.
__ sub(r6, r3, r4);
__ SmiToPtrArrayOffset(r6, r6);
__ add(r6, r5, r6);
__ LoadP(r3, MemOperand(r6, kDisplacement));
__ blr();
// Slow-case: Handle non-smi or out-of-bounds access to arguments
// by calling the runtime system.
__ bind(&slow);
__ push(r4);
__ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1);
}
void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) {
// sp[0] : number of parameters
// sp[1] : receiver displacement
// sp[2] : function
// Check if the calling frame is an arguments adaptor frame.
Label runtime;
__ LoadP(r6, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
__ LoadP(r5, MemOperand(r6, StandardFrameConstants::kContextOffset));
STATIC_ASSERT(StackFrame::ARGUMENTS_ADAPTOR < 0x3fffu);
__ CmpSmiLiteral(r5, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
__ bne(&runtime);
// Patch the arguments.length and the parameters pointer in the current frame.
__ LoadP(r5, MemOperand(r6, ArgumentsAdaptorFrameConstants::kLengthOffset));
__ StoreP(r5, MemOperand(sp, 0 * kPointerSize));
__ SmiToPtrArrayOffset(r5, r5);
__ add(r6, r6, r5);
__ addi(r6, r6, Operand(StandardFrameConstants::kCallerSPOffset));
__ StoreP(r6, MemOperand(sp, 1 * kPointerSize));
__ bind(&runtime);
__ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
}
void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
// Stack layout:
// sp[0] : number of parameters (tagged)
// sp[1] : address of receiver argument
// sp[2] : function
// Registers used over whole function:
// r9 : allocated object (tagged)
// r11 : mapped parameter count (tagged)
__ LoadP(r4, MemOperand(sp, 0 * kPointerSize));
// r4 = parameter count (tagged)
// Check if the calling frame is an arguments adaptor frame.
Label runtime;
Label adaptor_frame, try_allocate;
__ LoadP(r6, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
__ LoadP(r5, MemOperand(r6, StandardFrameConstants::kContextOffset));
STATIC_ASSERT(StackFrame::ARGUMENTS_ADAPTOR < 0x3fffu);
__ CmpSmiLiteral(r5, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
__ beq(&adaptor_frame);
// No adaptor, parameter count = argument count.
__ mr(r5, r4);
__ b(&try_allocate);
// We have an adaptor frame. Patch the parameters pointer.
__ bind(&adaptor_frame);
__ LoadP(r5, MemOperand(r6, ArgumentsAdaptorFrameConstants::kLengthOffset));
__ SmiToPtrArrayOffset(r7, r5);
__ add(r6, r6, r7);
__ addi(r6, r6, Operand(StandardFrameConstants::kCallerSPOffset));
__ StoreP(r6, MemOperand(sp, 1 * kPointerSize));
// r4 = parameter count (tagged)
// r5 = argument count (tagged)
// Compute the mapped parameter count = min(r4, r5) in r4.
Label skip;
__ cmp(r4, r5);
__ blt(&skip);
__ mr(r4, r5);
__ bind(&skip);
__ bind(&try_allocate);
// Compute the sizes of backing store, parameter map, and arguments object.
// 1. Parameter map, has 2 extra words containing context and backing store.
const int kParameterMapHeaderSize =
FixedArray::kHeaderSize + 2 * kPointerSize;
// If there are no mapped parameters, we do not need the parameter_map.
Label skip2, skip3;
__ CmpSmiLiteral(r4, Smi::FromInt(0), r0);
__ bne(&skip2);
__ li(r11, Operand::Zero());
__ b(&skip3);
__ bind(&skip2);
__ SmiToPtrArrayOffset(r11, r4);
__ addi(r11, r11, Operand(kParameterMapHeaderSize));
__ bind(&skip3);
// 2. Backing store.
__ SmiToPtrArrayOffset(r7, r5);
__ add(r11, r11, r7);
__ addi(r11, r11, Operand(FixedArray::kHeaderSize));
// 3. Arguments object.
__ addi(r11, r11, Operand(Heap::kSloppyArgumentsObjectSize));
// Do the allocation of all three objects in one go.
__ Allocate(r11, r3, r6, r7, &runtime, TAG_OBJECT);
// r3 = address of new object(s) (tagged)
// r5 = argument count (smi-tagged)
// Get the arguments boilerplate from the current native context into r4.
const int kNormalOffset =
Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX);
const int kAliasedOffset =
Context::SlotOffset(Context::ALIASED_ARGUMENTS_MAP_INDEX);
__ LoadP(r7,
MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
__ LoadP(r7, FieldMemOperand(r7, GlobalObject::kNativeContextOffset));
Label skip4, skip5;
__ cmpi(r4, Operand::Zero());
__ bne(&skip4);
__ LoadP(r7, MemOperand(r7, kNormalOffset));
__ b(&skip5);
__ bind(&skip4);
__ LoadP(r7, MemOperand(r7, kAliasedOffset));
__ bind(&skip5);
// r3 = address of new object (tagged)
// r4 = mapped parameter count (tagged)
// r5 = argument count (smi-tagged)
// r7 = address of arguments map (tagged)
__ StoreP(r7, FieldMemOperand(r3, JSObject::kMapOffset), r0);
__ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex);
__ StoreP(r6, FieldMemOperand(r3, JSObject::kPropertiesOffset), r0);
__ StoreP(r6, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
// Set up the callee in-object property.
STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
__ LoadP(r6, MemOperand(sp, 2 * kPointerSize));
__ AssertNotSmi(r6);
const int kCalleeOffset =
JSObject::kHeaderSize + Heap::kArgumentsCalleeIndex * kPointerSize;
__ StoreP(r6, FieldMemOperand(r3, kCalleeOffset), r0);
// Use the length (smi tagged) and set that as an in-object property too.
__ AssertSmi(r5);
STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
const int kLengthOffset =
JSObject::kHeaderSize + Heap::kArgumentsLengthIndex * kPointerSize;
__ StoreP(r5, FieldMemOperand(r3, kLengthOffset), r0);
// Set up the elements pointer in the allocated arguments object.
// If we allocated a parameter map, r7 will point there, otherwise
// it will point to the backing store.
__ addi(r7, r3, Operand(Heap::kSloppyArgumentsObjectSize));
__ StoreP(r7, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
// r3 = address of new object (tagged)
// r4 = mapped parameter count (tagged)
// r5 = argument count (tagged)
// r7 = address of parameter map or backing store (tagged)
// Initialize parameter map. If there are no mapped arguments, we're done.
Label skip_parameter_map, skip6;
__ CmpSmiLiteral(r4, Smi::FromInt(0), r0);
__ bne(&skip6);
// Move backing store address to r6, because it is
// expected there when filling in the unmapped arguments.
__ mr(r6, r7);
__ b(&skip_parameter_map);
__ bind(&skip6);
__ LoadRoot(r9, Heap::kSloppyArgumentsElementsMapRootIndex);
__ StoreP(r9, FieldMemOperand(r7, FixedArray::kMapOffset), r0);
__ AddSmiLiteral(r9, r4, Smi::FromInt(2), r0);
__ StoreP(r9, FieldMemOperand(r7, FixedArray::kLengthOffset), r0);
__ StoreP(cp, FieldMemOperand(r7, FixedArray::kHeaderSize + 0 * kPointerSize),
r0);
__ SmiToPtrArrayOffset(r9, r4);
__ add(r9, r7, r9);
__ addi(r9, r9, Operand(kParameterMapHeaderSize));
__ StoreP(r9, FieldMemOperand(r7, FixedArray::kHeaderSize + 1 * kPointerSize),
r0);
// Copy the parameter slots and the holes in the arguments.
// We need to fill in mapped_parameter_count slots. They index the context,
// where parameters are stored in reverse order, at
// MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
// The mapped parameter thus need to get indices
// MIN_CONTEXT_SLOTS+parameter_count-1 ..
// MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
// We loop from right to left.
Label parameters_loop, parameters_test;
__ mr(r9, r4);
__ LoadP(r11, MemOperand(sp, 0 * kPointerSize));
__ AddSmiLiteral(r11, r11, Smi::FromInt(Context::MIN_CONTEXT_SLOTS), r0);
__ sub(r11, r11, r4);
__ LoadRoot(r10, Heap::kTheHoleValueRootIndex);
__ SmiToPtrArrayOffset(r6, r9);
__ add(r6, r7, r6);
__ addi(r6, r6, Operand(kParameterMapHeaderSize));
// r9 = loop variable (tagged)
// r4 = mapping index (tagged)
// r6 = address of backing store (tagged)
// r7 = address of parameter map (tagged)
// r8 = temporary scratch (a.o., for address calculation)
// r10 = the hole value
__ b(&parameters_test);
__ bind(&parameters_loop);
__ SubSmiLiteral(r9, r9, Smi::FromInt(1), r0);
__ SmiToPtrArrayOffset(r8, r9);
__ addi(r8, r8, Operand(kParameterMapHeaderSize - kHeapObjectTag));
__ StorePX(r11, MemOperand(r8, r7));
__ subi(r8, r8, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
__ StorePX(r10, MemOperand(r8, r6));
__ AddSmiLiteral(r11, r11, Smi::FromInt(1), r0);
__ bind(&parameters_test);
__ CmpSmiLiteral(r9, Smi::FromInt(0), r0);
__ bne(&parameters_loop);
__ bind(&skip_parameter_map);
// r5 = argument count (tagged)
// r6 = address of backing store (tagged)
// r8 = scratch
// Copy arguments header and remaining slots (if there are any).
__ LoadRoot(r8, Heap::kFixedArrayMapRootIndex);
__ StoreP(r8, FieldMemOperand(r6, FixedArray::kMapOffset), r0);
__ StoreP(r5, FieldMemOperand(r6, FixedArray::kLengthOffset), r0);
Label arguments_loop, arguments_test;
__ mr(r11, r4);
__ LoadP(r7, MemOperand(sp, 1 * kPointerSize));
__ SmiToPtrArrayOffset(r8, r11);
__ sub(r7, r7, r8);
__ b(&arguments_test);
__ bind(&arguments_loop);
__ subi(r7, r7, Operand(kPointerSize));
__ LoadP(r9, MemOperand(r7, 0));
__ SmiToPtrArrayOffset(r8, r11);
__ add(r8, r6, r8);
__ StoreP(r9, FieldMemOperand(r8, FixedArray::kHeaderSize), r0);
__ AddSmiLiteral(r11, r11, Smi::FromInt(1), r0);
__ bind(&arguments_test);
__ cmp(r11, r5);
__ blt(&arguments_loop);
// Return and remove the on-stack parameters.
__ addi(sp, sp, Operand(3 * kPointerSize));
__ Ret();
// Do the runtime call to allocate the arguments object.
// r5 = argument count (tagged)
__ bind(&runtime);
__ StoreP(r5, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
__ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1);
}
void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) {
// Return address is in lr.
Label slow;
Register receiver = LoadDescriptor::ReceiverRegister();
Register key = LoadDescriptor::NameRegister();
// Check that the key is an array index, that is Uint32.
__ TestIfPositiveSmi(key, r0);
__ bne(&slow, cr0);
// Everything is fine, call runtime.
__ Push(receiver, key); // Receiver, key.
// Perform tail call to the entry.
__ TailCallExternalReference(
ExternalReference(IC_Utility(IC::kLoadElementWithInterceptor),
masm->isolate()),
2, 1);
__ bind(&slow);
PropertyAccessCompiler::TailCallBuiltin(
masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC));
}
void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
// sp[0] : number of parameters
// sp[4] : receiver displacement
// sp[8] : function
// Check if the calling frame is an arguments adaptor frame.
Label adaptor_frame, try_allocate, runtime;
__ LoadP(r5, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
__ LoadP(r6, MemOperand(r5, StandardFrameConstants::kContextOffset));
STATIC_ASSERT(StackFrame::ARGUMENTS_ADAPTOR < 0x3fffu);
__ CmpSmiLiteral(r6, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0);
__ beq(&adaptor_frame);
// Get the length from the frame.
__ LoadP(r4, MemOperand(sp, 0));
__ b(&try_allocate);
// Patch the arguments.length and the parameters pointer.
__ bind(&adaptor_frame);
__ LoadP(r4, MemOperand(r5, ArgumentsAdaptorFrameConstants::kLengthOffset));
__ StoreP(r4, MemOperand(sp, 0));
__ SmiToPtrArrayOffset(r6, r4);
__ add(r6, r5, r6);
__ addi(r6, r6, Operand(StandardFrameConstants::kCallerSPOffset));
__ StoreP(r6, MemOperand(sp, 1 * kPointerSize));
// Try the new space allocation. Start out with computing the size
// of the arguments object and the elements array in words.
Label add_arguments_object;
__ bind(&try_allocate);
__ cmpi(r4, Operand::Zero());
__ beq(&add_arguments_object);
__ SmiUntag(r4);
__ addi(r4, r4, Operand(FixedArray::kHeaderSize / kPointerSize));
__ bind(&add_arguments_object);
__ addi(r4, r4, Operand(Heap::kStrictArgumentsObjectSize / kPointerSize));
// Do the allocation of both objects in one go.
__ Allocate(r4, r3, r5, r6, &runtime,
static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
// Get the arguments boilerplate from the current native context.
__ LoadP(r7,
MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
__ LoadP(r7, FieldMemOperand(r7, GlobalObject::kNativeContextOffset));
__ LoadP(
r7,
MemOperand(r7, Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX)));
__ StoreP(r7, FieldMemOperand(r3, JSObject::kMapOffset), r0);
__ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex);
__ StoreP(r6, FieldMemOperand(r3, JSObject::kPropertiesOffset), r0);
__ StoreP(r6, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
// Get the length (smi tagged) and set that as an in-object property too.
STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
__ LoadP(r4, MemOperand(sp, 0 * kPointerSize));
__ AssertSmi(r4);
__ StoreP(r4,
FieldMemOperand(r3, JSObject::kHeaderSize +
Heap::kArgumentsLengthIndex * kPointerSize),
r0);
// If there are no actual arguments, we're done.
Label done;
__ cmpi(r4, Operand::Zero());
__ beq(&done);
// Get the parameters pointer from the stack.
__ LoadP(r5, MemOperand(sp, 1 * kPointerSize));
// Set up the elements pointer in the allocated arguments object and
// initialize the header in the elements fixed array.
__ addi(r7, r3, Operand(Heap::kStrictArgumentsObjectSize));
__ StoreP(r7, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
__ LoadRoot(r6, Heap::kFixedArrayMapRootIndex);
__ StoreP(r6, FieldMemOperand(r7, FixedArray::kMapOffset), r0);
__ StoreP(r4, FieldMemOperand(r7, FixedArray::kLengthOffset), r0);
// Untag the length for the loop.
__ SmiUntag(r4);
// Copy the fixed array slots.
Label loop;
// Set up r7 to point just prior to the first array slot.
__ addi(r7, r7,
Operand(FixedArray::kHeaderSize - kHeapObjectTag - kPointerSize));
__ mtctr(r4);
__ bind(&loop);
// Pre-decrement r5 with kPointerSize on each iteration.
// Pre-decrement in order to skip receiver.
__ LoadPU(r6, MemOperand(r5, -kPointerSize));
// Pre-increment r7 with kPointerSize on each iteration.
__ StorePU(r6, MemOperand(r7, kPointerSize));
__ bdnz(&loop);
// Return and remove the on-stack parameters.
__ bind(&done);
__ addi(sp, sp, Operand(3 * kPointerSize));
__ Ret();
// Do the runtime call to allocate the arguments object.
__ bind(&runtime);
__ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1);
}
void RegExpExecStub::Generate(MacroAssembler* masm) {
// Just jump directly to runtime if native RegExp is not selected at compile
// time or if regexp entry in generated code is turned off runtime switch or
// at compilation.
#ifdef V8_INTERPRETED_REGEXP
__ TailCallRuntime(Runtime::kRegExpExecRT, 4, 1);
#else // V8_INTERPRETED_REGEXP
// Stack frame on entry.
// sp[0]: last_match_info (expected JSArray)
// sp[4]: previous index
// sp[8]: subject string
// sp[12]: JSRegExp object
const int kLastMatchInfoOffset = 0 * kPointerSize;
const int kPreviousIndexOffset = 1 * kPointerSize;
const int kSubjectOffset = 2 * kPointerSize;
const int kJSRegExpOffset = 3 * kPointerSize;
Label runtime, br_over, encoding_type_UC16;
// Allocation of registers for this function. These are in callee save
// registers and will be preserved by the call to the native RegExp code, as
// this code is called using the normal C calling convention. When calling
// directly from generated code the native RegExp code will not do a GC and
// therefore the content of these registers are safe to use after the call.
Register subject = r14;
Register regexp_data = r15;
Register last_match_info_elements = r16;
Register code = r17;
// Ensure register assigments are consistent with callee save masks
DCHECK(subject.bit() & kCalleeSaved);
DCHECK(regexp_data.bit() & kCalleeSaved);
DCHECK(last_match_info_elements.bit() & kCalleeSaved);
DCHECK(code.bit() & kCalleeSaved);
// Ensure that a RegExp stack is allocated.
ExternalReference address_of_regexp_stack_memory_address =
ExternalReference::address_of_regexp_stack_memory_address(isolate());
ExternalReference address_of_regexp_stack_memory_size =
ExternalReference::address_of_regexp_stack_memory_size(isolate());
__ mov(r3, Operand(address_of_regexp_stack_memory_size));
__ LoadP(r3, MemOperand(r3, 0));
__ cmpi(r3, Operand::Zero());
__ beq(&runtime);
// Check that the first argument is a JSRegExp object.
__ LoadP(r3, MemOperand(sp, kJSRegExpOffset));
__ JumpIfSmi(r3, &runtime);
__ CompareObjectType(r3, r4, r4, JS_REGEXP_TYPE);
__ bne(&runtime);
// Check that the RegExp has been compiled (data contains a fixed array).
__ LoadP(regexp_data, FieldMemOperand(r3, JSRegExp::kDataOffset));
if (FLAG_debug_code) {
__ TestIfSmi(regexp_data, r0);
__ Check(ne, kUnexpectedTypeForRegExpDataFixedArrayExpected, cr0);
__ CompareObjectType(regexp_data, r3, r3, FIXED_ARRAY_TYPE);
__ Check(eq, kUnexpectedTypeForRegExpDataFixedArrayExpected);
}
// regexp_data: RegExp data (FixedArray)
// Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
__ LoadP(r3, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
// DCHECK(Smi::FromInt(JSRegExp::IRREGEXP) < (char *)0xffffu);
__ CmpSmiLiteral(r3, Smi::FromInt(JSRegExp::IRREGEXP), r0);
__ bne(&runtime);
// regexp_data: RegExp data (FixedArray)
// Check that the number of captures fit in the static offsets vector buffer.
__ LoadP(r5,
FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
// Check (number_of_captures + 1) * 2 <= offsets vector size
// Or number_of_captures * 2 <= offsets vector size - 2
// SmiToShortArrayOffset accomplishes the multiplication by 2 and
// SmiUntag (which is a nop for 32-bit).
__ SmiToShortArrayOffset(r5, r5);
STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
__ cmpli(r5, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
__ bgt(&runtime);
// Reset offset for possibly sliced string.
__ li(r11, Operand::Zero());
__ LoadP(subject, MemOperand(sp, kSubjectOffset));
__ JumpIfSmi(subject, &runtime);
__ mr(r6, subject); // Make a copy of the original subject string.
__ LoadP(r3, FieldMemOperand(subject, HeapObject::kMapOffset));
__ lbz(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
// subject: subject string
// r6: subject string
// r3: subject string instance type
// regexp_data: RegExp data (FixedArray)
// Handle subject string according to its encoding and representation:
// (1) Sequential string? If yes, go to (5).
// (2) Anything but sequential or cons? If yes, go to (6).
// (3) Cons string. If the string is flat, replace subject with first string.
// Otherwise bailout.
// (4) Is subject external? If yes, go to (7).
// (5) Sequential string. Load regexp code according to encoding.
// (E) Carry on.
/// [...]
// Deferred code at the end of the stub:
// (6) Not a long external string? If yes, go to (8).
// (7) External string. Make it, offset-wise, look like a sequential string.
// Go to (5).
// (8) Short external string or not a string? If yes, bail out to runtime.
// (9) Sliced string. Replace subject with parent. Go to (4).
Label seq_string /* 5 */, external_string /* 7 */, check_underlying /* 4 */,
not_seq_nor_cons /* 6 */, not_long_external /* 8 */;
// (1) Sequential string? If yes, go to (5).
STATIC_ASSERT((kIsNotStringMask | kStringRepresentationMask |
kShortExternalStringMask) == 0x93);
__ andi(r4, r3, Operand(kIsNotStringMask | kStringRepresentationMask |
kShortExternalStringMask));
STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
__ beq(&seq_string, cr0); // Go to (5).
// (2) Anything but sequential or cons? If yes, go to (6).
STATIC_ASSERT(kConsStringTag < kExternalStringTag);
STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
STATIC_ASSERT(kExternalStringTag < 0xffffu);
__ cmpi(r4, Operand(kExternalStringTag));
__ bge(&not_seq_nor_cons); // Go to (6).
// (3) Cons string. Check that it's flat.
// Replace subject with first string and reload instance type.
__ LoadP(r3, FieldMemOperand(subject, ConsString::kSecondOffset));
__ CompareRoot(r3, Heap::kempty_stringRootIndex);
__ bne(&runtime);
__ LoadP(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
// (4) Is subject external? If yes, go to (7).
__ bind(&check_underlying);
__ LoadP(r3, FieldMemOperand(subject, HeapObject::kMapOffset));
__ lbz(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
STATIC_ASSERT(kSeqStringTag == 0);
STATIC_ASSERT(kStringRepresentationMask == 3);
__ andi(r0, r3, Operand(kStringRepresentationMask));
// The underlying external string is never a short external string.
STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength);
STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength);
__ bne(&external_string, cr0); // Go to (7).
// (5) Sequential string. Load regexp code according to encoding.
__ bind(&seq_string);
// subject: sequential subject string (or look-alike, external string)
// r6: original subject string
// Load previous index and check range before r6 is overwritten. We have to
// use r6 instead of subject here because subject might have been only made
// to look like a sequential string when it actually is an external string.
__ LoadP(r4, MemOperand(sp, kPreviousIndexOffset));
__ JumpIfNotSmi(r4, &runtime);
__ LoadP(r6, FieldMemOperand(r6, String::kLengthOffset));
__ cmpl(r6, r4);
__ ble(&runtime);
__ SmiUntag(r4);
STATIC_ASSERT(4 == kOneByteStringTag);
STATIC_ASSERT(kTwoByteStringTag == 0);
STATIC_ASSERT(kStringEncodingMask == 4);
__ ExtractBitMask(r6, r3, kStringEncodingMask, SetRC);
__ beq(&encoding_type_UC16, cr0);
__ LoadP(code,
FieldMemOperand(regexp_data, JSRegExp::kDataOneByteCodeOffset));
__ b(&br_over);
__ bind(&encoding_type_UC16);
__ LoadP(code, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset));
__ bind(&br_over);
// (E) Carry on. String handling is done.
// code: irregexp code
// Check that the irregexp code has been generated for the actual string
// encoding. If it has, the field contains a code object otherwise it contains
// a smi (code flushing support).
__ JumpIfSmi(code, &runtime);
// r4: previous index
// r6: encoding of subject string (1 if one_byte, 0 if two_byte);
// code: Address of generated regexp code
// subject: Subject string
// regexp_data: RegExp data (FixedArray)
// All checks done. Now push arguments for native regexp code.
__ IncrementCounter(isolate()->counters()->regexp_entry_native(), 1, r3, r5);
// Isolates: note we add an additional parameter here (isolate pointer).
const int kRegExpExecuteArguments = 10;
const int kParameterRegisters = 8;
__ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters);
// Stack pointer now points to cell where return address is to be written.
// Arguments are before that on the stack or in registers.
// Argument 10 (in stack parameter area): Pass current isolate address.
__ mov(r3, Operand(ExternalReference::isolate_address(isolate())));
__ StoreP(r3, MemOperand(sp, (kStackFrameExtraParamSlot + 1) * kPointerSize));
// Argument 9 is a dummy that reserves the space used for
// the return address added by the ExitFrame in native calls.
// Argument 8 (r10): Indicate that this is a direct call from JavaScript.
__ li(r10, Operand(1));
// Argument 7 (r9): Start (high end) of backtracking stack memory area.
__ mov(r3, Operand(address_of_regexp_stack_memory_address));
__ LoadP(r3, MemOperand(r3, 0));
__ mov(r5, Operand(address_of_regexp_stack_memory_size));
__ LoadP(r5, MemOperand(r5, 0));
__ add(r9, r3, r5);
// Argument 6 (r8): Set the number of capture registers to zero to force
// global egexps to behave as non-global. This does not affect non-global
// regexps.
__ li(r8, Operand::Zero());
// Argument 5 (r7): static offsets vector buffer.
__ mov(
r7,
Operand(ExternalReference::address_of_static_offsets_vector(isolate())));
// For arguments 4 (r6) and 3 (r5) get string length, calculate start of data
// and calculate the shift of the index (0 for one-byte and 1 for two-byte).
__ addi(r18, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
__ xori(r6, r6, Operand(1));
// Load the length from the original subject string from the previous stack
// frame. Therefore we have to use fp, which points exactly to two pointer
// sizes below the previous sp. (Because creating a new stack frame pushes
// the previous fp onto the stack and moves up sp by 2 * kPointerSize.)
__ LoadP(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
// If slice offset is not 0, load the length from the original sliced string.
// Argument 4, r6: End of string data
// Argument 3, r5: Start of string data
// Prepare start and end index of the input.
__ ShiftLeft_(r11, r11, r6);
__ add(r11, r18, r11);
__ ShiftLeft_(r5, r4, r6);
__ add(r5, r11, r5);
__ LoadP(r18, FieldMemOperand(subject, String::kLengthOffset));
__ SmiUntag(r18);
__ ShiftLeft_(r6, r18, r6);
__ add(r6, r11, r6);
// Argument 2 (r4): Previous index.
// Already there
// Argument 1 (r3): Subject string.
__ mr(r3, subject);
// Locate the code entry and call it.
__ addi(code, code, Operand(Code::kHeaderSize - kHeapObjectTag));
#if ABI_USES_FUNCTION_DESCRIPTORS && defined(USE_SIMULATOR)
// Even Simulated AIX/PPC64 Linux uses a function descriptor for the
// RegExp routine. Extract the instruction address here since
// DirectCEntryStub::GenerateCall will not do it for calls out to
// what it thinks is C code compiled for the simulator/host
// platform.
__ LoadP(code, MemOperand(code, 0)); // Instruction address
#endif
DirectCEntryStub stub(isolate());
stub.GenerateCall(masm, code);
__ LeaveExitFrame(false, no_reg, true);
// r3: result
// subject: subject string (callee saved)
// regexp_data: RegExp data (callee saved)
// last_match_info_elements: Last match info elements (callee saved)
// Check the result.
Label success;
__ cmpi(r3, Operand(1));
// We expect exactly one result since we force the called regexp to behave
// as non-global.
__ beq(&success);
Label failure;
__ cmpi(r3, Operand(NativeRegExpMacroAssembler::FAILURE));
__ beq(&failure);
__ cmpi(r3, Operand(NativeRegExpMacroAssembler::EXCEPTION));
// If not exception it can only be retry. Handle that in the runtime system.
__ bne(&runtime);
// Result must now be exception. If there is no pending exception already a
// stack overflow (on the backtrack stack) was detected in RegExp code but
// haven't created the exception yet. Handle that in the runtime system.
// TODO(592): Rerunning the RegExp to get the stack overflow exception.
__ mov(r4, Operand(isolate()->factory()->the_hole_value()));
__ mov(r5, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
isolate())));
__ LoadP(r3, MemOperand(r5, 0));
__ cmp(r3, r4);
__ beq(&runtime);
__ StoreP(r4, MemOperand(r5, 0)); // Clear pending exception.
// Check if the exception is a termination. If so, throw as uncatchable.
__ CompareRoot(r3, Heap::kTerminationExceptionRootIndex);
Label termination_exception;
__ beq(&termination_exception);
__ Throw(r3);
__ bind(&termination_exception);
__ ThrowUncatchable(r3);
__ bind(&failure);
// For failure and exception return null.
__ mov(r3, Operand(isolate()->factory()->null_value()));
__ addi(sp, sp, Operand(4 * kPointerSize));
__ Ret();
// Process the result from the native regexp code.
__ bind(&success);
__ LoadP(r4,
FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
// Calculate number of capture registers (number_of_captures + 1) * 2.
// SmiToShortArrayOffset accomplishes the multiplication by 2 and
// SmiUntag (which is a nop for 32-bit).
__ SmiToShortArrayOffset(r4, r4);
__ addi(r4, r4, Operand(2));
__ LoadP(r3, MemOperand(sp, kLastMatchInfoOffset));
__ JumpIfSmi(r3, &runtime);
__ CompareObjectType(r3, r5, r5, JS_ARRAY_TYPE);
__ bne(&runtime);
// Check that the JSArray is in fast case.
__ LoadP(last_match_info_elements,
FieldMemOperand(r3, JSArray::kElementsOffset));
__ LoadP(r3,
FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
__ CompareRoot(r3, Heap::kFixedArrayMapRootIndex);
__ bne(&runtime);
// Check that the last match info has space for the capture registers and the
// additional information.
__ LoadP(
r3, FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
__ addi(r5, r4, Operand(RegExpImpl::kLastMatchOverhead));
__ SmiUntag(r0, r3);
__ cmp(r5, r0);
__ bgt(&runtime);
// r4: number of capture registers
// subject: subject string
// Store the capture count.
__ SmiTag(r5, r4);
__ StoreP(r5, FieldMemOperand(last_match_info_elements,
RegExpImpl::kLastCaptureCountOffset),
r0);
// Store last subject and last input.
__ StoreP(subject, FieldMemOperand(last_match_info_elements,
RegExpImpl::kLastSubjectOffset),
r0);
__ mr(r5, subject);
__ RecordWriteField(last_match_info_elements, RegExpImpl::kLastSubjectOffset,
subject, r10, kLRHasNotBeenSaved, kDontSaveFPRegs);
__ mr(subject, r5);
__ StoreP(subject, FieldMemOperand(last_match_info_elements,
RegExpImpl::kLastInputOffset),
r0);
__ RecordWriteField(last_match_info_elements, RegExpImpl::kLastInputOffset,
subject, r10, kLRHasNotBeenSaved, kDontSaveFPRegs);
// Get the static offsets vector filled by the native regexp code.
ExternalReference address_of_static_offsets_vector =
ExternalReference::address_of_static_offsets_vector(isolate());
__ mov(r5, Operand(address_of_static_offsets_vector));
// r4: number of capture registers
// r5: offsets vector
Label next_capture;
// Capture register counter starts from number of capture registers and
// counts down until wraping after zero.
__ addi(
r3, last_match_info_elements,
Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag - kPointerSize));
__ addi(r5, r5, Operand(-kIntSize)); // bias down for lwzu
__ mtctr(r4);
__ bind(&next_capture);
// Read the value from the static offsets vector buffer.
__ lwzu(r6, MemOperand(r5, kIntSize));
// Store the smi value in the last match info.
__ SmiTag(r6);
__ StorePU(r6, MemOperand(r3, kPointerSize));
__ bdnz(&next_capture);
// Return last match info.
__ LoadP(r3, MemOperand(sp, kLastMatchInfoOffset));
__ addi(sp, sp, Operand(4 * kPointerSize));
__ Ret();
// Do the runtime call to execute the regexp.
__ bind(&runtime);
__ TailCallRuntime(Runtime::kRegExpExecRT, 4, 1);
// Deferred code for string handling.
// (6) Not a long external string? If yes, go to (8).
__ bind(&not_seq_nor_cons);
// Compare flags are still set.
__ bgt(&not_long_external); // Go to (8).
// (7) External string. Make it, offset-wise, look like a sequential string.
__ bind(&external_string);
__ LoadP(r3, FieldMemOperand(subject, HeapObject::kMapOffset));
__ lbz(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
if (FLAG_debug_code) {
// Assert that we do not have a cons or slice (indirect strings) here.
// Sequential strings have already been ruled out.
STATIC_ASSERT(kIsIndirectStringMask == 1);
__ andi(r0, r3, Operand(kIsIndirectStringMask));
__ Assert(eq, kExternalStringExpectedButNotFound, cr0);
}
__ LoadP(subject,
FieldMemOperand(subject, ExternalString::kResourceDataOffset));
// Move the pointer so that offset-wise, it looks like a sequential string.
STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
__ subi(subject, subject,
Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
__ b(&seq_string); // Go to (5).
// (8) Short external string or not a string? If yes, bail out to runtime.
__ bind(&not_long_external);
STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag != 0);
__ andi(r0, r4, Operand(kIsNotStringMask | kShortExternalStringMask));
__ bne(&runtime, cr0);
// (9) Sliced string. Replace subject with parent. Go to (4).
// Load offset into r11 and replace subject string with parent.
__ LoadP(r11, FieldMemOperand(subject, SlicedString::kOffsetOffset));
__ SmiUntag(r11);
__ LoadP(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
__ b(&check_underlying); // Go to (4).
#endif // V8_INTERPRETED_REGEXP
}
static void GenerateRecordCallTarget(MacroAssembler* masm) {
// Cache the called function in a feedback vector slot. Cache states
// are uninitialized, monomorphic (indicated by a JSFunction), and
// megamorphic.
// r3 : number of arguments to the construct function
// r4 : the function to call
// r5 : Feedback vector
// r6 : slot in feedback vector (Smi)
Label initialize, done, miss, megamorphic, not_array_function;
DCHECK_EQ(*TypeFeedbackVector::MegamorphicSentinel(masm->isolate()),
masm->isolate()->heap()->megamorphic_symbol());
DCHECK_EQ(*TypeFeedbackVector::UninitializedSentinel(masm->isolate()),
masm->isolate()->heap()->uninitialized_symbol());
// Load the cache state into r7.
__ SmiToPtrArrayOffset(r7, r6);
__ add(r7, r5, r7);
__ LoadP(r7, FieldMemOperand(r7, FixedArray::kHeaderSize));
// A monomorphic cache hit or an already megamorphic state: invoke the
// function without changing the state.
__ cmp(r7, r4);
__ b(eq, &done);
if (!FLAG_pretenuring_call_new) {
// If we came here, we need to see if we are the array function.
// If we didn't have a matching function, and we didn't find the megamorph
// sentinel, then we have in the slot either some other function or an
// AllocationSite. Do a map check on the object in ecx.
__ LoadP(r8, FieldMemOperand(r7, 0));
__ CompareRoot(r8, Heap::kAllocationSiteMapRootIndex);
__ bne(&miss);
// Make sure the function is the Array() function
__ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r7);
__ cmp(r4, r7);
__ bne(&megamorphic);
__ b(&done);
}
__ bind(&miss);
// A monomorphic miss (i.e, here the cache is not uninitialized) goes
// megamorphic.
__ CompareRoot(r7, Heap::kuninitialized_symbolRootIndex);
__ beq(&initialize);
// MegamorphicSentinel is an immortal immovable object (undefined) so no
// write-barrier is needed.
__ bind(&megamorphic);
__ SmiToPtrArrayOffset(r7, r6);
__ add(r7, r5, r7);
__ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
__ StoreP(ip, FieldMemOperand(r7, FixedArray::kHeaderSize), r0);
__ jmp(&done);
// An uninitialized cache is patched with the function
__ bind(&initialize);
if (!FLAG_pretenuring_call_new) {
// Make sure the function is the Array() function.
__ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r7);
__ cmp(r4, r7);
__ bne(&not_array_function);
// The target function is the Array constructor,
// Create an AllocationSite if we don't already have it, store it in the
// slot.
{
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
// Arguments register must be smi-tagged to call out.
__ SmiTag(r3);
__ Push(r6, r5, r4, r3);
CreateAllocationSiteStub create_stub(masm->isolate());
__ CallStub(&create_stub);
__ Pop(r6, r5, r4, r3);
__ SmiUntag(r3);
}
__ b(&done);
__ bind(&not_array_function);
}
__ SmiToPtrArrayOffset(r7, r6);
__ add(r7, r5, r7);
__ addi(r7, r7, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
__ StoreP(r4, MemOperand(r7, 0));
__ Push(r7, r5, r4);
__ RecordWrite(r5, r7, r4, kLRHasNotBeenSaved, kDontSaveFPRegs,
EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
__ Pop(r7, r5, r4);
__ bind(&done);
}
static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
// Do not transform the receiver for strict mode functions and natives.
__ LoadP(r6, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
__ lwz(r7, FieldMemOperand(r6, SharedFunctionInfo::kCompilerHintsOffset));
__ TestBit(r7,
#if V8_TARGET_ARCH_PPC64
SharedFunctionInfo::kStrictModeFunction,
#else
SharedFunctionInfo::kStrictModeFunction + kSmiTagSize,
#endif
r0);
__ bne(cont, cr0);
// Do not transform the receiver for native.
__ TestBit(r7,
#if V8_TARGET_ARCH_PPC64
SharedFunctionInfo::kNative,
#else
SharedFunctionInfo::kNative + kSmiTagSize,
#endif
r0);
__ bne(cont, cr0);
}
static void EmitSlowCase(MacroAssembler* masm, int argc, Label* non_function) {
// Check for function proxy.
STATIC_ASSERT(JS_FUNCTION_PROXY_TYPE < 0xffffu);
__ cmpi(r7, Operand(JS_FUNCTION_PROXY_TYPE));
__ bne(non_function);
__ push(r4); // put proxy as additional argument
__ li(r3, Operand(argc + 1));
__ li(r5, Operand::Zero());
__ GetBuiltinFunction(r4, Builtins::CALL_FUNCTION_PROXY);
{
Handle<Code> adaptor =
masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
__ Jump(adaptor, RelocInfo::CODE_TARGET);
}
// CALL_NON_FUNCTION expects the non-function callee as receiver (instead
// of the original receiver from the call site).
__ bind(non_function);
__ StoreP(r4, MemOperand(sp, argc * kPointerSize), r0);
__ li(r3, Operand(argc)); // Set up the number of arguments.
__ li(r5, Operand::Zero());
__ GetBuiltinFunction(r4, Builtins::CALL_NON_FUNCTION);
__ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
RelocInfo::CODE_TARGET);
}
static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
// Wrap the receiver and patch it back onto the stack.
{
FrameAndConstantPoolScope frame_scope(masm, StackFrame::INTERNAL);
__ Push(r4, r6);
__ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
__ pop(r4);
}
__ StoreP(r3, MemOperand(sp, argc * kPointerSize), r0);
__ b(cont);
}
static void CallFunctionNoFeedback(MacroAssembler* masm, int argc,
bool needs_checks, bool call_as_method) {
// r4 : the function to call
Label slow, non_function, wrap, cont;
if (needs_checks) {
// Check that the function is really a JavaScript function.
// r4: pushed function (to be verified)
__ JumpIfSmi(r4, &non_function);
// Goto slow case if we do not have a function.
__ CompareObjectType(r4, r7, r7, JS_FUNCTION_TYPE);
__ bne(&slow);
}
// Fast-case: Invoke the function now.
// r4: pushed function
ParameterCount actual(argc);
if (call_as_method) {
if (needs_checks) {
EmitContinueIfStrictOrNative(masm, &cont);
}
// Compute the receiver in sloppy mode.
__ LoadP(r6, MemOperand(sp, argc * kPointerSize), r0);
if (needs_checks) {
__ JumpIfSmi(r6, &wrap);
__ CompareObjectType(r6, r7, r7, FIRST_SPEC_OBJECT_TYPE);
__ blt(&wrap);
} else {
__ b(&wrap);
}
__ bind(&cont);
}
__ InvokeFunction(r4, actual, JUMP_FUNCTION, NullCallWrapper());
if (needs_checks) {
// Slow-case: Non-function called.
__ bind(&slow);
EmitSlowCase(masm, argc, &non_function);
}
if (call_as_method) {
__ bind(&wrap);
EmitWrapCase(masm, argc, &cont);
}
}
void CallFunctionStub::Generate(MacroAssembler* masm) {
CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
}
void CallConstructStub::Generate(MacroAssembler* masm) {
// r3 : number of arguments
// r4 : the function to call
// r5 : feedback vector
// r6 : (only if r5 is not the megamorphic symbol) slot in feedback
// vector (Smi)
Label slow, non_function_call;
// Check that the function is not a smi.
__ JumpIfSmi(r4, &non_function_call);
// Check that the function is a JSFunction.
__ CompareObjectType(r4, r7, r7, JS_FUNCTION_TYPE);
__ bne(&slow);
if (RecordCallTarget()) {
GenerateRecordCallTarget(masm);
__ SmiToPtrArrayOffset(r8, r6);
__ add(r8, r5, r8);
if (FLAG_pretenuring_call_new) {
// Put the AllocationSite from the feedback vector into r5.
// By adding kPointerSize we encode that we know the AllocationSite
// entry is at the feedback vector slot given by r6 + 1.
__ LoadP(r5, FieldMemOperand(r8, FixedArray::kHeaderSize + kPointerSize));
} else {
Label feedback_register_initialized;
// Put the AllocationSite from the feedback vector into r5, or undefined.
__ LoadP(r5, FieldMemOperand(r8, FixedArray::kHeaderSize));
__ LoadP(r8, FieldMemOperand(r5, AllocationSite::kMapOffset));
__ CompareRoot(r8, Heap::kAllocationSiteMapRootIndex);
__ beq(&feedback_register_initialized);
__ LoadRoot(r5, Heap::kUndefinedValueRootIndex);
__ bind(&feedback_register_initialized);
}
__ AssertUndefinedOrAllocationSite(r5, r8);
}
// Jump to the function-specific construct stub.
Register jmp_reg = r7;
__ LoadP(jmp_reg, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
__ LoadP(jmp_reg,
FieldMemOperand(jmp_reg, SharedFunctionInfo::kConstructStubOffset));
__ addi(ip, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
__ JumpToJSEntry(ip);
// r3: number of arguments
// r4: called object
// r7: object type
Label do_call;
__ bind(&slow);
STATIC_ASSERT(JS_FUNCTION_PROXY_TYPE < 0xffffu);
__ cmpi(r7, Operand(JS_FUNCTION_PROXY_TYPE));
__ bne(&non_function_call);
__ GetBuiltinFunction(r4, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
__ b(&do_call);
__ bind(&non_function_call);
__ GetBuiltinFunction(r4, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
__ bind(&do_call);
// Set expected number of arguments to zero (not changing r3).
__ li(r5, Operand::Zero());
__ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
RelocInfo::CODE_TARGET);
}
static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) {
__ LoadP(vector, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
__ LoadP(vector,
FieldMemOperand(vector, JSFunction::kSharedFunctionInfoOffset));
__ LoadP(vector,
FieldMemOperand(vector, SharedFunctionInfo::kFeedbackVectorOffset));
}
void CallIC_ArrayStub::Generate(MacroAssembler* masm) {
// r4 - function
// r6 - slot id
Label miss;
int argc = arg_count();
ParameterCount actual(argc);
EmitLoadTypeFeedbackVector(masm, r5);
__ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r7);
__ cmp(r4, r7);
__ bne(&miss);
__ mov(r3, Operand(arg_count()));
__ SmiToPtrArrayOffset(r7, r6);
__ add(r7, r5, r7);
__ LoadP(r7, FieldMemOperand(r7, FixedArray::kHeaderSize));
// Verify that r7 contains an AllocationSite
__ LoadP(r8, FieldMemOperand(r7, HeapObject::kMapOffset));
__ CompareRoot(r8, Heap::kAllocationSiteMapRootIndex);
__ bne(&miss);
__ mr(r5, r7);
ArrayConstructorStub stub(masm->isolate(), arg_count());
__ TailCallStub(&stub);
__ bind(&miss);
GenerateMiss(masm);
// The slow case, we need this no matter what to complete a call after a miss.
CallFunctionNoFeedback(masm, arg_count(), true, CallAsMethod());
// Unreachable.
__ stop("Unexpected code address");
}
void CallICStub::Generate(MacroAssembler* masm) {
// r4 - function
// r6 - slot id (Smi)
Label extra_checks_or_miss, slow_start;
Label slow, non_function, wrap, cont;
Label have_js_function;
int argc = arg_count();
ParameterCount actual(argc);
EmitLoadTypeFeedbackVector(masm, r5);
// The checks. First, does r4 match the recorded monomorphic target?
__ SmiToPtrArrayOffset(r7, r6);
__ add(r7, r5, r7);
__ LoadP(r7, FieldMemOperand(r7, FixedArray::kHeaderSize));
__ cmp(r4, r7);
__ bne(&extra_checks_or_miss);
__ bind(&have_js_function);
if (CallAsMethod()) {
EmitContinueIfStrictOrNative(masm, &cont);
// Compute the receiver in sloppy mode.
__ LoadP(r6, MemOperand(sp, argc * kPointerSize), r0);
__ JumpIfSmi(r6, &wrap);
__ CompareObjectType(r6, r7, r7, FIRST_SPEC_OBJECT_TYPE);
__ blt(&wrap);
__ bind(&cont);
}
__ InvokeFunction(r4, actual, JUMP_FUNCTION, NullCallWrapper());
__ bind(&slow);
EmitSlowCase(masm, argc, &non_function);
if (CallAsMethod()) {
__ bind(&wrap);
EmitWrapCase(masm, argc, &cont);
}
__ bind(&extra_checks_or_miss);
Label miss;
__ CompareRoot(r7, Heap::kmegamorphic_symbolRootIndex);
__ beq(&slow_start);
__ CompareRoot(r7, Heap::kuninitialized_symbolRootIndex);
__ beq(&miss);
if (!FLAG_trace_ic) {
// We are going megamorphic. If the feedback is a JSFunction, it is fine
// to handle it here. More complex cases are dealt with in the runtime.
__ AssertNotSmi(r7);
__ CompareObjectType(r7, r8, r8, JS_FUNCTION_TYPE);
__ bne(&miss);
__ SmiToPtrArrayOffset(r7, r6);
__ add(r7, r5, r7);
__ LoadRoot(ip, Heap::kmegamorphic_symbolRootIndex);
__ StoreP(ip, FieldMemOperand(r7, FixedArray::kHeaderSize), r0);
// We have to update statistics for runtime profiling.
const int with_types_offset =
FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
__ LoadP(r7, FieldMemOperand(r5, with_types_offset));
__ SubSmiLiteral(r7, r7, Smi::FromInt(1), r0);
__ StoreP(r7, FieldMemOperand(r5, with_types_offset), r0);
const int generic_offset =
FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
__ LoadP(r7, FieldMemOperand(r5, generic_offset));
__ AddSmiLiteral(r7, r7, Smi::FromInt(1), r0);
__ StoreP(r7, FieldMemOperand(r5, generic_offset), r0);
__ jmp(&slow_start);
}
// We are here because tracing is on or we are going monomorphic.
__ bind(&miss);
GenerateMiss(masm);
// the slow case
__ bind(&slow_start);
// Check that the function is really a JavaScript function.
// r4: pushed function (to be verified)
__ JumpIfSmi(r4, &non_function);
// Goto slow case if we do not have a function.
__ CompareObjectType(r4, r7, r7, JS_FUNCTION_TYPE);
__ bne(&slow);
__ b(&have_js_function);
}
void CallICStub::GenerateMiss(MacroAssembler* masm) {
// Get the receiver of the function from the stack; 1 ~ return address.
__ LoadP(r7, MemOperand(sp, (arg_count() + 1) * kPointerSize), r0);
{
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
// Push the receiver and the function and feedback info.
__ Push(r7, r4, r5, r6);
// Call the entry.
IC::UtilityId id = GetICState() == DEFAULT ? IC::kCallIC_Miss
: IC::kCallIC_Customization_Miss;
ExternalReference miss = ExternalReference(IC_Utility(id), masm->isolate());
__ CallExternalReference(miss, 4);
// Move result to r4 and exit the internal frame.
__ mr(r4, r3);
}
}
// StringCharCodeAtGenerator
void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
// If the receiver is a smi trigger the non-string case.
if (check_mode_ == RECEIVER_IS_UNKNOWN) {
__ JumpIfSmi(object_, receiver_not_string_);
// Fetch the instance type of the receiver into result register.
__ LoadP(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
__ lbz(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
// If the receiver is not a string trigger the non-string case.
__ andi(r0, result_, Operand(kIsNotStringMask));
__ bne(receiver_not_string_, cr0);
}
// If the index is non-smi trigger the non-smi case.
__ JumpIfNotSmi(index_, &index_not_smi_);
__ bind(&got_smi_index_);
// Check for index out of range.
__ LoadP(ip, FieldMemOperand(object_, String::kLengthOffset));
__ cmpl(ip, index_);
__ ble(index_out_of_range_);
__ SmiUntag(index_);
StringCharLoadGenerator::Generate(masm, object_, index_, result_,
&call_runtime_);
__ SmiTag(result_);
__ bind(&exit_);
}
void StringCharCodeAtGenerator::GenerateSlow(
MacroAssembler* masm, const RuntimeCallHelper& call_helper) {
__ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
// Index is not a smi.
__ bind(&index_not_smi_);
// If index is a heap number, try converting it to an integer.
__ CheckMap(index_, result_, Heap::kHeapNumberMapRootIndex, index_not_number_,
DONT_DO_SMI_CHECK);
call_helper.BeforeCall(masm);
__ push(object_);
__ push(index_); // Consumed by runtime conversion function.
if (index_flags_ == STRING_INDEX_IS_NUMBER) {
__ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
} else {
DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
// NumberToSmi discards numbers that are not exact integers.
__ CallRuntime(Runtime::kNumberToSmi, 1);
}
// Save the conversion result before the pop instructions below
// have a chance to overwrite it.
__ Move(index_, r3);
__ pop(object_);
// Reload the instance type.
__ LoadP(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
__ lbz(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
call_helper.AfterCall(masm);
// If index is still not a smi, it must be out of range.
__ JumpIfNotSmi(index_, index_out_of_range_);
// Otherwise, return to the fast path.
__ b(&got_smi_index_);
// Call runtime. We get here when the receiver is a string and the
// index is a number, but the code of getting the actual character
// is too complex (e.g., when the string needs to be flattened).
__ bind(&call_runtime_);
call_helper.BeforeCall(masm);
__ SmiTag(index_);
__ Push(object_, index_);
__ CallRuntime(Runtime::kStringCharCodeAtRT, 2);
__ Move(result_, r3);
call_helper.AfterCall(masm);
__ b(&exit_);
__ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
}