2012-01-27 16:54:22 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2010-08-25 09:44:44 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
|
|
|
#if defined(V8_TARGET_ARCH_ARM)
|
|
|
|
|
|
|
|
#include "bootstrapper.h"
|
2013-04-30 11:34:43 +00:00
|
|
|
#include "builtins-decls.h"
|
2010-08-30 11:48:07 +00:00
|
|
|
#include "code-stubs.h"
|
2010-08-25 09:44:44 +00:00
|
|
|
#include "regexp-macro-assembler.h"
|
2013-01-21 14:53:29 +00:00
|
|
|
#include "stub-cache.h"
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
2013-04-04 17:55:43 +00:00
|
|
|
void FastCloneShallowArrayStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { r3, r2, r1 };
|
|
|
|
descriptor->register_param_count_ = 3;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->stack_parameter_count_ = NULL;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
Runtime::FunctionForId(Runtime::kCreateArrayLiteralShallow)->entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-26 13:08:08 +00:00
|
|
|
void FastCloneShallowObjectStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { r3, r2, r1, r0 };
|
|
|
|
descriptor->register_param_count_ = 4;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->stack_parameter_count_ = NULL;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
Runtime::FunctionForId(Runtime::kCreateObjectLiteralShallow)->entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
void KeyedLoadFastElementStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { r1, r0 };
|
|
|
|
descriptor->register_param_count_ = 2;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
2013-01-30 14:25:34 +00:00
|
|
|
FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure);
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-02 16:32:47 +00:00
|
|
|
void LoadFieldStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { r0 };
|
|
|
|
descriptor->register_param_count_ = 1;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->stack_parameter_count_ = NULL;
|
|
|
|
descriptor->deoptimization_handler_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KeyedLoadFieldStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { r1 };
|
|
|
|
descriptor->register_param_count_ = 1;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->stack_parameter_count_ = NULL;
|
|
|
|
descriptor->deoptimization_handler_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-20 10:37:13 +00:00
|
|
|
void KeyedStoreFastElementStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { r2, r1, r0 };
|
|
|
|
descriptor->register_param_count_ = 3;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-04 12:01:59 +00:00
|
|
|
void TransitionElementsKindStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { r0, r1 };
|
|
|
|
descriptor->register_param_count_ = 2;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
Address entry =
|
|
|
|
Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry;
|
|
|
|
descriptor->deoptimization_handler_ = FUNCTION_ADDR(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-24 11:32:17 +00:00
|
|
|
void CompareNilICStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { r0 };
|
|
|
|
descriptor->register_param_count_ = 1;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
FUNCTION_ADDR(CompareNilIC_Miss);
|
|
|
|
descriptor->miss_handler_ =
|
|
|
|
ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-25 16:00:32 +00:00
|
|
|
static void InitializeArrayConstructorDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor,
|
|
|
|
int constant_stack_parameter_count) {
|
2013-03-01 16:06:34 +00:00
|
|
|
// register state
|
2013-04-25 16:00:32 +00:00
|
|
|
// r0 -- number of arguments
|
2013-03-01 16:06:34 +00:00
|
|
|
// r2 -- type info cell with elements kind
|
2013-04-25 16:00:32 +00:00
|
|
|
static Register registers[] = { r2 };
|
|
|
|
descriptor->register_param_count_ = 1;
|
|
|
|
if (constant_stack_parameter_count != 0) {
|
|
|
|
// stack param count needs (constructor pointer, and single argument)
|
|
|
|
descriptor->stack_parameter_count_ = &r0;
|
|
|
|
}
|
|
|
|
descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count;
|
2013-03-01 16:06:34 +00:00
|
|
|
descriptor->register_params_ = registers;
|
2013-04-02 11:28:01 +00:00
|
|
|
descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
|
2013-03-01 16:06:34 +00:00
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
FUNCTION_ADDR(ArrayConstructor_StubFailure);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
2013-04-25 16:00:32 +00:00
|
|
|
InitializeArrayConstructorDescriptor(isolate, descriptor, 0);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
2013-04-25 16:00:32 +00:00
|
|
|
InitializeArrayConstructorDescriptor(isolate, descriptor, 1);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
2013-04-25 16:00:32 +00:00
|
|
|
InitializeArrayConstructorDescriptor(isolate, descriptor, -1);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
#define __ ACCESS_MASM(masm)
|
|
|
|
|
|
|
|
static void EmitIdenticalObjectComparison(MacroAssembler* masm,
|
|
|
|
Label* slow,
|
2012-11-14 15:59:45 +00:00
|
|
|
Condition cond);
|
2010-08-25 09:44:44 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
2011-04-28 17:49:55 +00:00
|
|
|
// Check if the operand is a heap number.
|
|
|
|
static void EmitCheckForHeapNumber(MacroAssembler* masm, Register operand,
|
|
|
|
Register scratch1, Register scratch2,
|
|
|
|
Label* not_a_heap_number) {
|
|
|
|
__ ldr(scratch1, FieldMemOperand(operand, HeapObject::kMapOffset));
|
|
|
|
__ LoadRoot(scratch2, Heap::kHeapNumberMapRootIndex);
|
|
|
|
__ cmp(scratch1, scratch2);
|
|
|
|
__ b(ne, not_a_heap_number);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-18 20:37:27 +00:00
|
|
|
void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) {
|
|
|
|
// Update the static counter each time a new code stub is generated.
|
|
|
|
Isolate* isolate = masm->isolate();
|
|
|
|
isolate->counters()->code_stubs()->Increment();
|
|
|
|
|
|
|
|
CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(isolate);
|
|
|
|
int param_count = descriptor->register_param_count_;
|
|
|
|
{
|
|
|
|
// Call the runtime system in a fresh internal frame.
|
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
|
|
|
ASSERT(descriptor->register_param_count_ == 0 ||
|
|
|
|
r0.is(descriptor->register_params_[param_count - 1]));
|
|
|
|
// Push arguments
|
|
|
|
for (int i = 0; i < param_count; ++i) {
|
|
|
|
__ push(descriptor->register_params_[i]);
|
|
|
|
}
|
|
|
|
ExternalReference miss = descriptor->miss_handler_;
|
|
|
|
__ CallExternalReference(miss, descriptor->register_param_count_);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-28 14:18:26 +00:00
|
|
|
void ToNumberStub::Generate(MacroAssembler* masm) {
|
|
|
|
// The ToNumber stub takes one argument in eax.
|
|
|
|
Label check_heap_number, call_builtin;
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(r0, &check_heap_number);
|
2011-01-28 14:18:26 +00:00
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&check_heap_number);
|
2011-04-28 17:49:55 +00:00
|
|
|
EmitCheckForHeapNumber(masm, r0, r1, ip, &call_builtin);
|
2011-01-28 14:18:26 +00:00
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&call_builtin);
|
|
|
|
__ push(r0);
|
2011-04-29 20:07:41 +00:00
|
|
|
__ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
|
2011-01-28 14:18:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void FastNewClosureStub::Generate(MacroAssembler* masm) {
|
|
|
|
// Create a new closure from the given function info in new
|
|
|
|
// space. Set the context to the current context in cp.
|
2012-06-14 14:06:22 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
Label gc;
|
|
|
|
|
|
|
|
// Pop the function info from the stack.
|
|
|
|
__ pop(r3);
|
|
|
|
|
|
|
|
// Attempt to allocate new JSFunction in new space.
|
2013-03-14 08:32:52 +00:00
|
|
|
__ Allocate(JSFunction::kSize, r0, r1, r2, &gc, TAG_OBJECT);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-06-14 14:06:22 +00:00
|
|
|
__ IncrementCounter(counters->fast_new_closure_total(), 1, r6, r7);
|
|
|
|
|
2013-04-11 16:28:19 +00:00
|
|
|
int map_index = Context::FunctionMapIndex(language_mode_, is_generator_);
|
2011-03-17 20:28:30 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
// Compute the function map in the current native context and set that
|
2010-08-25 09:44:44 +00:00
|
|
|
// as the map of the allocated object.
|
2012-08-17 12:59:00 +00:00
|
|
|
__ ldr(r2, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
|
2012-08-17 09:03:08 +00:00
|
|
|
__ ldr(r2, FieldMemOperand(r2, GlobalObject::kNativeContextOffset));
|
2012-06-14 14:06:22 +00:00
|
|
|
__ ldr(r5, MemOperand(r2, Context::SlotOffset(map_index)));
|
|
|
|
__ str(r5, FieldMemOperand(r0, HeapObject::kMapOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Initialize the rest of the function. We don't have to update the
|
|
|
|
// write barrier because the allocated object is in new space.
|
|
|
|
__ LoadRoot(r1, Heap::kEmptyFixedArrayRootIndex);
|
2012-06-14 14:06:22 +00:00
|
|
|
__ LoadRoot(r5, Heap::kTheHoleValueRootIndex);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ str(r1, FieldMemOperand(r0, JSObject::kPropertiesOffset));
|
|
|
|
__ str(r1, FieldMemOperand(r0, JSObject::kElementsOffset));
|
2012-06-14 14:06:22 +00:00
|
|
|
__ str(r5, FieldMemOperand(r0, JSFunction::kPrototypeOrInitialMapOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ str(r3, FieldMemOperand(r0, JSFunction::kSharedFunctionInfoOffset));
|
|
|
|
__ str(cp, FieldMemOperand(r0, JSFunction::kContextOffset));
|
|
|
|
__ str(r1, FieldMemOperand(r0, JSFunction::kLiteralsOffset));
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Initialize the code pointer in the function to be the one
|
|
|
|
// found in the shared function info object.
|
2012-06-14 14:06:22 +00:00
|
|
|
// But first check if there is an optimized version for our context.
|
|
|
|
Label check_optimized;
|
|
|
|
Label install_unoptimized;
|
|
|
|
if (FLAG_cache_optimized_code) {
|
|
|
|
__ ldr(r1,
|
|
|
|
FieldMemOperand(r3, SharedFunctionInfo::kOptimizedCodeMapOffset));
|
|
|
|
__ tst(r1, r1);
|
|
|
|
__ b(ne, &check_optimized);
|
|
|
|
}
|
|
|
|
__ bind(&install_unoptimized);
|
|
|
|
__ LoadRoot(r4, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ str(r4, FieldMemOperand(r0, JSFunction::kNextFunctionLinkOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ldr(r3, FieldMemOperand(r3, SharedFunctionInfo::kCodeOffset));
|
|
|
|
__ add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag));
|
|
|
|
__ str(r3, FieldMemOperand(r0, JSFunction::kCodeEntryOffset));
|
|
|
|
|
|
|
|
// Return result. The argument function info has been popped already.
|
|
|
|
__ Ret();
|
|
|
|
|
2012-06-14 14:06:22 +00:00
|
|
|
__ bind(&check_optimized);
|
|
|
|
|
|
|
|
__ IncrementCounter(counters->fast_new_closure_try_optimized(), 1, r6, r7);
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
// r2 holds native context, r1 points to fixed array of 3-element entries
|
|
|
|
// (native context, optimized code, literals).
|
2012-06-14 14:06:22 +00:00
|
|
|
// The optimized code map must never be empty, so check the first elements.
|
|
|
|
Label install_optimized;
|
|
|
|
// Speculatively move code object into r4.
|
|
|
|
__ ldr(r4, FieldMemOperand(r1, FixedArray::kHeaderSize + kPointerSize));
|
|
|
|
__ ldr(r5, FieldMemOperand(r1, FixedArray::kHeaderSize));
|
|
|
|
__ cmp(r2, r5);
|
|
|
|
__ b(eq, &install_optimized);
|
|
|
|
|
|
|
|
// Iterate through the rest of map backwards. r4 holds an index as a Smi.
|
|
|
|
Label loop;
|
|
|
|
__ ldr(r4, FieldMemOperand(r1, FixedArray::kLengthOffset));
|
|
|
|
__ bind(&loop);
|
|
|
|
// Do not double check first entry.
|
|
|
|
|
|
|
|
__ cmp(r4, Operand(Smi::FromInt(SharedFunctionInfo::kEntryLength)));
|
|
|
|
__ b(eq, &install_unoptimized);
|
|
|
|
__ sub(r4, r4, Operand(
|
|
|
|
Smi::FromInt(SharedFunctionInfo::kEntryLength))); // Skip an entry.
|
|
|
|
__ add(r5, r1, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
|
|
|
|
__ add(r5, r5, Operand(r4, LSL, kPointerSizeLog2 - kSmiTagSize));
|
|
|
|
__ ldr(r5, MemOperand(r5));
|
|
|
|
__ cmp(r2, r5);
|
|
|
|
__ b(ne, &loop);
|
|
|
|
// Hit: fetch the optimized code.
|
|
|
|
__ add(r5, r1, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
|
|
|
|
__ add(r5, r5, Operand(r4, LSL, kPointerSizeLog2 - kSmiTagSize));
|
|
|
|
__ add(r5, r5, Operand(kPointerSize));
|
|
|
|
__ ldr(r4, MemOperand(r5));
|
|
|
|
|
|
|
|
__ bind(&install_optimized);
|
|
|
|
__ IncrementCounter(counters->fast_new_closure_install_optimized(),
|
|
|
|
1, r6, r7);
|
|
|
|
|
|
|
|
// TODO(fschneider): Idea: store proper code pointers in the map and either
|
|
|
|
// unmangle them on marking or do nothing as the whole map is discarded on
|
|
|
|
// major GC anyway.
|
|
|
|
__ add(r4, r4, Operand(Code::kHeaderSize - kHeapObjectTag));
|
|
|
|
__ str(r4, FieldMemOperand(r0, JSFunction::kCodeEntryOffset));
|
|
|
|
|
|
|
|
// Now link a function into a list of optimized functions.
|
|
|
|
__ ldr(r4, ContextOperand(r2, Context::OPTIMIZED_FUNCTIONS_LIST));
|
|
|
|
|
|
|
|
__ str(r4, FieldMemOperand(r0, JSFunction::kNextFunctionLinkOffset));
|
|
|
|
// No need for write barrier as JSFunction (eax) is in the new space.
|
|
|
|
|
|
|
|
__ str(r0, ContextOperand(r2, Context::OPTIMIZED_FUNCTIONS_LIST));
|
|
|
|
// Store JSFunction (eax) into edx before issuing write barrier as
|
|
|
|
// it clobbers all the registers passed.
|
|
|
|
__ mov(r4, r0);
|
|
|
|
__ RecordWriteContextSlot(
|
|
|
|
r2,
|
|
|
|
Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST),
|
|
|
|
r4,
|
|
|
|
r1,
|
|
|
|
kLRHasNotBeenSaved,
|
|
|
|
kDontSaveFPRegs);
|
|
|
|
|
|
|
|
// Return result. The argument function info has been popped already.
|
|
|
|
__ Ret();
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Create a new closure through the slower runtime call.
|
|
|
|
__ bind(&gc);
|
2010-11-22 09:57:21 +00:00
|
|
|
__ LoadRoot(r4, Heap::kFalseValueRootIndex);
|
|
|
|
__ Push(cp, r3, r4);
|
|
|
|
__ TailCallRuntime(Runtime::kNewClosure, 3, 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FastNewContextStub::Generate(MacroAssembler* masm) {
|
|
|
|
// Try to allocate the context in new space.
|
|
|
|
Label gc;
|
2011-01-25 13:01:45 +00:00
|
|
|
int length = slots_ + Context::MIN_CONTEXT_SLOTS;
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Attempt to allocate the context in new space.
|
2013-03-14 08:32:52 +00:00
|
|
|
__ Allocate(FixedArray::SizeFor(length), r0, r1, r2, &gc, TAG_OBJECT);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Load the function from the stack.
|
|
|
|
__ ldr(r3, MemOperand(sp, 0));
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the object header.
|
2012-01-27 16:54:22 +00:00
|
|
|
__ LoadRoot(r1, Heap::kFunctionContextMapRootIndex);
|
2011-01-25 13:01:45 +00:00
|
|
|
__ mov(r2, Operand(Smi::FromInt(length)));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ str(r2, FieldMemOperand(r0, FixedArray::kLengthOffset));
|
2012-01-27 16:54:22 +00:00
|
|
|
__ str(r1, FieldMemOperand(r0, HeapObject::kMapOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-01-27 16:54:22 +00:00
|
|
|
// Set up the fixed slots, copy the global object from the previous context.
|
2012-08-17 12:59:00 +00:00
|
|
|
__ ldr(r2, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(r1, Operand(Smi::FromInt(0)));
|
|
|
|
__ str(r3, MemOperand(r0, Context::SlotOffset(Context::CLOSURE_INDEX)));
|
2011-06-09 12:45:26 +00:00
|
|
|
__ str(cp, MemOperand(r0, Context::SlotOffset(Context::PREVIOUS_INDEX)));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ str(r1, MemOperand(r0, Context::SlotOffset(Context::EXTENSION_INDEX)));
|
2012-08-17 12:59:00 +00:00
|
|
|
__ str(r2, MemOperand(r0, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Initialize the rest of the slots to undefined.
|
|
|
|
__ LoadRoot(r1, Heap::kUndefinedValueRootIndex);
|
2011-01-25 13:01:45 +00:00
|
|
|
for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) {
|
2010-08-25 09:44:44 +00:00
|
|
|
__ str(r1, MemOperand(r0, Context::SlotOffset(i)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the on-stack argument and return.
|
|
|
|
__ mov(cp, r0);
|
|
|
|
__ pop();
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Need to collect. Call into runtime system.
|
|
|
|
__ bind(&gc);
|
2011-06-09 11:26:01 +00:00
|
|
|
__ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-06 15:59:02 +00:00
|
|
|
void FastNewBlockContextStub::Generate(MacroAssembler* masm) {
|
|
|
|
// Stack layout on entry:
|
|
|
|
//
|
|
|
|
// [sp]: function.
|
|
|
|
// [sp + kPointerSize]: serialized scope info
|
|
|
|
|
|
|
|
// Try to allocate the context in new space.
|
|
|
|
Label gc;
|
|
|
|
int length = slots_ + Context::MIN_CONTEXT_SLOTS;
|
2013-03-14 08:32:52 +00:00
|
|
|
__ Allocate(FixedArray::SizeFor(length), r0, r1, r2, &gc, TAG_OBJECT);
|
2011-10-06 15:59:02 +00:00
|
|
|
|
|
|
|
// Load the function from the stack.
|
|
|
|
__ ldr(r3, MemOperand(sp, 0));
|
|
|
|
|
|
|
|
// Load the serialized scope info from the stack.
|
|
|
|
__ ldr(r1, MemOperand(sp, 1 * kPointerSize));
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the object header.
|
2011-10-06 15:59:02 +00:00
|
|
|
__ LoadRoot(r2, Heap::kBlockContextMapRootIndex);
|
|
|
|
__ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
|
|
|
|
__ mov(r2, Operand(Smi::FromInt(length)));
|
|
|
|
__ str(r2, FieldMemOperand(r0, FixedArray::kLengthOffset));
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
// If this block context is nested in the native context we get a smi
|
2011-10-06 15:59:02 +00:00
|
|
|
// sentinel instead of a function. The block context should get the
|
2012-08-17 09:03:08 +00:00
|
|
|
// canonical empty function of the native context as its closure which
|
2011-10-06 15:59:02 +00:00
|
|
|
// we still have to look up.
|
|
|
|
Label after_sentinel;
|
|
|
|
__ JumpIfNotSmi(r3, &after_sentinel);
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
const char* message = "Expected 0 as a Smi sentinel";
|
|
|
|
__ cmp(r3, Operand::Zero());
|
|
|
|
__ Assert(eq, message);
|
|
|
|
}
|
|
|
|
__ ldr(r3, GlobalObjectOperand());
|
2012-08-17 09:03:08 +00:00
|
|
|
__ ldr(r3, FieldMemOperand(r3, GlobalObject::kNativeContextOffset));
|
2011-10-06 15:59:02 +00:00
|
|
|
__ ldr(r3, ContextOperand(r3, Context::CLOSURE_INDEX));
|
|
|
|
__ bind(&after_sentinel);
|
|
|
|
|
2012-01-27 16:54:22 +00:00
|
|
|
// Set up the fixed slots, copy the global object from the previous context.
|
2012-08-17 12:59:00 +00:00
|
|
|
__ ldr(r2, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX));
|
2011-10-06 15:59:02 +00:00
|
|
|
__ str(r3, ContextOperand(r0, Context::CLOSURE_INDEX));
|
|
|
|
__ str(cp, ContextOperand(r0, Context::PREVIOUS_INDEX));
|
|
|
|
__ str(r1, ContextOperand(r0, Context::EXTENSION_INDEX));
|
2012-08-17 12:59:00 +00:00
|
|
|
__ str(r2, ContextOperand(r0, Context::GLOBAL_OBJECT_INDEX));
|
2011-10-06 15:59:02 +00:00
|
|
|
|
|
|
|
// Initialize the rest of the slots to the hole value.
|
|
|
|
__ LoadRoot(r1, Heap::kTheHoleValueRootIndex);
|
|
|
|
for (int i = 0; i < slots_; i++) {
|
|
|
|
__ str(r1, ContextOperand(r0, i + Context::MIN_CONTEXT_SLOTS));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the on-stack argument and return.
|
|
|
|
__ mov(cp, r0);
|
|
|
|
__ add(sp, sp, Operand(2 * kPointerSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Need to collect. Call into runtime system.
|
|
|
|
__ bind(&gc);
|
|
|
|
__ TailCallRuntime(Runtime::kPushBlockContext, 2, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Takes a Smi and converts to an IEEE 64 bit floating point value in two
|
|
|
|
// registers. The format is 1 sign bit, 11 exponent bits (biased 1023) and
|
|
|
|
// 52 fraction bits (20 in the first word, 32 in the second). Zeros is a
|
|
|
|
// scratch register. Destroys the source register. No GC occurs during this
|
|
|
|
// stub so you don't have to set up the frame.
|
2012-12-18 16:25:45 +00:00
|
|
|
class ConvertToDoubleStub : public PlatformCodeStub {
|
2010-08-25 09:44:44 +00:00
|
|
|
public:
|
|
|
|
ConvertToDoubleStub(Register result_reg_1,
|
|
|
|
Register result_reg_2,
|
|
|
|
Register source_reg,
|
|
|
|
Register scratch_reg)
|
|
|
|
: result1_(result_reg_1),
|
|
|
|
result2_(result_reg_2),
|
|
|
|
source_(source_reg),
|
|
|
|
zeros_(scratch_reg) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register result1_;
|
|
|
|
Register result2_;
|
|
|
|
Register source_;
|
|
|
|
Register zeros_;
|
|
|
|
|
|
|
|
// Minor key encoding in 16 bits.
|
|
|
|
class ModeBits: public BitField<OverwriteMode, 0, 2> {};
|
|
|
|
class OpBits: public BitField<Token::Value, 2, 14> {};
|
|
|
|
|
|
|
|
Major MajorKey() { return ConvertToDouble; }
|
|
|
|
int MinorKey() {
|
|
|
|
// Encode the parameters in a unique 16 bit value.
|
|
|
|
return result1_.code() +
|
|
|
|
(result2_.code() << 4) +
|
|
|
|
(source_.code() << 8) +
|
|
|
|
(zeros_.code() << 12);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Generate(MacroAssembler* masm);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void ConvertToDoubleStub::Generate(MacroAssembler* masm) {
|
2011-04-13 11:59:17 +00:00
|
|
|
Register exponent = result1_;
|
|
|
|
Register mantissa = result2_;
|
2011-04-11 09:04:30 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
Label not_special;
|
|
|
|
// Convert from Smi to integer.
|
|
|
|
__ mov(source_, Operand(source_, ASR, kSmiTagSize));
|
|
|
|
// Move sign bit from source to destination. This works because the sign bit
|
|
|
|
// in the exponent word of the double has the same position and polarity as
|
|
|
|
// the 2's complement sign bit in a Smi.
|
|
|
|
STATIC_ASSERT(HeapNumber::kSignMask == 0x80000000u);
|
|
|
|
__ and_(exponent, source_, Operand(HeapNumber::kSignMask), SetCC);
|
|
|
|
// Subtract from 0 if source was negative.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ rsb(source_, source_, Operand::Zero(), LeaveCC, ne);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// We have -1, 0 or 1, which we treat specially. Register source_ contains
|
|
|
|
// absolute value: it is either equal to 1 (special case of -1 and 1),
|
|
|
|
// greater than 1 (not a special case) or less than 1 (special case of 0).
|
|
|
|
__ cmp(source_, Operand(1));
|
|
|
|
__ b(gt, ¬_special);
|
|
|
|
|
|
|
|
// For 1 or -1 we need to or in the 0 exponent (biased to 1023).
|
2012-03-12 13:56:56 +00:00
|
|
|
const uint32_t exponent_word_for_1 =
|
2010-08-25 09:44:44 +00:00
|
|
|
HeapNumber::kExponentBias << HeapNumber::kExponentShift;
|
|
|
|
__ orr(exponent, exponent, Operand(exponent_word_for_1), LeaveCC, eq);
|
|
|
|
// 1, 0 and -1 all have 0 for the second word.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ mov(mantissa, Operand::Zero());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(¬_special);
|
2013-04-18 10:32:18 +00:00
|
|
|
__ clz(zeros_, source_);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Compute exponent and or it into the exponent register.
|
|
|
|
// We use mantissa as a scratch register here. Use a fudge factor to
|
|
|
|
// divide the constant 31 + HeapNumber::kExponentBias, 0x41d, into two parts
|
|
|
|
// that fit in the ARM's constant field.
|
|
|
|
int fudge = 0x400;
|
|
|
|
__ rsb(mantissa, zeros_, Operand(31 + HeapNumber::kExponentBias - fudge));
|
|
|
|
__ add(mantissa, mantissa, Operand(fudge));
|
|
|
|
__ orr(exponent,
|
|
|
|
exponent,
|
|
|
|
Operand(mantissa, LSL, HeapNumber::kExponentShift));
|
|
|
|
// Shift up the source chopping the top bit off.
|
|
|
|
__ add(zeros_, zeros_, Operand(1));
|
|
|
|
// This wouldn't work for 1.0 or -1.0 as the shift would be 32 which means 0.
|
|
|
|
__ mov(source_, Operand(source_, LSL, zeros_));
|
|
|
|
// Compute lower part of fraction (last 12 bits).
|
|
|
|
__ mov(mantissa, Operand(source_, LSL, HeapNumber::kMantissaBitsInTopWord));
|
|
|
|
// And the top (top 20 bits).
|
|
|
|
__ orr(exponent,
|
|
|
|
exponent,
|
|
|
|
Operand(source_, LSR, 32 - HeapNumber::kMantissaBitsInTopWord));
|
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-27 10:53:22 +00:00
|
|
|
bool WriteInt32ToHeapNumberStub::IsPregenerated() {
|
2011-09-19 07:38:48 +00:00
|
|
|
// These variants are compiled ahead of time. See next method.
|
|
|
|
if (the_int_.is(r1) && the_heap_number_.is(r0) && scratch_.is(r2)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (the_int_.is(r2) && the_heap_number_.is(r0) && scratch_.is(r3)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Other register combinations are generated as and when they are needed,
|
|
|
|
// so it is unsafe to call them from stubs (we can't generate a stub while
|
|
|
|
// we are generating a stub).
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-27 12:33:24 +00:00
|
|
|
void WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime(
|
|
|
|
Isolate* isolate) {
|
2011-09-19 07:38:48 +00:00
|
|
|
WriteInt32ToHeapNumberStub stub1(r1, r0, r2);
|
|
|
|
WriteInt32ToHeapNumberStub stub2(r2, r0, r3);
|
2013-02-27 12:33:24 +00:00
|
|
|
stub1.GetCode(isolate)->set_is_pregenerated(true);
|
|
|
|
stub2.GetCode(isolate)->set_is_pregenerated(true);
|
2011-09-19 07:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// See comment for class.
|
|
|
|
void WriteInt32ToHeapNumberStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label max_negative_int;
|
|
|
|
// the_int_ has the answer which is a signed int32 but not a Smi.
|
|
|
|
// We test for the special value that has a different exponent. This test
|
|
|
|
// has the neat side effect of setting the flags according to the sign.
|
|
|
|
STATIC_ASSERT(HeapNumber::kSignMask == 0x80000000u);
|
|
|
|
__ cmp(the_int_, Operand(0x80000000u));
|
|
|
|
__ b(eq, &max_negative_int);
|
|
|
|
// Set up the correct exponent in scratch_. All non-Smi int32s have the same.
|
|
|
|
// A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased).
|
|
|
|
uint32_t non_smi_exponent =
|
|
|
|
(HeapNumber::kExponentBias + 30) << HeapNumber::kExponentShift;
|
|
|
|
__ mov(scratch_, Operand(non_smi_exponent));
|
|
|
|
// Set the sign bit in scratch_ if the value was negative.
|
|
|
|
__ orr(scratch_, scratch_, Operand(HeapNumber::kSignMask), LeaveCC, cs);
|
|
|
|
// Subtract from 0 if the value was negative.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ rsb(the_int_, the_int_, Operand::Zero(), LeaveCC, cs);
|
2010-08-25 09:44:44 +00:00
|
|
|
// We should be masking the implict first digit of the mantissa away here,
|
|
|
|
// but it just ends up combining harmlessly with the last digit of the
|
|
|
|
// exponent that happens to be 1. The sign bit is 0 so we shift 10 to get
|
|
|
|
// the most significant 1 to hit the last bit of the 12 bit sign and exponent.
|
|
|
|
ASSERT(((1 << HeapNumber::kExponentShift) & non_smi_exponent) != 0);
|
|
|
|
const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2;
|
|
|
|
__ orr(scratch_, scratch_, Operand(the_int_, LSR, shift_distance));
|
|
|
|
__ str(scratch_, FieldMemOperand(the_heap_number_,
|
|
|
|
HeapNumber::kExponentOffset));
|
|
|
|
__ mov(scratch_, Operand(the_int_, LSL, 32 - shift_distance));
|
|
|
|
__ str(scratch_, FieldMemOperand(the_heap_number_,
|
|
|
|
HeapNumber::kMantissaOffset));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&max_negative_int);
|
|
|
|
// The max negative int32 is stored as a positive number in the mantissa of
|
|
|
|
// a double because it uses a sign bit instead of using two's complement.
|
|
|
|
// The actual mantissa bits stored are all 0 because the implicit most
|
|
|
|
// significant 1 bit is not stored.
|
|
|
|
non_smi_exponent += 1 << HeapNumber::kExponentShift;
|
|
|
|
__ mov(ip, Operand(HeapNumber::kSignMask | non_smi_exponent));
|
|
|
|
__ str(ip, FieldMemOperand(the_heap_number_, HeapNumber::kExponentOffset));
|
2013-01-07 09:43:12 +00:00
|
|
|
__ mov(ip, Operand::Zero());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ str(ip, FieldMemOperand(the_heap_number_, HeapNumber::kMantissaOffset));
|
|
|
|
__ 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,
|
2012-11-14 15:59:45 +00:00
|
|
|
Condition cond) {
|
2010-08-25 09:44:44 +00:00
|
|
|
Label not_identical;
|
|
|
|
Label heap_number, return_equal;
|
|
|
|
__ cmp(r0, r1);
|
|
|
|
__ b(ne, ¬_identical);
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
// 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(r0, r4, r4, FIRST_SPEC_OBJECT_TYPE);
|
|
|
|
__ b(ge, slow);
|
|
|
|
} else {
|
|
|
|
__ CompareObjectType(r0, r4, r4, HEAP_NUMBER_TYPE);
|
|
|
|
__ b(eq, &heap_number);
|
|
|
|
// Comparing JS objects with <=, >= is complicated.
|
|
|
|
if (cond != eq) {
|
|
|
|
__ cmp(r4, Operand(FIRST_SPEC_OBJECT_TYPE));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(ge, slow);
|
2012-11-14 15:59:45 +00:00
|
|
|
// 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) {
|
|
|
|
__ cmp(r4, Operand(ODDBALL_TYPE));
|
|
|
|
__ b(ne, &return_equal);
|
|
|
|
__ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ cmp(r0, r2);
|
|
|
|
__ b(ne, &return_equal);
|
|
|
|
if (cond == le) {
|
|
|
|
// undefined <= undefined should fail.
|
|
|
|
__ mov(r0, Operand(GREATER));
|
|
|
|
} else {
|
|
|
|
// undefined >= undefined should fail.
|
|
|
|
__ mov(r0, Operand(LESS));
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
2012-11-14 15:59:45 +00:00
|
|
|
__ Ret();
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&return_equal);
|
2011-01-26 08:32:54 +00:00
|
|
|
if (cond == lt) {
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(r0, Operand(GREATER)); // Things aren't less than themselves.
|
2011-01-26 08:32:54 +00:00
|
|
|
} else if (cond == gt) {
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(r0, Operand(LESS)); // Things aren't greater than themselves.
|
|
|
|
} else {
|
|
|
|
__ mov(r0, Operand(EQUAL)); // Things are <=, >=, ==, === themselves.
|
|
|
|
}
|
|
|
|
__ Ret();
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
// 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).
|
|
|
|
__ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset));
|
|
|
|
// Test that exponent bits are all set.
|
|
|
|
__ Sbfx(r3, r2, HeapNumber::kExponentShift, HeapNumber::kExponentBits);
|
|
|
|
// NaNs have all-one exponents so they sign extend to -1.
|
|
|
|
__ cmp(r3, Operand(-1));
|
|
|
|
__ b(ne, &return_equal);
|
|
|
|
|
|
|
|
// Shift out flag and all exponent bits, retaining only mantissa.
|
|
|
|
__ mov(r2, Operand(r2, LSL, HeapNumber::kNonMantissaBitsInTopWord));
|
|
|
|
// Or with all low-bits of mantissa.
|
|
|
|
__ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset));
|
|
|
|
__ orr(r0, r3, Operand(r2), SetCC);
|
|
|
|
// For equal we already have the right value in r0: 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) {
|
|
|
|
// All-zero means Infinity means equal.
|
|
|
|
__ Ret(eq);
|
|
|
|
if (cond == le) {
|
|
|
|
__ mov(r0, Operand(GREATER)); // NaN <= NaN should fail.
|
|
|
|
} else {
|
|
|
|
__ mov(r0, Operand(LESS)); // NaN >= NaN should fail.
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-14 15:59:45 +00:00
|
|
|
__ Ret();
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
2012-11-14 15:59:45 +00:00
|
|
|
// No fall through here.
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(¬_identical);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// See comment at call site.
|
|
|
|
static void EmitSmiNonsmiComparison(MacroAssembler* masm,
|
|
|
|
Register lhs,
|
|
|
|
Register rhs,
|
|
|
|
Label* lhs_not_nan,
|
|
|
|
Label* slow,
|
|
|
|
bool strict) {
|
|
|
|
ASSERT((lhs.is(r0) && rhs.is(r1)) ||
|
|
|
|
(lhs.is(r1) && rhs.is(r0)));
|
|
|
|
|
|
|
|
Label rhs_is_smi;
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(rhs, &rhs_is_smi);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Lhs is a Smi. Check whether the rhs is a heap number.
|
|
|
|
__ CompareObjectType(rhs, r4, r4, 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 r0 then there is already a non zero value in it.
|
|
|
|
if (!rhs.is(r0)) {
|
|
|
|
__ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne);
|
|
|
|
}
|
|
|
|
__ Ret(ne);
|
|
|
|
} else {
|
|
|
|
// Smi compared non-strictly with a non-Smi non-heap-number. Call
|
|
|
|
// the runtime.
|
|
|
|
__ b(ne, slow);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lhs is a smi, rhs is a number.
|
2013-04-07 04:34:20 +00:00
|
|
|
// Convert lhs to a double in d7.
|
|
|
|
__ SmiToDoubleVFPRegister(lhs, d7, r7, s15);
|
|
|
|
// Load the double from rhs, tagged HeapNumber r0, to d6.
|
|
|
|
__ sub(r7, rhs, Operand(kHeapObjectTag));
|
|
|
|
__ vldr(d6, r7, HeapNumber::kValueOffset);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// We now have both loaded as doubles but we can skip the lhs nan check
|
|
|
|
// since it's a smi.
|
|
|
|
__ jmp(lhs_not_nan);
|
|
|
|
|
|
|
|
__ bind(&rhs_is_smi);
|
|
|
|
// Rhs is a smi. Check whether the non-smi lhs is a heap number.
|
|
|
|
__ CompareObjectType(lhs, r4, r4, 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 r0 then there is already a non zero value in it.
|
|
|
|
if (!lhs.is(r0)) {
|
|
|
|
__ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne);
|
|
|
|
}
|
|
|
|
__ Ret(ne);
|
|
|
|
} else {
|
|
|
|
// Smi compared non-strictly with a non-smi non-heap-number. Call
|
|
|
|
// the runtime.
|
|
|
|
__ b(ne, slow);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rhs is a smi, lhs is a heap number.
|
2013-04-07 04:34:20 +00:00
|
|
|
// Load the double from lhs, tagged HeapNumber r1, to d7.
|
|
|
|
__ sub(r7, lhs, Operand(kHeapObjectTag));
|
|
|
|
__ vldr(d7, r7, HeapNumber::kValueOffset);
|
|
|
|
// Convert rhs to a double in d6 .
|
|
|
|
__ SmiToDoubleVFPRegister(rhs, d6, r7, s13);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Fall through to both_loaded_as_doubles.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// See comment at call site.
|
|
|
|
static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm,
|
|
|
|
Register lhs,
|
|
|
|
Register rhs) {
|
|
|
|
ASSERT((lhs.is(r0) && rhs.is(r1)) ||
|
|
|
|
(lhs.is(r1) && rhs.is(r0)));
|
|
|
|
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
// If either operand is a JS object or an oddball value, then they are
|
2010-08-25 09:44:44 +00:00
|
|
|
// not equal since their pointers are different.
|
|
|
|
// There is no test for undetectability in strict equality.
|
2011-09-21 14:46:54 +00:00
|
|
|
STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
|
2010-08-25 09:44:44 +00:00
|
|
|
Label first_non_object;
|
|
|
|
// Get the type of the first operand into r2 and compare it with
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
// FIRST_SPEC_OBJECT_TYPE.
|
|
|
|
__ CompareObjectType(rhs, r2, r2, FIRST_SPEC_OBJECT_TYPE);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(lt, &first_non_object);
|
|
|
|
|
|
|
|
// Return non-zero (r0 is not zero)
|
|
|
|
Label return_not_equal;
|
|
|
|
__ bind(&return_not_equal);
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&first_non_object);
|
|
|
|
// Check for oddballs: true, false, null, undefined.
|
|
|
|
__ cmp(r2, Operand(ODDBALL_TYPE));
|
|
|
|
__ b(eq, &return_not_equal);
|
|
|
|
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
__ CompareObjectType(lhs, r3, r3, FIRST_SPEC_OBJECT_TYPE);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(ge, &return_not_equal);
|
|
|
|
|
|
|
|
// Check for oddballs: true, false, null, undefined.
|
|
|
|
__ cmp(r3, Operand(ODDBALL_TYPE));
|
|
|
|
__ b(eq, &return_not_equal);
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Now that we have the types we might as well check for
|
|
|
|
// internalized-internalized.
|
|
|
|
// Ensure that no non-strings have the internalized bit set.
|
|
|
|
STATIC_ASSERT(LAST_TYPE < kNotStringTag + kIsInternalizedMask);
|
|
|
|
STATIC_ASSERT(kInternalizedTag != 0);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ and_(r2, r2, Operand(r3));
|
2013-02-28 17:03:34 +00:00
|
|
|
__ tst(r2, Operand(kIsInternalizedMask));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(ne, &return_not_equal);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
ASSERT((lhs.is(r0) && rhs.is(r1)) ||
|
|
|
|
(lhs.is(r1) && rhs.is(r0)));
|
|
|
|
|
|
|
|
__ CompareObjectType(rhs, r3, r2, HEAP_NUMBER_TYPE);
|
|
|
|
__ b(ne, not_heap_numbers);
|
|
|
|
__ ldr(r2, FieldMemOperand(lhs, HeapObject::kMapOffset));
|
|
|
|
__ cmp(r2, r3);
|
|
|
|
__ b(ne, 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.
|
2013-04-07 04:34:20 +00:00
|
|
|
__ sub(r7, rhs, Operand(kHeapObjectTag));
|
|
|
|
__ vldr(d6, r7, HeapNumber::kValueOffset);
|
|
|
|
__ sub(r7, lhs, Operand(kHeapObjectTag));
|
|
|
|
__ vldr(d7, r7, HeapNumber::kValueOffset);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ jmp(both_loaded_as_doubles);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Fast negative check for internalized-to-internalized equality.
|
|
|
|
static void EmitCheckForInternalizedStringsOrObjects(MacroAssembler* masm,
|
|
|
|
Register lhs,
|
|
|
|
Register rhs,
|
|
|
|
Label* possible_strings,
|
|
|
|
Label* not_both_strings) {
|
2010-08-25 09:44:44 +00:00
|
|
|
ASSERT((lhs.is(r0) && rhs.is(r1)) ||
|
|
|
|
(lhs.is(r1) && rhs.is(r0)));
|
|
|
|
|
|
|
|
// r2 is object type of rhs.
|
2013-02-28 17:03:34 +00:00
|
|
|
// Ensure that no non-strings have the internalized bit set.
|
2010-08-25 09:44:44 +00:00
|
|
|
Label object_test;
|
2013-02-28 17:03:34 +00:00
|
|
|
STATIC_ASSERT(kInternalizedTag != 0);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ tst(r2, Operand(kIsNotStringMask));
|
|
|
|
__ b(ne, &object_test);
|
2013-02-28 17:03:34 +00:00
|
|
|
__ tst(r2, Operand(kIsInternalizedMask));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, possible_strings);
|
|
|
|
__ CompareObjectType(lhs, r3, r3, FIRST_NONSTRING_TYPE);
|
|
|
|
__ b(ge, not_both_strings);
|
2013-02-28 17:03:34 +00:00
|
|
|
__ tst(r3, Operand(kIsInternalizedMask));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, possible_strings);
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Both are internalized. We already checked they weren't the same pointer
|
2010-08-25 09:44:44 +00:00
|
|
|
// so they are not equal.
|
|
|
|
__ mov(r0, Operand(NOT_EQUAL));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&object_test);
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
__ cmp(r2, Operand(FIRST_SPEC_OBJECT_TYPE));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(lt, not_both_strings);
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
__ CompareObjectType(lhs, r2, r3, FIRST_SPEC_OBJECT_TYPE);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(lt, 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.
|
|
|
|
__ ldr(r3, FieldMemOperand(rhs, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(r2, FieldMemOperand(r2, Map::kBitFieldOffset));
|
|
|
|
__ ldrb(r3, FieldMemOperand(r3, Map::kBitFieldOffset));
|
|
|
|
__ and_(r0, r2, Operand(r3));
|
|
|
|
__ and_(r0, r0, Operand(1 << Map::kIsUndetectable));
|
|
|
|
__ eor(r0, r0, Operand(1 << Map::kIsUndetectable));
|
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm,
|
|
|
|
Register object,
|
|
|
|
Register result,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register scratch3,
|
|
|
|
bool object_is_smi,
|
|
|
|
Label* not_found) {
|
|
|
|
// Use of registers. Register result is used as a temporary.
|
|
|
|
Register number_string_cache = result;
|
|
|
|
Register mask = scratch3;
|
|
|
|
|
|
|
|
// Load the number string cache.
|
|
|
|
__ LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex);
|
|
|
|
|
|
|
|
// Make the hash mask from the length of the number string cache. It
|
|
|
|
// contains two elements (number and string) for each cache entry.
|
|
|
|
__ ldr(mask, FieldMemOperand(number_string_cache, FixedArray::kLengthOffset));
|
|
|
|
// Divide length by two (length is a smi).
|
|
|
|
__ mov(mask, Operand(mask, ASR, kSmiTagSize + 1));
|
|
|
|
__ sub(mask, mask, Operand(1)); // Make mask.
|
|
|
|
|
|
|
|
// Calculate the entry in the number string cache. The hash value in the
|
|
|
|
// number string cache for smis is just the smi value, and the hash for
|
|
|
|
// doubles is the xor of the upper and lower words. See
|
|
|
|
// Heap::GetNumberStringCache.
|
2011-03-23 11:13:07 +00:00
|
|
|
Isolate* isolate = masm->isolate();
|
2010-08-25 09:44:44 +00:00
|
|
|
Label is_smi;
|
|
|
|
Label load_result_from_cache;
|
|
|
|
if (!object_is_smi) {
|
2011-01-26 07:44:45 +00:00
|
|
|
__ JumpIfSmi(object, &is_smi);
|
2013-04-07 04:34:20 +00:00
|
|
|
__ CheckMap(object,
|
|
|
|
scratch1,
|
|
|
|
Heap::kHeapNumberMapRootIndex,
|
|
|
|
not_found,
|
|
|
|
DONT_DO_SMI_CHECK);
|
|
|
|
|
|
|
|
STATIC_ASSERT(8 == kDoubleSize);
|
|
|
|
__ add(scratch1,
|
|
|
|
object,
|
|
|
|
Operand(HeapNumber::kValueOffset - kHeapObjectTag));
|
|
|
|
__ ldm(ia, scratch1, scratch1.bit() | scratch2.bit());
|
|
|
|
__ eor(scratch1, scratch1, Operand(scratch2));
|
|
|
|
__ and_(scratch1, scratch1, Operand(mask));
|
|
|
|
|
|
|
|
// Calculate address of entry in string cache: each entry consists
|
|
|
|
// of two pointer sized fields.
|
|
|
|
__ add(scratch1,
|
|
|
|
number_string_cache,
|
|
|
|
Operand(scratch1, LSL, kPointerSizeLog2 + 1));
|
|
|
|
|
|
|
|
Register probe = mask;
|
|
|
|
__ ldr(probe,
|
|
|
|
FieldMemOperand(scratch1, FixedArray::kHeaderSize));
|
|
|
|
__ JumpIfSmi(probe, not_found);
|
|
|
|
__ sub(scratch2, object, Operand(kHeapObjectTag));
|
|
|
|
__ vldr(d0, scratch2, HeapNumber::kValueOffset);
|
|
|
|
__ sub(probe, probe, Operand(kHeapObjectTag));
|
|
|
|
__ vldr(d1, probe, HeapNumber::kValueOffset);
|
|
|
|
__ VFPCompareAndSetFlags(d0, d1);
|
|
|
|
__ b(ne, not_found); // The cache did not contain this value.
|
|
|
|
__ b(&load_result_from_cache);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&is_smi);
|
|
|
|
Register scratch = scratch1;
|
|
|
|
__ and_(scratch, mask, Operand(object, ASR, 1));
|
|
|
|
// Calculate address of entry in string cache: each entry consists
|
|
|
|
// of two pointer sized fields.
|
|
|
|
__ add(scratch,
|
|
|
|
number_string_cache,
|
|
|
|
Operand(scratch, LSL, kPointerSizeLog2 + 1));
|
|
|
|
|
|
|
|
// Check if the entry is the smi we are looking for.
|
|
|
|
Register probe = mask;
|
|
|
|
__ ldr(probe, FieldMemOperand(scratch, FixedArray::kHeaderSize));
|
|
|
|
__ cmp(object, probe);
|
|
|
|
__ b(ne, not_found);
|
|
|
|
|
|
|
|
// Get the result from the cache.
|
|
|
|
__ bind(&load_result_from_cache);
|
|
|
|
__ ldr(result,
|
|
|
|
FieldMemOperand(scratch, FixedArray::kHeaderSize + kPointerSize));
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(isolate->counters()->number_to_string_native(),
|
2010-08-25 09:44:44 +00:00
|
|
|
1,
|
|
|
|
scratch1,
|
|
|
|
scratch2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NumberToStringStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label runtime;
|
|
|
|
|
|
|
|
__ ldr(r1, MemOperand(sp, 0));
|
|
|
|
|
|
|
|
// Generate code to lookup number in the number string cache.
|
|
|
|
GenerateLookupNumberStringCache(masm, r1, r0, r2, r3, r4, false, &runtime);
|
|
|
|
__ add(sp, sp, Operand(1 * kPointerSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&runtime);
|
|
|
|
// Handle number to string in the runtime system if not found in the cache.
|
|
|
|
__ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
static void ICCompareStub_CheckInputType(MacroAssembler* masm,
|
|
|
|
Register input,
|
|
|
|
Register scratch,
|
|
|
|
CompareIC::State expected,
|
|
|
|
Label* fail) {
|
|
|
|
Label ok;
|
|
|
|
if (expected == CompareIC::SMI) {
|
|
|
|
__ JumpIfNotSmi(input, fail);
|
2013-02-28 14:43:57 +00:00
|
|
|
} else if (expected == CompareIC::NUMBER) {
|
2012-11-14 15:59:45 +00:00
|
|
|
__ JumpIfSmi(input, &ok);
|
|
|
|
__ CheckMap(input, scratch, Heap::kHeapNumberMapRootIndex, fail,
|
|
|
|
DONT_DO_SMI_CHECK);
|
|
|
|
}
|
2013-02-28 17:03:34 +00:00
|
|
|
// We could be strict about internalized/non-internalized here, but as long as
|
2012-11-14 15:59:45 +00:00
|
|
|
// hydrogen doesn't care, the stub doesn't have to care either.
|
|
|
|
__ bind(&ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// On entry r1 and r2 are the values to be compared.
|
2010-08-25 09:44:44 +00:00
|
|
|
// On exit r0 is 0, positive or negative to indicate the result of
|
|
|
|
// the comparison.
|
2012-11-14 15:59:45 +00:00
|
|
|
void ICCompareStub::GenerateGeneric(MacroAssembler* masm) {
|
|
|
|
Register lhs = r1;
|
|
|
|
Register rhs = r0;
|
|
|
|
Condition cc = GetCondition();
|
|
|
|
|
|
|
|
Label miss;
|
|
|
|
ICCompareStub_CheckInputType(masm, lhs, r2, left_, &miss);
|
|
|
|
ICCompareStub_CheckInputType(masm, rhs, r3, right_, &miss);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
Label slow; // Call builtin.
|
|
|
|
Label not_smis, both_loaded_as_doubles, lhs_not_nan;
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
Label not_two_smis, smi_done;
|
|
|
|
__ orr(r2, r1, r0);
|
|
|
|
__ JumpIfNotSmi(r2, ¬_two_smis);
|
|
|
|
__ mov(r1, Operand(r1, ASR, 1));
|
|
|
|
__ sub(r0, r1, Operand(r0, ASR, 1));
|
|
|
|
__ Ret();
|
|
|
|
__ bind(¬_two_smis);
|
2010-09-15 10:14:25 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// 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.
|
2012-11-14 15:59:45 +00:00
|
|
|
EmitIdenticalObjectComparison(masm, &slow, cc);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
ASSERT_EQ(0, Smi::FromInt(0));
|
2012-11-14 15:59:45 +00:00
|
|
|
__ and_(r2, lhs, Operand(rhs));
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(r2, ¬_smis);
|
2010-08-25 09:44:44 +00:00
|
|
|
// 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. If VFP3 is supported the double values of the numbers have
|
|
|
|
// been loaded into d7 and d6. Otherwise, the double values have been loaded
|
|
|
|
// into r0, r1, r2, and r3.
|
2012-11-14 15:59:45 +00:00
|
|
|
EmitSmiNonsmiComparison(masm, lhs, rhs, &lhs_not_nan, &slow, strict());
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&both_loaded_as_doubles);
|
|
|
|
// The arguments have been converted to doubles and stored in d6 and d7, if
|
|
|
|
// VFP3 is supported, or in r0, r1, r2, and r3.
|
2011-03-23 11:13:07 +00:00
|
|
|
Isolate* isolate = masm->isolate();
|
2013-04-07 04:34:20 +00:00
|
|
|
__ bind(&lhs_not_nan);
|
|
|
|
Label no_nan;
|
|
|
|
// ARMv7 VFP3 instructions to implement double precision comparison.
|
|
|
|
__ VFPCompareAndSetFlags(d7, d6);
|
|
|
|
Label nan;
|
|
|
|
__ b(vs, &nan);
|
|
|
|
__ mov(r0, Operand(EQUAL), LeaveCC, eq);
|
|
|
|
__ mov(r0, Operand(LESS), LeaveCC, lt);
|
|
|
|
__ mov(r0, Operand(GREATER), LeaveCC, gt);
|
|
|
|
__ Ret();
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-04-07 04:34:20 +00:00
|
|
|
__ bind(&nan);
|
|
|
|
// If one of the sides was a NaN then the v flag is set. Load r0 with
|
|
|
|
// whatever it takes to make the comparison fail, since comparisons with NaN
|
|
|
|
// always fail.
|
|
|
|
if (cc == lt || cc == le) {
|
|
|
|
__ mov(r0, Operand(GREATER));
|
2010-08-25 09:44:44 +00:00
|
|
|
} else {
|
2013-04-07 04:34:20 +00:00
|
|
|
__ mov(r0, Operand(LESS));
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
2013-04-07 04:34:20 +00:00
|
|
|
__ Ret();
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(¬_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_.
|
2012-11-14 15:59:45 +00:00
|
|
|
if (strict()) {
|
2010-08-25 09:44:44 +00:00
|
|
|
// This returns non-equal for some object types, or falls through if it
|
|
|
|
// was not lucky.
|
2012-11-14 15:59:45 +00:00
|
|
|
EmitStrictTwoHeapObjectCompare(masm, lhs, rhs);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
Label check_for_internalized_strings;
|
2010-08-25 09:44:44 +00:00
|
|
|
Label flat_string_check;
|
|
|
|
// Check for heap-number-heap-number comparison. Can jump to slow case,
|
|
|
|
// or load both doubles into r0, r1, r2, r3 and jump to the code that handles
|
2013-02-28 17:03:34 +00:00
|
|
|
// that case. If the inputs are not doubles then jumps to
|
|
|
|
// check_for_internalized_strings.
|
2010-08-25 09:44:44 +00:00
|
|
|
// In this case r2 will contain the type of rhs_. Never falls through.
|
|
|
|
EmitCheckForTwoHeapNumbers(masm,
|
2012-11-14 15:59:45 +00:00
|
|
|
lhs,
|
|
|
|
rhs,
|
2010-08-25 09:44:44 +00:00
|
|
|
&both_loaded_as_doubles,
|
2013-02-28 17:03:34 +00:00
|
|
|
&check_for_internalized_strings,
|
2010-08-25 09:44:44 +00:00
|
|
|
&flat_string_check);
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
__ bind(&check_for_internalized_strings);
|
2010-08-25 09:44:44 +00:00
|
|
|
// In the strict case the EmitStrictTwoHeapObjectCompare already took care of
|
2013-02-28 17:03:34 +00:00
|
|
|
// internalized strings.
|
2012-11-14 15:59:45 +00:00
|
|
|
if (cc == eq && !strict()) {
|
2013-02-28 17:03:34 +00:00
|
|
|
// Returns an answer for two internalized strings or two detectable objects.
|
2010-08-25 09:44:44 +00:00
|
|
|
// Otherwise jumps to string case or not both strings case.
|
|
|
|
// Assumes that r2 is the type of rhs_ on entry.
|
2013-02-28 17:03:34 +00:00
|
|
|
EmitCheckForInternalizedStringsOrObjects(
|
|
|
|
masm, lhs, rhs, &flat_string_check, &slow);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for both being sequential ASCII strings, and inline if that is the
|
|
|
|
// case.
|
|
|
|
__ bind(&flat_string_check);
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
__ JumpIfNonSmisNotBothSequentialAsciiStrings(lhs, rhs, r2, r3, &slow);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(isolate->counters()->string_compare_native(), 1, r2, r3);
|
2012-11-14 15:59:45 +00:00
|
|
|
if (cc == eq) {
|
2011-05-05 11:40:08 +00:00
|
|
|
StringCompareStub::GenerateFlatAsciiStringEquals(masm,
|
2012-11-14 15:59:45 +00:00
|
|
|
lhs,
|
|
|
|
rhs,
|
2010-08-25 09:44:44 +00:00
|
|
|
r2,
|
|
|
|
r3,
|
2011-05-05 11:40:08 +00:00
|
|
|
r4);
|
|
|
|
} else {
|
|
|
|
StringCompareStub::GenerateCompareFlatAsciiStrings(masm,
|
2012-11-14 15:59:45 +00:00
|
|
|
lhs,
|
|
|
|
rhs,
|
2011-05-05 11:40:08 +00:00
|
|
|
r2,
|
|
|
|
r3,
|
|
|
|
r4,
|
|
|
|
r5);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
// Never falls through to here.
|
|
|
|
|
|
|
|
__ bind(&slow);
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
__ Push(lhs, rhs);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Figure out which native to call and setup the arguments.
|
|
|
|
Builtins::JavaScript native;
|
2012-11-14 15:59:45 +00:00
|
|
|
if (cc == eq) {
|
|
|
|
native = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
|
2010-08-25 09:44:44 +00:00
|
|
|
} else {
|
|
|
|
native = Builtins::COMPARE;
|
|
|
|
int ncr; // NaN compare result
|
2012-11-14 15:59:45 +00:00
|
|
|
if (cc == lt || cc == le) {
|
2010-08-25 09:44:44 +00:00
|
|
|
ncr = GREATER;
|
|
|
|
} else {
|
2012-11-14 15:59:45 +00:00
|
|
|
ASSERT(cc == gt || cc == ge); // remaining cases
|
2010-08-25 09:44:44 +00:00
|
|
|
ncr = LESS;
|
|
|
|
}
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(ncr)));
|
|
|
|
__ push(r0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
|
|
|
|
// tagged as a small integer.
|
2011-04-29 20:07:41 +00:00
|
|
|
__ InvokeBuiltin(native, JUMP_FUNCTION);
|
2012-11-14 15:59:45 +00:00
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-09 07:59:00 +00:00
|
|
|
// The stub expects its argument in the tos_ register and returns its result in
|
|
|
|
// it, too: zero for false, and a non-zero value for true.
|
2010-08-25 09:44:44 +00:00
|
|
|
void ToBooleanStub::Generate(MacroAssembler* masm) {
|
2011-09-15 11:30:45 +00:00
|
|
|
// This stub overrides SometimesSetsUpAFrame() to return false. That means
|
|
|
|
// we cannot call anything that could cause a GC from this stub.
|
2011-08-09 07:59:00 +00:00
|
|
|
Label patch;
|
2011-06-22 08:28:35 +00:00
|
|
|
const Register map = r9.is(tos_) ? r7 : r9;
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-08-09 07:59:00 +00:00
|
|
|
// undefined -> false.
|
2011-08-11 07:22:16 +00:00
|
|
|
CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false);
|
2011-08-09 07:59:00 +00:00
|
|
|
|
|
|
|
// Boolean -> its value.
|
2011-08-11 07:22:16 +00:00
|
|
|
CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false);
|
|
|
|
CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true);
|
2011-08-09 07:59:00 +00:00
|
|
|
|
|
|
|
// 'null' -> false.
|
2011-08-11 07:22:16 +00:00
|
|
|
CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false);
|
2011-08-09 07:59:00 +00:00
|
|
|
|
|
|
|
if (types_.Contains(SMI)) {
|
|
|
|
// Smis: 0 -> false, all other -> true
|
|
|
|
__ tst(tos_, Operand(kSmiTagMask));
|
|
|
|
// tos_ contains the correct return value already
|
|
|
|
__ Ret(eq);
|
|
|
|
} else if (types_.NeedsMap()) {
|
|
|
|
// If we need a map later and have a Smi -> patch.
|
|
|
|
__ JumpIfSmi(tos_, &patch);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (types_.NeedsMap()) {
|
|
|
|
__ ldr(map, FieldMemOperand(tos_, HeapObject::kMapOffset));
|
|
|
|
|
2011-08-11 07:22:16 +00:00
|
|
|
if (types_.CanBeUndetectable()) {
|
|
|
|
__ ldrb(ip, FieldMemOperand(map, Map::kBitFieldOffset));
|
|
|
|
__ tst(ip, Operand(1 << Map::kIsUndetectable));
|
|
|
|
// Undetectable -> false.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ mov(tos_, Operand::Zero(), LeaveCC, ne);
|
2011-08-11 07:22:16 +00:00
|
|
|
__ Ret(ne);
|
|
|
|
}
|
2011-08-09 07:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (types_.Contains(SPEC_OBJECT)) {
|
|
|
|
// Spec object -> true.
|
|
|
|
__ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE);
|
|
|
|
// tos_ contains the correct non-zero return value already.
|
|
|
|
__ Ret(ge);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (types_.Contains(STRING)) {
|
|
|
|
// String value -> false iff empty.
|
2013-04-07 04:34:20 +00:00
|
|
|
__ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE);
|
|
|
|
__ ldr(tos_, FieldMemOperand(tos_, String::kLengthOffset), lt);
|
|
|
|
__ Ret(lt); // the string length is OK as the return value
|
2011-08-09 07:59:00 +00:00
|
|
|
}
|
2011-06-22 08:28:35 +00:00
|
|
|
|
2011-08-09 07:59:00 +00:00
|
|
|
if (types_.Contains(HEAP_NUMBER)) {
|
|
|
|
// Heap number -> false iff +0, -0, or NaN.
|
|
|
|
Label not_heap_number;
|
|
|
|
__ CompareRoot(map, Heap::kHeapNumberMapRootIndex);
|
|
|
|
__ b(ne, ¬_heap_number);
|
2012-08-10 12:24:06 +00:00
|
|
|
|
2013-04-07 04:34:20 +00:00
|
|
|
__ vldr(d1, FieldMemOperand(tos_, HeapNumber::kValueOffset));
|
|
|
|
__ VFPCompareAndSetFlags(d1, 0.0);
|
|
|
|
// "tos_" is a register, and contains a non zero value by default.
|
|
|
|
// Hence we only need to overwrite "tos_" with zero to return false for
|
|
|
|
// FP_ZERO or FP_NAN cases. Otherwise, by default it returns true.
|
|
|
|
__ mov(tos_, Operand::Zero(), LeaveCC, eq); // for FP_ZERO
|
|
|
|
__ mov(tos_, Operand::Zero(), LeaveCC, vs); // for FP_NAN
|
2011-08-09 07:59:00 +00:00
|
|
|
__ Ret();
|
|
|
|
__ bind(¬_heap_number);
|
|
|
|
}
|
|
|
|
|
2011-08-11 07:22:16 +00:00
|
|
|
__ bind(&patch);
|
|
|
|
GenerateTypeTransition(masm);
|
2011-08-09 07:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ToBooleanStub::CheckOddball(MacroAssembler* masm,
|
|
|
|
Type type,
|
|
|
|
Heap::RootListIndex value,
|
2011-08-11 07:22:16 +00:00
|
|
|
bool result) {
|
2011-08-09 07:59:00 +00:00
|
|
|
if (types_.Contains(type)) {
|
|
|
|
// If we see an expected oddball, return its ToBoolean value tos_.
|
|
|
|
__ LoadRoot(ip, value);
|
|
|
|
__ cmp(tos_, ip);
|
|
|
|
// The value of a root is never NULL, so we can avoid loading a non-null
|
|
|
|
// value into tos_ when we want to return 'true'.
|
|
|
|
if (!result) {
|
2013-01-07 09:43:12 +00:00
|
|
|
__ mov(tos_, Operand::Zero(), LeaveCC, eq);
|
2011-08-09 07:59:00 +00:00
|
|
|
}
|
|
|
|
__ Ret(eq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) {
|
|
|
|
if (!tos_.is(r3)) {
|
|
|
|
__ mov(r3, Operand(tos_));
|
|
|
|
}
|
|
|
|
__ mov(r2, Operand(Smi::FromInt(tos_.code())));
|
|
|
|
__ mov(r1, Operand(Smi::FromInt(types_.ToByte())));
|
|
|
|
__ Push(r3, r2, r1);
|
|
|
|
// Patch the caller to an appropriate specialized stub and return the
|
|
|
|
// operation result to the caller of the stub.
|
|
|
|
__ TailCallExternalReference(
|
|
|
|
ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()),
|
|
|
|
3,
|
|
|
|
1);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
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.
|
|
|
|
__ stm(db_w, sp, kCallerSaved | lr.bit());
|
2013-01-23 16:29:48 +00:00
|
|
|
|
|
|
|
const Register scratch = r1;
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
if (save_doubles_ == kSaveFPRegs) {
|
2013-04-19 16:01:57 +00:00
|
|
|
__ SaveFPRegs(sp, scratch);
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
const int argument_count = 1;
|
|
|
|
const int fp_argument_count = 0;
|
|
|
|
|
|
|
|
AllowExternalCallThatCantCauseGC scope(masm);
|
|
|
|
__ PrepareCallCFunction(argument_count, fp_argument_count, scratch);
|
2013-04-24 07:39:35 +00:00
|
|
|
__ mov(r0, Operand(ExternalReference::isolate_address(masm->isolate())));
|
2011-09-19 18:36:47 +00:00
|
|
|
__ CallCFunction(
|
|
|
|
ExternalReference::store_buffer_overflow_function(masm->isolate()),
|
|
|
|
argument_count);
|
|
|
|
if (save_doubles_ == kSaveFPRegs) {
|
2013-04-19 16:01:57 +00:00
|
|
|
__ RestoreFPRegs(sp, scratch);
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
__ ldm(ia_w, sp, kCallerSaved | pc.bit()); // Also pop pc to get Ret(0).
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-13 11:08:25 +00:00
|
|
|
void UnaryOpStub::PrintName(StringStream* stream) {
|
2011-04-28 17:49:55 +00:00
|
|
|
const char* op_name = Token::Name(op_);
|
2011-04-28 21:02:14 +00:00
|
|
|
const char* overwrite_name = NULL; // Make g++ happy.
|
2011-04-28 17:49:55 +00:00
|
|
|
switch (mode_) {
|
|
|
|
case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break;
|
|
|
|
case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break;
|
|
|
|
}
|
2011-07-13 11:08:25 +00:00
|
|
|
stream->Add("UnaryOpStub_%s_%s_%s",
|
|
|
|
op_name,
|
|
|
|
overwrite_name,
|
|
|
|
UnaryOpIC::GetName(operand_type_));
|
2011-04-28 17:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(svenpanne): Use virtual functions instead of switch.
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::Generate(MacroAssembler* masm) {
|
2011-04-28 17:49:55 +00:00
|
|
|
switch (operand_type_) {
|
2011-05-24 12:20:16 +00:00
|
|
|
case UnaryOpIC::UNINITIALIZED:
|
2011-04-28 17:49:55 +00:00
|
|
|
GenerateTypeTransition(masm);
|
|
|
|
break;
|
2011-05-24 12:20:16 +00:00
|
|
|
case UnaryOpIC::SMI:
|
2011-04-28 17:49:55 +00:00
|
|
|
GenerateSmiStub(masm);
|
|
|
|
break;
|
2013-02-28 14:43:57 +00:00
|
|
|
case UnaryOpIC::NUMBER:
|
|
|
|
GenerateNumberStub(masm);
|
2011-04-28 17:49:55 +00:00
|
|
|
break;
|
2011-05-24 12:20:16 +00:00
|
|
|
case UnaryOpIC::GENERIC:
|
2011-04-28 17:49:55 +00:00
|
|
|
GenerateGenericStub(masm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) {
|
2011-07-01 07:50:46 +00:00
|
|
|
__ mov(r3, Operand(r0)); // the operand
|
|
|
|
__ mov(r2, Operand(Smi::FromInt(op_)));
|
|
|
|
__ mov(r1, Operand(Smi::FromInt(mode_)));
|
2011-04-28 17:49:55 +00:00
|
|
|
__ mov(r0, Operand(Smi::FromInt(operand_type_)));
|
|
|
|
__ Push(r3, r2, r1, r0);
|
|
|
|
|
|
|
|
__ TailCallExternalReference(
|
2011-07-01 07:50:46 +00:00
|
|
|
ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1);
|
2011-04-28 17:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(svenpanne): Use virtual functions instead of switch.
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) {
|
2011-04-28 17:49:55 +00:00
|
|
|
switch (op_) {
|
|
|
|
case Token::SUB:
|
|
|
|
GenerateSmiStubSub(masm);
|
|
|
|
break;
|
|
|
|
case Token::BIT_NOT:
|
|
|
|
GenerateSmiStubBitNot(masm);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) {
|
2011-04-28 17:49:55 +00:00
|
|
|
Label non_smi, slow;
|
|
|
|
GenerateSmiCodeSub(masm, &non_smi, &slow);
|
|
|
|
__ bind(&non_smi);
|
|
|
|
__ bind(&slow);
|
|
|
|
GenerateTypeTransition(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) {
|
2011-04-28 17:49:55 +00:00
|
|
|
Label non_smi;
|
|
|
|
GenerateSmiCodeBitNot(masm, &non_smi);
|
|
|
|
__ bind(&non_smi);
|
|
|
|
GenerateTypeTransition(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm,
|
|
|
|
Label* non_smi,
|
|
|
|
Label* slow) {
|
2011-04-28 17:49:55 +00:00
|
|
|
__ JumpIfNotSmi(r0, non_smi);
|
|
|
|
|
|
|
|
// The result of negating zero or the smallest negative smi is not a smi.
|
|
|
|
__ bic(ip, r0, Operand(0x80000000), SetCC);
|
|
|
|
__ b(eq, slow);
|
|
|
|
|
|
|
|
// Return '0 - value'.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ rsb(r0, r0, Operand::Zero());
|
2011-04-28 17:49:55 +00:00
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateSmiCodeBitNot(MacroAssembler* masm,
|
|
|
|
Label* non_smi) {
|
2011-04-28 17:49:55 +00:00
|
|
|
__ JumpIfNotSmi(r0, non_smi);
|
|
|
|
|
|
|
|
// Flip bits and revert inverted smi-tag.
|
|
|
|
__ mvn(r0, Operand(r0));
|
|
|
|
__ bic(r0, r0, Operand(kSmiTagMask));
|
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(svenpanne): Use virtual functions instead of switch.
|
2013-02-28 14:43:57 +00:00
|
|
|
void UnaryOpStub::GenerateNumberStub(MacroAssembler* masm) {
|
2011-04-28 17:49:55 +00:00
|
|
|
switch (op_) {
|
|
|
|
case Token::SUB:
|
2013-02-28 14:43:57 +00:00
|
|
|
GenerateNumberStubSub(masm);
|
2011-04-28 17:49:55 +00:00
|
|
|
break;
|
|
|
|
case Token::BIT_NOT:
|
2013-02-28 14:43:57 +00:00
|
|
|
GenerateNumberStubBitNot(masm);
|
2011-04-28 17:49:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 14:43:57 +00:00
|
|
|
void UnaryOpStub::GenerateNumberStubSub(MacroAssembler* masm) {
|
2011-05-18 17:32:36 +00:00
|
|
|
Label non_smi, slow, call_builtin;
|
|
|
|
GenerateSmiCodeSub(masm, &non_smi, &call_builtin);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ bind(&non_smi);
|
|
|
|
GenerateHeapNumberCodeSub(masm, &slow);
|
|
|
|
__ bind(&slow);
|
|
|
|
GenerateTypeTransition(masm);
|
2011-05-18 17:32:36 +00:00
|
|
|
__ bind(&call_builtin);
|
|
|
|
GenerateGenericCodeFallback(masm);
|
2011-04-28 17:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 14:43:57 +00:00
|
|
|
void UnaryOpStub::GenerateNumberStubBitNot(MacroAssembler* masm) {
|
2011-04-28 17:49:55 +00:00
|
|
|
Label non_smi, slow;
|
|
|
|
GenerateSmiCodeBitNot(masm, &non_smi);
|
|
|
|
__ bind(&non_smi);
|
|
|
|
GenerateHeapNumberCodeBitNot(masm, &slow);
|
|
|
|
__ bind(&slow);
|
|
|
|
GenerateTypeTransition(masm);
|
|
|
|
}
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm,
|
|
|
|
Label* slow) {
|
2011-04-28 17:49:55 +00:00
|
|
|
EmitCheckForHeapNumber(masm, r0, r1, r6, slow);
|
|
|
|
// r0 is a heap number. Get a new heap number in r1.
|
|
|
|
if (mode_ == UNARY_OVERWRITE) {
|
|
|
|
__ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset));
|
|
|
|
__ eor(r2, r2, Operand(HeapNumber::kSignMask)); // Flip sign.
|
|
|
|
__ str(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset));
|
|
|
|
} else {
|
|
|
|
Label slow_allocate_heapnumber, heapnumber_allocated;
|
|
|
|
__ AllocateHeapNumber(r1, r2, r3, r6, &slow_allocate_heapnumber);
|
|
|
|
__ jmp(&heapnumber_allocated);
|
|
|
|
|
|
|
|
__ bind(&slow_allocate_heapnumber);
|
2011-09-15 11:30:45 +00:00
|
|
|
{
|
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
|
|
|
__ push(r0);
|
|
|
|
__ CallRuntime(Runtime::kNumberAlloc, 0);
|
|
|
|
__ mov(r1, Operand(r0));
|
|
|
|
__ pop(r0);
|
|
|
|
}
|
2011-04-28 17:49:55 +00:00
|
|
|
|
|
|
|
__ bind(&heapnumber_allocated);
|
|
|
|
__ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset));
|
|
|
|
__ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset));
|
|
|
|
__ str(r3, FieldMemOperand(r1, HeapNumber::kMantissaOffset));
|
|
|
|
__ eor(r2, r2, Operand(HeapNumber::kSignMask)); // Flip sign.
|
|
|
|
__ str(r2, FieldMemOperand(r1, HeapNumber::kExponentOffset));
|
|
|
|
__ mov(r0, Operand(r1));
|
|
|
|
}
|
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-12 11:25:50 +00:00
|
|
|
void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm,
|
|
|
|
Label* slow) {
|
2011-04-28 17:49:55 +00:00
|
|
|
EmitCheckForHeapNumber(masm, r0, r1, r6, slow);
|
2013-04-22 21:30:57 +00:00
|
|
|
|
2013-03-12 11:25:50 +00:00
|
|
|
// Convert the heap number in r0 to an untagged integer in r1.
|
2013-04-22 21:30:57 +00:00
|
|
|
__ vldr(d0, FieldMemOperand(r0, HeapNumber::kValueOffset));
|
|
|
|
__ ECMAToInt32(r1, d0, r2, r3, r4, d1);
|
2011-04-28 17:49:55 +00:00
|
|
|
|
|
|
|
// Do the bitwise operation and check if the result fits in a smi.
|
|
|
|
Label try_float;
|
|
|
|
__ mvn(r1, Operand(r1));
|
2013-03-12 11:25:50 +00:00
|
|
|
__ cmn(r1, Operand(0x40000000));
|
2011-04-28 17:49:55 +00:00
|
|
|
__ b(mi, &try_float);
|
|
|
|
|
|
|
|
// Tag the result as a smi and we're done.
|
|
|
|
__ mov(r0, Operand(r1, LSL, kSmiTagSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Try to store the result in a heap number.
|
|
|
|
__ bind(&try_float);
|
|
|
|
if (mode_ == UNARY_NO_OVERWRITE) {
|
|
|
|
Label slow_allocate_heapnumber, heapnumber_allocated;
|
2013-03-12 11:25:50 +00:00
|
|
|
__ AllocateHeapNumber(r0, r3, r4, r6, &slow_allocate_heapnumber);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ jmp(&heapnumber_allocated);
|
|
|
|
|
|
|
|
__ bind(&slow_allocate_heapnumber);
|
2011-09-15 11:30:45 +00:00
|
|
|
{
|
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
2013-03-12 11:25:50 +00:00
|
|
|
// Push the lower bit of the result (left shifted to look like a smi).
|
|
|
|
__ mov(r2, Operand(r1, LSL, 31));
|
|
|
|
// Push the 31 high bits (bit 0 cleared to look like a smi).
|
|
|
|
__ bic(r1, r1, Operand(1));
|
|
|
|
__ Push(r2, r1);
|
2011-09-15 11:30:45 +00:00
|
|
|
__ CallRuntime(Runtime::kNumberAlloc, 0);
|
2013-03-12 11:25:50 +00:00
|
|
|
__ Pop(r2, r1); // Restore the result.
|
|
|
|
__ orr(r1, r1, Operand(r2, LSR, 31));
|
2011-09-15 11:30:45 +00:00
|
|
|
}
|
2011-04-28 17:49:55 +00:00
|
|
|
__ bind(&heapnumber_allocated);
|
|
|
|
}
|
|
|
|
|
2013-04-07 04:34:20 +00:00
|
|
|
__ vmov(s0, r1);
|
|
|
|
__ vcvt_f64_s32(d0, s0);
|
|
|
|
__ vstr(d0, FieldMemOperand(r0, HeapNumber::kValueOffset));
|
|
|
|
__ Ret();
|
2011-04-28 17:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(svenpanne): Use virtual functions instead of switch.
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) {
|
2011-04-28 17:49:55 +00:00
|
|
|
switch (op_) {
|
|
|
|
case Token::SUB:
|
|
|
|
GenerateGenericStubSub(masm);
|
|
|
|
break;
|
|
|
|
case Token::BIT_NOT:
|
|
|
|
GenerateGenericStubBitNot(masm);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) {
|
2011-04-28 17:49:55 +00:00
|
|
|
Label non_smi, slow;
|
|
|
|
GenerateSmiCodeSub(masm, &non_smi, &slow);
|
|
|
|
__ bind(&non_smi);
|
|
|
|
GenerateHeapNumberCodeSub(masm, &slow);
|
|
|
|
__ bind(&slow);
|
|
|
|
GenerateGenericCodeFallback(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) {
|
2011-04-28 17:49:55 +00:00
|
|
|
Label non_smi, slow;
|
|
|
|
GenerateSmiCodeBitNot(masm, &non_smi);
|
|
|
|
__ bind(&non_smi);
|
|
|
|
GenerateHeapNumberCodeBitNot(masm, &slow);
|
|
|
|
__ bind(&slow);
|
|
|
|
GenerateGenericCodeFallback(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) {
|
2011-04-28 17:49:55 +00:00
|
|
|
// Handle the slow case by jumping to the JavaScript builtin.
|
|
|
|
__ push(r0);
|
|
|
|
switch (op_) {
|
|
|
|
case Token::SUB:
|
2011-04-29 20:07:41 +00:00
|
|
|
__ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION);
|
2011-04-28 17:49:55 +00:00
|
|
|
break;
|
|
|
|
case Token::BIT_NOT:
|
2011-04-29 20:07:41 +00:00
|
|
|
__ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION);
|
2011-04-28 17:49:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-22 21:30:57 +00:00
|
|
|
// Generates code to call a C function to do a double operation.
|
|
|
|
// This code never falls through, but returns with a heap number containing
|
|
|
|
// the result in r0.
|
|
|
|
// Register heapnumber_result must be a heap number in which the
|
|
|
|
// result of the operation will be stored.
|
|
|
|
// Requires the following layout on entry:
|
|
|
|
// d0: Left value.
|
|
|
|
// d1: Right value.
|
|
|
|
// If soft float ABI, use also r0, r1, r2, r3.
|
|
|
|
static void CallCCodeForDoubleOperation(MacroAssembler* masm,
|
|
|
|
Token::Value op,
|
|
|
|
Register heap_number_result,
|
|
|
|
Register scratch) {
|
|
|
|
// Assert that heap_number_result is callee-saved.
|
|
|
|
// We currently always use r5 to pass it.
|
|
|
|
ASSERT(heap_number_result.is(r5));
|
|
|
|
|
|
|
|
// Push the current return address before the C call. Return will be
|
|
|
|
// through pop(pc) below.
|
|
|
|
__ push(lr);
|
|
|
|
__ PrepareCallCFunction(0, 2, scratch);
|
|
|
|
if (!masm->use_eabi_hardfloat()) {
|
|
|
|
__ vmov(r0, r1, d0);
|
|
|
|
__ vmov(r2, r3, d1);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
AllowExternalCallThatCantCauseGC scope(masm);
|
|
|
|
__ CallCFunction(
|
|
|
|
ExternalReference::double_fp_operation(op, masm->isolate()), 0, 2);
|
|
|
|
}
|
|
|
|
// Store answer in the overwritable heap number. Double returned in
|
|
|
|
// registers r0 and r1 or in d0.
|
|
|
|
if (masm->use_eabi_hardfloat()) {
|
|
|
|
__ vstr(d0, FieldMemOperand(heap_number_result, HeapNumber::kValueOffset));
|
|
|
|
} else {
|
|
|
|
__ Strd(r0, r1,
|
|
|
|
FieldMemOperand(heap_number_result, HeapNumber::kValueOffset));
|
|
|
|
}
|
|
|
|
// Place heap_number_result in r0 and return to the pushed return address.
|
|
|
|
__ mov(r0, Operand(heap_number_result));
|
|
|
|
__ pop(pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
void BinaryOpStub::Initialize() {
|
2013-04-07 04:34:20 +00:00
|
|
|
platform_specific_bit_ = true; // VFP2 is a base requirement for V8
|
2012-11-14 15:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) {
|
2011-01-25 14:52:35 +00:00
|
|
|
Label get_result;
|
|
|
|
|
|
|
|
__ Push(r1, r0);
|
|
|
|
|
|
|
|
__ mov(r2, Operand(Smi::FromInt(MinorKey())));
|
2012-11-14 15:59:45 +00:00
|
|
|
__ push(r2);
|
2011-01-25 14:52:35 +00:00
|
|
|
|
|
|
|
__ TailCallExternalReference(
|
2011-05-24 12:20:16 +00:00
|
|
|
ExternalReference(IC_Utility(IC::kBinaryOp_Patch),
|
2011-03-22 13:20:04 +00:00
|
|
|
masm->isolate()),
|
2012-11-14 15:59:45 +00:00
|
|
|
3,
|
2011-01-25 14:52:35 +00:00
|
|
|
1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(
|
2011-01-25 14:52:35 +00:00
|
|
|
MacroAssembler* masm) {
|
2010-12-07 11:31:57 +00:00
|
|
|
UNIMPLEMENTED();
|
2011-01-25 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
void BinaryOpStub_GenerateSmiSmiOperation(MacroAssembler* masm,
|
|
|
|
Token::Value op) {
|
2011-01-26 07:41:02 +00:00
|
|
|
Register left = r1;
|
|
|
|
Register right = r0;
|
2011-01-26 20:25:33 +00:00
|
|
|
Register scratch1 = r7;
|
|
|
|
Register scratch2 = r9;
|
2011-01-26 07:41:02 +00:00
|
|
|
|
|
|
|
ASSERT(right.is(r0));
|
2011-01-26 20:25:33 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-01-26 07:41:02 +00:00
|
|
|
|
2011-01-26 20:25:33 +00:00
|
|
|
Label not_smi_result;
|
2012-11-14 15:59:45 +00:00
|
|
|
switch (op) {
|
2011-01-26 07:41:02 +00:00
|
|
|
case Token::ADD:
|
2011-01-26 08:00:51 +00:00
|
|
|
__ add(right, left, Operand(right), SetCC); // Add optimistically.
|
2011-01-26 07:41:02 +00:00
|
|
|
__ Ret(vc);
|
|
|
|
__ sub(right, right, Operand(left)); // Revert optimistic add.
|
|
|
|
break;
|
|
|
|
case Token::SUB:
|
|
|
|
__ sub(right, left, Operand(right), SetCC); // Subtract optimistically.
|
|
|
|
__ Ret(vc);
|
|
|
|
__ sub(right, left, Operand(right)); // Revert optimistic subtract.
|
|
|
|
break;
|
2011-01-26 20:25:33 +00:00
|
|
|
case Token::MUL:
|
|
|
|
// Remove tag from one of the operands. This way the multiplication result
|
|
|
|
// will be a smi if it fits the smi range.
|
|
|
|
__ SmiUntag(ip, right);
|
|
|
|
// Do multiplication
|
|
|
|
// scratch1 = lower 32 bits of ip * left.
|
|
|
|
// scratch2 = higher 32 bits of ip * left.
|
|
|
|
__ smull(scratch1, scratch2, left, ip);
|
|
|
|
// Check for overflowing the smi range - no overflow if higher 33 bits of
|
|
|
|
// the result are identical.
|
|
|
|
__ mov(ip, Operand(scratch1, ASR, 31));
|
|
|
|
__ cmp(ip, Operand(scratch2));
|
|
|
|
__ b(ne, ¬_smi_result);
|
|
|
|
// Go slow on zero result to handle -0.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(scratch1, Operand::Zero());
|
2011-01-26 20:25:33 +00:00
|
|
|
__ mov(right, Operand(scratch1), LeaveCC, ne);
|
|
|
|
__ Ret(ne);
|
|
|
|
// We need -0 if we were multiplying a negative number with 0 to get 0.
|
|
|
|
// We know one of them was zero.
|
|
|
|
__ add(scratch2, right, Operand(left), SetCC);
|
|
|
|
__ mov(right, Operand(Smi::FromInt(0)), LeaveCC, pl);
|
|
|
|
__ Ret(pl); // Return smi 0 if the non-zero one was positive.
|
|
|
|
// We fall through here if we multiplied a negative number with 0, because
|
|
|
|
// that would mean we should produce -0.
|
|
|
|
break;
|
2012-12-20 16:31:19 +00:00
|
|
|
case Token::DIV: {
|
|
|
|
Label div_with_sdiv;
|
|
|
|
|
|
|
|
// Check for 0 divisor.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(right, Operand::Zero());
|
2012-12-20 16:31:19 +00:00
|
|
|
__ b(eq, ¬_smi_result);
|
|
|
|
|
2011-02-01 16:38:25 +00:00
|
|
|
// Check for power of two on the right hand side.
|
2012-12-20 16:31:19 +00:00
|
|
|
__ sub(scratch1, right, Operand(1));
|
|
|
|
__ tst(scratch1, right);
|
|
|
|
if (CpuFeatures::IsSupported(SUDIV)) {
|
|
|
|
__ b(ne, &div_with_sdiv);
|
|
|
|
// Check for no remainder.
|
|
|
|
__ tst(left, scratch1);
|
|
|
|
__ b(ne, ¬_smi_result);
|
|
|
|
// Check for positive left hand side.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(left, Operand::Zero());
|
2012-12-20 16:31:19 +00:00
|
|
|
__ b(mi, &div_with_sdiv);
|
|
|
|
} else {
|
|
|
|
__ b(ne, ¬_smi_result);
|
|
|
|
// Check for positive and no remainder.
|
|
|
|
__ orr(scratch2, scratch1, Operand(0x80000000u));
|
|
|
|
__ tst(left, scratch2);
|
|
|
|
__ b(ne, ¬_smi_result);
|
|
|
|
}
|
2011-02-01 16:38:25 +00:00
|
|
|
|
|
|
|
// Perform division by shifting.
|
2013-04-18 10:32:18 +00:00
|
|
|
__ clz(scratch1, scratch1);
|
2011-02-01 16:38:25 +00:00
|
|
|
__ rsb(scratch1, scratch1, Operand(31));
|
|
|
|
__ mov(right, Operand(left, LSR, scratch1));
|
|
|
|
__ Ret();
|
2012-12-20 16:31:19 +00:00
|
|
|
|
|
|
|
if (CpuFeatures::IsSupported(SUDIV)) {
|
|
|
|
Label result_not_zero;
|
|
|
|
|
|
|
|
__ bind(&div_with_sdiv);
|
|
|
|
// Do division.
|
|
|
|
__ sdiv(scratch1, left, right);
|
|
|
|
// Check that the remainder is zero.
|
|
|
|
__ mls(scratch2, scratch1, right, left);
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(scratch2, Operand::Zero());
|
2012-12-20 16:31:19 +00:00
|
|
|
__ b(ne, ¬_smi_result);
|
|
|
|
// Check for negative zero result.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(scratch1, Operand::Zero());
|
2012-12-20 16:31:19 +00:00
|
|
|
__ b(ne, &result_not_zero);
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(right, Operand::Zero());
|
2012-12-20 16:31:19 +00:00
|
|
|
__ b(lt, ¬_smi_result);
|
|
|
|
__ bind(&result_not_zero);
|
|
|
|
// Check for the corner case of dividing the most negative smi by -1.
|
|
|
|
__ cmp(scratch1, Operand(0x40000000));
|
|
|
|
__ b(eq, ¬_smi_result);
|
|
|
|
// Tag and return the result.
|
|
|
|
__ SmiTag(right, scratch1);
|
|
|
|
__ Ret();
|
|
|
|
}
|
2011-02-01 16:38:25 +00:00
|
|
|
break;
|
2012-12-20 16:31:19 +00:00
|
|
|
}
|
|
|
|
case Token::MOD: {
|
|
|
|
Label modulo_with_sdiv;
|
|
|
|
|
|
|
|
if (CpuFeatures::IsSupported(SUDIV)) {
|
|
|
|
// Check for x % 0.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(right, Operand::Zero());
|
2012-12-20 16:31:19 +00:00
|
|
|
__ b(eq, ¬_smi_result);
|
|
|
|
|
|
|
|
// Check for two positive smis.
|
|
|
|
__ orr(scratch1, left, Operand(right));
|
|
|
|
__ tst(scratch1, Operand(0x80000000u));
|
|
|
|
__ b(ne, &modulo_with_sdiv);
|
|
|
|
|
|
|
|
// Check for power of two on the right hand side.
|
|
|
|
__ sub(scratch1, right, Operand(1));
|
|
|
|
__ tst(scratch1, right);
|
|
|
|
__ b(ne, &modulo_with_sdiv);
|
|
|
|
} else {
|
|
|
|
// Check for two positive smis.
|
|
|
|
__ orr(scratch1, left, Operand(right));
|
|
|
|
__ tst(scratch1, Operand(0x80000000u));
|
|
|
|
__ b(ne, ¬_smi_result);
|
2011-02-01 16:38:25 +00:00
|
|
|
|
2012-12-20 16:31:19 +00:00
|
|
|
// Check for power of two on the right hand side.
|
|
|
|
__ JumpIfNotPowerOfTwoOrZero(right, scratch1, ¬_smi_result);
|
|
|
|
}
|
2011-02-01 16:38:25 +00:00
|
|
|
|
2012-12-20 16:31:19 +00:00
|
|
|
// Perform modulus by masking (scratch1 contains right - 1).
|
2011-02-01 16:38:25 +00:00
|
|
|
__ and_(right, left, Operand(scratch1));
|
|
|
|
__ Ret();
|
2012-12-20 16:31:19 +00:00
|
|
|
|
|
|
|
if (CpuFeatures::IsSupported(SUDIV)) {
|
|
|
|
__ bind(&modulo_with_sdiv);
|
|
|
|
__ mov(scratch2, right);
|
|
|
|
// Perform modulus with sdiv and mls.
|
|
|
|
__ sdiv(scratch1, left, right);
|
|
|
|
__ mls(right, scratch1, right, left);
|
|
|
|
// Return if the result is not 0.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(right, Operand::Zero());
|
2012-12-20 16:31:19 +00:00
|
|
|
__ Ret(ne);
|
|
|
|
// The result is 0, check for -0 case.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(left, Operand::Zero());
|
2012-12-20 16:31:19 +00:00
|
|
|
__ Ret(pl);
|
|
|
|
// This is a -0 case, restore the value of right.
|
|
|
|
__ mov(right, scratch2);
|
|
|
|
// We fall through here to not_smi_result to produce -0.
|
|
|
|
}
|
2011-02-01 16:38:25 +00:00
|
|
|
break;
|
2012-12-20 16:31:19 +00:00
|
|
|
}
|
2011-02-04 10:52:19 +00:00
|
|
|
case Token::BIT_OR:
|
|
|
|
__ orr(right, left, Operand(right));
|
|
|
|
__ Ret();
|
|
|
|
break;
|
|
|
|
case Token::BIT_AND:
|
|
|
|
__ and_(right, left, Operand(right));
|
|
|
|
__ Ret();
|
|
|
|
break;
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
__ eor(right, left, Operand(right));
|
|
|
|
__ Ret();
|
|
|
|
break;
|
2011-02-10 20:04:54 +00:00
|
|
|
case Token::SAR:
|
|
|
|
// Remove tags from right operand.
|
|
|
|
__ GetLeastBitsFromSmi(scratch1, right, 5);
|
|
|
|
__ mov(right, Operand(left, ASR, scratch1));
|
|
|
|
// Smi tag result.
|
|
|
|
__ bic(right, right, Operand(kSmiTagMask));
|
|
|
|
__ Ret();
|
|
|
|
break;
|
|
|
|
case Token::SHR:
|
|
|
|
// Remove tags from operands. We can't do this on a 31 bit number
|
|
|
|
// because then the 0s get shifted into bit 30 instead of bit 31.
|
|
|
|
__ SmiUntag(scratch1, left);
|
|
|
|
__ GetLeastBitsFromSmi(scratch2, right, 5);
|
|
|
|
__ mov(scratch1, Operand(scratch1, LSR, scratch2));
|
|
|
|
// Unsigned shift is not allowed to produce a negative number, so
|
|
|
|
// check the sign bit and the sign bit after Smi tagging.
|
|
|
|
__ tst(scratch1, Operand(0xc0000000));
|
|
|
|
__ b(ne, ¬_smi_result);
|
|
|
|
// Smi tag result.
|
|
|
|
__ SmiTag(right, scratch1);
|
|
|
|
__ Ret();
|
|
|
|
break;
|
|
|
|
case Token::SHL:
|
|
|
|
// Remove tags from operands.
|
|
|
|
__ SmiUntag(scratch1, left);
|
|
|
|
__ GetLeastBitsFromSmi(scratch2, right, 5);
|
|
|
|
__ mov(scratch1, Operand(scratch1, LSL, scratch2));
|
|
|
|
// Check that the signed result fits in a Smi.
|
|
|
|
__ add(scratch2, scratch1, Operand(0x40000000), SetCC);
|
|
|
|
__ b(mi, ¬_smi_result);
|
|
|
|
__ SmiTag(right, scratch1);
|
|
|
|
__ Ret();
|
|
|
|
break;
|
2011-01-26 07:41:02 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2011-01-26 20:25:33 +00:00
|
|
|
__ bind(¬_smi_result);
|
2011-01-26 07:41:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm,
|
|
|
|
Register result,
|
|
|
|
Register heap_number_map,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Label* gc_required,
|
|
|
|
OverwriteMode mode);
|
|
|
|
|
|
|
|
|
|
|
|
void BinaryOpStub_GenerateFPOperation(MacroAssembler* masm,
|
|
|
|
BinaryOpIC::TypeInfo left_type,
|
|
|
|
BinaryOpIC::TypeInfo right_type,
|
|
|
|
bool smi_operands,
|
|
|
|
Label* not_numbers,
|
|
|
|
Label* gc_required,
|
|
|
|
Label* miss,
|
|
|
|
Token::Value op,
|
|
|
|
OverwriteMode mode) {
|
2011-02-02 10:30:41 +00:00
|
|
|
Register left = r1;
|
|
|
|
Register right = r0;
|
2013-04-02 18:25:09 +00:00
|
|
|
Register scratch1 = r6;
|
|
|
|
Register scratch2 = r7;
|
2011-03-11 12:12:44 +00:00
|
|
|
Register scratch3 = r4;
|
2011-02-02 10:30:41 +00:00
|
|
|
|
2011-02-04 10:52:19 +00:00
|
|
|
ASSERT(smi_operands || (not_numbers != NULL));
|
2012-10-12 11:09:14 +00:00
|
|
|
if (smi_operands) {
|
|
|
|
__ AssertSmi(left);
|
|
|
|
__ AssertSmi(right);
|
2011-02-04 10:52:19 +00:00
|
|
|
}
|
2012-11-14 15:59:45 +00:00
|
|
|
if (left_type == BinaryOpIC::SMI) {
|
|
|
|
__ JumpIfNotSmi(left, miss);
|
|
|
|
}
|
|
|
|
if (right_type == BinaryOpIC::SMI) {
|
|
|
|
__ JumpIfNotSmi(right, miss);
|
|
|
|
}
|
2011-02-02 10:30:41 +00:00
|
|
|
|
2013-04-02 18:25:09 +00:00
|
|
|
Register heap_number_map = r9;
|
2011-02-02 10:30:41 +00:00
|
|
|
__ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
switch (op) {
|
2011-02-04 10:52:19 +00:00
|
|
|
case Token::ADD:
|
|
|
|
case Token::SUB:
|
|
|
|
case Token::MUL:
|
|
|
|
case Token::DIV:
|
|
|
|
case Token::MOD: {
|
|
|
|
// Allocate new heap number for result.
|
|
|
|
Register result = r5;
|
2012-11-14 15:59:45 +00:00
|
|
|
BinaryOpStub_GenerateHeapResultAllocation(
|
|
|
|
masm, result, heap_number_map, scratch1, scratch2, gc_required, mode);
|
2011-02-04 10:52:19 +00:00
|
|
|
|
2013-04-22 21:30:57 +00:00
|
|
|
// Load left and right operands into d0 and d1.
|
2011-02-04 10:52:19 +00:00
|
|
|
if (smi_operands) {
|
2013-04-22 21:30:57 +00:00
|
|
|
__ SmiUntag(scratch1, right);
|
|
|
|
__ vmov(d1.high(), scratch1);
|
|
|
|
__ vcvt_f64_s32(d1, d1.high());
|
|
|
|
__ SmiUntag(scratch1, left);
|
|
|
|
__ vmov(d0.high(), scratch1);
|
|
|
|
__ vcvt_f64_s32(d0, d0.high());
|
2011-02-04 10:52:19 +00:00
|
|
|
} else {
|
2013-04-22 21:30:57 +00:00
|
|
|
// Load right operand into d1.
|
2012-11-14 15:59:45 +00:00
|
|
|
if (right_type == BinaryOpIC::INT32) {
|
2013-04-22 21:30:57 +00:00
|
|
|
__ LoadNumberAsInt32Double(
|
|
|
|
right, d1, heap_number_map, scratch1, d8, miss);
|
2012-11-14 15:59:45 +00:00
|
|
|
} else {
|
2013-02-28 14:43:57 +00:00
|
|
|
Label* fail = (right_type == BinaryOpIC::NUMBER) ? miss : not_numbers;
|
2013-04-22 21:30:57 +00:00
|
|
|
__ LoadNumber(right, d1, heap_number_map, scratch1, fail);
|
2012-11-14 15:59:45 +00:00
|
|
|
}
|
2013-04-22 21:30:57 +00:00
|
|
|
// Load left operand into d0.
|
2012-11-14 15:59:45 +00:00
|
|
|
if (left_type == BinaryOpIC::INT32) {
|
2013-04-22 21:30:57 +00:00
|
|
|
__ LoadNumberAsInt32Double(
|
|
|
|
left, d0, heap_number_map, scratch1, d8, miss);
|
2012-11-14 15:59:45 +00:00
|
|
|
} else {
|
2013-02-28 14:43:57 +00:00
|
|
|
Label* fail = (left_type == BinaryOpIC::NUMBER) ? miss : not_numbers;
|
2013-04-22 21:30:57 +00:00
|
|
|
__ LoadNumber(
|
|
|
|
left, d0, heap_number_map, scratch1, fail);
|
2012-11-14 15:59:45 +00:00
|
|
|
}
|
2011-02-04 10:52:19 +00:00
|
|
|
}
|
2011-02-02 10:30:41 +00:00
|
|
|
|
2011-02-04 10:52:19 +00:00
|
|
|
// Calculate the result.
|
2013-04-22 21:30:57 +00:00
|
|
|
if (op != Token::MOD) {
|
2011-02-04 10:52:19 +00:00
|
|
|
// Using VFP registers:
|
2013-04-22 21:30:57 +00:00
|
|
|
// d0: Left value
|
|
|
|
// d1: Right value
|
2012-11-14 15:59:45 +00:00
|
|
|
switch (op) {
|
2011-02-04 10:52:19 +00:00
|
|
|
case Token::ADD:
|
2013-04-22 21:30:57 +00:00
|
|
|
__ vadd(d5, d0, d1);
|
2011-02-04 10:52:19 +00:00
|
|
|
break;
|
|
|
|
case Token::SUB:
|
2013-04-22 21:30:57 +00:00
|
|
|
__ vsub(d5, d0, d1);
|
2011-02-04 10:52:19 +00:00
|
|
|
break;
|
|
|
|
case Token::MUL:
|
2013-04-22 21:30:57 +00:00
|
|
|
__ vmul(d5, d0, d1);
|
2011-02-04 10:52:19 +00:00
|
|
|
break;
|
|
|
|
case Token::DIV:
|
2013-04-22 21:30:57 +00:00
|
|
|
__ vdiv(d5, d0, d1);
|
2011-02-04 10:52:19 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2011-02-02 10:30:41 +00:00
|
|
|
|
2011-02-04 10:52:19 +00:00
|
|
|
__ sub(r0, result, Operand(kHeapObjectTag));
|
|
|
|
__ vstr(d5, r0, HeapNumber::kValueOffset);
|
|
|
|
__ add(r0, r0, Operand(kHeapObjectTag));
|
|
|
|
__ Ret();
|
|
|
|
} else {
|
2011-03-02 09:31:42 +00:00
|
|
|
// Call the C function to handle the double operation.
|
2013-04-22 21:30:57 +00:00
|
|
|
CallCCodeForDoubleOperation(masm, op, result, scratch1);
|
2011-04-13 11:59:17 +00:00
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ stop("Unreachable code.");
|
|
|
|
}
|
2011-02-04 10:52:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_XOR:
|
2011-02-10 20:04:54 +00:00
|
|
|
case Token::BIT_AND:
|
|
|
|
case Token::SAR:
|
|
|
|
case Token::SHR:
|
|
|
|
case Token::SHL: {
|
2011-02-04 10:52:19 +00:00
|
|
|
if (smi_operands) {
|
|
|
|
__ SmiUntag(r3, left);
|
|
|
|
__ SmiUntag(r2, right);
|
|
|
|
} else {
|
|
|
|
// Convert operands to 32-bit integers. Right in r2 and left in r3.
|
2013-04-22 21:30:57 +00:00
|
|
|
__ ConvertNumberToInt32(
|
|
|
|
left, r3, heap_number_map,
|
|
|
|
scratch1, scratch2, scratch3, d0, d1, not_numbers);
|
|
|
|
__ ConvertNumberToInt32(
|
|
|
|
right, r2, heap_number_map,
|
|
|
|
scratch1, scratch2, scratch3, d0, d1, not_numbers);
|
2011-02-04 10:52:19 +00:00
|
|
|
}
|
2011-02-10 20:04:54 +00:00
|
|
|
|
|
|
|
Label result_not_a_smi;
|
2012-11-14 15:59:45 +00:00
|
|
|
switch (op) {
|
2011-02-04 10:52:19 +00:00
|
|
|
case Token::BIT_OR:
|
|
|
|
__ orr(r2, r3, Operand(r2));
|
|
|
|
break;
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
__ eor(r2, r3, Operand(r2));
|
|
|
|
break;
|
|
|
|
case Token::BIT_AND:
|
|
|
|
__ and_(r2, r3, Operand(r2));
|
|
|
|
break;
|
2011-02-10 20:04:54 +00:00
|
|
|
case Token::SAR:
|
|
|
|
// Use only the 5 least significant bits of the shift count.
|
|
|
|
__ GetLeastBitsFromInt32(r2, r2, 5);
|
|
|
|
__ mov(r2, Operand(r3, ASR, r2));
|
|
|
|
break;
|
|
|
|
case Token::SHR:
|
|
|
|
// Use only the 5 least significant bits of the shift count.
|
|
|
|
__ GetLeastBitsFromInt32(r2, r2, 5);
|
|
|
|
__ mov(r2, Operand(r3, LSR, r2), SetCC);
|
|
|
|
// SHR is special because it is required to produce a positive answer.
|
|
|
|
// The code below for writing into heap numbers isn't capable of
|
|
|
|
// writing the register as an unsigned int so we go to slow case if we
|
|
|
|
// hit this case.
|
2013-04-07 04:34:20 +00:00
|
|
|
__ b(mi, &result_not_a_smi);
|
2011-02-10 20:04:54 +00:00
|
|
|
break;
|
|
|
|
case Token::SHL:
|
|
|
|
// Use only the 5 least significant bits of the shift count.
|
|
|
|
__ GetLeastBitsFromInt32(r2, r2, 5);
|
|
|
|
__ mov(r2, Operand(r3, LSL, r2));
|
|
|
|
break;
|
2011-02-04 10:52:19 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the *signed* result fits in a smi.
|
|
|
|
__ add(r3, r2, Operand(0x40000000), SetCC);
|
|
|
|
__ b(mi, &result_not_a_smi);
|
|
|
|
__ SmiTag(r0, r2);
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Allocate new heap number for result.
|
|
|
|
__ bind(&result_not_a_smi);
|
2011-02-16 14:48:41 +00:00
|
|
|
Register result = r5;
|
|
|
|
if (smi_operands) {
|
|
|
|
__ AllocateHeapNumber(
|
|
|
|
result, scratch1, scratch2, heap_number_map, gc_required);
|
|
|
|
} else {
|
2012-11-14 15:59:45 +00:00
|
|
|
BinaryOpStub_GenerateHeapResultAllocation(
|
|
|
|
masm, result, heap_number_map, scratch1, scratch2, gc_required,
|
|
|
|
mode);
|
2011-02-16 14:48:41 +00:00
|
|
|
}
|
2011-02-04 10:52:19 +00:00
|
|
|
|
|
|
|
// r2: Answer as signed int32.
|
|
|
|
// r5: Heap number to write answer into.
|
|
|
|
|
|
|
|
// Nothing can go wrong now, so move the heap number to r0, which is the
|
|
|
|
// result.
|
|
|
|
__ mov(r0, Operand(r5));
|
|
|
|
|
2013-04-07 04:34:20 +00:00
|
|
|
// Convert the int32 in r2 to the heap number in r0. r3 is corrupted. As
|
|
|
|
// mentioned above SHR needs to always produce a positive result.
|
|
|
|
__ vmov(s0, r2);
|
|
|
|
if (op == Token::SHR) {
|
|
|
|
__ vcvt_f64_u32(d0, s0);
|
2011-02-04 10:52:19 +00:00
|
|
|
} else {
|
2013-04-07 04:34:20 +00:00
|
|
|
__ vcvt_f64_s32(d0, s0);
|
2011-02-04 10:52:19 +00:00
|
|
|
}
|
2013-04-07 04:34:20 +00:00
|
|
|
__ sub(r3, r0, Operand(kHeapObjectTag));
|
|
|
|
__ vstr(d0, r3, HeapNumber::kValueOffset);
|
|
|
|
__ Ret();
|
2011-02-04 10:52:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
2011-01-26 07:41:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-25 14:52:35 +00:00
|
|
|
// Generate the smi code. If the operation on smis are successful this return is
|
|
|
|
// generated. If the result is not a smi and heap number allocation is not
|
|
|
|
// requested the code falls through. If number allocation is requested but a
|
2012-11-14 15:59:45 +00:00
|
|
|
// heap number cannot be allocated the code jumps to the label gc_required.
|
|
|
|
void BinaryOpStub_GenerateSmiCode(
|
2011-05-24 12:20:16 +00:00
|
|
|
MacroAssembler* masm,
|
2011-04-13 11:59:17 +00:00
|
|
|
Label* use_runtime,
|
2011-01-25 14:52:35 +00:00
|
|
|
Label* gc_required,
|
2012-11-14 15:59:45 +00:00
|
|
|
Token::Value op,
|
|
|
|
BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results,
|
|
|
|
OverwriteMode mode) {
|
2011-01-25 14:52:35 +00:00
|
|
|
Label not_smis;
|
|
|
|
|
|
|
|
Register left = r1;
|
|
|
|
Register right = r0;
|
|
|
|
Register scratch1 = r7;
|
|
|
|
|
|
|
|
// Perform combined smi check on both operands.
|
|
|
|
__ orr(scratch1, left, Operand(right));
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(scratch1, ¬_smis);
|
2011-01-25 14:52:35 +00:00
|
|
|
|
2011-02-01 16:38:25 +00:00
|
|
|
// If the smi-smi operation results in a smi return is generated.
|
2012-11-14 15:59:45 +00:00
|
|
|
BinaryOpStub_GenerateSmiSmiOperation(masm, op);
|
2011-01-25 14:52:35 +00:00
|
|
|
|
|
|
|
// If heap number results are possible generate the result in an allocated
|
|
|
|
// heap number.
|
2012-11-14 15:59:45 +00:00
|
|
|
if (allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS) {
|
|
|
|
BinaryOpStub_GenerateFPOperation(
|
|
|
|
masm, BinaryOpIC::UNINITIALIZED, BinaryOpIC::UNINITIALIZED, true,
|
|
|
|
use_runtime, gc_required, ¬_smis, op, mode);
|
2011-01-25 14:52:35 +00:00
|
|
|
}
|
|
|
|
__ bind(¬_smis);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) {
|
2011-01-25 14:52:35 +00:00
|
|
|
Label not_smis, call_runtime;
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
if (result_type_ == BinaryOpIC::UNINITIALIZED ||
|
|
|
|
result_type_ == BinaryOpIC::SMI) {
|
2011-01-25 14:52:35 +00:00
|
|
|
// Only allow smi results.
|
2012-11-14 15:59:45 +00:00
|
|
|
BinaryOpStub_GenerateSmiCode(
|
|
|
|
masm, &call_runtime, NULL, op_, NO_HEAPNUMBER_RESULTS, mode_);
|
2011-01-25 14:52:35 +00:00
|
|
|
} else {
|
|
|
|
// Allow heap number result and don't make a transition if a heap number
|
|
|
|
// cannot be allocated.
|
2012-11-14 15:59:45 +00:00
|
|
|
BinaryOpStub_GenerateSmiCode(
|
|
|
|
masm, &call_runtime, &call_runtime, op_, ALLOW_HEAPNUMBER_RESULTS,
|
|
|
|
mode_);
|
2011-01-25 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Code falls through if the result is not returned as either a smi or heap
|
|
|
|
// number.
|
|
|
|
GenerateTypeTransition(masm);
|
|
|
|
|
|
|
|
__ bind(&call_runtime);
|
2012-11-14 15:59:45 +00:00
|
|
|
GenerateRegisterArgsPush(masm);
|
2011-01-25 14:52:35 +00:00
|
|
|
GenerateCallRuntime(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) {
|
2011-04-15 06:39:36 +00:00
|
|
|
Label call_runtime;
|
2012-11-14 15:59:45 +00:00
|
|
|
ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING);
|
2011-04-15 06:39:36 +00:00
|
|
|
ASSERT(op_ == Token::ADD);
|
|
|
|
// If both arguments are strings, call the string add stub.
|
|
|
|
// Otherwise, do a transition.
|
|
|
|
|
|
|
|
// Registers containing left and right operands respectively.
|
|
|
|
Register left = r1;
|
|
|
|
Register right = r0;
|
|
|
|
|
|
|
|
// Test if left operand is a string.
|
|
|
|
__ JumpIfSmi(left, &call_runtime);
|
|
|
|
__ CompareObjectType(left, r2, r2, FIRST_NONSTRING_TYPE);
|
|
|
|
__ b(ge, &call_runtime);
|
|
|
|
|
|
|
|
// Test if right operand is a string.
|
|
|
|
__ JumpIfSmi(right, &call_runtime);
|
|
|
|
__ CompareObjectType(right, r2, r2, FIRST_NONSTRING_TYPE);
|
|
|
|
__ b(ge, &call_runtime);
|
|
|
|
|
|
|
|
StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB);
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
__ TailCallStub(&string_add_stub);
|
|
|
|
|
|
|
|
__ bind(&call_runtime);
|
|
|
|
GenerateTypeTransition(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) {
|
2012-11-14 15:59:45 +00:00
|
|
|
ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32);
|
2011-01-25 14:52:35 +00:00
|
|
|
|
2011-03-02 09:31:42 +00:00
|
|
|
Register left = r1;
|
|
|
|
Register right = r0;
|
|
|
|
Register scratch1 = r7;
|
|
|
|
Register scratch2 = r9;
|
|
|
|
DwVfpRegister double_scratch = d0;
|
|
|
|
|
|
|
|
Register heap_number_result = no_reg;
|
|
|
|
Register heap_number_map = r6;
|
|
|
|
__ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
|
|
|
|
|
|
|
|
Label call_runtime;
|
|
|
|
// Labels for type transition, used for wrong input or output types.
|
|
|
|
// Both label are currently actually bound to the same position. We use two
|
|
|
|
// different label to differentiate the cause leading to type transition.
|
|
|
|
Label transition;
|
|
|
|
|
|
|
|
// Smi-smi fast case.
|
|
|
|
Label skip;
|
|
|
|
__ orr(scratch1, left, right);
|
|
|
|
__ JumpIfNotSmi(scratch1, &skip);
|
2012-11-14 15:59:45 +00:00
|
|
|
BinaryOpStub_GenerateSmiSmiOperation(masm, op_);
|
2011-03-02 09:31:42 +00:00
|
|
|
// Fall through if the result is not a smi.
|
|
|
|
__ bind(&skip);
|
|
|
|
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD:
|
|
|
|
case Token::SUB:
|
|
|
|
case Token::MUL:
|
|
|
|
case Token::DIV:
|
|
|
|
case Token::MOD: {
|
2012-11-14 15:59:45 +00:00
|
|
|
// It could be that only SMIs have been seen at either the left
|
|
|
|
// or the right operand. For precise type feedback, patch the IC
|
|
|
|
// again if this changes.
|
|
|
|
if (left_type_ == BinaryOpIC::SMI) {
|
|
|
|
__ JumpIfNotSmi(left, &transition);
|
|
|
|
}
|
|
|
|
if (right_type_ == BinaryOpIC::SMI) {
|
|
|
|
__ JumpIfNotSmi(right, &transition);
|
|
|
|
}
|
2011-06-17 10:45:29 +00:00
|
|
|
// Load both operands and check that they are 32-bit integer.
|
|
|
|
// Jump to type transition if they are not. The registers r0 and r1 (right
|
|
|
|
// and left) are preserved for the runtime call.
|
2013-04-22 21:30:57 +00:00
|
|
|
__ LoadNumberAsInt32Double(
|
|
|
|
right, d1, heap_number_map, scratch1, d8, &transition);
|
|
|
|
__ LoadNumberAsInt32Double(
|
|
|
|
left, d0, heap_number_map, scratch1, d8, &transition);
|
|
|
|
|
|
|
|
if (op_ != Token::MOD) {
|
2011-03-02 09:31:42 +00:00
|
|
|
Label return_heap_number;
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD:
|
2013-04-22 21:30:57 +00:00
|
|
|
__ vadd(d5, d0, d1);
|
2011-03-02 09:31:42 +00:00
|
|
|
break;
|
|
|
|
case Token::SUB:
|
2013-04-22 21:30:57 +00:00
|
|
|
__ vsub(d5, d0, d1);
|
2011-03-02 09:31:42 +00:00
|
|
|
break;
|
|
|
|
case Token::MUL:
|
2013-04-22 21:30:57 +00:00
|
|
|
__ vmul(d5, d0, d1);
|
2011-03-02 09:31:42 +00:00
|
|
|
break;
|
|
|
|
case Token::DIV:
|
2013-04-22 21:30:57 +00:00
|
|
|
__ vdiv(d5, d0, d1);
|
2011-03-02 09:31:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op_ != Token::DIV) {
|
|
|
|
// These operations produce an integer result.
|
|
|
|
// Try to return a smi if we can.
|
|
|
|
// Otherwise return a heap number if allowed, or jump to type
|
|
|
|
// transition.
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
if (result_type_ <= BinaryOpIC::INT32) {
|
2013-03-05 19:35:59 +00:00
|
|
|
__ TryDoubleToInt32Exact(scratch1, d5, d8);
|
2011-03-02 09:31:42 +00:00
|
|
|
// If the ne condition is set, result does
|
|
|
|
// not fit in a 32-bit integer.
|
|
|
|
__ b(ne, &transition);
|
2013-03-05 19:35:59 +00:00
|
|
|
} else {
|
|
|
|
__ vcvt_s32_f64(s8, d5);
|
|
|
|
__ vmov(scratch1, s8);
|
2011-03-02 09:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the result fits in a smi.
|
|
|
|
__ add(scratch2, scratch1, Operand(0x40000000), SetCC);
|
|
|
|
// If not try to return a heap number.
|
|
|
|
__ b(mi, &return_heap_number);
|
2013-04-22 10:56:37 +00:00
|
|
|
// Check for minus zero. Return heap number for minus zero if
|
|
|
|
// double results are allowed; otherwise transition.
|
2011-03-29 07:43:27 +00:00
|
|
|
Label not_zero;
|
2011-08-23 12:00:09 +00:00
|
|
|
__ cmp(scratch1, Operand::Zero());
|
2011-03-29 07:43:27 +00:00
|
|
|
__ b(ne, ¬_zero);
|
|
|
|
__ vmov(scratch2, d5.high());
|
|
|
|
__ tst(scratch2, Operand(HeapNumber::kSignMask));
|
2013-04-22 10:56:37 +00:00
|
|
|
__ b(ne, result_type_ <= BinaryOpIC::INT32 ? &transition
|
|
|
|
: &return_heap_number);
|
2011-03-29 07:43:27 +00:00
|
|
|
__ bind(¬_zero);
|
|
|
|
|
2011-03-02 09:31:42 +00:00
|
|
|
// Tag the result and return.
|
|
|
|
__ SmiTag(r0, scratch1);
|
|
|
|
__ Ret();
|
2011-03-29 07:43:27 +00:00
|
|
|
} else {
|
|
|
|
// DIV just falls through to allocating a heap number.
|
2011-03-02 09:31:42 +00:00
|
|
|
}
|
|
|
|
|
2011-06-06 07:47:21 +00:00
|
|
|
__ bind(&return_heap_number);
|
|
|
|
// Return a heap number, or fall through to type transition or runtime
|
|
|
|
// call if we can't.
|
2013-04-22 10:56:37 +00:00
|
|
|
// We are using vfp registers so r5 is available.
|
|
|
|
heap_number_result = r5;
|
|
|
|
BinaryOpStub_GenerateHeapResultAllocation(masm,
|
|
|
|
heap_number_result,
|
|
|
|
heap_number_map,
|
|
|
|
scratch1,
|
|
|
|
scratch2,
|
|
|
|
&call_runtime,
|
|
|
|
mode_);
|
|
|
|
__ sub(r0, heap_number_result, Operand(kHeapObjectTag));
|
|
|
|
__ vstr(d5, r0, HeapNumber::kValueOffset);
|
|
|
|
__ mov(r0, heap_number_result);
|
|
|
|
__ Ret();
|
2011-03-02 09:31:42 +00:00
|
|
|
|
|
|
|
// A DIV operation expecting an integer result falls through
|
|
|
|
// to type transition.
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// We preserved r0 and r1 to be able to call runtime.
|
|
|
|
// Save the left value on the stack.
|
|
|
|
__ Push(r5, r4);
|
|
|
|
|
2011-04-26 16:40:20 +00:00
|
|
|
Label pop_and_call_runtime;
|
|
|
|
|
2011-03-02 09:31:42 +00:00
|
|
|
// Allocate a heap number to store the result.
|
|
|
|
heap_number_result = r5;
|
2012-11-14 15:59:45 +00:00
|
|
|
BinaryOpStub_GenerateHeapResultAllocation(masm,
|
|
|
|
heap_number_result,
|
|
|
|
heap_number_map,
|
|
|
|
scratch1,
|
|
|
|
scratch2,
|
|
|
|
&pop_and_call_runtime,
|
|
|
|
mode_);
|
2011-03-02 09:31:42 +00:00
|
|
|
|
|
|
|
// Load the left value from the value saved on the stack.
|
|
|
|
__ Pop(r1, r0);
|
|
|
|
|
|
|
|
// Call the C function to handle the double operation.
|
2013-04-22 21:30:57 +00:00
|
|
|
CallCCodeForDoubleOperation(masm, op_, heap_number_result, scratch1);
|
2011-04-13 11:59:17 +00:00
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ stop("Unreachable code.");
|
|
|
|
}
|
2011-04-26 16:40:20 +00:00
|
|
|
|
|
|
|
__ bind(&pop_and_call_runtime);
|
|
|
|
__ Drop(2);
|
|
|
|
__ b(&call_runtime);
|
2011-03-02 09:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
case Token::BIT_AND:
|
|
|
|
case Token::SAR:
|
|
|
|
case Token::SHR:
|
|
|
|
case Token::SHL: {
|
|
|
|
Label return_heap_number;
|
|
|
|
// Convert operands to 32-bit integers. Right in r2 and left in r3. The
|
|
|
|
// registers r0 and r1 (right and left) are preserved for the runtime
|
|
|
|
// call.
|
2013-04-22 21:30:57 +00:00
|
|
|
__ LoadNumberAsInt32(left, r3, heap_number_map,
|
|
|
|
scratch1, d0, d1, &transition);
|
|
|
|
__ LoadNumberAsInt32(right, r2, heap_number_map,
|
|
|
|
scratch1, d0, d1, &transition);
|
2011-03-02 09:31:42 +00:00
|
|
|
|
|
|
|
// The ECMA-262 standard specifies that, for shift operations, only the
|
|
|
|
// 5 least significant bits of the shift value should be used.
|
|
|
|
switch (op_) {
|
|
|
|
case Token::BIT_OR:
|
|
|
|
__ orr(r2, r3, Operand(r2));
|
|
|
|
break;
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
__ eor(r2, r3, Operand(r2));
|
|
|
|
break;
|
|
|
|
case Token::BIT_AND:
|
|
|
|
__ and_(r2, r3, Operand(r2));
|
|
|
|
break;
|
|
|
|
case Token::SAR:
|
|
|
|
__ and_(r2, r2, Operand(0x1f));
|
|
|
|
__ mov(r2, Operand(r3, ASR, r2));
|
|
|
|
break;
|
|
|
|
case Token::SHR:
|
|
|
|
__ and_(r2, r2, Operand(0x1f));
|
|
|
|
__ mov(r2, Operand(r3, LSR, r2), SetCC);
|
|
|
|
// SHR is special because it is required to produce a positive answer.
|
|
|
|
// We only get a negative result if the shift value (r2) is 0.
|
|
|
|
// This result cannot be respresented as a signed 32-bit integer, try
|
|
|
|
// to return a heap number if we can.
|
2013-04-07 04:34:20 +00:00
|
|
|
__ b(mi, (result_type_ <= BinaryOpIC::INT32)
|
|
|
|
? &transition
|
|
|
|
: &return_heap_number);
|
2011-03-02 09:31:42 +00:00
|
|
|
break;
|
|
|
|
case Token::SHL:
|
|
|
|
__ and_(r2, r2, Operand(0x1f));
|
|
|
|
__ mov(r2, Operand(r3, LSL, r2));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the result fits in a smi.
|
|
|
|
__ add(scratch1, r2, Operand(0x40000000), SetCC);
|
|
|
|
// If not try to return a heap number. (We know the result is an int32.)
|
|
|
|
__ b(mi, &return_heap_number);
|
|
|
|
// Tag the result and return.
|
|
|
|
__ SmiTag(r0, r2);
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&return_heap_number);
|
2011-04-13 11:59:17 +00:00
|
|
|
heap_number_result = r5;
|
2012-11-14 15:59:45 +00:00
|
|
|
BinaryOpStub_GenerateHeapResultAllocation(masm,
|
|
|
|
heap_number_result,
|
|
|
|
heap_number_map,
|
|
|
|
scratch1,
|
|
|
|
scratch2,
|
|
|
|
&call_runtime,
|
|
|
|
mode_);
|
2011-04-13 11:59:17 +00:00
|
|
|
|
2013-04-07 04:34:20 +00:00
|
|
|
if (op_ != Token::SHR) {
|
|
|
|
// Convert the result to a floating point value.
|
|
|
|
__ vmov(double_scratch.low(), r2);
|
|
|
|
__ vcvt_f64_s32(double_scratch, double_scratch.low());
|
2011-03-02 09:31:42 +00:00
|
|
|
} else {
|
2013-04-07 04:34:20 +00:00
|
|
|
// The result must be interpreted as an unsigned 32-bit integer.
|
|
|
|
__ vmov(double_scratch.low(), r2);
|
|
|
|
__ vcvt_f64_u32(double_scratch, double_scratch.low());
|
2011-03-02 09:31:42 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 04:34:20 +00:00
|
|
|
// Store the result.
|
|
|
|
__ sub(r0, heap_number_result, Operand(kHeapObjectTag));
|
|
|
|
__ vstr(double_scratch, r0, HeapNumber::kValueOffset);
|
|
|
|
__ mov(r0, heap_number_result);
|
|
|
|
__ Ret();
|
|
|
|
|
2011-03-02 09:31:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2011-06-06 07:47:21 +00:00
|
|
|
// We never expect DIV to yield an integer result, so we always generate
|
|
|
|
// type transition code for DIV operations expecting an integer result: the
|
|
|
|
// code will fall through to this type transition.
|
|
|
|
if (transition.is_linked() ||
|
|
|
|
((op_ == Token::DIV) && (result_type_ <= BinaryOpIC::INT32))) {
|
2011-03-02 09:31:42 +00:00
|
|
|
__ bind(&transition);
|
|
|
|
GenerateTypeTransition(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&call_runtime);
|
2012-11-14 15:59:45 +00:00
|
|
|
GenerateRegisterArgsPush(masm);
|
2011-03-02 09:31:42 +00:00
|
|
|
GenerateCallRuntime(masm);
|
2011-01-25 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) {
|
2011-03-11 12:12:44 +00:00
|
|
|
Label call_runtime;
|
2011-01-25 14:52:35 +00:00
|
|
|
|
2011-03-28 16:36:08 +00:00
|
|
|
if (op_ == Token::ADD) {
|
|
|
|
// Handle string addition here, because it is the only operation
|
|
|
|
// that does not do a ToNumber conversion on the operands.
|
|
|
|
GenerateAddStrings(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert oddball arguments to numbers.
|
|
|
|
Label check, done;
|
|
|
|
__ CompareRoot(r1, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ b(ne, &check);
|
|
|
|
if (Token::IsBitOp(op_)) {
|
|
|
|
__ mov(r1, Operand(Smi::FromInt(0)));
|
|
|
|
} else {
|
|
|
|
__ LoadRoot(r1, Heap::kNanValueRootIndex);
|
|
|
|
}
|
|
|
|
__ jmp(&done);
|
|
|
|
__ bind(&check);
|
|
|
|
__ CompareRoot(r0, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ b(ne, &done);
|
|
|
|
if (Token::IsBitOp(op_)) {
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(0)));
|
|
|
|
} else {
|
|
|
|
__ LoadRoot(r0, Heap::kNanValueRootIndex);
|
|
|
|
}
|
|
|
|
__ bind(&done);
|
|
|
|
|
2013-02-28 14:43:57 +00:00
|
|
|
GenerateNumberStub(masm);
|
2011-03-28 16:36:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 14:43:57 +00:00
|
|
|
void BinaryOpStub::GenerateNumberStub(MacroAssembler* masm) {
|
2012-11-14 15:59:45 +00:00
|
|
|
Label call_runtime, transition;
|
|
|
|
BinaryOpStub_GenerateFPOperation(
|
|
|
|
masm, left_type_, right_type_, false,
|
|
|
|
&transition, &call_runtime, &transition, op_, mode_);
|
|
|
|
|
|
|
|
__ bind(&transition);
|
|
|
|
GenerateTypeTransition(masm);
|
2011-01-25 14:52:35 +00:00
|
|
|
|
|
|
|
__ bind(&call_runtime);
|
2012-11-14 15:59:45 +00:00
|
|
|
GenerateRegisterArgsPush(masm);
|
2011-01-25 14:52:35 +00:00
|
|
|
GenerateCallRuntime(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) {
|
2012-11-14 15:59:45 +00:00
|
|
|
Label call_runtime, call_string_add_or_runtime, transition;
|
|
|
|
|
|
|
|
BinaryOpStub_GenerateSmiCode(
|
|
|
|
masm, &call_runtime, &call_runtime, op_, ALLOW_HEAPNUMBER_RESULTS, mode_);
|
2011-01-25 14:52:35 +00:00
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
BinaryOpStub_GenerateFPOperation(
|
|
|
|
masm, left_type_, right_type_, false,
|
|
|
|
&call_string_add_or_runtime, &call_runtime, &transition, op_, mode_);
|
2011-01-25 14:52:35 +00:00
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
__ bind(&transition);
|
|
|
|
GenerateTypeTransition(masm);
|
2011-01-25 14:52:35 +00:00
|
|
|
|
2011-02-16 14:48:41 +00:00
|
|
|
__ bind(&call_string_add_or_runtime);
|
2011-01-26 12:31:35 +00:00
|
|
|
if (op_ == Token::ADD) {
|
|
|
|
GenerateAddStrings(masm);
|
|
|
|
}
|
2011-01-25 14:52:35 +00:00
|
|
|
|
2011-02-16 14:48:41 +00:00
|
|
|
__ bind(&call_runtime);
|
2012-11-14 15:59:45 +00:00
|
|
|
GenerateRegisterArgsPush(masm);
|
2011-02-16 14:48:41 +00:00
|
|
|
GenerateCallRuntime(masm);
|
2011-01-25 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) {
|
2011-01-26 12:31:35 +00:00
|
|
|
ASSERT(op_ == Token::ADD);
|
2011-02-22 12:26:31 +00:00
|
|
|
Label left_not_string, call_runtime;
|
2011-01-26 12:31:35 +00:00
|
|
|
|
2011-01-25 14:52:35 +00:00
|
|
|
Register left = r1;
|
|
|
|
Register right = r0;
|
|
|
|
|
2011-02-22 09:35:37 +00:00
|
|
|
// Check if left argument is a string.
|
|
|
|
__ JumpIfSmi(left, &left_not_string);
|
2011-01-25 14:52:35 +00:00
|
|
|
__ CompareObjectType(left, r2, r2, FIRST_NONSTRING_TYPE);
|
2011-02-22 09:35:37 +00:00
|
|
|
__ b(ge, &left_not_string);
|
|
|
|
|
|
|
|
StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB);
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
__ TailCallStub(&string_add_left_stub);
|
2011-01-25 14:52:35 +00:00
|
|
|
|
2011-02-22 09:35:37 +00:00
|
|
|
// Left operand is not a string, test right.
|
|
|
|
__ bind(&left_not_string);
|
2011-01-26 07:44:45 +00:00
|
|
|
__ JumpIfSmi(right, &call_runtime);
|
2011-01-25 14:52:35 +00:00
|
|
|
__ CompareObjectType(right, r2, r2, FIRST_NONSTRING_TYPE);
|
|
|
|
__ b(ge, &call_runtime);
|
|
|
|
|
2011-02-22 09:35:37 +00:00
|
|
|
StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB);
|
2011-01-25 14:52:35 +00:00
|
|
|
GenerateRegisterArgsPush(masm);
|
2011-02-22 09:35:37 +00:00
|
|
|
__ TailCallStub(&string_add_right_stub);
|
2011-01-25 14:52:35 +00:00
|
|
|
|
|
|
|
// At least one argument is not a string.
|
|
|
|
__ bind(&call_runtime);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm,
|
|
|
|
Register result,
|
|
|
|
Register heap_number_map,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Label* gc_required,
|
|
|
|
OverwriteMode mode) {
|
2011-01-25 14:52:35 +00:00
|
|
|
// Code below will scratch result if allocation fails. To keep both arguments
|
|
|
|
// intact for the runtime call result cannot be one of these.
|
|
|
|
ASSERT(!result.is(r0) && !result.is(r1));
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
if (mode == OVERWRITE_LEFT || mode == OVERWRITE_RIGHT) {
|
2011-01-25 14:52:35 +00:00
|
|
|
Label skip_allocation, allocated;
|
2012-11-14 15:59:45 +00:00
|
|
|
Register overwritable_operand = mode == OVERWRITE_LEFT ? r1 : r0;
|
2011-01-25 14:52:35 +00:00
|
|
|
// If the overwritable operand is already an object, we skip the
|
|
|
|
// allocation of a heap number.
|
2011-01-26 07:44:45 +00:00
|
|
|
__ JumpIfNotSmi(overwritable_operand, &skip_allocation);
|
2011-01-25 14:52:35 +00:00
|
|
|
// Allocate a heap number for the result.
|
|
|
|
__ AllocateHeapNumber(
|
|
|
|
result, scratch1, scratch2, heap_number_map, gc_required);
|
|
|
|
__ b(&allocated);
|
|
|
|
__ bind(&skip_allocation);
|
|
|
|
// Use object holding the overwritable operand for result.
|
|
|
|
__ mov(result, Operand(overwritable_operand));
|
|
|
|
__ bind(&allocated);
|
|
|
|
} else {
|
2012-11-14 15:59:45 +00:00
|
|
|
ASSERT(mode == NO_OVERWRITE);
|
2011-01-25 14:52:35 +00:00
|
|
|
__ AllocateHeapNumber(
|
|
|
|
result, scratch1, scratch2, heap_number_map, gc_required);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) {
|
2011-01-25 14:52:35 +00:00
|
|
|
__ Push(r1, r0);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void TranscendentalCacheStub::Generate(MacroAssembler* masm) {
|
2011-03-02 14:40:38 +00:00
|
|
|
// Untagged case: double input in d2, double result goes
|
|
|
|
// into d2.
|
|
|
|
// Tagged case: tagged input on top of stack and in r0,
|
|
|
|
// tagged result (heap number) goes into r0.
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
Label input_not_smi;
|
|
|
|
Label loaded;
|
2011-03-02 14:40:38 +00:00
|
|
|
Label calculate;
|
|
|
|
Label invalid_cache;
|
|
|
|
const Register scratch0 = r9;
|
|
|
|
const Register scratch1 = r7;
|
|
|
|
const Register cache_entry = r0;
|
|
|
|
const bool tagged = (argument_type_ == TAGGED);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-04-07 04:34:20 +00:00
|
|
|
if (tagged) {
|
|
|
|
// Argument is a number and is on stack and in r0.
|
|
|
|
// Load argument and check if it is a smi.
|
|
|
|
__ JumpIfNotSmi(r0, &input_not_smi);
|
|
|
|
|
|
|
|
// Input is a smi. Convert to double and load the low and high words
|
|
|
|
// of the double into r2, r3.
|
|
|
|
__ IntegerToDoubleConversionWithVFP3(r0, r3, r2);
|
|
|
|
__ b(&loaded);
|
|
|
|
|
|
|
|
__ bind(&input_not_smi);
|
|
|
|
// Check if input is a HeapNumber.
|
|
|
|
__ CheckMap(r0,
|
|
|
|
r1,
|
|
|
|
Heap::kHeapNumberMapRootIndex,
|
|
|
|
&calculate,
|
|
|
|
DONT_DO_SMI_CHECK);
|
|
|
|
// Input is a HeapNumber. Load it to a double register and store the
|
|
|
|
// low and high words into r2, r3.
|
|
|
|
__ vldr(d0, FieldMemOperand(r0, HeapNumber::kValueOffset));
|
|
|
|
__ vmov(r2, r3, d0);
|
|
|
|
} else {
|
|
|
|
// Input is untagged double in d2. Output goes to d2.
|
|
|
|
__ vmov(r2, r3, d2);
|
|
|
|
}
|
|
|
|
__ bind(&loaded);
|
|
|
|
// r2 = low 32 bits of double value
|
|
|
|
// r3 = high 32 bits of double value
|
|
|
|
// Compute hash (the shifts are arithmetic):
|
|
|
|
// h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1);
|
|
|
|
__ eor(r1, r2, Operand(r3));
|
|
|
|
__ eor(r1, r1, Operand(r1, ASR, 16));
|
|
|
|
__ eor(r1, r1, Operand(r1, ASR, 8));
|
|
|
|
ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize));
|
|
|
|
__ And(r1, r1, Operand(TranscendentalCache::SubCache::kCacheSize - 1));
|
|
|
|
|
|
|
|
// r2 = low 32 bits of double value.
|
|
|
|
// r3 = high 32 bits of double value.
|
|
|
|
// r1 = TranscendentalCache::hash(double value).
|
|
|
|
Isolate* isolate = masm->isolate();
|
|
|
|
ExternalReference cache_array =
|
|
|
|
ExternalReference::transcendental_cache_array_address(isolate);
|
|
|
|
__ mov(cache_entry, Operand(cache_array));
|
|
|
|
// cache_entry points to cache array.
|
|
|
|
int cache_array_index
|
|
|
|
= type_ * sizeof(isolate->transcendental_cache()->caches_[0]);
|
|
|
|
__ ldr(cache_entry, MemOperand(cache_entry, cache_array_index));
|
|
|
|
// r0 points to the cache for the type type_.
|
|
|
|
// If NULL, the cache hasn't been initialized yet, so go through runtime.
|
|
|
|
__ cmp(cache_entry, Operand::Zero());
|
|
|
|
__ b(eq, &invalid_cache);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2013-04-07 04:34:20 +00:00
|
|
|
// Check that the layout of cache elements match expectations.
|
|
|
|
{ TranscendentalCache::SubCache::Element test_elem[2];
|
|
|
|
char* elem_start = reinterpret_cast<char*>(&test_elem[0]);
|
|
|
|
char* elem2_start = reinterpret_cast<char*>(&test_elem[1]);
|
|
|
|
char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0]));
|
|
|
|
char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1]));
|
|
|
|
char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output));
|
|
|
|
CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer.
|
|
|
|
CHECK_EQ(0, elem_in0 - elem_start);
|
|
|
|
CHECK_EQ(kIntSize, elem_in1 - elem_start);
|
|
|
|
CHECK_EQ(2 * kIntSize, elem_out - elem_start);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
#endif
|
|
|
|
|
2013-04-07 04:34:20 +00:00
|
|
|
// Find the address of the r1'st entry in the cache, i.e., &r0[r1*12].
|
|
|
|
__ add(r1, r1, Operand(r1, LSL, 1));
|
|
|
|
__ add(cache_entry, cache_entry, Operand(r1, LSL, 2));
|
|
|
|
// Check if cache matches: Double value is stored in uint32_t[2] array.
|
|
|
|
__ ldm(ia, cache_entry, r4.bit() | r5.bit() | r6.bit());
|
|
|
|
__ cmp(r2, r4);
|
|
|
|
__ cmp(r3, r5, eq);
|
|
|
|
__ b(ne, &calculate);
|
|
|
|
// Cache hit. Load result, cleanup and return.
|
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
__ IncrementCounter(
|
|
|
|
counters->transcendental_cache_hit(), 1, scratch0, scratch1);
|
|
|
|
if (tagged) {
|
|
|
|
// Pop input value from stack and load result into r0.
|
|
|
|
__ pop();
|
|
|
|
__ mov(r0, Operand(r6));
|
|
|
|
} else {
|
|
|
|
// Load result into d2.
|
|
|
|
__ vldr(d2, FieldMemOperand(r6, HeapNumber::kValueOffset));
|
|
|
|
}
|
|
|
|
__ Ret();
|
2011-03-02 14:40:38 +00:00
|
|
|
|
|
|
|
__ bind(&calculate);
|
2011-11-25 13:38:43 +00:00
|
|
|
__ IncrementCounter(
|
|
|
|
counters->transcendental_cache_miss(), 1, scratch0, scratch1);
|
2011-03-02 14:40:38 +00:00
|
|
|
if (tagged) {
|
|
|
|
__ bind(&invalid_cache);
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference runtime_function =
|
|
|
|
ExternalReference(RuntimeFunction(), masm->isolate());
|
|
|
|
__ TailCallExternalReference(runtime_function, 1, 1);
|
2011-03-02 14:40:38 +00:00
|
|
|
} else {
|
|
|
|
Label no_update;
|
|
|
|
Label skip_cache;
|
|
|
|
|
|
|
|
// Call C function to calculate the result and update the cache.
|
2012-07-16 09:44:59 +00:00
|
|
|
// r0: precalculated cache entry address.
|
|
|
|
// r2 and r3: parts of the double value.
|
|
|
|
// Store r0, r2 and r3 on stack for later before calling C function.
|
|
|
|
__ Push(r3, r2, cache_entry);
|
2011-03-02 14:40:38 +00:00
|
|
|
GenerateCallCFunction(masm, scratch0);
|
|
|
|
__ GetCFunctionDoubleResult(d2);
|
|
|
|
|
|
|
|
// Try to update the cache. If we cannot allocate a
|
|
|
|
// heap number, we return the result without updating.
|
2012-07-16 09:44:59 +00:00
|
|
|
__ Pop(r3, r2, cache_entry);
|
2011-03-02 14:40:38 +00:00
|
|
|
__ LoadRoot(r5, Heap::kHeapNumberMapRootIndex);
|
|
|
|
__ AllocateHeapNumber(r6, scratch0, scratch1, r5, &no_update);
|
|
|
|
__ vstr(d2, FieldMemOperand(r6, HeapNumber::kValueOffset));
|
|
|
|
__ stm(ia, cache_entry, r2.bit() | r3.bit() | r6.bit());
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&invalid_cache);
|
|
|
|
// The cache is invalid. Call runtime which will recreate the
|
|
|
|
// cache.
|
|
|
|
__ LoadRoot(r5, Heap::kHeapNumberMapRootIndex);
|
|
|
|
__ AllocateHeapNumber(r0, scratch0, scratch1, r5, &skip_cache);
|
|
|
|
__ vstr(d2, FieldMemOperand(r0, HeapNumber::kValueOffset));
|
2011-09-15 11:30:45 +00:00
|
|
|
{
|
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
|
|
|
__ push(r0);
|
|
|
|
__ CallRuntime(RuntimeFunction(), 1);
|
|
|
|
}
|
2011-03-02 14:40:38 +00:00
|
|
|
__ vldr(d2, FieldMemOperand(r0, HeapNumber::kValueOffset));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&skip_cache);
|
|
|
|
// Call C function to calculate the result and answer directly
|
|
|
|
// without updating the cache.
|
|
|
|
GenerateCallCFunction(masm, scratch0);
|
|
|
|
__ GetCFunctionDoubleResult(d2);
|
|
|
|
__ bind(&no_update);
|
|
|
|
|
|
|
|
// We return the value in d2 without adding it to the cache, but
|
|
|
|
// we cause a scavenging GC so that future allocations will succeed.
|
2011-09-15 11:30:45 +00:00
|
|
|
{
|
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
|
|
|
|
|
|
|
// Allocate an aligned object larger than a HeapNumber.
|
|
|
|
ASSERT(4 * kPointerSize >= HeapNumber::kSize);
|
|
|
|
__ mov(scratch0, Operand(4 * kPointerSize));
|
|
|
|
__ push(scratch0);
|
|
|
|
__ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Ret();
|
|
|
|
}
|
2011-03-02 14:40:38 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-03-02 14:40:38 +00:00
|
|
|
void TranscendentalCacheStub::GenerateCallCFunction(MacroAssembler* masm,
|
|
|
|
Register scratch) {
|
2011-03-22 13:20:04 +00:00
|
|
|
Isolate* isolate = masm->isolate();
|
|
|
|
|
2011-03-02 14:40:38 +00:00
|
|
|
__ push(lr);
|
2011-04-27 14:29:25 +00:00
|
|
|
__ PrepareCallCFunction(0, 1, scratch);
|
2011-04-29 08:50:38 +00:00
|
|
|
if (masm->use_eabi_hardfloat()) {
|
2011-04-27 14:29:25 +00:00
|
|
|
__ vmov(d0, d2);
|
|
|
|
} else {
|
|
|
|
__ vmov(r0, r1, d2);
|
|
|
|
}
|
2011-09-16 13:06:51 +00:00
|
|
|
AllowExternalCallThatCantCauseGC scope(masm);
|
2011-03-02 14:40:38 +00:00
|
|
|
switch (type_) {
|
|
|
|
case TranscendentalCache::SIN:
|
2011-04-27 14:29:25 +00:00
|
|
|
__ CallCFunction(ExternalReference::math_sin_double_function(isolate),
|
|
|
|
0, 1);
|
2011-03-02 14:40:38 +00:00
|
|
|
break;
|
|
|
|
case TranscendentalCache::COS:
|
2011-04-27 14:29:25 +00:00
|
|
|
__ CallCFunction(ExternalReference::math_cos_double_function(isolate),
|
|
|
|
0, 1);
|
2011-03-02 14:40:38 +00:00
|
|
|
break;
|
2011-11-25 13:15:31 +00:00
|
|
|
case TranscendentalCache::TAN:
|
|
|
|
__ CallCFunction(ExternalReference::math_tan_double_function(isolate),
|
|
|
|
0, 1);
|
|
|
|
break;
|
2011-03-02 14:40:38 +00:00
|
|
|
case TranscendentalCache::LOG:
|
2011-04-27 14:29:25 +00:00
|
|
|
__ CallCFunction(ExternalReference::math_log_double_function(isolate),
|
|
|
|
0, 1);
|
2011-03-02 14:40:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
__ pop(lr);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() {
|
|
|
|
switch (type_) {
|
|
|
|
// Add more cases when necessary.
|
|
|
|
case TranscendentalCache::SIN: return Runtime::kMath_sin;
|
|
|
|
case TranscendentalCache::COS: return Runtime::kMath_cos;
|
2011-11-25 13:15:31 +00:00
|
|
|
case TranscendentalCache::TAN: return Runtime::kMath_tan;
|
2010-12-02 11:20:44 +00:00
|
|
|
case TranscendentalCache::LOG: return Runtime::kMath_log;
|
2010-08-25 09:44:44 +00:00
|
|
|
default:
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
return Runtime::kAbort;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StackCheckStub::Generate(MacroAssembler* masm) {
|
2010-10-19 11:14:03 +00:00
|
|
|
__ TailCallRuntime(Runtime::kStackGuard, 0, 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-14 14:00:31 +00:00
|
|
|
void InterruptStub::Generate(MacroAssembler* masm) {
|
|
|
|
__ TailCallRuntime(Runtime::kInterrupt, 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-08 10:29:40 +00:00
|
|
|
void MathPowStub::Generate(MacroAssembler* masm) {
|
2011-12-07 16:55:00 +00:00
|
|
|
const Register base = r1;
|
|
|
|
const Register exponent = r2;
|
|
|
|
const Register heapnumbermap = r5;
|
|
|
|
const Register heapnumber = r0;
|
2012-12-18 16:25:45 +00:00
|
|
|
const DwVfpRegister double_base = d1;
|
|
|
|
const DwVfpRegister double_exponent = d2;
|
|
|
|
const DwVfpRegister double_result = d3;
|
|
|
|
const DwVfpRegister double_scratch = d0;
|
2011-12-07 16:55:00 +00:00
|
|
|
const SwVfpRegister single_scratch = s0;
|
|
|
|
const Register scratch = r9;
|
|
|
|
const Register scratch2 = r7;
|
|
|
|
|
2012-01-27 16:54:22 +00:00
|
|
|
Label call_runtime, done, int_exponent;
|
2011-12-07 16:55:00 +00:00
|
|
|
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.
|
2011-03-08 10:29:40 +00:00
|
|
|
__ ldr(base, MemOperand(sp, 1 * kPointerSize));
|
|
|
|
__ ldr(exponent, MemOperand(sp, 0 * kPointerSize));
|
|
|
|
|
2011-12-07 16:55:00 +00:00
|
|
|
__ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex);
|
2011-03-08 10:29:40 +00:00
|
|
|
|
2012-01-27 16:54:22 +00:00
|
|
|
__ UntagAndJumpIfSmi(scratch, base, &base_is_smi);
|
2011-03-08 10:29:40 +00:00
|
|
|
__ ldr(scratch, FieldMemOperand(base, JSObject::kMapOffset));
|
|
|
|
__ cmp(scratch, heapnumbermap);
|
|
|
|
__ b(ne, &call_runtime);
|
2011-12-07 16:55:00 +00:00
|
|
|
|
2011-03-08 10:29:40 +00:00
|
|
|
__ vldr(double_base, FieldMemOperand(base, HeapNumber::kValueOffset));
|
2011-12-07 16:55:00 +00:00
|
|
|
__ jmp(&unpack_exponent);
|
|
|
|
|
|
|
|
__ bind(&base_is_smi);
|
2012-01-27 16:54:22 +00:00
|
|
|
__ vmov(single_scratch, scratch);
|
2011-12-07 16:55:00 +00:00
|
|
|
__ vcvt_f64_s32(double_base, single_scratch);
|
|
|
|
__ bind(&unpack_exponent);
|
2011-03-08 10:29:40 +00:00
|
|
|
|
2012-01-27 16:54:22 +00:00
|
|
|
__ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
|
2011-03-08 10:29:40 +00:00
|
|
|
|
|
|
|
__ ldr(scratch, FieldMemOperand(exponent, JSObject::kMapOffset));
|
|
|
|
__ cmp(scratch, heapnumbermap);
|
|
|
|
__ b(ne, &call_runtime);
|
|
|
|
__ vldr(double_exponent,
|
|
|
|
FieldMemOperand(exponent, HeapNumber::kValueOffset));
|
2011-12-07 16:55:00 +00:00
|
|
|
} else if (exponent_type_ == TAGGED) {
|
|
|
|
// Base is already in double_base.
|
2012-01-27 16:54:22 +00:00
|
|
|
__ UntagAndJumpIfSmi(scratch, exponent, &int_exponent);
|
2011-12-07 16:55:00 +00:00
|
|
|
|
|
|
|
__ vldr(double_exponent,
|
|
|
|
FieldMemOperand(exponent, HeapNumber::kValueOffset));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exponent_type_ != INTEGER) {
|
2011-12-09 12:11:56 +00:00
|
|
|
Label int_exponent_convert;
|
2011-12-07 16:55:00 +00:00
|
|
|
// Detect integer exponents stored as double.
|
|
|
|
__ vcvt_u32_f64(single_scratch, double_exponent);
|
|
|
|
// We do not check for NaN or Infinity here because comparing numbers on
|
|
|
|
// ARM correctly distinguishes NaNs. We end up calling the built-in.
|
|
|
|
__ vcvt_f64_u32(double_scratch, single_scratch);
|
|
|
|
__ VFPCompareAndSetFlags(double_scratch, double_exponent);
|
2011-12-09 12:11:56 +00:00
|
|
|
__ b(eq, &int_exponent_convert);
|
2011-12-07 16:55:00 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// Test for 0.5.
|
2012-09-25 14:32:07 +00:00
|
|
|
__ vmov(double_scratch, 0.5, scratch);
|
2011-12-07 16:55:00 +00:00
|
|
|
__ VFPCompareAndSetFlags(double_exponent, double_scratch);
|
|
|
|
__ b(ne, ¬_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).
|
2012-09-25 14:32:07 +00:00
|
|
|
__ vmov(double_scratch, -V8_INFINITY, scratch);
|
2011-12-07 16:55:00 +00:00
|
|
|
__ VFPCompareAndSetFlags(double_base, double_scratch);
|
|
|
|
__ vneg(double_result, double_scratch, eq);
|
|
|
|
__ b(eq, &done);
|
|
|
|
|
|
|
|
// Add +0 to convert -0 to +0.
|
|
|
|
__ vadd(double_scratch, double_base, kDoubleRegZero);
|
|
|
|
__ vsqrt(double_result, double_scratch);
|
|
|
|
__ jmp(&done);
|
|
|
|
|
|
|
|
__ bind(¬_plus_half);
|
2012-09-25 14:32:07 +00:00
|
|
|
__ vmov(double_scratch, -0.5, scratch);
|
2011-12-07 16:55:00 +00:00
|
|
|
__ VFPCompareAndSetFlags(double_exponent, double_scratch);
|
|
|
|
__ b(ne, &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).
|
2012-09-25 14:32:07 +00:00
|
|
|
__ vmov(double_scratch, -V8_INFINITY, scratch);
|
2011-12-07 16:55:00 +00:00
|
|
|
__ VFPCompareAndSetFlags(double_base, double_scratch);
|
|
|
|
__ vmov(double_result, kDoubleRegZero, eq);
|
|
|
|
__ b(eq, &done);
|
|
|
|
|
|
|
|
// Add +0 to convert -0 to +0.
|
|
|
|
__ vadd(double_scratch, double_base, kDoubleRegZero);
|
2012-09-25 14:32:07 +00:00
|
|
|
__ vmov(double_result, 1.0, scratch);
|
2011-12-07 16:55:00 +00:00
|
|
|
__ vsqrt(double_scratch, double_scratch);
|
|
|
|
__ vdiv(double_result, double_result, double_scratch);
|
|
|
|
__ jmp(&done);
|
|
|
|
}
|
2011-03-08 10:29:40 +00:00
|
|
|
|
|
|
|
__ push(lr);
|
2011-09-15 11:30:45 +00:00
|
|
|
{
|
|
|
|
AllowExternalCallThatCantCauseGC scope(masm);
|
2011-12-07 16:55:00 +00:00
|
|
|
__ PrepareCallCFunction(0, 2, scratch);
|
|
|
|
__ SetCallCDoubleArguments(double_base, double_exponent);
|
2011-09-15 11:30:45 +00:00
|
|
|
__ CallCFunction(
|
|
|
|
ExternalReference::power_double_double_function(masm->isolate()),
|
|
|
|
0, 2);
|
|
|
|
}
|
2011-12-07 16:55:00 +00:00
|
|
|
__ pop(lr);
|
|
|
|
__ GetCFunctionDoubleResult(double_result);
|
|
|
|
__ jmp(&done);
|
2011-12-09 12:11:56 +00:00
|
|
|
|
|
|
|
__ bind(&int_exponent_convert);
|
|
|
|
__ vcvt_u32_f64(single_scratch, double_exponent);
|
2012-01-27 16:54:22 +00:00
|
|
|
__ vmov(scratch, single_scratch);
|
2011-12-07 16:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate power with integer exponent.
|
|
|
|
__ bind(&int_exponent);
|
|
|
|
|
2012-01-27 16:54:22 +00:00
|
|
|
// Get two copies of exponent in the registers scratch and exponent.
|
|
|
|
if (exponent_type_ == INTEGER) {
|
|
|
|
__ mov(scratch, exponent);
|
|
|
|
} else {
|
|
|
|
// Exponent has previously been stored into scratch as untagged integer.
|
|
|
|
__ mov(exponent, scratch);
|
|
|
|
}
|
2011-12-07 16:55:00 +00:00
|
|
|
__ vmov(double_scratch, double_base); // Back up base.
|
2012-09-25 14:32:07 +00:00
|
|
|
__ vmov(double_result, 1.0, scratch2);
|
2011-12-07 16:55:00 +00:00
|
|
|
|
|
|
|
// Get absolute value of exponent.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(scratch, Operand::Zero());
|
|
|
|
__ mov(scratch2, Operand::Zero(), LeaveCC, mi);
|
2011-12-07 16:55:00 +00:00
|
|
|
__ sub(scratch, scratch2, scratch, LeaveCC, mi);
|
|
|
|
|
|
|
|
Label while_true;
|
|
|
|
__ bind(&while_true);
|
|
|
|
__ mov(scratch, Operand(scratch, ASR, 1), SetCC);
|
|
|
|
__ vmul(double_result, double_result, double_scratch, cs);
|
|
|
|
__ vmul(double_scratch, double_scratch, double_scratch, ne);
|
|
|
|
__ b(ne, &while_true);
|
|
|
|
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(exponent, Operand::Zero());
|
2011-12-07 16:55:00 +00:00
|
|
|
__ b(ge, &done);
|
2012-09-25 14:32:07 +00:00
|
|
|
__ vmov(double_scratch, 1.0, scratch);
|
2011-12-07 16:55:00 +00:00
|
|
|
__ vdiv(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.
|
|
|
|
__ VFPCompareAndSetFlags(double_result, 0.0);
|
|
|
|
__ b(ne, &done);
|
|
|
|
// double_exponent may not containe the exponent value if the input was a
|
|
|
|
// smi. We set it with exponent value before bailing out.
|
|
|
|
__ vmov(single_scratch, exponent);
|
|
|
|
__ vcvt_f64_s32(double_exponent, single_scratch);
|
|
|
|
|
|
|
|
// Returning or bailing out.
|
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
if (exponent_type_ == ON_STACK) {
|
|
|
|
// The arguments are still on the stack.
|
|
|
|
__ bind(&call_runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kMath_pow_cfunction, 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);
|
2011-03-08 10:29:40 +00:00
|
|
|
__ vstr(double_result,
|
|
|
|
FieldMemOperand(heapnumber, HeapNumber::kValueOffset));
|
2011-12-07 16:55:00 +00:00
|
|
|
ASSERT(heapnumber.is(r0));
|
|
|
|
__ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
|
2011-12-09 12:11:56 +00:00
|
|
|
__ Ret(2);
|
2011-12-07 16:55:00 +00:00
|
|
|
} else {
|
|
|
|
__ push(lr);
|
|
|
|
{
|
|
|
|
AllowExternalCallThatCantCauseGC scope(masm);
|
|
|
|
__ PrepareCallCFunction(0, 2, scratch);
|
|
|
|
__ SetCallCDoubleArguments(double_base, double_exponent);
|
|
|
|
__ CallCFunction(
|
|
|
|
ExternalReference::power_double_double_function(masm->isolate()),
|
|
|
|
0, 2);
|
|
|
|
}
|
|
|
|
__ pop(lr);
|
|
|
|
__ GetCFunctionDoubleResult(double_result);
|
2011-03-08 10:29:40 +00:00
|
|
|
|
2011-12-07 16:55:00 +00:00
|
|
|
__ bind(&done);
|
|
|
|
__ IncrementCounter(counters->math_pow(), 1, scratch, scratch2);
|
|
|
|
__ Ret();
|
|
|
|
}
|
2011-03-08 10:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-09 10:38:19 +00:00
|
|
|
bool CEntryStub::NeedsImmovableCode() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-27 10:53:22 +00:00
|
|
|
bool CEntryStub::IsPregenerated() {
|
2011-09-16 13:06:51 +00:00
|
|
|
return (!save_doubles_ || ISOLATE->fp_stubs_generated()) &&
|
|
|
|
result_size_ == 1;
|
2011-09-16 11:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-27 12:33:24 +00:00
|
|
|
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
|
|
|
|
CEntryStub::GenerateAheadOfTime(isolate);
|
|
|
|
WriteInt32ToHeapNumberStub::GenerateFixedRegStubsAheadOfTime(isolate);
|
|
|
|
StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
|
2013-04-04 17:55:43 +00:00
|
|
|
StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
|
2013-02-27 12:33:24 +00:00
|
|
|
RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate);
|
2013-04-25 16:00:32 +00:00
|
|
|
if (FLAG_optimize_constructed_arrays) {
|
|
|
|
ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
|
|
|
|
}
|
2011-09-16 11:29:13 +00:00
|
|
|
}
|
2011-09-16 13:06:51 +00:00
|
|
|
|
|
|
|
|
2013-02-27 12:33:24 +00:00
|
|
|
void CodeStub::GenerateFPStubs(Isolate* isolate) {
|
2013-04-07 04:34:20 +00:00
|
|
|
SaveFPRegsMode mode = kSaveFPRegs;
|
2012-12-18 16:25:45 +00:00
|
|
|
CEntryStub save_doubles(1, mode);
|
|
|
|
StoreBufferOverflowStub stub(mode);
|
|
|
|
// These stubs might already be in the snapshot, detect that and don't
|
|
|
|
// regenerate, which would lead to code stub initialization state being messed
|
|
|
|
// up.
|
2013-03-05 10:48:16 +00:00
|
|
|
Code* save_doubles_code;
|
|
|
|
if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) {
|
|
|
|
save_doubles_code = *save_doubles.GetCode(isolate);
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
2013-04-04 17:55:43 +00:00
|
|
|
Code* store_buffer_overflow_code;
|
|
|
|
if (!stub.FindCodeInCache(&store_buffer_overflow_code, isolate)) {
|
|
|
|
store_buffer_overflow_code = *stub.GetCode(isolate);
|
|
|
|
}
|
|
|
|
save_doubles_code->set_is_pregenerated(true);
|
|
|
|
store_buffer_overflow_code->set_is_pregenerated(true);
|
2013-03-05 10:48:16 +00:00
|
|
|
isolate->set_fp_stubs_generated(true);
|
2011-09-16 13:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-27 12:33:24 +00:00
|
|
|
void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
|
2011-09-28 12:23:40 +00:00
|
|
|
CEntryStub stub(1, kDontSaveFPRegs);
|
2013-02-27 12:33:24 +00:00
|
|
|
Handle<Code> code = stub.GetCode(isolate);
|
2011-09-28 12:23:40 +00:00
|
|
|
code->set_is_pregenerated(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-09 12:29:06 +00:00
|
|
|
static void JumpIfOOM(MacroAssembler* masm,
|
|
|
|
Register value,
|
|
|
|
Register scratch,
|
|
|
|
Label* oom_label) {
|
|
|
|
STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3);
|
|
|
|
STATIC_ASSERT(kFailureTag == 3);
|
|
|
|
__ and_(scratch, value, Operand(0xf));
|
|
|
|
__ cmp(scratch, Operand(0xf));
|
|
|
|
__ b(eq, oom_label);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void CEntryStub::GenerateCore(MacroAssembler* masm,
|
|
|
|
Label* throw_normal_exception,
|
|
|
|
Label* throw_termination_exception,
|
|
|
|
Label* throw_out_of_memory_exception,
|
|
|
|
bool do_gc,
|
2011-01-25 07:49:39 +00:00
|
|
|
bool always_allocate) {
|
2010-08-25 09:44:44 +00:00
|
|
|
// r0: result parameter for PerformGC, if any
|
|
|
|
// r4: number of arguments including receiver (C callee-saved)
|
|
|
|
// r5: pointer to builtin function (C callee-saved)
|
|
|
|
// r6: pointer to the first argument (C callee-saved)
|
2011-03-22 13:20:04 +00:00
|
|
|
Isolate* isolate = masm->isolate();
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
if (do_gc) {
|
|
|
|
// Passing r0.
|
2011-04-27 14:29:25 +00:00
|
|
|
__ PrepareCallCFunction(1, 0, r1);
|
|
|
|
__ CallCFunction(ExternalReference::perform_gc_function(isolate),
|
|
|
|
1, 0);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ExternalReference scope_depth =
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference::heap_always_allocate_scope_depth(isolate);
|
2010-08-25 09:44:44 +00:00
|
|
|
if (always_allocate) {
|
|
|
|
__ mov(r0, Operand(scope_depth));
|
|
|
|
__ ldr(r1, MemOperand(r0));
|
|
|
|
__ add(r1, r1, Operand(1));
|
|
|
|
__ str(r1, MemOperand(r0));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call C built-in.
|
|
|
|
// r0 = argc, r1 = argv
|
|
|
|
__ mov(r0, Operand(r4));
|
|
|
|
__ mov(r1, Operand(r6));
|
|
|
|
|
2011-01-25 07:49:39 +00:00
|
|
|
#if defined(V8_HOST_ARCH_ARM)
|
2010-08-25 09:44:44 +00:00
|
|
|
int frame_alignment = MacroAssembler::ActivationFrameAlignment();
|
|
|
|
int frame_alignment_mask = frame_alignment - 1;
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
if (frame_alignment > kPointerSize) {
|
|
|
|
Label alignment_as_expected;
|
|
|
|
ASSERT(IsPowerOf2(frame_alignment));
|
2011-01-26 09:52:25 +00:00
|
|
|
__ tst(sp, Operand(frame_alignment_mask));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, &alignment_as_expected);
|
|
|
|
// Don't use Check here, as it will call Runtime_Abort re-entering here.
|
|
|
|
__ stop("Unexpected alignment");
|
|
|
|
__ bind(&alignment_as_expected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-24 07:39:35 +00:00
|
|
|
__ mov(r2, Operand(ExternalReference::isolate_address(isolate)));
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2011-06-15 09:17:54 +00:00
|
|
|
// 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.
|
2011-01-25 07:49:39 +00:00
|
|
|
// 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.
|
2012-06-12 17:26:28 +00:00
|
|
|
{
|
|
|
|
// Prevent literal pool emission before return address.
|
|
|
|
Assembler::BlockConstPoolScope block_const_pool(masm);
|
|
|
|
masm->add(lr, pc, Operand(4));
|
|
|
|
__ str(lr, MemOperand(sp, 0));
|
|
|
|
masm->Jump(r5);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-04-15 15:55:47 +00:00
|
|
|
__ VFPEnsureFPSCRState(r2);
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
if (always_allocate) {
|
|
|
|
// It's okay to clobber r2 and r3 here. Don't mess with r0 and r1
|
|
|
|
// though (contain the result).
|
|
|
|
__ mov(r2, Operand(scope_depth));
|
|
|
|
__ ldr(r3, MemOperand(r2));
|
|
|
|
__ sub(r3, r3, Operand(1));
|
|
|
|
__ str(r3, MemOperand(r2));
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for failure result
|
|
|
|
Label failure_returned;
|
|
|
|
STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0);
|
|
|
|
// Lower 2 bits of r2 are 0 iff r0 has failure tag.
|
|
|
|
__ add(r2, r0, Operand(1));
|
|
|
|
__ tst(r2, Operand(kFailureTagMask));
|
|
|
|
__ b(eq, &failure_returned);
|
|
|
|
|
|
|
|
// Exit C frame and return.
|
|
|
|
// r0:r1: result
|
|
|
|
// sp: stack pointer
|
|
|
|
// fp: frame pointer
|
2011-02-15 13:53:51 +00:00
|
|
|
// Callee-saved register r4 still holds argc.
|
|
|
|
__ LeaveExitFrame(save_doubles_, r4);
|
|
|
|
__ mov(pc, lr);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// check if we should retry or throw exception
|
|
|
|
Label retry;
|
|
|
|
__ bind(&failure_returned);
|
|
|
|
STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0);
|
|
|
|
__ tst(r0, Operand(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize));
|
|
|
|
__ b(eq, &retry);
|
|
|
|
|
|
|
|
// Special handling of out of memory exceptions.
|
2013-01-09 12:29:06 +00:00
|
|
|
JumpIfOOM(masm, r0, ip, throw_out_of_memory_exception);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-04-16 12:16:55 +00:00
|
|
|
// Retrieve the pending exception.
|
2011-09-08 16:29:57 +00:00
|
|
|
__ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
|
2011-03-22 13:20:04 +00:00
|
|
|
isolate)));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ldr(r0, MemOperand(ip));
|
2013-04-16 12:16:55 +00:00
|
|
|
|
|
|
|
// See if we just retrieved an OOM exception.
|
|
|
|
JumpIfOOM(masm, r0, ip, throw_out_of_memory_exception);
|
|
|
|
|
|
|
|
// Clear the pending exception.
|
|
|
|
__ mov(r3, Operand(isolate->factory()->the_hole_value()));
|
|
|
|
__ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
|
|
|
|
isolate)));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ str(r3, MemOperand(ip));
|
|
|
|
|
|
|
|
// Special handling of termination exceptions which are uncatchable
|
|
|
|
// by javascript code.
|
2011-03-22 13:20:04 +00:00
|
|
|
__ cmp(r0, Operand(isolate->factory()->termination_exception()));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, throw_termination_exception);
|
|
|
|
|
|
|
|
// Handle normal exception.
|
|
|
|
__ jmp(throw_normal_exception);
|
|
|
|
|
|
|
|
__ bind(&retry); // pass last failure (r0) as parameter (r0) when retrying
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CEntryStub::Generate(MacroAssembler* masm) {
|
|
|
|
// Called from JavaScript; parameters are on stack as if calling JS function
|
|
|
|
// r0: number of arguments including receiver
|
|
|
|
// r1: 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)
|
|
|
|
|
|
|
|
// Result returned in r0 or r0+r1 by default.
|
|
|
|
|
|
|
|
// NOTE: Invocations of builtins may return failure objects
|
|
|
|
// instead of a proper result. The builtin entry handles
|
|
|
|
// this by performing a garbage collection and retrying the
|
|
|
|
// builtin once.
|
|
|
|
|
2011-02-04 13:43:38 +00:00
|
|
|
// Compute the argv pointer in a callee-saved register.
|
|
|
|
__ add(r6, sp, Operand(r0, LSL, kPointerSizeLog2));
|
|
|
|
__ sub(r6, r6, Operand(kPointerSize));
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Enter the exit frame that transitions from JavaScript to C++.
|
2011-09-15 11:30:45 +00:00
|
|
|
FrameScope scope(masm, StackFrame::MANUAL);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ EnterExitFrame(save_doubles_);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up argc and the builtin function in callee-saved registers.
|
2011-02-04 13:43:38 +00:00
|
|
|
__ mov(r4, Operand(r0));
|
|
|
|
__ mov(r5, Operand(r1));
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// r4: number of arguments (C callee-saved)
|
|
|
|
// r5: pointer to builtin function (C callee-saved)
|
|
|
|
// r6: pointer to first argument (C callee-saved)
|
|
|
|
|
|
|
|
Label throw_normal_exception;
|
|
|
|
Label throw_termination_exception;
|
|
|
|
Label throw_out_of_memory_exception;
|
|
|
|
|
|
|
|
// Call into the runtime system.
|
|
|
|
GenerateCore(masm,
|
|
|
|
&throw_normal_exception,
|
|
|
|
&throw_termination_exception,
|
|
|
|
&throw_out_of_memory_exception,
|
|
|
|
false,
|
2011-01-25 07:49:39 +00:00
|
|
|
false);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Do space-specific GC and retry runtime call.
|
|
|
|
GenerateCore(masm,
|
|
|
|
&throw_normal_exception,
|
|
|
|
&throw_termination_exception,
|
|
|
|
&throw_out_of_memory_exception,
|
|
|
|
true,
|
2011-01-25 07:49:39 +00:00
|
|
|
false);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Do full GC and retry runtime call one final time.
|
|
|
|
Failure* failure = Failure::InternalError();
|
|
|
|
__ mov(r0, Operand(reinterpret_cast<int32_t>(failure)));
|
|
|
|
GenerateCore(masm,
|
|
|
|
&throw_normal_exception,
|
|
|
|
&throw_termination_exception,
|
|
|
|
&throw_out_of_memory_exception,
|
|
|
|
true,
|
2011-01-25 07:49:39 +00:00
|
|
|
true);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&throw_out_of_memory_exception);
|
2012-02-10 08:47:35 +00:00
|
|
|
// Set external caught exception to false.
|
|
|
|
Isolate* isolate = masm->isolate();
|
|
|
|
ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress,
|
|
|
|
isolate);
|
2013-01-04 10:56:24 +00:00
|
|
|
__ mov(r0, Operand(false, RelocInfo::NONE32));
|
2012-02-10 08:47:35 +00:00
|
|
|
__ mov(r2, Operand(external_caught));
|
|
|
|
__ str(r0, MemOperand(r2));
|
|
|
|
|
|
|
|
// Set pending exception and r0 to out of memory exception.
|
2013-01-09 12:29:06 +00:00
|
|
|
Label already_have_failure;
|
|
|
|
JumpIfOOM(masm, r0, ip, &already_have_failure);
|
|
|
|
Failure* out_of_memory = Failure::OutOfMemoryException(0x1);
|
2012-02-10 08:47:35 +00:00
|
|
|
__ mov(r0, Operand(reinterpret_cast<int32_t>(out_of_memory)));
|
2013-01-09 12:29:06 +00:00
|
|
|
__ bind(&already_have_failure);
|
2012-02-10 08:47:35 +00:00
|
|
|
__ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
|
|
|
|
isolate)));
|
|
|
|
__ str(r0, MemOperand(r2));
|
|
|
|
// Fall through to the next label.
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&throw_termination_exception);
|
2012-02-10 08:47:35 +00:00
|
|
|
__ ThrowUncatchable(r0);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&throw_normal_exception);
|
2012-02-10 08:47:35 +00:00
|
|
|
__ Throw(r0);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) {
|
|
|
|
// r0: code entry
|
|
|
|
// r1: function
|
|
|
|
// r2: receiver
|
|
|
|
// r3: argc
|
|
|
|
// [sp+0]: argv
|
|
|
|
|
2011-11-11 13:48:14 +00:00
|
|
|
Label invoke, handler_entry, exit;
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Called from C, so do not pop argc and args on exit (preserve sp)
|
|
|
|
// No need to save register-passed args
|
|
|
|
// Save callee-saved registers (incl. cp and fp), sp, and lr
|
|
|
|
__ stm(db_w, sp, kCalleeSaved | lr.bit());
|
|
|
|
|
2013-04-07 04:34:20 +00:00
|
|
|
// Save callee-saved vfp registers.
|
|
|
|
__ vstm(db_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
|
|
|
|
// Set up the reserved register for 0.0.
|
|
|
|
__ vmov(kDoubleRegZero, 0.0);
|
2013-04-15 15:55:47 +00:00
|
|
|
__ VFPEnsureFPSCRState(r4);
|
2011-06-22 06:24:34 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Get address of argv, see stm above.
|
|
|
|
// r0: code entry
|
|
|
|
// r1: function
|
|
|
|
// r2: receiver
|
|
|
|
// r3: argc
|
2011-06-22 06:24:34 +00:00
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up argv in r4.
|
2011-06-22 06:24:34 +00:00
|
|
|
int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize;
|
2013-04-07 04:34:20 +00:00
|
|
|
offset_to_argv += kNumDoubleCalleeSaved * kDoubleSize;
|
2011-06-22 06:24:34 +00:00
|
|
|
__ ldr(r4, MemOperand(sp, offset_to_argv));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Push a frame with special values setup to mark it as an entry frame.
|
|
|
|
// r0: code entry
|
|
|
|
// r1: function
|
|
|
|
// r2: receiver
|
|
|
|
// r3: argc
|
|
|
|
// r4: argv
|
2011-03-22 13:20:04 +00:00
|
|
|
Isolate* isolate = masm->isolate();
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(r8, Operand(-1)); // Push a bad frame pointer to fail if it is used.
|
|
|
|
int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY;
|
|
|
|
__ mov(r7, Operand(Smi::FromInt(marker)));
|
|
|
|
__ mov(r6, Operand(Smi::FromInt(marker)));
|
2011-03-22 13:20:04 +00:00
|
|
|
__ mov(r5,
|
2011-09-08 16:29:57 +00:00
|
|
|
Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate)));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ldr(r5, MemOperand(r5));
|
|
|
|
__ Push(r8, r7, r6, r5);
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up frame pointer for the frame to be pushed.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ add(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// If this is the outermost JS call, set js_entry_sp value.
|
2011-05-17 11:11:12 +00:00
|
|
|
Label non_outermost_js;
|
2011-09-08 16:29:57 +00:00
|
|
|
ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ mov(r5, Operand(ExternalReference(js_entry_sp)));
|
|
|
|
__ ldr(r6, MemOperand(r5));
|
2011-08-23 12:00:09 +00:00
|
|
|
__ cmp(r6, Operand::Zero());
|
2011-05-17 11:11:12 +00:00
|
|
|
__ b(ne, &non_outermost_js);
|
|
|
|
__ str(fp, MemOperand(r5));
|
|
|
|
__ mov(ip, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
|
|
|
|
Label cont;
|
|
|
|
__ b(&cont);
|
|
|
|
__ bind(&non_outermost_js);
|
|
|
|
__ mov(ip, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
|
|
|
|
__ bind(&cont);
|
|
|
|
__ push(ip);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-11-11 13:48:14 +00:00
|
|
|
// Jump to a faked try block that does the invoke, with a faked catch
|
|
|
|
// block that sets the pending exception.
|
|
|
|
__ jmp(&invoke);
|
2012-06-12 17:26:28 +00:00
|
|
|
|
|
|
|
// Block literal pool emission whilst taking the position of the handler
|
|
|
|
// entry. This avoids making the assumption that literal pools are always
|
|
|
|
// emitted after an instruction is emitted, rather than before.
|
|
|
|
{
|
|
|
|
Assembler::BlockConstPoolScope block_const_pool(masm);
|
|
|
|
__ 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)));
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
__ str(r0, MemOperand(ip));
|
|
|
|
__ mov(r0, Operand(reinterpret_cast<int32_t>(Failure::Exception())));
|
|
|
|
__ b(&exit);
|
|
|
|
|
2011-11-11 13:48:14 +00:00
|
|
|
// Invoke: Link this frame into the handler chain. There's only one
|
|
|
|
// handler block in this code object, so its index is 0.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&invoke);
|
|
|
|
// Must preserve r0-r4, r5-r7 are available.
|
2012-02-09 09:43:37 +00:00
|
|
|
__ PushTryHandler(StackHandler::JS_ENTRY, 0);
|
2010-08-25 09:44:44 +00:00
|
|
|
// If an exception not caught by another handler occurs, this handler
|
|
|
|
// returns control to the code after the bl(&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.
|
2011-10-04 09:07:50 +00:00
|
|
|
__ mov(r5, Operand(isolate->factory()->the_hole_value()));
|
2011-09-08 16:29:57 +00:00
|
|
|
__ mov(ip, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
|
2011-03-22 13:20:04 +00:00
|
|
|
isolate)));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ str(r5, 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
|
|
|
|
// r0: code entry
|
|
|
|
// r1: function
|
|
|
|
// r2: receiver
|
|
|
|
// r3: argc
|
|
|
|
// r4: argv
|
|
|
|
if (is_construct) {
|
2011-03-23 13:40:07 +00:00
|
|
|
ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
|
2011-03-22 13:20:04 +00:00
|
|
|
isolate);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(ip, Operand(construct_entry));
|
|
|
|
} else {
|
2011-03-23 13:40:07 +00:00
|
|
|
ExternalReference entry(Builtins::kJSEntryTrampoline, isolate);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(ip, Operand(entry));
|
|
|
|
}
|
|
|
|
__ ldr(ip, MemOperand(ip)); // deref address
|
|
|
|
|
|
|
|
// Branch and link to JSEntryTrampoline. We don't use the double underscore
|
|
|
|
// macro for the add instruction because we don't want the coverage tool
|
2012-06-12 17:26:28 +00:00
|
|
|
// inserting instructions here after we read the pc. We block literal pool
|
|
|
|
// emission for the same reason.
|
|
|
|
{
|
|
|
|
Assembler::BlockConstPoolScope block_const_pool(masm);
|
|
|
|
__ mov(lr, Operand(pc));
|
|
|
|
masm->add(pc, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-05-17 11:11:12 +00:00
|
|
|
// Unlink this frame from the handler chain.
|
|
|
|
__ PopTryHandler();
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-05-17 11:11:12 +00:00
|
|
|
__ bind(&exit); // r0 holds result
|
|
|
|
// Check if the current stack frame is marked as the outermost JS frame.
|
|
|
|
Label non_outermost_js_2;
|
|
|
|
__ pop(r5);
|
|
|
|
__ cmp(r5, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
|
|
|
|
__ b(ne, &non_outermost_js_2);
|
2011-08-23 12:00:09 +00:00
|
|
|
__ mov(r6, Operand::Zero());
|
2010-12-07 11:31:57 +00:00
|
|
|
__ mov(r5, Operand(ExternalReference(js_entry_sp)));
|
2011-05-17 11:11:12 +00:00
|
|
|
__ str(r6, MemOperand(r5));
|
|
|
|
__ bind(&non_outermost_js_2);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Restore the top frame descriptors from the stack.
|
|
|
|
__ pop(r3);
|
2011-03-22 13:20:04 +00:00
|
|
|
__ mov(ip,
|
2011-09-08 16:29:57 +00:00
|
|
|
Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate)));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ str(r3, MemOperand(ip));
|
|
|
|
|
|
|
|
// Reset the stack to the callee saved registers.
|
|
|
|
__ add(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset));
|
|
|
|
|
|
|
|
// Restore callee-saved registers and return.
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ mov(lr, Operand(pc));
|
|
|
|
}
|
|
|
|
#endif
|
2011-06-22 06:24:34 +00:00
|
|
|
|
2013-04-07 04:34:20 +00:00
|
|
|
// Restore callee-saved vfp registers.
|
|
|
|
__ vldm(ia_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg);
|
2011-06-22 06:24:34 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ldm(ia_w, sp, kCalleeSaved | pc.bit());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-19 14:53:38 +00:00
|
|
|
// Uses registers r0 to r4.
|
|
|
|
// Expected input (depending on whether args are in registers or on the stack):
|
|
|
|
// * object: r0 or at sp + 1 * kPointerSize.
|
|
|
|
// * function: r1 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 on the stack,
|
|
|
|
// in the safepoint slot for register r4.
|
|
|
|
// (See LCodeGen::DoInstanceOfKnownGlobal)
|
2010-08-25 09:44:44 +00:00
|
|
|
void InstanceofStub::Generate(MacroAssembler* masm) {
|
2011-01-19 14:53:38 +00:00
|
|
|
// Call site inlining and patching implies arguments in registers.
|
|
|
|
ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck());
|
|
|
|
// ReturnTrueFalse is only implemented for inlined call sites.
|
|
|
|
ASSERT(!ReturnTrueFalseObject() || HasCallSiteInlineCheck());
|
|
|
|
|
2010-12-21 10:52:50 +00:00
|
|
|
// Fixed register usage throughout the stub:
|
2010-12-23 16:33:30 +00:00
|
|
|
const Register object = r0; // Object (lhs).
|
2011-01-19 14:53:38 +00:00
|
|
|
Register map = r3; // Map of the object.
|
2010-12-23 16:33:30 +00:00
|
|
|
const Register function = r1; // Function (rhs).
|
2010-12-21 10:52:50 +00:00
|
|
|
const Register prototype = r4; // Prototype of the function.
|
2011-01-19 14:53:38 +00:00
|
|
|
const Register inline_site = r9;
|
2010-12-21 10:52:50 +00:00
|
|
|
const Register scratch = r2;
|
2011-01-19 14:53:38 +00:00
|
|
|
|
2012-01-11 09:39:37 +00:00
|
|
|
const int32_t kDeltaToLoadBoolResult = 4 * kPointerSize;
|
2011-01-19 14:53:38 +00:00
|
|
|
|
2010-12-21 10:52:50 +00:00
|
|
|
Label slow, loop, is_instance, is_not_instance, not_js_object;
|
2011-01-19 14:53:38 +00:00
|
|
|
|
2011-01-05 12:01:53 +00:00
|
|
|
if (!HasArgsInRegisters()) {
|
2010-12-23 16:33:30 +00:00
|
|
|
__ ldr(object, MemOperand(sp, 1 * kPointerSize));
|
|
|
|
__ ldr(function, MemOperand(sp, 0));
|
2010-12-21 10:52:50 +00:00
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2010-12-21 10:52:50 +00:00
|
|
|
// Check that the left hand is a JS object and load map.
|
2011-01-26 07:44:45 +00:00
|
|
|
__ JumpIfSmi(object, ¬_js_object);
|
2010-12-23 16:33:30 +00:00
|
|
|
__ IsObjectJSObjectType(object, map, scratch, ¬_js_object);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-01-19 14:53:38 +00:00
|
|
|
// 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()) {
|
|
|
|
Label miss;
|
2012-01-27 16:54:22 +00:00
|
|
|
__ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex);
|
2011-01-19 14:53:38 +00:00
|
|
|
__ b(ne, &miss);
|
2012-01-27 16:54:22 +00:00
|
|
|
__ CompareRoot(map, Heap::kInstanceofCacheMapRootIndex);
|
2011-01-19 14:53:38 +00:00
|
|
|
__ b(ne, &miss);
|
|
|
|
__ LoadRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
|
|
|
|
__ Ret(HasArgsInRegisters() ? 0 : 2);
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-01-19 14:53:38 +00:00
|
|
|
// Get the prototype of the function.
|
2011-10-17 12:44:16 +00:00
|
|
|
__ TryGetFunctionPrototype(function, prototype, scratch, &slow, true);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Check that the function prototype is a JS object.
|
2011-01-26 07:44:45 +00:00
|
|
|
__ JumpIfSmi(prototype, &slow);
|
2010-12-21 10:52:50 +00:00
|
|
|
__ IsObjectJSObjectType(prototype, scratch, scratch, &slow);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-01-19 14:53:38 +00:00
|
|
|
// 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 {
|
|
|
|
ASSERT(HasArgsInRegisters());
|
|
|
|
// Patch the (relocated) inlined map check.
|
|
|
|
|
|
|
|
// The offset was stored in r4 safepoint slot.
|
|
|
|
// (See LCodeGen::DoDeferredLInstanceOfKnownGlobal)
|
2011-02-21 11:29:45 +00:00
|
|
|
__ LoadFromSafepointRegisterSlot(scratch, r4);
|
2011-01-19 14:53:38 +00:00
|
|
|
__ sub(inline_site, lr, scratch);
|
|
|
|
// Get the map location in scratch and patch it.
|
|
|
|
__ GetRelocatedValueLocation(inline_site, scratch);
|
2012-01-11 09:39:37 +00:00
|
|
|
__ ldr(scratch, MemOperand(scratch));
|
|
|
|
__ str(map, FieldMemOperand(scratch, JSGlobalPropertyCell::kValueOffset));
|
2011-01-19 14:53:38 +00:00
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Register mapping: r3 is object map and r4 is function prototype.
|
|
|
|
// Get prototype of object into r2.
|
2010-12-21 10:52:50 +00:00
|
|
|
__ ldr(scratch, FieldMemOperand(map, Map::kPrototypeOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-01-19 14:53:38 +00:00
|
|
|
// We don't need map any more. Use it as a scratch register.
|
|
|
|
Register scratch2 = map;
|
|
|
|
map = no_reg;
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Loop through the prototype chain looking for the function prototype.
|
2011-01-19 14:53:38 +00:00
|
|
|
__ LoadRoot(scratch2, Heap::kNullValueRootIndex);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&loop);
|
2010-12-21 10:52:50 +00:00
|
|
|
__ cmp(scratch, Operand(prototype));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, &is_instance);
|
2011-01-19 14:53:38 +00:00
|
|
|
__ cmp(scratch, scratch2);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, &is_not_instance);
|
2010-12-21 10:52:50 +00:00
|
|
|
__ ldr(scratch, FieldMemOperand(scratch, HeapObject::kMapOffset));
|
|
|
|
__ ldr(scratch, FieldMemOperand(scratch, Map::kPrototypeOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ jmp(&loop);
|
|
|
|
|
|
|
|
__ bind(&is_instance);
|
2011-01-19 14:53:38 +00:00
|
|
|
if (!HasCallSiteInlineCheck()) {
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(0)));
|
|
|
|
__ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
|
|
|
|
} else {
|
|
|
|
// Patch the call site to return true.
|
|
|
|
__ LoadRoot(r0, Heap::kTrueValueRootIndex);
|
|
|
|
__ add(inline_site, inline_site, Operand(kDeltaToLoadBoolResult));
|
|
|
|
// Get the boolean result location in scratch and patch it.
|
|
|
|
__ GetRelocatedValueLocation(inline_site, scratch);
|
|
|
|
__ str(r0, MemOperand(scratch));
|
|
|
|
|
|
|
|
if (!ReturnTrueFalseObject()) {
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(0)));
|
|
|
|
}
|
|
|
|
}
|
2011-01-05 12:01:53 +00:00
|
|
|
__ Ret(HasArgsInRegisters() ? 0 : 2);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&is_not_instance);
|
2011-01-19 14:53:38 +00:00
|
|
|
if (!HasCallSiteInlineCheck()) {
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(1)));
|
|
|
|
__ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex);
|
|
|
|
} else {
|
|
|
|
// Patch the call site to return false.
|
|
|
|
__ LoadRoot(r0, Heap::kFalseValueRootIndex);
|
|
|
|
__ add(inline_site, inline_site, Operand(kDeltaToLoadBoolResult));
|
|
|
|
// Get the boolean result location in scratch and patch it.
|
|
|
|
__ GetRelocatedValueLocation(inline_site, scratch);
|
|
|
|
__ str(r0, MemOperand(scratch));
|
|
|
|
|
|
|
|
if (!ReturnTrueFalseObject()) {
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(1)));
|
|
|
|
}
|
|
|
|
}
|
2011-01-05 12:01:53 +00:00
|
|
|
__ Ret(HasArgsInRegisters() ? 0 : 2);
|
2010-12-21 10:52:50 +00:00
|
|
|
|
|
|
|
Label object_not_null, object_not_null_or_smi;
|
|
|
|
__ bind(¬_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.
|
2011-01-26 07:44:45 +00:00
|
|
|
__ JumpIfSmi(function, &slow);
|
2011-01-19 14:53:38 +00:00
|
|
|
__ CompareObjectType(function, scratch2, scratch, JS_FUNCTION_TYPE);
|
2010-12-21 10:52:50 +00:00
|
|
|
__ b(ne, &slow);
|
|
|
|
|
|
|
|
// Null is not instance of anything.
|
2011-04-14 08:01:19 +00:00
|
|
|
__ cmp(scratch, Operand(masm->isolate()->factory()->null_value()));
|
2010-12-21 10:52:50 +00:00
|
|
|
__ b(ne, &object_not_null);
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(1)));
|
2011-01-05 12:01:53 +00:00
|
|
|
__ Ret(HasArgsInRegisters() ? 0 : 2);
|
2010-12-21 10:52:50 +00:00
|
|
|
|
|
|
|
__ bind(&object_not_null);
|
|
|
|
// Smi values are not instances of anything.
|
2011-01-26 07:44:45 +00:00
|
|
|
__ JumpIfNotSmi(object, &object_not_null_or_smi);
|
2010-12-21 10:52:50 +00:00
|
|
|
__ mov(r0, Operand(Smi::FromInt(1)));
|
2011-01-05 12:01:53 +00:00
|
|
|
__ Ret(HasArgsInRegisters() ? 0 : 2);
|
2010-12-21 10:52:50 +00:00
|
|
|
|
|
|
|
__ bind(&object_not_null_or_smi);
|
|
|
|
// String values are not instances of anything.
|
|
|
|
__ IsObjectJSStringType(object, scratch, &slow);
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(1)));
|
2011-01-05 12:01:53 +00:00
|
|
|
__ Ret(HasArgsInRegisters() ? 0 : 2);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Slow-case. Tail call builtin.
|
2011-01-06 12:41:41 +00:00
|
|
|
__ bind(&slow);
|
2011-01-19 14:53:38 +00:00
|
|
|
if (!ReturnTrueFalseObject()) {
|
|
|
|
if (HasArgsInRegisters()) {
|
|
|
|
__ Push(r0, r1);
|
|
|
|
}
|
2011-04-29 20:07:41 +00:00
|
|
|
__ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
|
2011-01-19 14:53:38 +00:00
|
|
|
} else {
|
2011-09-15 11:30:45 +00:00
|
|
|
{
|
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
|
|
|
__ Push(r0, r1);
|
|
|
|
__ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION);
|
|
|
|
}
|
2011-08-23 12:00:09 +00:00
|
|
|
__ cmp(r0, Operand::Zero());
|
2011-01-19 14:53:38 +00:00
|
|
|
__ LoadRoot(r0, Heap::kTrueValueRootIndex, eq);
|
|
|
|
__ LoadRoot(r0, Heap::kFalseValueRootIndex, ne);
|
|
|
|
__ Ret(HasArgsInRegisters() ? 0 : 2);
|
2010-12-23 16:33:30 +00:00
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-21 17:54:36 +00:00
|
|
|
void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label miss;
|
|
|
|
Register receiver;
|
|
|
|
if (kind() == Code::KEYED_LOAD_IC) {
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- lr : return address
|
|
|
|
// -- r0 : key
|
|
|
|
// -- r1 : receiver
|
|
|
|
// -----------------------------------
|
2013-02-28 17:03:34 +00:00
|
|
|
__ cmp(r0, Operand(masm->isolate()->factory()->prototype_string()));
|
2013-01-21 17:54:36 +00:00
|
|
|
__ b(ne, &miss);
|
|
|
|
receiver = r1;
|
|
|
|
} else {
|
|
|
|
ASSERT(kind() == Code::LOAD_IC);
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- r2 : name
|
|
|
|
// -- lr : return address
|
|
|
|
// -- r0 : receiver
|
|
|
|
// -- sp[0] : receiver
|
|
|
|
// -----------------------------------
|
|
|
|
receiver = r0;
|
|
|
|
}
|
|
|
|
|
|
|
|
StubCompiler::GenerateLoadFunctionPrototype(masm, receiver, r3, r4, &miss);
|
|
|
|
__ bind(&miss);
|
2013-03-13 14:11:05 +00:00
|
|
|
StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind()));
|
2013-01-21 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-21 14:53:29 +00:00
|
|
|
void StringLengthStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label miss;
|
|
|
|
Register receiver;
|
|
|
|
if (kind() == Code::KEYED_LOAD_IC) {
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- lr : return address
|
|
|
|
// -- r0 : key
|
|
|
|
// -- r1 : receiver
|
|
|
|
// -----------------------------------
|
2013-02-28 17:03:34 +00:00
|
|
|
__ cmp(r0, Operand(masm->isolate()->factory()->length_string()));
|
2013-01-21 14:53:29 +00:00
|
|
|
__ b(ne, &miss);
|
|
|
|
receiver = r1;
|
|
|
|
} else {
|
|
|
|
ASSERT(kind() == Code::LOAD_IC);
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- r2 : name
|
|
|
|
// -- lr : return address
|
|
|
|
// -- r0 : receiver
|
|
|
|
// -- sp[0] : receiver
|
|
|
|
// -----------------------------------
|
|
|
|
receiver = r0;
|
|
|
|
}
|
|
|
|
|
|
|
|
StubCompiler::GenerateLoadStringLength(masm, receiver, r3, r4, &miss,
|
|
|
|
support_wrapper_);
|
|
|
|
|
|
|
|
__ bind(&miss);
|
2013-03-13 14:11:05 +00:00
|
|
|
StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind()));
|
2013-01-21 14:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-25 11:55:29 +00:00
|
|
|
void StoreArrayLengthStub::Generate(MacroAssembler* masm) {
|
|
|
|
// This accepts as a receiver anything JSArray::SetElementsLength accepts
|
|
|
|
// (currently anything except for external arrays which means anything with
|
|
|
|
// elements of FixedArray type). Value must be a number, but only smis are
|
|
|
|
// accepted as the most common case.
|
|
|
|
Label miss;
|
|
|
|
|
|
|
|
Register receiver;
|
|
|
|
Register value;
|
|
|
|
if (kind() == Code::KEYED_STORE_IC) {
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- lr : return address
|
|
|
|
// -- r0 : value
|
|
|
|
// -- r1 : key
|
|
|
|
// -- r2 : receiver
|
|
|
|
// -----------------------------------
|
2013-02-28 17:03:34 +00:00
|
|
|
__ cmp(r1, Operand(masm->isolate()->factory()->length_string()));
|
2013-01-25 11:55:29 +00:00
|
|
|
__ b(ne, &miss);
|
|
|
|
receiver = r2;
|
|
|
|
value = r0;
|
|
|
|
} else {
|
|
|
|
ASSERT(kind() == Code::STORE_IC);
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- lr : return address
|
|
|
|
// -- r0 : value
|
|
|
|
// -- r1 : receiver
|
|
|
|
// -- r2 : key
|
|
|
|
// -----------------------------------
|
|
|
|
receiver = r1;
|
|
|
|
value = r0;
|
|
|
|
}
|
|
|
|
Register scratch = r3;
|
|
|
|
|
|
|
|
// Check that the receiver isn't a smi.
|
|
|
|
__ JumpIfSmi(receiver, &miss);
|
|
|
|
|
|
|
|
// Check that the object is a JS array.
|
|
|
|
__ CompareObjectType(receiver, scratch, scratch, JS_ARRAY_TYPE);
|
|
|
|
__ b(ne, &miss);
|
|
|
|
|
|
|
|
// Check that elements are FixedArray.
|
|
|
|
// We rely on StoreIC_ArrayLength below to deal with all types of
|
|
|
|
// fast elements (including COW).
|
|
|
|
__ ldr(scratch, FieldMemOperand(receiver, JSArray::kElementsOffset));
|
|
|
|
__ CompareObjectType(scratch, scratch, scratch, FIXED_ARRAY_TYPE);
|
|
|
|
__ b(ne, &miss);
|
|
|
|
|
|
|
|
// Check that the array has fast properties, otherwise the length
|
|
|
|
// property might have been redefined.
|
|
|
|
__ ldr(scratch, FieldMemOperand(receiver, JSArray::kPropertiesOffset));
|
|
|
|
__ ldr(scratch, FieldMemOperand(scratch, FixedArray::kMapOffset));
|
|
|
|
__ CompareRoot(scratch, Heap::kHashTableMapRootIndex);
|
|
|
|
__ b(eq, &miss);
|
|
|
|
|
|
|
|
// Check that value is a smi.
|
|
|
|
__ JumpIfNotSmi(value, &miss);
|
|
|
|
|
|
|
|
// Prepare tail call to StoreIC_ArrayLength.
|
|
|
|
__ Push(receiver, value);
|
|
|
|
|
|
|
|
ExternalReference ref =
|
|
|
|
ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate());
|
|
|
|
__ TailCallExternalReference(ref, 2, 1);
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
|
2013-03-13 14:11:05 +00:00
|
|
|
StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind()));
|
2013-01-25 11:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-19 14:53:38 +00:00
|
|
|
Register InstanceofStub::left() { return r0; }
|
|
|
|
|
|
|
|
|
|
|
|
Register InstanceofStub::right() { return r1; }
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
|
|
|
|
// The displacement is the offset of the last parameter (if any)
|
|
|
|
// relative to the frame pointer.
|
2012-03-12 13:56:56 +00:00
|
|
|
const int kDisplacement =
|
2010-08-25 09:44:44 +00:00
|
|
|
StandardFrameConstants::kCallerSPOffset - kPointerSize;
|
|
|
|
|
|
|
|
// Check that the key is a smi.
|
|
|
|
Label slow;
|
2011-01-26 07:44:45 +00:00
|
|
|
__ JumpIfNotSmi(r1, &slow);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Check if the calling frame is an arguments adaptor frame.
|
|
|
|
Label adaptor;
|
|
|
|
__ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
|
|
|
|
__ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
|
|
|
|
__ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
|
|
|
|
__ b(eq, &adaptor);
|
|
|
|
|
|
|
|
// Check index against formal parameters count limit passed in
|
|
|
|
// through register r0. Use unsigned comparison to get negative
|
|
|
|
// check for free.
|
|
|
|
__ cmp(r1, r0);
|
2011-01-06 10:56:23 +00:00
|
|
|
__ b(hs, &slow);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Read the argument from the stack and return it.
|
|
|
|
__ sub(r3, r0, r1);
|
|
|
|
__ add(r3, fp, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize));
|
|
|
|
__ ldr(r0, MemOperand(r3, kDisplacement));
|
|
|
|
__ Jump(lr);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
__ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
|
|
|
|
__ cmp(r1, r0);
|
|
|
|
__ b(cs, &slow);
|
|
|
|
|
|
|
|
// Read the argument from the adaptor frame and return it.
|
|
|
|
__ sub(r3, r0, r1);
|
|
|
|
__ add(r3, r2, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize));
|
|
|
|
__ ldr(r0, MemOperand(r3, kDisplacement));
|
|
|
|
__ Jump(lr);
|
|
|
|
|
|
|
|
// Slow-case: Handle non-smi or out-of-bounds access to arguments
|
|
|
|
// by calling the runtime system.
|
|
|
|
__ bind(&slow);
|
|
|
|
__ push(r1);
|
|
|
|
__ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-16 14:12:58 +00:00
|
|
|
void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) {
|
2010-08-25 09:44:44 +00:00
|
|
|
// sp[0] : number of parameters
|
|
|
|
// sp[4] : receiver displacement
|
|
|
|
// sp[8] : function
|
|
|
|
|
2011-06-16 14:12:58 +00:00
|
|
|
// Check if the calling frame is an arguments adaptor frame.
|
|
|
|
Label runtime;
|
|
|
|
__ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
|
|
|
|
__ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset));
|
|
|
|
__ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
|
|
|
|
__ b(ne, &runtime);
|
|
|
|
|
|
|
|
// Patch the arguments.length and the parameters pointer in the current frame.
|
|
|
|
__ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
|
|
|
|
__ str(r2, MemOperand(sp, 0 * kPointerSize));
|
|
|
|
__ add(r3, r3, Operand(r2, LSL, 1));
|
|
|
|
__ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
|
|
|
|
__ str(r3, MemOperand(sp, 1 * kPointerSize));
|
|
|
|
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) {
|
|
|
|
// Stack layout:
|
|
|
|
// sp[0] : number of parameters (tagged)
|
|
|
|
// sp[4] : address of receiver argument
|
|
|
|
// sp[8] : function
|
|
|
|
// Registers used over whole function:
|
|
|
|
// r6 : allocated object (tagged)
|
|
|
|
// r9 : mapped parameter count (tagged)
|
|
|
|
|
|
|
|
__ ldr(r1, MemOperand(sp, 0 * kPointerSize));
|
|
|
|
// r1 = parameter count (tagged)
|
|
|
|
|
|
|
|
// Check if the calling frame is an arguments adaptor frame.
|
|
|
|
Label runtime;
|
|
|
|
Label adaptor_frame, try_allocate;
|
|
|
|
__ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
|
|
|
|
__ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset));
|
|
|
|
__ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
|
|
|
|
__ b(eq, &adaptor_frame);
|
|
|
|
|
|
|
|
// No adaptor, parameter count = argument count.
|
|
|
|
__ mov(r2, r1);
|
|
|
|
__ b(&try_allocate);
|
|
|
|
|
|
|
|
// We have an adaptor frame. Patch the parameters pointer.
|
|
|
|
__ bind(&adaptor_frame);
|
|
|
|
__ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset));
|
|
|
|
__ add(r3, r3, Operand(r2, LSL, 1));
|
|
|
|
__ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
|
|
|
|
__ str(r3, MemOperand(sp, 1 * kPointerSize));
|
|
|
|
|
|
|
|
// r1 = parameter count (tagged)
|
|
|
|
// r2 = argument count (tagged)
|
|
|
|
// Compute the mapped parameter count = min(r1, r2) in r1.
|
|
|
|
__ cmp(r1, Operand(r2));
|
|
|
|
__ mov(r1, Operand(r2), LeaveCC, gt);
|
|
|
|
|
|
|
|
__ 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.
|
|
|
|
__ cmp(r1, Operand(Smi::FromInt(0)));
|
2011-08-23 12:00:09 +00:00
|
|
|
__ mov(r9, Operand::Zero(), LeaveCC, eq);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ mov(r9, Operand(r1, LSL, 1), LeaveCC, ne);
|
|
|
|
__ add(r9, r9, Operand(kParameterMapHeaderSize), LeaveCC, ne);
|
|
|
|
|
|
|
|
// 2. Backing store.
|
|
|
|
__ add(r9, r9, Operand(r2, LSL, 1));
|
|
|
|
__ add(r9, r9, Operand(FixedArray::kHeaderSize));
|
|
|
|
|
|
|
|
// 3. Arguments object.
|
|
|
|
__ add(r9, r9, Operand(Heap::kArgumentsObjectSize));
|
|
|
|
|
|
|
|
// Do the allocation of all three objects in one go.
|
2013-03-25 15:54:15 +00:00
|
|
|
__ Allocate(r9, r0, r3, r4, &runtime, TAG_OBJECT);
|
2011-06-16 14:12:58 +00:00
|
|
|
|
|
|
|
// r0 = address of new object(s) (tagged)
|
|
|
|
// r2 = argument count (tagged)
|
2012-08-17 12:59:00 +00:00
|
|
|
// Get the arguments boilerplate from the current native context into r4.
|
2011-06-16 14:12:58 +00:00
|
|
|
const int kNormalOffset =
|
|
|
|
Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX);
|
|
|
|
const int kAliasedOffset =
|
|
|
|
Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX);
|
|
|
|
|
2012-08-17 12:59:00 +00:00
|
|
|
__ ldr(r4, MemOperand(r8, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
|
2012-08-17 09:03:08 +00:00
|
|
|
__ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
|
2011-08-23 12:00:09 +00:00
|
|
|
__ cmp(r1, Operand::Zero());
|
2011-06-16 14:12:58 +00:00
|
|
|
__ ldr(r4, MemOperand(r4, kNormalOffset), eq);
|
|
|
|
__ ldr(r4, MemOperand(r4, kAliasedOffset), ne);
|
|
|
|
|
|
|
|
// r0 = address of new object (tagged)
|
|
|
|
// r1 = mapped parameter count (tagged)
|
|
|
|
// r2 = argument count (tagged)
|
|
|
|
// r4 = address of boilerplate object (tagged)
|
|
|
|
// Copy the JS object part.
|
|
|
|
for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) {
|
|
|
|
__ ldr(r3, FieldMemOperand(r4, i));
|
|
|
|
__ str(r3, FieldMemOperand(r0, i));
|
|
|
|
}
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the callee in-object property.
|
2011-06-16 14:12:58 +00:00
|
|
|
STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
|
|
|
|
__ ldr(r3, MemOperand(sp, 2 * kPointerSize));
|
|
|
|
const int kCalleeOffset = JSObject::kHeaderSize +
|
|
|
|
Heap::kArgumentsCalleeIndex * kPointerSize;
|
|
|
|
__ str(r3, FieldMemOperand(r0, kCalleeOffset));
|
|
|
|
|
|
|
|
// Use the length (smi tagged) and set that as an in-object property too.
|
|
|
|
STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
|
|
|
|
const int kLengthOffset = JSObject::kHeaderSize +
|
|
|
|
Heap::kArgumentsLengthIndex * kPointerSize;
|
|
|
|
__ str(r2, FieldMemOperand(r0, kLengthOffset));
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the elements pointer in the allocated arguments object.
|
2011-06-16 14:12:58 +00:00
|
|
|
// If we allocated a parameter map, r4 will point there, otherwise
|
|
|
|
// it will point to the backing store.
|
|
|
|
__ add(r4, r0, Operand(Heap::kArgumentsObjectSize));
|
|
|
|
__ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
|
|
|
|
|
|
|
|
// r0 = address of new object (tagged)
|
|
|
|
// r1 = mapped parameter count (tagged)
|
|
|
|
// r2 = argument count (tagged)
|
|
|
|
// r4 = address of parameter map or backing store (tagged)
|
|
|
|
// Initialize parameter map. If there are no mapped arguments, we're done.
|
|
|
|
Label skip_parameter_map;
|
|
|
|
__ cmp(r1, Operand(Smi::FromInt(0)));
|
|
|
|
// Move backing store address to r3, because it is
|
|
|
|
// expected there when filling in the unmapped arguments.
|
|
|
|
__ mov(r3, r4, LeaveCC, eq);
|
|
|
|
__ b(eq, &skip_parameter_map);
|
|
|
|
|
|
|
|
__ LoadRoot(r6, Heap::kNonStrictArgumentsElementsMapRootIndex);
|
|
|
|
__ str(r6, FieldMemOperand(r4, FixedArray::kMapOffset));
|
|
|
|
__ add(r6, r1, Operand(Smi::FromInt(2)));
|
|
|
|
__ str(r6, FieldMemOperand(r4, FixedArray::kLengthOffset));
|
|
|
|
__ str(r8, FieldMemOperand(r4, FixedArray::kHeaderSize + 0 * kPointerSize));
|
|
|
|
__ add(r6, r4, Operand(r1, LSL, 1));
|
|
|
|
__ add(r6, r6, Operand(kParameterMapHeaderSize));
|
|
|
|
__ str(r6, FieldMemOperand(r4, FixedArray::kHeaderSize + 1 * kPointerSize));
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
__ mov(r6, r1);
|
|
|
|
__ ldr(r9, MemOperand(sp, 0 * kPointerSize));
|
|
|
|
__ add(r9, r9, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
|
|
|
|
__ sub(r9, r9, Operand(r1));
|
|
|
|
__ LoadRoot(r7, Heap::kTheHoleValueRootIndex);
|
|
|
|
__ add(r3, r4, Operand(r6, LSL, 1));
|
|
|
|
__ add(r3, r3, Operand(kParameterMapHeaderSize));
|
|
|
|
|
|
|
|
// r6 = loop variable (tagged)
|
|
|
|
// r1 = mapping index (tagged)
|
|
|
|
// r3 = address of backing store (tagged)
|
|
|
|
// r4 = address of parameter map (tagged)
|
|
|
|
// r5 = temporary scratch (a.o., for address calculation)
|
|
|
|
// r7 = the hole value
|
|
|
|
__ jmp(¶meters_test);
|
|
|
|
|
|
|
|
__ bind(¶meters_loop);
|
|
|
|
__ sub(r6, r6, Operand(Smi::FromInt(1)));
|
|
|
|
__ mov(r5, Operand(r6, LSL, 1));
|
|
|
|
__ add(r5, r5, Operand(kParameterMapHeaderSize - kHeapObjectTag));
|
|
|
|
__ str(r9, MemOperand(r4, r5));
|
|
|
|
__ sub(r5, r5, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize));
|
|
|
|
__ str(r7, MemOperand(r3, r5));
|
|
|
|
__ add(r9, r9, Operand(Smi::FromInt(1)));
|
|
|
|
__ bind(¶meters_test);
|
|
|
|
__ cmp(r6, Operand(Smi::FromInt(0)));
|
|
|
|
__ b(ne, ¶meters_loop);
|
|
|
|
|
|
|
|
__ bind(&skip_parameter_map);
|
|
|
|
// r2 = argument count (tagged)
|
|
|
|
// r3 = address of backing store (tagged)
|
|
|
|
// r5 = scratch
|
|
|
|
// Copy arguments header and remaining slots (if there are any).
|
|
|
|
__ LoadRoot(r5, Heap::kFixedArrayMapRootIndex);
|
|
|
|
__ str(r5, FieldMemOperand(r3, FixedArray::kMapOffset));
|
|
|
|
__ str(r2, FieldMemOperand(r3, FixedArray::kLengthOffset));
|
|
|
|
|
|
|
|
Label arguments_loop, arguments_test;
|
|
|
|
__ mov(r9, r1);
|
|
|
|
__ ldr(r4, MemOperand(sp, 1 * kPointerSize));
|
|
|
|
__ sub(r4, r4, Operand(r9, LSL, 1));
|
|
|
|
__ jmp(&arguments_test);
|
|
|
|
|
|
|
|
__ bind(&arguments_loop);
|
|
|
|
__ sub(r4, r4, Operand(kPointerSize));
|
|
|
|
__ ldr(r6, MemOperand(r4, 0));
|
|
|
|
__ add(r5, r3, Operand(r9, LSL, 1));
|
|
|
|
__ str(r6, FieldMemOperand(r5, FixedArray::kHeaderSize));
|
|
|
|
__ add(r9, r9, Operand(Smi::FromInt(1)));
|
|
|
|
|
|
|
|
__ bind(&arguments_test);
|
|
|
|
__ cmp(r9, Operand(r2));
|
|
|
|
__ b(lt, &arguments_loop);
|
|
|
|
|
|
|
|
// Return and remove the on-stack parameters.
|
|
|
|
__ add(sp, sp, Operand(3 * kPointerSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Do the runtime call to allocate the arguments object.
|
2012-01-16 09:46:21 +00:00
|
|
|
// r2 = argument count (tagged)
|
2011-06-16 14:12:58 +00:00
|
|
|
__ bind(&runtime);
|
|
|
|
__ str(r2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count.
|
|
|
|
__ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
|
|
|
|
// sp[0] : number of parameters
|
|
|
|
// sp[4] : receiver displacement
|
|
|
|
// sp[8] : function
|
2010-08-25 09:44:44 +00:00
|
|
|
// Check if the calling frame is an arguments adaptor frame.
|
|
|
|
Label adaptor_frame, try_allocate, runtime;
|
|
|
|
__ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
|
|
|
|
__ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
|
|
|
|
__ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
|
|
|
|
__ b(eq, &adaptor_frame);
|
|
|
|
|
|
|
|
// Get the length from the frame.
|
|
|
|
__ ldr(r1, MemOperand(sp, 0));
|
|
|
|
__ b(&try_allocate);
|
|
|
|
|
|
|
|
// Patch the arguments.length and the parameters pointer.
|
|
|
|
__ bind(&adaptor_frame);
|
|
|
|
__ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
|
|
|
|
__ str(r1, MemOperand(sp, 0));
|
|
|
|
__ add(r3, r2, Operand(r1, LSL, kPointerSizeLog2 - kSmiTagSize));
|
|
|
|
__ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset));
|
|
|
|
__ str(r3, 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);
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(r1, Operand::Zero());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, &add_arguments_object);
|
|
|
|
__ mov(r1, Operand(r1, LSR, kSmiTagSize));
|
|
|
|
__ add(r1, r1, Operand(FixedArray::kHeaderSize / kPointerSize));
|
|
|
|
__ bind(&add_arguments_object);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ add(r1, r1, Operand(Heap::kArgumentsObjectSizeStrict / kPointerSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Do the allocation of both objects in one go.
|
2013-03-25 15:54:15 +00:00
|
|
|
__ Allocate(r1, r0, r2, r3, &runtime,
|
|
|
|
static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-08-17 12:59:00 +00:00
|
|
|
// Get the arguments boilerplate from the current native context.
|
|
|
|
__ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
|
2012-08-17 09:03:08 +00:00
|
|
|
__ ldr(r4, FieldMemOperand(r4, GlobalObject::kNativeContextOffset));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ ldr(r4, MemOperand(r4, Context::SlotOffset(
|
|
|
|
Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX)));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Copy the JS object part.
|
2013-04-12 14:46:43 +00:00
|
|
|
__ CopyFields(r0, r4, d0, s0, JSObject::kHeaderSize / kPointerSize);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Get the length (smi tagged) and set that as an in-object property too.
|
2011-03-17 20:28:41 +00:00
|
|
|
STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ldr(r1, MemOperand(sp, 0 * kPointerSize));
|
2011-03-17 20:28:41 +00:00
|
|
|
__ str(r1, FieldMemOperand(r0, JSObject::kHeaderSize +
|
2011-06-16 14:12:58 +00:00
|
|
|
Heap::kArgumentsLengthIndex * kPointerSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// If there are no actual arguments, we're done.
|
|
|
|
Label done;
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(r1, Operand::Zero());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, &done);
|
|
|
|
|
|
|
|
// Get the parameters pointer from the stack.
|
|
|
|
__ ldr(r2, MemOperand(sp, 1 * kPointerSize));
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the elements pointer in the allocated arguments object and
|
2010-08-25 09:44:44 +00:00
|
|
|
// initialize the header in the elements fixed array.
|
2011-06-16 14:12:58 +00:00
|
|
|
__ add(r4, r0, Operand(Heap::kArgumentsObjectSizeStrict));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset));
|
|
|
|
__ LoadRoot(r3, Heap::kFixedArrayMapRootIndex);
|
|
|
|
__ str(r3, FieldMemOperand(r4, FixedArray::kMapOffset));
|
|
|
|
__ str(r1, FieldMemOperand(r4, FixedArray::kLengthOffset));
|
2011-06-16 14:12:58 +00:00
|
|
|
// Untag the length for the loop.
|
|
|
|
__ mov(r1, Operand(r1, LSR, kSmiTagSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Copy the fixed array slots.
|
|
|
|
Label loop;
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up r4 to point to the first array slot.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
|
|
|
|
__ bind(&loop);
|
|
|
|
// Pre-decrement r2 with kPointerSize on each iteration.
|
|
|
|
// Pre-decrement in order to skip receiver.
|
|
|
|
__ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex));
|
|
|
|
// Post-increment r4 with kPointerSize on each iteration.
|
|
|
|
__ str(r3, MemOperand(r4, kPointerSize, PostIndex));
|
|
|
|
__ sub(r1, r1, Operand(1));
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(r1, Operand::Zero());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(ne, &loop);
|
|
|
|
|
|
|
|
// Return and remove the on-stack parameters.
|
|
|
|
__ bind(&done);
|
|
|
|
__ add(sp, sp, Operand(3 * kPointerSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Do the runtime call to allocate the arguments object.
|
|
|
|
__ bind(&runtime);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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::kRegExpExec, 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
|
|
|
|
|
2012-03-12 13:56:56 +00:00
|
|
|
const int kLastMatchInfoOffset = 0 * kPointerSize;
|
|
|
|
const int kPreviousIndexOffset = 1 * kPointerSize;
|
|
|
|
const int kSubjectOffset = 2 * kPointerSize;
|
|
|
|
const int kJSRegExpOffset = 3 * kPointerSize;
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-02-26 09:53:07 +00:00
|
|
|
Label runtime;
|
2010-08-25 09:44:44 +00:00
|
|
|
// 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 = r4;
|
|
|
|
Register regexp_data = r5;
|
|
|
|
Register last_match_info_elements = r6;
|
|
|
|
|
|
|
|
// Ensure that a RegExp stack is allocated.
|
2011-03-22 13:20:04 +00:00
|
|
|
Isolate* isolate = masm->isolate();
|
2010-08-25 09:44:44 +00:00
|
|
|
ExternalReference address_of_regexp_stack_memory_address =
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference::address_of_regexp_stack_memory_address(isolate);
|
2010-08-25 09:44:44 +00:00
|
|
|
ExternalReference address_of_regexp_stack_memory_size =
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference::address_of_regexp_stack_memory_size(isolate);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(r0, Operand(address_of_regexp_stack_memory_size));
|
|
|
|
__ ldr(r0, MemOperand(r0, 0));
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(r0, Operand::Zero());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, &runtime);
|
|
|
|
|
|
|
|
// Check that the first argument is a JSRegExp object.
|
|
|
|
__ ldr(r0, MemOperand(sp, kJSRegExpOffset));
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(r0, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE);
|
|
|
|
__ b(ne, &runtime);
|
|
|
|
|
|
|
|
// Check that the RegExp has been compiled (data contains a fixed array).
|
|
|
|
__ ldr(regexp_data, FieldMemOperand(r0, JSRegExp::kDataOffset));
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ tst(regexp_data, Operand(kSmiTagMask));
|
2011-01-26 08:32:54 +00:00
|
|
|
__ Check(ne, "Unexpected type for RegExp data, FixedArray expected");
|
2010-08-25 09:44:44 +00:00
|
|
|
__ CompareObjectType(regexp_data, r0, r0, FIXED_ARRAY_TYPE);
|
|
|
|
__ Check(eq, "Unexpected type for RegExp data, FixedArray expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
// regexp_data: RegExp data (FixedArray)
|
|
|
|
// Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
|
|
|
|
__ ldr(r0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset));
|
|
|
|
__ cmp(r0, Operand(Smi::FromInt(JSRegExp::IRREGEXP)));
|
|
|
|
__ b(ne, &runtime);
|
|
|
|
|
|
|
|
// regexp_data: RegExp data (FixedArray)
|
|
|
|
// Check that the number of captures fit in the static offsets vector buffer.
|
|
|
|
__ ldr(r2,
|
|
|
|
FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
|
2013-02-26 09:53:07 +00:00
|
|
|
// Check (number_of_captures + 1) * 2 <= offsets vector size
|
|
|
|
// Or number_of_captures * 2 <= offsets vector size - 2
|
|
|
|
// Multiplying by 2 comes for free since r2 is smi-tagged.
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
|
2013-02-26 09:53:07 +00:00
|
|
|
STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
|
|
|
|
__ cmp(r2, Operand(Isolate::kJSRegexpStaticOffsetsVectorSize - 2));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(hi, &runtime);
|
|
|
|
|
2011-08-26 13:03:30 +00:00
|
|
|
// Reset offset for possibly sliced string.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ mov(r9, Operand::Zero());
|
2013-02-26 09:53:07 +00:00
|
|
|
__ ldr(subject, MemOperand(sp, kSubjectOffset));
|
|
|
|
__ JumpIfSmi(subject, &runtime);
|
|
|
|
__ mov(r3, subject); // Make a copy of the original subject string.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
|
2013-02-26 09:53:07 +00:00
|
|
|
// subject: subject string
|
|
|
|
// r3: subject string
|
|
|
|
// r0: 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).
|
2011-11-25 14:04:47 +00:00
|
|
|
__ and_(r1,
|
|
|
|
r0,
|
|
|
|
Operand(kIsNotStringMask |
|
|
|
|
kStringRepresentationMask |
|
|
|
|
kShortExternalStringMask),
|
|
|
|
SetCC);
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
|
2013-02-26 09:53:07 +00:00
|
|
|
__ b(eq, &seq_string); // Go to (5).
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-02-26 09:53:07 +00:00
|
|
|
// (2) Anything but sequential or cons? If yes, go to (6).
|
2011-08-29 11:41:23 +00:00
|
|
|
STATIC_ASSERT(kConsStringTag < kExternalStringTag);
|
|
|
|
STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
|
2011-11-24 18:36:24 +00:00
|
|
|
STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
|
2011-11-25 14:04:47 +00:00
|
|
|
STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
|
2011-08-26 13:03:30 +00:00
|
|
|
__ cmp(r1, Operand(kExternalStringTag));
|
2013-02-26 09:53:07 +00:00
|
|
|
__ b(ge, ¬_seq_nor_cons); // Go to (6).
|
2011-11-24 18:36:24 +00:00
|
|
|
|
2013-02-26 09:53:07 +00:00
|
|
|
// (3) Cons string. Check that it's flat.
|
|
|
|
// Replace subject with first string and reload instance type.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ldr(r0, FieldMemOperand(subject, ConsString::kSecondOffset));
|
2013-02-28 17:03:34 +00:00
|
|
|
__ CompareRoot(r0, Heap::kempty_stringRootIndex);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(ne, &runtime);
|
|
|
|
__ ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
|
2013-02-26 09:53:07 +00:00
|
|
|
|
|
|
|
// (4) Is subject external? If yes, go to (7).
|
|
|
|
__ bind(&check_underlying);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset));
|
|
|
|
STATIC_ASSERT(kSeqStringTag == 0);
|
|
|
|
__ tst(r0, Operand(kStringRepresentationMask));
|
2013-02-26 09:53:07 +00:00
|
|
|
// The underlying external string is never a short external string.
|
|
|
|
STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength);
|
|
|
|
STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength);
|
|
|
|
__ b(ne, &external_string); // Go to (7).
|
2011-11-25 14:04:47 +00:00
|
|
|
|
2013-02-26 09:53:07 +00:00
|
|
|
// (5) Sequential string. Load regexp code according to encoding.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&seq_string);
|
2013-02-26 09:53:07 +00:00
|
|
|
// subject: sequential subject string (or look-alike, external string)
|
|
|
|
// r3: original subject string
|
|
|
|
// Load previous index and check range before r3 is overwritten. We have to
|
|
|
|
// use r3 instead of subject here because subject might have been only made
|
|
|
|
// to look like a sequential string when it actually is an external string.
|
|
|
|
__ ldr(r1, MemOperand(sp, kPreviousIndexOffset));
|
|
|
|
__ JumpIfNotSmi(r1, &runtime);
|
|
|
|
__ ldr(r3, FieldMemOperand(r3, String::kLengthOffset));
|
|
|
|
__ cmp(r3, Operand(r1));
|
|
|
|
__ b(ls, &runtime);
|
|
|
|
__ mov(r1, Operand(r1, ASR, kSmiTagSize));
|
|
|
|
|
2012-11-08 12:14:29 +00:00
|
|
|
STATIC_ASSERT(4 == kOneByteStringTag);
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT(kTwoByteStringTag == 0);
|
|
|
|
__ and_(r0, r0, Operand(kStringEncodingMask));
|
|
|
|
__ mov(r3, Operand(r0, ASR, 2), SetCC);
|
|
|
|
__ ldr(r7, FieldMemOperand(regexp_data, JSRegExp::kDataAsciiCodeOffset), ne);
|
|
|
|
__ ldr(r7, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset), eq);
|
|
|
|
|
2013-02-26 09:53:07 +00:00
|
|
|
// (E) Carry on. String handling is done.
|
|
|
|
// r7: irregexp code
|
2010-08-25 09:44:44 +00:00
|
|
|
// 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
|
2011-07-05 06:19:53 +00:00
|
|
|
// a smi (code flushing support).
|
|
|
|
__ JumpIfSmi(r7, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// r1: previous index
|
2011-03-15 10:03:57 +00:00
|
|
|
// r3: encoding of subject string (1 if ASCII, 0 if two_byte);
|
2010-08-25 09:44:44 +00:00
|
|
|
// r7: code
|
|
|
|
// subject: Subject string
|
|
|
|
// regexp_data: RegExp data (FixedArray)
|
|
|
|
// All checks done. Now push arguments for native regexp code.
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(isolate->counters()->regexp_entry_native(), 1, r0, r2);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
// Isolates: note we add an additional parameter here (isolate pointer).
|
2012-05-22 14:05:44 +00:00
|
|
|
const int kRegExpExecuteArguments = 9;
|
2012-03-12 13:56:56 +00:00
|
|
|
const int kParameterRegisters = 4;
|
2011-02-15 13:53:51 +00:00
|
|
|
__ 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.
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-05-22 14:05:44 +00:00
|
|
|
// Argument 9 (sp[20]): Pass current isolate address.
|
2013-04-24 07:39:35 +00:00
|
|
|
__ mov(r0, Operand(ExternalReference::isolate_address(isolate)));
|
2012-05-22 14:05:44 +00:00
|
|
|
__ str(r0, MemOperand(sp, 5 * kPointerSize));
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2012-05-22 14:05:44 +00:00
|
|
|
// Argument 8 (sp[16]): Indicate that this is a direct call from JavaScript.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(r0, Operand(1));
|
2012-05-22 14:05:44 +00:00
|
|
|
__ str(r0, MemOperand(sp, 4 * kPointerSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-05-22 14:05:44 +00:00
|
|
|
// Argument 7 (sp[12]): Start (high end) of backtracking stack memory area.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(r0, Operand(address_of_regexp_stack_memory_address));
|
|
|
|
__ ldr(r0, MemOperand(r0, 0));
|
|
|
|
__ mov(r2, Operand(address_of_regexp_stack_memory_size));
|
|
|
|
__ ldr(r2, MemOperand(r2, 0));
|
|
|
|
__ add(r0, r0, Operand(r2));
|
2012-05-22 14:05:44 +00:00
|
|
|
__ str(r0, MemOperand(sp, 3 * kPointerSize));
|
|
|
|
|
|
|
|
// Argument 6: Set the number of capture registers to zero to force global
|
|
|
|
// regexps to behave as non-global. This does not affect non-global regexps.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ mov(r0, Operand::Zero());
|
2011-02-15 13:53:51 +00:00
|
|
|
__ str(r0, MemOperand(sp, 2 * kPointerSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-02-15 13:53:51 +00:00
|
|
|
// Argument 5 (sp[4]): static offsets vector buffer.
|
2011-03-22 13:20:04 +00:00
|
|
|
__ mov(r0,
|
|
|
|
Operand(ExternalReference::address_of_static_offsets_vector(isolate)));
|
2011-02-15 13:53:51 +00:00
|
|
|
__ str(r0, MemOperand(sp, 1 * kPointerSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// For arguments 4 and 3 get string length, calculate start of string data and
|
|
|
|
// calculate the shift of the index (0 for ASCII and 1 for two byte).
|
2011-09-20 16:33:03 +00:00
|
|
|
__ add(r8, subject, Operand(SeqString::kHeaderSize - kHeapObjectTag));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ eor(r3, r3, Operand(1));
|
2011-08-26 13:03:30 +00:00
|
|
|
// 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.)
|
2011-09-02 13:42:50 +00:00
|
|
|
__ ldr(subject, MemOperand(fp, kSubjectOffset + 2 * kPointerSize));
|
2011-08-26 13:03:30 +00:00
|
|
|
// If slice offset is not 0, load the length from the original sliced string.
|
|
|
|
// Argument 4, r3: End of string data
|
|
|
|
// Argument 3, r2: Start of string data
|
|
|
|
// Prepare start and end index of the input.
|
|
|
|
__ add(r9, r8, Operand(r9, LSL, r3));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ add(r2, r9, Operand(r1, LSL, r3));
|
2011-08-26 13:03:30 +00:00
|
|
|
|
2011-09-02 13:42:50 +00:00
|
|
|
__ ldr(r8, FieldMemOperand(subject, String::kLengthOffset));
|
2011-08-26 13:03:30 +00:00
|
|
|
__ mov(r8, Operand(r8, ASR, kSmiTagSize));
|
|
|
|
__ add(r3, r9, Operand(r8, LSL, r3));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Argument 2 (r1): Previous index.
|
|
|
|
// Already there
|
|
|
|
|
|
|
|
// Argument 1 (r0): Subject string.
|
2011-09-02 13:42:50 +00:00
|
|
|
__ mov(r0, subject);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Locate the code entry and call it.
|
|
|
|
__ add(r7, r7, Operand(Code::kHeaderSize - kHeapObjectTag));
|
2011-02-15 13:53:51 +00:00
|
|
|
DirectCEntryStub stub;
|
|
|
|
stub.GenerateCall(masm, r7);
|
|
|
|
|
|
|
|
__ LeaveExitFrame(false, no_reg);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// r0: 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;
|
2012-05-22 14:05:44 +00:00
|
|
|
__ cmp(r0, Operand(1));
|
|
|
|
// We expect exactly one result since we force the called regexp to behave
|
|
|
|
// as non-global.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, &success);
|
|
|
|
Label failure;
|
2011-09-02 13:42:50 +00:00
|
|
|
__ cmp(r0, Operand(NativeRegExpMacroAssembler::FAILURE));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, &failure);
|
2011-09-02 13:42:50 +00:00
|
|
|
__ cmp(r0, Operand(NativeRegExpMacroAssembler::EXCEPTION));
|
2010-08-25 09:44:44 +00:00
|
|
|
// If not exception it can only be retry. Handle that in the runtime system.
|
|
|
|
__ b(ne, &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.
|
2011-10-04 09:07:50 +00:00
|
|
|
__ mov(r1, Operand(isolate->factory()->the_hole_value()));
|
2011-09-08 16:29:57 +00:00
|
|
|
__ mov(r2, Operand(ExternalReference(Isolate::kPendingExceptionAddress,
|
2011-03-22 13:20:04 +00:00
|
|
|
isolate)));
|
2011-02-15 13:53:51 +00:00
|
|
|
__ ldr(r0, MemOperand(r2, 0));
|
2011-09-02 13:42:50 +00:00
|
|
|
__ cmp(r0, r1);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, &runtime);
|
2011-02-15 13:53:51 +00:00
|
|
|
|
|
|
|
__ str(r1, MemOperand(r2, 0)); // Clear pending exception.
|
|
|
|
|
|
|
|
// Check if the exception is a termination. If so, throw as uncatchable.
|
2011-09-02 13:42:50 +00:00
|
|
|
__ CompareRoot(r0, Heap::kTerminationExceptionRootIndex);
|
|
|
|
|
2011-02-15 13:53:51 +00:00
|
|
|
Label termination_exception;
|
|
|
|
__ b(eq, &termination_exception);
|
|
|
|
|
2012-02-10 08:47:35 +00:00
|
|
|
__ Throw(r0);
|
2011-02-15 13:53:51 +00:00
|
|
|
|
|
|
|
__ bind(&termination_exception);
|
2012-02-10 08:47:35 +00:00
|
|
|
__ ThrowUncatchable(r0);
|
2011-02-15 13:53:51 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&failure);
|
|
|
|
// For failure and exception return null.
|
2011-04-14 08:01:19 +00:00
|
|
|
__ mov(r0, Operand(masm->isolate()->factory()->null_value()));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ add(sp, sp, Operand(4 * kPointerSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Process the result from the native regexp code.
|
|
|
|
__ bind(&success);
|
|
|
|
__ ldr(r1,
|
|
|
|
FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset));
|
|
|
|
// Calculate number of capture registers (number_of_captures + 1) * 2.
|
2013-02-26 09:53:07 +00:00
|
|
|
// Multiplying by 2 comes for free since r1 is smi-tagged.
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
|
|
|
|
__ add(r1, r1, Operand(2)); // r1 was a smi.
|
|
|
|
|
2013-02-26 09:53:07 +00:00
|
|
|
__ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
|
|
|
|
__ JumpIfSmi(r0, &runtime);
|
|
|
|
__ CompareObjectType(r0, r2, r2, JS_ARRAY_TYPE);
|
|
|
|
__ b(ne, &runtime);
|
|
|
|
// Check that the JSArray is in fast case.
|
|
|
|
__ ldr(last_match_info_elements,
|
|
|
|
FieldMemOperand(r0, JSArray::kElementsOffset));
|
|
|
|
__ ldr(r0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset));
|
|
|
|
__ CompareRoot(r0, Heap::kFixedArrayMapRootIndex);
|
|
|
|
__ b(ne, &runtime);
|
|
|
|
// Check that the last match info has space for the capture registers and the
|
|
|
|
// additional information.
|
|
|
|
__ ldr(r0,
|
|
|
|
FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset));
|
|
|
|
__ add(r2, r1, Operand(RegExpImpl::kLastMatchOverhead));
|
|
|
|
__ cmp(r2, Operand(r0, ASR, kSmiTagSize));
|
|
|
|
__ b(gt, &runtime);
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// r1: number of capture registers
|
|
|
|
// r4: subject string
|
|
|
|
// Store the capture count.
|
|
|
|
__ mov(r2, Operand(r1, LSL, kSmiTagSize + kSmiShiftSize)); // To smi.
|
|
|
|
__ str(r2, FieldMemOperand(last_match_info_elements,
|
|
|
|
RegExpImpl::kLastCaptureCountOffset));
|
|
|
|
// Store last subject and last input.
|
|
|
|
__ str(subject,
|
|
|
|
FieldMemOperand(last_match_info_elements,
|
|
|
|
RegExpImpl::kLastSubjectOffset));
|
2011-09-19 18:36:47 +00:00
|
|
|
__ mov(r2, subject);
|
|
|
|
__ RecordWriteField(last_match_info_elements,
|
|
|
|
RegExpImpl::kLastSubjectOffset,
|
2013-02-26 09:53:07 +00:00
|
|
|
subject,
|
2011-09-19 18:36:47 +00:00
|
|
|
r7,
|
|
|
|
kLRHasNotBeenSaved,
|
|
|
|
kDontSaveFPRegs);
|
2013-02-26 09:53:07 +00:00
|
|
|
__ mov(subject, r2);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ str(subject,
|
|
|
|
FieldMemOperand(last_match_info_elements,
|
|
|
|
RegExpImpl::kLastInputOffset));
|
2011-09-19 18:36:47 +00:00
|
|
|
__ RecordWriteField(last_match_info_elements,
|
|
|
|
RegExpImpl::kLastInputOffset,
|
|
|
|
subject,
|
|
|
|
r7,
|
|
|
|
kLRHasNotBeenSaved,
|
|
|
|
kDontSaveFPRegs);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Get the static offsets vector filled by the native regexp code.
|
|
|
|
ExternalReference address_of_static_offsets_vector =
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference::address_of_static_offsets_vector(isolate);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(r2, Operand(address_of_static_offsets_vector));
|
|
|
|
|
|
|
|
// r1: number of capture registers
|
|
|
|
// r2: offsets vector
|
|
|
|
Label next_capture, done;
|
|
|
|
// Capture register counter starts from number of capture registers and
|
|
|
|
// counts down until wraping after zero.
|
|
|
|
__ add(r0,
|
|
|
|
last_match_info_elements,
|
|
|
|
Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag));
|
|
|
|
__ bind(&next_capture);
|
|
|
|
__ sub(r1, r1, Operand(1), SetCC);
|
|
|
|
__ b(mi, &done);
|
|
|
|
// Read the value from the static offsets vector buffer.
|
|
|
|
__ ldr(r3, MemOperand(r2, kPointerSize, PostIndex));
|
|
|
|
// Store the smi value in the last match info.
|
|
|
|
__ mov(r3, Operand(r3, LSL, kSmiTagSize));
|
|
|
|
__ str(r3, MemOperand(r0, kPointerSize, PostIndex));
|
|
|
|
__ jmp(&next_capture);
|
|
|
|
__ bind(&done);
|
|
|
|
|
|
|
|
// Return last match info.
|
|
|
|
__ ldr(r0, MemOperand(sp, kLastMatchInfoOffset));
|
|
|
|
__ add(sp, sp, Operand(4 * kPointerSize));
|
|
|
|
__ Ret();
|
|
|
|
|
2013-02-26 09:53:07 +00:00
|
|
|
// Do the runtime call to execute the regexp.
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
|
|
|
|
|
|
|
|
// Deferred code for string handling.
|
|
|
|
// (6) Not a long external string? If yes, go to (8).
|
|
|
|
__ bind(¬_seq_nor_cons);
|
|
|
|
// Compare flags are still set.
|
|
|
|
__ b(gt, ¬_long_external); // Go to (8).
|
|
|
|
|
|
|
|
// (7) External string. Make it, offset-wise, look like a sequential string.
|
2011-11-25 14:04:47 +00:00
|
|
|
__ bind(&external_string);
|
|
|
|
__ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(r0, FieldMemOperand(r0, 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.
|
|
|
|
__ tst(r0, Operand(kIsIndirectStringMask));
|
|
|
|
__ Assert(eq, "external string expected, but not found");
|
|
|
|
}
|
|
|
|
__ ldr(subject,
|
|
|
|
FieldMemOperand(subject, ExternalString::kResourceDataOffset));
|
|
|
|
// Move the pointer so that offset-wise, it looks like a sequential string.
|
2012-11-15 13:31:27 +00:00
|
|
|
STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
|
2011-11-25 14:04:47 +00:00
|
|
|
__ sub(subject,
|
|
|
|
subject,
|
|
|
|
Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
|
2013-02-26 09:53:07 +00:00
|
|
|
__ jmp(&seq_string); // Go to (5).
|
2011-11-25 14:04:47 +00:00
|
|
|
|
2013-02-26 09:53:07 +00:00
|
|
|
// (8) Short external string or not a string? If yes, bail out to runtime.
|
|
|
|
__ bind(¬_long_external);
|
|
|
|
STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
|
|
|
|
__ tst(r1, Operand(kIsNotStringMask | kShortExternalStringMask));
|
|
|
|
__ b(ne, &runtime);
|
|
|
|
|
|
|
|
// (9) Sliced string. Replace subject with parent. Go to (4).
|
|
|
|
// Load offset into r9 and replace subject string with parent.
|
|
|
|
__ ldr(r9, FieldMemOperand(subject, SlicedString::kOffsetOffset));
|
|
|
|
__ mov(r9, Operand(r9, ASR, kSmiTagSize));
|
|
|
|
__ ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
|
|
|
|
__ jmp(&check_underlying); // Go to (4).
|
2010-08-25 09:44:44 +00:00
|
|
|
#endif // V8_INTERPRETED_REGEXP
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void RegExpConstructResultStub::Generate(MacroAssembler* masm) {
|
|
|
|
const int kMaxInlineLength = 100;
|
|
|
|
Label slowcase;
|
|
|
|
Label done;
|
2011-04-14 08:01:19 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
__ ldr(r1, MemOperand(sp, kPointerSize * 2));
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(r1, &slowcase);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ cmp(r1, Operand(Smi::FromInt(kMaxInlineLength)));
|
|
|
|
__ b(hi, &slowcase);
|
|
|
|
// Smi-tagging is equivalent to multiplying by 2.
|
|
|
|
// Allocate RegExpResult followed by FixedArray with size in ebx.
|
|
|
|
// JSArray: [Map][empty properties][Elements][Length-smi][index][input]
|
|
|
|
// Elements: [Map][Length][..elements..]
|
|
|
|
// Size of JSArray with two in-object properties and the header of a
|
|
|
|
// FixedArray.
|
|
|
|
int objects_size =
|
|
|
|
(JSRegExpResult::kSize + FixedArray::kHeaderSize) / kPointerSize;
|
|
|
|
__ mov(r5, Operand(r1, LSR, kSmiTagSize + kSmiShiftSize));
|
|
|
|
__ add(r2, r5, Operand(objects_size));
|
2013-03-25 15:54:15 +00:00
|
|
|
__ Allocate(
|
2010-12-07 11:31:57 +00:00
|
|
|
r2, // In: Size, in words.
|
|
|
|
r0, // Out: Start of allocation (tagged).
|
|
|
|
r3, // Scratch register.
|
|
|
|
r4, // Scratch register.
|
|
|
|
&slowcase,
|
|
|
|
static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
|
|
|
|
// r0: Start of allocated area, object-tagged.
|
|
|
|
// r1: Number of elements in array, as smi.
|
|
|
|
// r5: Number of elements, untagged.
|
|
|
|
|
|
|
|
// Set JSArray map to global.regexp_result_map().
|
|
|
|
// Set empty properties FixedArray.
|
|
|
|
// Set elements to point to FixedArray allocated right after the JSArray.
|
|
|
|
// Interleave operations for better latency.
|
2012-08-17 12:59:00 +00:00
|
|
|
__ ldr(r2, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX));
|
2010-12-07 11:31:57 +00:00
|
|
|
__ add(r3, r0, Operand(JSRegExpResult::kSize));
|
2011-04-14 08:01:19 +00:00
|
|
|
__ mov(r4, Operand(factory->empty_fixed_array()));
|
2012-08-17 09:03:08 +00:00
|
|
|
__ ldr(r2, FieldMemOperand(r2, GlobalObject::kNativeContextOffset));
|
2010-12-07 11:31:57 +00:00
|
|
|
__ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
|
|
|
|
__ ldr(r2, ContextOperand(r2, Context::REGEXP_RESULT_MAP_INDEX));
|
|
|
|
__ str(r4, FieldMemOperand(r0, JSObject::kPropertiesOffset));
|
|
|
|
__ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
|
|
|
|
|
|
|
|
// Set input, index and length fields from arguments.
|
|
|
|
__ ldr(r1, MemOperand(sp, kPointerSize * 0));
|
2012-01-27 16:54:22 +00:00
|
|
|
__ ldr(r2, MemOperand(sp, kPointerSize * 1));
|
|
|
|
__ ldr(r6, MemOperand(sp, kPointerSize * 2));
|
2010-12-07 11:31:57 +00:00
|
|
|
__ str(r1, FieldMemOperand(r0, JSRegExpResult::kInputOffset));
|
2012-01-27 16:54:22 +00:00
|
|
|
__ str(r2, FieldMemOperand(r0, JSRegExpResult::kIndexOffset));
|
|
|
|
__ str(r6, FieldMemOperand(r0, JSArray::kLengthOffset));
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Fill out the elements FixedArray.
|
|
|
|
// r0: JSArray, tagged.
|
|
|
|
// r3: FixedArray, tagged.
|
|
|
|
// r5: Number of elements in array, untagged.
|
|
|
|
|
|
|
|
// Set map.
|
2011-04-14 08:01:19 +00:00
|
|
|
__ mov(r2, Operand(factory->fixed_array_map()));
|
2010-12-07 11:31:57 +00:00
|
|
|
__ str(r2, FieldMemOperand(r3, HeapObject::kMapOffset));
|
|
|
|
// Set FixedArray length.
|
|
|
|
__ mov(r6, Operand(r5, LSL, kSmiTagSize));
|
|
|
|
__ str(r6, FieldMemOperand(r3, FixedArray::kLengthOffset));
|
2012-09-14 12:01:12 +00:00
|
|
|
// Fill contents of fixed-array with undefined.
|
|
|
|
__ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
|
2012-09-14 12:01:12 +00:00
|
|
|
// Fill fixed array elements with undefined.
|
2010-12-07 11:31:57 +00:00
|
|
|
// r0: JSArray, tagged.
|
2012-09-14 12:01:12 +00:00
|
|
|
// r2: undefined.
|
2010-12-07 11:31:57 +00:00
|
|
|
// r3: Start of elements in FixedArray.
|
|
|
|
// r5: Number of elements to fill.
|
|
|
|
Label loop;
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(r5, Operand::Zero());
|
2010-12-07 11:31:57 +00:00
|
|
|
__ bind(&loop);
|
2012-01-26 16:05:28 +00:00
|
|
|
__ b(le, &done); // Jump if r5 is negative or zero.
|
2010-12-07 11:31:57 +00:00
|
|
|
__ sub(r5, r5, Operand(1), SetCC);
|
|
|
|
__ str(r2, MemOperand(r3, r5, LSL, kPointerSizeLog2));
|
|
|
|
__ jmp(&loop);
|
|
|
|
|
|
|
|
__ bind(&done);
|
|
|
|
__ add(sp, sp, Operand(3 * kPointerSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&slowcase);
|
|
|
|
__ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-01 16:06:34 +00:00
|
|
|
static void GenerateRecordCallTargetNoArray(MacroAssembler* masm) {
|
2012-01-27 13:03:19 +00:00
|
|
|
// Cache the called function in a global property cell. Cache states
|
|
|
|
// are uninitialized, monomorphic (indicated by a JSFunction), and
|
|
|
|
// megamorphic.
|
|
|
|
// r1 : the function to call
|
|
|
|
// r2 : cache cell for call target
|
2013-03-01 16:06:34 +00:00
|
|
|
ASSERT(!FLAG_optimize_constructed_arrays);
|
2012-01-27 13:03:19 +00:00
|
|
|
Label done;
|
2011-09-27 11:42:02 +00:00
|
|
|
|
2012-01-27 13:20:01 +00:00
|
|
|
ASSERT_EQ(*TypeFeedbackCells::MegamorphicSentinel(masm->isolate()),
|
|
|
|
masm->isolate()->heap()->undefined_value());
|
|
|
|
ASSERT_EQ(*TypeFeedbackCells::UninitializedSentinel(masm->isolate()),
|
|
|
|
masm->isolate()->heap()->the_hole_value());
|
2011-09-27 11:42:02 +00:00
|
|
|
|
2012-01-27 13:03:19 +00:00
|
|
|
// Load the cache state into r3.
|
|
|
|
__ ldr(r3, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset));
|
2011-09-27 11:42:02 +00:00
|
|
|
|
2012-01-27 13:03:19 +00:00
|
|
|
// A monomorphic cache hit or an already megamorphic state: invoke the
|
|
|
|
// function without changing the state.
|
|
|
|
__ cmp(r3, r1);
|
|
|
|
__ b(eq, &done);
|
|
|
|
__ CompareRoot(r3, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ b(eq, &done);
|
|
|
|
|
|
|
|
// A monomorphic miss (i.e, here the cache is not uninitialized) goes
|
|
|
|
// megamorphic.
|
|
|
|
__ CompareRoot(r3, Heap::kTheHoleValueRootIndex);
|
|
|
|
// MegamorphicSentinel is an immortal immovable object (undefined) so no
|
|
|
|
// write-barrier is needed.
|
|
|
|
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex, ne);
|
|
|
|
__ str(ip, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset), ne);
|
|
|
|
|
|
|
|
// An uninitialized cache is patched with the function.
|
|
|
|
__ str(r1, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset), eq);
|
|
|
|
// No need for a write barrier here - cells are rescanned.
|
2011-09-27 11:42:02 +00:00
|
|
|
|
2012-01-27 13:03:19 +00:00
|
|
|
__ bind(&done);
|
2011-09-27 11:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-01 16:06:34 +00:00
|
|
|
static void GenerateRecordCallTarget(MacroAssembler* masm) {
|
|
|
|
// Cache the called function in a global property cell. Cache states
|
|
|
|
// are uninitialized, monomorphic (indicated by a JSFunction), and
|
|
|
|
// megamorphic.
|
|
|
|
// r1 : the function to call
|
|
|
|
// r2 : cache cell for call target
|
|
|
|
ASSERT(FLAG_optimize_constructed_arrays);
|
|
|
|
Label initialize, done, miss, megamorphic, not_array_function;
|
|
|
|
|
|
|
|
ASSERT_EQ(*TypeFeedbackCells::MegamorphicSentinel(masm->isolate()),
|
|
|
|
masm->isolate()->heap()->undefined_value());
|
|
|
|
ASSERT_EQ(*TypeFeedbackCells::UninitializedSentinel(masm->isolate()),
|
|
|
|
masm->isolate()->heap()->the_hole_value());
|
|
|
|
|
|
|
|
// Load the cache state into r3.
|
|
|
|
__ ldr(r3, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset));
|
|
|
|
|
|
|
|
// A monomorphic cache hit or an already megamorphic state: invoke the
|
|
|
|
// function without changing the state.
|
|
|
|
__ cmp(r3, r1);
|
|
|
|
__ b(eq, &done);
|
|
|
|
__ CompareRoot(r3, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ b(eq, &done);
|
|
|
|
|
|
|
|
// Special handling of the Array() function, which caches not only the
|
|
|
|
// monomorphic Array function but the initial ElementsKind with special
|
|
|
|
// sentinels
|
|
|
|
Handle<Object> terminal_kind_sentinel =
|
|
|
|
TypeFeedbackCells::MonomorphicArraySentinel(masm->isolate(),
|
|
|
|
LAST_FAST_ELEMENTS_KIND);
|
|
|
|
__ cmp(r3, Operand(terminal_kind_sentinel));
|
2013-04-25 16:00:32 +00:00
|
|
|
__ b(gt, &miss);
|
2013-03-01 16:06:34 +00:00
|
|
|
// Make sure the function is the Array() function
|
|
|
|
__ LoadArrayFunction(r3);
|
|
|
|
__ cmp(r1, r3);
|
|
|
|
__ b(ne, &megamorphic);
|
|
|
|
__ jmp(&done);
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
|
|
|
|
// A monomorphic miss (i.e, here the cache is not uninitialized) goes
|
|
|
|
// megamorphic.
|
|
|
|
__ CompareRoot(r3, Heap::kTheHoleValueRootIndex);
|
|
|
|
__ b(eq, &initialize);
|
|
|
|
// MegamorphicSentinel is an immortal immovable object (undefined) so no
|
|
|
|
// write-barrier is needed.
|
|
|
|
__ bind(&megamorphic);
|
|
|
|
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ str(ip, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset));
|
|
|
|
|
|
|
|
// An uninitialized cache is patched with the function or sentinel to
|
|
|
|
// indicate the ElementsKind if function is the Array constructor.
|
|
|
|
__ bind(&initialize);
|
|
|
|
// Make sure the function is the Array() function
|
|
|
|
__ LoadArrayFunction(r3);
|
|
|
|
__ cmp(r1, r3);
|
|
|
|
__ b(ne, ¬_array_function);
|
|
|
|
|
|
|
|
// The target function is the Array constructor, install a sentinel value in
|
|
|
|
// the constructor's type info cell that will track the initial ElementsKind
|
|
|
|
// that should be used for the array when its constructed.
|
|
|
|
Handle<Object> initial_kind_sentinel =
|
|
|
|
TypeFeedbackCells::MonomorphicArraySentinel(masm->isolate(),
|
|
|
|
GetInitialFastElementsKind());
|
|
|
|
__ mov(r3, Operand(initial_kind_sentinel));
|
|
|
|
__ str(r3, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset));
|
|
|
|
__ b(&done);
|
|
|
|
|
|
|
|
__ bind(¬_array_function);
|
|
|
|
__ str(r1, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset));
|
|
|
|
// No need for a write barrier here - cells are rescanned.
|
|
|
|
|
|
|
|
__ bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void CallFunctionStub::Generate(MacroAssembler* masm) {
|
2011-11-08 14:39:37 +00:00
|
|
|
// r1 : the function to call
|
2012-01-27 13:03:19 +00:00
|
|
|
// r2 : cache cell for call target
|
2011-09-13 11:42:57 +00:00
|
|
|
Label slow, non_function;
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-05-24 14:01:36 +00:00
|
|
|
// The receiver might implicitly be the global object. This is
|
|
|
|
// indicated by passing the hole as the receiver to the call
|
|
|
|
// function stub.
|
|
|
|
if (ReceiverMightBeImplicit()) {
|
|
|
|
Label call;
|
2010-08-25 09:44:44 +00:00
|
|
|
// Get the receiver from the stack.
|
|
|
|
// function, receiver [, arguments]
|
2011-05-24 14:01:36 +00:00
|
|
|
__ ldr(r4, MemOperand(sp, argc_ * kPointerSize));
|
|
|
|
// Call as function is indicated with the hole.
|
|
|
|
__ CompareRoot(r4, Heap::kTheHoleValueRootIndex);
|
|
|
|
__ b(ne, &call);
|
|
|
|
// Patch the receiver on the stack with the global receiver object.
|
2012-08-17 12:59:00 +00:00
|
|
|
__ ldr(r3,
|
|
|
|
MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
|
2012-04-19 14:17:12 +00:00
|
|
|
__ ldr(r3, FieldMemOperand(r3, GlobalObject::kGlobalReceiverOffset));
|
|
|
|
__ str(r3, MemOperand(sp, argc_ * kPointerSize));
|
2011-05-24 14:01:36 +00:00
|
|
|
__ bind(&call);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the function is really a JavaScript function.
|
|
|
|
// r1: pushed function (to be verified)
|
2011-09-13 11:42:57 +00:00
|
|
|
__ JumpIfSmi(r1, &non_function);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Get the map of the function object.
|
2012-04-19 14:17:12 +00:00
|
|
|
__ CompareObjectType(r1, r3, r3, JS_FUNCTION_TYPE);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(ne, &slow);
|
|
|
|
|
2012-04-19 14:17:12 +00:00
|
|
|
if (RecordCallTarget()) {
|
2013-03-01 16:06:34 +00:00
|
|
|
if (FLAG_optimize_constructed_arrays) {
|
|
|
|
GenerateRecordCallTarget(masm);
|
|
|
|
} else {
|
|
|
|
GenerateRecordCallTargetNoArray(masm);
|
|
|
|
}
|
2012-04-19 14:17:12 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Fast-case: Invoke the function now.
|
|
|
|
// r1: pushed function
|
|
|
|
ParameterCount actual(argc_);
|
2011-05-24 14:01:36 +00:00
|
|
|
|
|
|
|
if (ReceiverMightBeImplicit()) {
|
|
|
|
Label call_as_function;
|
|
|
|
__ CompareRoot(r4, Heap::kTheHoleValueRootIndex);
|
|
|
|
__ b(eq, &call_as_function);
|
2011-05-30 13:23:17 +00:00
|
|
|
__ InvokeFunction(r1,
|
|
|
|
actual,
|
|
|
|
JUMP_FUNCTION,
|
|
|
|
NullCallWrapper(),
|
|
|
|
CALL_AS_METHOD);
|
2011-05-24 14:01:36 +00:00
|
|
|
__ bind(&call_as_function);
|
|
|
|
}
|
|
|
|
__ InvokeFunction(r1,
|
|
|
|
actual,
|
|
|
|
JUMP_FUNCTION,
|
|
|
|
NullCallWrapper(),
|
|
|
|
CALL_AS_FUNCTION);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Slow-case: Non-function called.
|
|
|
|
__ bind(&slow);
|
2012-04-19 14:17:12 +00:00
|
|
|
if (RecordCallTarget()) {
|
|
|
|
// If there is a call target cache, mark it megamorphic in the
|
|
|
|
// non-function case. MegamorphicSentinel is an immortal immovable
|
|
|
|
// object (undefined) so no write barrier is needed.
|
|
|
|
ASSERT_EQ(*TypeFeedbackCells::MegamorphicSentinel(masm->isolate()),
|
|
|
|
masm->isolate()->heap()->undefined_value());
|
|
|
|
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ str(ip, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset));
|
|
|
|
}
|
2011-09-13 11:42:57 +00:00
|
|
|
// Check for function proxy.
|
2012-04-19 14:17:12 +00:00
|
|
|
__ cmp(r3, Operand(JS_FUNCTION_PROXY_TYPE));
|
2011-09-13 11:42:57 +00:00
|
|
|
__ b(ne, &non_function);
|
|
|
|
__ push(r1); // put proxy as additional argument
|
2013-01-04 10:56:24 +00:00
|
|
|
__ mov(r0, Operand(argc_ + 1, RelocInfo::NONE32));
|
2013-01-07 09:43:12 +00:00
|
|
|
__ mov(r2, Operand::Zero());
|
2011-09-13 11:42:57 +00:00
|
|
|
__ GetBuiltinEntry(r3, Builtins::CALL_FUNCTION_PROXY);
|
2011-11-08 14:39:37 +00:00
|
|
|
__ SetCallKind(r5, CALL_AS_METHOD);
|
2011-09-13 11:42:57 +00:00
|
|
|
{
|
|
|
|
Handle<Code> adaptor =
|
|
|
|
masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
|
|
|
|
__ Jump(adaptor, RelocInfo::CODE_TARGET);
|
|
|
|
}
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// CALL_NON_FUNCTION expects the non-function callee as receiver (instead
|
|
|
|
// of the original receiver from the call site).
|
2011-09-13 11:42:57 +00:00
|
|
|
__ bind(&non_function);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ str(r1, MemOperand(sp, argc_ * kPointerSize));
|
2012-01-13 13:09:52 +00:00
|
|
|
__ mov(r0, Operand(argc_)); // Set up the number of arguments.
|
2013-01-07 09:43:12 +00:00
|
|
|
__ mov(r2, Operand::Zero());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION);
|
2011-07-19 08:19:31 +00:00
|
|
|
__ SetCallKind(r5, CALL_AS_METHOD);
|
2011-03-23 13:40:07 +00:00
|
|
|
__ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
|
2010-08-25 09:44:44 +00:00
|
|
|
RelocInfo::CODE_TARGET);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-27 13:03:19 +00:00
|
|
|
void CallConstructStub::Generate(MacroAssembler* masm) {
|
|
|
|
// r0 : number of arguments
|
|
|
|
// r1 : the function to call
|
|
|
|
// r2 : cache cell for call target
|
|
|
|
Label slow, non_function_call;
|
|
|
|
|
|
|
|
// Check that the function is not a smi.
|
|
|
|
__ JumpIfSmi(r1, &non_function_call);
|
|
|
|
// Check that the function is a JSFunction.
|
|
|
|
__ CompareObjectType(r1, r3, r3, JS_FUNCTION_TYPE);
|
|
|
|
__ b(ne, &slow);
|
|
|
|
|
|
|
|
if (RecordCallTarget()) {
|
2013-03-01 16:06:34 +00:00
|
|
|
if (FLAG_optimize_constructed_arrays) {
|
|
|
|
GenerateRecordCallTarget(masm);
|
|
|
|
} else {
|
|
|
|
GenerateRecordCallTargetNoArray(masm);
|
|
|
|
}
|
2012-01-27 13:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Jump to the function-specific construct stub.
|
2013-03-01 16:06:34 +00:00
|
|
|
Register jmp_reg = FLAG_optimize_constructed_arrays ? r3 : r2;
|
|
|
|
__ ldr(jmp_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
|
|
|
|
__ ldr(jmp_reg, FieldMemOperand(jmp_reg,
|
|
|
|
SharedFunctionInfo::kConstructStubOffset));
|
|
|
|
__ add(pc, jmp_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
|
2012-01-27 13:03:19 +00:00
|
|
|
|
|
|
|
// r0: number of arguments
|
|
|
|
// r1: called object
|
|
|
|
// r3: object type
|
|
|
|
Label do_call;
|
|
|
|
__ bind(&slow);
|
|
|
|
__ cmp(r3, Operand(JS_FUNCTION_PROXY_TYPE));
|
|
|
|
__ b(ne, &non_function_call);
|
|
|
|
__ GetBuiltinEntry(r3, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
|
|
|
|
__ jmp(&do_call);
|
|
|
|
|
|
|
|
__ bind(&non_function_call);
|
|
|
|
__ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
|
|
|
|
__ bind(&do_call);
|
|
|
|
// Set expected number of arguments to zero (not changing r0).
|
2013-01-07 09:43:12 +00:00
|
|
|
__ mov(r2, Operand::Zero());
|
2012-01-27 13:03:19 +00:00
|
|
|
__ SetCallKind(r5, CALL_AS_METHOD);
|
|
|
|
__ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
|
|
|
|
RelocInfo::CODE_TARGET);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// StringCharCodeAtGenerator
|
|
|
|
void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
|
|
|
|
Label flat_string;
|
|
|
|
Label ascii_string;
|
|
|
|
Label got_char_code;
|
2011-08-26 13:03:30 +00:00
|
|
|
Label sliced_string;
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// If the receiver is a smi trigger the non-string case.
|
2011-01-26 07:44:45 +00:00
|
|
|
__ JumpIfSmi(object_, receiver_not_string_);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Fetch the instance type of the receiver into result register.
|
|
|
|
__ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
|
|
|
|
// If the receiver is not a string trigger the non-string case.
|
|
|
|
__ tst(result_, Operand(kIsNotStringMask));
|
|
|
|
__ b(ne, receiver_not_string_);
|
|
|
|
|
|
|
|
// If the index is non-smi trigger the non-smi case.
|
2011-01-26 07:44:45 +00:00
|
|
|
__ JumpIfNotSmi(index_, &index_not_smi_);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&got_smi_index_);
|
|
|
|
|
|
|
|
// Check for index out of range.
|
|
|
|
__ ldr(ip, FieldMemOperand(object_, String::kLengthOffset));
|
2011-11-09 14:32:51 +00:00
|
|
|
__ cmp(ip, Operand(index_));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(ls, index_out_of_range_);
|
|
|
|
|
2011-11-24 11:07:39 +00:00
|
|
|
__ mov(index_, Operand(index_, ASR, kSmiTagSize));
|
|
|
|
|
|
|
|
StringCharLoadGenerator::Generate(masm,
|
|
|
|
object_,
|
|
|
|
index_,
|
|
|
|
result_,
|
|
|
|
&call_runtime_);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ mov(result_, Operand(result_, LSL, kSmiTagSize));
|
|
|
|
__ bind(&exit_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringCharCodeAtGenerator::GenerateSlow(
|
2011-10-28 12:37:29 +00:00
|
|
|
MacroAssembler* masm,
|
|
|
|
const RuntimeCallHelper& call_helper) {
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Abort("Unexpected fallthrough to CharCodeAt slow case");
|
|
|
|
|
|
|
|
// Index is not a smi.
|
|
|
|
__ bind(&index_not_smi_);
|
|
|
|
// If index is a heap number, try converting it to an integer.
|
|
|
|
__ CheckMap(index_,
|
2011-11-09 14:32:51 +00:00
|
|
|
result_,
|
2010-08-25 09:44:44 +00:00
|
|
|
Heap::kHeapNumberMapRootIndex,
|
|
|
|
index_not_number_,
|
2011-05-17 12:05:06 +00:00
|
|
|
DONT_DO_SMI_CHECK);
|
2010-08-25 09:44:44 +00:00
|
|
|
call_helper.BeforeCall(masm);
|
2011-11-09 14:32:51 +00:00
|
|
|
__ push(object_);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ push(index_); // Consumed by runtime conversion function.
|
|
|
|
if (index_flags_ == STRING_INDEX_IS_NUMBER) {
|
|
|
|
__ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
|
|
|
|
} else {
|
|
|
|
ASSERT(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.
|
2011-11-09 14:32:51 +00:00
|
|
|
__ Move(index_, r0);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ pop(object_);
|
|
|
|
// Reload the instance type.
|
|
|
|
__ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
|
|
|
|
call_helper.AfterCall(masm);
|
|
|
|
// If index is still not a smi, it must be out of range.
|
2011-11-09 14:32:51 +00:00
|
|
|
__ JumpIfNotSmi(index_, index_out_of_range_);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Otherwise, return to the fast path.
|
|
|
|
__ jmp(&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);
|
2011-11-24 11:07:39 +00:00
|
|
|
__ mov(index_, Operand(index_, LSL, kSmiTagSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Push(object_, index_);
|
|
|
|
__ CallRuntime(Runtime::kStringCharCodeAt, 2);
|
|
|
|
__ Move(result_, r0);
|
|
|
|
call_helper.AfterCall(masm);
|
|
|
|
__ jmp(&exit_);
|
|
|
|
|
|
|
|
__ Abort("Unexpected fallthrough from CharCodeAt slow case");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// StringCharFromCodeGenerator
|
|
|
|
|
|
|
|
void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
|
|
|
|
// Fast case of Heap::LookupSingleCharacterStringFromCode.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiShiftSize == 0);
|
2013-01-09 10:30:54 +00:00
|
|
|
ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ tst(code_,
|
|
|
|
Operand(kSmiTagMask |
|
2013-01-09 10:30:54 +00:00
|
|
|
((~String::kMaxOneByteCharCode) << kSmiTagSize)));
|
2011-01-26 08:32:54 +00:00
|
|
|
__ b(ne, &slow_case_);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
|
2011-03-15 10:03:57 +00:00
|
|
|
// At this point code register contains smi tagged ASCII char code.
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ add(result_, result_, Operand(code_, LSL, kPointerSizeLog2 - kSmiTagSize));
|
|
|
|
__ ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize));
|
2012-01-27 16:54:22 +00:00
|
|
|
__ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, &slow_case_);
|
|
|
|
__ bind(&exit_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringCharFromCodeGenerator::GenerateSlow(
|
2011-10-28 12:37:29 +00:00
|
|
|
MacroAssembler* masm,
|
|
|
|
const RuntimeCallHelper& call_helper) {
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Abort("Unexpected fallthrough to CharFromCode slow case");
|
|
|
|
|
|
|
|
__ bind(&slow_case_);
|
|
|
|
call_helper.BeforeCall(masm);
|
|
|
|
__ push(code_);
|
|
|
|
__ CallRuntime(Runtime::kCharFromCode, 1);
|
|
|
|
__ Move(result_, r0);
|
|
|
|
call_helper.AfterCall(masm);
|
|
|
|
__ jmp(&exit_);
|
|
|
|
|
|
|
|
__ Abort("Unexpected fallthrough from CharFromCode slow case");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
|
|
|
|
Register dest,
|
|
|
|
Register src,
|
|
|
|
Register count,
|
|
|
|
Register scratch,
|
|
|
|
bool ascii) {
|
|
|
|
Label loop;
|
|
|
|
Label done;
|
|
|
|
// This loop just copies one character at a time, as it is only used for very
|
|
|
|
// short strings.
|
|
|
|
if (!ascii) {
|
|
|
|
__ add(count, count, Operand(count), SetCC);
|
|
|
|
} else {
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(count, Operand::Zero());
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
__ b(eq, &done);
|
|
|
|
|
|
|
|
__ bind(&loop);
|
|
|
|
__ ldrb(scratch, MemOperand(src, 1, PostIndex));
|
|
|
|
// Perform sub between load and dependent store to get the load time to
|
|
|
|
// complete.
|
|
|
|
__ sub(count, count, Operand(1), SetCC);
|
|
|
|
__ strb(scratch, MemOperand(dest, 1, PostIndex));
|
|
|
|
// last iteration.
|
|
|
|
__ b(gt, &loop);
|
|
|
|
|
|
|
|
__ bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum CopyCharactersFlags {
|
|
|
|
COPY_ASCII = 1,
|
|
|
|
DEST_ALWAYS_ALIGNED = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateCopyCharactersLong(MacroAssembler* masm,
|
|
|
|
Register dest,
|
|
|
|
Register src,
|
|
|
|
Register count,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register scratch3,
|
|
|
|
Register scratch4,
|
|
|
|
Register scratch5,
|
|
|
|
int flags) {
|
|
|
|
bool ascii = (flags & COPY_ASCII) != 0;
|
|
|
|
bool dest_always_aligned = (flags & DEST_ALWAYS_ALIGNED) != 0;
|
|
|
|
|
|
|
|
if (dest_always_aligned && FLAG_debug_code) {
|
|
|
|
// Check that destination is actually word aligned if the flag says
|
|
|
|
// that it is.
|
|
|
|
__ tst(dest, Operand(kPointerAlignmentMask));
|
|
|
|
__ Check(eq, "Destination of copy not aligned.");
|
|
|
|
}
|
|
|
|
|
|
|
|
const int kReadAlignment = 4;
|
|
|
|
const int kReadAlignmentMask = kReadAlignment - 1;
|
|
|
|
// Ensure that reading an entire aligned word containing the last character
|
|
|
|
// of a string will not read outside the allocated area (because we pad up
|
|
|
|
// to kObjectAlignment).
|
|
|
|
STATIC_ASSERT(kObjectAlignment >= kReadAlignment);
|
|
|
|
// Assumes word reads and writes are little endian.
|
|
|
|
// Nothing to do for zero characters.
|
|
|
|
Label done;
|
|
|
|
if (!ascii) {
|
|
|
|
__ add(count, count, Operand(count), SetCC);
|
|
|
|
} else {
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(count, Operand::Zero());
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
__ b(eq, &done);
|
|
|
|
|
|
|
|
// Assume that you cannot read (or write) unaligned.
|
|
|
|
Label byte_loop;
|
|
|
|
// Must copy at least eight bytes, otherwise just do it one byte at a time.
|
|
|
|
__ cmp(count, Operand(8));
|
|
|
|
__ add(count, dest, Operand(count));
|
|
|
|
Register limit = count; // Read until src equals this.
|
|
|
|
__ b(lt, &byte_loop);
|
|
|
|
|
|
|
|
if (!dest_always_aligned) {
|
|
|
|
// Align dest by byte copying. Copies between zero and three bytes.
|
|
|
|
__ and_(scratch4, dest, Operand(kReadAlignmentMask), SetCC);
|
|
|
|
Label dest_aligned;
|
|
|
|
__ b(eq, &dest_aligned);
|
|
|
|
__ cmp(scratch4, Operand(2));
|
|
|
|
__ ldrb(scratch1, MemOperand(src, 1, PostIndex));
|
|
|
|
__ ldrb(scratch2, MemOperand(src, 1, PostIndex), le);
|
|
|
|
__ ldrb(scratch3, MemOperand(src, 1, PostIndex), lt);
|
|
|
|
__ strb(scratch1, MemOperand(dest, 1, PostIndex));
|
|
|
|
__ strb(scratch2, MemOperand(dest, 1, PostIndex), le);
|
|
|
|
__ strb(scratch3, MemOperand(dest, 1, PostIndex), lt);
|
|
|
|
__ bind(&dest_aligned);
|
|
|
|
}
|
|
|
|
|
|
|
|
Label simple_loop;
|
|
|
|
|
|
|
|
__ sub(scratch4, dest, Operand(src));
|
|
|
|
__ and_(scratch4, scratch4, Operand(0x03), SetCC);
|
|
|
|
__ b(eq, &simple_loop);
|
|
|
|
// Shift register is number of bits in a source word that
|
|
|
|
// must be combined with bits in the next source word in order
|
|
|
|
// to create a destination word.
|
|
|
|
|
|
|
|
// Complex loop for src/dst that are not aligned the same way.
|
|
|
|
{
|
|
|
|
Label loop;
|
|
|
|
__ mov(scratch4, Operand(scratch4, LSL, 3));
|
|
|
|
Register left_shift = scratch4;
|
|
|
|
__ and_(src, src, Operand(~3)); // Round down to load previous word.
|
|
|
|
__ ldr(scratch1, MemOperand(src, 4, PostIndex));
|
|
|
|
// Store the "shift" most significant bits of scratch in the least
|
|
|
|
// signficant bits (i.e., shift down by (32-shift)).
|
|
|
|
__ rsb(scratch2, left_shift, Operand(32));
|
|
|
|
Register right_shift = scratch2;
|
|
|
|
__ mov(scratch1, Operand(scratch1, LSR, right_shift));
|
|
|
|
|
|
|
|
__ bind(&loop);
|
|
|
|
__ ldr(scratch3, MemOperand(src, 4, PostIndex));
|
|
|
|
__ sub(scratch5, limit, Operand(dest));
|
|
|
|
__ orr(scratch1, scratch1, Operand(scratch3, LSL, left_shift));
|
|
|
|
__ str(scratch1, MemOperand(dest, 4, PostIndex));
|
|
|
|
__ mov(scratch1, Operand(scratch3, LSR, right_shift));
|
|
|
|
// Loop if four or more bytes left to copy.
|
|
|
|
// Compare to eight, because we did the subtract before increasing dst.
|
|
|
|
__ sub(scratch5, scratch5, Operand(8), SetCC);
|
|
|
|
__ b(ge, &loop);
|
|
|
|
}
|
|
|
|
// There is now between zero and three bytes left to copy (negative that
|
|
|
|
// number is in scratch5), and between one and three bytes already read into
|
|
|
|
// scratch1 (eight times that number in scratch4). We may have read past
|
|
|
|
// the end of the string, but because objects are aligned, we have not read
|
|
|
|
// past the end of the object.
|
|
|
|
// Find the minimum of remaining characters to move and preloaded characters
|
|
|
|
// and write those as bytes.
|
|
|
|
__ add(scratch5, scratch5, Operand(4), SetCC);
|
|
|
|
__ b(eq, &done);
|
|
|
|
__ cmp(scratch4, Operand(scratch5, LSL, 3), ne);
|
|
|
|
// Move minimum of bytes read and bytes left to copy to scratch4.
|
|
|
|
__ mov(scratch5, Operand(scratch4, LSR, 3), LeaveCC, lt);
|
|
|
|
// Between one and three (value in scratch5) characters already read into
|
|
|
|
// scratch ready to write.
|
|
|
|
__ cmp(scratch5, Operand(2));
|
|
|
|
__ strb(scratch1, MemOperand(dest, 1, PostIndex));
|
|
|
|
__ mov(scratch1, Operand(scratch1, LSR, 8), LeaveCC, ge);
|
|
|
|
__ strb(scratch1, MemOperand(dest, 1, PostIndex), ge);
|
|
|
|
__ mov(scratch1, Operand(scratch1, LSR, 8), LeaveCC, gt);
|
|
|
|
__ strb(scratch1, MemOperand(dest, 1, PostIndex), gt);
|
|
|
|
// Copy any remaining bytes.
|
|
|
|
__ b(&byte_loop);
|
|
|
|
|
|
|
|
// Simple loop.
|
|
|
|
// Copy words from src to dst, until less than four bytes left.
|
|
|
|
// Both src and dest are word aligned.
|
|
|
|
__ bind(&simple_loop);
|
|
|
|
{
|
|
|
|
Label loop;
|
|
|
|
__ bind(&loop);
|
|
|
|
__ ldr(scratch1, MemOperand(src, 4, PostIndex));
|
|
|
|
__ sub(scratch3, limit, Operand(dest));
|
|
|
|
__ str(scratch1, MemOperand(dest, 4, PostIndex));
|
|
|
|
// Compare to 8, not 4, because we do the substraction before increasing
|
|
|
|
// dest.
|
|
|
|
__ cmp(scratch3, Operand(8));
|
|
|
|
__ b(ge, &loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy bytes from src to dst until dst hits limit.
|
|
|
|
__ bind(&byte_loop);
|
|
|
|
__ cmp(dest, Operand(limit));
|
|
|
|
__ ldrb(scratch1, MemOperand(src, 1, PostIndex), lt);
|
|
|
|
__ b(ge, &done);
|
|
|
|
__ strb(scratch1, MemOperand(dest, 1, PostIndex));
|
|
|
|
__ b(&byte_loop);
|
|
|
|
|
|
|
|
__ bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
void StringHelper::GenerateTwoCharacterStringTableProbe(MacroAssembler* masm,
|
2010-08-25 09:44:44 +00:00
|
|
|
Register c1,
|
|
|
|
Register c2,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register scratch3,
|
|
|
|
Register scratch4,
|
|
|
|
Register scratch5,
|
|
|
|
Label* not_found) {
|
|
|
|
// Register scratch3 is the general scratch register in this function.
|
|
|
|
Register scratch = scratch3;
|
|
|
|
|
|
|
|
// Make sure that both characters are not digits as such strings has a
|
2013-02-28 17:03:34 +00:00
|
|
|
// different hash algorithm. Don't try to look for these in the string table.
|
2010-08-25 09:44:44 +00:00
|
|
|
Label not_array_index;
|
|
|
|
__ sub(scratch, c1, Operand(static_cast<int>('0')));
|
|
|
|
__ cmp(scratch, Operand(static_cast<int>('9' - '0')));
|
|
|
|
__ b(hi, ¬_array_index);
|
|
|
|
__ sub(scratch, c2, Operand(static_cast<int>('0')));
|
|
|
|
__ cmp(scratch, Operand(static_cast<int>('9' - '0')));
|
|
|
|
|
|
|
|
// If check failed combine both characters into single halfword.
|
|
|
|
// This is required by the contract of the method: code at the
|
|
|
|
// not_found branch expects this combination in c1 register
|
|
|
|
__ orr(c1, c1, Operand(c2, LSL, kBitsPerByte), LeaveCC, ls);
|
|
|
|
__ b(ls, not_found);
|
|
|
|
|
|
|
|
__ bind(¬_array_index);
|
|
|
|
// Calculate the two character string hash.
|
|
|
|
Register hash = scratch1;
|
|
|
|
StringHelper::GenerateHashInit(masm, hash, c1);
|
|
|
|
StringHelper::GenerateHashAddCharacter(masm, hash, c2);
|
|
|
|
StringHelper::GenerateHashGetHash(masm, hash);
|
|
|
|
|
|
|
|
// Collect the two characters in a register.
|
|
|
|
Register chars = c1;
|
|
|
|
__ orr(chars, chars, Operand(c2, LSL, kBitsPerByte));
|
|
|
|
|
|
|
|
// chars: two character string, char 1 in byte 0 and char 2 in byte 1.
|
|
|
|
// hash: hash of two character string.
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Load string table
|
|
|
|
// Load address of first element of the string table.
|
|
|
|
Register string_table = c2;
|
|
|
|
__ LoadRoot(string_table, Heap::kStringTableRootIndex);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
Register undefined = scratch4;
|
|
|
|
__ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Calculate capacity mask from the string table capacity.
|
2010-08-25 09:44:44 +00:00
|
|
|
Register mask = scratch2;
|
2013-02-28 17:03:34 +00:00
|
|
|
__ ldr(mask, FieldMemOperand(string_table, StringTable::kCapacityOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(mask, Operand(mask, ASR, 1));
|
|
|
|
__ sub(mask, mask, Operand(1));
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Calculate untagged address of the first element of the string table.
|
|
|
|
Register first_string_table_element = string_table;
|
|
|
|
__ add(first_string_table_element, string_table,
|
|
|
|
Operand(StringTable::kElementsStartOffset - kHeapObjectTag));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Registers
|
|
|
|
// chars: two character string, char 1 in byte 0 and char 2 in byte 1.
|
|
|
|
// hash: hash of two character string
|
|
|
|
// mask: capacity mask
|
2013-02-28 17:03:34 +00:00
|
|
|
// first_string_table_element: address of the first element of
|
|
|
|
// the string table
|
2011-03-15 10:03:57 +00:00
|
|
|
// undefined: the undefined object
|
2010-08-25 09:44:44 +00:00
|
|
|
// scratch: -
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Perform a number of probes in the string table.
|
2012-03-12 13:56:56 +00:00
|
|
|
const int kProbes = 4;
|
2013-02-28 17:03:34 +00:00
|
|
|
Label found_in_string_table;
|
2010-08-25 09:44:44 +00:00
|
|
|
Label next_probe[kProbes];
|
2011-11-10 14:26:57 +00:00
|
|
|
Register candidate = scratch5; // Scratch register contains candidate.
|
2010-08-25 09:44:44 +00:00
|
|
|
for (int i = 0; i < kProbes; i++) {
|
2013-02-28 17:03:34 +00:00
|
|
|
// Calculate entry in string table.
|
2010-08-25 09:44:44 +00:00
|
|
|
if (i > 0) {
|
2013-02-28 17:03:34 +00:00
|
|
|
__ add(candidate, hash, Operand(StringTable::GetProbeOffset(i)));
|
2010-08-25 09:44:44 +00:00
|
|
|
} else {
|
|
|
|
__ mov(candidate, hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ and_(candidate, candidate, Operand(mask));
|
|
|
|
|
|
|
|
// Load the entry from the symble table.
|
2013-02-28 17:03:34 +00:00
|
|
|
STATIC_ASSERT(StringTable::kEntrySize == 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ldr(candidate,
|
2013-02-28 17:03:34 +00:00
|
|
|
MemOperand(first_string_table_element,
|
2010-08-25 09:44:44 +00:00
|
|
|
candidate,
|
|
|
|
LSL,
|
|
|
|
kPointerSizeLog2));
|
|
|
|
|
|
|
|
// If entry is undefined no string with this hash can be found.
|
2011-03-15 10:03:57 +00:00
|
|
|
Label is_string;
|
|
|
|
__ CompareObjectType(candidate, scratch, scratch, ODDBALL_TYPE);
|
|
|
|
__ b(ne, &is_string);
|
|
|
|
|
|
|
|
__ cmp(undefined, candidate);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, not_found);
|
2011-11-10 14:26:57 +00:00
|
|
|
// Must be the hole (deleted entry).
|
2011-03-15 10:03:57 +00:00
|
|
|
if (FLAG_debug_code) {
|
2011-11-10 14:26:57 +00:00
|
|
|
__ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
|
2011-03-15 10:03:57 +00:00
|
|
|
__ cmp(ip, candidate);
|
2013-02-28 17:03:34 +00:00
|
|
|
__ Assert(eq, "oddball in string table is not undefined or the hole");
|
2011-03-15 10:03:57 +00:00
|
|
|
}
|
|
|
|
__ jmp(&next_probe[i]);
|
|
|
|
|
|
|
|
__ bind(&is_string);
|
|
|
|
|
|
|
|
// Check that the candidate is a non-external ASCII string. The instance
|
|
|
|
// type is still in the scratch register from the CompareObjectType
|
|
|
|
// operation.
|
|
|
|
__ JumpIfInstanceTypeIsNotSequentialAscii(scratch, scratch, &next_probe[i]);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// If length is not 2 the string is not a candidate.
|
|
|
|
__ ldr(scratch, FieldMemOperand(candidate, String::kLengthOffset));
|
|
|
|
__ cmp(scratch, Operand(Smi::FromInt(2)));
|
|
|
|
__ b(ne, &next_probe[i]);
|
|
|
|
|
|
|
|
// Check if the two characters match.
|
|
|
|
// Assumes that word load is little endian.
|
2012-11-15 13:31:27 +00:00
|
|
|
__ ldrh(scratch, FieldMemOperand(candidate, SeqOneByteString::kHeaderSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmp(chars, scratch);
|
2013-02-28 17:03:34 +00:00
|
|
|
__ b(eq, &found_in_string_table);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&next_probe[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching 2 character string found by probing.
|
|
|
|
__ jmp(not_found);
|
|
|
|
|
|
|
|
// Scratch register contains result when we fall through to here.
|
2011-11-10 14:26:57 +00:00
|
|
|
Register result = candidate;
|
2013-02-28 17:03:34 +00:00
|
|
|
__ bind(&found_in_string_table);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Move(r0, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateHashInit(MacroAssembler* masm,
|
|
|
|
Register hash,
|
|
|
|
Register character) {
|
|
|
|
// hash = character + (character << 10);
|
2012-01-10 13:24:18 +00:00
|
|
|
__ LoadRoot(hash, Heap::kHashSeedRootIndex);
|
2012-01-04 15:12:15 +00:00
|
|
|
// Untag smi seed and add the character.
|
|
|
|
__ add(hash, character, Operand(hash, LSR, kSmiTagSize));
|
|
|
|
// hash += hash << 10;
|
|
|
|
__ add(hash, hash, Operand(hash, LSL, 10));
|
2010-08-25 09:44:44 +00:00
|
|
|
// hash ^= hash >> 6;
|
2011-11-10 14:26:57 +00:00
|
|
|
__ eor(hash, hash, Operand(hash, LSR, 6));
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm,
|
|
|
|
Register hash,
|
|
|
|
Register character) {
|
|
|
|
// hash += character;
|
|
|
|
__ add(hash, hash, Operand(character));
|
|
|
|
// hash += hash << 10;
|
|
|
|
__ add(hash, hash, Operand(hash, LSL, 10));
|
|
|
|
// hash ^= hash >> 6;
|
2011-11-10 14:26:57 +00:00
|
|
|
__ eor(hash, hash, Operand(hash, LSR, 6));
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateHashGetHash(MacroAssembler* masm,
|
|
|
|
Register hash) {
|
|
|
|
// hash += hash << 3;
|
|
|
|
__ add(hash, hash, Operand(hash, LSL, 3));
|
|
|
|
// hash ^= hash >> 11;
|
2011-11-10 14:26:57 +00:00
|
|
|
__ eor(hash, hash, Operand(hash, LSR, 11));
|
2010-08-25 09:44:44 +00:00
|
|
|
// hash += hash << 15;
|
2012-01-10 12:01:04 +00:00
|
|
|
__ add(hash, hash, Operand(hash, LSL, 15));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-01-10 12:01:04 +00:00
|
|
|
__ and_(hash, hash, Operand(String::kHashBitMask), SetCC);
|
2011-11-10 14:26:57 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// if (hash == 0) hash = 27;
|
2012-01-10 12:01:04 +00:00
|
|
|
__ mov(hash, Operand(StringHasher::kZeroHash), LeaveCC, eq);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SubStringStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label runtime;
|
|
|
|
|
|
|
|
// Stack frame on entry.
|
|
|
|
// lr: return address
|
|
|
|
// sp[0]: to
|
|
|
|
// sp[4]: from
|
|
|
|
// sp[8]: string
|
|
|
|
|
|
|
|
// This stub is called from the native-call %_SubString(...), so
|
|
|
|
// nothing can be assumed about the arguments. It is tested that:
|
|
|
|
// "string" is a sequential string,
|
|
|
|
// both "from" and "to" are smis, and
|
|
|
|
// 0 <= from <= to <= string.length.
|
|
|
|
// If any of these assumptions fail, we call the runtime system.
|
|
|
|
|
2012-03-12 13:56:56 +00:00
|
|
|
const int kToOffset = 0 * kPointerSize;
|
|
|
|
const int kFromOffset = 1 * kPointerSize;
|
|
|
|
const int kStringOffset = 2 * kPointerSize;
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-12-14 10:22:33 +00:00
|
|
|
__ Ldrd(r2, r3, MemOperand(sp, kToOffset));
|
2010-09-15 10:22:55 +00:00
|
|
|
STATIC_ASSERT(kFromOffset == kToOffset + 4);
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
|
2011-08-26 13:03:30 +00:00
|
|
|
|
2012-11-07 13:22:03 +00:00
|
|
|
// Arithmetic shift right by one un-smi-tags. In this case we rotate right
|
|
|
|
// instead because we bail out on non-smi values: ROR and ASR are equivalent
|
|
|
|
// for smis but they set the flags in a way that's easier to optimize.
|
|
|
|
__ mov(r2, Operand(r2, ROR, 1), SetCC);
|
|
|
|
__ mov(r3, Operand(r3, ROR, 1), SetCC, cc);
|
|
|
|
// If either to or from had the smi tag bit set, then C is set now, and N
|
|
|
|
// has the same value: we rotated by 1, so the bottom bit is now the top bit.
|
2012-01-27 16:54:22 +00:00
|
|
|
// We want to bailout to runtime here if From is negative. In that case, the
|
|
|
|
// next instruction is not executed and we fall through to bailing out to
|
2012-11-07 13:22:03 +00:00
|
|
|
// runtime.
|
|
|
|
// Executed if both r2 and r3 are untagged integers.
|
|
|
|
__ sub(r2, r2, Operand(r3), SetCC, cc);
|
|
|
|
// One of the above un-smis or the above SUB could have set N==1.
|
|
|
|
__ b(mi, &runtime); // Either "from" or "to" is not an smi, or from > to.
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-12-14 10:22:33 +00:00
|
|
|
// Make sure first argument is a string.
|
2011-09-01 15:24:26 +00:00
|
|
|
__ ldr(r0, MemOperand(sp, kStringOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2012-11-07 13:22:03 +00:00
|
|
|
// Do a JumpIfSmi, but fold its jump into the subsequent string test.
|
|
|
|
__ tst(r0, Operand(kSmiTagMask));
|
|
|
|
Condition is_string = masm->IsObjectStringType(r0, r1, ne);
|
|
|
|
ASSERT(is_string == eq);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(NegateCondition(is_string), &runtime);
|
|
|
|
|
2013-02-20 14:29:40 +00:00
|
|
|
Label single_char;
|
|
|
|
__ cmp(r2, Operand(1));
|
|
|
|
__ b(eq, &single_char);
|
|
|
|
|
2011-09-01 15:24:26 +00:00
|
|
|
// Short-cut for the case of trivial substring.
|
|
|
|
Label return_r0;
|
|
|
|
// r0: original string
|
|
|
|
// r2: result string length
|
|
|
|
__ ldr(r4, FieldMemOperand(r0, String::kLengthOffset));
|
|
|
|
__ cmp(r2, Operand(r4, ASR, 1));
|
2012-04-17 10:49:15 +00:00
|
|
|
// Return original string.
|
2011-09-01 15:24:26 +00:00
|
|
|
__ b(eq, &return_r0);
|
2012-04-17 10:49:15 +00:00
|
|
|
// Longer than original string's length or negative: unsafe arguments.
|
|
|
|
__ b(hi, &runtime);
|
|
|
|
// Shorter than original string's length: an actual substring.
|
2011-09-01 15:24:26 +00:00
|
|
|
|
2011-12-14 10:22:33 +00:00
|
|
|
// Deal with different string types: update the index if necessary
|
|
|
|
// and put the underlying string into r5.
|
|
|
|
// r0: original string
|
|
|
|
// r1: instance type
|
|
|
|
// r2: length
|
|
|
|
// r3: from index (untagged)
|
|
|
|
Label underlying_unpacked, sliced_string, seq_or_external_string;
|
|
|
|
// If the string is not indirect, it can only be sequential or external.
|
|
|
|
STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
|
|
|
|
STATIC_ASSERT(kIsIndirectStringMask != 0);
|
|
|
|
__ tst(r1, Operand(kIsIndirectStringMask));
|
|
|
|
__ b(eq, &seq_or_external_string);
|
|
|
|
|
|
|
|
__ tst(r1, Operand(kSlicedNotConsMask));
|
|
|
|
__ b(ne, &sliced_string);
|
|
|
|
// Cons string. Check whether it is flat, then fetch first part.
|
|
|
|
__ ldr(r5, FieldMemOperand(r0, ConsString::kSecondOffset));
|
2013-02-28 17:03:34 +00:00
|
|
|
__ CompareRoot(r5, Heap::kempty_stringRootIndex);
|
2011-12-14 10:22:33 +00:00
|
|
|
__ b(ne, &runtime);
|
|
|
|
__ ldr(r5, FieldMemOperand(r0, ConsString::kFirstOffset));
|
|
|
|
// Update instance type.
|
|
|
|
__ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
|
|
|
|
__ jmp(&underlying_unpacked);
|
|
|
|
|
|
|
|
__ bind(&sliced_string);
|
|
|
|
// Sliced string. Fetch parent and correct start index by offset.
|
|
|
|
__ ldr(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
|
2012-03-07 14:19:28 +00:00
|
|
|
__ ldr(r4, FieldMemOperand(r0, SlicedString::kOffsetOffset));
|
2012-01-27 16:54:22 +00:00
|
|
|
__ add(r3, r3, Operand(r4, ASR, 1)); // Add offset to index.
|
2011-12-14 10:22:33 +00:00
|
|
|
// Update instance type.
|
|
|
|
__ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
|
|
|
|
__ jmp(&underlying_unpacked);
|
|
|
|
|
|
|
|
__ bind(&seq_or_external_string);
|
|
|
|
// Sequential or external string. Just move string to the expected register.
|
|
|
|
__ mov(r5, r0);
|
|
|
|
|
|
|
|
__ bind(&underlying_unpacked);
|
|
|
|
|
|
|
|
if (FLAG_string_slices) {
|
|
|
|
Label copy_routine;
|
|
|
|
// r5: underlying subject string
|
|
|
|
// r1: instance type of underlying subject string
|
|
|
|
// r2: length
|
|
|
|
// r3: adjusted start index (untagged)
|
|
|
|
__ cmp(r2, Operand(SlicedString::kMinLength));
|
|
|
|
// Short slice. Copy instead of slicing.
|
|
|
|
__ b(lt, ©_routine);
|
|
|
|
// Allocate new sliced string. At this point we do not reload the instance
|
|
|
|
// type including the string encoding because we simply rely on the info
|
|
|
|
// provided by the original string. It does not matter if the original
|
|
|
|
// string's encoding is wrong because we always have to recheck encoding of
|
|
|
|
// the newly created string's parent anyways due to externalized strings.
|
|
|
|
Label two_byte_slice, set_slice_header;
|
2012-11-08 12:14:29 +00:00
|
|
|
STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
|
2011-12-14 10:22:33 +00:00
|
|
|
STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
|
|
|
|
__ tst(r1, Operand(kStringEncodingMask));
|
|
|
|
__ b(eq, &two_byte_slice);
|
|
|
|
__ AllocateAsciiSlicedString(r0, r2, r6, r7, &runtime);
|
|
|
|
__ jmp(&set_slice_header);
|
|
|
|
__ bind(&two_byte_slice);
|
|
|
|
__ AllocateTwoByteSlicedString(r0, r2, r6, r7, &runtime);
|
|
|
|
__ bind(&set_slice_header);
|
|
|
|
__ mov(r3, Operand(r3, LSL, 1));
|
|
|
|
__ str(r5, FieldMemOperand(r0, SlicedString::kParentOffset));
|
2012-03-07 14:19:28 +00:00
|
|
|
__ str(r3, FieldMemOperand(r0, SlicedString::kOffsetOffset));
|
2011-12-14 10:22:33 +00:00
|
|
|
__ jmp(&return_r0);
|
|
|
|
|
|
|
|
__ bind(©_routine);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-12-14 10:22:33 +00:00
|
|
|
// r5: underlying subject string
|
|
|
|
// r1: instance type of underlying subject string
|
|
|
|
// r2: length
|
|
|
|
// r3: adjusted start index (untagged)
|
|
|
|
Label two_byte_sequential, sequential_string, allocate_result;
|
|
|
|
STATIC_ASSERT(kExternalStringTag != 0);
|
|
|
|
STATIC_ASSERT(kSeqStringTag == 0);
|
|
|
|
__ tst(r1, Operand(kExternalStringTag));
|
|
|
|
__ b(eq, &sequential_string);
|
2011-09-01 15:24:26 +00:00
|
|
|
|
2011-12-14 10:22:33 +00:00
|
|
|
// Handle external string.
|
|
|
|
// Rule out short external strings.
|
|
|
|
STATIC_CHECK(kShortExternalStringTag != 0);
|
|
|
|
__ tst(r1, Operand(kShortExternalStringTag));
|
|
|
|
__ b(ne, &runtime);
|
|
|
|
__ ldr(r5, FieldMemOperand(r5, ExternalString::kResourceDataOffset));
|
|
|
|
// r5 already points to the first character of underlying string.
|
|
|
|
__ jmp(&allocate_result);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-12-14 10:22:33 +00:00
|
|
|
__ bind(&sequential_string);
|
|
|
|
// Locate first character of underlying subject string.
|
2012-11-15 13:31:27 +00:00
|
|
|
STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
|
|
|
|
__ add(r5, r5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
|
2011-12-14 10:22:33 +00:00
|
|
|
|
|
|
|
__ bind(&allocate_result);
|
|
|
|
// Sequential acii string. Allocate the result.
|
2012-11-08 12:14:29 +00:00
|
|
|
STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
|
2011-12-14 10:22:33 +00:00
|
|
|
__ tst(r1, Operand(kStringEncodingMask));
|
|
|
|
__ b(eq, &two_byte_sequential);
|
|
|
|
|
2012-01-16 12:38:59 +00:00
|
|
|
// Allocate and copy the resulting ASCII string.
|
2011-12-14 10:22:33 +00:00
|
|
|
__ AllocateAsciiString(r0, r2, r4, r6, r7, &runtime);
|
|
|
|
|
|
|
|
// Locate first character of substring to copy.
|
|
|
|
__ add(r5, r5, r3);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Locate first character of result.
|
2012-11-15 13:31:27 +00:00
|
|
|
__ add(r1, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-09-01 15:24:26 +00:00
|
|
|
// r0: result string
|
|
|
|
// r1: first character of result string
|
|
|
|
// r2: result string length
|
|
|
|
// r5: first character of substring to copy
|
2012-11-15 13:31:27 +00:00
|
|
|
STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0);
|
2010-08-25 09:44:44 +00:00
|
|
|
StringHelper::GenerateCopyCharactersLong(masm, r1, r5, r2, r3, r4, r6, r7, r9,
|
|
|
|
COPY_ASCII | DEST_ALWAYS_ALIGNED);
|
2011-09-01 15:24:26 +00:00
|
|
|
__ jmp(&return_r0);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-12-14 10:22:33 +00:00
|
|
|
// Allocate and copy the resulting two-byte string.
|
|
|
|
__ bind(&two_byte_sequential);
|
|
|
|
__ AllocateTwoByteString(r0, r2, r4, r6, r7, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-12-14 10:22:33 +00:00
|
|
|
// Locate first character of substring to copy.
|
2011-09-01 15:24:26 +00:00
|
|
|
STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
|
2011-12-14 10:22:33 +00:00
|
|
|
__ add(r5, r5, Operand(r3, LSL, 1));
|
2010-08-25 09:44:44 +00:00
|
|
|
// Locate first character of result.
|
|
|
|
__ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
|
2011-09-01 15:24:26 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// r0: result string.
|
|
|
|
// r1: first character of result.
|
|
|
|
// r2: result length.
|
2011-09-01 15:24:26 +00:00
|
|
|
// r5: first character of substring to copy.
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
|
2010-09-15 10:22:55 +00:00
|
|
|
StringHelper::GenerateCopyCharactersLong(
|
|
|
|
masm, r1, r5, r2, r3, r4, r6, r7, r9, DEST_ALWAYS_ALIGNED);
|
2011-09-01 15:24:26 +00:00
|
|
|
|
|
|
|
__ bind(&return_r0);
|
2011-12-14 10:22:33 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->sub_string_native(), 1, r3, r4);
|
2013-02-20 14:29:40 +00:00
|
|
|
__ Drop(3);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Just jump to runtime to create the sub string.
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kSubString, 3, 1);
|
2013-02-20 14:29:40 +00:00
|
|
|
|
|
|
|
__ bind(&single_char);
|
|
|
|
// r0: original string
|
|
|
|
// r1: instance type
|
|
|
|
// r2: length
|
|
|
|
// r3: from index (untagged)
|
|
|
|
__ SmiTag(r3, r3);
|
|
|
|
StringCharAtGenerator generator(
|
|
|
|
r0, r3, r2, r0, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER);
|
|
|
|
generator.GenerateFast(masm);
|
|
|
|
__ Drop(3);
|
|
|
|
__ Ret();
|
|
|
|
generator.SkipSlow(masm, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-05 11:40:08 +00:00
|
|
|
void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm,
|
|
|
|
Register left,
|
|
|
|
Register right,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register scratch3) {
|
|
|
|
Register length = scratch1;
|
|
|
|
|
|
|
|
// Compare lengths.
|
|
|
|
Label strings_not_equal, check_zero_length;
|
|
|
|
__ ldr(length, FieldMemOperand(left, String::kLengthOffset));
|
|
|
|
__ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
|
|
|
|
__ cmp(length, scratch2);
|
|
|
|
__ b(eq, &check_zero_length);
|
|
|
|
__ bind(&strings_not_equal);
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(NOT_EQUAL)));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Check if the length is zero.
|
|
|
|
Label compare_chars;
|
|
|
|
__ bind(&check_zero_length);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(length, Operand::Zero());
|
2011-05-05 11:40:08 +00:00
|
|
|
__ b(ne, &compare_chars);
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(EQUAL)));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Compare characters.
|
|
|
|
__ bind(&compare_chars);
|
2011-05-06 14:19:51 +00:00
|
|
|
GenerateAsciiCharsCompareLoop(masm,
|
|
|
|
left, right, length, scratch2, scratch3,
|
|
|
|
&strings_not_equal);
|
2011-05-05 11:40:08 +00:00
|
|
|
|
|
|
|
// Characters are equal.
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(EQUAL)));
|
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
|
|
|
|
Register left,
|
|
|
|
Register right,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register scratch3,
|
|
|
|
Register scratch4) {
|
2011-05-06 14:19:51 +00:00
|
|
|
Label result_not_equal, compare_lengths;
|
2010-08-25 09:44:44 +00:00
|
|
|
// Find minimum length and length difference.
|
|
|
|
__ ldr(scratch1, FieldMemOperand(left, String::kLengthOffset));
|
|
|
|
__ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset));
|
|
|
|
__ sub(scratch3, scratch1, Operand(scratch2), SetCC);
|
|
|
|
Register length_delta = scratch3;
|
|
|
|
__ mov(scratch1, scratch2, LeaveCC, gt);
|
|
|
|
Register min_length = scratch1;
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(min_length, Operand::Zero());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, &compare_lengths);
|
|
|
|
|
2011-05-06 14:19:51 +00:00
|
|
|
// Compare loop.
|
|
|
|
GenerateAsciiCharsCompareLoop(masm,
|
|
|
|
left, right, min_length, scratch2, scratch4,
|
|
|
|
&result_not_equal);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-05-06 14:19:51 +00:00
|
|
|
// Compare lengths - strings up to min-length are equal.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&compare_lengths);
|
|
|
|
ASSERT(Smi::FromInt(EQUAL) == static_cast<Smi*>(0));
|
2011-05-06 14:19:51 +00:00
|
|
|
// Use length_delta as result if it's zero.
|
|
|
|
__ mov(r0, Operand(length_delta), SetCC);
|
|
|
|
__ bind(&result_not_equal);
|
|
|
|
// Conditionally update the result based either on length_delta or
|
|
|
|
// the last comparion performed in the loop above.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(r0, Operand(Smi::FromInt(GREATER)), LeaveCC, gt);
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(LESS)), LeaveCC, lt);
|
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-06 14:19:51 +00:00
|
|
|
void StringCompareStub::GenerateAsciiCharsCompareLoop(
|
|
|
|
MacroAssembler* masm,
|
|
|
|
Register left,
|
|
|
|
Register right,
|
|
|
|
Register length,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Label* chars_not_equal) {
|
|
|
|
// Change index to run from -length to -1 by adding length to string
|
|
|
|
// start. This means that loop ends when index reaches zero, which
|
|
|
|
// doesn't need an additional compare.
|
|
|
|
__ SmiUntag(length);
|
|
|
|
__ add(scratch1, length,
|
2012-11-15 13:31:27 +00:00
|
|
|
Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
|
2011-05-06 14:19:51 +00:00
|
|
|
__ add(left, left, Operand(scratch1));
|
|
|
|
__ add(right, right, Operand(scratch1));
|
2011-08-23 12:00:09 +00:00
|
|
|
__ rsb(length, length, Operand::Zero());
|
2011-05-06 14:19:51 +00:00
|
|
|
Register index = length; // index = -length;
|
|
|
|
|
|
|
|
// Compare loop.
|
|
|
|
Label loop;
|
|
|
|
__ bind(&loop);
|
|
|
|
__ ldrb(scratch1, MemOperand(left, index));
|
|
|
|
__ ldrb(scratch2, MemOperand(right, index));
|
|
|
|
__ cmp(scratch1, scratch2);
|
|
|
|
__ b(ne, chars_not_equal);
|
|
|
|
__ add(index, index, Operand(1), SetCC);
|
|
|
|
__ b(ne, &loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void StringCompareStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label runtime;
|
|
|
|
|
2011-03-23 11:13:07 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Stack frame on entry.
|
|
|
|
// sp[0]: right string
|
|
|
|
// sp[4]: left string
|
2010-09-15 10:22:55 +00:00
|
|
|
__ Ldrd(r0 , r1, MemOperand(sp)); // Load right in r0, left in r1.
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
Label not_same;
|
|
|
|
__ cmp(r0, r1);
|
|
|
|
__ b(ne, ¬_same);
|
|
|
|
STATIC_ASSERT(EQUAL == 0);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(EQUAL)));
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_compare_native(), 1, r1, r2);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ add(sp, sp, Operand(2 * kPointerSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(¬_same);
|
|
|
|
|
2011-03-15 10:03:57 +00:00
|
|
|
// Check that both objects are sequential ASCII strings.
|
2010-09-15 10:22:55 +00:00
|
|
|
__ JumpIfNotBothSequentialAsciiStrings(r1, r0, r2, r3, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-03-15 10:03:57 +00:00
|
|
|
// Compare flat ASCII strings natively. Remove arguments from stack first.
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_compare_native(), 1, r2, r3);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ add(sp, sp, Operand(2 * kPointerSize));
|
2010-09-15 10:22:55 +00:00
|
|
|
GenerateCompareFlatAsciiStrings(masm, r1, r0, r2, r3, r4, r5);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
|
|
|
|
// tagged as a small integer.
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kStringCompare, 2, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringAddStub::Generate(MacroAssembler* masm) {
|
2011-12-15 11:04:58 +00:00
|
|
|
Label call_runtime, call_builtin;
|
2011-02-22 09:35:37 +00:00
|
|
|
Builtins::JavaScript builtin_id = Builtins::ADD;
|
|
|
|
|
2011-03-23 11:13:07 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Stack on entry:
|
2011-02-22 09:35:37 +00:00
|
|
|
// sp[0]: second argument (right).
|
|
|
|
// sp[4]: first argument (left).
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Load the two arguments.
|
|
|
|
__ ldr(r0, MemOperand(sp, 1 * kPointerSize)); // First argument.
|
|
|
|
__ ldr(r1, MemOperand(sp, 0 * kPointerSize)); // Second argument.
|
|
|
|
|
|
|
|
// Make sure that both arguments are strings if not known in advance.
|
2011-02-22 09:35:37 +00:00
|
|
|
if (flags_ == NO_STRING_ADD_FLAGS) {
|
2011-12-15 11:04:58 +00:00
|
|
|
__ JumpIfEitherSmi(r0, r1, &call_runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Load instance types.
|
|
|
|
__ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset));
|
|
|
|
__ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
|
|
|
|
__ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset));
|
|
|
|
STATIC_ASSERT(kStringTag == 0);
|
|
|
|
// If either is not a string, go to runtime.
|
|
|
|
__ tst(r4, Operand(kIsNotStringMask));
|
|
|
|
__ tst(r5, Operand(kIsNotStringMask), eq);
|
2011-12-15 11:04:58 +00:00
|
|
|
__ b(ne, &call_runtime);
|
2011-02-22 09:35:37 +00:00
|
|
|
} else {
|
|
|
|
// Here at least one of the arguments is definitely a string.
|
|
|
|
// We convert the one that is not known to be a string.
|
|
|
|
if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) {
|
|
|
|
ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0);
|
|
|
|
GenerateConvertArgument(
|
|
|
|
masm, 1 * kPointerSize, r0, r2, r3, r4, r5, &call_builtin);
|
|
|
|
builtin_id = Builtins::STRING_ADD_RIGHT;
|
|
|
|
} else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) {
|
|
|
|
ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0);
|
|
|
|
GenerateConvertArgument(
|
|
|
|
masm, 0 * kPointerSize, r1, r2, r3, r4, r5, &call_builtin);
|
|
|
|
builtin_id = Builtins::STRING_ADD_LEFT;
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Both arguments are strings.
|
|
|
|
// r0: first string
|
|
|
|
// r1: second string
|
2011-02-22 09:35:37 +00:00
|
|
|
// r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS)
|
|
|
|
// r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS)
|
2010-08-25 09:44:44 +00:00
|
|
|
{
|
|
|
|
Label strings_not_empty;
|
|
|
|
// Check if either of the strings are empty. In that case return the other.
|
|
|
|
__ ldr(r2, FieldMemOperand(r0, String::kLengthOffset));
|
|
|
|
__ ldr(r3, FieldMemOperand(r1, String::kLengthOffset));
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ cmp(r2, Operand(Smi::FromInt(0))); // Test if first string is empty.
|
|
|
|
__ mov(r0, Operand(r1), LeaveCC, eq); // If first is empty, return second.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
// Else test if second string is empty.
|
|
|
|
__ cmp(r3, Operand(Smi::FromInt(0)), ne);
|
|
|
|
__ b(ne, &strings_not_empty); // If either string was empty, return r0.
|
|
|
|
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_add_native(), 1, r2, r3);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ add(sp, sp, Operand(2 * kPointerSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&strings_not_empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ mov(r2, Operand(r2, ASR, kSmiTagSize));
|
|
|
|
__ mov(r3, Operand(r3, ASR, kSmiTagSize));
|
|
|
|
// Both strings are non-empty.
|
|
|
|
// r0: first string
|
|
|
|
// r1: second string
|
|
|
|
// r2: length of first string
|
|
|
|
// r3: length of second string
|
2011-02-22 09:35:37 +00:00
|
|
|
// r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS)
|
|
|
|
// r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS)
|
2010-08-25 09:44:44 +00:00
|
|
|
// Look at the length of the result of adding the two strings.
|
|
|
|
Label string_add_flat_result, longer_than_two;
|
|
|
|
// Adding two lengths can't overflow.
|
|
|
|
STATIC_ASSERT(String::kMaxLength < String::kMaxLength * 2);
|
|
|
|
__ add(r6, r2, Operand(r3));
|
2013-02-28 17:03:34 +00:00
|
|
|
// Use the string table when adding two one character strings, as it
|
|
|
|
// helps later optimizations to return a string here.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmp(r6, Operand(2));
|
|
|
|
__ b(ne, &longer_than_two);
|
|
|
|
|
2011-03-15 10:03:57 +00:00
|
|
|
// Check that both strings are non-external ASCII strings.
|
2011-02-22 09:35:37 +00:00
|
|
|
if (flags_ != NO_STRING_ADD_FLAGS) {
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset));
|
|
|
|
__ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
|
|
|
|
__ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset));
|
|
|
|
}
|
|
|
|
__ JumpIfBothInstanceTypesAreNotSequentialAscii(r4, r5, r6, r7,
|
2011-12-15 11:04:58 +00:00
|
|
|
&call_runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Get the two characters forming the sub string.
|
2012-11-15 13:31:27 +00:00
|
|
|
__ ldrb(r2, FieldMemOperand(r0, SeqOneByteString::kHeaderSize));
|
|
|
|
__ ldrb(r3, FieldMemOperand(r1, SeqOneByteString::kHeaderSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Try to lookup two character string in string table. If it is not found
|
2010-08-25 09:44:44 +00:00
|
|
|
// just allocate a new one.
|
|
|
|
Label make_two_character_string;
|
2013-02-28 17:03:34 +00:00
|
|
|
StringHelper::GenerateTwoCharacterStringTableProbe(
|
2010-08-25 09:44:44 +00:00
|
|
|
masm, r2, r3, r6, r7, r4, r5, r9, &make_two_character_string);
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_add_native(), 1, r2, r3);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ add(sp, sp, Operand(2 * kPointerSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&make_two_character_string);
|
|
|
|
// Resulting string has length 2 and first chars of two strings
|
|
|
|
// are combined into single halfword in r2 register.
|
|
|
|
// So we can fill resulting string without two loops by a single
|
|
|
|
// halfword store instruction (which assumes that processor is
|
|
|
|
// in a little endian mode)
|
|
|
|
__ mov(r6, Operand(2));
|
2011-12-15 11:04:58 +00:00
|
|
|
__ AllocateAsciiString(r0, r6, r4, r5, r9, &call_runtime);
|
2012-11-15 13:31:27 +00:00
|
|
|
__ strh(r2, FieldMemOperand(r0, SeqOneByteString::kHeaderSize));
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_add_native(), 1, r2, r3);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ add(sp, sp, Operand(2 * kPointerSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&longer_than_two);
|
|
|
|
// Check if resulting string will be flat.
|
2012-01-17 14:29:17 +00:00
|
|
|
__ cmp(r6, Operand(ConsString::kMinLength));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(lt, &string_add_flat_result);
|
|
|
|
// Handle exceptionally long strings in the runtime system.
|
|
|
|
STATIC_ASSERT((String::kMaxLength & 0x80000000) == 0);
|
|
|
|
ASSERT(IsPowerOf2(String::kMaxLength + 1));
|
|
|
|
// kMaxLength + 1 is representable as shifted literal, kMaxLength is not.
|
|
|
|
__ cmp(r6, Operand(String::kMaxLength + 1));
|
2011-12-15 11:04:58 +00:00
|
|
|
__ b(hs, &call_runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// If result is not supposed to be flat, allocate a cons string object.
|
2011-03-15 10:03:57 +00:00
|
|
|
// If both strings are ASCII the result is an ASCII cons string.
|
2011-02-22 09:35:37 +00:00
|
|
|
if (flags_ != NO_STRING_ADD_FLAGS) {
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset));
|
|
|
|
__ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
|
|
|
|
__ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset));
|
|
|
|
}
|
|
|
|
Label non_ascii, allocated, ascii_data;
|
|
|
|
STATIC_ASSERT(kTwoByteStringTag == 0);
|
|
|
|
__ tst(r4, Operand(kStringEncodingMask));
|
|
|
|
__ tst(r5, Operand(kStringEncodingMask), ne);
|
|
|
|
__ b(eq, &non_ascii);
|
|
|
|
|
|
|
|
// Allocate an ASCII cons string.
|
|
|
|
__ bind(&ascii_data);
|
2011-12-15 11:04:58 +00:00
|
|
|
__ AllocateAsciiConsString(r7, r6, r4, r5, &call_runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&allocated);
|
|
|
|
// Fill the fields of the cons string.
|
|
|
|
__ str(r0, FieldMemOperand(r7, ConsString::kFirstOffset));
|
|
|
|
__ str(r1, FieldMemOperand(r7, ConsString::kSecondOffset));
|
|
|
|
__ mov(r0, Operand(r7));
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_add_native(), 1, r2, r3);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ add(sp, sp, Operand(2 * kPointerSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&non_ascii);
|
|
|
|
// At least one of the strings is two-byte. Check whether it happens
|
2013-04-26 11:34:44 +00:00
|
|
|
// to contain only one byte characters.
|
2010-08-25 09:44:44 +00:00
|
|
|
// r4: first instance type.
|
|
|
|
// r5: second instance type.
|
2013-04-26 11:34:44 +00:00
|
|
|
__ tst(r4, Operand(kOneByteDataHintMask));
|
|
|
|
__ tst(r5, Operand(kOneByteDataHintMask), ne);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(ne, &ascii_data);
|
2013-01-14 15:17:56 +00:00
|
|
|
__ eor(r4, r4, Operand(r5));
|
2013-04-26 11:34:44 +00:00
|
|
|
STATIC_ASSERT(kOneByteStringTag != 0 && kOneByteDataHintTag != 0);
|
|
|
|
__ and_(r4, r4, Operand(kOneByteStringTag | kOneByteDataHintTag));
|
|
|
|
__ cmp(r4, Operand(kOneByteStringTag | kOneByteDataHintTag));
|
2013-01-14 15:17:56 +00:00
|
|
|
__ b(eq, &ascii_data);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Allocate a two byte cons string.
|
2011-12-15 11:04:58 +00:00
|
|
|
__ AllocateTwoByteConsString(r7, r6, r4, r5, &call_runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ jmp(&allocated);
|
|
|
|
|
2011-12-15 11:04:58 +00:00
|
|
|
// We cannot encounter sliced strings or cons strings here since:
|
2012-01-17 14:29:17 +00:00
|
|
|
STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength);
|
2011-12-15 11:04:58 +00:00
|
|
|
// Handle creating a flat result from either external or sequential strings.
|
|
|
|
// Locate the first characters' locations.
|
2010-08-25 09:44:44 +00:00
|
|
|
// r0: first string
|
|
|
|
// r1: second string
|
|
|
|
// r2: length of first string
|
|
|
|
// r3: length of second string
|
2011-02-22 09:35:37 +00:00
|
|
|
// r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS)
|
|
|
|
// r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS)
|
2010-08-25 09:44:44 +00:00
|
|
|
// r6: sum of lengths.
|
2011-12-15 11:04:58 +00:00
|
|
|
Label first_prepared, second_prepared;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&string_add_flat_result);
|
2011-02-22 09:35:37 +00:00
|
|
|
if (flags_ != NO_STRING_ADD_FLAGS) {
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset));
|
|
|
|
__ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
|
|
|
|
__ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset));
|
|
|
|
}
|
2011-12-15 11:04:58 +00:00
|
|
|
|
|
|
|
// Check whether both strings have same encoding
|
|
|
|
__ eor(r7, r4, Operand(r5));
|
|
|
|
__ tst(r7, Operand(kStringEncodingMask));
|
|
|
|
__ b(ne, &call_runtime);
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT(kSeqStringTag == 0);
|
|
|
|
__ tst(r4, Operand(kStringRepresentationMask));
|
2012-11-15 13:31:27 +00:00
|
|
|
STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize);
|
2011-12-15 11:04:58 +00:00
|
|
|
__ add(r7,
|
|
|
|
r0,
|
2012-11-15 13:31:27 +00:00
|
|
|
Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag),
|
2011-12-15 11:04:58 +00:00
|
|
|
LeaveCC,
|
|
|
|
eq);
|
|
|
|
__ b(eq, &first_prepared);
|
|
|
|
// External string: rule out short external string and load string resource.
|
|
|
|
STATIC_ASSERT(kShortExternalStringTag != 0);
|
|
|
|
__ tst(r4, Operand(kShortExternalStringMask));
|
|
|
|
__ b(ne, &call_runtime);
|
|
|
|
__ ldr(r7, FieldMemOperand(r0, ExternalString::kResourceDataOffset));
|
|
|
|
__ bind(&first_prepared);
|
|
|
|
|
|
|
|
STATIC_ASSERT(kSeqStringTag == 0);
|
|
|
|
__ tst(r5, Operand(kStringRepresentationMask));
|
2012-11-15 13:31:27 +00:00
|
|
|
STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize);
|
2011-12-15 11:04:58 +00:00
|
|
|
__ add(r1,
|
|
|
|
r1,
|
2012-11-15 13:31:27 +00:00
|
|
|
Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag),
|
2011-12-15 11:04:58 +00:00
|
|
|
LeaveCC,
|
|
|
|
eq);
|
|
|
|
__ b(eq, &second_prepared);
|
|
|
|
// External string: rule out short external string and load string resource.
|
|
|
|
STATIC_ASSERT(kShortExternalStringTag != 0);
|
|
|
|
__ tst(r5, Operand(kShortExternalStringMask));
|
|
|
|
__ b(ne, &call_runtime);
|
|
|
|
__ ldr(r1, FieldMemOperand(r1, ExternalString::kResourceDataOffset));
|
|
|
|
__ bind(&second_prepared);
|
|
|
|
|
|
|
|
Label non_ascii_string_add_flat_result;
|
|
|
|
// r7: first character of first string
|
|
|
|
// r1: first character of second string
|
2010-08-25 09:44:44 +00:00
|
|
|
// r2: length of first string.
|
|
|
|
// r3: length of second string.
|
2011-12-15 11:04:58 +00:00
|
|
|
// r6: sum of lengths.
|
|
|
|
// Both strings have the same encoding.
|
|
|
|
STATIC_ASSERT(kTwoByteStringTag == 0);
|
|
|
|
__ tst(r5, Operand(kStringEncodingMask));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ b(eq, &non_ascii_string_add_flat_result);
|
|
|
|
|
2011-12-15 11:04:58 +00:00
|
|
|
__ AllocateAsciiString(r0, r6, r4, r5, r9, &call_runtime);
|
2012-11-15 13:31:27 +00:00
|
|
|
__ add(r6, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
|
2011-12-15 11:04:58 +00:00
|
|
|
// r0: result string.
|
|
|
|
// r7: first character of first string.
|
|
|
|
// r1: first character of second string.
|
2010-08-25 09:44:44 +00:00
|
|
|
// r2: length of first string.
|
|
|
|
// r3: length of second string.
|
|
|
|
// r6: first character of result.
|
2011-12-15 11:04:58 +00:00
|
|
|
StringHelper::GenerateCopyCharacters(masm, r6, r7, r2, r4, true);
|
2010-08-25 09:44:44 +00:00
|
|
|
// r6: next character of result.
|
|
|
|
StringHelper::GenerateCopyCharacters(masm, r6, r1, r3, r4, true);
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_add_native(), 1, r2, r3);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ add(sp, sp, Operand(2 * kPointerSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&non_ascii_string_add_flat_result);
|
2011-12-15 11:04:58 +00:00
|
|
|
__ AllocateTwoByteString(r0, r6, r4, r5, r9, &call_runtime);
|
|
|
|
__ add(r6, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
|
|
|
|
// r0: result string.
|
|
|
|
// r7: first character of first string.
|
|
|
|
// r1: first character of second string.
|
2010-08-25 09:44:44 +00:00
|
|
|
// r2: length of first string.
|
|
|
|
// r3: length of second string.
|
|
|
|
// r6: first character of result.
|
2011-12-15 11:04:58 +00:00
|
|
|
StringHelper::GenerateCopyCharacters(masm, r6, r7, r2, r4, false);
|
|
|
|
// r6: next character of result.
|
2010-08-25 09:44:44 +00:00
|
|
|
StringHelper::GenerateCopyCharacters(masm, r6, r1, r3, r4, false);
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_add_native(), 1, r2, r3);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ add(sp, sp, Operand(2 * kPointerSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Just jump to runtime to add the two strings.
|
2011-12-15 11:04:58 +00:00
|
|
|
__ bind(&call_runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ TailCallRuntime(Runtime::kStringAdd, 2, 1);
|
2011-02-22 09:35:37 +00:00
|
|
|
|
|
|
|
if (call_builtin.is_linked()) {
|
|
|
|
__ bind(&call_builtin);
|
2011-04-29 20:07:41 +00:00
|
|
|
__ InvokeBuiltin(builtin_id, JUMP_FUNCTION);
|
2011-02-22 09:35:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringAddStub::GenerateConvertArgument(MacroAssembler* masm,
|
|
|
|
int stack_offset,
|
|
|
|
Register arg,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register scratch3,
|
|
|
|
Register scratch4,
|
|
|
|
Label* slow) {
|
|
|
|
// First check if the argument is already a string.
|
|
|
|
Label not_string, done;
|
|
|
|
__ JumpIfSmi(arg, ¬_string);
|
|
|
|
__ CompareObjectType(arg, scratch1, scratch1, FIRST_NONSTRING_TYPE);
|
|
|
|
__ b(lt, &done);
|
|
|
|
|
|
|
|
// Check the number to string cache.
|
|
|
|
Label not_cached;
|
|
|
|
__ bind(¬_string);
|
|
|
|
// Puts the cached result into scratch1.
|
|
|
|
NumberToStringStub::GenerateLookupNumberStringCache(masm,
|
|
|
|
arg,
|
|
|
|
scratch1,
|
|
|
|
scratch2,
|
|
|
|
scratch3,
|
|
|
|
scratch4,
|
|
|
|
false,
|
|
|
|
¬_cached);
|
|
|
|
__ mov(arg, scratch1);
|
|
|
|
__ str(arg, MemOperand(sp, stack_offset));
|
|
|
|
__ jmp(&done);
|
|
|
|
|
|
|
|
// Check if the argument is a safe string wrapper.
|
|
|
|
__ bind(¬_cached);
|
|
|
|
__ JumpIfSmi(arg, slow);
|
|
|
|
__ CompareObjectType(
|
|
|
|
arg, scratch1, scratch2, JS_VALUE_TYPE); // map -> scratch1.
|
|
|
|
__ b(ne, slow);
|
|
|
|
__ ldrb(scratch2, FieldMemOperand(scratch1, Map::kBitField2Offset));
|
|
|
|
__ and_(scratch2,
|
|
|
|
scratch2, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf));
|
|
|
|
__ cmp(scratch2,
|
|
|
|
Operand(1 << Map::kStringWrapperSafeForDefaultValueOf));
|
|
|
|
__ b(ne, slow);
|
|
|
|
__ ldr(arg, FieldMemOperand(arg, JSValue::kValueOffset));
|
|
|
|
__ str(arg, MemOperand(sp, stack_offset));
|
|
|
|
|
|
|
|
__ bind(&done);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void ICCompareStub::GenerateSmis(MacroAssembler* masm) {
|
2012-11-14 15:59:45 +00:00
|
|
|
ASSERT(state_ == CompareIC::SMI);
|
2010-12-07 11:31:57 +00:00
|
|
|
Label miss;
|
|
|
|
__ orr(r2, r1, r0);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(r2, &miss);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
if (GetCondition() == eq) {
|
|
|
|
// For equality we do not care about the sign of the result.
|
|
|
|
__ sub(r0, r0, r1, SetCC);
|
|
|
|
} else {
|
2011-02-09 14:57:24 +00:00
|
|
|
// Untag before subtracting to avoid handling overflow.
|
|
|
|
__ SmiUntag(r1);
|
|
|
|
__ sub(r0, r1, SmiUntagOperand(r0));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 14:43:57 +00:00
|
|
|
void ICCompareStub::GenerateNumbers(MacroAssembler* masm) {
|
|
|
|
ASSERT(state_ == CompareIC::NUMBER);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
Label generic_stub;
|
2012-03-02 13:40:14 +00:00
|
|
|
Label unordered, maybe_undefined1, maybe_undefined2;
|
2010-12-07 11:31:57 +00:00
|
|
|
Label miss;
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
if (left_ == CompareIC::SMI) {
|
|
|
|
__ JumpIfNotSmi(r1, &miss);
|
|
|
|
}
|
|
|
|
if (right_ == CompareIC::SMI) {
|
|
|
|
__ JumpIfNotSmi(r0, &miss);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Inlining the double comparison and falling back to the general compare
|
2013-04-07 04:34:20 +00:00
|
|
|
// stub if NaN is involved.
|
|
|
|
// Load left and right operand.
|
|
|
|
Label done, left, left_smi, right_smi;
|
|
|
|
__ JumpIfSmi(r0, &right_smi);
|
|
|
|
__ CheckMap(r0, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined1,
|
|
|
|
DONT_DO_SMI_CHECK);
|
|
|
|
__ sub(r2, r0, Operand(kHeapObjectTag));
|
|
|
|
__ vldr(d1, r2, HeapNumber::kValueOffset);
|
|
|
|
__ b(&left);
|
|
|
|
__ bind(&right_smi);
|
|
|
|
__ SmiUntag(r2, r0); // Can't clobber r0 yet.
|
|
|
|
SwVfpRegister single_scratch = d2.low();
|
|
|
|
__ vmov(single_scratch, r2);
|
|
|
|
__ vcvt_f64_s32(d1, single_scratch);
|
|
|
|
|
|
|
|
__ bind(&left);
|
|
|
|
__ JumpIfSmi(r1, &left_smi);
|
|
|
|
__ CheckMap(r1, r2, Heap::kHeapNumberMapRootIndex, &maybe_undefined2,
|
|
|
|
DONT_DO_SMI_CHECK);
|
|
|
|
__ sub(r2, r1, Operand(kHeapObjectTag));
|
|
|
|
__ vldr(d0, r2, HeapNumber::kValueOffset);
|
|
|
|
__ b(&done);
|
|
|
|
__ bind(&left_smi);
|
|
|
|
__ SmiUntag(r2, r1); // Can't clobber r1 yet.
|
|
|
|
single_scratch = d3.low();
|
|
|
|
__ vmov(single_scratch, r2);
|
|
|
|
__ vcvt_f64_s32(d0, single_scratch);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-04-07 04:34:20 +00:00
|
|
|
__ bind(&done);
|
|
|
|
// Compare operands.
|
|
|
|
__ VFPCompareAndSetFlags(d0, d1);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-04-07 04:34:20 +00:00
|
|
|
// Don't base result on status bits when a NaN is involved.
|
|
|
|
__ b(vs, &unordered);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-04-07 04:34:20 +00:00
|
|
|
// Return a result of -1, 0, or 1, based on status bits.
|
|
|
|
__ mov(r0, Operand(EQUAL), LeaveCC, eq);
|
|
|
|
__ mov(r0, Operand(LESS), LeaveCC, lt);
|
|
|
|
__ mov(r0, Operand(GREATER), LeaveCC, gt);
|
|
|
|
__ Ret();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-03-02 13:40:14 +00:00
|
|
|
__ bind(&unordered);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ bind(&generic_stub);
|
2012-11-14 15:59:45 +00:00
|
|
|
ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC,
|
|
|
|
CompareIC::GENERIC);
|
2013-02-27 12:33:24 +00:00
|
|
|
__ Jump(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-03-02 13:40:14 +00:00
|
|
|
__ bind(&maybe_undefined1);
|
|
|
|
if (Token::IsOrderedRelationalCompareOp(op_)) {
|
|
|
|
__ CompareRoot(r0, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ b(ne, &miss);
|
2012-11-14 15:59:45 +00:00
|
|
|
__ JumpIfSmi(r1, &unordered);
|
2012-03-02 13:40:14 +00:00
|
|
|
__ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE);
|
|
|
|
__ b(ne, &maybe_undefined2);
|
|
|
|
__ jmp(&unordered);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&maybe_undefined2);
|
|
|
|
if (Token::IsOrderedRelationalCompareOp(op_)) {
|
|
|
|
__ CompareRoot(r1, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ b(eq, &unordered);
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) {
|
|
|
|
ASSERT(state_ == CompareIC::INTERNALIZED_STRING);
|
2011-05-09 13:30:04 +00:00
|
|
|
Label miss;
|
|
|
|
|
|
|
|
// Registers containing left and right operands respectively.
|
|
|
|
Register left = r1;
|
|
|
|
Register right = r0;
|
|
|
|
Register tmp1 = r2;
|
|
|
|
Register tmp2 = r3;
|
|
|
|
|
|
|
|
// Check that both operands are heap objects.
|
|
|
|
__ JumpIfEitherSmi(left, right, &miss);
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Check that both operands are internalized strings.
|
2011-05-09 13:30:04 +00:00
|
|
|
__ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
|
|
|
|
__ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
|
|
|
|
__ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
|
2013-02-28 17:03:34 +00:00
|
|
|
STATIC_ASSERT(kInternalizedTag != 0);
|
2011-05-09 13:30:04 +00:00
|
|
|
__ and_(tmp1, tmp1, Operand(tmp2));
|
2013-02-28 17:03:34 +00:00
|
|
|
__ tst(tmp1, Operand(kIsInternalizedMask));
|
2011-05-09 13:30:04 +00:00
|
|
|
__ b(eq, &miss);
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Internalized strings are compared by identity.
|
2011-05-09 13:30:04 +00:00
|
|
|
__ cmp(left, right);
|
2013-03-01 13:28:55 +00:00
|
|
|
// Make sure r0 is non-zero. At this point input operands are
|
|
|
|
// guaranteed to be non-zero.
|
|
|
|
ASSERT(right.is(r0));
|
|
|
|
STATIC_ASSERT(EQUAL == 0);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) {
|
|
|
|
ASSERT(state_ == CompareIC::UNIQUE_NAME);
|
|
|
|
ASSERT(GetCondition() == eq);
|
|
|
|
Label miss;
|
|
|
|
|
|
|
|
// Registers containing left and right operands respectively.
|
|
|
|
Register left = r1;
|
|
|
|
Register right = r0;
|
|
|
|
Register tmp1 = r2;
|
|
|
|
Register tmp2 = r3;
|
|
|
|
|
|
|
|
// Check that both operands are heap objects.
|
|
|
|
__ JumpIfEitherSmi(left, right, &miss);
|
|
|
|
|
|
|
|
// Check that both operands are unique names. This leaves the instance
|
|
|
|
// types loaded in tmp1 and tmp2.
|
|
|
|
STATIC_ASSERT(kInternalizedTag != 0);
|
|
|
|
__ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
|
|
|
|
__ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
|
|
|
|
__ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
|
|
|
|
|
|
|
|
Label succeed1;
|
|
|
|
__ tst(tmp1, Operand(kIsInternalizedMask));
|
|
|
|
__ b(ne, &succeed1);
|
|
|
|
__ cmp(tmp1, Operand(SYMBOL_TYPE));
|
|
|
|
__ b(ne, &miss);
|
|
|
|
__ bind(&succeed1);
|
|
|
|
|
|
|
|
Label succeed2;
|
|
|
|
__ tst(tmp2, Operand(kIsInternalizedMask));
|
|
|
|
__ b(ne, &succeed2);
|
|
|
|
__ cmp(tmp2, Operand(SYMBOL_TYPE));
|
|
|
|
__ b(ne, &miss);
|
|
|
|
__ bind(&succeed2);
|
|
|
|
|
|
|
|
// Unique names are compared by identity.
|
|
|
|
__ cmp(left, right);
|
2011-05-09 13:30:04 +00:00
|
|
|
// Make sure r0 is non-zero. At this point input operands are
|
|
|
|
// guaranteed to be non-zero.
|
|
|
|
ASSERT(right.is(r0));
|
|
|
|
STATIC_ASSERT(EQUAL == 0);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-04 18:30:37 +00:00
|
|
|
void ICCompareStub::GenerateStrings(MacroAssembler* masm) {
|
2012-11-14 15:59:45 +00:00
|
|
|
ASSERT(state_ == CompareIC::STRING);
|
2011-05-04 18:30:37 +00:00
|
|
|
Label miss;
|
|
|
|
|
2012-03-09 13:12:59 +00:00
|
|
|
bool equality = Token::IsEqualityOp(op_);
|
|
|
|
|
2011-05-04 18:30:37 +00:00
|
|
|
// Registers containing left and right operands respectively.
|
|
|
|
Register left = r1;
|
|
|
|
Register right = r0;
|
|
|
|
Register tmp1 = r2;
|
|
|
|
Register tmp2 = r3;
|
|
|
|
Register tmp3 = r4;
|
|
|
|
Register tmp4 = r5;
|
|
|
|
|
|
|
|
// Check that both operands are heap objects.
|
|
|
|
__ JumpIfEitherSmi(left, right, &miss);
|
|
|
|
|
|
|
|
// Check that both operands are strings. This leaves the instance
|
|
|
|
// types loaded in tmp1 and tmp2.
|
|
|
|
__ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
|
|
|
|
__ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
|
|
|
|
__ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
|
|
|
|
STATIC_ASSERT(kNotStringTag != 0);
|
|
|
|
__ orr(tmp3, tmp1, tmp2);
|
|
|
|
__ tst(tmp3, Operand(kIsNotStringMask));
|
|
|
|
__ b(ne, &miss);
|
|
|
|
|
|
|
|
// Fast check for identical strings.
|
|
|
|
__ cmp(left, right);
|
|
|
|
STATIC_ASSERT(EQUAL == 0);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
|
|
|
|
__ Ret(eq);
|
|
|
|
|
|
|
|
// Handle not identical strings.
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Check that both strings are internalized strings. If they are, we're done
|
2011-05-04 18:30:37 +00:00
|
|
|
// because we already know they are not identical.
|
2012-03-09 13:12:59 +00:00
|
|
|
if (equality) {
|
|
|
|
ASSERT(GetCondition() == eq);
|
2013-02-28 17:03:34 +00:00
|
|
|
STATIC_ASSERT(kInternalizedTag != 0);
|
2012-03-09 13:12:59 +00:00
|
|
|
__ and_(tmp3, tmp1, Operand(tmp2));
|
2013-02-28 17:03:34 +00:00
|
|
|
__ tst(tmp3, Operand(kIsInternalizedMask));
|
2012-03-09 13:12:59 +00:00
|
|
|
// Make sure r0 is non-zero. At this point input operands are
|
|
|
|
// guaranteed to be non-zero.
|
|
|
|
ASSERT(right.is(r0));
|
|
|
|
__ Ret(ne);
|
|
|
|
}
|
2011-05-04 18:30:37 +00:00
|
|
|
|
|
|
|
// Check that both strings are sequential ASCII.
|
|
|
|
Label runtime;
|
2012-03-09 13:12:59 +00:00
|
|
|
__ JumpIfBothInstanceTypesAreNotSequentialAscii(
|
|
|
|
tmp1, tmp2, tmp3, tmp4, &runtime);
|
2011-05-04 18:30:37 +00:00
|
|
|
|
|
|
|
// Compare flat ASCII strings. Returns when done.
|
2012-03-09 13:12:59 +00:00
|
|
|
if (equality) {
|
|
|
|
StringCompareStub::GenerateFlatAsciiStringEquals(
|
|
|
|
masm, left, right, tmp1, tmp2, tmp3);
|
|
|
|
} else {
|
|
|
|
StringCompareStub::GenerateCompareFlatAsciiStrings(
|
|
|
|
masm, left, right, tmp1, tmp2, tmp3, tmp4);
|
|
|
|
}
|
2011-05-04 18:30:37 +00:00
|
|
|
|
|
|
|
// Handle more complex cases in runtime.
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ Push(left, right);
|
2012-03-09 13:12:59 +00:00
|
|
|
if (equality) {
|
|
|
|
__ TailCallRuntime(Runtime::kStringEquals, 2, 1);
|
|
|
|
} else {
|
|
|
|
__ TailCallRuntime(Runtime::kStringCompare, 2, 1);
|
|
|
|
}
|
2011-05-04 18:30:37 +00:00
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void ICCompareStub::GenerateObjects(MacroAssembler* masm) {
|
2012-11-14 15:59:45 +00:00
|
|
|
ASSERT(state_ == CompareIC::OBJECT);
|
2010-12-07 11:31:57 +00:00
|
|
|
Label miss;
|
|
|
|
__ and_(r2, r1, Operand(r0));
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(r2, &miss);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
__ CompareObjectType(r0, r2, r2, JS_OBJECT_TYPE);
|
|
|
|
__ b(ne, &miss);
|
|
|
|
__ CompareObjectType(r1, r2, r2, JS_OBJECT_TYPE);
|
|
|
|
__ b(ne, &miss);
|
|
|
|
|
|
|
|
ASSERT(GetCondition() == eq);
|
|
|
|
__ sub(r0, r0, Operand(r1));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-09 09:26:14 +00:00
|
|
|
void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) {
|
|
|
|
Label miss;
|
|
|
|
__ and_(r2, r1, Operand(r0));
|
|
|
|
__ JumpIfSmi(r2, &miss);
|
|
|
|
__ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
|
|
|
|
__ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
|
|
|
|
__ cmp(r2, Operand(known_map_));
|
|
|
|
__ b(ne, &miss);
|
|
|
|
__ cmp(r3, Operand(known_map_));
|
|
|
|
__ b(ne, &miss);
|
|
|
|
|
|
|
|
__ sub(r0, r0, Operand(r1));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-12-09 09:26:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ICCompareStub::GenerateMiss(MacroAssembler* masm) {
|
2011-09-15 11:30:45 +00:00
|
|
|
{
|
2011-12-09 09:26:14 +00:00
|
|
|
// Call the runtime system in a fresh internal frame.
|
|
|
|
ExternalReference miss =
|
|
|
|
ExternalReference(IC_Utility(IC::kCompareIC_Miss), masm->isolate());
|
|
|
|
|
2011-09-15 11:30:45 +00:00
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
|
|
|
__ Push(r1, r0);
|
2011-12-09 09:26:14 +00:00
|
|
|
__ push(lr);
|
|
|
|
__ Push(r1, r0);
|
2011-09-15 11:30:45 +00:00
|
|
|
__ mov(ip, Operand(Smi::FromInt(op_)));
|
|
|
|
__ push(ip);
|
|
|
|
__ CallExternalReference(miss, 3);
|
2011-12-09 09:26:14 +00:00
|
|
|
// Compute the entry point of the rewritten stub.
|
|
|
|
__ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag));
|
|
|
|
// Restore registers.
|
|
|
|
__ pop(lr);
|
|
|
|
__ pop(r0);
|
|
|
|
__ pop(r1);
|
2011-09-15 11:30:45 +00:00
|
|
|
}
|
2011-12-09 09:26:14 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
__ Jump(r2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-04 13:43:38 +00:00
|
|
|
void DirectCEntryStub::Generate(MacroAssembler* masm) {
|
|
|
|
__ ldr(pc, MemOperand(sp, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
|
2011-02-24 15:39:09 +00:00
|
|
|
ExternalReference function) {
|
|
|
|
__ mov(r2, Operand(function));
|
2011-08-16 09:58:34 +00:00
|
|
|
GenerateCall(masm, r2);
|
2011-02-04 13:43:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-15 13:53:51 +00:00
|
|
|
void DirectCEntryStub::GenerateCall(MacroAssembler* masm,
|
|
|
|
Register target) {
|
2013-02-27 12:33:24 +00:00
|
|
|
intptr_t code =
|
|
|
|
reinterpret_cast<intptr_t>(GetCode(masm->isolate()).location());
|
|
|
|
__ mov(lr, Operand(code, RelocInfo::CODE_TARGET));
|
2012-06-12 17:26:28 +00:00
|
|
|
|
|
|
|
// Prevent literal pool emission during calculation of return address.
|
|
|
|
Assembler::BlockConstPoolScope block_const_pool(masm);
|
|
|
|
|
2011-02-15 13:53:51 +00:00
|
|
|
// Push return address (accessible to GC through exit frame pc).
|
2011-08-12 08:45:17 +00:00
|
|
|
// Note that using pc with str is deprecated.
|
2011-08-16 09:58:34 +00:00
|
|
|
Label start;
|
|
|
|
__ bind(&start);
|
|
|
|
__ add(ip, pc, Operand(Assembler::kInstrSize));
|
2011-08-12 08:45:17 +00:00
|
|
|
__ str(ip, MemOperand(sp, 0));
|
2011-02-15 13:53:51 +00:00
|
|
|
__ Jump(target); // Call the C++ function.
|
2011-08-16 09:58:34 +00:00
|
|
|
ASSERT_EQ(Assembler::kInstrSize + Assembler::kPcLoadDelta,
|
|
|
|
masm->SizeOfCodeGeneratedSince(&start));
|
2013-04-15 15:55:47 +00:00
|
|
|
__ VFPEnsureFPSCRState(r2);
|
2011-02-15 13:53:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
|
|
|
|
Label* miss,
|
|
|
|
Label* done,
|
|
|
|
Register receiver,
|
|
|
|
Register properties,
|
|
|
|
Handle<Name> name,
|
|
|
|
Register scratch0) {
|
|
|
|
ASSERT(name->IsUniqueName());
|
2011-10-25 09:24:49 +00:00
|
|
|
// If names of slots in range from 1 to kProbes - 1 for the hash value are
|
|
|
|
// not equal to the name and kProbes-th slot is not used (its name is the
|
|
|
|
// undefined value), it guarantees the hash table doesn't contain the
|
|
|
|
// property. It's true even if some slots represent deleted properties
|
2012-02-28 08:32:44 +00:00
|
|
|
// (their names are the hole value).
|
2011-10-25 09:24:49 +00:00
|
|
|
for (int i = 0; i < kInlinedProbes; i++) {
|
|
|
|
// scratch0 points to properties hash.
|
|
|
|
// Compute the masked index: (hash + i + i * i) & mask.
|
|
|
|
Register index = scratch0;
|
|
|
|
// Capacity is smi 2^n.
|
|
|
|
__ ldr(index, FieldMemOperand(properties, kCapacityOffset));
|
|
|
|
__ sub(index, index, Operand(1));
|
|
|
|
__ and_(index, index, Operand(
|
2013-03-04 15:00:57 +00:00
|
|
|
Smi::FromInt(name->Hash() + NameDictionary::GetProbeOffset(i))));
|
2011-10-25 09:24:49 +00:00
|
|
|
|
|
|
|
// Scale the index by multiplying by the entry size.
|
2013-03-04 15:00:57 +00:00
|
|
|
ASSERT(NameDictionary::kEntrySize == 3);
|
2011-10-25 09:24:49 +00:00
|
|
|
__ add(index, index, Operand(index, LSL, 1)); // index *= 3.
|
|
|
|
|
|
|
|
Register entity_name = scratch0;
|
|
|
|
// Having undefined at this place means the name is not contained.
|
|
|
|
ASSERT_EQ(kSmiTagSize, 1);
|
|
|
|
Register tmp = properties;
|
|
|
|
__ add(tmp, properties, Operand(index, LSL, 1));
|
|
|
|
__ ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset));
|
|
|
|
|
|
|
|
ASSERT(!tmp.is(entity_name));
|
|
|
|
__ LoadRoot(tmp, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ cmp(entity_name, tmp);
|
|
|
|
__ b(eq, done);
|
|
|
|
|
2013-03-26 09:28:26 +00:00
|
|
|
// Load the hole ready for use below:
|
|
|
|
__ LoadRoot(tmp, Heap::kTheHoleValueRootIndex);
|
|
|
|
|
|
|
|
// Stop if found the property.
|
|
|
|
__ cmp(entity_name, Operand(Handle<Name>(name)));
|
|
|
|
__ b(eq, miss);
|
|
|
|
|
|
|
|
Label good;
|
|
|
|
__ cmp(entity_name, tmp);
|
|
|
|
__ b(eq, &good);
|
|
|
|
|
|
|
|
// Check if the entry name is not a unique name.
|
|
|
|
__ ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(entity_name,
|
|
|
|
FieldMemOperand(entity_name, Map::kInstanceTypeOffset));
|
|
|
|
__ tst(entity_name, Operand(kIsInternalizedMask));
|
|
|
|
__ b(ne, &good);
|
|
|
|
__ cmp(entity_name, Operand(SYMBOL_TYPE));
|
|
|
|
__ b(ne, miss);
|
|
|
|
|
|
|
|
__ bind(&good);
|
|
|
|
|
|
|
|
// Restore the properties.
|
|
|
|
__ ldr(properties,
|
|
|
|
FieldMemOperand(receiver, JSObject::kPropertiesOffset));
|
2011-10-25 09:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const int spill_mask =
|
|
|
|
(lr.bit() | r6.bit() | r5.bit() | r4.bit() | r3.bit() |
|
|
|
|
r2.bit() | r1.bit() | r0.bit());
|
|
|
|
|
|
|
|
__ stm(db_w, sp, spill_mask);
|
|
|
|
__ ldr(r0, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
|
2013-03-04 15:00:57 +00:00
|
|
|
__ mov(r1, Operand(Handle<Name>(name)));
|
|
|
|
NameDictionaryLookupStub stub(NEGATIVE_LOOKUP);
|
2011-10-25 09:24:49 +00:00
|
|
|
__ CallStub(&stub);
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(r0, Operand::Zero());
|
2011-10-25 09:24:49 +00:00
|
|
|
__ ldm(ia_w, sp, spill_mask);
|
|
|
|
|
|
|
|
__ b(eq, done);
|
|
|
|
__ b(ne, miss);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
// Probe the name dictionary in the |elements| register. Jump to the
|
2011-05-05 12:30:57 +00:00
|
|
|
// |done| label if a property with the given name is found. Jump to
|
|
|
|
// the |miss| label otherwise.
|
|
|
|
// If lookup was successful |scratch2| will be equal to elements + 4 * index.
|
2013-03-04 15:00:57 +00:00
|
|
|
void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
|
|
|
|
Label* miss,
|
|
|
|
Label* done,
|
|
|
|
Register elements,
|
|
|
|
Register name,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2) {
|
2011-10-27 07:59:12 +00:00
|
|
|
ASSERT(!elements.is(scratch1));
|
|
|
|
ASSERT(!elements.is(scratch2));
|
|
|
|
ASSERT(!name.is(scratch1));
|
|
|
|
ASSERT(!name.is(scratch2));
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
__ AssertName(name);
|
2011-05-05 12:30:57 +00:00
|
|
|
|
|
|
|
// Compute the capacity mask.
|
|
|
|
__ ldr(scratch1, FieldMemOperand(elements, kCapacityOffset));
|
|
|
|
__ mov(scratch1, Operand(scratch1, ASR, kSmiTagSize)); // convert smi to int
|
|
|
|
__ sub(scratch1, scratch1, Operand(1));
|
|
|
|
|
|
|
|
// Generate an unrolled loop that performs a few probes before
|
|
|
|
// giving up. Measurements done on Gmail indicate that 2 probes
|
|
|
|
// cover ~93% of loads from dictionaries.
|
|
|
|
for (int i = 0; i < kInlinedProbes; i++) {
|
|
|
|
// Compute the masked index: (hash + i + i * i) & mask.
|
2013-03-04 15:00:57 +00:00
|
|
|
__ ldr(scratch2, FieldMemOperand(name, Name::kHashFieldOffset));
|
2011-05-05 12:30:57 +00:00
|
|
|
if (i > 0) {
|
|
|
|
// Add the probe offset (i + i * i) left shifted to avoid right shifting
|
|
|
|
// the hash in a separate instruction. The value hash + i + i * i is right
|
|
|
|
// shifted in the following and instruction.
|
2013-03-04 15:00:57 +00:00
|
|
|
ASSERT(NameDictionary::GetProbeOffset(i) <
|
|
|
|
1 << (32 - Name::kHashFieldOffset));
|
2011-05-05 12:30:57 +00:00
|
|
|
__ add(scratch2, scratch2, Operand(
|
2013-03-04 15:00:57 +00:00
|
|
|
NameDictionary::GetProbeOffset(i) << Name::kHashShift));
|
2011-05-05 12:30:57 +00:00
|
|
|
}
|
2013-03-04 15:00:57 +00:00
|
|
|
__ and_(scratch2, scratch1, Operand(scratch2, LSR, Name::kHashShift));
|
2011-05-05 12:30:57 +00:00
|
|
|
|
|
|
|
// Scale the index by multiplying by the element size.
|
2013-03-04 15:00:57 +00:00
|
|
|
ASSERT(NameDictionary::kEntrySize == 3);
|
2011-05-05 12:30:57 +00:00
|
|
|
// scratch2 = scratch2 * 3.
|
|
|
|
__ add(scratch2, scratch2, Operand(scratch2, LSL, 1));
|
|
|
|
|
|
|
|
// Check if the key is identical to the name.
|
|
|
|
__ add(scratch2, elements, Operand(scratch2, LSL, 2));
|
|
|
|
__ ldr(ip, FieldMemOperand(scratch2, kElementsStartOffset));
|
|
|
|
__ cmp(name, Operand(ip));
|
|
|
|
__ b(eq, done);
|
|
|
|
}
|
|
|
|
|
|
|
|
const int spill_mask =
|
|
|
|
(lr.bit() | r6.bit() | r5.bit() | r4.bit() |
|
|
|
|
r3.bit() | r2.bit() | r1.bit() | r0.bit()) &
|
|
|
|
~(scratch1.bit() | scratch2.bit());
|
|
|
|
|
|
|
|
__ stm(db_w, sp, spill_mask);
|
2011-10-27 07:59:12 +00:00
|
|
|
if (name.is(r0)) {
|
|
|
|
ASSERT(!elements.is(r1));
|
|
|
|
__ Move(r1, name);
|
|
|
|
__ Move(r0, elements);
|
|
|
|
} else {
|
|
|
|
__ Move(r0, elements);
|
|
|
|
__ Move(r1, name);
|
|
|
|
}
|
2013-03-04 15:00:57 +00:00
|
|
|
NameDictionaryLookupStub stub(POSITIVE_LOOKUP);
|
2011-05-05 12:30:57 +00:00
|
|
|
__ CallStub(&stub);
|
2013-01-07 09:43:12 +00:00
|
|
|
__ cmp(r0, Operand::Zero());
|
2011-05-05 12:30:57 +00:00
|
|
|
__ mov(scratch2, Operand(r2));
|
|
|
|
__ ldm(ia_w, sp, spill_mask);
|
|
|
|
|
|
|
|
__ b(ne, done);
|
|
|
|
__ b(eq, miss);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
|
2011-09-15 11:30:45 +00:00
|
|
|
// This stub overrides SometimesSetsUpAFrame() to return false. That means
|
|
|
|
// we cannot call anything that could cause a GC from this stub.
|
2011-05-05 12:30:57 +00:00
|
|
|
// Registers:
|
2013-03-04 15:00:57 +00:00
|
|
|
// result: NameDictionary to probe
|
2011-05-05 12:30:57 +00:00
|
|
|
// r1: key
|
2013-03-04 15:00:57 +00:00
|
|
|
// dictionary: NameDictionary to probe.
|
|
|
|
// index: will hold an index of entry if lookup is successful.
|
|
|
|
// might alias with result_.
|
2011-05-05 12:30:57 +00:00
|
|
|
// Returns:
|
|
|
|
// result_ is zero if lookup failed, non zero otherwise.
|
|
|
|
|
|
|
|
Register result = r0;
|
|
|
|
Register dictionary = r0;
|
|
|
|
Register key = r1;
|
|
|
|
Register index = r2;
|
|
|
|
Register mask = r3;
|
|
|
|
Register hash = r4;
|
|
|
|
Register undefined = r5;
|
|
|
|
Register entry_key = r6;
|
|
|
|
|
|
|
|
Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
|
|
|
|
|
|
|
|
__ ldr(mask, FieldMemOperand(dictionary, kCapacityOffset));
|
|
|
|
__ mov(mask, Operand(mask, ASR, kSmiTagSize));
|
|
|
|
__ sub(mask, mask, Operand(1));
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
__ ldr(hash, FieldMemOperand(key, Name::kHashFieldOffset));
|
2011-05-05 12:30:57 +00:00
|
|
|
|
|
|
|
__ LoadRoot(undefined, Heap::kUndefinedValueRootIndex);
|
|
|
|
|
|
|
|
for (int i = kInlinedProbes; i < kTotalProbes; i++) {
|
|
|
|
// Compute the masked index: (hash + i + i * i) & mask.
|
|
|
|
// Capacity is smi 2^n.
|
|
|
|
if (i > 0) {
|
|
|
|
// Add the probe offset (i + i * i) left shifted to avoid right shifting
|
|
|
|
// the hash in a separate instruction. The value hash + i + i * i is right
|
|
|
|
// shifted in the following and instruction.
|
2013-03-04 15:00:57 +00:00
|
|
|
ASSERT(NameDictionary::GetProbeOffset(i) <
|
|
|
|
1 << (32 - Name::kHashFieldOffset));
|
2011-05-05 12:30:57 +00:00
|
|
|
__ add(index, hash, Operand(
|
2013-03-04 15:00:57 +00:00
|
|
|
NameDictionary::GetProbeOffset(i) << Name::kHashShift));
|
2011-05-05 12:30:57 +00:00
|
|
|
} else {
|
|
|
|
__ mov(index, Operand(hash));
|
|
|
|
}
|
2013-03-04 15:00:57 +00:00
|
|
|
__ and_(index, mask, Operand(index, LSR, Name::kHashShift));
|
2011-05-05 12:30:57 +00:00
|
|
|
|
|
|
|
// Scale the index by multiplying by the entry size.
|
2013-03-04 15:00:57 +00:00
|
|
|
ASSERT(NameDictionary::kEntrySize == 3);
|
2011-05-05 12:30:57 +00:00
|
|
|
__ add(index, index, Operand(index, LSL, 1)); // index *= 3.
|
|
|
|
|
|
|
|
ASSERT_EQ(kSmiTagSize, 1);
|
|
|
|
__ add(index, dictionary, Operand(index, LSL, 2));
|
|
|
|
__ ldr(entry_key, FieldMemOperand(index, kElementsStartOffset));
|
|
|
|
|
|
|
|
// Having undefined at this place means the name is not contained.
|
|
|
|
__ cmp(entry_key, Operand(undefined));
|
|
|
|
__ b(eq, ¬_in_dictionary);
|
|
|
|
|
|
|
|
// Stop if found the property.
|
|
|
|
__ cmp(entry_key, Operand(key));
|
|
|
|
__ b(eq, &in_dictionary);
|
|
|
|
|
|
|
|
if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) {
|
2013-03-04 15:00:57 +00:00
|
|
|
// Check if the entry name is not a unique name.
|
|
|
|
Label cont;
|
2011-05-05 12:30:57 +00:00
|
|
|
__ ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(entry_key,
|
|
|
|
FieldMemOperand(entry_key, Map::kInstanceTypeOffset));
|
2013-02-28 17:03:34 +00:00
|
|
|
__ tst(entry_key, Operand(kIsInternalizedMask));
|
2013-03-04 15:00:57 +00:00
|
|
|
__ b(ne, &cont);
|
|
|
|
__ cmp(entry_key, Operand(SYMBOL_TYPE));
|
|
|
|
__ b(ne, &maybe_in_dictionary);
|
|
|
|
__ bind(&cont);
|
2011-05-05 12:30:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&maybe_in_dictionary);
|
|
|
|
// If we are doing negative lookup then probing failure should be
|
|
|
|
// treated as a lookup success. For positive lookup probing failure
|
|
|
|
// should be treated as lookup failure.
|
|
|
|
if (mode_ == POSITIVE_LOOKUP) {
|
2011-08-23 12:00:09 +00:00
|
|
|
__ mov(result, Operand::Zero());
|
2011-05-05 12:30:57 +00:00
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&in_dictionary);
|
|
|
|
__ mov(result, Operand(1));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(¬_in_dictionary);
|
2011-08-23 12:00:09 +00:00
|
|
|
__ mov(result, Operand::Zero());
|
2011-05-05 12:30:57 +00:00
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
struct AheadOfTimeWriteBarrierStubList {
|
|
|
|
Register object, value, address;
|
|
|
|
RememberedSetAction action;
|
|
|
|
};
|
|
|
|
|
2012-03-12 13:56:56 +00:00
|
|
|
#define REG(Name) { kRegister_ ## Name ## _Code }
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2012-03-12 13:56:56 +00:00
|
|
|
static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = {
|
2011-09-19 18:50:06 +00:00
|
|
|
// Used in RegExpExecStub.
|
2012-03-12 13:56:56 +00:00
|
|
|
{ REG(r6), REG(r4), REG(r7), EMIT_REMEMBERED_SET },
|
2011-09-19 18:50:06 +00:00
|
|
|
// Used in CompileArrayPushCall.
|
|
|
|
// Also used in StoreIC::GenerateNormal via GenerateDictionaryStore.
|
|
|
|
// Also used in KeyedStoreIC::GenerateGeneric.
|
2012-03-12 13:56:56 +00:00
|
|
|
{ REG(r3), REG(r4), REG(r5), EMIT_REMEMBERED_SET },
|
2011-09-19 18:50:06 +00:00
|
|
|
// Used in CompileStoreGlobal.
|
2012-03-12 13:56:56 +00:00
|
|
|
{ REG(r4), REG(r1), REG(r2), OMIT_REMEMBERED_SET },
|
2011-09-19 18:50:06 +00:00
|
|
|
// Used in StoreStubCompiler::CompileStoreField via GenerateStoreField.
|
2012-03-12 13:56:56 +00:00
|
|
|
{ REG(r1), REG(r2), REG(r3), EMIT_REMEMBERED_SET },
|
|
|
|
{ REG(r3), REG(r2), REG(r1), EMIT_REMEMBERED_SET },
|
2011-09-19 18:50:06 +00:00
|
|
|
// Used in KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField.
|
2012-03-12 13:56:56 +00:00
|
|
|
{ REG(r2), REG(r1), REG(r3), EMIT_REMEMBERED_SET },
|
|
|
|
{ REG(r3), REG(r1), REG(r2), EMIT_REMEMBERED_SET },
|
2011-09-19 18:50:06 +00:00
|
|
|
// KeyedStoreStubCompiler::GenerateStoreFastElement.
|
2012-03-12 13:56:56 +00:00
|
|
|
{ REG(r3), REG(r2), REG(r4), EMIT_REMEMBERED_SET },
|
|
|
|
{ REG(r2), REG(r3), REG(r4), EMIT_REMEMBERED_SET },
|
2012-05-23 14:24:29 +00:00
|
|
|
// ElementsTransitionGenerator::GenerateMapChangeElementTransition
|
|
|
|
// and ElementsTransitionGenerator::GenerateSmiToDouble
|
2011-10-20 12:36:45 +00:00
|
|
|
// and ElementsTransitionGenerator::GenerateDoubleToObject
|
2012-03-12 13:56:56 +00:00
|
|
|
{ REG(r2), REG(r3), REG(r9), EMIT_REMEMBERED_SET },
|
|
|
|
{ REG(r2), REG(r3), REG(r9), OMIT_REMEMBERED_SET },
|
2011-10-20 12:36:45 +00:00
|
|
|
// ElementsTransitionGenerator::GenerateDoubleToObject
|
2012-03-12 13:56:56 +00:00
|
|
|
{ REG(r6), REG(r2), REG(r0), EMIT_REMEMBERED_SET },
|
|
|
|
{ REG(r2), REG(r6), REG(r9), EMIT_REMEMBERED_SET },
|
2011-11-11 14:49:16 +00:00
|
|
|
// StoreArrayLiteralElementStub::Generate
|
2012-03-12 13:56:56 +00:00
|
|
|
{ REG(r5), REG(r0), REG(r6), EMIT_REMEMBERED_SET },
|
2012-06-14 14:06:22 +00:00
|
|
|
// FastNewClosureStub::Generate
|
|
|
|
{ REG(r2), REG(r4), REG(r1), EMIT_REMEMBERED_SET },
|
2011-09-19 18:36:47 +00:00
|
|
|
// Null termination.
|
2012-03-12 13:56:56 +00:00
|
|
|
{ REG(no_reg), REG(no_reg), REG(no_reg), EMIT_REMEMBERED_SET}
|
2011-09-19 18:36:47 +00:00
|
|
|
};
|
|
|
|
|
2012-03-12 13:56:56 +00:00
|
|
|
#undef REG
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2012-09-27 11:31:26 +00:00
|
|
|
|
2011-09-27 10:53:22 +00:00
|
|
|
bool RecordWriteStub::IsPregenerated() {
|
2012-03-12 13:56:56 +00:00
|
|
|
for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime;
|
2011-09-19 18:36:47 +00:00
|
|
|
!entry->object.is(no_reg);
|
|
|
|
entry++) {
|
|
|
|
if (object_.is(entry->object) &&
|
|
|
|
value_.is(entry->value) &&
|
|
|
|
address_.is(entry->address) &&
|
|
|
|
remembered_set_action_ == entry->action &&
|
|
|
|
save_fp_regs_mode_ == kDontSaveFPRegs) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2011-09-19 18:50:06 +00:00
|
|
|
return false;
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-27 12:33:24 +00:00
|
|
|
void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
|
|
|
|
Isolate* isolate) {
|
2011-09-19 18:36:47 +00:00
|
|
|
StoreBufferOverflowStub stub1(kDontSaveFPRegs);
|
2013-02-27 12:33:24 +00:00
|
|
|
stub1.GetCode(isolate)->set_is_pregenerated(true);
|
2013-04-19 16:01:57 +00:00
|
|
|
// Hydrogen code stubs need stub2 at snapshot time.
|
|
|
|
StoreBufferOverflowStub stub2(kSaveFPRegs);
|
|
|
|
stub2.GetCode(isolate)->set_is_pregenerated(true);
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-27 12:33:24 +00:00
|
|
|
void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) {
|
2012-03-12 13:56:56 +00:00
|
|
|
for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime;
|
2011-09-19 18:36:47 +00:00
|
|
|
!entry->object.is(no_reg);
|
|
|
|
entry++) {
|
|
|
|
RecordWriteStub stub(entry->object,
|
|
|
|
entry->value,
|
|
|
|
entry->address,
|
|
|
|
entry->action,
|
|
|
|
kDontSaveFPRegs);
|
2013-02-27 12:33:24 +00:00
|
|
|
stub.GetCode(isolate)->set_is_pregenerated(true);
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-27 11:31:26 +00:00
|
|
|
bool CodeStub::CanUseFPRegisters() {
|
2013-04-07 04:34:20 +00:00
|
|
|
return true; // VFP2 is a base requirement for V8
|
2012-09-27 11:31:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Takes the input in 3 registers: address_ value_ and object_. A pointer to
|
|
|
|
// the value has just been written into the object, now this stub makes sure
|
|
|
|
// we keep the GC informed. The word in the object where the value has been
|
|
|
|
// written is in the address register.
|
|
|
|
void RecordWriteStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label skip_to_incremental_noncompacting;
|
|
|
|
Label skip_to_incremental_compacting;
|
|
|
|
|
|
|
|
// The first two instructions are generated with labels so as to get the
|
|
|
|
// offset fixed up correctly by the bind(Label*) call. We patch it back and
|
|
|
|
// forth between a compare instructions (a nop in this position) and the
|
|
|
|
// real branch when we start and stop incremental heap marking.
|
|
|
|
// See RecordWriteStub::Patch for details.
|
2012-06-12 17:26:28 +00:00
|
|
|
{
|
|
|
|
// Block literal pool emission, as the position of these two instructions
|
|
|
|
// is assumed by the patching code.
|
|
|
|
Assembler::BlockConstPoolScope block_const_pool(masm);
|
|
|
|
__ b(&skip_to_incremental_noncompacting);
|
|
|
|
__ b(&skip_to_incremental_compacting);
|
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
if (remembered_set_action_ == EMIT_REMEMBERED_SET) {
|
2011-09-20 13:32:27 +00:00
|
|
|
__ RememberedSetHelper(object_,
|
|
|
|
address_,
|
|
|
|
value_,
|
|
|
|
save_fp_regs_mode_,
|
|
|
|
MacroAssembler::kReturnAtEnd);
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
__ bind(&skip_to_incremental_noncompacting);
|
|
|
|
GenerateIncremental(masm, INCREMENTAL);
|
|
|
|
|
|
|
|
__ bind(&skip_to_incremental_compacting);
|
|
|
|
GenerateIncremental(masm, INCREMENTAL_COMPACTION);
|
|
|
|
|
|
|
|
// Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
|
|
|
|
// Will be checked in IncrementalMarking::ActivateGeneratedStub.
|
|
|
|
ASSERT(Assembler::GetBranchOffset(masm->instr_at(0)) < (1 << 12));
|
|
|
|
ASSERT(Assembler::GetBranchOffset(masm->instr_at(4)) < (1 << 12));
|
|
|
|
PatchBranchIntoNop(masm, 0);
|
|
|
|
PatchBranchIntoNop(masm, Assembler::kInstrSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
|
|
|
|
regs_.Save(masm);
|
|
|
|
|
|
|
|
if (remembered_set_action_ == EMIT_REMEMBERED_SET) {
|
|
|
|
Label dont_need_remembered_set;
|
|
|
|
|
|
|
|
__ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
|
2011-09-20 13:32:27 +00:00
|
|
|
__ JumpIfNotInNewSpace(regs_.scratch0(), // Value.
|
2011-09-19 18:36:47 +00:00
|
|
|
regs_.scratch0(),
|
|
|
|
&dont_need_remembered_set);
|
|
|
|
|
|
|
|
__ CheckPageFlag(regs_.object(),
|
|
|
|
regs_.scratch0(),
|
|
|
|
1 << MemoryChunk::SCAN_ON_SCAVENGE,
|
|
|
|
ne,
|
|
|
|
&dont_need_remembered_set);
|
|
|
|
|
|
|
|
// First notify the incremental marker if necessary, then update the
|
|
|
|
// remembered set.
|
|
|
|
CheckNeedsToInformIncrementalMarker(
|
|
|
|
masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
|
|
|
|
InformIncrementalMarker(masm, mode);
|
|
|
|
regs_.Restore(masm);
|
2011-09-20 13:32:27 +00:00
|
|
|
__ RememberedSetHelper(object_,
|
|
|
|
address_,
|
|
|
|
value_,
|
|
|
|
save_fp_regs_mode_,
|
|
|
|
MacroAssembler::kReturnAtEnd);
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
__ bind(&dont_need_remembered_set);
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckNeedsToInformIncrementalMarker(
|
|
|
|
masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
|
|
|
|
InformIncrementalMarker(masm, mode);
|
|
|
|
regs_.Restore(masm);
|
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) {
|
|
|
|
regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_);
|
|
|
|
int argument_count = 3;
|
|
|
|
__ PrepareCallCFunction(argument_count, regs_.scratch0());
|
|
|
|
Register address =
|
|
|
|
r0.is(regs_.address()) ? regs_.scratch0() : regs_.address();
|
|
|
|
ASSERT(!address.is(regs_.object()));
|
|
|
|
ASSERT(!address.is(r0));
|
|
|
|
__ Move(address, regs_.address());
|
|
|
|
__ Move(r0, regs_.object());
|
2012-11-22 07:05:20 +00:00
|
|
|
__ Move(r1, address);
|
2013-04-24 07:39:35 +00:00
|
|
|
__ mov(r2, Operand(ExternalReference::isolate_address(masm->isolate())));
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
AllowExternalCallThatCantCauseGC scope(masm);
|
|
|
|
if (mode == INCREMENTAL_COMPACTION) {
|
|
|
|
__ CallCFunction(
|
|
|
|
ExternalReference::incremental_evacuation_record_write_function(
|
|
|
|
masm->isolate()),
|
|
|
|
argument_count);
|
|
|
|
} else {
|
|
|
|
ASSERT(mode == INCREMENTAL);
|
|
|
|
__ CallCFunction(
|
|
|
|
ExternalReference::incremental_marking_record_write_function(
|
|
|
|
masm->isolate()),
|
|
|
|
argument_count);
|
|
|
|
}
|
|
|
|
regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
|
|
|
|
MacroAssembler* masm,
|
|
|
|
OnNoNeedToInformIncrementalMarker on_no_need,
|
|
|
|
Mode mode) {
|
|
|
|
Label on_black;
|
|
|
|
Label need_incremental;
|
|
|
|
Label need_incremental_pop_scratch;
|
|
|
|
|
2012-09-26 11:35:42 +00:00
|
|
|
__ and_(regs_.scratch0(), regs_.object(), Operand(~Page::kPageAlignmentMask));
|
|
|
|
__ ldr(regs_.scratch1(),
|
|
|
|
MemOperand(regs_.scratch0(),
|
|
|
|
MemoryChunk::kWriteBarrierCounterOffset));
|
|
|
|
__ sub(regs_.scratch1(), regs_.scratch1(), Operand(1), SetCC);
|
|
|
|
__ str(regs_.scratch1(),
|
|
|
|
MemOperand(regs_.scratch0(),
|
|
|
|
MemoryChunk::kWriteBarrierCounterOffset));
|
|
|
|
__ b(mi, &need_incremental);
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Let's look at the color of the object: If it is not black we don't have
|
|
|
|
// to inform the incremental marker.
|
|
|
|
__ JumpIfBlack(regs_.object(), regs_.scratch0(), regs_.scratch1(), &on_black);
|
|
|
|
|
|
|
|
regs_.Restore(masm);
|
|
|
|
if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
|
2011-09-20 13:32:27 +00:00
|
|
|
__ RememberedSetHelper(object_,
|
|
|
|
address_,
|
|
|
|
value_,
|
|
|
|
save_fp_regs_mode_,
|
|
|
|
MacroAssembler::kReturnAtEnd);
|
2011-09-19 18:36:47 +00:00
|
|
|
} else {
|
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&on_black);
|
|
|
|
|
|
|
|
// Get the value from the slot.
|
|
|
|
__ ldr(regs_.scratch0(), MemOperand(regs_.address(), 0));
|
|
|
|
|
|
|
|
if (mode == INCREMENTAL_COMPACTION) {
|
|
|
|
Label ensure_not_white;
|
|
|
|
|
|
|
|
__ CheckPageFlag(regs_.scratch0(), // Contains value.
|
|
|
|
regs_.scratch1(), // Scratch.
|
|
|
|
MemoryChunk::kEvacuationCandidateMask,
|
|
|
|
eq,
|
|
|
|
&ensure_not_white);
|
|
|
|
|
|
|
|
__ CheckPageFlag(regs_.object(),
|
|
|
|
regs_.scratch1(), // Scratch.
|
|
|
|
MemoryChunk::kSkipEvacuationSlotsRecordingMask,
|
|
|
|
eq,
|
|
|
|
&need_incremental);
|
|
|
|
|
|
|
|
__ bind(&ensure_not_white);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need extra registers for this, so we push the object and the address
|
|
|
|
// register temporarily.
|
|
|
|
__ Push(regs_.object(), regs_.address());
|
|
|
|
__ EnsureNotWhite(regs_.scratch0(), // The value.
|
|
|
|
regs_.scratch1(), // Scratch.
|
|
|
|
regs_.object(), // Scratch.
|
|
|
|
regs_.address(), // Scratch.
|
|
|
|
&need_incremental_pop_scratch);
|
|
|
|
__ Pop(regs_.object(), regs_.address());
|
|
|
|
|
|
|
|
regs_.Restore(masm);
|
|
|
|
if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
|
2011-09-20 13:32:27 +00:00
|
|
|
__ RememberedSetHelper(object_,
|
|
|
|
address_,
|
|
|
|
value_,
|
|
|
|
save_fp_regs_mode_,
|
|
|
|
MacroAssembler::kReturnAtEnd);
|
2011-09-19 18:36:47 +00:00
|
|
|
} else {
|
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&need_incremental_pop_scratch);
|
|
|
|
__ Pop(regs_.object(), regs_.address());
|
|
|
|
|
|
|
|
__ bind(&need_incremental);
|
|
|
|
|
|
|
|
// Fall through when we need to inform the incremental marker.
|
|
|
|
}
|
|
|
|
|
2011-11-11 14:49:16 +00:00
|
|
|
|
|
|
|
void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- r0 : element value to store
|
|
|
|
// -- r1 : array literal
|
|
|
|
// -- r2 : map of array literal
|
|
|
|
// -- r3 : element index as smi
|
|
|
|
// -- r4 : array literal index in function as smi
|
|
|
|
// -----------------------------------
|
|
|
|
|
|
|
|
Label element_done;
|
|
|
|
Label double_elements;
|
|
|
|
Label smi_element;
|
|
|
|
Label slow_elements;
|
|
|
|
Label fast_elements;
|
|
|
|
|
|
|
|
__ CheckFastElements(r2, r5, &double_elements);
|
2012-05-23 14:24:29 +00:00
|
|
|
// FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
|
2011-11-11 14:49:16 +00:00
|
|
|
__ JumpIfSmi(r0, &smi_element);
|
2012-05-23 14:24:29 +00:00
|
|
|
__ CheckFastSmiElements(r2, r5, &fast_elements);
|
2011-11-11 14:49:16 +00:00
|
|
|
|
|
|
|
// Store into the array literal requires a elements transition. Call into
|
|
|
|
// the runtime.
|
|
|
|
__ bind(&slow_elements);
|
|
|
|
// call.
|
|
|
|
__ Push(r1, r3, r0);
|
|
|
|
__ ldr(r5, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
|
|
|
|
__ ldr(r5, FieldMemOperand(r5, JSFunction::kLiteralsOffset));
|
|
|
|
__ Push(r5, r4);
|
|
|
|
__ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
|
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
// Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
|
2011-11-11 14:49:16 +00:00
|
|
|
__ bind(&fast_elements);
|
|
|
|
__ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
|
|
|
|
__ add(r6, r5, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize));
|
|
|
|
__ add(r6, r6, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
|
|
|
|
__ str(r0, MemOperand(r6, 0));
|
|
|
|
// Update the write barrier for the array store.
|
|
|
|
__ RecordWrite(r5, r6, r0, kLRHasNotBeenSaved, kDontSaveFPRegs,
|
|
|
|
EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
|
|
|
|
__ Ret();
|
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
// Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS,
|
|
|
|
// and value is Smi.
|
2011-11-11 14:49:16 +00:00
|
|
|
__ bind(&smi_element);
|
|
|
|
__ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
|
|
|
|
__ add(r6, r5, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize));
|
|
|
|
__ str(r0, FieldMemOperand(r6, FixedArray::kHeaderSize));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
|
|
|
|
__ bind(&double_elements);
|
|
|
|
__ ldr(r5, FieldMemOperand(r1, JSObject::kElementsOffset));
|
2013-04-22 21:30:57 +00:00
|
|
|
__ StoreNumberToDoubleElements(r0, r3, r5, r6, &slow_elements);
|
2011-11-11 14:49:16 +00:00
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
2012-07-17 15:18:15 +00:00
|
|
|
|
2013-01-29 09:12:20 +00:00
|
|
|
void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
|
2013-04-04 17:55:43 +00:00
|
|
|
CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs);
|
2013-02-27 12:33:24 +00:00
|
|
|
__ Call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET);
|
2013-02-05 08:09:32 +00:00
|
|
|
int parameter_count_offset =
|
|
|
|
StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
|
|
|
|
__ ldr(r1, MemOperand(fp, parameter_count_offset));
|
2013-04-02 11:28:01 +00:00
|
|
|
if (function_mode_ == JS_FUNCTION_STUB_MODE) {
|
|
|
|
__ add(r1, r1, Operand(1));
|
|
|
|
}
|
2013-01-29 09:12:20 +00:00
|
|
|
masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
|
2013-02-05 08:09:32 +00:00
|
|
|
__ mov(r1, Operand(r1, LSL, kPointerSizeLog2));
|
|
|
|
__ add(sp, sp, r1);
|
2013-01-29 09:12:20 +00:00
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-17 15:18:15 +00:00
|
|
|
void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
|
|
|
|
if (entry_hook_ != NULL) {
|
2012-11-22 14:59:52 +00:00
|
|
|
PredictableCodeSizeScope predictable(masm, 4 * Assembler::kInstrSize);
|
2012-07-17 15:18:15 +00:00
|
|
|
ProfileEntryHookStub stub;
|
|
|
|
__ push(lr);
|
|
|
|
__ CallStub(&stub);
|
|
|
|
__ pop(lr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
|
|
|
|
// The entry hook is a "push lr" instruction, followed by a call.
|
|
|
|
const int32_t kReturnAddressDistanceFromFunctionStart =
|
2012-10-18 12:21:42 +00:00
|
|
|
3 * Assembler::kInstrSize;
|
2012-07-17 15:18:15 +00:00
|
|
|
|
|
|
|
// Save live volatile registers.
|
|
|
|
__ Push(lr, r5, r1);
|
|
|
|
const int32_t kNumSavedRegs = 3;
|
|
|
|
|
|
|
|
// Compute the function's address for the first argument.
|
|
|
|
__ sub(r0, lr, Operand(kReturnAddressDistanceFromFunctionStart));
|
|
|
|
|
|
|
|
// The caller's return address is above the saved temporaries.
|
|
|
|
// Grab that for the second argument to the hook.
|
|
|
|
__ add(r1, sp, Operand(kNumSavedRegs * kPointerSize));
|
|
|
|
|
|
|
|
// Align the stack if necessary.
|
|
|
|
int frame_alignment = masm->ActivationFrameAlignment();
|
|
|
|
if (frame_alignment > kPointerSize) {
|
|
|
|
__ mov(r5, sp);
|
|
|
|
ASSERT(IsPowerOf2(frame_alignment));
|
|
|
|
__ and_(sp, sp, Operand(-frame_alignment));
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(V8_HOST_ARCH_ARM)
|
|
|
|
__ mov(ip, Operand(reinterpret_cast<int32_t>(&entry_hook_)));
|
|
|
|
__ ldr(ip, MemOperand(ip));
|
|
|
|
#else
|
|
|
|
// Under the simulator we need to indirect the entry hook through a
|
|
|
|
// trampoline function at a known address.
|
|
|
|
Address trampoline_address = reinterpret_cast<Address>(
|
|
|
|
reinterpret_cast<intptr_t>(EntryHookTrampoline));
|
|
|
|
ApiFunction dispatcher(trampoline_address);
|
|
|
|
__ mov(ip, Operand(ExternalReference(&dispatcher,
|
|
|
|
ExternalReference::BUILTIN_CALL,
|
|
|
|
masm->isolate())));
|
|
|
|
#endif
|
|
|
|
__ Call(ip);
|
|
|
|
|
|
|
|
// Restore the stack pointer if needed.
|
|
|
|
if (frame_alignment > kPointerSize) {
|
|
|
|
__ mov(sp, r5);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ Pop(lr, r5, r1);
|
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
2013-04-25 16:00:32 +00:00
|
|
|
|
|
|
|
template<class T>
|
|
|
|
static void CreateArrayDispatch(MacroAssembler* masm) {
|
|
|
|
int last_index = GetSequenceIndexFromFastElementsKind(
|
|
|
|
TERMINAL_FAST_ELEMENTS_KIND);
|
|
|
|
for (int i = 0; i <= last_index; ++i) {
|
|
|
|
Label next;
|
|
|
|
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
|
|
|
|
__ cmp(r3, Operand(kind));
|
|
|
|
__ b(ne, &next);
|
|
|
|
T stub(kind);
|
|
|
|
__ TailCallStub(&stub);
|
|
|
|
__ bind(&next);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we reached this point there is a problem.
|
|
|
|
__ Abort("Unexpected ElementsKind in array constructor");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void CreateArrayDispatchOneArgument(MacroAssembler* masm) {
|
|
|
|
// r2 - type info cell
|
|
|
|
// r3 - kind
|
|
|
|
// r0 - number of arguments
|
|
|
|
// r1 - constructor?
|
|
|
|
// sp[0] - last argument
|
|
|
|
ASSERT(FAST_SMI_ELEMENTS == 0);
|
|
|
|
ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
|
|
|
|
ASSERT(FAST_ELEMENTS == 2);
|
|
|
|
ASSERT(FAST_HOLEY_ELEMENTS == 3);
|
|
|
|
ASSERT(FAST_DOUBLE_ELEMENTS == 4);
|
|
|
|
ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
|
|
|
|
|
|
|
|
Handle<Object> undefined_sentinel(
|
|
|
|
masm->isolate()->heap()->undefined_value(),
|
|
|
|
masm->isolate());
|
|
|
|
|
|
|
|
// is the low bit set? If so, we are holey and that is good.
|
|
|
|
__ tst(r3, Operand(1));
|
|
|
|
Label normal_sequence;
|
|
|
|
__ b(ne, &normal_sequence);
|
|
|
|
|
|
|
|
// look at the first argument
|
|
|
|
__ ldr(r5, MemOperand(sp, 0));
|
|
|
|
__ cmp(r5, Operand::Zero());
|
|
|
|
__ b(eq, &normal_sequence);
|
|
|
|
|
|
|
|
// We are going to create a holey array, but our kind is non-holey.
|
|
|
|
// Fix kind and retry
|
|
|
|
__ add(r3, r3, Operand(1));
|
|
|
|
__ cmp(r2, Operand(undefined_sentinel));
|
|
|
|
__ b(eq, &normal_sequence);
|
|
|
|
|
|
|
|
// Save the resulting elements kind in type info
|
|
|
|
__ SmiTag(r3);
|
|
|
|
__ str(r3, FieldMemOperand(r2, kPointerSize));
|
|
|
|
__ SmiUntag(r3);
|
|
|
|
|
|
|
|
__ bind(&normal_sequence);
|
|
|
|
int last_index = GetSequenceIndexFromFastElementsKind(
|
|
|
|
TERMINAL_FAST_ELEMENTS_KIND);
|
|
|
|
for (int i = 0; i <= last_index; ++i) {
|
|
|
|
Label next;
|
|
|
|
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
|
|
|
|
__ cmp(r3, Operand(kind));
|
|
|
|
__ b(ne, &next);
|
|
|
|
ArraySingleArgumentConstructorStub stub(kind);
|
|
|
|
__ TailCallStub(&stub);
|
|
|
|
__ bind(&next);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we reached this point there is a problem.
|
|
|
|
__ Abort("Unexpected ElementsKind in array constructor");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
|
|
|
|
int to_index = GetSequenceIndexFromFastElementsKind(
|
|
|
|
TERMINAL_FAST_ELEMENTS_KIND);
|
|
|
|
for (int i = 0; i <= to_index; ++i) {
|
|
|
|
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
|
|
|
|
T stub(kind);
|
|
|
|
stub.GetCode(isolate)->set_is_pregenerated(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
|
|
|
|
ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
|
|
|
|
isolate);
|
|
|
|
ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
|
|
|
|
isolate);
|
|
|
|
ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
|
|
|
|
isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArrayConstructorStub::Generate(MacroAssembler* masm) {
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- r0 : argc (only if argument_count_ == ANY)
|
|
|
|
// -- r1 : constructor
|
|
|
|
// -- r2 : type info cell
|
|
|
|
// -- sp[0] : return address
|
|
|
|
// -- sp[4] : last argument
|
|
|
|
// -----------------------------------
|
|
|
|
Handle<Object> undefined_sentinel(
|
|
|
|
masm->isolate()->heap()->undefined_value(),
|
|
|
|
masm->isolate());
|
|
|
|
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
// The array construct code is only set for the global and natives
|
|
|
|
// builtin Array functions which always have maps.
|
|
|
|
|
|
|
|
// Initial map for the builtin Array function should be a map.
|
|
|
|
__ ldr(r3, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset));
|
|
|
|
// Will both indicate a NULL and a Smi.
|
|
|
|
__ tst(r3, Operand(kSmiTagMask));
|
|
|
|
__ Assert(ne, "Unexpected initial map for Array function");
|
|
|
|
__ CompareObjectType(r3, r3, r4, MAP_TYPE);
|
|
|
|
__ Assert(eq, "Unexpected initial map for Array function");
|
|
|
|
|
|
|
|
// We should either have undefined in ebx or a valid jsglobalpropertycell
|
|
|
|
Label okay_here;
|
|
|
|
Handle<Map> global_property_cell_map(
|
|
|
|
masm->isolate()->heap()->global_property_cell_map());
|
|
|
|
__ cmp(r2, Operand(undefined_sentinel));
|
|
|
|
__ b(eq, &okay_here);
|
|
|
|
__ ldr(r3, FieldMemOperand(r2, 0));
|
|
|
|
__ cmp(r3, Operand(global_property_cell_map));
|
|
|
|
__ Assert(eq, "Expected property cell in register ebx");
|
|
|
|
__ bind(&okay_here);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FLAG_optimize_constructed_arrays) {
|
|
|
|
Label no_info, switch_ready;
|
|
|
|
// Get the elements kind and case on that.
|
|
|
|
__ cmp(r2, Operand(undefined_sentinel));
|
|
|
|
__ b(eq, &no_info);
|
|
|
|
__ ldr(r3, FieldMemOperand(r2, kPointerSize));
|
|
|
|
|
|
|
|
// There is no info if the call site went megamorphic either
|
|
|
|
// TODO(mvstanton): Really? I thought if it was the array function that
|
|
|
|
// the cell wouldn't get stamped as megamorphic.
|
|
|
|
__ cmp(r3,
|
|
|
|
Operand(TypeFeedbackCells::MegamorphicSentinel(masm->isolate())));
|
|
|
|
__ b(eq, &no_info);
|
|
|
|
__ SmiUntag(r3);
|
|
|
|
__ jmp(&switch_ready);
|
|
|
|
__ bind(&no_info);
|
|
|
|
__ mov(r3, Operand(GetInitialFastElementsKind()));
|
|
|
|
__ bind(&switch_ready);
|
|
|
|
|
|
|
|
if (argument_count_ == ANY) {
|
|
|
|
Label not_zero_case, not_one_case;
|
|
|
|
__ tst(r0, r0);
|
|
|
|
__ b(ne, ¬_zero_case);
|
|
|
|
CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm);
|
|
|
|
|
|
|
|
__ bind(¬_zero_case);
|
|
|
|
__ cmp(r0, Operand(1));
|
|
|
|
__ b(gt, ¬_one_case);
|
|
|
|
CreateArrayDispatchOneArgument(masm);
|
|
|
|
|
|
|
|
__ bind(¬_one_case);
|
|
|
|
CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm);
|
|
|
|
} else if (argument_count_ == NONE) {
|
|
|
|
CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm);
|
|
|
|
} else if (argument_count_ == ONE) {
|
|
|
|
CreateArrayDispatchOneArgument(masm);
|
|
|
|
} else if (argument_count_ == MORE_THAN_ONE) {
|
|
|
|
CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm);
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Label generic_constructor;
|
|
|
|
// Run the native code for the Array function called as a constructor.
|
|
|
|
ArrayNativeCode(masm, &generic_constructor);
|
|
|
|
|
|
|
|
// Jump to the generic construct code in case the specialized code cannot
|
|
|
|
// handle the construction.
|
|
|
|
__ bind(&generic_constructor);
|
|
|
|
Handle<Code> generic_construct_stub =
|
|
|
|
masm->isolate()->builtins()->JSConstructStubGeneric();
|
|
|
|
__ Jump(generic_construct_stub, RelocInfo::CODE_TARGET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
#undef __
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_TARGET_ARCH_ARM
|