2011-01-25 07:49:39 +00:00
|
|
|
// Copyright 2011 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_IA32)
|
|
|
|
|
|
|
|
#include "bootstrapper.h"
|
2011-05-11 13:45:30 +00:00
|
|
|
#include "code-stubs.h"
|
2011-03-18 20:35:07 +00:00
|
|
|
#include "isolate.h"
|
2011-05-11 13:45:30 +00:00
|
|
|
#include "jsregexp.h"
|
2010-08-25 09:44:44 +00:00
|
|
|
#include "regexp-macro-assembler.h"
|
2011-10-13 10:53:31 +00:00
|
|
|
#include "stub-cache.h"
|
2011-11-17 17:05:12 +00:00
|
|
|
#include "codegen.h"
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
#define __ ACCESS_MASM(masm)
|
2011-01-28 14:18:26 +00:00
|
|
|
|
|
|
|
void ToNumberStub::Generate(MacroAssembler* masm) {
|
|
|
|
// The ToNumber stub takes one argument in eax.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label check_heap_number, call_builtin;
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(eax, &check_heap_number, Label::kNear);
|
2011-01-28 14:18:26 +00:00
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&check_heap_number);
|
|
|
|
__ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
|
2011-03-25 13:21:30 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ebx, Immediate(factory->heap_number_map()));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, &call_builtin, Label::kNear);
|
2011-01-28 14:18:26 +00:00
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&call_builtin);
|
|
|
|
__ pop(ecx); // Pop return address.
|
|
|
|
__ push(eax);
|
|
|
|
__ push(ecx); // Push return address.
|
|
|
|
__ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 esi.
|
|
|
|
Label gc;
|
|
|
|
__ AllocateInNewSpace(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT);
|
|
|
|
|
|
|
|
// Get the function info from the stack.
|
|
|
|
__ mov(edx, Operand(esp, 1 * kPointerSize));
|
|
|
|
|
2011-11-24 15:17:04 +00:00
|
|
|
int map_index = (language_mode_ == CLASSIC_MODE)
|
|
|
|
? Context::FUNCTION_MAP_INDEX
|
|
|
|
: Context::STRICT_MODE_FUNCTION_MAP_INDEX;
|
2011-03-17 20:28:30 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Compute the function map in the current global context and set that
|
|
|
|
// as the map of the allocated object.
|
|
|
|
__ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX)));
|
|
|
|
__ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalContextOffset));
|
2011-03-17 20:28:30 +00:00
|
|
|
__ mov(ecx, Operand(ecx, Context::SlotOffset(map_index)));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(FieldOperand(eax, JSObject::kMapOffset), ecx);
|
|
|
|
|
|
|
|
// Initialize the rest of the function. We don't have to update the
|
|
|
|
// write barrier because the allocated object is in new space.
|
2011-03-25 13:21:30 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
__ mov(ebx, Immediate(factory->empty_fixed_array()));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx);
|
|
|
|
__ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx);
|
|
|
|
__ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset),
|
2011-03-25 13:21:30 +00:00
|
|
|
Immediate(factory->the_hole_value()));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx);
|
|
|
|
__ mov(FieldOperand(eax, JSFunction::kContextOffset), esi);
|
|
|
|
__ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset),
|
2011-03-25 13:21:30 +00:00
|
|
|
Immediate(factory->undefined_value()));
|
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.
|
|
|
|
__ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset));
|
|
|
|
__ lea(edx, FieldOperand(edx, Code::kHeaderSize));
|
|
|
|
__ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx);
|
|
|
|
|
|
|
|
// Return and remove the on-stack parameter.
|
|
|
|
__ ret(1 * kPointerSize);
|
|
|
|
|
|
|
|
// Create a new closure through the slower runtime call.
|
|
|
|
__ bind(&gc);
|
|
|
|
__ pop(ecx); // Temporarily remove return address.
|
|
|
|
__ pop(edx);
|
|
|
|
__ push(esi);
|
|
|
|
__ push(edx);
|
2011-03-25 13:21:30 +00:00
|
|
|
__ push(Immediate(factory->false_value()));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ push(ecx); // Restore return address.
|
2010-11-22 09:57:21 +00:00
|
|
|
__ 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;
|
|
|
|
__ AllocateInNewSpace((length * kPointerSize) + FixedArray::kHeaderSize,
|
2010-08-25 09:44:44 +00:00
|
|
|
eax, ebx, ecx, &gc, TAG_OBJECT);
|
|
|
|
|
|
|
|
// Get the function from the stack.
|
|
|
|
__ mov(ecx, Operand(esp, 1 * kPointerSize));
|
|
|
|
|
|
|
|
// Setup the object header.
|
2011-03-25 13:21:30 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
2011-06-09 11:26:01 +00:00
|
|
|
__ mov(FieldOperand(eax, HeapObject::kMapOffset),
|
|
|
|
factory->function_context_map());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(FieldOperand(eax, Context::kLengthOffset),
|
2011-01-25 13:01:45 +00:00
|
|
|
Immediate(Smi::FromInt(length)));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Setup the fixed slots.
|
2011-01-03 11:39:22 +00:00
|
|
|
__ Set(ebx, Immediate(0)); // Set to NULL.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx);
|
2011-06-09 12:45:26 +00:00
|
|
|
__ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx);
|
|
|
|
|
2011-06-09 12:45:26 +00:00
|
|
|
// Copy the global object from the previous context.
|
|
|
|
__ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX)));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_INDEX)), ebx);
|
|
|
|
|
|
|
|
// Initialize the rest of the slots to undefined.
|
2011-03-25 13:21:30 +00:00
|
|
|
__ mov(ebx, factory->undefined_value());
|
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
|
|
|
__ mov(Operand(eax, Context::SlotOffset(i)), ebx);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return and remove the on-stack parameter.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(esi, eax);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(1 * kPointerSize);
|
|
|
|
|
|
|
|
// 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:
|
|
|
|
//
|
|
|
|
// [esp + (1 * kPointerSize)]: function
|
|
|
|
// [esp + (2 * kPointerSize)]: serialized scope info
|
|
|
|
|
|
|
|
// Try to allocate the context in new space.
|
|
|
|
Label gc;
|
|
|
|
int length = slots_ + Context::MIN_CONTEXT_SLOTS;
|
|
|
|
__ AllocateInNewSpace(FixedArray::SizeFor(length),
|
|
|
|
eax, ebx, ecx, &gc, TAG_OBJECT);
|
|
|
|
|
|
|
|
// Get the function or sentinel from the stack.
|
|
|
|
__ mov(ecx, Operand(esp, 1 * kPointerSize));
|
|
|
|
|
|
|
|
// Get the serialized scope info from the stack.
|
|
|
|
__ mov(ebx, Operand(esp, 2 * kPointerSize));
|
|
|
|
|
|
|
|
// Setup the object header.
|
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
__ mov(FieldOperand(eax, HeapObject::kMapOffset),
|
|
|
|
factory->block_context_map());
|
|
|
|
__ mov(FieldOperand(eax, Context::kLengthOffset),
|
|
|
|
Immediate(Smi::FromInt(length)));
|
|
|
|
|
|
|
|
// If this block context is nested in the global context we get a smi
|
|
|
|
// sentinel instead of a function. The block context should get the
|
|
|
|
// canonical empty function of the global context as its closure which
|
|
|
|
// we still have to look up.
|
|
|
|
Label after_sentinel;
|
|
|
|
__ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear);
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
const char* message = "Expected 0 as a Smi sentinel";
|
|
|
|
__ cmp(ecx, 0);
|
|
|
|
__ Assert(equal, message);
|
|
|
|
}
|
|
|
|
__ mov(ecx, GlobalObjectOperand());
|
|
|
|
__ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalContextOffset));
|
|
|
|
__ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX));
|
|
|
|
__ bind(&after_sentinel);
|
|
|
|
|
|
|
|
// Setup the fixed slots.
|
|
|
|
__ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx);
|
|
|
|
__ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi);
|
|
|
|
__ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx);
|
|
|
|
|
|
|
|
// Copy the global object from the previous context.
|
|
|
|
__ mov(ebx, ContextOperand(esi, Context::GLOBAL_INDEX));
|
|
|
|
__ mov(ContextOperand(eax, Context::GLOBAL_INDEX), ebx);
|
|
|
|
|
|
|
|
// Initialize the rest of the slots to the hole value.
|
|
|
|
if (slots_ == 1) {
|
|
|
|
__ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS),
|
|
|
|
factory->the_hole_value());
|
|
|
|
} else {
|
|
|
|
__ mov(ebx, factory->the_hole_value());
|
|
|
|
for (int i = 0; i < slots_; i++) {
|
|
|
|
__ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return and remove the on-stack parameters.
|
|
|
|
__ mov(esi, eax);
|
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
|
|
|
|
// Need to collect. Call into runtime system.
|
|
|
|
__ bind(&gc);
|
|
|
|
__ TailCallRuntime(Runtime::kPushBlockContext, 2, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-17 14:55:26 +00:00
|
|
|
static void GenerateFastCloneShallowArrayCommon(
|
|
|
|
MacroAssembler* masm,
|
|
|
|
int length,
|
|
|
|
FastCloneShallowArrayStub::Mode mode,
|
|
|
|
Label* fail) {
|
2011-11-17 15:08:59 +00:00
|
|
|
// Registers on entry:
|
2010-08-25 09:44:44 +00:00
|
|
|
//
|
2011-11-17 15:08:59 +00:00
|
|
|
// ecx: boilerplate literal array.
|
2011-11-17 14:55:26 +00:00
|
|
|
ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// All sizes here are multiples of kPointerSize.
|
2011-10-19 11:36:55 +00:00
|
|
|
int elements_size = 0;
|
2011-11-17 14:55:26 +00:00
|
|
|
if (length > 0) {
|
|
|
|
elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS
|
|
|
|
? FixedDoubleArray::SizeFor(length)
|
|
|
|
: FixedArray::SizeFor(length);
|
2011-10-19 11:36:55 +00:00
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
int size = JSArray::kSize + elements_size;
|
|
|
|
|
|
|
|
// Allocate both the JS array and the elements array in one big
|
|
|
|
// allocation. This avoids multiple limit checks.
|
2011-11-17 14:55:26 +00:00
|
|
|
__ AllocateInNewSpace(size, eax, ebx, edx, fail, TAG_OBJECT);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Copy the JS array part.
|
|
|
|
for (int i = 0; i < JSArray::kSize; i += kPointerSize) {
|
2011-11-17 14:55:26 +00:00
|
|
|
if ((i != JSArray::kElementsOffset) || (length == 0)) {
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(ebx, FieldOperand(ecx, i));
|
|
|
|
__ mov(FieldOperand(eax, i), ebx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-17 14:55:26 +00:00
|
|
|
if (length > 0) {
|
2010-08-25 09:44:44 +00:00
|
|
|
// Get hold of the elements array of the boilerplate and setup the
|
|
|
|
// elements pointer in the resulting object.
|
|
|
|
__ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset));
|
|
|
|
__ lea(edx, Operand(eax, JSArray::kSize));
|
|
|
|
__ mov(FieldOperand(eax, JSArray::kElementsOffset), edx);
|
|
|
|
|
|
|
|
// Copy the elements array.
|
2011-11-17 14:55:26 +00:00
|
|
|
if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) {
|
2011-10-19 11:36:55 +00:00
|
|
|
for (int i = 0; i < elements_size; i += kPointerSize) {
|
|
|
|
__ mov(ebx, FieldOperand(ecx, i));
|
|
|
|
__ mov(FieldOperand(edx, i), ebx);
|
|
|
|
}
|
|
|
|
} else {
|
2011-11-17 14:55:26 +00:00
|
|
|
ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS);
|
2011-10-19 11:36:55 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < FixedDoubleArray::kHeaderSize; i += kPointerSize) {
|
|
|
|
__ mov(ebx, FieldOperand(ecx, i));
|
|
|
|
__ mov(FieldOperand(edx, i), ebx);
|
|
|
|
}
|
|
|
|
while (i < elements_size) {
|
|
|
|
__ fld_d(FieldOperand(ecx, i));
|
|
|
|
__ fstp_d(FieldOperand(edx, i));
|
|
|
|
i += kDoubleSize;
|
|
|
|
}
|
|
|
|
ASSERT(i == elements_size);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-17 14:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) {
|
|
|
|
// Stack layout on entry:
|
|
|
|
//
|
|
|
|
// [esp + kPointerSize]: constant elements.
|
|
|
|
// [esp + (2 * kPointerSize)]: literal index.
|
|
|
|
// [esp + (3 * kPointerSize)]: literals array.
|
|
|
|
|
|
|
|
// Load boilerplate object into ecx and check if we need to create a
|
|
|
|
// boilerplate.
|
|
|
|
__ mov(ecx, Operand(esp, 3 * kPointerSize));
|
|
|
|
__ mov(eax, Operand(esp, 2 * kPointerSize));
|
|
|
|
STATIC_ASSERT(kPointerSize == 4);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size,
|
|
|
|
FixedArray::kHeaderSize));
|
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
__ cmp(ecx, factory->undefined_value());
|
|
|
|
Label slow_case;
|
|
|
|
__ j(equal, &slow_case);
|
|
|
|
|
|
|
|
FastCloneShallowArrayStub::Mode mode = mode_;
|
|
|
|
// ecx is boilerplate object.
|
|
|
|
if (mode == CLONE_ANY_ELEMENTS) {
|
|
|
|
Label double_elements, check_fast_elements;
|
|
|
|
__ mov(ebx, FieldOperand(ecx, JSArray::kElementsOffset));
|
|
|
|
__ CheckMap(ebx, factory->fixed_cow_array_map(),
|
|
|
|
&check_fast_elements, DONT_DO_SMI_CHECK);
|
|
|
|
GenerateFastCloneShallowArrayCommon(masm, 0,
|
|
|
|
COPY_ON_WRITE_ELEMENTS, &slow_case);
|
|
|
|
__ ret(3 * kPointerSize);
|
|
|
|
|
|
|
|
__ bind(&check_fast_elements);
|
|
|
|
__ CheckMap(ebx, factory->fixed_array_map(),
|
|
|
|
&double_elements, DONT_DO_SMI_CHECK);
|
|
|
|
GenerateFastCloneShallowArrayCommon(masm, length_,
|
|
|
|
CLONE_ELEMENTS, &slow_case);
|
|
|
|
__ ret(3 * kPointerSize);
|
|
|
|
|
|
|
|
__ bind(&double_elements);
|
|
|
|
mode = CLONE_DOUBLE_ELEMENTS;
|
|
|
|
// Fall through to generate the code to handle double elements.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
const char* message;
|
|
|
|
Handle<Map> expected_map;
|
|
|
|
if (mode == CLONE_ELEMENTS) {
|
|
|
|
message = "Expected (writable) fixed array";
|
|
|
|
expected_map = factory->fixed_array_map();
|
|
|
|
} else if (mode == CLONE_DOUBLE_ELEMENTS) {
|
|
|
|
message = "Expected (writable) fixed double array";
|
|
|
|
expected_map = factory->fixed_double_array_map();
|
|
|
|
} else {
|
|
|
|
ASSERT(mode == COPY_ON_WRITE_ELEMENTS);
|
|
|
|
message = "Expected copy-on-write fixed array";
|
|
|
|
expected_map = factory->fixed_cow_array_map();
|
|
|
|
}
|
|
|
|
__ push(ecx);
|
|
|
|
__ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset));
|
|
|
|
__ cmp(FieldOperand(ecx, HeapObject::kMapOffset), expected_map);
|
|
|
|
__ Assert(equal, message);
|
|
|
|
__ pop(ecx);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-11-17 14:55:26 +00:00
|
|
|
GenerateFastCloneShallowArrayCommon(masm, length_, mode, &slow_case);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Return and remove the on-stack parameters.
|
|
|
|
__ ret(3 * kPointerSize);
|
|
|
|
|
|
|
|
__ bind(&slow_case);
|
|
|
|
__ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-21 13:27:44 +00:00
|
|
|
void FastCloneShallowObjectStub::Generate(MacroAssembler* masm) {
|
|
|
|
// Stack layout on entry:
|
|
|
|
//
|
|
|
|
// [esp + kPointerSize]: object literal flags.
|
|
|
|
// [esp + (2 * kPointerSize)]: constant properties.
|
|
|
|
// [esp + (3 * kPointerSize)]: literal index.
|
|
|
|
// [esp + (4 * kPointerSize)]: literals array.
|
|
|
|
|
|
|
|
// Load boilerplate object into ecx and check if we need to create a
|
|
|
|
// boilerplate.
|
|
|
|
Label slow_case;
|
|
|
|
__ mov(ecx, Operand(esp, 4 * kPointerSize));
|
|
|
|
__ mov(eax, Operand(esp, 3 * kPointerSize));
|
|
|
|
STATIC_ASSERT(kPointerSize == 4);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size,
|
|
|
|
FixedArray::kHeaderSize));
|
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
__ cmp(ecx, factory->undefined_value());
|
|
|
|
__ j(equal, &slow_case);
|
|
|
|
|
|
|
|
// Check that the boilerplate contains only fast properties and we can
|
|
|
|
// statically determine the instance size.
|
|
|
|
int size = JSObject::kHeaderSize + length_ * kPointerSize;
|
|
|
|
__ mov(eax, FieldOperand(ecx, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(eax, FieldOperand(eax, Map::kInstanceSizeOffset));
|
|
|
|
__ cmp(eax, Immediate(size >> kPointerSizeLog2));
|
|
|
|
__ j(not_equal, &slow_case);
|
|
|
|
|
|
|
|
// Allocate the JS object and copy header together with all in-object
|
|
|
|
// properties from the boilerplate.
|
|
|
|
__ AllocateInNewSpace(size, eax, ebx, edx, &slow_case, TAG_OBJECT);
|
|
|
|
for (int i = 0; i < size; i += kPointerSize) {
|
|
|
|
__ mov(ebx, FieldOperand(ecx, i));
|
|
|
|
__ mov(FieldOperand(eax, i), ebx);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return and remove the on-stack parameters.
|
|
|
|
__ ret(4 * kPointerSize);
|
|
|
|
|
|
|
|
__ bind(&slow_case);
|
|
|
|
__ TailCallRuntime(Runtime::kCreateObjectLiteralShallow, 4, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-21 13:51:04 +00:00
|
|
|
// The stub expects its argument on the stack and returns its result in tos_:
|
|
|
|
// 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-07-21 13:51:04 +00:00
|
|
|
Label patch;
|
2011-05-18 10:40:01 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
2011-07-21 13:51:04 +00:00
|
|
|
const Register argument = eax;
|
2011-06-22 08:28:35 +00:00
|
|
|
const Register map = edx;
|
|
|
|
|
2011-07-21 13:51:04 +00:00
|
|
|
if (!types_.IsEmpty()) {
|
|
|
|
__ mov(argument, Operand(esp, 1 * kPointerSize));
|
|
|
|
}
|
2011-05-18 10:40:01 +00:00
|
|
|
|
|
|
|
// undefined -> false
|
2011-08-11 07:22:16 +00:00
|
|
|
CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false);
|
2011-05-18 10:40:01 +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);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-08-01 13:35:11 +00:00
|
|
|
// 'null' -> false.
|
2011-08-11 07:22:16 +00:00
|
|
|
CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false);
|
2011-07-21 13:51:04 +00:00
|
|
|
|
|
|
|
if (types_.Contains(SMI)) {
|
|
|
|
// Smis: 0 -> false, all other -> true
|
|
|
|
Label not_smi;
|
|
|
|
__ JumpIfNotSmi(argument, ¬_smi, Label::kNear);
|
2011-08-11 07:22:16 +00:00
|
|
|
// argument contains the correct return value already.
|
2011-07-21 13:51:04 +00:00
|
|
|
if (!tos_.is(argument)) {
|
|
|
|
__ mov(tos_, argument);
|
|
|
|
}
|
|
|
|
__ ret(1 * kPointerSize);
|
|
|
|
__ bind(¬_smi);
|
2011-07-28 13:33:51 +00:00
|
|
|
} else if (types_.NeedsMap()) {
|
2011-07-21 13:51:04 +00:00
|
|
|
// If we need a map later and have a Smi -> patch.
|
|
|
|
__ JumpIfSmi(argument, &patch, Label::kNear);
|
|
|
|
}
|
|
|
|
|
2011-07-28 13:33:51 +00:00
|
|
|
if (types_.NeedsMap()) {
|
2011-07-21 13:51:04 +00:00
|
|
|
__ mov(map, FieldOperand(argument, HeapObject::kMapOffset));
|
|
|
|
|
2011-08-11 07:22:16 +00:00
|
|
|
if (types_.CanBeUndetectable()) {
|
|
|
|
__ test_b(FieldOperand(map, Map::kBitFieldOffset),
|
|
|
|
1 << Map::kIsUndetectable);
|
|
|
|
// Undetectable -> false.
|
|
|
|
Label not_undetectable;
|
|
|
|
__ j(zero, ¬_undetectable, Label::kNear);
|
|
|
|
__ Set(tos_, Immediate(0));
|
|
|
|
__ ret(1 * kPointerSize);
|
|
|
|
__ bind(¬_undetectable);
|
|
|
|
}
|
2011-07-21 13:51:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (types_.Contains(SPEC_OBJECT)) {
|
|
|
|
// spec object -> true.
|
|
|
|
Label not_js_object;
|
|
|
|
__ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE);
|
|
|
|
__ j(below, ¬_js_object, Label::kNear);
|
2011-08-11 07:22:16 +00:00
|
|
|
// argument contains the correct return value already.
|
|
|
|
if (!tos_.is(argument)) {
|
|
|
|
__ Set(tos_, Immediate(1));
|
|
|
|
}
|
2011-07-21 13:51:04 +00:00
|
|
|
__ ret(1 * kPointerSize);
|
|
|
|
__ bind(¬_js_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (types_.Contains(STRING)) {
|
|
|
|
// String value -> false iff empty.
|
|
|
|
Label not_string;
|
|
|
|
__ CmpInstanceType(map, FIRST_NONSTRING_TYPE);
|
|
|
|
__ j(above_equal, ¬_string, Label::kNear);
|
|
|
|
__ mov(tos_, FieldOperand(argument, String::kLengthOffset));
|
|
|
|
__ ret(1 * kPointerSize); // the string length is OK as the return value
|
|
|
|
__ bind(¬_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (types_.Contains(HEAP_NUMBER)) {
|
|
|
|
// heap number -> false iff +0, -0, or NaN.
|
|
|
|
Label not_heap_number, false_result;
|
|
|
|
__ cmp(map, factory->heap_number_map());
|
|
|
|
__ j(not_equal, ¬_heap_number, Label::kNear);
|
|
|
|
__ fldz();
|
|
|
|
__ fld_d(FieldOperand(argument, HeapNumber::kValueOffset));
|
|
|
|
__ FCmp();
|
|
|
|
__ j(zero, &false_result, Label::kNear);
|
2011-08-11 07:22:16 +00:00
|
|
|
// argument contains the correct return value already.
|
|
|
|
if (!tos_.is(argument)) {
|
|
|
|
__ Set(tos_, Immediate(1));
|
|
|
|
}
|
2011-07-21 13:51:04 +00:00
|
|
|
__ ret(1 * kPointerSize);
|
|
|
|
__ bind(&false_result);
|
|
|
|
__ Set(tos_, Immediate(0));
|
|
|
|
__ ret(1 * kPointerSize);
|
|
|
|
__ bind(¬_heap_number);
|
|
|
|
}
|
|
|
|
|
2011-08-11 07:22:16 +00:00
|
|
|
__ bind(&patch);
|
|
|
|
GenerateTypeTransition(masm);
|
2011-07-21 13:51:04 +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.
|
|
|
|
__ pushad();
|
|
|
|
if (save_doubles_ == kSaveFPRegs) {
|
|
|
|
CpuFeatures::Scope scope(SSE2);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters));
|
2011-09-19 18:36:47 +00:00
|
|
|
for (int i = 0; i < XMMRegister::kNumRegisters; i++) {
|
|
|
|
XMMRegister reg = XMMRegister::from_code(i);
|
|
|
|
__ movdbl(Operand(esp, i * kDoubleSize), reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const int argument_count = 1;
|
|
|
|
|
|
|
|
AllowExternalCallThatCantCauseGC scope(masm);
|
|
|
|
__ PrepareCallCFunction(argument_count, ecx);
|
|
|
|
__ mov(Operand(esp, 0 * kPointerSize),
|
|
|
|
Immediate(ExternalReference::isolate_address()));
|
|
|
|
__ CallCFunction(
|
|
|
|
ExternalReference::store_buffer_overflow_function(masm->isolate()),
|
|
|
|
argument_count);
|
|
|
|
if (save_doubles_ == kSaveFPRegs) {
|
|
|
|
CpuFeatures::Scope scope(SSE2);
|
|
|
|
for (int i = 0; i < XMMRegister::kNumRegisters; i++) {
|
|
|
|
XMMRegister reg = XMMRegister::from_code(i);
|
|
|
|
__ movdbl(reg, Operand(esp, i * kDoubleSize));
|
|
|
|
}
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters));
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
__ popad();
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-21 13:51:04 +00:00
|
|
|
void ToBooleanStub::CheckOddball(MacroAssembler* masm,
|
|
|
|
Type type,
|
2011-08-01 12:53:24 +00:00
|
|
|
Heap::RootListIndex value,
|
2011-08-11 07:22:16 +00:00
|
|
|
bool result) {
|
2011-07-21 13:51:04 +00:00
|
|
|
const Register argument = eax;
|
|
|
|
if (types_.Contains(type)) {
|
|
|
|
// If we see an expected oddball, return its ToBoolean value tos_.
|
|
|
|
Label different_value;
|
2011-08-01 12:53:24 +00:00
|
|
|
__ CompareRoot(argument, value);
|
2011-07-21 13:51:04 +00:00
|
|
|
__ j(not_equal, &different_value, Label::kNear);
|
2011-08-11 07:22:16 +00:00
|
|
|
if (!result) {
|
|
|
|
// If we have to return zero, there is no way around clearing tos_.
|
|
|
|
__ Set(tos_, Immediate(0));
|
|
|
|
} else if (!tos_.is(argument)) {
|
|
|
|
// If we have to return non-zero, we can re-use the argument if it is the
|
|
|
|
// same register as the result, because we never see Smi-zero here.
|
|
|
|
__ Set(tos_, Immediate(1));
|
|
|
|
}
|
2011-07-21 13:51:04 +00:00
|
|
|
__ ret(1 * kPointerSize);
|
|
|
|
__ bind(&different_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) {
|
|
|
|
__ pop(ecx); // Get return address, operand is now on top of stack.
|
|
|
|
__ push(Immediate(Smi::FromInt(tos_.code())));
|
2011-07-22 12:42:40 +00:00
|
|
|
__ push(Immediate(Smi::FromInt(types_.ToByte())));
|
2011-07-21 13:51:04 +00:00
|
|
|
__ push(ecx); // Push return address.
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class FloatingPointHelper : public AllStatic {
|
|
|
|
public:
|
|
|
|
enum ArgLocation {
|
|
|
|
ARGS_ON_STACK,
|
|
|
|
ARGS_IN_REGISTERS
|
|
|
|
};
|
|
|
|
|
|
|
|
// Code pattern for loading a floating point value. Input value must
|
|
|
|
// be either a smi or a heap number object (fp value). Requirements:
|
|
|
|
// operand in register number. Returns operand as floating point number
|
|
|
|
// on FPU stack.
|
|
|
|
static void LoadFloatOperand(MacroAssembler* masm, Register number);
|
|
|
|
|
|
|
|
// Code pattern for loading floating point values. Input values must
|
|
|
|
// be either smi or heap number objects (fp values). Requirements:
|
|
|
|
// operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax.
|
|
|
|
// Returns operands as floating point numbers on FPU stack.
|
|
|
|
static void LoadFloatOperands(MacroAssembler* masm,
|
|
|
|
Register scratch,
|
|
|
|
ArgLocation arg_location = ARGS_ON_STACK);
|
|
|
|
|
|
|
|
// Similar to LoadFloatOperand but assumes that both operands are smis.
|
|
|
|
// Expects operands in edx, eax.
|
|
|
|
static void LoadFloatSmis(MacroAssembler* masm, Register scratch);
|
|
|
|
|
|
|
|
// Test if operands are smi or number objects (fp). Requirements:
|
|
|
|
// operand_1 in eax, operand_2 in edx; falls through on float
|
|
|
|
// operands, jumps to the non_float label otherwise.
|
|
|
|
static void CheckFloatOperands(MacroAssembler* masm,
|
|
|
|
Label* non_float,
|
|
|
|
Register scratch);
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Checks that the two floating point numbers on top of the FPU stack
|
|
|
|
// have int32 values.
|
|
|
|
static void CheckFloatOperandsAreInt32(MacroAssembler* masm,
|
|
|
|
Label* non_int32);
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Takes the operands in edx and eax and loads them as integers in eax
|
|
|
|
// and ecx.
|
|
|
|
static void LoadUnknownsAsIntegers(MacroAssembler* masm,
|
|
|
|
bool use_sse3,
|
|
|
|
Label* operand_conversion_failure);
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Must only be called after LoadUnknownsAsIntegers. Assumes that the
|
|
|
|
// operands are pushed on the stack, and that their conversions to int32
|
|
|
|
// are in eax and ecx. Checks that the original numbers were in the int32
|
|
|
|
// range.
|
|
|
|
static void CheckLoadedIntegersWereInt32(MacroAssembler* masm,
|
|
|
|
bool use_sse3,
|
|
|
|
Label* not_int32);
|
|
|
|
|
|
|
|
// Assumes that operands are smis or heap numbers and loads them
|
|
|
|
// into xmm0 and xmm1. Operands are in edx and eax.
|
2010-08-25 09:44:44 +00:00
|
|
|
// Leaves operands unchanged.
|
|
|
|
static void LoadSSE2Operands(MacroAssembler* masm);
|
|
|
|
|
|
|
|
// Test if operands are numbers (smi or HeapNumber objects), and load
|
|
|
|
// them into xmm0 and xmm1 if they are. Jump to label not_numbers if
|
|
|
|
// either operand is not a number. Operands are in edx and eax.
|
|
|
|
// Leaves operands unchanged.
|
|
|
|
static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers);
|
|
|
|
|
|
|
|
// Similar to LoadSSE2Operands but assumes that both operands are smis.
|
|
|
|
// Expects operands in edx, eax.
|
|
|
|
static void LoadSSE2Smis(MacroAssembler* masm, Register scratch);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Checks that the two floating point numbers loaded into xmm0 and xmm1
|
|
|
|
// have int32 values.
|
|
|
|
static void CheckSSE2OperandsAreInt32(MacroAssembler* masm,
|
|
|
|
Label* non_int32,
|
|
|
|
Register scratch);
|
2010-08-25 09:44:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-04-28 17:49:55 +00:00
|
|
|
// Get the integer part of a heap number. Surprisingly, all this bit twiddling
|
|
|
|
// is faster than using the built-in instructions on floating point registers.
|
|
|
|
// Trashes edi and ebx. Dest is ecx. Source cannot be ecx or one of the
|
|
|
|
// trashed registers.
|
|
|
|
static void IntegerConvert(MacroAssembler* masm,
|
|
|
|
Register source,
|
|
|
|
bool use_sse3,
|
|
|
|
Label* conversion_failure) {
|
|
|
|
ASSERT(!source.is(ecx) && !source.is(edi) && !source.is(ebx));
|
|
|
|
Label done, right_exponent, normal_exponent;
|
|
|
|
Register scratch = ebx;
|
|
|
|
Register scratch2 = edi;
|
2011-05-11 13:45:30 +00:00
|
|
|
// Get exponent word.
|
|
|
|
__ mov(scratch, FieldOperand(source, HeapNumber::kExponentOffset));
|
|
|
|
// Get exponent alone in scratch2.
|
|
|
|
__ mov(scratch2, scratch);
|
|
|
|
__ and_(scratch2, HeapNumber::kExponentMask);
|
2011-04-28 17:49:55 +00:00
|
|
|
if (use_sse3) {
|
|
|
|
CpuFeatures::Scope scope(SSE3);
|
2011-05-11 13:45:30 +00:00
|
|
|
// Check whether the exponent is too big for a 64 bit signed integer.
|
|
|
|
static const uint32_t kTooBigExponent =
|
|
|
|
(HeapNumber::kExponentBias + 63) << HeapNumber::kExponentShift;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(scratch2, Immediate(kTooBigExponent));
|
2011-05-11 13:45:30 +00:00
|
|
|
__ j(greater_equal, conversion_failure);
|
2011-04-28 17:49:55 +00:00
|
|
|
// Load x87 register with heap number.
|
|
|
|
__ fld_d(FieldOperand(source, HeapNumber::kValueOffset));
|
|
|
|
// Reserve space for 64 bit answer.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(esp, Immediate(sizeof(uint64_t))); // Nolint.
|
2011-04-28 17:49:55 +00:00
|
|
|
// Do conversion, which cannot fail because we checked the exponent.
|
|
|
|
__ fisttp_d(Operand(esp, 0));
|
|
|
|
__ mov(ecx, Operand(esp, 0)); // Load low word of answer into ecx.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(esp, Immediate(sizeof(uint64_t))); // Nolint.
|
2011-04-28 17:49:55 +00:00
|
|
|
} else {
|
|
|
|
// Load ecx with zero. We use this either for the final shift or
|
|
|
|
// for the answer.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ xor_(ecx, ecx);
|
2011-04-28 17:49:55 +00:00
|
|
|
// Check whether the exponent matches a 32 bit signed int that cannot be
|
|
|
|
// represented by a Smi. A non-smi 32 bit integer is 1.xxx * 2^30 so the
|
|
|
|
// exponent is 30 (biased). This is the exponent that we are fastest at and
|
|
|
|
// also the highest exponent we can handle here.
|
|
|
|
const uint32_t non_smi_exponent =
|
|
|
|
(HeapNumber::kExponentBias + 30) << HeapNumber::kExponentShift;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(scratch2, Immediate(non_smi_exponent));
|
2011-04-28 17:49:55 +00:00
|
|
|
// If we have a match of the int32-but-not-Smi exponent then skip some
|
|
|
|
// logic.
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(equal, &right_exponent, Label::kNear);
|
2011-04-28 17:49:55 +00:00
|
|
|
// If the exponent is higher than that then go to slow case. This catches
|
|
|
|
// numbers that don't fit in a signed int32, infinities and NaNs.
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(less, &normal_exponent, Label::kNear);
|
2011-04-28 17:49:55 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// Handle a big exponent. The only reason we have this code is that the
|
|
|
|
// >>> operator has a tendency to generate numbers with an exponent of 31.
|
|
|
|
const uint32_t big_non_smi_exponent =
|
|
|
|
(HeapNumber::kExponentBias + 31) << HeapNumber::kExponentShift;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(scratch2, Immediate(big_non_smi_exponent));
|
2011-04-28 17:49:55 +00:00
|
|
|
__ j(not_equal, conversion_failure);
|
|
|
|
// We have the big exponent, typically from >>>. This means the number is
|
|
|
|
// in the range 2^31 to 2^32 - 1. Get the top bits of the mantissa.
|
|
|
|
__ mov(scratch2, scratch);
|
|
|
|
__ and_(scratch2, HeapNumber::kMantissaMask);
|
|
|
|
// Put back the implicit 1.
|
|
|
|
__ or_(scratch2, 1 << HeapNumber::kExponentShift);
|
|
|
|
// Shift up the mantissa bits to take up the space the exponent used to
|
|
|
|
// take. We just orred in the implicit bit so that took care of one and
|
|
|
|
// we want to use the full unsigned range so we subtract 1 bit from the
|
|
|
|
// shift distance.
|
|
|
|
const int big_shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 1;
|
|
|
|
__ shl(scratch2, big_shift_distance);
|
|
|
|
// Get the second half of the double.
|
|
|
|
__ mov(ecx, FieldOperand(source, HeapNumber::kMantissaOffset));
|
|
|
|
// Shift down 21 bits to get the most significant 11 bits or the low
|
|
|
|
// mantissa word.
|
|
|
|
__ shr(ecx, 32 - big_shift_distance);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ or_(ecx, scratch2);
|
2011-04-28 17:49:55 +00:00
|
|
|
// We have the answer in ecx, but we may need to negate it.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(scratch, scratch);
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(positive, &done, Label::kNear);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ neg(ecx);
|
2011-08-26 08:22:13 +00:00
|
|
|
__ jmp(&done, Label::kNear);
|
2011-04-28 17:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&normal_exponent);
|
|
|
|
// Exponent word in scratch, exponent part of exponent word in scratch2.
|
|
|
|
// Zero in ecx.
|
|
|
|
// We know the exponent is smaller than 30 (biased). If it is less than
|
|
|
|
// 0 (biased) then the number is smaller in magnitude than 1.0 * 2^0, ie
|
|
|
|
// it rounds to zero.
|
|
|
|
const uint32_t zero_exponent =
|
|
|
|
(HeapNumber::kExponentBias + 0) << HeapNumber::kExponentShift;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(scratch2, Immediate(zero_exponent));
|
2011-04-28 17:49:55 +00:00
|
|
|
// ecx already has a Smi zero.
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(less, &done, Label::kNear);
|
2011-04-28 17:49:55 +00:00
|
|
|
|
|
|
|
// We have a shifted exponent between 0 and 30 in scratch2.
|
|
|
|
__ shr(scratch2, HeapNumber::kExponentShift);
|
|
|
|
__ mov(ecx, Immediate(30));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(ecx, scratch2);
|
2011-04-28 17:49:55 +00:00
|
|
|
|
|
|
|
__ bind(&right_exponent);
|
|
|
|
// Here ecx is the shift, scratch is the exponent word.
|
|
|
|
// Get the top bits of the mantissa.
|
|
|
|
__ and_(scratch, HeapNumber::kMantissaMask);
|
|
|
|
// Put back the implicit 1.
|
|
|
|
__ or_(scratch, 1 << HeapNumber::kExponentShift);
|
|
|
|
// Shift up the mantissa bits to take up the space the exponent used to
|
|
|
|
// take. We have kExponentShift + 1 significant bits int he low end of the
|
|
|
|
// word. Shift them to the top bits.
|
|
|
|
const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2;
|
|
|
|
__ shl(scratch, shift_distance);
|
|
|
|
// Get the second half of the double. For some exponents we don't
|
|
|
|
// actually need this because the bits get shifted out again, but
|
|
|
|
// it's probably slower to test than just to do it.
|
|
|
|
__ mov(scratch2, FieldOperand(source, HeapNumber::kMantissaOffset));
|
|
|
|
// Shift down 22 bits to get the most significant 10 bits or the low
|
|
|
|
// mantissa word.
|
|
|
|
__ shr(scratch2, 32 - shift_distance);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ or_(scratch2, scratch);
|
2011-04-28 17:49:55 +00:00
|
|
|
// Move down according to the exponent.
|
|
|
|
__ shr_cl(scratch2);
|
|
|
|
// Now the unsigned answer is in scratch2. We need to move it to ecx and
|
|
|
|
// we may need to fix the sign.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label negative;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ xor_(ecx, ecx);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ cmp(ecx, FieldOperand(source, HeapNumber::kExponentOffset));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(greater, &negative, Label::kNear);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ mov(ecx, scratch2);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ jmp(&done, Label::kNear);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ bind(&negative);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(ecx, scratch2);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ bind(&done);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2011-05-24 12:20:16 +00:00
|
|
|
case UnaryOpIC::HEAP_NUMBER:
|
2011-04-28 17:49:55 +00:00
|
|
|
GenerateHeapNumberStub(masm);
|
|
|
|
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-04-28 17:49:55 +00:00
|
|
|
__ pop(ecx); // Save return address.
|
2011-07-01 07:50:46 +00:00
|
|
|
|
|
|
|
__ push(eax); // the operand
|
2011-04-28 17:49:55 +00:00
|
|
|
__ push(Immediate(Smi::FromInt(op_)));
|
2011-07-01 07:50:46 +00:00
|
|
|
__ push(Immediate(Smi::FromInt(mode_)));
|
2011-04-28 17:49:55 +00:00
|
|
|
__ push(Immediate(Smi::FromInt(operand_type_)));
|
|
|
|
|
|
|
|
__ push(ecx); // Push return address.
|
|
|
|
|
|
|
|
// Patch the caller to an appropriate specialized stub and return the
|
|
|
|
// operation result to the caller of the stub.
|
|
|
|
__ 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-05-11 09:12:16 +00:00
|
|
|
Label non_smi, undo, slow;
|
|
|
|
GenerateSmiCodeSub(masm, &non_smi, &undo, &slow,
|
|
|
|
Label::kNear, Label::kNear, Label::kNear);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ bind(&undo);
|
|
|
|
GenerateSmiCodeUndo(masm);
|
|
|
|
__ bind(&non_smi);
|
|
|
|
__ bind(&slow);
|
|
|
|
GenerateTypeTransition(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) {
|
2011-05-11 09:12:16 +00:00
|
|
|
Label non_smi;
|
2011-04-28 17:49:55 +00:00
|
|
|
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* undo,
|
|
|
|
Label* slow,
|
|
|
|
Label::Distance non_smi_near,
|
|
|
|
Label::Distance undo_near,
|
|
|
|
Label::Distance slow_near) {
|
2011-04-28 17:49:55 +00:00
|
|
|
// Check whether the value is a smi.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(eax, non_smi, non_smi_near);
|
2011-04-28 17:49:55 +00:00
|
|
|
|
|
|
|
// We can't handle -0 with smis, so use a type transition for that case.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(eax, eax);
|
2011-05-11 09:12:16 +00:00
|
|
|
__ j(zero, slow, slow_near);
|
2011-04-28 17:49:55 +00:00
|
|
|
|
|
|
|
// Try optimistic subtraction '0 - value', saving operand in eax for undo.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(edx, eax);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ Set(eax, Immediate(0));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(eax, edx);
|
2011-05-11 09:12:16 +00:00
|
|
|
__ j(overflow, undo, undo_near);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateSmiCodeBitNot(
|
2011-05-11 09:12:16 +00:00
|
|
|
MacroAssembler* masm,
|
|
|
|
Label* non_smi,
|
|
|
|
Label::Distance non_smi_near) {
|
2011-04-28 17:49:55 +00:00
|
|
|
// Check whether the value is a smi.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(eax, non_smi, non_smi_near);
|
2011-04-28 17:49:55 +00:00
|
|
|
|
|
|
|
// Flip bits and revert inverted smi-tag.
|
|
|
|
__ not_(eax);
|
|
|
|
__ and_(eax, ~kSmiTagMask);
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateSmiCodeUndo(MacroAssembler* masm) {
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(eax, edx);
|
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::GenerateHeapNumberStub(MacroAssembler* masm) {
|
2011-04-28 17:49:55 +00:00
|
|
|
switch (op_) {
|
|
|
|
case Token::SUB:
|
|
|
|
GenerateHeapNumberStubSub(masm);
|
|
|
|
break;
|
|
|
|
case Token::BIT_NOT:
|
|
|
|
GenerateHeapNumberStubBitNot(masm);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) {
|
2011-05-18 17:32:36 +00:00
|
|
|
Label non_smi, undo, slow, call_builtin;
|
|
|
|
GenerateSmiCodeSub(masm, &non_smi, &undo, &call_builtin, Label::kNear);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ bind(&non_smi);
|
|
|
|
GenerateHeapNumberCodeSub(masm, &slow);
|
|
|
|
__ bind(&undo);
|
|
|
|
GenerateSmiCodeUndo(masm);
|
|
|
|
__ 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateHeapNumberStubBitNot(
|
2011-04-28 17:49:55 +00:00
|
|
|
MacroAssembler* masm) {
|
2011-05-11 09:12:16 +00:00
|
|
|
Label non_smi, slow;
|
|
|
|
GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ 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
|
|
|
__ mov(edx, FieldOperand(eax, HeapObject::kMapOffset));
|
|
|
|
__ cmp(edx, masm->isolate()->factory()->heap_number_map());
|
|
|
|
__ j(not_equal, slow);
|
|
|
|
|
|
|
|
if (mode_ == UNARY_OVERWRITE) {
|
2011-05-02 12:55:44 +00:00
|
|
|
__ xor_(FieldOperand(eax, HeapNumber::kExponentOffset),
|
|
|
|
Immediate(HeapNumber::kSignMask)); // Flip sign.
|
2011-04-28 17:49:55 +00:00
|
|
|
} else {
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(edx, eax);
|
2011-04-28 17:49:55 +00:00
|
|
|
// edx: operand
|
|
|
|
|
|
|
|
Label slow_allocate_heapnumber, heapnumber_allocated;
|
|
|
|
__ AllocateHeapNumber(eax, ebx, ecx, &slow_allocate_heapnumber);
|
2011-08-26 08:22:13 +00:00
|
|
|
__ jmp(&heapnumber_allocated, Label::kNear);
|
2011-04-28 17:49:55 +00:00
|
|
|
|
|
|
|
__ bind(&slow_allocate_heapnumber);
|
2011-09-15 11:30:45 +00:00
|
|
|
{
|
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
|
|
|
__ push(edx);
|
|
|
|
__ CallRuntime(Runtime::kNumberAlloc, 0);
|
|
|
|
__ pop(edx);
|
|
|
|
}
|
2011-04-28 17:49:55 +00:00
|
|
|
|
|
|
|
__ bind(&heapnumber_allocated);
|
|
|
|
// eax: allocated 'empty' number
|
|
|
|
__ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset));
|
|
|
|
__ xor_(ecx, HeapNumber::kSignMask); // Flip sign.
|
|
|
|
__ mov(FieldOperand(eax, HeapNumber::kExponentOffset), ecx);
|
|
|
|
__ mov(ecx, FieldOperand(edx, HeapNumber::kMantissaOffset));
|
|
|
|
__ mov(FieldOperand(eax, HeapNumber::kMantissaOffset), ecx);
|
|
|
|
}
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm,
|
|
|
|
Label* slow) {
|
2011-04-28 17:49:55 +00:00
|
|
|
__ mov(edx, FieldOperand(eax, HeapObject::kMapOffset));
|
|
|
|
__ cmp(edx, masm->isolate()->factory()->heap_number_map());
|
|
|
|
__ j(not_equal, slow);
|
|
|
|
|
|
|
|
// Convert the heap number in eax to an untagged integer in ecx.
|
2011-05-11 13:45:30 +00:00
|
|
|
IntegerConvert(masm, eax, CpuFeatures::IsSupported(SSE3), slow);
|
2011-04-28 17:49:55 +00:00
|
|
|
|
|
|
|
// Do the bitwise operation and check if the result fits in a smi.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label try_float;
|
2011-04-28 17:49:55 +00:00
|
|
|
__ not_(ecx);
|
|
|
|
__ cmp(ecx, 0xc0000000);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(sign, &try_float, Label::kNear);
|
2011-04-28 17:49:55 +00:00
|
|
|
|
|
|
|
// Tag the result as a smi and we're done.
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
__ lea(eax, Operand(ecx, times_2, kSmiTag));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Try to store the result in a heap number.
|
|
|
|
__ bind(&try_float);
|
|
|
|
if (mode_ == UNARY_NO_OVERWRITE) {
|
|
|
|
Label slow_allocate_heapnumber, heapnumber_allocated;
|
2011-05-18 07:40:51 +00:00
|
|
|
__ mov(ebx, eax);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ AllocateHeapNumber(eax, edx, edi, &slow_allocate_heapnumber);
|
|
|
|
__ jmp(&heapnumber_allocated);
|
|
|
|
|
|
|
|
__ bind(&slow_allocate_heapnumber);
|
2011-09-15 11:30:45 +00:00
|
|
|
{
|
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
|
|
|
// Push the original HeapNumber on the stack. The integer value can't
|
|
|
|
// be stored since it's untagged and not in the smi range (so we can't
|
|
|
|
// smi-tag it). We'll recalculate the value after the GC instead.
|
|
|
|
__ push(ebx);
|
|
|
|
__ CallRuntime(Runtime::kNumberAlloc, 0);
|
|
|
|
// New HeapNumber is in eax.
|
|
|
|
__ pop(edx);
|
|
|
|
}
|
2011-05-18 07:40:51 +00:00
|
|
|
// IntegerConvert uses ebx and edi as scratch registers.
|
|
|
|
// This conversion won't go slow-case.
|
|
|
|
IntegerConvert(masm, edx, CpuFeatures::IsSupported(SSE3), slow);
|
|
|
|
__ not_(ecx);
|
2011-04-28 17:49:55 +00:00
|
|
|
|
|
|
|
__ bind(&heapnumber_allocated);
|
|
|
|
}
|
|
|
|
if (CpuFeatures::IsSupported(SSE2)) {
|
|
|
|
CpuFeatures::Scope use_sse2(SSE2);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm0, ecx);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0);
|
|
|
|
} else {
|
|
|
|
__ push(ecx);
|
|
|
|
__ fild_s(Operand(esp, 0));
|
|
|
|
__ pop(ecx);
|
|
|
|
__ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
}
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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-05-11 09:12:16 +00:00
|
|
|
Label non_smi, undo, slow;
|
|
|
|
GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, Label::kNear);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ bind(&non_smi);
|
|
|
|
GenerateHeapNumberCodeSub(masm, &slow);
|
|
|
|
__ bind(&undo);
|
|
|
|
GenerateSmiCodeUndo(masm);
|
|
|
|
__ bind(&slow);
|
|
|
|
GenerateGenericCodeFallback(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) {
|
2011-05-11 09:12:16 +00:00
|
|
|
Label non_smi, slow;
|
|
|
|
GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear);
|
2011-04-28 17:49:55 +00:00
|
|
|
__ 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 corresponding JavaScript builtin.
|
|
|
|
__ pop(ecx); // pop return address.
|
|
|
|
__ push(eax);
|
|
|
|
__ push(ecx); // push return address
|
|
|
|
switch (op_) {
|
|
|
|
case Token::SUB:
|
|
|
|
__ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::BIT_NOT:
|
|
|
|
__ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) {
|
2010-12-07 11:31:57 +00:00
|
|
|
__ pop(ecx); // Save return address.
|
|
|
|
__ push(edx);
|
|
|
|
__ push(eax);
|
|
|
|
// Left and right arguments are now on top.
|
|
|
|
// Push this stub's key. Although the operation and the type info are
|
|
|
|
// encoded into the key, the encoding is opaque, so push them too.
|
|
|
|
__ push(Immediate(Smi::FromInt(MinorKey())));
|
|
|
|
__ push(Immediate(Smi::FromInt(op_)));
|
|
|
|
__ push(Immediate(Smi::FromInt(operands_type_)));
|
|
|
|
|
|
|
|
__ push(ecx); // Push return address.
|
|
|
|
|
|
|
|
// Patch the caller to an appropriate specialized stub and return the
|
|
|
|
// operation result to the caller of the stub.
|
|
|
|
__ 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()),
|
2010-12-07 11:31:57 +00:00
|
|
|
5,
|
|
|
|
1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Prepare for a type transition runtime call when the args are already on
|
|
|
|
// the stack, under the return address.
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) {
|
2010-12-07 11:31:57 +00:00
|
|
|
__ pop(ecx); // Save return address.
|
|
|
|
// Left and right arguments are already on top of the stack.
|
|
|
|
// Push this stub's key. Although the operation and the type info are
|
|
|
|
// encoded into the key, the encoding is opaque, so push them too.
|
|
|
|
__ push(Immediate(Smi::FromInt(MinorKey())));
|
|
|
|
__ push(Immediate(Smi::FromInt(op_)));
|
|
|
|
__ push(Immediate(Smi::FromInt(operands_type_)));
|
|
|
|
|
|
|
|
__ push(ecx); // Push return address.
|
|
|
|
|
|
|
|
// Patch the caller to an appropriate specialized stub and return the
|
|
|
|
// operation result to the caller of the stub.
|
|
|
|
__ 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()),
|
2010-12-07 11:31:57 +00:00
|
|
|
5,
|
|
|
|
1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::Generate(MacroAssembler* masm) {
|
2011-09-27 10:53:22 +00:00
|
|
|
// Explicitly allow generation of nested stubs. It is safe here because
|
|
|
|
// generation code does not use any raw pointers.
|
|
|
|
AllowStubCallsScope allow_stub_calls(masm, true);
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
switch (operands_type_) {
|
2011-05-24 12:20:16 +00:00
|
|
|
case BinaryOpIC::UNINITIALIZED:
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateTypeTransition(masm);
|
|
|
|
break;
|
2011-05-24 12:20:16 +00:00
|
|
|
case BinaryOpIC::SMI:
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateSmiStub(masm);
|
|
|
|
break;
|
2011-05-24 12:20:16 +00:00
|
|
|
case BinaryOpIC::INT32:
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateInt32Stub(masm);
|
|
|
|
break;
|
2011-05-24 12:20:16 +00:00
|
|
|
case BinaryOpIC::HEAP_NUMBER:
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateHeapNumberStub(masm);
|
|
|
|
break;
|
2011-05-24 12:20:16 +00:00
|
|
|
case BinaryOpIC::ODDBALL:
|
2011-03-28 16:36:08 +00:00
|
|
|
GenerateOddballStub(masm);
|
|
|
|
break;
|
2011-05-24 12:20:16 +00:00
|
|
|
case BinaryOpIC::BOTH_STRING:
|
2011-04-15 06:39:36 +00:00
|
|
|
GenerateBothStringStub(masm);
|
|
|
|
break;
|
2011-05-24 12:20:16 +00:00
|
|
|
case BinaryOpIC::STRING:
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateStringStub(masm);
|
|
|
|
break;
|
2011-05-24 12:20:16 +00:00
|
|
|
case BinaryOpIC::GENERIC:
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateGeneric(masm);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-13 11:08:25 +00:00
|
|
|
void BinaryOpStub::PrintName(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
const char* op_name = Token::Name(op_);
|
|
|
|
const char* overwrite_name;
|
|
|
|
switch (mode_) {
|
|
|
|
case NO_OVERWRITE: overwrite_name = "Alloc"; break;
|
|
|
|
case OVERWRITE_RIGHT: overwrite_name = "OverwriteRight"; break;
|
|
|
|
case OVERWRITE_LEFT: overwrite_name = "OverwriteLeft"; break;
|
|
|
|
default: overwrite_name = "UnknownOverwrite"; break;
|
|
|
|
}
|
2011-07-13 11:08:25 +00:00
|
|
|
stream->Add("BinaryOpStub_%s_%s_%s",
|
|
|
|
op_name,
|
|
|
|
overwrite_name,
|
|
|
|
BinaryOpIC::GetName(operands_type_));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateSmiCode(
|
|
|
|
MacroAssembler* masm,
|
2010-12-07 11:31:57 +00:00
|
|
|
Label* slow,
|
|
|
|
SmiCodeGenerateHeapNumberResults allow_heapnumber_results) {
|
|
|
|
// 1. Move arguments into edx, eax except for DIV and MOD, which need the
|
|
|
|
// dividend in eax and edx free for the division. Use eax, ebx for those.
|
|
|
|
Comment load_comment(masm, "-- Load arguments");
|
|
|
|
Register left = edx;
|
|
|
|
Register right = eax;
|
|
|
|
if (op_ == Token::DIV || op_ == Token::MOD) {
|
|
|
|
left = eax;
|
|
|
|
right = ebx;
|
2010-12-15 13:56:41 +00:00
|
|
|
__ mov(ebx, eax);
|
|
|
|
__ mov(eax, edx);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Prepare the smi check of both operands by oring them together.
|
|
|
|
Comment smi_check_comment(masm, "-- Smi check arguments");
|
|
|
|
Label not_smis;
|
|
|
|
Register combined = ecx;
|
|
|
|
ASSERT(!left.is(combined) && !right.is(combined));
|
|
|
|
switch (op_) {
|
|
|
|
case Token::BIT_OR:
|
|
|
|
// Perform the operation into eax and smi check the result. Preserve
|
|
|
|
// eax in case the result is not a smi.
|
|
|
|
ASSERT(!left.is(ecx) && !right.is(ecx));
|
|
|
|
__ mov(ecx, right);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ or_(right, left); // Bitwise or is commutative.
|
2010-12-07 11:31:57 +00:00
|
|
|
combined = right;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
case Token::BIT_AND:
|
|
|
|
case Token::ADD:
|
|
|
|
case Token::SUB:
|
|
|
|
case Token::MUL:
|
|
|
|
case Token::DIV:
|
|
|
|
case Token::MOD:
|
|
|
|
__ mov(combined, right);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ or_(combined, left);
|
2010-12-07 11:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::SHL:
|
|
|
|
case Token::SAR:
|
|
|
|
case Token::SHR:
|
|
|
|
// Move the right operand into ecx for the shift operation, use eax
|
|
|
|
// for the smi check register.
|
|
|
|
ASSERT(!left.is(ecx) && !right.is(ecx));
|
|
|
|
__ mov(ecx, right);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ or_(right, left);
|
2010-12-07 11:31:57 +00:00
|
|
|
combined = right;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3. Perform the smi check of the operands.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(combined, ¬_smis);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// 4. Operands are both smis, perform the operation leaving the result in
|
|
|
|
// eax and check the result if necessary.
|
|
|
|
Comment perform_smi(masm, "-- Perform smi operation");
|
|
|
|
Label use_fp_on_smis;
|
|
|
|
switch (op_) {
|
|
|
|
case Token::BIT_OR:
|
|
|
|
// Nothing to do.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
ASSERT(right.is(eax));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ xor_(right, left); // Bitwise xor is commutative.
|
2010-12-07 11:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::BIT_AND:
|
|
|
|
ASSERT(right.is(eax));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ and_(right, left); // Bitwise and is commutative.
|
2010-12-07 11:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::SHL:
|
|
|
|
// Remove tags from operands (but keep sign).
|
|
|
|
__ SmiUntag(left);
|
|
|
|
__ SmiUntag(ecx);
|
|
|
|
// Perform the operation.
|
|
|
|
__ shl_cl(left);
|
|
|
|
// Check that the *signed* result fits in a smi.
|
|
|
|
__ cmp(left, 0xc0000000);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(sign, &use_fp_on_smis);
|
2010-12-07 11:31:57 +00:00
|
|
|
// Tag the result and store it in register eax.
|
|
|
|
__ SmiTag(left);
|
|
|
|
__ mov(eax, left);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::SAR:
|
|
|
|
// Remove tags from operands (but keep sign).
|
|
|
|
__ SmiUntag(left);
|
|
|
|
__ SmiUntag(ecx);
|
|
|
|
// Perform the operation.
|
|
|
|
__ sar_cl(left);
|
|
|
|
// Tag the result and store it in register eax.
|
|
|
|
__ SmiTag(left);
|
|
|
|
__ mov(eax, left);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::SHR:
|
|
|
|
// Remove tags from operands (but keep sign).
|
|
|
|
__ SmiUntag(left);
|
|
|
|
__ SmiUntag(ecx);
|
|
|
|
// Perform the operation.
|
|
|
|
__ shr_cl(left);
|
|
|
|
// Check that the *unsigned* result fits in a smi.
|
|
|
|
// Neither of the two high-order bits can be set:
|
|
|
|
// - 0x80000000: high bit would be lost when smi tagging.
|
|
|
|
// - 0x40000000: this number would convert to negative when
|
|
|
|
// Smi tagging these two cases can only happen with shifts
|
|
|
|
// by 0 or 1 when handed a valid smi.
|
|
|
|
__ test(left, Immediate(0xc0000000));
|
2011-05-18 14:53:02 +00:00
|
|
|
__ j(not_zero, &use_fp_on_smis);
|
2010-12-07 11:31:57 +00:00
|
|
|
// Tag the result and store it in register eax.
|
|
|
|
__ SmiTag(left);
|
|
|
|
__ mov(eax, left);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::ADD:
|
|
|
|
ASSERT(right.is(eax));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(right, left); // Addition is commutative.
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(overflow, &use_fp_on_smis);
|
2010-12-07 11:31:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::SUB:
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(left, right);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(overflow, &use_fp_on_smis);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ mov(eax, left);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::MUL:
|
|
|
|
// If the smi tag is 0 we can just leave the tag on one operand.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case.
|
|
|
|
// We can't revert the multiplication if the result is not a smi
|
|
|
|
// so save the right operand.
|
|
|
|
__ mov(ebx, right);
|
|
|
|
// Remove tag from one of the operands (but keep sign).
|
|
|
|
__ SmiUntag(right);
|
|
|
|
// Do multiplication.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ imul(right, left); // Multiplication is commutative.
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(overflow, &use_fp_on_smis);
|
2010-12-07 11:31:57 +00:00
|
|
|
// Check for negative zero result. Use combined = left | right.
|
|
|
|
__ NegativeZeroTest(right, combined, &use_fp_on_smis);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::DIV:
|
|
|
|
// We can't revert the division if the result is not a smi so
|
|
|
|
// save the left operand.
|
|
|
|
__ mov(edi, left);
|
|
|
|
// Check for 0 divisor.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(right, right);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(zero, &use_fp_on_smis);
|
2010-12-07 11:31:57 +00:00
|
|
|
// Sign extend left into edx:eax.
|
|
|
|
ASSERT(left.is(eax));
|
|
|
|
__ cdq();
|
|
|
|
// Divide edx:eax by right.
|
|
|
|
__ idiv(right);
|
|
|
|
// Check for the corner case of dividing the most negative smi by
|
|
|
|
// -1. We cannot use the overflow flag, since it is not set by idiv
|
|
|
|
// instruction.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1);
|
|
|
|
__ cmp(eax, 0x40000000);
|
|
|
|
__ j(equal, &use_fp_on_smis);
|
|
|
|
// Check for negative zero result. Use combined = left | right.
|
|
|
|
__ NegativeZeroTest(eax, combined, &use_fp_on_smis);
|
|
|
|
// Check that the remainder is zero.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(edx, edx);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ j(not_zero, &use_fp_on_smis);
|
|
|
|
// Tag the result and store it in register eax.
|
|
|
|
__ SmiTag(eax);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::MOD:
|
|
|
|
// Check for 0 divisor.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(right, right);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(zero, ¬_smis);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Sign extend left into edx:eax.
|
|
|
|
ASSERT(left.is(eax));
|
|
|
|
__ cdq();
|
|
|
|
// Divide edx:eax by right.
|
|
|
|
__ idiv(right);
|
|
|
|
// Check for negative zero result. Use combined = left | right.
|
|
|
|
__ NegativeZeroTest(edx, combined, slow);
|
|
|
|
// Move remainder to register eax.
|
|
|
|
__ mov(eax, edx);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 5. Emit return of result in eax. Some operations have registers pushed.
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD:
|
|
|
|
case Token::SUB:
|
|
|
|
case Token::MUL:
|
|
|
|
case Token::DIV:
|
|
|
|
__ ret(0);
|
|
|
|
break;
|
|
|
|
case Token::MOD:
|
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_AND:
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
case Token::SAR:
|
|
|
|
case Token::SHL:
|
|
|
|
case Token::SHR:
|
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 6. For some operations emit inline code to perform floating point
|
|
|
|
// operations on known smis (e.g., if the result of the operation
|
|
|
|
// overflowed the smi range).
|
|
|
|
if (allow_heapnumber_results == NO_HEAPNUMBER_RESULTS) {
|
|
|
|
__ bind(&use_fp_on_smis);
|
|
|
|
switch (op_) {
|
|
|
|
// Undo the effects of some operations, and some register moves.
|
|
|
|
case Token::SHL:
|
|
|
|
// The arguments are saved on the stack, and only used from there.
|
|
|
|
break;
|
|
|
|
case Token::ADD:
|
|
|
|
// Revert right = right + left.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(right, left);
|
2010-12-07 11:31:57 +00:00
|
|
|
break;
|
|
|
|
case Token::SUB:
|
|
|
|
// Revert left = left - right.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(left, right);
|
2010-12-07 11:31:57 +00:00
|
|
|
break;
|
|
|
|
case Token::MUL:
|
|
|
|
// Right was clobbered but a copy is in ebx.
|
|
|
|
__ mov(right, ebx);
|
|
|
|
break;
|
|
|
|
case Token::DIV:
|
|
|
|
// Left was clobbered but a copy is in edi. Right is in ebx for
|
|
|
|
// division. They should be in eax, ebx for jump to not_smi.
|
|
|
|
__ mov(eax, edi);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// No other operators jump to use_fp_on_smis.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
__ jmp(¬_smis);
|
|
|
|
} else {
|
|
|
|
ASSERT(allow_heapnumber_results == ALLOW_HEAPNUMBER_RESULTS);
|
|
|
|
switch (op_) {
|
2011-05-18 14:53:02 +00:00
|
|
|
case Token::SHL:
|
|
|
|
case Token::SHR: {
|
2010-12-07 11:31:57 +00:00
|
|
|
Comment perform_float(masm, "-- Perform float operation on smis");
|
|
|
|
__ bind(&use_fp_on_smis);
|
|
|
|
// Result we want is in left == edx, so we can put the allocated heap
|
|
|
|
// number in eax.
|
|
|
|
__ AllocateHeapNumber(eax, ecx, ebx, slow);
|
|
|
|
// Store the result in the HeapNumber and return.
|
2011-05-18 14:53:02 +00:00
|
|
|
// It's OK to overwrite the arguments on the stack because we
|
|
|
|
// are about to return.
|
|
|
|
if (op_ == Token::SHR) {
|
2010-12-07 11:31:57 +00:00
|
|
|
__ mov(Operand(esp, 1 * kPointerSize), left);
|
2011-05-18 14:53:02 +00:00
|
|
|
__ mov(Operand(esp, 2 * kPointerSize), Immediate(0));
|
|
|
|
__ fild_d(Operand(esp, 1 * kPointerSize));
|
2010-12-07 11:31:57 +00:00
|
|
|
__ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset));
|
2011-05-18 14:53:02 +00:00
|
|
|
} else {
|
|
|
|
ASSERT_EQ(Token::SHL, op_);
|
|
|
|
if (CpuFeatures::IsSupported(SSE2)) {
|
|
|
|
CpuFeatures::Scope use_sse2(SSE2);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm0, left);
|
2011-05-18 14:53:02 +00:00
|
|
|
__ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0);
|
|
|
|
} else {
|
|
|
|
__ mov(Operand(esp, 1 * kPointerSize), left);
|
|
|
|
__ fild_s(Operand(esp, 1 * kPointerSize));
|
|
|
|
__ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2011-05-18 14:53:02 +00:00
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
break;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case Token::ADD:
|
|
|
|
case Token::SUB:
|
|
|
|
case Token::MUL:
|
|
|
|
case Token::DIV: {
|
|
|
|
Comment perform_float(masm, "-- Perform float operation on smis");
|
|
|
|
__ bind(&use_fp_on_smis);
|
|
|
|
// Restore arguments to edx, eax.
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD:
|
|
|
|
// Revert right = right + left.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(right, left);
|
2010-12-07 11:31:57 +00:00
|
|
|
break;
|
|
|
|
case Token::SUB:
|
|
|
|
// Revert left = left - right.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(left, right);
|
2010-12-07 11:31:57 +00:00
|
|
|
break;
|
|
|
|
case Token::MUL:
|
|
|
|
// Right was clobbered but a copy is in ebx.
|
|
|
|
__ mov(right, ebx);
|
|
|
|
break;
|
|
|
|
case Token::DIV:
|
|
|
|
// Left was clobbered but a copy is in edi. Right is in ebx for
|
|
|
|
// division.
|
|
|
|
__ mov(edx, edi);
|
|
|
|
__ mov(eax, right);
|
|
|
|
break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
__ AllocateHeapNumber(ecx, ebx, no_reg, slow);
|
2011-03-31 16:17:37 +00:00
|
|
|
if (CpuFeatures::IsSupported(SSE2)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
CpuFeatures::Scope use_sse2(SSE2);
|
|
|
|
FloatingPointHelper::LoadSSE2Smis(masm, ebx);
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD: __ addsd(xmm0, xmm1); break;
|
|
|
|
case Token::SUB: __ subsd(xmm0, xmm1); break;
|
|
|
|
case Token::MUL: __ mulsd(xmm0, xmm1); break;
|
|
|
|
case Token::DIV: __ divsd(xmm0, xmm1); break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
__ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0);
|
|
|
|
} else { // SSE2 not available, use FPU.
|
|
|
|
FloatingPointHelper::LoadFloatSmis(masm, ebx);
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD: __ faddp(1); break;
|
|
|
|
case Token::SUB: __ fsubp(1); break;
|
|
|
|
case Token::MUL: __ fmulp(1); break;
|
|
|
|
case Token::DIV: __ fdivp(1); break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
__ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset));
|
|
|
|
}
|
|
|
|
__ mov(eax, ecx);
|
|
|
|
__ ret(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 7. Non-smi operands, fall out to the non-smi code with the operands in
|
|
|
|
// edx and eax.
|
|
|
|
Comment done_comment(masm, "-- Enter non-smi code");
|
|
|
|
__ bind(¬_smis);
|
|
|
|
switch (op_) {
|
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::SHL:
|
|
|
|
case Token::SAR:
|
|
|
|
case Token::SHR:
|
|
|
|
// Right operand is saved in ecx and eax was destroyed by the smi
|
|
|
|
// check.
|
|
|
|
__ mov(eax, ecx);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::DIV:
|
|
|
|
case Token::MOD:
|
|
|
|
// Operands are in eax, ebx at this point.
|
|
|
|
__ mov(edx, eax);
|
|
|
|
__ mov(eax, ebx);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) {
|
2010-12-07 11:31:57 +00:00
|
|
|
Label call_runtime;
|
|
|
|
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD:
|
|
|
|
case Token::SUB:
|
|
|
|
case Token::MUL:
|
|
|
|
case Token::DIV:
|
|
|
|
break;
|
|
|
|
case Token::MOD:
|
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_AND:
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
case Token::SAR:
|
|
|
|
case Token::SHL:
|
|
|
|
case Token::SHR:
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
if (result_type_ == BinaryOpIC::UNINITIALIZED ||
|
|
|
|
result_type_ == BinaryOpIC::SMI) {
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateSmiCode(masm, &call_runtime, NO_HEAPNUMBER_RESULTS);
|
|
|
|
} else {
|
|
|
|
GenerateSmiCode(masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS);
|
|
|
|
}
|
|
|
|
__ bind(&call_runtime);
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD:
|
|
|
|
case Token::SUB:
|
|
|
|
case Token::MUL:
|
|
|
|
case Token::DIV:
|
|
|
|
GenerateTypeTransition(masm);
|
|
|
|
break;
|
|
|
|
case Token::MOD:
|
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_AND:
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
case Token::SAR:
|
|
|
|
case Token::SHL:
|
|
|
|
case Token::SHR:
|
|
|
|
GenerateTypeTransitionWithSavedArgs(masm);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateStringStub(MacroAssembler* masm) {
|
|
|
|
ASSERT(operands_type_ == BinaryOpIC::STRING);
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(op_ == Token::ADD);
|
2011-01-25 12:14:56 +00:00
|
|
|
// Try to add arguments as strings, otherwise, transition to the generic
|
2011-05-24 12:20:16 +00:00
|
|
|
// BinaryOpIC type.
|
2011-01-25 12:14:56 +00:00
|
|
|
GenerateAddStrings(masm);
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateTypeTransition(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;
|
2011-05-24 12:20:16 +00:00
|
|
|
ASSERT(operands_type_ == BinaryOpIC::BOTH_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 = edx;
|
|
|
|
Register right = eax;
|
|
|
|
|
|
|
|
// Test if left operand is a string.
|
2011-08-26 08:22:13 +00:00
|
|
|
__ JumpIfSmi(left, &call_runtime, Label::kNear);
|
2011-04-15 06:39:36 +00:00
|
|
|
__ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx);
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(above_equal, &call_runtime, Label::kNear);
|
2011-04-15 06:39:36 +00:00
|
|
|
|
|
|
|
// Test if right operand is a string.
|
2011-08-26 08:22:13 +00:00
|
|
|
__ JumpIfSmi(right, &call_runtime, Label::kNear);
|
2011-04-15 06:39:36 +00:00
|
|
|
__ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx);
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(above_equal, &call_runtime, Label::kNear);
|
2011-04-15 06:39:36 +00:00
|
|
|
|
|
|
|
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) {
|
2010-12-07 11:31:57 +00:00
|
|
|
Label call_runtime;
|
2011-05-24 12:20:16 +00:00
|
|
|
ASSERT(operands_type_ == BinaryOpIC::INT32);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Floating point case.
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD:
|
|
|
|
case Token::SUB:
|
|
|
|
case Token::MUL:
|
|
|
|
case Token::DIV: {
|
|
|
|
Label not_floats;
|
|
|
|
Label not_int32;
|
2011-03-31 16:17:37 +00:00
|
|
|
if (CpuFeatures::IsSupported(SSE2)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
CpuFeatures::Scope use_sse2(SSE2);
|
|
|
|
FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats);
|
|
|
|
FloatingPointHelper::CheckSSE2OperandsAreInt32(masm, ¬_int32, ecx);
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD: __ addsd(xmm0, xmm1); break;
|
|
|
|
case Token::SUB: __ subsd(xmm0, xmm1); break;
|
|
|
|
case Token::MUL: __ mulsd(xmm0, xmm1); break;
|
|
|
|
case Token::DIV: __ divsd(xmm0, xmm1); break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
// Check result type if it is currently Int32.
|
2011-05-24 12:20:16 +00:00
|
|
|
if (result_type_ <= BinaryOpIC::INT32) {
|
2010-12-07 11:31:57 +00:00
|
|
|
__ cvttsd2si(ecx, Operand(xmm0));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm2, ecx);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ ucomisd(xmm0, xmm2);
|
|
|
|
__ j(not_zero, ¬_int32);
|
|
|
|
__ j(carry, ¬_int32);
|
|
|
|
}
|
|
|
|
GenerateHeapResultAllocation(masm, &call_runtime);
|
|
|
|
__ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0);
|
|
|
|
__ ret(0);
|
|
|
|
} else { // SSE2 not available, use FPU.
|
|
|
|
FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx);
|
|
|
|
FloatingPointHelper::LoadFloatOperands(
|
|
|
|
masm,
|
|
|
|
ecx,
|
|
|
|
FloatingPointHelper::ARGS_IN_REGISTERS);
|
|
|
|
FloatingPointHelper::CheckFloatOperandsAreInt32(masm, ¬_int32);
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD: __ faddp(1); break;
|
|
|
|
case Token::SUB: __ fsubp(1); break;
|
|
|
|
case Token::MUL: __ fmulp(1); break;
|
|
|
|
case Token::DIV: __ fdivp(1); break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
Label after_alloc_failure;
|
|
|
|
GenerateHeapResultAllocation(masm, &after_alloc_failure);
|
|
|
|
__ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
__ ret(0);
|
|
|
|
__ bind(&after_alloc_failure);
|
|
|
|
__ ffree();
|
|
|
|
__ jmp(&call_runtime);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(¬_floats);
|
|
|
|
__ bind(¬_int32);
|
|
|
|
GenerateTypeTransition(masm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Token::MOD: {
|
|
|
|
// For MOD we go directly to runtime in the non-smi case.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_AND:
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
case Token::SAR:
|
|
|
|
case Token::SHL:
|
|
|
|
case Token::SHR: {
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
Label not_floats;
|
|
|
|
Label not_int32;
|
|
|
|
Label non_smi_result;
|
|
|
|
/* {
|
|
|
|
CpuFeatures::Scope use_sse2(SSE2);
|
|
|
|
FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats);
|
|
|
|
FloatingPointHelper::CheckSSE2OperandsAreInt32(masm, ¬_int32, ecx);
|
|
|
|
}*/
|
|
|
|
FloatingPointHelper::LoadUnknownsAsIntegers(masm,
|
|
|
|
use_sse3_,
|
|
|
|
¬_floats);
|
|
|
|
FloatingPointHelper::CheckLoadedIntegersWereInt32(masm, use_sse3_,
|
|
|
|
¬_int32);
|
|
|
|
switch (op_) {
|
2011-10-03 11:44:39 +00:00
|
|
|
case Token::BIT_OR: __ or_(eax, ecx); break;
|
|
|
|
case Token::BIT_AND: __ and_(eax, ecx); break;
|
|
|
|
case Token::BIT_XOR: __ xor_(eax, ecx); break;
|
2010-12-07 11:31:57 +00:00
|
|
|
case Token::SAR: __ sar_cl(eax); break;
|
|
|
|
case Token::SHL: __ shl_cl(eax); break;
|
|
|
|
case Token::SHR: __ shr_cl(eax); break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
if (op_ == Token::SHR) {
|
|
|
|
// Check if result is non-negative and fits in a smi.
|
|
|
|
__ test(eax, Immediate(0xc0000000));
|
|
|
|
__ j(not_zero, &call_runtime);
|
|
|
|
} else {
|
|
|
|
// Check if result fits in a smi.
|
|
|
|
__ cmp(eax, 0xc0000000);
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(negative, &non_smi_result, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
// Tag smi result and return.
|
|
|
|
__ SmiTag(eax);
|
|
|
|
__ ret(2 * kPointerSize); // Drop two pushed arguments from the stack.
|
|
|
|
|
|
|
|
// All ops except SHR return a signed int32 that we load in
|
|
|
|
// a HeapNumber.
|
|
|
|
if (op_ != Token::SHR) {
|
|
|
|
__ bind(&non_smi_result);
|
|
|
|
// Allocate a heap number if needed.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(ebx, eax); // ebx: result
|
2011-05-10 09:03:42 +00:00
|
|
|
Label skip_allocation;
|
2010-12-07 11:31:57 +00:00
|
|
|
switch (mode_) {
|
|
|
|
case OVERWRITE_LEFT:
|
|
|
|
case OVERWRITE_RIGHT:
|
|
|
|
// If the operand was an object, we skip the
|
|
|
|
// allocation of a heap number.
|
|
|
|
__ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ?
|
|
|
|
1 * kPointerSize : 2 * kPointerSize));
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(eax, &skip_allocation, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
// Fall through!
|
|
|
|
case NO_OVERWRITE:
|
|
|
|
__ AllocateHeapNumber(eax, ecx, edx, &call_runtime);
|
|
|
|
__ bind(&skip_allocation);
|
|
|
|
break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
// Store the result in the HeapNumber and return.
|
2011-03-31 16:17:37 +00:00
|
|
|
if (CpuFeatures::IsSupported(SSE2)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
CpuFeatures::Scope use_sse2(SSE2);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm0, ebx);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0);
|
|
|
|
} else {
|
|
|
|
__ mov(Operand(esp, 1 * kPointerSize), ebx);
|
|
|
|
__ fild_s(Operand(esp, 1 * kPointerSize));
|
|
|
|
__ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
}
|
|
|
|
__ ret(2 * kPointerSize); // Drop two pushed arguments from the stack.
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(¬_floats);
|
|
|
|
__ bind(¬_int32);
|
|
|
|
GenerateTypeTransitionWithSavedArgs(masm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: UNREACHABLE(); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If an allocation fails, or SHR or MOD hit a hard case,
|
|
|
|
// use the runtime system to get the correct result.
|
|
|
|
__ bind(&call_runtime);
|
2011-01-13 08:24:19 +00:00
|
|
|
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD:
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
__ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SUB:
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
__ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::MUL:
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
__ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::DIV:
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
__ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::MOD:
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
__ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::BIT_OR:
|
|
|
|
__ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::BIT_AND:
|
|
|
|
__ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
__ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SAR:
|
|
|
|
__ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SHL:
|
|
|
|
__ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SHR:
|
|
|
|
__ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) {
|
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);
|
|
|
|
}
|
|
|
|
|
2011-04-14 08:01:19 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
|
2011-03-28 16:36:08 +00:00
|
|
|
// Convert odd ball arguments to numbers.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label check, done;
|
2011-04-14 08:01:19 +00:00
|
|
|
__ cmp(edx, factory->undefined_value());
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, &check, Label::kNear);
|
2011-03-28 16:36:08 +00:00
|
|
|
if (Token::IsBitOp(op_)) {
|
2011-10-03 11:44:39 +00:00
|
|
|
__ xor_(edx, edx);
|
2011-03-28 16:36:08 +00:00
|
|
|
} else {
|
2011-04-14 08:01:19 +00:00
|
|
|
__ mov(edx, Immediate(factory->nan_value()));
|
2011-03-28 16:36:08 +00:00
|
|
|
}
|
2011-05-10 09:03:42 +00:00
|
|
|
__ jmp(&done, Label::kNear);
|
2011-03-28 16:36:08 +00:00
|
|
|
__ bind(&check);
|
2011-04-14 08:01:19 +00:00
|
|
|
__ cmp(eax, factory->undefined_value());
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, &done, Label::kNear);
|
2011-03-28 16:36:08 +00:00
|
|
|
if (Token::IsBitOp(op_)) {
|
2011-10-03 11:44:39 +00:00
|
|
|
__ xor_(eax, eax);
|
2011-03-28 16:36:08 +00:00
|
|
|
} else {
|
2011-04-14 08:01:19 +00:00
|
|
|
__ mov(eax, Immediate(factory->nan_value()));
|
2011-03-28 16:36:08 +00:00
|
|
|
}
|
|
|
|
__ bind(&done);
|
|
|
|
|
|
|
|
GenerateHeapNumberStub(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) {
|
2010-12-07 11:31:57 +00:00
|
|
|
Label call_runtime;
|
|
|
|
|
|
|
|
// Floating point case.
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD:
|
|
|
|
case Token::SUB:
|
|
|
|
case Token::MUL:
|
|
|
|
case Token::DIV: {
|
|
|
|
Label not_floats;
|
2011-03-31 16:17:37 +00:00
|
|
|
if (CpuFeatures::IsSupported(SSE2)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
CpuFeatures::Scope use_sse2(SSE2);
|
|
|
|
FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats);
|
|
|
|
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD: __ addsd(xmm0, xmm1); break;
|
|
|
|
case Token::SUB: __ subsd(xmm0, xmm1); break;
|
|
|
|
case Token::MUL: __ mulsd(xmm0, xmm1); break;
|
|
|
|
case Token::DIV: __ divsd(xmm0, xmm1); break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
GenerateHeapResultAllocation(masm, &call_runtime);
|
|
|
|
__ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0);
|
|
|
|
__ ret(0);
|
|
|
|
} else { // SSE2 not available, use FPU.
|
|
|
|
FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx);
|
|
|
|
FloatingPointHelper::LoadFloatOperands(
|
|
|
|
masm,
|
|
|
|
ecx,
|
|
|
|
FloatingPointHelper::ARGS_IN_REGISTERS);
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD: __ faddp(1); break;
|
|
|
|
case Token::SUB: __ fsubp(1); break;
|
|
|
|
case Token::MUL: __ fmulp(1); break;
|
|
|
|
case Token::DIV: __ fdivp(1); break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
Label after_alloc_failure;
|
|
|
|
GenerateHeapResultAllocation(masm, &after_alloc_failure);
|
|
|
|
__ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
__ ret(0);
|
|
|
|
__ bind(&after_alloc_failure);
|
|
|
|
__ ffree();
|
|
|
|
__ jmp(&call_runtime);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(¬_floats);
|
|
|
|
GenerateTypeTransition(masm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Token::MOD: {
|
|
|
|
// For MOD we go directly to runtime in the non-smi case.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_AND:
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
case Token::SAR:
|
|
|
|
case Token::SHL:
|
|
|
|
case Token::SHR: {
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
Label not_floats;
|
|
|
|
Label non_smi_result;
|
|
|
|
FloatingPointHelper::LoadUnknownsAsIntegers(masm,
|
|
|
|
use_sse3_,
|
|
|
|
¬_floats);
|
|
|
|
switch (op_) {
|
2011-10-03 11:44:39 +00:00
|
|
|
case Token::BIT_OR: __ or_(eax, ecx); break;
|
|
|
|
case Token::BIT_AND: __ and_(eax, ecx); break;
|
|
|
|
case Token::BIT_XOR: __ xor_(eax, ecx); break;
|
2010-12-07 11:31:57 +00:00
|
|
|
case Token::SAR: __ sar_cl(eax); break;
|
|
|
|
case Token::SHL: __ shl_cl(eax); break;
|
|
|
|
case Token::SHR: __ shr_cl(eax); break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
if (op_ == Token::SHR) {
|
|
|
|
// Check if result is non-negative and fits in a smi.
|
|
|
|
__ test(eax, Immediate(0xc0000000));
|
|
|
|
__ j(not_zero, &call_runtime);
|
|
|
|
} else {
|
|
|
|
// Check if result fits in a smi.
|
|
|
|
__ cmp(eax, 0xc0000000);
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(negative, &non_smi_result, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
// Tag smi result and return.
|
|
|
|
__ SmiTag(eax);
|
|
|
|
__ ret(2 * kPointerSize); // Drop two pushed arguments from the stack.
|
|
|
|
|
|
|
|
// All ops except SHR return a signed int32 that we load in
|
|
|
|
// a HeapNumber.
|
|
|
|
if (op_ != Token::SHR) {
|
|
|
|
__ bind(&non_smi_result);
|
|
|
|
// Allocate a heap number if needed.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(ebx, eax); // ebx: result
|
2011-05-10 09:03:42 +00:00
|
|
|
Label skip_allocation;
|
2010-12-07 11:31:57 +00:00
|
|
|
switch (mode_) {
|
|
|
|
case OVERWRITE_LEFT:
|
|
|
|
case OVERWRITE_RIGHT:
|
|
|
|
// If the operand was an object, we skip the
|
|
|
|
// allocation of a heap number.
|
|
|
|
__ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ?
|
|
|
|
1 * kPointerSize : 2 * kPointerSize));
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(eax, &skip_allocation, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
// Fall through!
|
|
|
|
case NO_OVERWRITE:
|
|
|
|
__ AllocateHeapNumber(eax, ecx, edx, &call_runtime);
|
|
|
|
__ bind(&skip_allocation);
|
|
|
|
break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
// Store the result in the HeapNumber and return.
|
2011-03-31 16:17:37 +00:00
|
|
|
if (CpuFeatures::IsSupported(SSE2)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
CpuFeatures::Scope use_sse2(SSE2);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm0, ebx);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0);
|
|
|
|
} else {
|
|
|
|
__ mov(Operand(esp, 1 * kPointerSize), ebx);
|
|
|
|
__ fild_s(Operand(esp, 1 * kPointerSize));
|
|
|
|
__ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
}
|
|
|
|
__ ret(2 * kPointerSize); // Drop two pushed arguments from the stack.
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(¬_floats);
|
|
|
|
GenerateTypeTransitionWithSavedArgs(masm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: UNREACHABLE(); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If an allocation fails, or SHR or MOD hit a hard case,
|
|
|
|
// use the runtime system to get the correct result.
|
|
|
|
__ bind(&call_runtime);
|
2011-01-13 08:24:19 +00:00
|
|
|
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD:
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
__ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SUB:
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
__ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::MUL:
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
__ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::DIV:
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
__ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::MOD:
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
__ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::BIT_OR:
|
|
|
|
__ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::BIT_AND:
|
|
|
|
__ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
__ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SAR:
|
|
|
|
__ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SHL:
|
|
|
|
__ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SHR:
|
|
|
|
__ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) {
|
2010-12-07 11:31:57 +00:00
|
|
|
Label call_runtime;
|
|
|
|
|
2011-03-23 11:13:07 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
__ IncrementCounter(counters->generic_binary_stub_calls(), 1);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD:
|
|
|
|
case Token::SUB:
|
|
|
|
case Token::MUL:
|
|
|
|
case Token::DIV:
|
2011-01-12 14:00:19 +00:00
|
|
|
break;
|
2011-01-13 08:24:19 +00:00
|
|
|
case Token::MOD:
|
2010-12-07 11:31:57 +00:00
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_AND:
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
case Token::SAR:
|
|
|
|
case Token::SHL:
|
|
|
|
case Token::SHR:
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
GenerateSmiCode(masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS);
|
|
|
|
|
|
|
|
// Floating point case.
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD:
|
|
|
|
case Token::SUB:
|
|
|
|
case Token::MUL:
|
|
|
|
case Token::DIV: {
|
|
|
|
Label not_floats;
|
2011-03-31 16:17:37 +00:00
|
|
|
if (CpuFeatures::IsSupported(SSE2)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
CpuFeatures::Scope use_sse2(SSE2);
|
|
|
|
FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats);
|
|
|
|
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD: __ addsd(xmm0, xmm1); break;
|
|
|
|
case Token::SUB: __ subsd(xmm0, xmm1); break;
|
|
|
|
case Token::MUL: __ mulsd(xmm0, xmm1); break;
|
|
|
|
case Token::DIV: __ divsd(xmm0, xmm1); break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
GenerateHeapResultAllocation(masm, &call_runtime);
|
|
|
|
__ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0);
|
|
|
|
__ ret(0);
|
|
|
|
} else { // SSE2 not available, use FPU.
|
|
|
|
FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx);
|
|
|
|
FloatingPointHelper::LoadFloatOperands(
|
|
|
|
masm,
|
|
|
|
ecx,
|
|
|
|
FloatingPointHelper::ARGS_IN_REGISTERS);
|
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD: __ faddp(1); break;
|
|
|
|
case Token::SUB: __ fsubp(1); break;
|
|
|
|
case Token::MUL: __ fmulp(1); break;
|
|
|
|
case Token::DIV: __ fdivp(1); break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
Label after_alloc_failure;
|
|
|
|
GenerateHeapResultAllocation(masm, &after_alloc_failure);
|
|
|
|
__ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
__ ret(0);
|
|
|
|
__ bind(&after_alloc_failure);
|
|
|
|
__ ffree();
|
|
|
|
__ jmp(&call_runtime);
|
|
|
|
}
|
|
|
|
__ bind(¬_floats);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Token::MOD: {
|
|
|
|
// For MOD we go directly to runtime in the non-smi case.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_AND:
|
2011-01-13 08:24:19 +00:00
|
|
|
case Token::BIT_XOR:
|
2010-12-07 11:31:57 +00:00
|
|
|
case Token::SAR:
|
|
|
|
case Token::SHL:
|
|
|
|
case Token::SHR: {
|
|
|
|
Label non_smi_result;
|
|
|
|
FloatingPointHelper::LoadUnknownsAsIntegers(masm,
|
|
|
|
use_sse3_,
|
|
|
|
&call_runtime);
|
|
|
|
switch (op_) {
|
2011-10-03 11:44:39 +00:00
|
|
|
case Token::BIT_OR: __ or_(eax, ecx); break;
|
|
|
|
case Token::BIT_AND: __ and_(eax, ecx); break;
|
|
|
|
case Token::BIT_XOR: __ xor_(eax, ecx); break;
|
2010-12-07 11:31:57 +00:00
|
|
|
case Token::SAR: __ sar_cl(eax); break;
|
|
|
|
case Token::SHL: __ shl_cl(eax); break;
|
|
|
|
case Token::SHR: __ shr_cl(eax); break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
if (op_ == Token::SHR) {
|
|
|
|
// Check if result is non-negative and fits in a smi.
|
|
|
|
__ test(eax, Immediate(0xc0000000));
|
|
|
|
__ j(not_zero, &call_runtime);
|
|
|
|
} else {
|
|
|
|
// Check if result fits in a smi.
|
|
|
|
__ cmp(eax, 0xc0000000);
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(negative, &non_smi_result, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
// Tag smi result and return.
|
|
|
|
__ SmiTag(eax);
|
|
|
|
__ ret(2 * kPointerSize); // Drop the arguments from the stack.
|
|
|
|
|
|
|
|
// All ops except SHR return a signed int32 that we load in
|
|
|
|
// a HeapNumber.
|
|
|
|
if (op_ != Token::SHR) {
|
|
|
|
__ bind(&non_smi_result);
|
|
|
|
// Allocate a heap number if needed.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(ebx, eax); // ebx: result
|
2011-05-10 09:03:42 +00:00
|
|
|
Label skip_allocation;
|
2010-12-07 11:31:57 +00:00
|
|
|
switch (mode_) {
|
|
|
|
case OVERWRITE_LEFT:
|
|
|
|
case OVERWRITE_RIGHT:
|
|
|
|
// If the operand was an object, we skip the
|
|
|
|
// allocation of a heap number.
|
|
|
|
__ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ?
|
|
|
|
1 * kPointerSize : 2 * kPointerSize));
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(eax, &skip_allocation, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
// Fall through!
|
|
|
|
case NO_OVERWRITE:
|
|
|
|
__ AllocateHeapNumber(eax, ecx, edx, &call_runtime);
|
|
|
|
__ bind(&skip_allocation);
|
|
|
|
break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
// Store the result in the HeapNumber and return.
|
2011-03-31 16:17:37 +00:00
|
|
|
if (CpuFeatures::IsSupported(SSE2)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
CpuFeatures::Scope use_sse2(SSE2);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm0, ebx);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0);
|
|
|
|
} else {
|
|
|
|
__ mov(Operand(esp, 1 * kPointerSize), ebx);
|
|
|
|
__ fild_s(Operand(esp, 1 * kPointerSize));
|
|
|
|
__ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
}
|
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
}
|
|
|
|
break;
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
default: UNREACHABLE(); break;
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
2010-09-07 13:33:40 +00:00
|
|
|
// If all else fails, use the runtime system to get the correct
|
2010-12-07 11:31:57 +00:00
|
|
|
// result.
|
|
|
|
__ bind(&call_runtime);
|
2011-01-13 08:24:19 +00:00
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD: {
|
2011-01-25 12:14:56 +00:00
|
|
|
GenerateAddStrings(masm);
|
2011-01-13 08:24:19 +00:00
|
|
|
GenerateRegisterArgsPush(masm);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION);
|
|
|
|
break;
|
2011-01-13 08:24:19 +00:00
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
case Token::SUB:
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateRegisterArgsPush(masm);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::MUL:
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateRegisterArgsPush(masm);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::DIV:
|
2010-12-07 11:31:57 +00:00
|
|
|
GenerateRegisterArgsPush(masm);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::MOD:
|
|
|
|
__ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::BIT_OR:
|
|
|
|
__ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::BIT_AND:
|
|
|
|
__ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
__ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SAR:
|
|
|
|
__ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SHL:
|
|
|
|
__ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
case Token::SHR:
|
|
|
|
__ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) {
|
2011-02-22 12:26:31 +00:00
|
|
|
ASSERT(op_ == Token::ADD);
|
2011-05-10 09:03:42 +00:00
|
|
|
Label left_not_string, call_runtime;
|
2011-01-25 12:14:56 +00:00
|
|
|
|
|
|
|
// Registers containing left and right operands respectively.
|
|
|
|
Register left = edx;
|
|
|
|
Register right = eax;
|
|
|
|
|
|
|
|
// Test if left operand is a string.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(left, &left_not_string, Label::kNear);
|
2011-01-25 12:14:56 +00:00
|
|
|
__ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(above_equal, &left_not_string, Label::kNear);
|
2011-01-25 12:14:56 +00:00
|
|
|
|
|
|
|
StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB);
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
__ TailCallStub(&string_add_left_stub);
|
|
|
|
|
|
|
|
// Left operand is not a string, test right.
|
|
|
|
__ bind(&left_not_string);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(right, &call_runtime, Label::kNear);
|
2011-01-25 12:14:56 +00:00
|
|
|
__ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(above_equal, &call_runtime, Label::kNear);
|
2011-01-25 12:14:56 +00:00
|
|
|
|
|
|
|
StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB);
|
|
|
|
GenerateRegisterArgsPush(masm);
|
|
|
|
__ TailCallStub(&string_add_right_stub);
|
|
|
|
|
|
|
|
// Neither argument is a string.
|
|
|
|
__ bind(&call_runtime);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateHeapResultAllocation(
|
2010-12-07 11:31:57 +00:00
|
|
|
MacroAssembler* masm,
|
|
|
|
Label* alloc_failure) {
|
2010-08-25 09:44:44 +00:00
|
|
|
Label skip_allocation;
|
|
|
|
OverwriteMode mode = mode_;
|
|
|
|
switch (mode) {
|
|
|
|
case OVERWRITE_LEFT: {
|
|
|
|
// If the argument in edx is already an object, we skip the
|
|
|
|
// allocation of a heap number.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(edx, &skip_allocation, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Allocate a heap number for the result. Keep eax and edx intact
|
|
|
|
// for the possible runtime call.
|
|
|
|
__ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure);
|
|
|
|
// Now edx can be overwritten losing one of the arguments as we are
|
|
|
|
// now done and will not need it any more.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(edx, ebx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&skip_allocation);
|
|
|
|
// Use object in edx as a result holder
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(eax, edx);
|
2010-08-25 09:44:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OVERWRITE_RIGHT:
|
|
|
|
// If the argument in eax is already an object, we skip the
|
|
|
|
// allocation of a heap number.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(eax, &skip_allocation, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Fall through!
|
|
|
|
case NO_OVERWRITE:
|
|
|
|
// Allocate a heap number for the result. Keep eax and edx intact
|
|
|
|
// for the possible runtime call.
|
|
|
|
__ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure);
|
|
|
|
// Now eax can be overwritten losing one of the arguments as we are
|
|
|
|
// now done and will not need it any more.
|
|
|
|
__ mov(eax, ebx);
|
|
|
|
__ bind(&skip_allocation);
|
|
|
|
break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 12:20:16 +00:00
|
|
|
void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) {
|
2010-08-25 09:44:44 +00:00
|
|
|
__ pop(ecx);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ push(edx);
|
|
|
|
__ push(eax);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ push(ecx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TranscendentalCacheStub::Generate(MacroAssembler* masm) {
|
2010-12-20 13:52:14 +00:00
|
|
|
// TAGGED case:
|
|
|
|
// Input:
|
|
|
|
// esp[4]: tagged number input argument (should be number).
|
|
|
|
// esp[0]: return address.
|
|
|
|
// Output:
|
|
|
|
// eax: tagged double result.
|
|
|
|
// UNTAGGED case:
|
|
|
|
// Input::
|
|
|
|
// esp[0]: return address.
|
|
|
|
// xmm1: untagged double input argument
|
|
|
|
// Output:
|
|
|
|
// xmm1: untagged double result.
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
Label runtime_call;
|
|
|
|
Label runtime_call_clear_stack;
|
2010-12-20 13:52:14 +00:00
|
|
|
Label skip_cache;
|
|
|
|
const bool tagged = (argument_type_ == TAGGED);
|
|
|
|
if (tagged) {
|
|
|
|
// Test that eax is a number.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label input_not_smi;
|
|
|
|
Label loaded;
|
2010-12-20 13:52:14 +00:00
|
|
|
__ mov(eax, Operand(esp, kPointerSize));
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(eax, &input_not_smi, Label::kNear);
|
2010-12-20 13:52:14 +00:00
|
|
|
// Input is a smi. Untag and load it onto the FPU stack.
|
|
|
|
// Then load the low and high words of the double into ebx, edx.
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
__ sar(eax, 1);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(esp, Immediate(2 * kPointerSize));
|
2010-12-20 13:52:14 +00:00
|
|
|
__ mov(Operand(esp, 0), eax);
|
|
|
|
__ fild_s(Operand(esp, 0));
|
|
|
|
__ fst_d(Operand(esp, 0));
|
|
|
|
__ pop(edx);
|
|
|
|
__ pop(ebx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ jmp(&loaded, Label::kNear);
|
2010-12-20 13:52:14 +00:00
|
|
|
__ bind(&input_not_smi);
|
|
|
|
// Check if input is a HeapNumber.
|
|
|
|
__ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
|
2011-03-25 13:21:30 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ebx, Immediate(factory->heap_number_map()));
|
2010-12-20 13:52:14 +00:00
|
|
|
__ j(not_equal, &runtime_call);
|
|
|
|
// Input is a HeapNumber. Push it on the FPU stack and load its
|
|
|
|
// low and high words into ebx, edx.
|
|
|
|
__ fld_d(FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
__ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset));
|
|
|
|
__ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset));
|
|
|
|
|
|
|
|
__ bind(&loaded);
|
|
|
|
} else { // UNTAGGED.
|
2011-03-31 16:17:37 +00:00
|
|
|
if (CpuFeatures::IsSupported(SSE4_1)) {
|
2010-12-20 13:52:14 +00:00
|
|
|
CpuFeatures::Scope sse4_scope(SSE4_1);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx.
|
2010-12-20 13:52:14 +00:00
|
|
|
} else {
|
|
|
|
__ pshufd(xmm0, xmm1, 0x1);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ movd(edx, xmm0);
|
2010-12-20 13:52:14 +00:00
|
|
|
}
|
2011-10-03 11:44:39 +00:00
|
|
|
__ movd(ebx, xmm1);
|
2010-12-20 13:52:14 +00:00
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2010-12-20 13:52:14 +00:00
|
|
|
// ST[0] or xmm1 == double value
|
2010-08-25 09:44:44 +00:00
|
|
|
// ebx = low 32 bits of double value
|
|
|
|
// edx = 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);
|
|
|
|
__ mov(ecx, ebx);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ xor_(ecx, edx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(eax, ecx);
|
|
|
|
__ sar(eax, 16);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ xor_(ecx, eax);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(eax, ecx);
|
|
|
|
__ sar(eax, 8);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ xor_(ecx, eax);
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ and_(ecx,
|
2011-03-18 20:35:07 +00:00
|
|
|
Immediate(TranscendentalCache::SubCache::kCacheSize - 1));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2010-12-20 13:52:14 +00:00
|
|
|
// ST[0] or xmm1 == double value.
|
2010-08-25 09:44:44 +00:00
|
|
|
// ebx = low 32 bits of double value.
|
|
|
|
// edx = high 32 bits of double value.
|
|
|
|
// ecx = TranscendentalCache::hash(double value).
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference cache_array =
|
|
|
|
ExternalReference::transcendental_cache_array_address(masm->isolate());
|
|
|
|
__ mov(eax, Immediate(cache_array));
|
|
|
|
int cache_array_index =
|
|
|
|
type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]);
|
|
|
|
__ mov(eax, Operand(eax, cache_array_index));
|
2010-08-25 09:44:44 +00:00
|
|
|
// Eax points to the cache for the type type_.
|
|
|
|
// If NULL, the cache hasn't been initialized yet, so go through runtime.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(eax, eax);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(zero, &runtime_call_clear_stack);
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Check that the layout of cache elements match expectations.
|
2011-03-18 20:35:07 +00:00
|
|
|
{ TranscendentalCache::SubCache::Element test_elem[2];
|
2010-08-25 09:44:44 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12].
|
|
|
|
__ lea(ecx, Operand(ecx, ecx, times_2, 0));
|
|
|
|
__ lea(ecx, Operand(eax, ecx, times_4, 0));
|
|
|
|
// Check if cache matches: Double value is stored in uint32_t[2] array.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label cache_miss;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmp(ebx, Operand(ecx, 0));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, &cache_miss, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmp(edx, Operand(ecx, kIntSize));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, &cache_miss, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Cache hit!
|
2011-11-25 13:15:31 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
__ IncrementCounter(counters->transcendental_cache_hit(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(eax, Operand(ecx, 2 * kIntSize));
|
2010-12-20 13:52:14 +00:00
|
|
|
if (tagged) {
|
|
|
|
__ fstp(0);
|
|
|
|
__ ret(kPointerSize);
|
|
|
|
} else { // UNTAGGED.
|
|
|
|
__ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
__ Ret();
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&cache_miss);
|
2011-11-25 13:15:31 +00:00
|
|
|
__ IncrementCounter(counters->transcendental_cache_miss(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Update cache with new value.
|
|
|
|
// We are short on registers, so use no_reg as scratch.
|
|
|
|
// This gives slightly larger code.
|
2010-12-20 13:52:14 +00:00
|
|
|
if (tagged) {
|
|
|
|
__ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack);
|
|
|
|
} else { // UNTAGGED.
|
|
|
|
__ AllocateHeapNumber(eax, edi, no_reg, &skip_cache);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(esp, Immediate(kDoubleSize));
|
2010-12-20 13:52:14 +00:00
|
|
|
__ movdbl(Operand(esp, 0), xmm1);
|
|
|
|
__ fld_d(Operand(esp, 0));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(esp, Immediate(kDoubleSize));
|
2010-12-20 13:52:14 +00:00
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
GenerateOperation(masm);
|
|
|
|
__ mov(Operand(ecx, 0), ebx);
|
|
|
|
__ mov(Operand(ecx, kIntSize), edx);
|
|
|
|
__ mov(Operand(ecx, 2 * kIntSize), eax);
|
|
|
|
__ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset));
|
2010-12-20 13:52:14 +00:00
|
|
|
if (tagged) {
|
|
|
|
__ ret(kPointerSize);
|
|
|
|
} else { // UNTAGGED.
|
|
|
|
__ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Skip cache and return answer directly, only in untagged case.
|
|
|
|
__ bind(&skip_cache);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(esp, Immediate(kDoubleSize));
|
2010-12-20 13:52:14 +00:00
|
|
|
__ movdbl(Operand(esp, 0), xmm1);
|
|
|
|
__ fld_d(Operand(esp, 0));
|
|
|
|
GenerateOperation(masm);
|
|
|
|
__ fstp_d(Operand(esp, 0));
|
|
|
|
__ movdbl(xmm1, Operand(esp, 0));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(esp, Immediate(kDoubleSize));
|
2010-12-21 10:25:51 +00:00
|
|
|
// We return the value in xmm1 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 unused object bigger than a HeapNumber.
|
|
|
|
__ push(Immediate(Smi::FromInt(2 * kDoubleSize)));
|
|
|
|
__ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace);
|
|
|
|
}
|
2010-12-20 13:52:14 +00:00
|
|
|
__ Ret();
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2010-12-20 13:52:14 +00:00
|
|
|
// Call runtime, doing whatever allocation and cleanup is necessary.
|
|
|
|
if (tagged) {
|
|
|
|
__ bind(&runtime_call_clear_stack);
|
|
|
|
__ fstp(0);
|
|
|
|
__ bind(&runtime_call);
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference runtime =
|
|
|
|
ExternalReference(RuntimeFunction(), masm->isolate());
|
|
|
|
__ TailCallExternalReference(runtime, 1, 1);
|
2010-12-20 13:52:14 +00:00
|
|
|
} else { // UNTAGGED.
|
2010-12-20 14:42:05 +00:00
|
|
|
__ bind(&runtime_call_clear_stack);
|
|
|
|
__ bind(&runtime_call);
|
2010-12-20 13:52:14 +00:00
|
|
|
__ AllocateHeapNumber(eax, edi, no_reg, &skip_cache);
|
|
|
|
__ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1);
|
2011-09-15 11:30:45 +00:00
|
|
|
{
|
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
|
|
|
__ push(eax);
|
|
|
|
__ CallRuntime(RuntimeFunction(), 1);
|
|
|
|
}
|
2010-12-20 13:52:14 +00:00
|
|
|
__ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
__ Ret();
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() {
|
|
|
|
switch (type_) {
|
|
|
|
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 TranscendentalCacheStub::GenerateOperation(MacroAssembler* masm) {
|
|
|
|
// Only free register is edi.
|
2010-12-20 13:52:14 +00:00
|
|
|
// Input value is on FP stack, and also in ebx/edx.
|
|
|
|
// Input value is possibly in xmm1.
|
|
|
|
// Address of result (a newly allocated HeapNumber) may be in eax.
|
2011-11-25 13:15:31 +00:00
|
|
|
if (type_ == TranscendentalCache::SIN ||
|
|
|
|
type_ == TranscendentalCache::COS ||
|
|
|
|
type_ == TranscendentalCache::TAN) {
|
2010-12-02 11:20:44 +00:00
|
|
|
// Both fsin and fcos require arguments in the range +/-2^63 and
|
|
|
|
// return NaN for infinities and NaN. They can share all code except
|
|
|
|
// the actual fsin/fcos operation.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label in_range, done;
|
2010-12-02 11:20:44 +00:00
|
|
|
// If argument is outside the range -2^63..2^63, fsin/cos doesn't
|
|
|
|
// work. We must reduce it to the appropriate range.
|
|
|
|
__ mov(edi, edx);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ and_(edi, Immediate(0x7ff00000)); // Exponent only.
|
2010-12-02 11:20:44 +00:00
|
|
|
int supported_exponent_limit =
|
|
|
|
(63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(edi, Immediate(supported_exponent_limit));
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(below, &in_range, Label::kNear);
|
2010-12-02 11:20:44 +00:00
|
|
|
// Check for infinity and NaN. Both return NaN for sin.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(edi, Immediate(0x7ff00000));
|
2011-05-10 09:03:42 +00:00
|
|
|
Label non_nan_result;
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(not_equal, &non_nan_result, Label::kNear);
|
2010-12-02 11:20:44 +00:00
|
|
|
// Input is +/-Infinity or NaN. Result is NaN.
|
|
|
|
__ fstp(0);
|
|
|
|
// NaN is represented by 0x7ff8000000000000.
|
|
|
|
__ push(Immediate(0x7ff80000));
|
|
|
|
__ push(Immediate(0));
|
|
|
|
__ fld_d(Operand(esp, 0));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(esp, Immediate(2 * kPointerSize));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ jmp(&done, Label::kNear);
|
2010-12-02 11:20:44 +00:00
|
|
|
|
|
|
|
__ bind(&non_nan_result);
|
|
|
|
|
|
|
|
// Use fpmod to restrict argument to the range +/-2*PI.
|
|
|
|
__ mov(edi, eax); // Save eax before using fnstsw_ax.
|
|
|
|
__ fldpi();
|
|
|
|
__ fadd(0);
|
|
|
|
__ fld(1);
|
|
|
|
// FPU Stack: input, 2*pi, input.
|
|
|
|
{
|
2011-05-10 09:03:42 +00:00
|
|
|
Label no_exceptions;
|
2010-12-02 11:20:44 +00:00
|
|
|
__ fwait();
|
|
|
|
__ fnstsw_ax();
|
|
|
|
// Clear if Illegal Operand or Zero Division exceptions are set.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(eax, Immediate(5));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &no_exceptions, Label::kNear);
|
2010-12-02 11:20:44 +00:00
|
|
|
__ fnclex();
|
|
|
|
__ bind(&no_exceptions);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2010-12-02 11:20:44 +00:00
|
|
|
// Compute st(0) % st(1)
|
|
|
|
{
|
2011-05-10 09:03:42 +00:00
|
|
|
Label partial_remainder_loop;
|
2010-12-02 11:20:44 +00:00
|
|
|
__ bind(&partial_remainder_loop);
|
|
|
|
__ fprem1();
|
|
|
|
__ fwait();
|
|
|
|
__ fnstsw_ax();
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(eax, Immediate(0x400 /* C2 */));
|
2010-12-02 11:20:44 +00:00
|
|
|
// If C2 is set, computation only has partial result. Loop to
|
|
|
|
// continue computation.
|
|
|
|
__ j(not_zero, &partial_remainder_loop);
|
|
|
|
}
|
|
|
|
// FPU Stack: input, 2*pi, input % 2*pi
|
|
|
|
__ fstp(2);
|
|
|
|
__ fstp(0);
|
|
|
|
__ mov(eax, edi); // Restore eax (allocated HeapNumber pointer).
|
|
|
|
|
|
|
|
// FPU Stack: input % 2*pi
|
|
|
|
__ bind(&in_range);
|
|
|
|
switch (type_) {
|
|
|
|
case TranscendentalCache::SIN:
|
|
|
|
__ fsin();
|
|
|
|
break;
|
|
|
|
case TranscendentalCache::COS:
|
|
|
|
__ fcos();
|
|
|
|
break;
|
2011-11-25 13:15:31 +00:00
|
|
|
case TranscendentalCache::TAN:
|
|
|
|
// FPTAN calculates tangent onto st(0) and pushes 1.0 onto the
|
|
|
|
// FP register stack.
|
|
|
|
__ fptan();
|
|
|
|
__ fstp(0); // Pop FP register stack.
|
|
|
|
break;
|
2010-12-02 11:20:44 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
__ bind(&done);
|
|
|
|
} else {
|
|
|
|
ASSERT(type_ == TranscendentalCache::LOG);
|
|
|
|
__ fldln2();
|
|
|
|
__ fxch();
|
|
|
|
__ fyl2x();
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Input: edx, eax are the left and right objects of a bit op.
|
|
|
|
// Output: eax, ecx are left and right integers for a bit op.
|
|
|
|
void FloatingPointHelper::LoadUnknownsAsIntegers(MacroAssembler* masm,
|
|
|
|
bool use_sse3,
|
|
|
|
Label* conversion_failure) {
|
|
|
|
// Check float operands.
|
|
|
|
Label arg1_is_object, check_undefined_arg1;
|
|
|
|
Label arg2_is_object, check_undefined_arg2;
|
|
|
|
Label load_arg2, done;
|
|
|
|
|
|
|
|
// Test if arg1 is a Smi.
|
2011-08-26 08:22:13 +00:00
|
|
|
__ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ SmiUntag(edx);
|
2011-08-26 11:56:12 +00:00
|
|
|
__ jmp(&load_arg2);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// If the argument is undefined it converts to zero (ECMA-262, section 9.5).
|
|
|
|
__ bind(&check_undefined_arg1);
|
2011-03-25 13:21:30 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
__ cmp(edx, factory->undefined_value());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, conversion_failure);
|
|
|
|
__ mov(edx, Immediate(0));
|
2011-08-26 11:56:12 +00:00
|
|
|
__ jmp(&load_arg2);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&arg1_is_object);
|
|
|
|
__ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset));
|
2011-03-25 13:21:30 +00:00
|
|
|
__ cmp(ebx, factory->heap_number_map());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, &check_undefined_arg1);
|
|
|
|
|
|
|
|
// Get the untagged integer version of the edx heap number in ecx.
|
2011-05-11 13:45:30 +00:00
|
|
|
IntegerConvert(masm, edx, use_sse3, conversion_failure);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(edx, ecx);
|
|
|
|
|
|
|
|
// Here edx has the untagged integer, eax has a Smi or a heap number.
|
|
|
|
__ bind(&load_arg2);
|
|
|
|
|
|
|
|
// Test if arg2 is a Smi.
|
2011-08-26 08:22:13 +00:00
|
|
|
__ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ SmiUntag(eax);
|
|
|
|
__ mov(ecx, eax);
|
2011-08-26 11:56:12 +00:00
|
|
|
__ jmp(&done);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// If the argument is undefined it converts to zero (ECMA-262, section 9.5).
|
|
|
|
__ bind(&check_undefined_arg2);
|
2011-03-25 13:21:30 +00:00
|
|
|
__ cmp(eax, factory->undefined_value());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, conversion_failure);
|
|
|
|
__ mov(ecx, Immediate(0));
|
2011-08-26 11:56:12 +00:00
|
|
|
__ jmp(&done);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&arg2_is_object);
|
|
|
|
__ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
|
2011-03-25 13:21:30 +00:00
|
|
|
__ cmp(ebx, factory->heap_number_map());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, &check_undefined_arg2);
|
|
|
|
|
|
|
|
// Get the untagged integer version of the eax heap number in ecx.
|
2011-05-11 13:45:30 +00:00
|
|
|
IntegerConvert(masm, eax, use_sse3, conversion_failure);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&done);
|
|
|
|
__ mov(eax, edx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void FloatingPointHelper::CheckLoadedIntegersWereInt32(MacroAssembler* masm,
|
|
|
|
bool use_sse3,
|
|
|
|
Label* not_int32) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm,
|
|
|
|
Register number) {
|
2011-05-10 09:03:42 +00:00
|
|
|
Label load_smi, done;
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(number, &load_smi, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ fld_d(FieldOperand(number, HeapNumber::kValueOffset));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ jmp(&done, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&load_smi);
|
|
|
|
__ SmiUntag(number);
|
|
|
|
__ push(number);
|
|
|
|
__ fild_s(Operand(esp, 0));
|
|
|
|
__ pop(number);
|
|
|
|
|
|
|
|
__ bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) {
|
2011-05-10 09:03:42 +00:00
|
|
|
Label load_smi_edx, load_eax, load_smi_eax, done;
|
2010-08-25 09:44:44 +00:00
|
|
|
// Load operand in edx into xmm0.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(edx, &load_smi_edx, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset));
|
|
|
|
|
|
|
|
__ bind(&load_eax);
|
|
|
|
// Load operand in eax into xmm1.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(eax, &load_smi_eax, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ jmp(&done, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&load_smi_edx);
|
|
|
|
__ SmiUntag(edx); // Untag smi before converting to float.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm0, edx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ SmiTag(edx); // Retag smi for heap number overwriting test.
|
|
|
|
__ jmp(&load_eax);
|
|
|
|
|
|
|
|
__ bind(&load_smi_eax);
|
|
|
|
__ SmiUntag(eax); // Untag smi before converting to float.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm1, eax);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ SmiTag(eax); // Retag smi for heap number overwriting test.
|
|
|
|
|
|
|
|
__ bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm,
|
|
|
|
Label* not_numbers) {
|
2011-05-10 09:03:42 +00:00
|
|
|
Label load_smi_edx, load_eax, load_smi_eax, load_float_eax, done;
|
2010-08-25 09:44:44 +00:00
|
|
|
// Load operand in edx into xmm0, or branch to not_numbers.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(edx, &load_smi_edx, Label::kNear);
|
2011-03-25 13:21:30 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
__ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, not_numbers); // Argument in edx is not a number.
|
|
|
|
__ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset));
|
|
|
|
__ bind(&load_eax);
|
|
|
|
// Load operand in eax into xmm1, or branch to not_numbers.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(eax, &load_smi_eax, Label::kNear);
|
2011-03-25 13:21:30 +00:00
|
|
|
__ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map());
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(equal, &load_float_eax, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ jmp(not_numbers); // Argument in eax is not a number.
|
|
|
|
__ bind(&load_smi_edx);
|
|
|
|
__ SmiUntag(edx); // Untag smi before converting to float.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm0, edx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ SmiTag(edx); // Retag smi for heap number overwriting test.
|
|
|
|
__ jmp(&load_eax);
|
|
|
|
__ bind(&load_smi_eax);
|
|
|
|
__ SmiUntag(eax); // Untag smi before converting to float.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm1, eax);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ SmiTag(eax); // Retag smi for heap number overwriting test.
|
2011-05-10 09:03:42 +00:00
|
|
|
__ jmp(&done, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&load_float_eax);
|
|
|
|
__ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
__ bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm,
|
|
|
|
Register scratch) {
|
|
|
|
const Register left = edx;
|
|
|
|
const Register right = eax;
|
|
|
|
__ mov(scratch, left);
|
|
|
|
ASSERT(!scratch.is(right)); // We're about to clobber scratch.
|
|
|
|
__ SmiUntag(scratch);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm0, scratch);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ mov(scratch, right);
|
|
|
|
__ SmiUntag(scratch);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm1, scratch);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void FloatingPointHelper::CheckSSE2OperandsAreInt32(MacroAssembler* masm,
|
|
|
|
Label* non_int32,
|
|
|
|
Register scratch) {
|
|
|
|
__ cvttsd2si(scratch, Operand(xmm0));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm2, scratch);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ ucomisd(xmm0, xmm2);
|
|
|
|
__ j(not_zero, non_int32);
|
|
|
|
__ j(carry, non_int32);
|
|
|
|
__ cvttsd2si(scratch, Operand(xmm1));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm2, scratch);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ ucomisd(xmm1, xmm2);
|
|
|
|
__ j(not_zero, non_int32);
|
|
|
|
__ j(carry, non_int32);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm,
|
|
|
|
Register scratch,
|
|
|
|
ArgLocation arg_location) {
|
2011-05-10 09:03:42 +00:00
|
|
|
Label load_smi_1, load_smi_2, done_load_1, done;
|
2010-08-25 09:44:44 +00:00
|
|
|
if (arg_location == ARGS_IN_REGISTERS) {
|
|
|
|
__ mov(scratch, edx);
|
|
|
|
} else {
|
|
|
|
__ mov(scratch, Operand(esp, 2 * kPointerSize));
|
|
|
|
}
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(scratch, &load_smi_1, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset));
|
|
|
|
__ bind(&done_load_1);
|
|
|
|
|
|
|
|
if (arg_location == ARGS_IN_REGISTERS) {
|
|
|
|
__ mov(scratch, eax);
|
|
|
|
} else {
|
|
|
|
__ mov(scratch, Operand(esp, 1 * kPointerSize));
|
|
|
|
}
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(scratch, &load_smi_2, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ jmp(&done, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&load_smi_1);
|
|
|
|
__ SmiUntag(scratch);
|
|
|
|
__ push(scratch);
|
|
|
|
__ fild_s(Operand(esp, 0));
|
|
|
|
__ pop(scratch);
|
|
|
|
__ jmp(&done_load_1);
|
|
|
|
|
|
|
|
__ bind(&load_smi_2);
|
|
|
|
__ SmiUntag(scratch);
|
|
|
|
__ push(scratch);
|
|
|
|
__ fild_s(Operand(esp, 0));
|
|
|
|
__ pop(scratch);
|
|
|
|
|
|
|
|
__ bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm,
|
|
|
|
Register scratch) {
|
|
|
|
const Register left = edx;
|
|
|
|
const Register right = eax;
|
|
|
|
__ mov(scratch, left);
|
|
|
|
ASSERT(!scratch.is(right)); // We're about to clobber scratch.
|
|
|
|
__ SmiUntag(scratch);
|
|
|
|
__ push(scratch);
|
|
|
|
__ fild_s(Operand(esp, 0));
|
|
|
|
|
|
|
|
__ mov(scratch, right);
|
|
|
|
__ SmiUntag(scratch);
|
|
|
|
__ mov(Operand(esp, 0), scratch);
|
|
|
|
__ fild_s(Operand(esp, 0));
|
|
|
|
__ pop(scratch);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm,
|
|
|
|
Label* non_float,
|
|
|
|
Register scratch) {
|
2011-05-10 09:03:42 +00:00
|
|
|
Label test_other, done;
|
2010-08-25 09:44:44 +00:00
|
|
|
// Test if both operands are floats or smi -> scratch=k_is_float;
|
|
|
|
// Otherwise scratch = k_not_float.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(edx, &test_other, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset));
|
2011-03-25 13:21:30 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
__ cmp(scratch, factory->heap_number_map());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, non_float); // argument in edx is not a number -> NaN
|
|
|
|
|
|
|
|
__ bind(&test_other);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(eax, &done, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset));
|
2011-03-25 13:21:30 +00:00
|
|
|
__ cmp(scratch, factory->heap_number_map());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, non_float); // argument in eax is not a number -> NaN
|
|
|
|
|
|
|
|
// Fall-through: Both operands are numbers.
|
|
|
|
__ bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void FloatingPointHelper::CheckFloatOperandsAreInt32(MacroAssembler* masm,
|
|
|
|
Label* non_int32) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathPowStub::Generate(MacroAssembler* masm) {
|
|
|
|
CpuFeatures::Scope use_sse2(SSE2);
|
2011-12-02 08:06:37 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
Label double_int_runtime, generic_runtime, done;
|
|
|
|
Label base_is_smi, unpack_exponent, exponent_not_smi, int_exponent;
|
2010-12-07 11:31:57 +00:00
|
|
|
// Save 1 in xmm3 - we need this several times later on.
|
|
|
|
__ mov(ecx, Immediate(1));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cvtsi2sd(xmm3, ecx);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-12-02 08:06:37 +00:00
|
|
|
switch (exponent_type_) {
|
|
|
|
case ON_STACK:
|
|
|
|
// 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
|
|
|
|
__ mov(edx, Operand(esp, 2 * kPointerSize));
|
|
|
|
__ mov(eax, Operand(esp, 1 * kPointerSize));
|
|
|
|
// edx: base (smi or heap number)
|
|
|
|
// eax: exponent (smi or heap number)
|
|
|
|
__ JumpIfSmi(edx, &base_is_smi, Label::kNear);
|
|
|
|
__ cmp(FieldOperand(edx, HeapObject::kMapOffset),
|
|
|
|
factory->heap_number_map());
|
|
|
|
__ j(not_equal, &generic_runtime);
|
|
|
|
|
|
|
|
// Check base for NaN or +/-Infinity
|
|
|
|
__ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset));
|
|
|
|
__ and_(ecx, HeapNumber::kExponentMask);
|
|
|
|
__ cmp(ecx, Immediate(HeapNumber::kExponentMask));
|
|
|
|
__ j(equal, &generic_runtime);
|
|
|
|
__ movdbl(xmm1, FieldOperand(edx, HeapNumber::kValueOffset));
|
|
|
|
__ jmp(&unpack_exponent, Label::kNear);
|
|
|
|
|
|
|
|
__ bind(&base_is_smi);
|
|
|
|
__ SmiUntag(edx);
|
|
|
|
__ cvtsi2sd(xmm1, edx);
|
|
|
|
__ bind(&unpack_exponent);
|
|
|
|
|
|
|
|
__ JumpIfNotSmi(eax, &exponent_not_smi, Label::kNear);
|
|
|
|
__ SmiUntag(eax);
|
|
|
|
__ jmp(&int_exponent);
|
|
|
|
|
|
|
|
__ bind(&exponent_not_smi);
|
|
|
|
__ cmp(FieldOperand(eax, HeapObject::kMapOffset),
|
|
|
|
factory->heap_number_map());
|
|
|
|
__ j(not_equal, &generic_runtime);
|
|
|
|
__ movdbl(xmm2, FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TAGGED:
|
|
|
|
// xmm1: base as double
|
|
|
|
// eax: exponent (smi or heap number)
|
|
|
|
__ JumpIfNotSmi(eax, &exponent_not_smi, Label::kNear);
|
|
|
|
__ SmiUntag(eax);
|
|
|
|
__ jmp(&int_exponent);
|
|
|
|
|
|
|
|
__ bind(&exponent_not_smi);
|
|
|
|
__ movdbl(xmm2, FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
// Fall through intended
|
|
|
|
case INTEGER:
|
|
|
|
// xmm1: base as double
|
|
|
|
// eax: exponent as untagged integer
|
|
|
|
case DOUBLE:
|
|
|
|
// xmm1: base as double
|
|
|
|
// xmm2: exponent as double
|
|
|
|
// Check base in xmm1 for NaN or +/-Infinity
|
|
|
|
const int kExponentShift = kBitsPerByte *
|
|
|
|
(HeapNumber::kExponentOffset - HeapNumber::kMantissaOffset);
|
|
|
|
if (CpuFeatures::IsSupported(SSE4_1)) {
|
|
|
|
__ extractps(ecx, xmm1, kExponentShift);
|
|
|
|
} else {
|
|
|
|
__ movsd(xmm4, xmm1);
|
|
|
|
__ psrlq(xmm4, kExponentShift);
|
|
|
|
__ movd(ecx, xmm4);
|
|
|
|
}
|
|
|
|
__ and_(ecx, HeapNumber::kExponentMask);
|
|
|
|
__ cmp(ecx, Immediate(HeapNumber::kExponentMask));
|
|
|
|
__ j(equal, &generic_runtime);
|
|
|
|
break;
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-12-02 08:06:37 +00:00
|
|
|
if (exponent_type_ != INTEGER) {
|
|
|
|
Label not_minus_half, fast_power;
|
|
|
|
// xmm1: base as double that is not +/- Infinity or NaN
|
|
|
|
// xmm2: exponent as double
|
|
|
|
// Detect integer exponents stored as double.
|
|
|
|
__ cvttsd2si(eax, Operand(xmm2));
|
|
|
|
// Skip to runtime if possibly NaN (indicated by the indefinite integer).
|
|
|
|
__ cmp(eax, Immediate(0x80000000u));
|
|
|
|
__ j(equal, &generic_runtime);
|
|
|
|
__ cvtsi2sd(xmm4, eax);
|
|
|
|
__ ucomisd(xmm2, xmm4);
|
|
|
|
__ j(equal, &int_exponent);
|
|
|
|
|
|
|
|
// Detect square root case.
|
|
|
|
// Test for -0.5.
|
|
|
|
// Load xmm4 with -0.5.
|
|
|
|
__ mov(ecx, Immediate(0xBF000000u));
|
|
|
|
__ movd(xmm4, ecx);
|
|
|
|
__ cvtss2sd(xmm4, xmm4);
|
|
|
|
// xmm3 now has -0.5.
|
|
|
|
__ ucomisd(xmm4, xmm2);
|
|
|
|
__ j(not_equal, ¬_minus_half, Label::kNear);
|
|
|
|
|
|
|
|
// Calculates reciprocal of square root.eax
|
|
|
|
// sqrtsd returns -0 when input is -0. ECMA spec requires +0.
|
|
|
|
__ xorps(xmm2, xmm2);
|
|
|
|
__ addsd(xmm2, xmm1);
|
|
|
|
__ sqrtsd(xmm2, xmm2);
|
|
|
|
__ divsd(xmm3, xmm2);
|
|
|
|
__ jmp(&done);
|
|
|
|
|
|
|
|
// Test for 0.5.
|
|
|
|
__ bind(¬_minus_half);
|
|
|
|
// Load xmm2 with 0.5.
|
|
|
|
// Since xmm3 is 1 and xmm4 is -0.5 this is simply xmm4 + xmm3.
|
|
|
|
__ addsd(xmm4, xmm3);
|
|
|
|
// xmm2 now has 0.5.
|
|
|
|
__ ucomisd(xmm4, xmm2);
|
|
|
|
__ j(not_equal, &fast_power, Label::kNear);
|
|
|
|
// Calculates square root.
|
|
|
|
// sqrtsd returns -0 when input is -0. ECMA spec requires +0.
|
|
|
|
__ xorps(xmm4, xmm4);
|
|
|
|
__ addsd(xmm4, xmm1);
|
|
|
|
__ sqrtsd(xmm3, xmm4);
|
|
|
|
__ jmp(&done);
|
|
|
|
|
|
|
|
// Using FPU instructions to calculate power.
|
|
|
|
Label fast_power_failed;
|
|
|
|
__ bind(&fast_power);
|
|
|
|
__ fnclex(); // Clear flags to catch exceptions later.
|
|
|
|
// Transfer (B)ase and (E)xponent onto the FPU register stack.
|
|
|
|
__ sub(esp, Immediate(kDoubleSize));
|
|
|
|
__ movdbl(Operand(esp, 0), xmm2);
|
|
|
|
__ fld_d(Operand(esp, 0)); // E
|
|
|
|
__ movdbl(Operand(esp, 0), xmm1);
|
|
|
|
__ fld_d(Operand(esp, 0)); // B, E
|
|
|
|
|
|
|
|
// Exponent is in st(1) and base is in st(0)
|
|
|
|
// B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B)
|
|
|
|
// FYL2X calculates st(1) * log2(st(0))
|
|
|
|
__ fyl2x(); // X
|
|
|
|
__ fld(0); // X, X
|
|
|
|
__ frndint(); // rnd(X), X
|
|
|
|
__ fsub(1); // rnd(X), X-rnd(X)
|
|
|
|
__ fxch(1); // X - rnd(X), rnd(X)
|
|
|
|
// F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1
|
|
|
|
__ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X)
|
|
|
|
__ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X)
|
|
|
|
__ faddp(1); // 1, 2^(X-rnd(X)), rnd(X)
|
|
|
|
// FSCALE calculates st(0) * 2^st(1)
|
|
|
|
__ fscale(); // 2^X, rnd(X)
|
|
|
|
__ fstp(1);
|
|
|
|
// Bail out to runtime in case of exceptions in the status word.
|
|
|
|
__ fnstsw_ax();
|
|
|
|
__ test_b(eax, 0x5F); // We check for all but precision exception.
|
|
|
|
__ j(not_zero, &fast_power_failed, Label::kNear);
|
|
|
|
__ fstp_d(Operand(esp, 0));
|
|
|
|
__ movdbl(xmm3, Operand(esp, 0));
|
|
|
|
__ add(esp, Immediate(kDoubleSize));
|
|
|
|
__ jmp(&done);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-12-02 08:06:37 +00:00
|
|
|
__ bind(&fast_power_failed);
|
|
|
|
__ fninit();
|
|
|
|
__ add(esp, Immediate(kDoubleSize));
|
|
|
|
__ jmp(&generic_runtime);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-12-02 08:06:37 +00:00
|
|
|
// Calculate power with integer exponent.
|
|
|
|
__ bind(&int_exponent);
|
|
|
|
// xmm1: base as double that is not +/- Infinity or NaN
|
|
|
|
// eax: exponent as untagged integer
|
|
|
|
__ mov(ecx, eax); // Back up exponent.
|
|
|
|
__ movsd(xmm4, xmm1); // Back up base.
|
|
|
|
__ movsd(xmm2, xmm3); // Load xmm2 with 1.
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Get absolute value of exponent.
|
2011-12-02 08:06:37 +00:00
|
|
|
Label no_neg, while_true, no_multiply;
|
2010-12-07 11:31:57 +00:00
|
|
|
__ cmp(eax, 0);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(greater_equal, &no_neg, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ neg(eax);
|
|
|
|
__ bind(&no_neg);
|
|
|
|
|
|
|
|
__ bind(&while_true);
|
|
|
|
__ shr(eax, 1);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_carry, &no_multiply, Label::kNear);
|
2011-12-02 08:06:37 +00:00
|
|
|
__ mulsd(xmm3, xmm1);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ bind(&no_multiply);
|
2011-12-02 08:06:37 +00:00
|
|
|
|
|
|
|
__ mulsd(xmm1, xmm1);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ j(not_zero, &while_true);
|
|
|
|
|
|
|
|
// base has the original value of the exponent - if the exponent is
|
|
|
|
// negative return 1/result.
|
2011-12-02 08:06:37 +00:00
|
|
|
__ test(ecx, ecx);
|
|
|
|
__ j(positive, &done);
|
|
|
|
__ divsd(xmm2, xmm3);
|
|
|
|
__ movsd(xmm3, xmm2);
|
|
|
|
// 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.
|
|
|
|
__ xorps(xmm2, xmm2);
|
|
|
|
__ ucomisd(xmm2, xmm3);
|
|
|
|
__ j(equal, &double_int_runtime);
|
|
|
|
|
|
|
|
// Returning or bailing out.
|
|
|
|
if (exponent_type_ == ON_STACK) {
|
|
|
|
// The stub is called from non-optimized code, which expects the result
|
|
|
|
// as heap number in eax.
|
|
|
|
__ bind(&done);
|
|
|
|
// xmm3: result
|
|
|
|
__ AllocateHeapNumber(eax, ecx, edx, &generic_runtime);
|
|
|
|
__ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm3);
|
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
|
|
|
|
// The arguments are still on the stack.
|
|
|
|
__ bind(&generic_runtime);
|
|
|
|
__ bind(&double_int_runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1);
|
|
|
|
} else {
|
|
|
|
__ jmp(&done);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-12-02 08:06:37 +00:00
|
|
|
Label return_from_runtime;
|
|
|
|
StubRuntimeCallHelper callhelper;
|
|
|
|
__ bind(&generic_runtime);
|
|
|
|
// xmm1: base
|
|
|
|
// xmm2: exponent
|
|
|
|
{
|
|
|
|
AllowExternalCallThatCantCauseGC scope(masm);
|
|
|
|
__ PrepareCallCFunction(4, eax);
|
|
|
|
__ movdbl(Operand(esp, 0 * kDoubleSize), xmm1);
|
|
|
|
__ movdbl(Operand(esp, 1 * kDoubleSize), xmm2);
|
|
|
|
__ CallCFunction(
|
|
|
|
ExternalReference::power_double_double_function(masm->isolate()), 4);
|
|
|
|
}
|
|
|
|
__ jmp(&return_from_runtime, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-12-02 08:06:37 +00:00
|
|
|
__ bind(&double_int_runtime);
|
|
|
|
// xmm4: base
|
|
|
|
// ecx: exponent
|
|
|
|
{
|
|
|
|
AllowExternalCallThatCantCauseGC scope(masm);
|
|
|
|
__ PrepareCallCFunction(4, eax);
|
|
|
|
__ movdbl(Operand(esp, 0 * kDoubleSize), xmm4);
|
|
|
|
__ mov(Operand(esp, 1 * kDoubleSize), ecx);
|
|
|
|
__ CallCFunction(
|
|
|
|
ExternalReference::power_double_int_function(masm->isolate()), 4);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-12-02 08:06:37 +00:00
|
|
|
__ bind(&return_from_runtime);
|
|
|
|
// Return value is in st(0) on ia32.
|
|
|
|
// Store it into the (fixed) result register.
|
|
|
|
__ sub(esp, Immediate(kDoubleSize));
|
|
|
|
__ fstp_d(Operand(esp, 0));
|
|
|
|
__ movdbl(xmm3, Operand(esp, 0));
|
|
|
|
__ add(esp, Immediate(kDoubleSize));
|
|
|
|
|
|
|
|
// xmm3: result
|
|
|
|
__ bind(&done);
|
|
|
|
__ ret(0);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
|
|
|
|
// The key is in edx and the parameter count is in eax.
|
|
|
|
|
|
|
|
// The displacement is used for skipping the frame pointer on the
|
|
|
|
// stack. It is the offset of the last parameter (if any) relative
|
|
|
|
// to the frame pointer.
|
|
|
|
static const int kDisplacement = 1 * kPointerSize;
|
|
|
|
|
|
|
|
// Check that the key is a smi.
|
|
|
|
Label slow;
|
2011-08-26 08:22:13 +00:00
|
|
|
__ JumpIfNotSmi(edx, &slow, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Check if the calling frame is an arguments adaptor frame.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label adaptor;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
|
|
|
|
__ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(equal, &adaptor, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Check index against formal parameters count limit passed in
|
|
|
|
// through register eax. Use unsigned comparison to get negative
|
|
|
|
// check for free.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(edx, eax);
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(above_equal, &slow, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Read the argument from the stack and return it.
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these.
|
|
|
|
__ lea(ebx, Operand(ebp, eax, times_2, 0));
|
|
|
|
__ neg(edx);
|
|
|
|
__ mov(eax, Operand(ebx, edx, times_2, kDisplacement));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
__ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(edx, ecx);
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(above_equal, &slow, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Read the argument from the stack and return it.
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these.
|
|
|
|
__ lea(ebx, Operand(ebx, ecx, times_2, 0));
|
|
|
|
__ neg(edx);
|
|
|
|
__ mov(eax, Operand(ebx, edx, times_2, kDisplacement));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Slow-case: Handle non-smi or out-of-bounds access to arguments
|
|
|
|
// by calling the runtime system.
|
|
|
|
__ bind(&slow);
|
|
|
|
__ pop(ebx); // Return address.
|
|
|
|
__ push(edx);
|
|
|
|
__ push(ebx);
|
|
|
|
__ 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
|
|
|
// esp[0] : return address
|
|
|
|
// esp[4] : number of parameters
|
|
|
|
// esp[8] : receiver displacement
|
2011-06-16 14:12:58 +00:00
|
|
|
// esp[12] : function
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-06-16 14:12:58 +00:00
|
|
|
// Check if the calling frame is an arguments adaptor frame.
|
|
|
|
Label runtime;
|
|
|
|
__ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
|
|
|
|
__ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ j(not_equal, &runtime, Label::kNear);
|
|
|
|
|
|
|
|
// Patch the arguments.length and the parameters pointer.
|
|
|
|
__ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset));
|
|
|
|
__ mov(Operand(esp, 1 * kPointerSize), ecx);
|
|
|
|
__ lea(edx, Operand(edx, ecx, times_2,
|
|
|
|
StandardFrameConstants::kCallerSPOffset));
|
|
|
|
__ mov(Operand(esp, 2 * kPointerSize), edx);
|
|
|
|
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) {
|
|
|
|
// esp[0] : return address
|
|
|
|
// esp[4] : number of parameters (tagged)
|
|
|
|
// esp[8] : receiver displacement
|
|
|
|
// esp[12] : function
|
|
|
|
|
|
|
|
// ebx = parameter count (tagged)
|
|
|
|
__ mov(ebx, Operand(esp, 1 * kPointerSize));
|
|
|
|
|
|
|
|
// Check if the calling frame is an arguments adaptor frame.
|
|
|
|
// TODO(rossberg): Factor out some of the bits that are shared with the other
|
|
|
|
// Generate* functions.
|
|
|
|
Label runtime;
|
|
|
|
Label adaptor_frame, try_allocate;
|
|
|
|
__ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
|
|
|
|
__ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ j(equal, &adaptor_frame, Label::kNear);
|
|
|
|
|
|
|
|
// No adaptor, parameter count = argument count.
|
|
|
|
__ mov(ecx, ebx);
|
|
|
|
__ jmp(&try_allocate, Label::kNear);
|
|
|
|
|
|
|
|
// We have an adaptor frame. Patch the parameters pointer.
|
|
|
|
__ bind(&adaptor_frame);
|
|
|
|
__ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset));
|
|
|
|
__ lea(edx, Operand(edx, ecx, times_2,
|
|
|
|
StandardFrameConstants::kCallerSPOffset));
|
|
|
|
__ mov(Operand(esp, 2 * kPointerSize), edx);
|
|
|
|
|
|
|
|
// ebx = parameter count (tagged)
|
|
|
|
// ecx = argument count (tagged)
|
|
|
|
// esp[4] = parameter count (tagged)
|
|
|
|
// esp[8] = address of receiver argument
|
|
|
|
// Compute the mapped parameter count = min(ebx, ecx) in ebx.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ebx, ecx);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ j(less_equal, &try_allocate, Label::kNear);
|
|
|
|
__ mov(ebx, ecx);
|
|
|
|
|
|
|
|
__ bind(&try_allocate);
|
|
|
|
|
|
|
|
// Save mapped parameter count.
|
|
|
|
__ push(ebx);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
Label no_parameter_map;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(ebx, ebx);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ j(zero, &no_parameter_map, Label::kNear);
|
|
|
|
__ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize));
|
|
|
|
__ bind(&no_parameter_map);
|
|
|
|
|
|
|
|
// 2. Backing store.
|
|
|
|
__ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize));
|
|
|
|
|
|
|
|
// 3. Arguments object.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(ebx, Immediate(Heap::kArgumentsObjectSize));
|
2011-06-16 14:12:58 +00:00
|
|
|
|
|
|
|
// Do the allocation of all three objects in one go.
|
|
|
|
__ AllocateInNewSpace(ebx, eax, edx, edi, &runtime, TAG_OBJECT);
|
|
|
|
|
|
|
|
// eax = address of new object(s) (tagged)
|
|
|
|
// ecx = argument count (tagged)
|
|
|
|
// esp[0] = mapped parameter count (tagged)
|
|
|
|
// esp[8] = parameter count (tagged)
|
|
|
|
// esp[12] = address of receiver argument
|
|
|
|
// Get the arguments boilerplate from the current (global) context into edi.
|
|
|
|
Label has_mapped_parameters, copy;
|
|
|
|
__ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX)));
|
|
|
|
__ mov(edi, FieldOperand(edi, GlobalObject::kGlobalContextOffset));
|
|
|
|
__ mov(ebx, Operand(esp, 0 * kPointerSize));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(ebx, ebx);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ j(not_zero, &has_mapped_parameters, Label::kNear);
|
|
|
|
__ mov(edi, Operand(edi,
|
|
|
|
Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX)));
|
|
|
|
__ jmp(©, Label::kNear);
|
|
|
|
|
|
|
|
__ bind(&has_mapped_parameters);
|
|
|
|
__ mov(edi, Operand(edi,
|
|
|
|
Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX)));
|
|
|
|
__ bind(©);
|
|
|
|
|
|
|
|
// eax = address of new object (tagged)
|
|
|
|
// ebx = mapped parameter count (tagged)
|
|
|
|
// ecx = argument count (tagged)
|
|
|
|
// edi = address of boilerplate object (tagged)
|
|
|
|
// esp[0] = mapped parameter count (tagged)
|
|
|
|
// esp[8] = parameter count (tagged)
|
|
|
|
// esp[12] = address of receiver argument
|
|
|
|
// Copy the JS object part.
|
|
|
|
for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) {
|
|
|
|
__ mov(edx, FieldOperand(edi, i));
|
|
|
|
__ mov(FieldOperand(eax, i), edx);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the callee in-object property.
|
|
|
|
STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
|
|
|
|
__ mov(edx, Operand(esp, 4 * kPointerSize));
|
|
|
|
__ mov(FieldOperand(eax, JSObject::kHeaderSize +
|
|
|
|
Heap::kArgumentsCalleeIndex * kPointerSize),
|
|
|
|
edx);
|
|
|
|
|
|
|
|
// Use the length (smi tagged) and set that as an in-object property too.
|
|
|
|
STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
|
|
|
|
__ mov(FieldOperand(eax, JSObject::kHeaderSize +
|
|
|
|
Heap::kArgumentsLengthIndex * kPointerSize),
|
|
|
|
ecx);
|
|
|
|
|
|
|
|
// Setup the elements pointer in the allocated arguments object.
|
|
|
|
// If we allocated a parameter map, edi will point there, otherwise to the
|
|
|
|
// backing store.
|
|
|
|
__ lea(edi, Operand(eax, Heap::kArgumentsObjectSize));
|
|
|
|
__ mov(FieldOperand(eax, JSObject::kElementsOffset), edi);
|
|
|
|
|
|
|
|
// eax = address of new object (tagged)
|
|
|
|
// ebx = mapped parameter count (tagged)
|
|
|
|
// ecx = argument count (tagged)
|
|
|
|
// edi = address of parameter map or backing store (tagged)
|
|
|
|
// esp[0] = mapped parameter count (tagged)
|
|
|
|
// esp[8] = parameter count (tagged)
|
|
|
|
// esp[12] = address of receiver argument
|
|
|
|
// Free a register.
|
|
|
|
__ push(eax);
|
|
|
|
|
|
|
|
// Initialize parameter map. If there are no mapped arguments, we're done.
|
|
|
|
Label skip_parameter_map;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(ebx, ebx);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ j(zero, &skip_parameter_map);
|
|
|
|
|
|
|
|
__ mov(FieldOperand(edi, FixedArray::kMapOffset),
|
|
|
|
Immediate(FACTORY->non_strict_arguments_elements_map()));
|
|
|
|
__ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2))));
|
|
|
|
__ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax);
|
|
|
|
__ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi);
|
|
|
|
__ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize));
|
|
|
|
__ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
__ push(ecx);
|
|
|
|
__ mov(eax, Operand(esp, 2 * kPointerSize));
|
|
|
|
__ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS)));
|
|
|
|
__ add(ebx, Operand(esp, 4 * kPointerSize));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(ebx, eax);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ mov(ecx, FACTORY->the_hole_value());
|
|
|
|
__ mov(edx, edi);
|
|
|
|
__ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize));
|
|
|
|
// eax = loop variable (tagged)
|
|
|
|
// ebx = mapping index (tagged)
|
|
|
|
// ecx = the hole value
|
|
|
|
// edx = address of parameter map (tagged)
|
|
|
|
// edi = address of backing store (tagged)
|
|
|
|
// esp[0] = argument count (tagged)
|
|
|
|
// esp[4] = address of new object (tagged)
|
|
|
|
// esp[8] = mapped parameter count (tagged)
|
|
|
|
// esp[16] = parameter count (tagged)
|
|
|
|
// esp[20] = address of receiver argument
|
|
|
|
__ jmp(¶meters_test, Label::kNear);
|
|
|
|
|
|
|
|
__ bind(¶meters_loop);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(eax, Immediate(Smi::FromInt(1)));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx);
|
|
|
|
__ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(ebx, Immediate(Smi::FromInt(1)));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ bind(¶meters_test);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(eax, eax);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ j(not_zero, ¶meters_loop, Label::kNear);
|
|
|
|
__ pop(ecx);
|
|
|
|
|
|
|
|
__ bind(&skip_parameter_map);
|
|
|
|
|
|
|
|
// ecx = argument count (tagged)
|
|
|
|
// edi = address of backing store (tagged)
|
|
|
|
// esp[0] = address of new object (tagged)
|
|
|
|
// esp[4] = mapped parameter count (tagged)
|
|
|
|
// esp[12] = parameter count (tagged)
|
|
|
|
// esp[16] = address of receiver argument
|
|
|
|
// Copy arguments header and remaining slots (if there are any).
|
|
|
|
__ mov(FieldOperand(edi, FixedArray::kMapOffset),
|
|
|
|
Immediate(FACTORY->fixed_array_map()));
|
|
|
|
__ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx);
|
|
|
|
|
|
|
|
Label arguments_loop, arguments_test;
|
|
|
|
__ mov(ebx, Operand(esp, 1 * kPointerSize));
|
|
|
|
__ mov(edx, Operand(esp, 4 * kPointerSize));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(edx, ebx); // Is there a smarter way to do negative scaling?
|
|
|
|
__ sub(edx, ebx);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ jmp(&arguments_test, Label::kNear);
|
|
|
|
|
|
|
|
__ bind(&arguments_loop);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(edx, Immediate(kPointerSize));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ mov(eax, Operand(edx, 0));
|
|
|
|
__ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(ebx, Immediate(Smi::FromInt(1)));
|
2011-06-16 14:12:58 +00:00
|
|
|
|
|
|
|
__ bind(&arguments_test);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ebx, ecx);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ j(less, &arguments_loop, Label::kNear);
|
|
|
|
|
|
|
|
// Restore.
|
|
|
|
__ pop(eax); // Address of arguments object.
|
|
|
|
__ pop(ebx); // Parameter count.
|
|
|
|
|
|
|
|
// Return and remove the on-stack parameters.
|
|
|
|
__ ret(3 * kPointerSize);
|
|
|
|
|
|
|
|
// Do the runtime call to allocate the arguments object.
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ pop(eax); // Remove saved parameter count.
|
|
|
|
__ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count.
|
|
|
|
__ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
|
|
|
|
// esp[0] : return address
|
|
|
|
// esp[4] : number of parameters
|
|
|
|
// esp[8] : receiver displacement
|
|
|
|
// esp[12] : 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;
|
|
|
|
__ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
|
|
|
|
__ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(equal, &adaptor_frame, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Get the length from the frame.
|
|
|
|
__ mov(ecx, Operand(esp, 1 * kPointerSize));
|
2011-08-26 08:22:13 +00:00
|
|
|
__ jmp(&try_allocate, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Patch the arguments.length and the parameters pointer.
|
|
|
|
__ bind(&adaptor_frame);
|
|
|
|
__ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset));
|
|
|
|
__ mov(Operand(esp, 1 * kPointerSize), ecx);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ lea(edx, Operand(edx, ecx, times_2,
|
|
|
|
StandardFrameConstants::kCallerSPOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(Operand(esp, 2 * kPointerSize), edx);
|
|
|
|
|
|
|
|
// Try the new space allocation. Start out with computing the size of
|
|
|
|
// the arguments object and the elements array.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label add_arguments_object;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&try_allocate);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(ecx, ecx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &add_arguments_object, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize));
|
|
|
|
__ bind(&add_arguments_object);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Do the allocation of both objects in one go.
|
|
|
|
__ AllocateInNewSpace(ecx, eax, edx, ebx, &runtime, TAG_OBJECT);
|
|
|
|
|
|
|
|
// Get the arguments boilerplate from the current (global) context.
|
|
|
|
__ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX)));
|
|
|
|
__ mov(edi, FieldOperand(edi, GlobalObject::kGlobalContextOffset));
|
2011-06-16 14:12:58 +00:00
|
|
|
const int offset =
|
|
|
|
Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX);
|
|
|
|
__ mov(edi, Operand(edi, offset));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Copy the JS object part.
|
|
|
|
for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) {
|
|
|
|
__ mov(ebx, FieldOperand(edi, i));
|
|
|
|
__ mov(FieldOperand(eax, i), ebx);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
__ mov(ecx, Operand(esp, 1 * kPointerSize));
|
2011-03-17 20:28:41 +00:00
|
|
|
__ mov(FieldOperand(eax, JSObject::kHeaderSize +
|
2011-06-16 14:12:58 +00:00
|
|
|
Heap::kArgumentsLengthIndex * kPointerSize),
|
2011-03-17 20:28:41 +00:00
|
|
|
ecx);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// If there are no actual arguments, we're done.
|
|
|
|
Label done;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(ecx, ecx);
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(zero, &done, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Get the parameters pointer from the stack.
|
|
|
|
__ mov(edx, Operand(esp, 2 * kPointerSize));
|
|
|
|
|
|
|
|
// Setup the elements pointer in the allocated arguments object and
|
|
|
|
// initialize the header in the elements fixed array.
|
2011-06-16 14:12:58 +00:00
|
|
|
__ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(FieldOperand(eax, JSObject::kElementsOffset), edi);
|
|
|
|
__ mov(FieldOperand(edi, FixedArray::kMapOffset),
|
2011-06-16 14:12:58 +00:00
|
|
|
Immediate(FACTORY->fixed_array_map()));
|
2011-03-17 20:28:41 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx);
|
|
|
|
// Untag the length for the loop below.
|
|
|
|
__ SmiUntag(ecx);
|
|
|
|
|
|
|
|
// Copy the fixed array slots.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label loop;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&loop);
|
|
|
|
__ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver.
|
|
|
|
__ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(edi, Immediate(kPointerSize));
|
|
|
|
__ sub(edx, Immediate(kPointerSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ dec(ecx);
|
|
|
|
__ j(not_zero, &loop);
|
|
|
|
|
|
|
|
// Return and remove the on-stack parameters.
|
|
|
|
__ bind(&done);
|
|
|
|
__ ret(3 * kPointerSize);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
// esp[0]: return address
|
|
|
|
// esp[4]: last_match_info (expected JSArray)
|
|
|
|
// esp[8]: previous index
|
|
|
|
// esp[12]: subject string
|
|
|
|
// esp[16]: JSRegExp object
|
|
|
|
|
|
|
|
static const int kLastMatchInfoOffset = 1 * kPointerSize;
|
|
|
|
static const int kPreviousIndexOffset = 2 * kPointerSize;
|
|
|
|
static const int kSubjectOffset = 3 * kPointerSize;
|
|
|
|
static const int kJSRegExpOffset = 4 * kPointerSize;
|
|
|
|
|
|
|
|
Label runtime, invoke_regexp;
|
|
|
|
|
|
|
|
// Ensure that a RegExp stack is allocated.
|
|
|
|
ExternalReference address_of_regexp_stack_memory_address =
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference::address_of_regexp_stack_memory_address(
|
|
|
|
masm->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(masm->isolate());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(ebx, ebx);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(zero, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Check that the first argument is a JSRegExp object.
|
|
|
|
__ mov(eax, Operand(esp, kJSRegExpOffset));
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(eax, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ CmpObjectType(eax, JS_REGEXP_TYPE, ecx);
|
|
|
|
__ j(not_equal, &runtime);
|
|
|
|
// Check that the RegExp has been compiled (data contains a fixed array).
|
|
|
|
__ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset));
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ test(ecx, Immediate(kSmiTagMask));
|
|
|
|
__ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected");
|
|
|
|
__ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx);
|
|
|
|
__ Check(equal, "Unexpected type for RegExp data, FixedArray expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
// ecx: RegExp data (FixedArray)
|
|
|
|
// Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
|
|
|
|
__ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP)));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, &runtime);
|
|
|
|
|
|
|
|
// ecx: RegExp data (FixedArray)
|
|
|
|
// Check that the number of captures fit in the static offsets vector buffer.
|
|
|
|
__ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset));
|
|
|
|
// Calculate number of capture registers (number_of_captures + 1) * 2. This
|
|
|
|
// uses the asumption that smis are 2 * their untagged value.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(edx, Immediate(2)); // edx was a smi.
|
2010-08-25 09:44:44 +00:00
|
|
|
// Check that the static offsets vector buffer is large enough.
|
|
|
|
__ cmp(edx, OffsetsVector::kStaticOffsetsVectorSize);
|
|
|
|
__ j(above, &runtime);
|
|
|
|
|
|
|
|
// ecx: RegExp data (FixedArray)
|
|
|
|
// edx: Number of capture registers
|
|
|
|
// Check that the second argument is a string.
|
|
|
|
__ mov(eax, Operand(esp, kSubjectOffset));
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(eax, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
Condition is_string = masm->IsObjectStringType(eax, ebx, ebx);
|
|
|
|
__ j(NegateCondition(is_string), &runtime);
|
|
|
|
// Get the length of the string to ebx.
|
|
|
|
__ mov(ebx, FieldOperand(eax, String::kLengthOffset));
|
|
|
|
|
|
|
|
// ebx: Length of subject string as a smi
|
|
|
|
// ecx: RegExp data (FixedArray)
|
|
|
|
// edx: Number of capture registers
|
|
|
|
// Check that the third argument is a positive smi less than the subject
|
|
|
|
// string length. A negative value will be greater (unsigned comparison).
|
|
|
|
__ mov(eax, Operand(esp, kPreviousIndexOffset));
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(eax, &runtime);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(eax, ebx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(above_equal, &runtime);
|
|
|
|
|
|
|
|
// ecx: RegExp data (FixedArray)
|
|
|
|
// edx: Number of capture registers
|
|
|
|
// Check that the fourth object is a JSArray object.
|
|
|
|
__ mov(eax, Operand(esp, kLastMatchInfoOffset));
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(eax, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ CmpObjectType(eax, JS_ARRAY_TYPE, ebx);
|
|
|
|
__ j(not_equal, &runtime);
|
|
|
|
// Check that the JSArray is in fast case.
|
|
|
|
__ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset));
|
|
|
|
__ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset));
|
2011-03-25 13:21:30 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
__ cmp(eax, factory->fixed_array_map());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, &runtime);
|
|
|
|
// Check that the last match info has space for the capture registers and the
|
|
|
|
// additional information.
|
|
|
|
__ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset));
|
|
|
|
__ SmiUntag(eax);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(edx, Immediate(RegExpImpl::kLastMatchOverhead));
|
|
|
|
__ cmp(edx, eax);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(greater, &runtime);
|
|
|
|
|
2011-08-26 13:03:30 +00:00
|
|
|
// Reset offset for possibly sliced string.
|
|
|
|
__ Set(edi, Immediate(0));
|
2010-08-25 09:44:44 +00:00
|
|
|
// ecx: RegExp data (FixedArray)
|
|
|
|
// Check the representation and encoding of the subject string.
|
|
|
|
Label seq_ascii_string, seq_two_byte_string, check_code;
|
|
|
|
__ mov(eax, Operand(esp, kSubjectOffset));
|
|
|
|
__ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
|
|
|
|
// First check for flat two byte string.
|
2011-11-25 14:04:47 +00:00
|
|
|
__ and_(ebx, kIsNotStringMask |
|
|
|
|
kStringRepresentationMask |
|
|
|
|
kStringEncodingMask |
|
|
|
|
kShortExternalStringMask);
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0);
|
2011-08-26 13:03:30 +00:00
|
|
|
__ j(zero, &seq_two_byte_string, Label::kNear);
|
2011-11-24 18:36:24 +00:00
|
|
|
// Any other flat string must be a flat ascii string. None of the following
|
2011-11-25 14:04:47 +00:00
|
|
|
// string type tests will succeed if subject is not a string or a short
|
|
|
|
// external string.
|
|
|
|
__ and_(ebx, Immediate(kIsNotStringMask |
|
|
|
|
kStringRepresentationMask |
|
|
|
|
kShortExternalStringMask));
|
2011-08-26 13:03:30 +00:00
|
|
|
__ j(zero, &seq_ascii_string, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-11-24 18:36:24 +00:00
|
|
|
// ebx: whether subject is a string and if yes, its string representation
|
2011-08-26 13:03:30 +00:00
|
|
|
// Check for flat cons string or sliced string.
|
2010-08-25 09:44:44 +00:00
|
|
|
// A flat cons string is a cons string where the second part is the empty
|
|
|
|
// string. In that case the subject string is just the first part of the cons
|
|
|
|
// string. Also in this case the first part of the cons string is known to be
|
|
|
|
// a sequential string or an external string.
|
2011-08-26 13:03:30 +00:00
|
|
|
// In the case of a sliced string its offset has to be taken into account.
|
2011-11-25 14:04:47 +00:00
|
|
|
Label cons_string, external_string, check_encoding;
|
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-10-03 11:44:39 +00:00
|
|
|
__ cmp(ebx, Immediate(kExternalStringTag));
|
2011-08-26 13:03:30 +00:00
|
|
|
__ j(less, &cons_string);
|
2011-11-25 14:04:47 +00:00
|
|
|
__ j(equal, &external_string);
|
2011-08-26 13:03:30 +00:00
|
|
|
|
2011-11-25 14:04:47 +00:00
|
|
|
// Catch non-string subject or short external string.
|
|
|
|
STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
|
|
|
|
__ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag));
|
2011-11-24 18:36:24 +00:00
|
|
|
__ j(not_zero, &runtime);
|
|
|
|
|
2011-08-26 13:03:30 +00:00
|
|
|
// String is sliced.
|
|
|
|
__ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset));
|
|
|
|
__ mov(eax, FieldOperand(eax, SlicedString::kParentOffset));
|
|
|
|
// edi: offset of sliced string, smi-tagged.
|
|
|
|
// eax: parent string.
|
|
|
|
__ jmp(&check_encoding, Label::kNear);
|
|
|
|
// String is a cons string, check whether it is flat.
|
|
|
|
__ bind(&cons_string);
|
|
|
|
__ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, &runtime);
|
|
|
|
__ mov(eax, FieldOperand(eax, ConsString::kFirstOffset));
|
2011-08-26 13:03:30 +00:00
|
|
|
__ bind(&check_encoding);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
|
2011-08-26 13:03:30 +00:00
|
|
|
// eax: first part of cons string or parent of sliced string.
|
|
|
|
// ebx: map of first part of cons string or map of parent of sliced string.
|
|
|
|
// Is first part of cons or parent of slice a flat two byte string?
|
2010-08-25 09:44:44 +00:00
|
|
|
__ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset),
|
|
|
|
kStringRepresentationMask | kStringEncodingMask);
|
|
|
|
STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0);
|
2011-08-26 13:03:30 +00:00
|
|
|
__ j(zero, &seq_two_byte_string, Label::kNear);
|
2011-11-25 14:04:47 +00:00
|
|
|
// Any other flat string must be sequential ascii or external.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ test_b(FieldOperand(ebx, Map::kInstanceTypeOffset),
|
|
|
|
kStringRepresentationMask);
|
2011-11-25 14:04:47 +00:00
|
|
|
__ j(not_zero, &external_string);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&seq_ascii_string);
|
|
|
|
// eax: subject string (flat ascii)
|
|
|
|
// ecx: RegExp data (FixedArray)
|
|
|
|
__ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset));
|
2011-08-26 13:03:30 +00:00
|
|
|
__ Set(ecx, Immediate(1)); // Type is ascii.
|
|
|
|
__ jmp(&check_code, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&seq_two_byte_string);
|
|
|
|
// eax: subject string (flat two byte)
|
|
|
|
// ecx: RegExp data (FixedArray)
|
|
|
|
__ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset));
|
2011-08-26 13:03:30 +00:00
|
|
|
__ Set(ecx, Immediate(0)); // Type is two byte.
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&check_code);
|
|
|
|
// Check that the irregexp code has been generated for the actual string
|
|
|
|
// encoding. If it has, the field contains a code object otherwise it contains
|
2011-07-05 06:19:53 +00:00
|
|
|
// a smi (code flushing support).
|
|
|
|
__ JumpIfSmi(edx, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// eax: subject string
|
|
|
|
// edx: code
|
2011-08-26 13:03:30 +00:00
|
|
|
// ecx: encoding of subject string (1 if ascii, 0 if two_byte);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Load used arguments before starting to push arguments for call to native
|
|
|
|
// RegExp code to avoid handling changing stack height.
|
|
|
|
__ mov(ebx, Operand(esp, kPreviousIndexOffset));
|
|
|
|
__ SmiUntag(ebx); // Previous index from smi.
|
|
|
|
|
|
|
|
// eax: subject string
|
|
|
|
// ebx: previous index
|
|
|
|
// edx: code
|
2011-08-26 13:03:30 +00:00
|
|
|
// ecx: encoding of subject string (1 if ascii 0 if two_byte);
|
2010-08-25 09:44:44 +00:00
|
|
|
// All checks done. Now push arguments for native regexp code.
|
2011-03-23 11:13:07 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
__ IncrementCounter(counters->regexp_entry_native(), 1);
|
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).
|
|
|
|
static const int kRegExpExecuteArguments = 8;
|
2011-02-15 13:53:51 +00:00
|
|
|
__ EnterApiExitFrame(kRegExpExecuteArguments);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
// Argument 8: Pass current isolate address.
|
|
|
|
__ mov(Operand(esp, 7 * kPointerSize),
|
|
|
|
Immediate(ExternalReference::isolate_address()));
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Argument 7: Indicate that this is a direct call from JavaScript.
|
|
|
|
__ mov(Operand(esp, 6 * kPointerSize), Immediate(1));
|
|
|
|
|
|
|
|
// Argument 6: Start (high end) of backtracking stack memory area.
|
2011-08-26 13:03:30 +00:00
|
|
|
__ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address));
|
|
|
|
__ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size));
|
|
|
|
__ mov(Operand(esp, 5 * kPointerSize), esi);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Argument 5: static offsets vector buffer.
|
|
|
|
__ mov(Operand(esp, 4 * kPointerSize),
|
2011-03-22 13:20:04 +00:00
|
|
|
Immediate(ExternalReference::address_of_static_offsets_vector(
|
|
|
|
masm->isolate())));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-08-26 13:03:30 +00:00
|
|
|
// Argument 2: Previous index.
|
|
|
|
__ mov(Operand(esp, 1 * kPointerSize), ebx);
|
|
|
|
|
|
|
|
// Argument 1: Original subject string.
|
|
|
|
// The original subject is in the previous stack frame. Therefore we have to
|
|
|
|
// use ebp, which points exactly to one pointer size below the previous esp.
|
|
|
|
// (Because creating a new stack frame pushes the previous ebp onto the stack
|
|
|
|
// and thereby moves up esp by one kPointerSize.)
|
|
|
|
__ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize));
|
|
|
|
__ mov(Operand(esp, 0 * kPointerSize), esi);
|
|
|
|
|
|
|
|
// esi: original subject string
|
|
|
|
// eax: underlying subject string
|
|
|
|
// ebx: previous index
|
|
|
|
// ecx: encoding of subject string (1 if ascii 0 if two_byte);
|
|
|
|
// edx: code
|
2010-08-25 09:44:44 +00:00
|
|
|
// Argument 4: End of string data
|
|
|
|
// Argument 3: Start of string data
|
2011-08-26 13:03:30 +00:00
|
|
|
// Prepare start and end index of the input.
|
|
|
|
// Load the length from the original sliced string if that is the case.
|
|
|
|
__ mov(esi, FieldOperand(esi, String::kLengthOffset));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(esi, edi); // Calculate input end wrt offset.
|
2011-08-26 13:03:30 +00:00
|
|
|
__ SmiUntag(edi);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(ebx, edi); // Calculate input start wrt offset.
|
2011-08-26 13:03:30 +00:00
|
|
|
|
|
|
|
// ebx: start index of the input string
|
|
|
|
// esi: end index of the input string
|
2011-05-10 09:03:42 +00:00
|
|
|
Label setup_two_byte, setup_rest;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(ecx, ecx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &setup_two_byte, Label::kNear);
|
2011-08-26 13:03:30 +00:00
|
|
|
__ SmiUntag(esi);
|
|
|
|
__ lea(ecx, FieldOperand(eax, esi, times_1, SeqAsciiString::kHeaderSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4.
|
|
|
|
__ lea(ecx, FieldOperand(eax, ebx, times_1, SeqAsciiString::kHeaderSize));
|
|
|
|
__ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3.
|
2011-05-10 09:03:42 +00:00
|
|
|
__ jmp(&setup_rest, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&setup_two_byte);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-08-26 13:03:30 +00:00
|
|
|
STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2).
|
|
|
|
__ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4.
|
|
|
|
__ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize));
|
|
|
|
__ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3.
|
|
|
|
|
|
|
|
__ bind(&setup_rest);
|
|
|
|
|
|
|
|
// Locate the code entry and call it.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag));
|
|
|
|
__ call(edx);
|
2011-02-15 13:53:51 +00:00
|
|
|
|
|
|
|
// Drop arguments and come back to JS mode.
|
|
|
|
__ LeaveApiExitFrame();
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Check the result.
|
|
|
|
Label success;
|
|
|
|
__ cmp(eax, NativeRegExpMacroAssembler::SUCCESS);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(equal, &success);
|
2010-08-25 09:44:44 +00:00
|
|
|
Label failure;
|
|
|
|
__ cmp(eax, NativeRegExpMacroAssembler::FAILURE);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(equal, &failure);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION);
|
|
|
|
// If not exception it can only be retry. Handle that in the runtime system.
|
|
|
|
__ j(not_equal, &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-09-08 16:29:57 +00:00
|
|
|
ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
|
2011-03-22 13:20:04 +00:00
|
|
|
masm->isolate());
|
2011-10-04 09:07:50 +00:00
|
|
|
__ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value()));
|
2011-02-15 13:53:51 +00:00
|
|
|
__ mov(eax, Operand::StaticVariable(pending_exception));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(edx, eax);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(equal, &runtime);
|
2011-02-15 13:53:51 +00:00
|
|
|
// For exception, throw the exception again.
|
|
|
|
|
|
|
|
// Clear the pending exception variable.
|
|
|
|
__ mov(Operand::StaticVariable(pending_exception), edx);
|
|
|
|
|
|
|
|
// Special handling of termination exceptions which are uncatchable
|
|
|
|
// by javascript code.
|
2011-03-25 13:21:30 +00:00
|
|
|
__ cmp(eax, factory->termination_exception());
|
2011-02-15 13:53:51 +00:00
|
|
|
Label throw_termination_exception;
|
2011-08-26 13:03:30 +00:00
|
|
|
__ j(equal, &throw_termination_exception, Label::kNear);
|
2011-02-15 13:53:51 +00:00
|
|
|
|
|
|
|
// Handle normal exception by following handler chain.
|
|
|
|
__ Throw(eax);
|
|
|
|
|
|
|
|
__ bind(&throw_termination_exception);
|
|
|
|
__ ThrowUncatchable(TERMINATION, eax);
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&failure);
|
2011-02-15 13:53:51 +00:00
|
|
|
// For failure to match, return null.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(eax, factory->null_value());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(4 * kPointerSize);
|
|
|
|
|
|
|
|
// Load RegExp data.
|
|
|
|
__ bind(&success);
|
|
|
|
__ mov(eax, Operand(esp, kJSRegExpOffset));
|
|
|
|
__ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset));
|
|
|
|
__ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset));
|
|
|
|
// Calculate number of capture registers (number_of_captures + 1) * 2.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(edx, Immediate(2)); // edx was a smi.
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// edx: Number of capture registers
|
|
|
|
// Load last_match_info which is still known to be a fast case JSArray.
|
|
|
|
__ mov(eax, Operand(esp, kLastMatchInfoOffset));
|
|
|
|
__ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset));
|
|
|
|
|
|
|
|
// ebx: last_match_info backing store (FixedArray)
|
|
|
|
// edx: number of capture registers
|
|
|
|
// Store the capture count.
|
|
|
|
__ SmiTag(edx); // Number of capture registers to smi.
|
|
|
|
__ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx);
|
|
|
|
__ SmiUntag(edx); // Number of capture registers back from smi.
|
|
|
|
// Store last subject and last input.
|
|
|
|
__ mov(eax, Operand(esp, kSubjectOffset));
|
|
|
|
__ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax);
|
2011-09-19 18:36:47 +00:00
|
|
|
__ RecordWriteField(ebx,
|
|
|
|
RegExpImpl::kLastSubjectOffset,
|
|
|
|
eax,
|
|
|
|
edi,
|
|
|
|
kDontSaveFPRegs);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(eax, Operand(esp, kSubjectOffset));
|
|
|
|
__ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax);
|
2011-09-19 18:36:47 +00:00
|
|
|
__ RecordWriteField(ebx,
|
|
|
|
RegExpImpl::kLastInputOffset,
|
|
|
|
eax,
|
|
|
|
edi,
|
|
|
|
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(masm->isolate());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(ecx, Immediate(address_of_static_offsets_vector));
|
|
|
|
|
|
|
|
// ebx: last_match_info backing store (FixedArray)
|
|
|
|
// ecx: offsets vector
|
|
|
|
// edx: number of capture registers
|
2011-05-10 09:03:42 +00:00
|
|
|
Label next_capture, done;
|
2010-08-25 09:44:44 +00:00
|
|
|
// Capture register counter starts from number of capture registers and
|
|
|
|
// counts down until wraping after zero.
|
|
|
|
__ bind(&next_capture);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(edx, Immediate(1));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(negative, &done, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Read the value from the static offsets vector buffer.
|
|
|
|
__ mov(edi, Operand(ecx, edx, times_int_size, 0));
|
|
|
|
__ SmiTag(edi);
|
|
|
|
// Store the smi value in the last match info.
|
|
|
|
__ mov(FieldOperand(ebx,
|
|
|
|
edx,
|
|
|
|
times_pointer_size,
|
|
|
|
RegExpImpl::kFirstCaptureOffset),
|
|
|
|
edi);
|
|
|
|
__ jmp(&next_capture);
|
|
|
|
__ bind(&done);
|
|
|
|
|
|
|
|
// Return last match info.
|
|
|
|
__ mov(eax, Operand(esp, kLastMatchInfoOffset));
|
|
|
|
__ ret(4 * kPointerSize);
|
|
|
|
|
2011-11-25 14:04:47 +00:00
|
|
|
// External string. Short external strings have already been ruled out.
|
|
|
|
// eax: subject string (expected to be external)
|
|
|
|
// ebx: scratch
|
|
|
|
__ bind(&external_string);
|
|
|
|
__ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(ebx, FieldOperand(ebx, 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.
|
|
|
|
__ test_b(ebx, kIsIndirectStringMask);
|
|
|
|
__ Assert(zero, "external string expected, but not found");
|
|
|
|
}
|
|
|
|
__ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset));
|
|
|
|
// Move the pointer so that offset-wise, it looks like a sequential string.
|
|
|
|
STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize);
|
|
|
|
__ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
|
|
|
|
STATIC_ASSERT(kTwoByteStringTag == 0);
|
|
|
|
__ test_b(ebx, kStringEncodingMask);
|
|
|
|
__ j(not_zero, &seq_ascii_string);
|
|
|
|
__ jmp(&seq_two_byte_string);
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Do the runtime call to execute the regexp.
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
|
|
|
|
#endif // V8_INTERPRETED_REGEXP
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void RegExpConstructResultStub::Generate(MacroAssembler* masm) {
|
|
|
|
const int kMaxInlineLength = 100;
|
|
|
|
Label slowcase;
|
2011-05-10 09:03:42 +00:00
|
|
|
Label done;
|
2010-12-07 11:31:57 +00:00
|
|
|
__ mov(ebx, Operand(esp, kPointerSize * 3));
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(ebx, &slowcase);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength)));
|
2010-12-07 11:31:57 +00:00
|
|
|
__ j(above, &slowcase);
|
|
|
|
// Smi-tagging is equivalent to multiplying by 2.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
// Allocate RegExpResult followed by FixedArray with size in ebx.
|
|
|
|
// JSArray: [Map][empty properties][Elements][Length-smi][index][input]
|
|
|
|
// Elements: [Map][Length][..elements..]
|
|
|
|
__ AllocateInNewSpace(JSRegExpResult::kSize + FixedArray::kHeaderSize,
|
|
|
|
times_half_pointer_size,
|
|
|
|
ebx, // In: Number of elements (times 2, being a smi)
|
|
|
|
eax, // Out: Start of allocation (tagged).
|
|
|
|
ecx, // Out: End of allocation.
|
|
|
|
edx, // Scratch register
|
|
|
|
&slowcase,
|
|
|
|
TAG_OBJECT);
|
|
|
|
// eax: Start of allocated area, object-tagged.
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
__ mov(edx, ContextOperand(esi, Context::GLOBAL_INDEX));
|
2011-03-25 13:21:30 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
__ mov(ecx, Immediate(factory->empty_fixed_array()));
|
2010-12-07 11:31:57 +00:00
|
|
|
__ lea(ebx, Operand(eax, JSRegExpResult::kSize));
|
|
|
|
__ mov(edx, FieldOperand(edx, GlobalObject::kGlobalContextOffset));
|
|
|
|
__ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx);
|
|
|
|
__ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx);
|
|
|
|
__ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX));
|
|
|
|
__ mov(FieldOperand(eax, HeapObject::kMapOffset), edx);
|
|
|
|
|
|
|
|
// Set input, index and length fields from arguments.
|
|
|
|
__ mov(ecx, Operand(esp, kPointerSize * 1));
|
|
|
|
__ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx);
|
|
|
|
__ mov(ecx, Operand(esp, kPointerSize * 2));
|
|
|
|
__ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx);
|
|
|
|
__ mov(ecx, Operand(esp, kPointerSize * 3));
|
|
|
|
__ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx);
|
|
|
|
|
|
|
|
// Fill out the elements FixedArray.
|
|
|
|
// eax: JSArray.
|
|
|
|
// ebx: FixedArray.
|
|
|
|
// ecx: Number of elements in array, as smi.
|
|
|
|
|
|
|
|
// Set map.
|
|
|
|
__ mov(FieldOperand(ebx, HeapObject::kMapOffset),
|
2011-03-25 13:21:30 +00:00
|
|
|
Immediate(factory->fixed_array_map()));
|
2010-12-07 11:31:57 +00:00
|
|
|
// Set length.
|
|
|
|
__ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx);
|
|
|
|
// Fill contents of fixed-array with the-hole.
|
|
|
|
__ SmiUntag(ecx);
|
2011-03-25 13:21:30 +00:00
|
|
|
__ mov(edx, Immediate(factory->the_hole_value()));
|
2010-12-07 11:31:57 +00:00
|
|
|
__ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize));
|
|
|
|
// Fill fixed array elements with hole.
|
|
|
|
// eax: JSArray.
|
|
|
|
// ecx: Number of elements to fill.
|
|
|
|
// ebx: Start of elements in FixedArray.
|
|
|
|
// edx: the hole.
|
|
|
|
Label loop;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(ecx, ecx);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ bind(&loop);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(less_equal, &done, Label::kNear); // Jump if ecx is negative or zero.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(ecx, Immediate(1));
|
2010-12-07 11:31:57 +00:00
|
|
|
__ mov(Operand(ebx, ecx, times_pointer_size, 0), edx);
|
|
|
|
__ jmp(&loop);
|
|
|
|
|
|
|
|
__ bind(&done);
|
|
|
|
__ ret(3 * kPointerSize);
|
|
|
|
|
|
|
|
__ bind(&slowcase);
|
|
|
|
__ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm,
|
|
|
|
Register object,
|
|
|
|
Register result,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
bool object_is_smi,
|
|
|
|
Label* not_found) {
|
|
|
|
// Use of registers. Register result is used as a temporary.
|
|
|
|
Register number_string_cache = result;
|
|
|
|
Register mask = scratch1;
|
|
|
|
Register scratch = scratch2;
|
|
|
|
|
|
|
|
// Load the number string cache.
|
2011-10-20 12:27:10 +00:00
|
|
|
ExternalReference roots_array_start =
|
|
|
|
ExternalReference::roots_array_start(masm->isolate());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex));
|
|
|
|
__ mov(number_string_cache,
|
2011-10-20 12:27:10 +00:00
|
|
|
Operand::StaticArray(scratch, times_pointer_size, roots_array_start));
|
2010-08-25 09:44:44 +00:00
|
|
|
// Make the hash mask from the length of the number string cache. It
|
|
|
|
// contains two elements (number and string) for each cache entry.
|
|
|
|
__ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset));
|
|
|
|
__ shr(mask, kSmiTagSize + 1); // Untag length and divide it by two.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(mask, Immediate(1)); // Make mask.
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// 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-05-10 09:03:42 +00:00
|
|
|
Label smi_hash_calculated;
|
|
|
|
Label load_result_from_cache;
|
2010-08-25 09:44:44 +00:00
|
|
|
if (object_is_smi) {
|
|
|
|
__ mov(scratch, object);
|
|
|
|
__ SmiUntag(scratch);
|
|
|
|
} else {
|
2011-05-10 09:03:42 +00:00
|
|
|
Label not_smi;
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(object, ¬_smi, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(scratch, object);
|
|
|
|
__ SmiUntag(scratch);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ jmp(&smi_hash_calculated, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(¬_smi);
|
|
|
|
__ cmp(FieldOperand(object, HeapObject::kMapOffset),
|
2011-03-25 13:21:30 +00:00
|
|
|
masm->isolate()->factory()->heap_number_map());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, not_found);
|
|
|
|
STATIC_ASSERT(8 == kDoubleSize);
|
|
|
|
__ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset));
|
|
|
|
__ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4));
|
|
|
|
// Object is heap number and hash is now in scratch. Calculate cache index.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ and_(scratch, mask);
|
2010-08-25 09:44:44 +00:00
|
|
|
Register index = scratch;
|
|
|
|
Register probe = mask;
|
|
|
|
__ mov(probe,
|
|
|
|
FieldOperand(number_string_cache,
|
|
|
|
index,
|
|
|
|
times_twice_pointer_size,
|
|
|
|
FixedArray::kHeaderSize));
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(probe, not_found);
|
2011-03-31 16:17:37 +00:00
|
|
|
if (CpuFeatures::IsSupported(SSE2)) {
|
2010-08-25 09:44:44 +00:00
|
|
|
CpuFeatures::Scope fscope(SSE2);
|
|
|
|
__ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset));
|
|
|
|
__ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset));
|
|
|
|
__ ucomisd(xmm0, xmm1);
|
|
|
|
} else {
|
|
|
|
__ fld_d(FieldOperand(object, HeapNumber::kValueOffset));
|
|
|
|
__ fld_d(FieldOperand(probe, HeapNumber::kValueOffset));
|
|
|
|
__ FCmp();
|
|
|
|
}
|
|
|
|
__ j(parity_even, not_found); // Bail out if NaN is involved.
|
|
|
|
__ j(not_equal, not_found); // The cache did not contain this value.
|
2011-05-10 09:03:42 +00:00
|
|
|
__ jmp(&load_result_from_cache, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&smi_hash_calculated);
|
|
|
|
// Object is smi and hash is now in scratch. Calculate cache index.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ and_(scratch, mask);
|
2010-08-25 09:44:44 +00:00
|
|
|
Register index = scratch;
|
|
|
|
// Check if the entry is the smi we are looking for.
|
|
|
|
__ cmp(object,
|
|
|
|
FieldOperand(number_string_cache,
|
|
|
|
index,
|
|
|
|
times_twice_pointer_size,
|
|
|
|
FixedArray::kHeaderSize));
|
|
|
|
__ j(not_equal, not_found);
|
|
|
|
|
|
|
|
// Get the result from the cache.
|
|
|
|
__ bind(&load_result_from_cache);
|
|
|
|
__ mov(result,
|
|
|
|
FieldOperand(number_string_cache,
|
|
|
|
index,
|
|
|
|
times_twice_pointer_size,
|
|
|
|
FixedArray::kHeaderSize + kPointerSize));
|
2011-03-23 11:13:07 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
__ IncrementCounter(counters->number_to_string_native(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NumberToStringStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label runtime;
|
|
|
|
|
|
|
|
__ mov(ebx, Operand(esp, kPointerSize));
|
|
|
|
|
|
|
|
// Generate code to lookup number in the number string cache.
|
|
|
|
GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, false, &runtime);
|
|
|
|
__ ret(1 * kPointerSize);
|
|
|
|
|
|
|
|
__ bind(&runtime);
|
|
|
|
// Handle number to string in the runtime system if not found in the cache.
|
|
|
|
__ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int NegativeComparisonResult(Condition cc) {
|
|
|
|
ASSERT(cc != equal);
|
|
|
|
ASSERT((cc == less) || (cc == less_equal)
|
|
|
|
|| (cc == greater) || (cc == greater_equal));
|
|
|
|
return (cc == greater || cc == greater_equal) ? LESS : GREATER;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompareStub::Generate(MacroAssembler* masm) {
|
|
|
|
ASSERT(lhs_.is(no_reg) && rhs_.is(no_reg));
|
|
|
|
|
2011-08-26 08:22:13 +00:00
|
|
|
Label check_unequal_objects;
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2010-09-15 10:14:25 +00:00
|
|
|
// Compare two smis if required.
|
|
|
|
if (include_smi_compare_) {
|
|
|
|
Label non_smi, smi_done;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(ecx, edx);
|
|
|
|
__ or_(ecx, eax);
|
2011-08-26 08:22:13 +00:00
|
|
|
__ JumpIfNotSmi(ecx, &non_smi, Label::kNear);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(edx, eax); // Return on the result of the subtraction.
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(no_overflow, &smi_done, Label::kNear);
|
2010-10-18 14:04:28 +00:00
|
|
|
__ not_(edx); // Correct sign in case of overflow. edx is never 0 here.
|
2010-09-15 10:14:25 +00:00
|
|
|
__ bind(&smi_done);
|
|
|
|
__ mov(eax, edx);
|
|
|
|
__ ret(0);
|
|
|
|
__ bind(&non_smi);
|
|
|
|
} else if (FLAG_debug_code) {
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(ecx, edx);
|
|
|
|
__ or_(ecx, eax);
|
2010-09-15 10:14:25 +00:00
|
|
|
__ test(ecx, Immediate(kSmiTagMask));
|
|
|
|
__ Assert(not_zero, "Unexpected smi operands.");
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
// Identical objects can be compared fast, but there are some tricky cases
|
|
|
|
// for NaN and undefined.
|
|
|
|
{
|
|
|
|
Label not_identical;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(eax, edx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, ¬_identical);
|
|
|
|
|
|
|
|
if (cc_ != equal) {
|
|
|
|
// Check for undefined. undefined OP undefined is false even though
|
|
|
|
// undefined == undefined.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label check_for_nan;
|
2011-03-25 13:21:30 +00:00
|
|
|
__ cmp(edx, masm->isolate()->factory()->undefined_value());
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, &check_for_nan, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc_))));
|
|
|
|
__ ret(0);
|
|
|
|
__ bind(&check_for_nan);
|
|
|
|
}
|
|
|
|
|
2011-03-25 13:21:30 +00:00
|
|
|
// Test for NaN. Sadly, we can't just compare to factory->nan_value(),
|
2010-08-25 09:44:44 +00:00
|
|
|
// so we do the second best thing - test it ourselves.
|
|
|
|
// Note: if cc_ != equal, never_nan_nan_ is not used.
|
|
|
|
if (never_nan_nan_ && (cc_ == equal)) {
|
|
|
|
__ Set(eax, Immediate(Smi::FromInt(EQUAL)));
|
|
|
|
__ ret(0);
|
|
|
|
} else {
|
2011-05-10 09:03:42 +00:00
|
|
|
Label heap_number;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmp(FieldOperand(edx, HeapObject::kMapOffset),
|
2011-03-25 13:21:30 +00:00
|
|
|
Immediate(masm->isolate()->factory()->heap_number_map()));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(equal, &heap_number, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
if (cc_ != equal) {
|
|
|
|
// Call runtime on identical JSObjects. Otherwise return 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
|
|
|
__ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(above_equal, ¬_identical);
|
|
|
|
}
|
|
|
|
__ Set(eax, Immediate(Smi::FromInt(EQUAL)));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ 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.
|
|
|
|
// We only accept QNaNs, which have bit 51 set.
|
|
|
|
// Read top bits of double representation (second word of value).
|
|
|
|
|
|
|
|
// Value is a QNaN if value & kQuietNaNMask == kQuietNaNMask, i.e.,
|
|
|
|
// all bits in the mask are set. We only need to check the word
|
|
|
|
// that contains the exponent and high bit of the mantissa.
|
|
|
|
STATIC_ASSERT(((kQuietNaNHighBitsMask << 1) & 0x80000000u) != 0);
|
|
|
|
__ mov(edx, FieldOperand(edx, HeapNumber::kExponentOffset));
|
2011-01-03 11:39:22 +00:00
|
|
|
__ Set(eax, Immediate(0));
|
2010-08-25 09:44:44 +00:00
|
|
|
// Shift value and mask so kQuietNaNHighBitsMask applies to topmost
|
|
|
|
// bits.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(edx, edx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmp(edx, kQuietNaNHighBitsMask << 1);
|
|
|
|
if (cc_ == equal) {
|
|
|
|
STATIC_ASSERT(EQUAL != 1);
|
|
|
|
__ setcc(above_equal, eax);
|
|
|
|
__ ret(0);
|
|
|
|
} else {
|
2011-05-10 09:03:42 +00:00
|
|
|
Label nan;
|
|
|
|
__ j(above_equal, &nan, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Set(eax, Immediate(Smi::FromInt(EQUAL)));
|
|
|
|
__ ret(0);
|
|
|
|
__ bind(&nan);
|
|
|
|
__ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc_))));
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(¬_identical);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Strict equality can quickly decide whether objects are equal.
|
|
|
|
// Non-strict object equality is slower, so it is handled later in the stub.
|
|
|
|
if (cc_ == equal && strict_) {
|
|
|
|
Label slow; // Fallthrough label.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label not_smis;
|
2010-08-25 09:44:44 +00:00
|
|
|
// If we're doing a strict equality comparison, we don't have to do
|
|
|
|
// type conversion, so we generate code to do fast comparison for objects
|
|
|
|
// and oddballs. Non-smi numbers and strings still go through the usual
|
|
|
|
// slow-case code.
|
|
|
|
// If either is a Smi (we know that not both are), then they can only
|
|
|
|
// be equal if the other is a HeapNumber. If so, use the slow case.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
ASSERT_EQ(0, Smi::FromInt(0));
|
|
|
|
__ mov(ecx, Immediate(kSmiTagMask));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ and_(ecx, eax);
|
|
|
|
__ test(ecx, edx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_zero, ¬_smis, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// One operand is a smi.
|
|
|
|
|
|
|
|
// Check whether the non-smi is a heap number.
|
|
|
|
STATIC_ASSERT(kSmiTagMask == 1);
|
|
|
|
// ecx still holds eax & kSmiTag, which is either zero or one.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(ecx, Immediate(0x01));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(ebx, edx);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ xor_(ebx, eax);
|
|
|
|
__ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx.
|
|
|
|
__ xor_(ebx, eax);
|
2010-08-25 09:44:44 +00:00
|
|
|
// if eax was smi, ebx is now edx, else eax.
|
|
|
|
|
|
|
|
// Check if the non-smi operand is a heap number.
|
|
|
|
__ cmp(FieldOperand(ebx, HeapObject::kMapOffset),
|
2011-03-25 13:21:30 +00:00
|
|
|
Immediate(masm->isolate()->factory()->heap_number_map()));
|
2010-08-25 09:44:44 +00:00
|
|
|
// If heap number, handle it in the slow case.
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(equal, &slow, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Return non-equal (ebx is not zero)
|
|
|
|
__ mov(eax, ebx);
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(¬_smis);
|
|
|
|
// If either operand is a JSObject or an oddball value, then they are not
|
|
|
|
// equal since their pointers are different
|
|
|
|
// There is no test for undetectability in strict equality.
|
|
|
|
|
|
|
|
// Get the type of the first operand.
|
|
|
|
// If the first object is a JS object, we have done pointer comparison.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label first_non_object;
|
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
|
|
|
STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
|
|
|
|
__ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(below, &first_non_object, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Return non-zero (eax is not zero)
|
2011-05-10 09:03:42 +00:00
|
|
|
Label return_not_equal;
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT(kHeapObjectTag != 0);
|
|
|
|
__ bind(&return_not_equal);
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&first_non_object);
|
|
|
|
// Check for oddballs: true, false, null, undefined.
|
|
|
|
__ CmpInstanceType(ecx, ODDBALL_TYPE);
|
|
|
|
__ j(equal, &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
|
|
|
__ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(above_equal, &return_not_equal);
|
|
|
|
|
|
|
|
// Check for oddballs: true, false, null, undefined.
|
|
|
|
__ CmpInstanceType(ecx, ODDBALL_TYPE);
|
|
|
|
__ j(equal, &return_not_equal);
|
|
|
|
|
|
|
|
// Fall through to the general case.
|
|
|
|
__ bind(&slow);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the number comparison code.
|
|
|
|
if (include_number_compare_) {
|
|
|
|
Label non_number_comparison;
|
|
|
|
Label unordered;
|
2011-03-31 16:17:37 +00:00
|
|
|
if (CpuFeatures::IsSupported(SSE2)) {
|
2010-08-25 09:44:44 +00:00
|
|
|
CpuFeatures::Scope use_sse2(SSE2);
|
|
|
|
CpuFeatures::Scope use_cmov(CMOV);
|
|
|
|
|
|
|
|
FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison);
|
|
|
|
__ ucomisd(xmm0, xmm1);
|
|
|
|
|
|
|
|
// Don't base result on EFLAGS when a NaN is involved.
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(parity_even, &unordered, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Return a result of -1, 0, or 1, based on EFLAGS.
|
|
|
|
__ mov(eax, 0); // equal
|
|
|
|
__ mov(ecx, Immediate(Smi::FromInt(1)));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmov(above, eax, ecx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(ecx, Immediate(Smi::FromInt(-1)));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmov(below, eax, ecx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(0);
|
|
|
|
} else {
|
|
|
|
FloatingPointHelper::CheckFloatOperands(
|
|
|
|
masm, &non_number_comparison, ebx);
|
|
|
|
FloatingPointHelper::LoadFloatOperand(masm, eax);
|
|
|
|
FloatingPointHelper::LoadFloatOperand(masm, edx);
|
|
|
|
__ FCmp();
|
|
|
|
|
|
|
|
// Don't base result on EFLAGS when a NaN is involved.
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(parity_even, &unordered, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-05-10 09:03:42 +00:00
|
|
|
Label below_label, above_label;
|
2010-08-25 09:44:44 +00:00
|
|
|
// Return a result of -1, 0, or 1, based on EFLAGS.
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(below, &below_label, Label::kNear);
|
|
|
|
__ j(above, &above_label, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-01-03 11:39:22 +00:00
|
|
|
__ Set(eax, Immediate(0));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&below_label);
|
|
|
|
__ mov(eax, Immediate(Smi::FromInt(-1)));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&above_label);
|
|
|
|
__ mov(eax, Immediate(Smi::FromInt(1)));
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If one of the numbers was NaN, then the result is always false.
|
|
|
|
// The cc is never not-equal.
|
|
|
|
__ bind(&unordered);
|
|
|
|
ASSERT(cc_ != not_equal);
|
|
|
|
if (cc_ == less || cc_ == less_equal) {
|
|
|
|
__ mov(eax, Immediate(Smi::FromInt(1)));
|
|
|
|
} else {
|
|
|
|
__ mov(eax, Immediate(Smi::FromInt(-1)));
|
|
|
|
}
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// The number comparison code did not provide a valid result.
|
|
|
|
__ bind(&non_number_comparison);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fast negative check for symbol-to-symbol equality.
|
|
|
|
Label check_for_strings;
|
|
|
|
if (cc_ == equal) {
|
|
|
|
BranchIfNonSymbol(masm, &check_for_strings, eax, ecx);
|
|
|
|
BranchIfNonSymbol(masm, &check_for_strings, edx, ecx);
|
|
|
|
|
|
|
|
// We've already checked for object identity, so if both operands
|
|
|
|
// are symbols they aren't equal. Register eax already holds a
|
|
|
|
// non-zero value, which indicates not equal, so just return.
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&check_for_strings);
|
|
|
|
|
|
|
|
__ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx,
|
|
|
|
&check_unequal_objects);
|
|
|
|
|
|
|
|
// Inline comparison of ascii strings.
|
2011-05-05 11:40:08 +00:00
|
|
|
if (cc_ == equal) {
|
|
|
|
StringCompareStub::GenerateFlatAsciiStringEquals(masm,
|
2010-08-25 09:44:44 +00:00
|
|
|
edx,
|
|
|
|
eax,
|
|
|
|
ecx,
|
2011-05-05 11:40:08 +00:00
|
|
|
ebx);
|
|
|
|
} else {
|
|
|
|
StringCompareStub::GenerateCompareFlatAsciiStrings(masm,
|
|
|
|
edx,
|
|
|
|
eax,
|
|
|
|
ecx,
|
|
|
|
ebx,
|
|
|
|
edi);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
__ Abort("Unexpected fall-through from string comparison");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
__ bind(&check_unequal_objects);
|
|
|
|
if (cc_ == equal && !strict_) {
|
|
|
|
// Non-strict equality. Objects are unequal if
|
|
|
|
// they are both JSObjects and not undetectable,
|
|
|
|
// and their pointers are different.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label not_both_objects;
|
|
|
|
Label return_unequal;
|
2010-08-25 09:44:44 +00:00
|
|
|
// At most one is a smi, so we can test for smi by adding the two.
|
|
|
|
// A smi plus a heap object has the low bit set, a heap object plus
|
|
|
|
// a heap object has the low bit clear.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagMask == 1);
|
|
|
|
__ lea(ecx, Operand(eax, edx, times_1, 0));
|
|
|
|
__ test(ecx, Immediate(kSmiTagMask));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_zero, ¬_both_objects, Label::kNear);
|
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
|
|
|
__ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(below, ¬_both_objects, Label::kNear);
|
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
|
|
|
__ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(below, ¬_both_objects, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// We do not bail out after this point. Both are JSObjects, and
|
|
|
|
// they are equal if and only if both are undetectable.
|
|
|
|
// The and of the undetectable flags is 1 if and only if they are equal.
|
|
|
|
__ test_b(FieldOperand(ecx, Map::kBitFieldOffset),
|
|
|
|
1 << Map::kIsUndetectable);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &return_unequal, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ test_b(FieldOperand(ebx, Map::kBitFieldOffset),
|
|
|
|
1 << Map::kIsUndetectable);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &return_unequal, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// The objects are both undetectable, so they both compare as the value
|
|
|
|
// undefined, and are equal.
|
|
|
|
__ Set(eax, Immediate(EQUAL));
|
|
|
|
__ bind(&return_unequal);
|
|
|
|
// Return non-equal by returning the non-zero object pointer in eax,
|
|
|
|
// or return equal if we fell through to here.
|
|
|
|
__ ret(0); // rax, rdx were pushed
|
|
|
|
__ bind(¬_both_objects);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push arguments below the return address.
|
|
|
|
__ pop(ecx);
|
|
|
|
__ push(edx);
|
|
|
|
__ push(eax);
|
|
|
|
|
|
|
|
// Figure out which native to call and setup the arguments.
|
|
|
|
Builtins::JavaScript builtin;
|
|
|
|
if (cc_ == equal) {
|
|
|
|
builtin = strict_ ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
|
|
|
|
} else {
|
|
|
|
builtin = Builtins::COMPARE;
|
|
|
|
__ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc_))));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore return address on the stack.
|
|
|
|
__ push(ecx);
|
|
|
|
|
|
|
|
// Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
|
|
|
|
// tagged as a small integer.
|
|
|
|
__ InvokeBuiltin(builtin, JUMP_FUNCTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CompareStub::BranchIfNonSymbol(MacroAssembler* masm,
|
|
|
|
Label* label,
|
|
|
|
Register object,
|
|
|
|
Register scratch) {
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(object, label);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(scratch, FieldOperand(object, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset));
|
|
|
|
__ and_(scratch, kIsSymbolMask | kIsNotStringMask);
|
|
|
|
__ cmp(scratch, kSymbolTag | kStringTag);
|
|
|
|
__ j(not_equal, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-11 13:48:14 +00:00
|
|
|
void CallFunctionStub::FinishCode(Handle<Code> code) {
|
2011-09-27 11:42:02 +00:00
|
|
|
code->set_has_function_cache(RecordCallTarget());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CallFunctionStub::Clear(Heap* heap, Address address) {
|
|
|
|
ASSERT(Memory::uint8_at(address + kPointerSize) == Assembler::kTestEaxByte);
|
|
|
|
// 1 ~ size of the test eax opcode.
|
|
|
|
Object* cell = Memory::Object_at(address + kPointerSize + 1);
|
|
|
|
// Low-level because clearing happens during GC.
|
|
|
|
reinterpret_cast<JSGlobalPropertyCell*>(cell)->set_value(
|
|
|
|
RawUninitializedSentinel(heap));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Object* CallFunctionStub::GetCachedValue(Address address) {
|
|
|
|
ASSERT(Memory::uint8_at(address + kPointerSize) == Assembler::kTestEaxByte);
|
|
|
|
// 1 ~ size of the test eax opcode.
|
|
|
|
Object* cell = Memory::Object_at(address + kPointerSize + 1);
|
|
|
|
return JSGlobalPropertyCell::cast(cell)->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void CallFunctionStub::Generate(MacroAssembler* masm) {
|
2011-11-08 14:39:37 +00:00
|
|
|
// edi : the function to call
|
2011-09-27 11:42:02 +00:00
|
|
|
Isolate* isolate = masm->isolate();
|
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()) {
|
2011-09-27 11:42:02 +00:00
|
|
|
Label receiver_ok;
|
2010-08-25 09:44:44 +00:00
|
|
|
// Get the receiver from the stack.
|
|
|
|
// +1 ~ return address
|
|
|
|
__ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize));
|
2011-05-24 14:01:36 +00:00
|
|
|
// Call as function is indicated with the hole.
|
2011-09-27 11:42:02 +00:00
|
|
|
__ cmp(eax, isolate->factory()->the_hole_value());
|
|
|
|
__ j(not_equal, &receiver_ok, Label::kNear);
|
2011-05-24 14:01:36 +00:00
|
|
|
// Patch the receiver on the stack with the global receiver object.
|
|
|
|
__ mov(ebx, GlobalObjectOperand());
|
|
|
|
__ mov(ebx, FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset));
|
|
|
|
__ mov(Operand(esp, (argc_ + 1) * kPointerSize), ebx);
|
2011-09-27 11:42:02 +00:00
|
|
|
__ bind(&receiver_ok);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the function really is a JavaScript function.
|
2011-09-13 11:42:57 +00:00
|
|
|
__ JumpIfSmi(edi, &non_function);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Goto slow case if we do not have a function.
|
|
|
|
__ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(not_equal, &slow);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-09-27 11:42:02 +00:00
|
|
|
if (RecordCallTarget()) {
|
|
|
|
// Cache the called function in a global property cell in the
|
|
|
|
// instruction stream after the call. Cache states are uninitialized,
|
|
|
|
// monomorphic (indicated by a JSFunction), and megamorphic.
|
|
|
|
Label initialize, call;
|
|
|
|
// Load the cache cell address into ebx and the cache state into ecx.
|
|
|
|
__ mov(ebx, Operand(esp, 0)); // Return address.
|
|
|
|
__ mov(ebx, Operand(ebx, 1)); // 1 ~ sizeof 'test eax' opcode in bytes.
|
|
|
|
__ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset));
|
|
|
|
|
|
|
|
// A monomorphic cache hit or an already megamorphic state: invoke the
|
|
|
|
// function without changing the state.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ecx, edi);
|
2011-09-27 11:42:02 +00:00
|
|
|
__ j(equal, &call, Label::kNear);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ecx, Immediate(MegamorphicSentinel(isolate)));
|
2011-09-27 11:42:02 +00:00
|
|
|
__ j(equal, &call, Label::kNear);
|
|
|
|
|
|
|
|
// A monomorphic miss (i.e, here the cache is not uninitialized) goes
|
|
|
|
// megamorphic.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ecx, Immediate(UninitializedSentinel(isolate)));
|
2011-09-27 11:42:02 +00:00
|
|
|
__ j(equal, &initialize, Label::kNear);
|
2011-09-27 13:45:13 +00:00
|
|
|
// MegamorphicSentinel is a root so no write-barrier is needed.
|
2011-09-27 11:42:02 +00:00
|
|
|
__ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset),
|
|
|
|
Immediate(MegamorphicSentinel(isolate)));
|
|
|
|
__ jmp(&call, Label::kNear);
|
|
|
|
|
|
|
|
// An uninitialized cache is patched with the function.
|
|
|
|
__ bind(&initialize);
|
|
|
|
__ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi);
|
2011-09-27 13:45:13 +00:00
|
|
|
__ mov(ecx, edi);
|
|
|
|
__ RecordWriteField(ebx,
|
|
|
|
JSGlobalPropertyCell::kValueOffset,
|
|
|
|
ecx,
|
|
|
|
edx,
|
|
|
|
kDontSaveFPRegs,
|
|
|
|
OMIT_REMEMBERED_SET, // Cells are rescanned.
|
|
|
|
OMIT_SMI_CHECK);
|
2011-09-27 11:42:02 +00:00
|
|
|
|
|
|
|
__ bind(&call);
|
|
|
|
}
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Fast-case: Just invoke the function.
|
|
|
|
ParameterCount actual(argc_);
|
2011-05-24 14:01:36 +00:00
|
|
|
|
|
|
|
if (ReceiverMightBeImplicit()) {
|
|
|
|
Label call_as_function;
|
2011-09-27 11:42:02 +00:00
|
|
|
__ cmp(eax, isolate->factory()->the_hole_value());
|
2011-05-24 14:01:36 +00:00
|
|
|
__ j(equal, &call_as_function);
|
2011-05-30 13:23:17 +00:00
|
|
|
__ InvokeFunction(edi,
|
|
|
|
actual,
|
|
|
|
JUMP_FUNCTION,
|
|
|
|
NullCallWrapper(),
|
|
|
|
CALL_AS_METHOD);
|
2011-05-24 14:01:36 +00:00
|
|
|
__ bind(&call_as_function);
|
|
|
|
}
|
|
|
|
__ InvokeFunction(edi,
|
|
|
|
actual,
|
|
|
|
JUMP_FUNCTION,
|
|
|
|
NullCallWrapper(),
|
|
|
|
CALL_AS_FUNCTION);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Slow-case: Non-function called.
|
|
|
|
__ bind(&slow);
|
2011-09-27 11:42:02 +00:00
|
|
|
if (RecordCallTarget()) {
|
|
|
|
// If there is a call target cache, mark it megamorphic in the
|
|
|
|
// non-function case.
|
|
|
|
__ mov(ebx, Operand(esp, 0));
|
|
|
|
__ mov(ebx, Operand(ebx, 1));
|
|
|
|
__ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset),
|
|
|
|
Immediate(MegamorphicSentinel(isolate)));
|
|
|
|
}
|
2011-09-13 11:42:57 +00:00
|
|
|
// Check for function proxy.
|
|
|
|
__ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE);
|
|
|
|
__ j(not_equal, &non_function);
|
|
|
|
__ pop(ecx);
|
|
|
|
__ push(edi); // put proxy as additional argument under return address
|
|
|
|
__ push(ecx);
|
|
|
|
__ Set(eax, Immediate(argc_ + 1));
|
|
|
|
__ Set(ebx, Immediate(0));
|
|
|
|
__ SetCallKind(ecx, CALL_AS_FUNCTION);
|
|
|
|
__ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY);
|
|
|
|
{
|
2011-09-27 11:42:02 +00:00
|
|
|
Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline();
|
2011-09-13 11:42:57 +00:00
|
|
|
__ jmp(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
|
|
|
__ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi);
|
|
|
|
__ Set(eax, Immediate(argc_));
|
|
|
|
__ Set(ebx, Immediate(0));
|
2011-09-13 11:42:57 +00:00
|
|
|
__ SetCallKind(ecx, CALL_AS_METHOD);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION);
|
2011-09-27 11:42:02 +00:00
|
|
|
Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline();
|
2010-08-25 09:44:44 +00:00
|
|
|
__ jmp(adaptor, RelocInfo::CODE_TARGET);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-09 10:38:19 +00:00
|
|
|
bool CEntryStub::NeedsImmovableCode() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeStub::GenerateStubsAheadOfTime() {
|
2011-09-28 12:23:40 +00:00
|
|
|
CEntryStub::GenerateAheadOfTime();
|
2011-09-27 10:53:22 +00:00
|
|
|
StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime();
|
|
|
|
// It is important that the store buffer overflow stubs are generated first.
|
|
|
|
RecordWriteStub::GenerateFixedRegStubsAheadOfTime();
|
2011-09-16 11:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-16 13:06:51 +00:00
|
|
|
void CodeStub::GenerateFPStubs() {
|
2011-09-19 18:36:47 +00:00
|
|
|
CEntryStub save_doubles(1, kSaveFPRegs);
|
2011-09-16 13:06:51 +00:00
|
|
|
Handle<Code> code = save_doubles.GetCode();
|
2011-09-28 10:32:12 +00:00
|
|
|
code->set_is_pregenerated(true);
|
2011-09-16 13:06:51 +00:00
|
|
|
code->GetIsolate()->set_fp_stubs_generated(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-28 12:23:40 +00:00
|
|
|
void CEntryStub::GenerateAheadOfTime() {
|
|
|
|
CEntryStub stub(1, kDontSaveFPRegs);
|
|
|
|
Handle<Code> code = stub.GetCode();
|
|
|
|
code->set_is_pregenerated(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void CEntryStub::GenerateThrowTOS(MacroAssembler* masm) {
|
2011-02-15 13:53:51 +00:00
|
|
|
__ Throw(eax);
|
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_scope) {
|
2010-08-25 09:44:44 +00:00
|
|
|
// eax: result parameter for PerformGC, if any
|
|
|
|
// ebx: pointer to C function (C callee-saved)
|
|
|
|
// ebp: frame pointer (restored after C call)
|
|
|
|
// esp: stack pointer (restored after C call)
|
|
|
|
// edi: number of arguments including receiver (C callee-saved)
|
|
|
|
// esi: pointer to the first argument (C callee-saved)
|
|
|
|
|
|
|
|
// Result returned in eax, or eax+edx if result_size_ is 2.
|
|
|
|
|
|
|
|
// Check stack alignment.
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ CheckStackAlignment();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_gc) {
|
|
|
|
// Pass failure code returned from last attempt as first argument to
|
|
|
|
// PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the
|
|
|
|
// stack alignment is known to be correct. This function takes one argument
|
|
|
|
// which is passed on the stack, and we know that the stack has been
|
|
|
|
// prepared to pass at least one argument.
|
|
|
|
__ mov(Operand(esp, 0 * kPointerSize), eax); // Result.
|
|
|
|
__ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY);
|
|
|
|
}
|
|
|
|
|
|
|
|
ExternalReference scope_depth =
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference::heap_always_allocate_scope_depth(masm->isolate());
|
2010-08-25 09:44:44 +00:00
|
|
|
if (always_allocate_scope) {
|
|
|
|
__ inc(Operand::StaticVariable(scope_depth));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call C function.
|
|
|
|
__ mov(Operand(esp, 0 * kPointerSize), edi); // argc.
|
|
|
|
__ mov(Operand(esp, 1 * kPointerSize), esi); // argv.
|
2011-03-18 20:35:07 +00:00
|
|
|
__ mov(Operand(esp, 2 * kPointerSize),
|
|
|
|
Immediate(ExternalReference::isolate_address()));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ call(ebx);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Result is in eax or edx:eax - do not destroy these registers!
|
|
|
|
|
|
|
|
if (always_allocate_scope) {
|
|
|
|
__ dec(Operand::StaticVariable(scope_depth));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we're not trying to return 'the hole' from the runtime
|
|
|
|
// call as this may lead to crashes in the IC code later.
|
|
|
|
if (FLAG_debug_code) {
|
2011-05-10 09:03:42 +00:00
|
|
|
Label okay;
|
2011-03-25 13:21:30 +00:00
|
|
|
__ cmp(eax, masm->isolate()->factory()->the_hole_value());
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, &okay, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ int3();
|
|
|
|
__ bind(&okay);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for failure result.
|
|
|
|
Label failure_returned;
|
|
|
|
STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0);
|
|
|
|
__ lea(ecx, Operand(eax, 1));
|
|
|
|
// Lower 2 bits of ecx are 0 iff eax has failure tag.
|
|
|
|
__ test(ecx, Immediate(kFailureTagMask));
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(zero, &failure_returned);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
ExternalReference pending_exception_address(
|
2011-09-08 16:29:57 +00:00
|
|
|
Isolate::kPendingExceptionAddress, masm->isolate());
|
2011-02-08 20:13:08 +00:00
|
|
|
|
|
|
|
// Check that there is no pending exception, otherwise we
|
|
|
|
// should have returned some failure value.
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ push(edx);
|
2011-10-04 09:07:50 +00:00
|
|
|
__ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value()));
|
2011-05-10 09:03:42 +00:00
|
|
|
Label okay;
|
2011-02-08 20:13:08 +00:00
|
|
|
__ cmp(edx, Operand::StaticVariable(pending_exception_address));
|
|
|
|
// Cannot use check here as it attempts to generate call into runtime.
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(equal, &okay, Label::kNear);
|
2011-02-08 20:13:08 +00:00
|
|
|
__ int3();
|
|
|
|
__ bind(&okay);
|
|
|
|
__ pop(edx);
|
|
|
|
}
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Exit the JavaScript to C++ exit frame.
|
2011-09-19 18:36:47 +00:00
|
|
|
__ LeaveExitFrame(save_doubles_ == kSaveFPRegs);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Handling of failure.
|
|
|
|
__ bind(&failure_returned);
|
|
|
|
|
|
|
|
Label retry;
|
|
|
|
// If the returned exception is RETRY_AFTER_GC continue at retry label
|
|
|
|
STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0);
|
|
|
|
__ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize));
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(zero, &retry, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Special handling of out of memory exceptions.
|
|
|
|
__ cmp(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException()));
|
|
|
|
__ j(equal, throw_out_of_memory_exception);
|
|
|
|
|
|
|
|
// Retrieve the pending exception and clear the variable.
|
|
|
|
__ mov(eax, Operand::StaticVariable(pending_exception_address));
|
2011-10-04 09:07:50 +00:00
|
|
|
__ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value()));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(Operand::StaticVariable(pending_exception_address), edx);
|
|
|
|
|
|
|
|
// Special handling of termination exceptions which are uncatchable
|
|
|
|
// by javascript code.
|
2011-03-25 13:21:30 +00:00
|
|
|
__ cmp(eax, masm->isolate()->factory()->termination_exception());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(equal, throw_termination_exception);
|
|
|
|
|
|
|
|
// Handle normal exception.
|
|
|
|
__ jmp(throw_normal_exception);
|
|
|
|
|
|
|
|
// Retry.
|
|
|
|
__ bind(&retry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CEntryStub::GenerateThrowUncatchable(MacroAssembler* masm,
|
|
|
|
UncatchableExceptionType type) {
|
2011-02-15 13:53:51 +00:00
|
|
|
__ ThrowUncatchable(type, eax);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CEntryStub::Generate(MacroAssembler* masm) {
|
|
|
|
// eax: number of arguments including receiver
|
|
|
|
// ebx: pointer to C function (C callee-saved)
|
|
|
|
// ebp: frame pointer (restored after C call)
|
|
|
|
// esp: stack pointer (restored after C call)
|
|
|
|
// esi: current context (C callee-saved)
|
|
|
|
// edi: JS function of the caller (C callee-saved)
|
|
|
|
|
|
|
|
// 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 (twice).
|
|
|
|
|
|
|
|
// Enter the exit frame that transitions from JavaScript to C++.
|
2011-09-19 18:36:47 +00:00
|
|
|
__ EnterExitFrame(save_doubles_ == kSaveFPRegs);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// eax: result parameter for PerformGC, if any (setup below)
|
|
|
|
// ebx: pointer to builtin function (C callee-saved)
|
|
|
|
// ebp: frame pointer (restored after C call)
|
|
|
|
// esp: stack pointer (restored after C call)
|
|
|
|
// edi: number of arguments including receiver (C callee-saved)
|
|
|
|
// esi: argv pointer (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,
|
|
|
|
false);
|
|
|
|
|
|
|
|
// Do space-specific GC and retry runtime call.
|
|
|
|
GenerateCore(masm,
|
|
|
|
&throw_normal_exception,
|
|
|
|
&throw_termination_exception,
|
|
|
|
&throw_out_of_memory_exception,
|
|
|
|
true,
|
|
|
|
false);
|
|
|
|
|
|
|
|
// Do full GC and retry runtime call one final time.
|
|
|
|
Failure* failure = Failure::InternalError();
|
|
|
|
__ mov(eax, Immediate(reinterpret_cast<int32_t>(failure)));
|
|
|
|
GenerateCore(masm,
|
|
|
|
&throw_normal_exception,
|
|
|
|
&throw_termination_exception,
|
|
|
|
&throw_out_of_memory_exception,
|
|
|
|
true,
|
|
|
|
true);
|
|
|
|
|
|
|
|
__ bind(&throw_out_of_memory_exception);
|
|
|
|
GenerateThrowUncatchable(masm, OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
__ bind(&throw_termination_exception);
|
|
|
|
GenerateThrowUncatchable(masm, TERMINATION);
|
|
|
|
|
|
|
|
__ bind(&throw_normal_exception);
|
|
|
|
GenerateThrowTOS(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) {
|
2011-11-11 13:48:14 +00:00
|
|
|
Label invoke, handler_entry, exit;
|
2010-08-25 09:44:44 +00:00
|
|
|
Label not_outermost_js, not_outermost_js_2;
|
|
|
|
|
|
|
|
// Setup frame.
|
|
|
|
__ push(ebp);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(ebp, esp);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Push marker in two places.
|
|
|
|
int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY;
|
|
|
|
__ push(Immediate(Smi::FromInt(marker))); // context slot
|
|
|
|
__ push(Immediate(Smi::FromInt(marker))); // function slot
|
|
|
|
// Save callee-saved registers (C calling conventions).
|
|
|
|
__ push(edi);
|
|
|
|
__ push(esi);
|
|
|
|
__ push(ebx);
|
|
|
|
|
|
|
|
// Save copies of the top frame descriptor on the stack.
|
2011-09-08 16:29:57 +00:00
|
|
|
ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ push(Operand::StaticVariable(c_entry_fp));
|
|
|
|
|
|
|
|
// If this is the outermost JS call, set js_entry_sp value.
|
2011-09-08 16:29:57 +00:00
|
|
|
ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress,
|
2011-03-22 13:20:04 +00:00
|
|
|
masm->isolate());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0));
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(not_equal, ¬_outermost_js, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(Operand::StaticVariable(js_entry_sp), ebp);
|
2011-05-17 11:11:12 +00:00
|
|
|
__ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
|
|
|
|
Label cont;
|
2011-08-26 08:22:13 +00:00
|
|
|
__ jmp(&cont, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(¬_outermost_js);
|
2011-05-17 11:11:12 +00:00
|
|
|
__ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME)));
|
|
|
|
__ bind(&cont);
|
2010-08-25 09:44:44 +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);
|
|
|
|
__ 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.
|
2011-09-08 16:29:57 +00:00
|
|
|
ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
|
2011-03-22 13:20:04 +00:00
|
|
|
masm->isolate());
|
2011-01-27 18:21:07 +00:00
|
|
|
__ mov(Operand::StaticVariable(pending_exception), eax);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(eax, reinterpret_cast<int32_t>(Failure::Exception()));
|
|
|
|
__ jmp(&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);
|
2011-11-11 13:48:14 +00:00
|
|
|
__ PushTryHandler(IN_JS_ENTRY, JS_ENTRY_HANDLER, 0);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Clear any pending exceptions.
|
2011-10-04 09:07:50 +00:00
|
|
|
__ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value()));
|
2011-01-27 18:21:07 +00:00
|
|
|
__ mov(Operand::StaticVariable(pending_exception), edx);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Fake a receiver (NULL).
|
|
|
|
__ push(Immediate(0)); // receiver
|
|
|
|
|
2011-11-11 13:48:14 +00:00
|
|
|
// Invoke the function by calling through JS entry trampoline builtin and
|
|
|
|
// pop the faked function when we return. Notice that we cannot store a
|
|
|
|
// reference to the trampoline code directly in this stub, because the
|
|
|
|
// builtin stubs may not have been generated yet.
|
2010-08-25 09:44:44 +00:00
|
|
|
if (is_construct) {
|
2011-11-11 13:48:14 +00:00
|
|
|
ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
|
|
|
|
masm->isolate());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(edx, Immediate(construct_entry));
|
|
|
|
} else {
|
2011-03-23 13:40:07 +00:00
|
|
|
ExternalReference entry(Builtins::kJSEntryTrampoline,
|
2011-03-22 13:20:04 +00:00
|
|
|
masm->isolate());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(edx, Immediate(entry));
|
|
|
|
}
|
|
|
|
__ mov(edx, Operand(edx, 0)); // deref address
|
|
|
|
__ lea(edx, FieldOperand(edx, Code::kHeaderSize));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ call(edx);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Unlink this frame from the handler chain.
|
2011-05-17 11:11:12 +00:00
|
|
|
__ PopTryHandler();
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-05-17 11:11:12 +00:00
|
|
|
__ bind(&exit);
|
|
|
|
// Check if the current stack frame is marked as the outermost JS frame.
|
|
|
|
__ pop(ebx);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME)));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, ¬_outermost_js_2);
|
|
|
|
__ mov(Operand::StaticVariable(js_entry_sp), Immediate(0));
|
|
|
|
__ bind(¬_outermost_js_2);
|
|
|
|
|
|
|
|
// Restore the top frame descriptor from the stack.
|
2011-03-18 20:35:07 +00:00
|
|
|
__ pop(Operand::StaticVariable(ExternalReference(
|
2011-09-08 16:29:57 +00:00
|
|
|
Isolate::kCEntryFPAddress,
|
2011-03-22 13:20:04 +00:00
|
|
|
masm->isolate())));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Restore callee-saved registers (C calling conventions).
|
|
|
|
__ pop(ebx);
|
|
|
|
__ pop(esi);
|
|
|
|
__ pop(edi);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(esp, Immediate(2 * kPointerSize)); // remove markers
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Restore frame pointer and return.
|
|
|
|
__ pop(ebp);
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-05 11:17:37 +00:00
|
|
|
// Generate stub code for instanceof.
|
|
|
|
// This code can patch a call site inlined cache of the instance of check,
|
|
|
|
// which looks like this.
|
|
|
|
//
|
|
|
|
// 81 ff XX XX XX XX cmp edi, <the hole, patched to a map>
|
|
|
|
// 75 0a jne <some near label>
|
|
|
|
// b8 XX XX XX XX mov eax, <the hole, patched to either true or false>
|
|
|
|
//
|
|
|
|
// If call site patching is requested the stack will have the delta from the
|
|
|
|
// return address to the cmp instruction just below the return address. This
|
|
|
|
// also means that call site patching can only take place with arguments in
|
|
|
|
// registers. TOS looks like this when call site patching is requested
|
|
|
|
//
|
|
|
|
// esp[0] : return address
|
|
|
|
// esp[4] : delta from return address to cmp instruction
|
|
|
|
//
|
2010-08-25 09:44:44 +00:00
|
|
|
void InstanceofStub::Generate(MacroAssembler* masm) {
|
2011-01-05 11:17:37 +00:00
|
|
|
// Call site inlining and patching implies arguments in registers.
|
|
|
|
ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck());
|
|
|
|
|
2010-12-16 08:58:42 +00:00
|
|
|
// Fixed register usage throughout the stub.
|
|
|
|
Register object = eax; // Object (lhs).
|
|
|
|
Register map = ebx; // Map of the object.
|
|
|
|
Register function = edx; // Function (rhs).
|
|
|
|
Register prototype = edi; // Prototype of the function.
|
|
|
|
Register scratch = ecx;
|
|
|
|
|
2011-01-05 11:17:37 +00:00
|
|
|
// Constants describing the call site code to patch.
|
|
|
|
static const int kDeltaToCmpImmediate = 2;
|
|
|
|
static const int kDeltaToMov = 8;
|
|
|
|
static const int kDeltaToMovImmediate = 9;
|
2011-01-05 13:03:21 +00:00
|
|
|
static const int8_t kCmpEdiImmediateByte1 = BitCast<int8_t, uint8_t>(0x81);
|
|
|
|
static const int8_t kCmpEdiImmediateByte2 = BitCast<int8_t, uint8_t>(0xff);
|
|
|
|
static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8);
|
2011-01-05 11:17:37 +00:00
|
|
|
|
2011-10-20 12:27:10 +00:00
|
|
|
ExternalReference roots_array_start =
|
|
|
|
ExternalReference::roots_array_start(masm->isolate());
|
2011-01-05 11:17:37 +00:00
|
|
|
|
|
|
|
ASSERT_EQ(object.code(), InstanceofStub::left().code());
|
|
|
|
ASSERT_EQ(function.code(), InstanceofStub::right().code());
|
|
|
|
|
2010-12-16 08:58:42 +00:00
|
|
|
// Get the object and function - they are always both needed.
|
|
|
|
Label slow, not_js_object;
|
2011-01-05 11:17:37 +00:00
|
|
|
if (!HasArgsInRegisters()) {
|
2010-12-16 08:58:42 +00:00
|
|
|
__ mov(object, Operand(esp, 2 * kPointerSize));
|
|
|
|
__ mov(function, Operand(esp, 1 * kPointerSize));
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Check that the left hand is a JS object.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(object, ¬_js_object);
|
2010-12-16 08:58:42 +00:00
|
|
|
__ IsObjectJSObjectType(object, map, scratch, ¬_js_object);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-01-05 11:17:37 +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()) {
|
|
|
|
// Look up the function and the map in the instanceof cache.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label miss;
|
2011-01-05 11:17:37 +00:00
|
|
|
__ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex));
|
2011-10-20 12:27:10 +00:00
|
|
|
__ cmp(function, Operand::StaticArray(scratch,
|
|
|
|
times_pointer_size,
|
|
|
|
roots_array_start));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, &miss, Label::kNear);
|
2011-01-05 11:17:37 +00:00
|
|
|
__ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex));
|
|
|
|
__ cmp(map, Operand::StaticArray(
|
2011-10-20 12:27:10 +00:00
|
|
|
scratch, times_pointer_size, roots_array_start));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, &miss, Label::kNear);
|
2011-01-05 11:17:37 +00:00
|
|
|
__ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex));
|
|
|
|
__ mov(eax, Operand::StaticArray(
|
2011-10-20 12:27:10 +00:00
|
|
|
scratch, times_pointer_size, roots_array_start));
|
2011-01-05 11:17:37 +00:00
|
|
|
__ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize);
|
|
|
|
__ bind(&miss);
|
|
|
|
}
|
|
|
|
|
2010-12-16 08:58:42 +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-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(prototype, &slow);
|
2010-12-16 08:58:42 +00:00
|
|
|
__ IsObjectJSObjectType(prototype, scratch, scratch, &slow);
|
|
|
|
|
2011-01-05 11:17:37 +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()) {
|
2010-12-16 08:58:42 +00:00
|
|
|
__ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex));
|
2011-10-20 12:27:10 +00:00
|
|
|
__ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start),
|
|
|
|
map);
|
2010-12-16 08:58:42 +00:00
|
|
|
__ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex));
|
2011-10-20 12:27:10 +00:00
|
|
|
__ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start),
|
2010-12-16 08:58:42 +00:00
|
|
|
function);
|
2011-01-05 11:17:37 +00:00
|
|
|
} else {
|
|
|
|
// The constants for the code patching are based on no push instructions
|
|
|
|
// at the call site.
|
|
|
|
ASSERT(HasArgsInRegisters());
|
|
|
|
// Get return address and delta to inlined map check.
|
|
|
|
__ mov(scratch, Operand(esp, 0 * kPointerSize));
|
|
|
|
__ sub(scratch, Operand(esp, 1 * kPointerSize));
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ cmpb(Operand(scratch, 0), kCmpEdiImmediateByte1);
|
|
|
|
__ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)");
|
|
|
|
__ cmpb(Operand(scratch, 1), kCmpEdiImmediateByte2);
|
|
|
|
__ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)");
|
|
|
|
}
|
|
|
|
__ mov(Operand(scratch, kDeltaToCmpImmediate), map);
|
|
|
|
}
|
2010-12-16 08:58:42 +00:00
|
|
|
|
|
|
|
// Loop through the prototype chain of the object looking for the function
|
|
|
|
// prototype.
|
|
|
|
__ mov(scratch, FieldOperand(map, Map::kPrototypeOffset));
|
2011-05-10 09:03:42 +00:00
|
|
|
Label loop, is_instance, is_not_instance;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&loop);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(scratch, prototype);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(equal, &is_instance, Label::kNear);
|
2011-03-25 13:21:30 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(scratch, Immediate(factory->null_value()));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(equal, &is_not_instance, Label::kNear);
|
2010-12-16 08:58:42 +00:00
|
|
|
__ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset));
|
|
|
|
__ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ jmp(&loop);
|
|
|
|
|
|
|
|
__ bind(&is_instance);
|
2011-01-05 11:17:37 +00:00
|
|
|
if (!HasCallSiteInlineCheck()) {
|
|
|
|
__ Set(eax, Immediate(0));
|
|
|
|
__ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex));
|
|
|
|
__ mov(Operand::StaticArray(scratch,
|
2011-10-20 12:27:10 +00:00
|
|
|
times_pointer_size, roots_array_start), eax);
|
2011-01-05 11:17:37 +00:00
|
|
|
} else {
|
|
|
|
// Get return address and delta to inlined map check.
|
2011-03-25 13:21:30 +00:00
|
|
|
__ mov(eax, factory->true_value());
|
2011-01-05 11:17:37 +00:00
|
|
|
__ mov(scratch, Operand(esp, 0 * kPointerSize));
|
|
|
|
__ sub(scratch, Operand(esp, 1 * kPointerSize));
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte);
|
|
|
|
__ Assert(equal, "InstanceofStub unexpected call site cache (mov)");
|
|
|
|
}
|
|
|
|
__ mov(Operand(scratch, kDeltaToMovImmediate), eax);
|
|
|
|
if (!ReturnTrueFalseObject()) {
|
|
|
|
__ Set(eax, Immediate(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&is_not_instance);
|
2011-01-05 11:17:37 +00:00
|
|
|
if (!HasCallSiteInlineCheck()) {
|
|
|
|
__ Set(eax, Immediate(Smi::FromInt(1)));
|
|
|
|
__ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex));
|
|
|
|
__ mov(Operand::StaticArray(
|
2011-10-20 12:27:10 +00:00
|
|
|
scratch, times_pointer_size, roots_array_start), eax);
|
2011-01-05 11:17:37 +00:00
|
|
|
} else {
|
|
|
|
// Get return address and delta to inlined map check.
|
2011-03-25 13:21:30 +00:00
|
|
|
__ mov(eax, factory->false_value());
|
2011-01-05 11:17:37 +00:00
|
|
|
__ mov(scratch, Operand(esp, 0 * kPointerSize));
|
|
|
|
__ sub(scratch, Operand(esp, 1 * kPointerSize));
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte);
|
|
|
|
__ Assert(equal, "InstanceofStub unexpected call site cache (mov)");
|
|
|
|
}
|
|
|
|
__ mov(Operand(scratch, kDeltaToMovImmediate), eax);
|
|
|
|
if (!ReturnTrueFalseObject()) {
|
|
|
|
__ Set(eax, Immediate(Smi::FromInt(1)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize);
|
2010-12-16 08:58:42 +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-08-26 08:22:13 +00:00
|
|
|
__ JumpIfSmi(function, &slow, Label::kNear);
|
2010-12-16 08:58:42 +00:00
|
|
|
__ CmpObjectType(function, JS_FUNCTION_TYPE, scratch);
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(not_equal, &slow, Label::kNear);
|
2010-12-16 08:58:42 +00:00
|
|
|
|
|
|
|
// Null is not instance of anything.
|
2011-03-25 13:21:30 +00:00
|
|
|
__ cmp(object, factory->null_value());
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(not_equal, &object_not_null, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Set(eax, Immediate(Smi::FromInt(1)));
|
2011-01-05 11:17:37 +00:00
|
|
|
__ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize);
|
2010-12-16 08:58:42 +00:00
|
|
|
|
|
|
|
__ bind(&object_not_null);
|
|
|
|
// Smi values is not instance of anything.
|
2011-08-26 08:22:13 +00:00
|
|
|
__ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear);
|
2010-12-16 08:58:42 +00:00
|
|
|
__ Set(eax, Immediate(Smi::FromInt(1)));
|
2011-01-05 11:17:37 +00:00
|
|
|
__ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize);
|
2010-12-16 08:58:42 +00:00
|
|
|
|
|
|
|
__ bind(&object_not_null_or_smi);
|
|
|
|
// String values is not instance of anything.
|
|
|
|
Condition is_string = masm->IsObjectStringType(object, scratch, scratch);
|
2011-08-26 08:22:13 +00:00
|
|
|
__ j(NegateCondition(is_string), &slow, Label::kNear);
|
2010-12-16 08:58:42 +00:00
|
|
|
__ Set(eax, Immediate(Smi::FromInt(1)));
|
2011-01-05 11:17:37 +00:00
|
|
|
__ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Slow-case: Go through the JavaScript implementation.
|
|
|
|
__ bind(&slow);
|
2011-01-05 14:19:12 +00:00
|
|
|
if (!ReturnTrueFalseObject()) {
|
|
|
|
// Tail call the builtin which returns 0 or 1.
|
|
|
|
if (HasArgsInRegisters()) {
|
|
|
|
// Push arguments below return address.
|
|
|
|
__ pop(scratch);
|
|
|
|
__ push(object);
|
|
|
|
__ push(function);
|
|
|
|
__ push(scratch);
|
|
|
|
}
|
|
|
|
__ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
|
|
|
|
} else {
|
|
|
|
// Call the builtin and convert 0/1 to true/false.
|
2011-09-15 11:30:45 +00:00
|
|
|
{
|
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
|
|
|
__ push(object);
|
|
|
|
__ push(function);
|
|
|
|
__ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION);
|
|
|
|
}
|
2011-05-10 09:03:42 +00:00
|
|
|
Label true_value, done;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(eax, eax);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &true_value, Label::kNear);
|
2011-03-25 13:21:30 +00:00
|
|
|
__ mov(eax, factory->false_value());
|
2011-05-10 09:03:42 +00:00
|
|
|
__ jmp(&done, Label::kNear);
|
2011-01-05 14:19:12 +00:00
|
|
|
__ bind(&true_value);
|
2011-03-25 13:21:30 +00:00
|
|
|
__ mov(eax, factory->true_value());
|
2011-01-05 14:19:12 +00:00
|
|
|
__ bind(&done);
|
|
|
|
__ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize);
|
2010-12-16 08:58:42 +00:00
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-05 11:17:37 +00:00
|
|
|
Register InstanceofStub::left() { return eax; }
|
|
|
|
|
|
|
|
|
|
|
|
Register InstanceofStub::right() { return edx; }
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
int CompareStub::MinorKey() {
|
|
|
|
// Encode the three parameters in a unique 16 bit value. To avoid duplicate
|
|
|
|
// stubs the never NaN NaN condition is only taken into account if the
|
|
|
|
// condition is equals.
|
|
|
|
ASSERT(static_cast<unsigned>(cc_) < (1 << 12));
|
|
|
|
ASSERT(lhs_.is(no_reg) && rhs_.is(no_reg));
|
|
|
|
return ConditionField::encode(static_cast<unsigned>(cc_))
|
|
|
|
| RegisterField::encode(false) // lhs_ and rhs_ are not used
|
|
|
|
| StrictField::encode(strict_)
|
|
|
|
| NeverNanNanField::encode(cc_ == equal ? never_nan_nan_ : false)
|
2010-09-15 10:14:25 +00:00
|
|
|
| IncludeNumberCompareField::encode(include_number_compare_)
|
|
|
|
| IncludeSmiCompareField::encode(include_smi_compare_);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Unfortunately you have to run without snapshots to see most of these
|
|
|
|
// names in the profile since most compare stubs end up in the snapshot.
|
2011-07-13 11:08:25 +00:00
|
|
|
void CompareStub::PrintName(StringStream* stream) {
|
2010-08-25 09:44:44 +00:00
|
|
|
ASSERT(lhs_.is(no_reg) && rhs_.is(no_reg));
|
|
|
|
const char* cc_name;
|
|
|
|
switch (cc_) {
|
|
|
|
case less: cc_name = "LT"; break;
|
|
|
|
case greater: cc_name = "GT"; break;
|
|
|
|
case less_equal: cc_name = "LE"; break;
|
|
|
|
case greater_equal: cc_name = "GE"; break;
|
|
|
|
case equal: cc_name = "EQ"; break;
|
|
|
|
case not_equal: cc_name = "NE"; break;
|
|
|
|
default: cc_name = "UnknownCondition"; break;
|
|
|
|
}
|
2011-07-13 11:08:25 +00:00
|
|
|
bool is_equality = cc_ == equal || cc_ == not_equal;
|
|
|
|
stream->Add("CompareStub_%s", cc_name);
|
|
|
|
if (strict_ && is_equality) stream->Add("_STRICT");
|
|
|
|
if (never_nan_nan_ && is_equality) stream->Add("_NO_NAN");
|
|
|
|
if (!include_number_compare_) stream->Add("_NO_NUMBER");
|
|
|
|
if (!include_smi_compare_) stream->Add("_NO_SMI");
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// StringCharCodeAtGenerator
|
|
|
|
|
|
|
|
void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
|
|
|
|
// If the receiver is a smi trigger the non-string case.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-06-17 18:32:36 +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.
|
|
|
|
__ mov(result_, FieldOperand(object_, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
|
|
|
|
// If the receiver is not a string trigger the non-string case.
|
|
|
|
__ test(result_, Immediate(kIsNotStringMask));
|
|
|
|
__ j(not_zero, receiver_not_string_);
|
|
|
|
|
|
|
|
// If the index is non-smi trigger the non-smi case.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-06-17 18:32:36 +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.
|
2011-11-09 14:32:51 +00:00
|
|
|
__ cmp(index_, FieldOperand(object_, String::kLengthOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(above_equal, index_out_of_range_);
|
|
|
|
|
2011-11-09 14:32:51 +00:00
|
|
|
__ SmiUntag(index_);
|
2011-11-17 17:05:12 +00:00
|
|
|
|
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
StringCharLoadGenerator::Generate(
|
|
|
|
masm, factory, object_, index_, result_, &call_runtime_);
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
__ SmiTag(result_);
|
|
|
|
__ 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.
|
2011-03-25 13:21:30 +00:00
|
|
|
__ CheckMap(index_,
|
|
|
|
masm->isolate()->factory()->heap_number_map(),
|
|
|
|
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);
|
|
|
|
__ push(object_);
|
|
|
|
__ 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);
|
|
|
|
}
|
2011-11-09 14:32:51 +00:00
|
|
|
if (!index_.is(eax)) {
|
2010-08-25 09:44:44 +00:00
|
|
|
// Save the conversion result before the pop instructions below
|
|
|
|
// have a chance to overwrite it.
|
2011-11-09 14:32:51 +00:00
|
|
|
__ mov(index_, eax);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
__ pop(object_);
|
|
|
|
// Reload the instance type.
|
|
|
|
__ mov(result_, FieldOperand(object_, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
|
|
|
|
call_helper.AfterCall(masm);
|
|
|
|
// If index is still not a smi, it must be out of range.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
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);
|
|
|
|
__ push(object_);
|
2011-11-17 17:05:12 +00:00
|
|
|
__ SmiTag(index_);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ push(index_);
|
|
|
|
__ CallRuntime(Runtime::kStringCharCodeAt, 2);
|
|
|
|
if (!result_.is(eax)) {
|
|
|
|
__ mov(result_, eax);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
ASSERT(IsPowerOf2(String::kMaxAsciiCharCode + 1));
|
|
|
|
__ test(code_,
|
|
|
|
Immediate(kSmiTagMask |
|
|
|
|
((~String::kMaxAsciiCharCode) << kSmiTagSize)));
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(not_zero, &slow_case_);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-03-25 13:21:30 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
__ Set(result_, Immediate(factory->single_character_string_cache()));
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
STATIC_ASSERT(kSmiShiftSize == 0);
|
|
|
|
// At this point code register contains smi tagged ascii char code.
|
|
|
|
__ mov(result_, FieldOperand(result_,
|
|
|
|
code_, times_half_pointer_size,
|
|
|
|
FixedArray::kHeaderSize));
|
2011-03-25 13:21:30 +00:00
|
|
|
__ cmp(result_, factory->undefined_value());
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(equal, &slow_case_);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ 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);
|
|
|
|
if (!result_.is(eax)) {
|
|
|
|
__ mov(result_, eax);
|
|
|
|
}
|
|
|
|
call_helper.AfterCall(masm);
|
|
|
|
__ jmp(&exit_);
|
|
|
|
|
|
|
|
__ Abort("Unexpected fallthrough from CharFromCode slow case");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// StringCharAtGenerator
|
|
|
|
|
|
|
|
void StringCharAtGenerator::GenerateFast(MacroAssembler* masm) {
|
|
|
|
char_code_at_generator_.GenerateFast(masm);
|
|
|
|
char_from_code_generator_.GenerateFast(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringCharAtGenerator::GenerateSlow(
|
2011-10-28 12:37:29 +00:00
|
|
|
MacroAssembler* masm,
|
|
|
|
const RuntimeCallHelper& call_helper) {
|
2010-08-25 09:44:44 +00:00
|
|
|
char_code_at_generator_.GenerateSlow(masm, call_helper);
|
|
|
|
char_from_code_generator_.GenerateSlow(masm, call_helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringAddStub::Generate(MacroAssembler* masm) {
|
2010-09-03 12:10:44 +00:00
|
|
|
Label string_add_runtime, call_builtin;
|
|
|
|
Builtins::JavaScript builtin_id = Builtins::ADD;
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Load the two arguments.
|
|
|
|
__ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument.
|
|
|
|
__ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument.
|
|
|
|
|
|
|
|
// Make sure that both arguments are strings if not known in advance.
|
2010-09-03 12:10:44 +00:00
|
|
|
if (flags_ == NO_STRING_ADD_FLAGS) {
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(eax, &string_add_runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx);
|
|
|
|
__ j(above_equal, &string_add_runtime);
|
|
|
|
|
|
|
|
// First argument is a a string, test second.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(edx, &string_add_runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx);
|
|
|
|
__ j(above_equal, &string_add_runtime);
|
2010-09-03 12:10:44 +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, 2 * kPointerSize, eax, ebx, ecx, edi,
|
|
|
|
&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, 1 * kPointerSize, edx, ebx, ecx, edi,
|
|
|
|
&call_builtin);
|
|
|
|
builtin_id = Builtins::STRING_ADD_LEFT;
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Both arguments are strings.
|
|
|
|
// eax: first string
|
|
|
|
// edx: second string
|
|
|
|
// Check if either of the strings are empty. In that case return the other.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label second_not_zero_length, both_not_zero_length;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(ecx, FieldOperand(edx, String::kLengthOffset));
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(ecx, ecx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_zero, &second_not_zero_length, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Second string is empty, result is first string which is already in eax.
|
2011-03-23 11:13:07 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
__ IncrementCounter(counters->string_add_native(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
__ bind(&second_not_zero_length);
|
|
|
|
__ mov(ebx, FieldOperand(eax, String::kLengthOffset));
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(ebx, ebx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_zero, &both_not_zero_length, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// First string is empty, result is second string which is in edx.
|
|
|
|
__ mov(eax, edx);
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_add_native(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
|
|
|
|
// Both strings are non-empty.
|
|
|
|
// eax: first string
|
|
|
|
// ebx: length of first string as a smi
|
|
|
|
// ecx: length of second string as a smi
|
|
|
|
// edx: second string
|
|
|
|
// Look at the length of the result of adding the two strings.
|
|
|
|
Label string_add_flat_result, longer_than_two;
|
|
|
|
__ bind(&both_not_zero_length);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(ebx, ecx);
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength);
|
|
|
|
// Handle exceptionally long strings in the runtime system.
|
|
|
|
__ j(overflow, &string_add_runtime);
|
2011-03-15 10:03:57 +00:00
|
|
|
// Use the symbol table when adding two one character strings, as it
|
|
|
|
// helps later optimizations to return a symbol here.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ebx, Immediate(Smi::FromInt(2)));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, &longer_than_two);
|
|
|
|
|
|
|
|
// Check that both strings are non-external ascii strings.
|
|
|
|
__ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx,
|
|
|
|
&string_add_runtime);
|
|
|
|
|
2010-09-01 17:20:36 +00:00
|
|
|
// Get the two characters forming the new string.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ movzx_b(ebx, FieldOperand(eax, SeqAsciiString::kHeaderSize));
|
|
|
|
__ movzx_b(ecx, FieldOperand(edx, SeqAsciiString::kHeaderSize));
|
|
|
|
|
|
|
|
// Try to lookup two character string in symbol table. If it is not found
|
|
|
|
// just allocate a new one.
|
2010-09-01 17:20:36 +00:00
|
|
|
Label make_two_character_string, make_two_character_string_no_reload;
|
2010-08-25 09:44:44 +00:00
|
|
|
StringHelper::GenerateTwoCharacterSymbolTableProbe(
|
2010-09-01 17:20:36 +00:00
|
|
|
masm, ebx, ecx, eax, edx, edi,
|
|
|
|
&make_two_character_string_no_reload, &make_two_character_string);
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_add_native(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
|
2010-09-01 17:20:36 +00:00
|
|
|
// Allocate a two character string.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&make_two_character_string);
|
2010-09-01 17:20:36 +00:00
|
|
|
// Reload the arguments.
|
|
|
|
__ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument.
|
|
|
|
__ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument.
|
|
|
|
// Get the two characters forming the new string.
|
|
|
|
__ movzx_b(ebx, FieldOperand(eax, SeqAsciiString::kHeaderSize));
|
|
|
|
__ movzx_b(ecx, FieldOperand(edx, SeqAsciiString::kHeaderSize));
|
|
|
|
__ bind(&make_two_character_string_no_reload);
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_add_make_two_char(), 1);
|
2010-09-01 17:20:36 +00:00
|
|
|
__ AllocateAsciiString(eax, // Result.
|
|
|
|
2, // Length.
|
|
|
|
edi, // Scratch 1.
|
|
|
|
edx, // Scratch 2.
|
|
|
|
&string_add_runtime);
|
|
|
|
// Pack both characters in ebx.
|
|
|
|
__ shl(ecx, kBitsPerByte);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ or_(ebx, ecx);
|
2010-09-01 17:20:36 +00:00
|
|
|
// Set the characters in the new string.
|
|
|
|
__ mov_w(FieldOperand(eax, SeqAsciiString::kHeaderSize), ebx);
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_add_native(), 1);
|
2010-09-01 17:20:36 +00:00
|
|
|
__ ret(2 * kPointerSize);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&longer_than_two);
|
|
|
|
// Check if resulting string will be flat.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(ebx, Immediate(Smi::FromInt(String::kMinNonFlatLength)));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(below, &string_add_flat_result);
|
|
|
|
|
|
|
|
// If result is not supposed to be flat allocate a cons string object. If both
|
|
|
|
// strings are ascii the result is an ascii cons string.
|
|
|
|
Label non_ascii, allocated, ascii_data;
|
|
|
|
__ mov(edi, FieldOperand(eax, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset));
|
|
|
|
__ mov(edi, FieldOperand(edx, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ and_(ecx, edi);
|
2011-09-01 15:24:26 +00:00
|
|
|
STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0);
|
|
|
|
STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
|
|
|
|
__ test(ecx, Immediate(kStringEncodingMask));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(zero, &non_ascii);
|
|
|
|
__ bind(&ascii_data);
|
|
|
|
// Allocate an acsii cons string.
|
|
|
|
__ AllocateAsciiConsString(ecx, edi, no_reg, &string_add_runtime);
|
|
|
|
__ bind(&allocated);
|
|
|
|
// Fill the fields of the cons string.
|
|
|
|
if (FLAG_debug_code) __ AbortIfNotSmi(ebx);
|
|
|
|
__ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx);
|
|
|
|
__ mov(FieldOperand(ecx, ConsString::kHashFieldOffset),
|
|
|
|
Immediate(String::kEmptyHashField));
|
|
|
|
__ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax);
|
|
|
|
__ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx);
|
|
|
|
__ mov(eax, ecx);
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_add_native(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
__ bind(&non_ascii);
|
|
|
|
// At least one of the strings is two-byte. Check whether it happens
|
|
|
|
// to contain only ascii characters.
|
|
|
|
// ecx: first instance type AND second instance type.
|
|
|
|
// edi: second instance type.
|
|
|
|
__ test(ecx, Immediate(kAsciiDataHintMask));
|
|
|
|
__ j(not_zero, &ascii_data);
|
|
|
|
__ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ xor_(edi, ecx);
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT(kAsciiStringTag != 0 && kAsciiDataHintTag != 0);
|
|
|
|
__ and_(edi, kAsciiStringTag | kAsciiDataHintTag);
|
|
|
|
__ cmp(edi, kAsciiStringTag | kAsciiDataHintTag);
|
|
|
|
__ j(equal, &ascii_data);
|
|
|
|
// Allocate a two byte cons string.
|
2011-09-01 15:24:26 +00:00
|
|
|
__ AllocateTwoByteConsString(ecx, edi, no_reg, &string_add_runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ jmp(&allocated);
|
|
|
|
|
|
|
|
// Handle creating a flat result. First check that both strings are not
|
|
|
|
// external strings.
|
|
|
|
// eax: first string
|
|
|
|
// ebx: length of resulting flat string as a smi
|
|
|
|
// edx: second string
|
|
|
|
__ bind(&string_add_flat_result);
|
|
|
|
__ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset));
|
|
|
|
__ and_(ecx, kStringRepresentationMask);
|
|
|
|
__ cmp(ecx, kExternalStringTag);
|
|
|
|
__ j(equal, &string_add_runtime);
|
|
|
|
__ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset));
|
|
|
|
__ and_(ecx, kStringRepresentationMask);
|
|
|
|
__ cmp(ecx, kExternalStringTag);
|
|
|
|
__ j(equal, &string_add_runtime);
|
2011-08-26 13:03:30 +00:00
|
|
|
// We cannot encounter sliced strings here since:
|
|
|
|
STATIC_ASSERT(SlicedString::kMinLength >= String::kMinNonFlatLength);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Now check if both strings are ascii strings.
|
|
|
|
// eax: first string
|
|
|
|
// ebx: length of resulting flat string as a smi
|
|
|
|
// edx: second string
|
|
|
|
Label non_ascii_string_add_flat_result;
|
2011-09-01 15:24:26 +00:00
|
|
|
STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0);
|
|
|
|
STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset));
|
2011-09-01 15:24:26 +00:00
|
|
|
__ test_b(FieldOperand(ecx, Map::kInstanceTypeOffset), kStringEncodingMask);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(zero, &non_ascii_string_add_flat_result);
|
|
|
|
__ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset));
|
2011-09-01 15:24:26 +00:00
|
|
|
__ test_b(FieldOperand(ecx, Map::kInstanceTypeOffset), kStringEncodingMask);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(zero, &string_add_runtime);
|
|
|
|
|
|
|
|
// Both strings are ascii strings. As they are short they are both flat.
|
|
|
|
// ebx: length of resulting flat string as a smi
|
|
|
|
__ SmiUntag(ebx);
|
|
|
|
__ AllocateAsciiString(eax, ebx, ecx, edx, edi, &string_add_runtime);
|
|
|
|
// eax: result string
|
|
|
|
__ mov(ecx, eax);
|
|
|
|
// Locate first character of result.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(ecx, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag));
|
2010-08-25 09:44:44 +00:00
|
|
|
// Load first argument and locate first character.
|
|
|
|
__ mov(edx, Operand(esp, 2 * kPointerSize));
|
|
|
|
__ mov(edi, FieldOperand(edx, String::kLengthOffset));
|
|
|
|
__ SmiUntag(edi);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(edx, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag));
|
2010-08-25 09:44:44 +00:00
|
|
|
// eax: result string
|
|
|
|
// ecx: first character of result
|
|
|
|
// edx: first char of first argument
|
|
|
|
// edi: length of first argument
|
|
|
|
StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true);
|
|
|
|
// Load second argument and locate first character.
|
|
|
|
__ mov(edx, Operand(esp, 1 * kPointerSize));
|
|
|
|
__ mov(edi, FieldOperand(edx, String::kLengthOffset));
|
|
|
|
__ SmiUntag(edi);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(edx, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag));
|
2010-08-25 09:44:44 +00:00
|
|
|
// eax: result string
|
|
|
|
// ecx: next character of result
|
|
|
|
// edx: first char of second argument
|
|
|
|
// edi: length of second argument
|
|
|
|
StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true);
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_add_native(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
|
|
|
|
// Handle creating a flat two byte result.
|
|
|
|
// eax: first string - known to be two byte
|
|
|
|
// ebx: length of resulting flat string as a smi
|
|
|
|
// edx: second string
|
|
|
|
__ bind(&non_ascii_string_add_flat_result);
|
|
|
|
__ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset));
|
2011-09-01 15:24:26 +00:00
|
|
|
__ test_b(FieldOperand(ecx, Map::kInstanceTypeOffset), kStringEncodingMask);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_zero, &string_add_runtime);
|
|
|
|
// Both strings are two byte strings. As they are short they are both
|
|
|
|
// flat.
|
|
|
|
__ SmiUntag(ebx);
|
|
|
|
__ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &string_add_runtime);
|
|
|
|
// eax: result string
|
|
|
|
__ mov(ecx, eax);
|
|
|
|
// Locate first character of result.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(ecx,
|
2010-08-25 09:44:44 +00:00
|
|
|
Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
|
|
|
|
// Load first argument and locate first character.
|
|
|
|
__ mov(edx, Operand(esp, 2 * kPointerSize));
|
|
|
|
__ mov(edi, FieldOperand(edx, String::kLengthOffset));
|
|
|
|
__ SmiUntag(edi);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(edx,
|
2010-08-25 09:44:44 +00:00
|
|
|
Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
|
|
|
|
// eax: result string
|
|
|
|
// ecx: first character of result
|
|
|
|
// edx: first char of first argument
|
|
|
|
// edi: length of first argument
|
|
|
|
StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false);
|
|
|
|
// Load second argument and locate first character.
|
|
|
|
__ mov(edx, Operand(esp, 1 * kPointerSize));
|
|
|
|
__ mov(edi, FieldOperand(edx, String::kLengthOffset));
|
|
|
|
__ SmiUntag(edi);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(edx, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag));
|
2010-08-25 09:44:44 +00:00
|
|
|
// eax: result string
|
|
|
|
// ecx: next character of result
|
|
|
|
// edx: first char of second argument
|
|
|
|
// edi: length of second argument
|
|
|
|
StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false);
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_add_native(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
|
|
|
|
// Just jump to runtime to add the two strings.
|
|
|
|
__ bind(&string_add_runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kStringAdd, 2, 1);
|
2010-09-03 12:10:44 +00:00
|
|
|
|
|
|
|
if (call_builtin.is_linked()) {
|
|
|
|
__ bind(&call_builtin);
|
|
|
|
__ InvokeBuiltin(builtin_id, JUMP_FUNCTION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringAddStub::GenerateConvertArgument(MacroAssembler* masm,
|
|
|
|
int stack_offset,
|
|
|
|
Register arg,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register scratch3,
|
|
|
|
Label* slow) {
|
|
|
|
// First check if the argument is already a string.
|
|
|
|
Label not_string, done;
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(arg, ¬_string);
|
2010-09-03 12:10:44 +00:00
|
|
|
__ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1);
|
|
|
|
__ j(below, &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,
|
|
|
|
false,
|
|
|
|
¬_cached);
|
|
|
|
__ mov(arg, scratch1);
|
|
|
|
__ mov(Operand(esp, stack_offset), arg);
|
|
|
|
__ jmp(&done);
|
|
|
|
|
|
|
|
// Check if the argument is a safe string wrapper.
|
|
|
|
__ bind(¬_cached);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(arg, slow);
|
2010-09-03 12:10:44 +00:00
|
|
|
__ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1.
|
|
|
|
__ j(not_equal, slow);
|
|
|
|
__ test_b(FieldOperand(scratch1, Map::kBitField2Offset),
|
|
|
|
1 << Map::kStringWrapperSafeForDefaultValueOf);
|
|
|
|
__ j(zero, slow);
|
|
|
|
__ mov(arg, FieldOperand(arg, JSValue::kValueOffset));
|
|
|
|
__ mov(Operand(esp, stack_offset), arg);
|
|
|
|
|
|
|
|
__ bind(&done);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateCopyCharacters(MacroAssembler* masm,
|
|
|
|
Register dest,
|
|
|
|
Register src,
|
|
|
|
Register count,
|
|
|
|
Register scratch,
|
|
|
|
bool ascii) {
|
2011-05-10 09:03:42 +00:00
|
|
|
Label loop;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&loop);
|
|
|
|
// This loop just copies one character at a time, as it is only used for very
|
|
|
|
// short strings.
|
|
|
|
if (ascii) {
|
|
|
|
__ mov_b(scratch, Operand(src, 0));
|
|
|
|
__ mov_b(Operand(dest, 0), scratch);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(src, Immediate(1));
|
|
|
|
__ add(dest, Immediate(1));
|
2010-08-25 09:44:44 +00:00
|
|
|
} else {
|
|
|
|
__ mov_w(scratch, Operand(src, 0));
|
|
|
|
__ mov_w(Operand(dest, 0), scratch);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(src, Immediate(2));
|
|
|
|
__ add(dest, Immediate(2));
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(count, Immediate(1));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_zero, &loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm,
|
|
|
|
Register dest,
|
|
|
|
Register src,
|
|
|
|
Register count,
|
|
|
|
Register scratch,
|
|
|
|
bool ascii) {
|
|
|
|
// Copy characters using rep movs of doublewords.
|
|
|
|
// The destination is aligned on a 4 byte boundary because we are
|
|
|
|
// copying to the beginning of a newly allocated string.
|
|
|
|
ASSERT(dest.is(edi)); // rep movs destination
|
|
|
|
ASSERT(src.is(esi)); // rep movs source
|
|
|
|
ASSERT(count.is(ecx)); // rep movs count
|
|
|
|
ASSERT(!scratch.is(dest));
|
|
|
|
ASSERT(!scratch.is(src));
|
|
|
|
ASSERT(!scratch.is(count));
|
|
|
|
|
|
|
|
// Nothing to do for zero characters.
|
|
|
|
Label done;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(count, count);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(zero, &done);
|
|
|
|
|
|
|
|
// Make count the number of bytes to copy.
|
|
|
|
if (!ascii) {
|
|
|
|
__ shl(count, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't enter the rep movs if there are less than 4 bytes to copy.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label last_bytes;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ test(count, Immediate(~3));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &last_bytes, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Copy from edi to esi using rep movs instruction.
|
|
|
|
__ mov(scratch, count);
|
|
|
|
__ sar(count, 2); // Number of doublewords to copy.
|
|
|
|
__ cld();
|
|
|
|
__ rep_movs();
|
|
|
|
|
|
|
|
// Find number of bytes left.
|
|
|
|
__ mov(count, scratch);
|
|
|
|
__ and_(count, 3);
|
|
|
|
|
|
|
|
// Check if there are more bytes to copy.
|
|
|
|
__ bind(&last_bytes);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(count, count);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(zero, &done);
|
|
|
|
|
|
|
|
// Copy remaining characters.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label loop;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&loop);
|
|
|
|
__ mov_b(scratch, Operand(src, 0));
|
|
|
|
__ mov_b(Operand(dest, 0), scratch);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(src, Immediate(1));
|
|
|
|
__ add(dest, Immediate(1));
|
|
|
|
__ sub(count, Immediate(1));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_zero, &loop);
|
|
|
|
|
|
|
|
__ bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm,
|
|
|
|
Register c1,
|
|
|
|
Register c2,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register scratch3,
|
2010-09-01 17:20:36 +00:00
|
|
|
Label* not_probed,
|
2010-08-25 09:44:44 +00:00
|
|
|
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
|
|
|
|
// different hash algorithm. Don't try to look for these in the symbol table.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label not_array_index;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(scratch, c1);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(scratch, Immediate(static_cast<int>('0')));
|
|
|
|
__ cmp(scratch, Immediate(static_cast<int>('9' - '0')));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(above, ¬_array_index, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(scratch, c2);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(scratch, Immediate(static_cast<int>('0')));
|
|
|
|
__ cmp(scratch, Immediate(static_cast<int>('9' - '0')));
|
2010-09-01 17:20:36 +00:00
|
|
|
__ j(below_equal, not_probed);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(¬_array_index);
|
|
|
|
// Calculate the two character string hash.
|
|
|
|
Register hash = scratch1;
|
|
|
|
GenerateHashInit(masm, hash, c1, scratch);
|
|
|
|
GenerateHashAddCharacter(masm, hash, c2, scratch);
|
|
|
|
GenerateHashGetHash(masm, hash, scratch);
|
|
|
|
|
|
|
|
// Collect the two characters in a register.
|
|
|
|
Register chars = c1;
|
|
|
|
__ shl(c2, kBitsPerByte);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ or_(chars, c2);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// chars: two character string, char 1 in byte 0 and char 2 in byte 1.
|
|
|
|
// hash: hash of two character string.
|
|
|
|
|
|
|
|
// Load the symbol table.
|
|
|
|
Register symbol_table = c2;
|
2011-10-20 12:27:10 +00:00
|
|
|
ExternalReference roots_array_start =
|
|
|
|
ExternalReference::roots_array_start(masm->isolate());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(scratch, Immediate(Heap::kSymbolTableRootIndex));
|
|
|
|
__ mov(symbol_table,
|
2011-10-20 12:27:10 +00:00
|
|
|
Operand::StaticArray(scratch, times_pointer_size, roots_array_start));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Calculate capacity mask from the symbol table capacity.
|
|
|
|
Register mask = scratch2;
|
|
|
|
__ mov(mask, FieldOperand(symbol_table, SymbolTable::kCapacityOffset));
|
|
|
|
__ SmiUntag(mask);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(mask, Immediate(1));
|
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
|
|
|
|
// symbol_table: symbol table
|
|
|
|
// mask: capacity mask
|
|
|
|
// scratch: -
|
|
|
|
|
|
|
|
// Perform a number of probes in the symbol table.
|
|
|
|
static const int kProbes = 4;
|
|
|
|
Label found_in_symbol_table;
|
|
|
|
Label next_probe[kProbes], next_probe_pop_mask[kProbes];
|
2011-11-10 14:26:57 +00:00
|
|
|
Register candidate = scratch; // Scratch register contains candidate.
|
2010-08-25 09:44:44 +00:00
|
|
|
for (int i = 0; i < kProbes; i++) {
|
|
|
|
// Calculate entry in symbol table.
|
|
|
|
__ mov(scratch, hash);
|
|
|
|
if (i > 0) {
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(scratch, Immediate(SymbolTable::GetProbeOffset(i)));
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
2011-10-03 11:44:39 +00:00
|
|
|
__ and_(scratch, mask);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Load the entry from the symbol table.
|
|
|
|
STATIC_ASSERT(SymbolTable::kEntrySize == 1);
|
|
|
|
__ mov(candidate,
|
|
|
|
FieldOperand(symbol_table,
|
|
|
|
scratch,
|
|
|
|
times_pointer_size,
|
|
|
|
SymbolTable::kElementsStartOffset));
|
|
|
|
|
|
|
|
// If entry is undefined no string with this hash can be found.
|
2011-03-25 13:21:30 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
__ cmp(candidate, factory->undefined_value());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(equal, not_found);
|
2011-11-10 14:26:57 +00:00
|
|
|
__ cmp(candidate, factory->the_hole_value());
|
2011-03-15 10:03:57 +00:00
|
|
|
__ j(equal, &next_probe[i]);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// If length is not 2 the string is not a candidate.
|
|
|
|
__ cmp(FieldOperand(candidate, String::kLengthOffset),
|
|
|
|
Immediate(Smi::FromInt(2)));
|
|
|
|
__ j(not_equal, &next_probe[i]);
|
|
|
|
|
|
|
|
// As we are out of registers save the mask on the stack and use that
|
|
|
|
// register as a temporary.
|
|
|
|
__ push(mask);
|
|
|
|
Register temp = mask;
|
|
|
|
|
|
|
|
// Check that the candidate is a non-external ascii string.
|
|
|
|
__ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset));
|
|
|
|
__ JumpIfInstanceTypeIsNotSequentialAscii(
|
|
|
|
temp, temp, &next_probe_pop_mask[i]);
|
|
|
|
|
|
|
|
// Check if the two characters match.
|
|
|
|
__ mov(temp, FieldOperand(candidate, SeqAsciiString::kHeaderSize));
|
|
|
|
__ and_(temp, 0x0000ffff);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(chars, temp);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(equal, &found_in_symbol_table);
|
|
|
|
__ bind(&next_probe_pop_mask[i]);
|
|
|
|
__ pop(mask);
|
|
|
|
__ 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;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&found_in_symbol_table);
|
|
|
|
__ pop(mask); // Pop saved mask from the stack.
|
|
|
|
if (!result.is(eax)) {
|
|
|
|
__ mov(eax, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateHashInit(MacroAssembler* masm,
|
|
|
|
Register hash,
|
|
|
|
Register character,
|
|
|
|
Register scratch) {
|
|
|
|
// hash = character + (character << 10);
|
|
|
|
__ mov(hash, character);
|
|
|
|
__ shl(hash, 10);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(hash, character);
|
2010-08-25 09:44:44 +00:00
|
|
|
// hash ^= hash >> 6;
|
|
|
|
__ mov(scratch, hash);
|
2011-11-10 14:26:57 +00:00
|
|
|
__ shr(scratch, 6);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ xor_(hash, scratch);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm,
|
|
|
|
Register hash,
|
|
|
|
Register character,
|
|
|
|
Register scratch) {
|
|
|
|
// hash += character;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(hash, character);
|
2010-08-25 09:44:44 +00:00
|
|
|
// hash += hash << 10;
|
|
|
|
__ mov(scratch, hash);
|
|
|
|
__ shl(scratch, 10);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(hash, scratch);
|
2010-08-25 09:44:44 +00:00
|
|
|
// hash ^= hash >> 6;
|
|
|
|
__ mov(scratch, hash);
|
2011-11-10 14:26:57 +00:00
|
|
|
__ shr(scratch, 6);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ xor_(hash, scratch);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateHashGetHash(MacroAssembler* masm,
|
|
|
|
Register hash,
|
|
|
|
Register scratch) {
|
|
|
|
// hash += hash << 3;
|
|
|
|
__ mov(scratch, hash);
|
|
|
|
__ shl(scratch, 3);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(hash, scratch);
|
2010-08-25 09:44:44 +00:00
|
|
|
// hash ^= hash >> 11;
|
|
|
|
__ mov(scratch, hash);
|
2011-11-10 14:26:57 +00:00
|
|
|
__ shr(scratch, 11);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ xor_(hash, scratch);
|
2010-08-25 09:44:44 +00:00
|
|
|
// hash += hash << 15;
|
|
|
|
__ mov(scratch, hash);
|
|
|
|
__ shl(scratch, 15);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(hash, scratch);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-11-10 14:26:57 +00:00
|
|
|
uint32_t kHashShiftCutOffMask = (1 << (32 - String::kHashShift)) - 1;
|
|
|
|
__ and_(hash, kHashShiftCutOffMask);
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// if (hash == 0) hash = 27;
|
2011-05-10 09:03:42 +00:00
|
|
|
Label hash_not_zero;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(hash, hash);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_zero, &hash_not_zero, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(hash, Immediate(27));
|
|
|
|
__ bind(&hash_not_zero);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SubStringStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label runtime;
|
|
|
|
|
|
|
|
// Stack frame on entry.
|
|
|
|
// esp[0]: return address
|
|
|
|
// esp[4]: to
|
|
|
|
// esp[8]: from
|
|
|
|
// esp[12]: string
|
|
|
|
|
|
|
|
// Make sure first argument is a string.
|
|
|
|
__ mov(eax, Operand(esp, 3 * kPointerSize));
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(eax, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
Condition is_string = masm->IsObjectStringType(eax, ebx, ebx);
|
|
|
|
__ j(NegateCondition(is_string), &runtime);
|
|
|
|
|
|
|
|
// eax: string
|
|
|
|
// ebx: instance type
|
|
|
|
|
|
|
|
// Calculate length of sub string using the smi values.
|
|
|
|
Label result_longer_than_two;
|
|
|
|
__ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(ecx, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(edx, Operand(esp, 2 * kPointerSize)); // From index.
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(edx, &runtime);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(ecx, edx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmp(ecx, FieldOperand(eax, String::kLengthOffset));
|
|
|
|
Label return_eax;
|
|
|
|
__ j(equal, &return_eax);
|
|
|
|
// Special handling of sub-strings of length 1 and 2. One character strings
|
|
|
|
// are handled in the runtime system (looked up in the single character
|
|
|
|
// cache). Two character strings are looked for in the symbol cache.
|
|
|
|
__ SmiUntag(ecx); // Result length is no longer smi.
|
|
|
|
__ cmp(ecx, 2);
|
|
|
|
__ j(greater, &result_longer_than_two);
|
|
|
|
__ j(less, &runtime);
|
|
|
|
|
|
|
|
// Sub string of length 2 requested.
|
|
|
|
// eax: string
|
|
|
|
// ebx: instance type
|
|
|
|
// ecx: sub string length (value is 2)
|
|
|
|
// edx: from index (smi)
|
|
|
|
__ JumpIfInstanceTypeIsNotSequentialAscii(ebx, ebx, &runtime);
|
|
|
|
|
|
|
|
// Get the two characters forming the sub string.
|
|
|
|
__ SmiUntag(edx); // From index is no longer smi.
|
|
|
|
__ movzx_b(ebx, FieldOperand(eax, edx, times_1, SeqAsciiString::kHeaderSize));
|
|
|
|
__ movzx_b(ecx,
|
|
|
|
FieldOperand(eax, edx, times_1, SeqAsciiString::kHeaderSize + 1));
|
|
|
|
|
|
|
|
// Try to lookup two character string in symbol table.
|
|
|
|
Label make_two_character_string;
|
|
|
|
StringHelper::GenerateTwoCharacterSymbolTableProbe(
|
2010-09-01 17:20:36 +00:00
|
|
|
masm, ebx, ecx, eax, edx, edi,
|
|
|
|
&make_two_character_string, &make_two_character_string);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(3 * kPointerSize);
|
|
|
|
|
|
|
|
__ bind(&make_two_character_string);
|
|
|
|
// Setup registers for allocating the two character string.
|
|
|
|
__ mov(eax, Operand(esp, 3 * kPointerSize));
|
|
|
|
__ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset));
|
|
|
|
__ Set(ecx, Immediate(2));
|
|
|
|
|
2011-08-30 08:22:41 +00:00
|
|
|
if (FLAG_string_slices) {
|
2011-08-30 08:41:54 +00:00
|
|
|
Label copy_routine;
|
2011-08-30 08:22:41 +00:00
|
|
|
// If coming from the make_two_character_string path, the string
|
|
|
|
// is too short to be sliced anyways.
|
|
|
|
STATIC_ASSERT(2 < SlicedString::kMinLength);
|
|
|
|
__ jmp(©_routine);
|
|
|
|
__ bind(&result_longer_than_two);
|
|
|
|
|
|
|
|
// eax: string
|
|
|
|
// ebx: instance type
|
|
|
|
// ecx: sub string length
|
|
|
|
// edx: from index (smi)
|
2011-11-17 08:40:40 +00:00
|
|
|
Label allocate_slice, sliced_string, seq_or_external_string;
|
2011-08-30 08:22:41 +00:00
|
|
|
__ cmp(ecx, SlicedString::kMinLength);
|
|
|
|
// Short slice. Copy instead of slicing.
|
|
|
|
__ j(less, ©_routine);
|
2011-11-17 08:40:40 +00:00
|
|
|
// If the string is not indirect, it can only be sequential or external.
|
2011-08-30 08:22:41 +00:00
|
|
|
STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
|
|
|
|
STATIC_ASSERT(kIsIndirectStringMask != 0);
|
|
|
|
__ test(ebx, Immediate(kIsIndirectStringMask));
|
2011-11-17 08:40:40 +00:00
|
|
|
__ j(zero, &seq_or_external_string, Label::kNear);
|
2011-08-30 08:22:41 +00:00
|
|
|
|
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
__ test(ebx, Immediate(kSlicedNotConsMask));
|
|
|
|
__ j(not_zero, &sliced_string, Label::kNear);
|
|
|
|
// Cons string. Check whether it is flat, then fetch first part.
|
|
|
|
__ cmp(FieldOperand(eax, ConsString::kSecondOffset),
|
|
|
|
factory->empty_string());
|
|
|
|
__ j(not_equal, &runtime);
|
|
|
|
__ mov(edi, FieldOperand(eax, ConsString::kFirstOffset));
|
|
|
|
__ jmp(&allocate_slice, Label::kNear);
|
|
|
|
|
|
|
|
__ bind(&sliced_string);
|
|
|
|
// Sliced string. Fetch parent and correct start index by offset.
|
|
|
|
__ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset));
|
|
|
|
__ mov(edi, FieldOperand(eax, SlicedString::kParentOffset));
|
|
|
|
__ jmp(&allocate_slice, Label::kNear);
|
|
|
|
|
2011-11-17 08:40:40 +00:00
|
|
|
__ bind(&seq_or_external_string);
|
|
|
|
// Sequential or external string. Just move string to the correct register.
|
2011-08-30 08:22:41 +00:00
|
|
|
__ mov(edi, eax);
|
|
|
|
|
|
|
|
__ bind(&allocate_slice);
|
|
|
|
// edi: underlying subject string
|
|
|
|
// ebx: instance type of original subject string
|
|
|
|
// edx: offset
|
|
|
|
// ecx: length
|
|
|
|
// 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;
|
2011-09-01 15:24:26 +00:00
|
|
|
STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0);
|
|
|
|
STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
|
|
|
|
__ test(ebx, Immediate(kStringEncodingMask));
|
2011-08-30 08:22:41 +00:00
|
|
|
__ j(zero, &two_byte_slice, Label::kNear);
|
|
|
|
__ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime);
|
|
|
|
__ jmp(&set_slice_header, Label::kNear);
|
|
|
|
__ bind(&two_byte_slice);
|
2011-09-01 15:24:26 +00:00
|
|
|
__ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime);
|
2011-08-30 08:22:41 +00:00
|
|
|
__ bind(&set_slice_header);
|
|
|
|
__ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx);
|
|
|
|
__ SmiTag(ecx);
|
|
|
|
__ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx);
|
|
|
|
__ mov(FieldOperand(eax, SlicedString::kParentOffset), edi);
|
|
|
|
__ mov(FieldOperand(eax, SlicedString::kHashFieldOffset),
|
|
|
|
Immediate(String::kEmptyHashField));
|
|
|
|
__ jmp(&return_eax);
|
|
|
|
|
|
|
|
__ bind(©_routine);
|
|
|
|
} else {
|
|
|
|
__ bind(&result_longer_than_two);
|
|
|
|
}
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// eax: string
|
|
|
|
// ebx: instance type
|
|
|
|
// ecx: result string length
|
|
|
|
// Check for flat ascii string
|
|
|
|
Label non_ascii_flat;
|
|
|
|
__ JumpIfInstanceTypeIsNotSequentialAscii(ebx, ebx, &non_ascii_flat);
|
|
|
|
|
|
|
|
// Allocate the result.
|
|
|
|
__ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime);
|
|
|
|
|
|
|
|
// eax: result string
|
|
|
|
// ecx: result string length
|
|
|
|
__ mov(edx, esi); // esi used by following code.
|
|
|
|
// Locate first character of result.
|
|
|
|
__ mov(edi, eax);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(edi, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag));
|
2010-08-25 09:44:44 +00:00
|
|
|
// Load string argument and locate character of sub string start.
|
|
|
|
__ mov(esi, Operand(esp, 3 * kPointerSize));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(esi, Immediate(SeqAsciiString::kHeaderSize - kHeapObjectTag));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(ebx, Operand(esp, 2 * kPointerSize)); // from
|
|
|
|
__ SmiUntag(ebx);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(esi, ebx);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// eax: result string
|
|
|
|
// ecx: result length
|
|
|
|
// edx: original value of esi
|
|
|
|
// edi: first character of result
|
|
|
|
// esi: character of sub string start
|
|
|
|
StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true);
|
|
|
|
__ mov(esi, edx); // Restore esi.
|
2011-03-23 11:13:07 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
__ IncrementCounter(counters->sub_string_native(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(3 * kPointerSize);
|
|
|
|
|
|
|
|
__ bind(&non_ascii_flat);
|
|
|
|
// eax: string
|
|
|
|
// ebx: instance type & kStringRepresentationMask | kStringEncodingMask
|
|
|
|
// ecx: result string length
|
|
|
|
// Check for flat two byte string
|
|
|
|
__ cmp(ebx, kSeqStringTag | kTwoByteStringTag);
|
|
|
|
__ j(not_equal, &runtime);
|
|
|
|
|
|
|
|
// Allocate the result.
|
|
|
|
__ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime);
|
|
|
|
|
|
|
|
// eax: result string
|
|
|
|
// ecx: result string length
|
|
|
|
__ mov(edx, esi); // esi used by following code.
|
|
|
|
// Locate first character of result.
|
|
|
|
__ mov(edi, eax);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(edi,
|
2010-08-25 09:44:44 +00:00
|
|
|
Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
|
|
|
|
// Load string argument and locate character of sub string start.
|
|
|
|
__ mov(esi, Operand(esp, 3 * kPointerSize));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(esi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(ebx, Operand(esp, 2 * kPointerSize)); // from
|
|
|
|
// As from is a smi it is 2 times the value which matches the size of a two
|
|
|
|
// byte character.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(esi, ebx);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// eax: result string
|
|
|
|
// ecx: result length
|
|
|
|
// edx: original value of esi
|
|
|
|
// edi: first character of result
|
|
|
|
// esi: character of sub string start
|
|
|
|
StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false);
|
|
|
|
__ mov(esi, edx); // Restore esi.
|
|
|
|
|
|
|
|
__ bind(&return_eax);
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->sub_string_native(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(3 * kPointerSize);
|
|
|
|
|
|
|
|
// Just jump to runtime to create the sub string.
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kSubString, 3, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-05 11:40:08 +00:00
|
|
|
void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm,
|
|
|
|
Register left,
|
|
|
|
Register right,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2) {
|
|
|
|
Register length = scratch1;
|
|
|
|
|
|
|
|
// Compare lengths.
|
2011-05-11 09:12:16 +00:00
|
|
|
Label strings_not_equal, check_zero_length;
|
2011-05-05 11:40:08 +00:00
|
|
|
__ mov(length, FieldOperand(left, String::kLengthOffset));
|
|
|
|
__ cmp(length, FieldOperand(right, String::kLengthOffset));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(equal, &check_zero_length, Label::kNear);
|
2011-05-05 11:40:08 +00:00
|
|
|
__ bind(&strings_not_equal);
|
|
|
|
__ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL)));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Check if the length is zero.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label compare_chars;
|
2011-05-05 11:40:08 +00:00
|
|
|
__ bind(&check_zero_length);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(length, length);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_zero, &compare_chars, Label::kNear);
|
2011-05-05 11:40:08 +00:00
|
|
|
__ Set(eax, Immediate(Smi::FromInt(EQUAL)));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Compare characters.
|
|
|
|
__ bind(&compare_chars);
|
2011-05-06 14:19:51 +00:00
|
|
|
GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2,
|
2011-05-11 09:12:16 +00:00
|
|
|
&strings_not_equal, Label::kNear);
|
2011-05-05 11:40:08 +00:00
|
|
|
|
|
|
|
// Characters are equal.
|
|
|
|
__ Set(eax, Immediate(Smi::FromInt(EQUAL)));
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
|
|
|
|
Register left,
|
|
|
|
Register right,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register scratch3) {
|
2011-03-23 11:13:07 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
__ IncrementCounter(counters->string_compare_native(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Find minimum length.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label left_shorter;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ mov(scratch1, FieldOperand(left, String::kLengthOffset));
|
|
|
|
__ mov(scratch3, scratch1);
|
|
|
|
__ sub(scratch3, FieldOperand(right, String::kLengthOffset));
|
|
|
|
|
|
|
|
Register length_delta = scratch3;
|
|
|
|
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(less_equal, &left_shorter, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Right string is shorter. Change scratch1 to be length of right string.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(scratch1, length_delta);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&left_shorter);
|
|
|
|
|
|
|
|
Register min_length = scratch1;
|
|
|
|
|
|
|
|
// If either length is zero, just compare lengths.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label compare_lengths;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(min_length, min_length);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &compare_lengths, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-05-06 14:19:51 +00:00
|
|
|
// Compare characters.
|
2011-05-11 09:12:16 +00:00
|
|
|
Label result_not_equal;
|
2011-05-06 14:19:51 +00:00
|
|
|
GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2,
|
2011-05-11 09:12:16 +00:00
|
|
|
&result_not_equal, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Compare lengths - strings up to min-length are equal.
|
|
|
|
__ bind(&compare_lengths);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(length_delta, length_delta);
|
2011-05-11 09:12:16 +00:00
|
|
|
__ j(not_zero, &result_not_equal, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Result is EQUAL.
|
|
|
|
STATIC_ASSERT(EQUAL == 0);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ Set(eax, Immediate(Smi::FromInt(EQUAL)));
|
|
|
|
__ ret(0);
|
|
|
|
|
2011-05-10 09:03:42 +00:00
|
|
|
Label result_greater;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&result_not_equal);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(greater, &result_greater, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Result is LESS.
|
|
|
|
__ Set(eax, Immediate(Smi::FromInt(LESS)));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Result is GREATER.
|
|
|
|
__ bind(&result_greater);
|
|
|
|
__ Set(eax, Immediate(Smi::FromInt(GREATER)));
|
|
|
|
__ ret(0);
|
2011-05-06 14:19:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringCompareStub::GenerateAsciiCharsCompareLoop(
|
|
|
|
MacroAssembler* masm,
|
|
|
|
Register left,
|
|
|
|
Register right,
|
|
|
|
Register length,
|
|
|
|
Register scratch,
|
2011-05-11 09:12:16 +00:00
|
|
|
Label* chars_not_equal,
|
|
|
|
Label::Distance chars_not_equal_near) {
|
2011-05-06 14:19:51 +00:00
|
|
|
// 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);
|
|
|
|
__ lea(left,
|
|
|
|
FieldOperand(left, length, times_1, SeqAsciiString::kHeaderSize));
|
|
|
|
__ lea(right,
|
|
|
|
FieldOperand(right, length, times_1, SeqAsciiString::kHeaderSize));
|
|
|
|
__ neg(length);
|
|
|
|
Register index = length; // index = -length;
|
|
|
|
|
|
|
|
// Compare loop.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label loop;
|
2011-05-06 14:19:51 +00:00
|
|
|
__ bind(&loop);
|
|
|
|
__ mov_b(scratch, Operand(left, index, times_1, 0));
|
|
|
|
__ cmpb(scratch, Operand(right, index, times_1, 0));
|
2011-05-11 09:12:16 +00:00
|
|
|
__ j(not_equal, chars_not_equal, chars_not_equal_near);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(index, Immediate(1));
|
2011-05-06 14:19:51 +00:00
|
|
|
__ j(not_zero, &loop);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringCompareStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label runtime;
|
|
|
|
|
|
|
|
// Stack frame on entry.
|
|
|
|
// esp[0]: return address
|
|
|
|
// esp[4]: right string
|
|
|
|
// esp[8]: left string
|
|
|
|
|
|
|
|
__ mov(edx, Operand(esp, 2 * kPointerSize)); // left
|
|
|
|
__ mov(eax, Operand(esp, 1 * kPointerSize)); // right
|
|
|
|
|
2011-05-10 09:03:42 +00:00
|
|
|
Label not_same;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(edx, eax);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, ¬_same, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT(EQUAL == 0);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ Set(eax, Immediate(Smi::FromInt(EQUAL)));
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
|
|
|
|
__ bind(¬_same);
|
|
|
|
|
|
|
|
// Check that both objects are sequential ascii strings.
|
|
|
|
__ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime);
|
|
|
|
|
|
|
|
// Compare flat ascii strings.
|
|
|
|
// Drop arguments from the stack.
|
|
|
|
__ pop(ecx);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(esp, Immediate(2 * kPointerSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ push(ecx);
|
|
|
|
GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi);
|
|
|
|
|
|
|
|
// Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
|
|
|
|
// tagged as a small integer.
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kStringCompare, 2, 1);
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
void ICCompareStub::GenerateSmis(MacroAssembler* masm) {
|
|
|
|
ASSERT(state_ == CompareIC::SMIS);
|
2011-05-10 09:03:42 +00:00
|
|
|
Label miss;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(ecx, edx);
|
|
|
|
__ or_(ecx, eax);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfNotSmi(ecx, &miss, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
if (GetCondition() == equal) {
|
|
|
|
// For equality we do not care about the sign of the result.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(eax, edx);
|
2010-12-07 11:31:57 +00:00
|
|
|
} else {
|
2011-05-10 09:03:42 +00:00
|
|
|
Label done;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(edx, eax);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(no_overflow, &done, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
// Correct sign of result in case of overflow.
|
|
|
|
__ not_(edx);
|
|
|
|
__ bind(&done);
|
|
|
|
__ mov(eax, edx);
|
|
|
|
}
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) {
|
|
|
|
ASSERT(state_ == CompareIC::HEAP_NUMBERS);
|
|
|
|
|
2011-05-10 09:03:42 +00:00
|
|
|
Label generic_stub;
|
|
|
|
Label unordered;
|
|
|
|
Label miss;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(ecx, edx);
|
|
|
|
__ and_(ecx, eax);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(ecx, &generic_stub, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
__ CmpObjectType(eax, HEAP_NUMBER_TYPE, ecx);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(not_equal, &miss, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(not_equal, &miss, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Inlining the double comparison and falling back to the general compare
|
|
|
|
// stub if NaN is involved or SS2 or CMOV is unsupported.
|
2011-03-31 16:17:37 +00:00
|
|
|
if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
CpuFeatures::Scope scope1(SSE2);
|
|
|
|
CpuFeatures::Scope scope2(CMOV);
|
|
|
|
|
|
|
|
// Load left and right operand
|
|
|
|
__ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset));
|
|
|
|
__ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset));
|
|
|
|
|
|
|
|
// Compare operands
|
|
|
|
__ ucomisd(xmm0, xmm1);
|
|
|
|
|
|
|
|
// Don't base result on EFLAGS when a NaN is involved.
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(parity_even, &unordered, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Return a result of -1, 0, or 1, based on EFLAGS.
|
|
|
|
// Performing mov, because xor would destroy the flag register.
|
|
|
|
__ mov(eax, 0); // equal
|
|
|
|
__ mov(ecx, Immediate(Smi::FromInt(1)));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmov(above, eax, ecx);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ mov(ecx, Immediate(Smi::FromInt(-1)));
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmov(below, eax, ecx);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&unordered);
|
|
|
|
}
|
|
|
|
|
|
|
|
CompareStub stub(GetCondition(), strict(), NO_COMPARE_FLAGS);
|
|
|
|
__ bind(&generic_stub);
|
|
|
|
__ jmp(stub.GetCode(), RelocInfo::CODE_TARGET);
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-09 13:30:04 +00:00
|
|
|
void ICCompareStub::GenerateSymbols(MacroAssembler* masm) {
|
|
|
|
ASSERT(state_ == CompareIC::SYMBOLS);
|
|
|
|
ASSERT(GetCondition() == equal);
|
|
|
|
|
|
|
|
// Registers containing left and right operands respectively.
|
|
|
|
Register left = edx;
|
|
|
|
Register right = eax;
|
|
|
|
Register tmp1 = ecx;
|
|
|
|
Register tmp2 = ebx;
|
|
|
|
|
|
|
|
// Check that both operands are heap objects.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label miss;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(tmp1, left);
|
2011-05-09 13:30:04 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ and_(tmp1, right);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(tmp1, &miss, Label::kNear);
|
2011-05-09 13:30:04 +00:00
|
|
|
|
|
|
|
// Check that both operands are symbols.
|
|
|
|
__ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset));
|
|
|
|
__ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
|
|
|
|
__ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
|
|
|
|
STATIC_ASSERT(kSymbolTag != 0);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ and_(tmp1, tmp2);
|
2011-05-09 13:30:04 +00:00
|
|
|
__ test(tmp1, Immediate(kIsSymbolMask));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &miss, Label::kNear);
|
2011-05-09 13:30:04 +00:00
|
|
|
|
|
|
|
// Symbols are compared by identity.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label done;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(left, right);
|
2011-05-09 13:30:04 +00:00
|
|
|
// Make sure eax is non-zero. At this point input operands are
|
|
|
|
// guaranteed to be non-zero.
|
|
|
|
ASSERT(right.is(eax));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, &done, Label::kNear);
|
2011-05-09 13:30:04 +00:00
|
|
|
STATIC_ASSERT(EQUAL == 0);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ Set(eax, Immediate(Smi::FromInt(EQUAL)));
|
|
|
|
__ bind(&done);
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-04 18:30:37 +00:00
|
|
|
void ICCompareStub::GenerateStrings(MacroAssembler* masm) {
|
|
|
|
ASSERT(state_ == CompareIC::STRINGS);
|
2011-05-05 11:40:08 +00:00
|
|
|
ASSERT(GetCondition() == equal);
|
2011-05-04 18:30:37 +00:00
|
|
|
Label miss;
|
|
|
|
|
|
|
|
// Registers containing left and right operands respectively.
|
|
|
|
Register left = edx;
|
|
|
|
Register right = eax;
|
|
|
|
Register tmp1 = ecx;
|
|
|
|
Register tmp2 = ebx;
|
|
|
|
Register tmp3 = edi;
|
|
|
|
|
|
|
|
// Check that both operands are heap objects.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(tmp1, left);
|
2011-05-04 18:30:37 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ and_(tmp1, right);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(tmp1, &miss);
|
2011-05-04 18:30:37 +00:00
|
|
|
|
|
|
|
// Check that both operands are strings. This leaves the instance
|
|
|
|
// types loaded in tmp1 and tmp2.
|
|
|
|
__ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset));
|
|
|
|
__ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset));
|
|
|
|
__ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
|
|
|
|
__ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
|
|
|
|
__ mov(tmp3, tmp1);
|
|
|
|
STATIC_ASSERT(kNotStringTag != 0);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ or_(tmp3, tmp2);
|
2011-05-04 18:30:37 +00:00
|
|
|
__ test(tmp3, Immediate(kIsNotStringMask));
|
|
|
|
__ j(not_zero, &miss);
|
|
|
|
|
|
|
|
// Fast check for identical strings.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label not_same;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ cmp(left, right);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, ¬_same, Label::kNear);
|
2011-05-04 18:30:37 +00:00
|
|
|
STATIC_ASSERT(EQUAL == 0);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ Set(eax, Immediate(Smi::FromInt(EQUAL)));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Handle not identical strings.
|
|
|
|
__ bind(¬_same);
|
|
|
|
|
|
|
|
// Check that both strings are symbols. If they are, we're done
|
|
|
|
// because we already know they are not identical.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label do_compare;
|
2011-05-04 18:30:37 +00:00
|
|
|
STATIC_ASSERT(kSymbolTag != 0);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ and_(tmp1, tmp2);
|
2011-05-04 18:30:37 +00:00
|
|
|
__ test(tmp1, Immediate(kIsSymbolMask));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &do_compare, Label::kNear);
|
2011-05-04 18:30:37 +00:00
|
|
|
// Make sure eax is non-zero. At this point input operands are
|
|
|
|
// guaranteed to be non-zero.
|
|
|
|
ASSERT(right.is(eax));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Check that both strings are sequential ASCII.
|
|
|
|
Label runtime;
|
|
|
|
__ bind(&do_compare);
|
|
|
|
__ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime);
|
|
|
|
|
|
|
|
// Compare flat ASCII strings. Returns when done.
|
2011-05-05 11:40:08 +00:00
|
|
|
StringCompareStub::GenerateFlatAsciiStringEquals(
|
|
|
|
masm, left, right, tmp1, tmp2);
|
2011-05-04 18:30:37 +00:00
|
|
|
|
|
|
|
// Handle more complex cases in runtime.
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ pop(tmp1); // Return address.
|
|
|
|
__ push(left);
|
|
|
|
__ push(right);
|
|
|
|
__ push(tmp1);
|
2011-05-05 11:40:08 +00:00
|
|
|
__ TailCallRuntime(Runtime::kStringEquals, 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) {
|
|
|
|
ASSERT(state_ == CompareIC::OBJECTS);
|
2011-05-10 09:03:42 +00:00
|
|
|
Label miss;
|
2011-10-03 11:44:39 +00:00
|
|
|
__ mov(ecx, edx);
|
|
|
|
__ and_(ecx, eax);
|
2011-06-17 18:32:36 +00:00
|
|
|
__ JumpIfSmi(ecx, &miss, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
__ CmpObjectType(eax, JS_OBJECT_TYPE, ecx);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(not_equal, &miss, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ CmpObjectType(edx, JS_OBJECT_TYPE, ecx);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(not_equal, &miss, Label::kNear);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
ASSERT(GetCondition() == equal);
|
2011-10-03 11:44:39 +00:00
|
|
|
__ sub(eax, edx);
|
2010-12-07 11:31:57 +00:00
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ICCompareStub::GenerateMiss(MacroAssembler* masm) {
|
|
|
|
// Save the registers.
|
|
|
|
__ pop(ecx);
|
|
|
|
__ push(edx);
|
|
|
|
__ push(eax);
|
|
|
|
__ push(ecx);
|
|
|
|
|
2011-09-15 11:30:45 +00:00
|
|
|
{
|
|
|
|
// Call the runtime system in a fresh internal frame.
|
|
|
|
ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss),
|
|
|
|
masm->isolate());
|
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
|
|
|
__ push(edx);
|
|
|
|
__ push(eax);
|
|
|
|
__ push(Immediate(Smi::FromInt(op_)));
|
|
|
|
__ CallExternalReference(miss, 3);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Compute the entry point of the rewritten stub.
|
|
|
|
__ lea(edi, FieldOperand(eax, Code::kHeaderSize));
|
|
|
|
|
|
|
|
// Restore registers.
|
|
|
|
__ pop(ecx);
|
|
|
|
__ pop(eax);
|
|
|
|
__ pop(edx);
|
|
|
|
__ push(ecx);
|
|
|
|
|
|
|
|
// Do a tail call to the rewritten stub.
|
2011-10-03 11:44:39 +00:00
|
|
|
__ jmp(edi);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-05 12:30:57 +00:00
|
|
|
// Helper function used to check that the dictionary doesn't contain
|
|
|
|
// the property. This function may return false negatives, so miss_label
|
|
|
|
// must always call a backup property check that is complete.
|
|
|
|
// This function is safe to call if the receiver has fast properties.
|
|
|
|
// Name must be a symbol and receiver must be a heap object.
|
2011-10-25 09:24:49 +00:00
|
|
|
void StringDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
|
|
|
|
Label* miss,
|
|
|
|
Label* done,
|
|
|
|
Register properties,
|
|
|
|
Handle<String> name,
|
|
|
|
Register r0) {
|
|
|
|
ASSERT(name->IsSymbol());
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// (their names are the null value).
|
|
|
|
for (int i = 0; i < kInlinedProbes; i++) {
|
|
|
|
// Compute the masked index: (hash + i + i * i) & mask.
|
|
|
|
Register index = r0;
|
|
|
|
// Capacity is smi 2^n.
|
|
|
|
__ mov(index, FieldOperand(properties, kCapacityOffset));
|
|
|
|
__ dec(index);
|
|
|
|
__ and_(index,
|
|
|
|
Immediate(Smi::FromInt(name->Hash() +
|
|
|
|
StringDictionary::GetProbeOffset(i))));
|
|
|
|
|
|
|
|
// Scale the index by multiplying by the entry size.
|
|
|
|
ASSERT(StringDictionary::kEntrySize == 3);
|
|
|
|
__ lea(index, Operand(index, index, times_2, 0)); // index *= 3.
|
|
|
|
Register entity_name = r0;
|
|
|
|
// Having undefined at this place means the name is not contained.
|
|
|
|
ASSERT_EQ(kSmiTagSize, 1);
|
|
|
|
__ mov(entity_name, Operand(properties, index, times_half_pointer_size,
|
|
|
|
kElementsStartOffset - kHeapObjectTag));
|
|
|
|
__ cmp(entity_name, masm->isolate()->factory()->undefined_value());
|
|
|
|
__ j(equal, done);
|
|
|
|
|
|
|
|
// Stop if found the property.
|
|
|
|
__ cmp(entity_name, Handle<String>(name));
|
|
|
|
__ j(equal, miss);
|
|
|
|
|
|
|
|
// Check if the entry name is not a symbol.
|
|
|
|
__ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset));
|
|
|
|
__ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset),
|
|
|
|
kIsSymbolMask);
|
|
|
|
__ j(zero, miss);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringDictionaryLookupStub stub(properties,
|
|
|
|
r0,
|
|
|
|
r0,
|
|
|
|
StringDictionaryLookupStub::NEGATIVE_LOOKUP);
|
|
|
|
__ push(Immediate(Handle<Object>(name)));
|
|
|
|
__ push(Immediate(name->Hash()));
|
|
|
|
__ CallStub(&stub);
|
|
|
|
__ test(r0, r0);
|
|
|
|
__ j(not_zero, miss);
|
|
|
|
__ jmp(done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-05 12:30:57 +00:00
|
|
|
// Probe the string dictionary in the |elements| register. Jump to the
|
|
|
|
// |done| label if a property with the given name is found leaving the
|
|
|
|
// index into the dictionary in |r0|. Jump to the |miss| label
|
|
|
|
// otherwise.
|
|
|
|
void StringDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
|
|
|
|
Label* miss,
|
|
|
|
Label* done,
|
|
|
|
Register elements,
|
|
|
|
Register name,
|
|
|
|
Register r0,
|
|
|
|
Register r1) {
|
2011-10-27 07:59:12 +00:00
|
|
|
ASSERT(!elements.is(r0));
|
|
|
|
ASSERT(!elements.is(r1));
|
|
|
|
ASSERT(!name.is(r0));
|
|
|
|
ASSERT(!name.is(r1));
|
|
|
|
|
2011-05-05 12:30:57 +00:00
|
|
|
// Assert that name contains a string.
|
|
|
|
if (FLAG_debug_code) __ AbortIfNotString(name);
|
|
|
|
|
|
|
|
__ mov(r1, FieldOperand(elements, kCapacityOffset));
|
|
|
|
__ shr(r1, kSmiTagSize); // convert smi to int
|
|
|
|
__ dec(r1);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
__ mov(r0, FieldOperand(name, String::kHashFieldOffset));
|
|
|
|
__ shr(r0, String::kHashShift);
|
|
|
|
if (i > 0) {
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(r0, Immediate(StringDictionary::GetProbeOffset(i)));
|
2011-05-05 12:30:57 +00:00
|
|
|
}
|
2011-10-03 11:44:39 +00:00
|
|
|
__ and_(r0, r1);
|
2011-05-05 12:30:57 +00:00
|
|
|
|
|
|
|
// Scale the index by multiplying by the entry size.
|
|
|
|
ASSERT(StringDictionary::kEntrySize == 3);
|
|
|
|
__ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3
|
|
|
|
|
|
|
|
// Check if the key is identical to the name.
|
|
|
|
__ cmp(name, Operand(elements,
|
|
|
|
r0,
|
|
|
|
times_4,
|
|
|
|
kElementsStartOffset - kHeapObjectTag));
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(equal, done);
|
2011-05-05 12:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StringDictionaryLookupStub stub(elements,
|
|
|
|
r1,
|
|
|
|
r0,
|
|
|
|
POSITIVE_LOOKUP);
|
|
|
|
__ push(name);
|
|
|
|
__ mov(r0, FieldOperand(name, String::kHashFieldOffset));
|
|
|
|
__ shr(r0, String::kHashShift);
|
|
|
|
__ push(r0);
|
|
|
|
__ CallStub(&stub);
|
|
|
|
|
2011-10-03 11:44:39 +00:00
|
|
|
__ test(r1, r1);
|
2011-05-05 12:30:57 +00:00
|
|
|
__ j(zero, miss);
|
|
|
|
__ jmp(done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringDictionaryLookupStub::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
|
|
|
// Stack frame on entry:
|
|
|
|
// esp[0 * kPointerSize]: return address.
|
|
|
|
// esp[1 * kPointerSize]: key's hash.
|
|
|
|
// esp[2 * kPointerSize]: key.
|
|
|
|
// Registers:
|
|
|
|
// dictionary_: StringDictionary to probe.
|
|
|
|
// result_: used as scratch.
|
|
|
|
// index_: will hold an index of entry if lookup is successful.
|
|
|
|
// might alias with result_.
|
|
|
|
// Returns:
|
|
|
|
// result_ is zero if lookup failed, non zero otherwise.
|
|
|
|
|
|
|
|
Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
|
|
|
|
|
|
|
|
Register scratch = result_;
|
|
|
|
|
|
|
|
__ mov(scratch, FieldOperand(dictionary_, kCapacityOffset));
|
|
|
|
__ dec(scratch);
|
|
|
|
__ SmiUntag(scratch);
|
|
|
|
__ push(scratch);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// (their names are the null value).
|
|
|
|
for (int i = kInlinedProbes; i < kTotalProbes; i++) {
|
|
|
|
// Compute the masked index: (hash + i + i * i) & mask.
|
|
|
|
__ mov(scratch, Operand(esp, 2 * kPointerSize));
|
|
|
|
if (i > 0) {
|
2011-10-03 11:44:39 +00:00
|
|
|
__ add(scratch, Immediate(StringDictionary::GetProbeOffset(i)));
|
2011-05-05 12:30:57 +00:00
|
|
|
}
|
|
|
|
__ and_(scratch, Operand(esp, 0));
|
|
|
|
|
|
|
|
// Scale the index by multiplying by the entry size.
|
|
|
|
ASSERT(StringDictionary::kEntrySize == 3);
|
|
|
|
__ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3.
|
|
|
|
|
|
|
|
// Having undefined at this place means the name is not contained.
|
|
|
|
ASSERT_EQ(kSmiTagSize, 1);
|
|
|
|
__ mov(scratch, Operand(dictionary_,
|
|
|
|
index_,
|
|
|
|
times_pointer_size,
|
|
|
|
kElementsStartOffset - kHeapObjectTag));
|
|
|
|
__ cmp(scratch, masm->isolate()->factory()->undefined_value());
|
|
|
|
__ j(equal, ¬_in_dictionary);
|
|
|
|
|
|
|
|
// Stop if found the property.
|
|
|
|
__ cmp(scratch, Operand(esp, 3 * kPointerSize));
|
|
|
|
__ j(equal, &in_dictionary);
|
|
|
|
|
|
|
|
if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) {
|
|
|
|
// If we hit a non symbol key during negative lookup
|
|
|
|
// we have to bailout as this key might be equal to the
|
|
|
|
// key we are looking for.
|
|
|
|
|
|
|
|
// Check if the entry name is not a symbol.
|
|
|
|
__ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset));
|
|
|
|
__ test_b(FieldOperand(scratch, Map::kInstanceTypeOffset),
|
|
|
|
kIsSymbolMask);
|
|
|
|
__ j(zero, &maybe_in_dictionary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__ 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) {
|
|
|
|
__ mov(result_, Immediate(0));
|
|
|
|
__ Drop(1);
|
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&in_dictionary);
|
|
|
|
__ mov(result_, Immediate(1));
|
|
|
|
__ Drop(1);
|
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
|
|
|
|
__ bind(¬_in_dictionary);
|
|
|
|
__ mov(result_, Immediate(0));
|
|
|
|
__ Drop(1);
|
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
struct AheadOfTimeWriteBarrierStubList {
|
|
|
|
Register object, value, address;
|
|
|
|
RememberedSetAction action;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct AheadOfTimeWriteBarrierStubList kAheadOfTime[] = {
|
|
|
|
// Used in RegExpExecStub.
|
|
|
|
{ ebx, eax, edi, EMIT_REMEMBERED_SET },
|
|
|
|
// Used in CompileArrayPushCall.
|
|
|
|
{ ebx, ecx, edx, EMIT_REMEMBERED_SET },
|
2011-10-04 11:38:12 +00:00
|
|
|
{ ebx, edi, edx, OMIT_REMEMBERED_SET },
|
2011-09-28 10:32:12 +00:00
|
|
|
// Used in CompileStoreGlobal and CallFunctionStub.
|
2011-09-19 18:36:47 +00:00
|
|
|
{ ebx, ecx, edx, OMIT_REMEMBERED_SET },
|
|
|
|
// Used in StoreStubCompiler::CompileStoreField and
|
|
|
|
// KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField.
|
|
|
|
{ edx, ecx, ebx, EMIT_REMEMBERED_SET },
|
|
|
|
// GenerateStoreField calls the stub with two different permutations of
|
|
|
|
// registers. This is the second.
|
|
|
|
{ ebx, ecx, edx, EMIT_REMEMBERED_SET },
|
2011-10-04 11:38:12 +00:00
|
|
|
// StoreIC::GenerateNormal via GenerateDictionaryStore
|
2011-09-19 18:36:47 +00:00
|
|
|
{ ebx, edi, edx, EMIT_REMEMBERED_SET },
|
|
|
|
// KeyedStoreIC::GenerateGeneric.
|
|
|
|
{ ebx, edx, ecx, EMIT_REMEMBERED_SET},
|
|
|
|
// KeyedStoreStubCompiler::GenerateStoreFastElement.
|
|
|
|
{ edi, edx, ecx, EMIT_REMEMBERED_SET},
|
2011-10-20 12:36:45 +00:00
|
|
|
// ElementsTransitionGenerator::GenerateSmiOnlyToObject
|
|
|
|
// and ElementsTransitionGenerator::GenerateSmiOnlyToDouble
|
|
|
|
// and ElementsTransitionGenerator::GenerateDoubleToObject
|
2011-10-13 10:53:31 +00:00
|
|
|
{ edx, ebx, edi, EMIT_REMEMBERED_SET},
|
2011-10-20 12:36:45 +00:00
|
|
|
// ElementsTransitionGenerator::GenerateDoubleToObject
|
2011-10-13 10:53:31 +00:00
|
|
|
{ eax, edx, esi, EMIT_REMEMBERED_SET},
|
|
|
|
{ edx, eax, edi, EMIT_REMEMBERED_SET},
|
2011-10-31 14:42:06 +00:00
|
|
|
// StoreArrayLiteralElementStub::Generate
|
|
|
|
{ ebx, eax, ecx, EMIT_REMEMBERED_SET},
|
2011-09-19 18:36:47 +00:00
|
|
|
// Null termination.
|
|
|
|
{ no_reg, no_reg, no_reg, EMIT_REMEMBERED_SET}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-27 10:53:22 +00:00
|
|
|
bool RecordWriteStub::IsPregenerated() {
|
2011-09-19 18:36:47 +00:00
|
|
|
for (AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime;
|
|
|
|
!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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime() {
|
|
|
|
StoreBufferOverflowStub stub1(kDontSaveFPRegs);
|
2011-09-28 10:32:12 +00:00
|
|
|
stub1.GetCode()->set_is_pregenerated(true);
|
2011-09-27 10:53:22 +00:00
|
|
|
|
|
|
|
CpuFeatures::TryForceFeatureScope scope(SSE2);
|
|
|
|
if (CpuFeatures::IsSupported(SSE2)) {
|
|
|
|
StoreBufferOverflowStub stub2(kSaveFPRegs);
|
2011-09-28 10:32:12 +00:00
|
|
|
stub2.GetCode()->set_is_pregenerated(true);
|
2011-09-27 10:53:22 +00:00
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RecordWriteStub::GenerateFixedRegStubsAheadOfTime() {
|
|
|
|
for (AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime;
|
|
|
|
!entry->object.is(no_reg);
|
|
|
|
entry++) {
|
|
|
|
RecordWriteStub stub(entry->object,
|
|
|
|
entry->value,
|
|
|
|
entry->address,
|
|
|
|
entry->action,
|
|
|
|
kDontSaveFPRegs);
|
2011-09-28 10:32:12 +00:00
|
|
|
stub.GetCode()->set_is_pregenerated(true);
|
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.
|
|
|
|
__ jmp(&skip_to_incremental_noncompacting, Label::kNear);
|
|
|
|
__ jmp(&skip_to_incremental_compacting, Label::kFar);
|
|
|
|
|
|
|
|
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
|
|
|
} else {
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ 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.
|
|
|
|
masm->set_byte_at(0, kTwoByteNopInstruction);
|
|
|
|
masm->set_byte_at(2, kFiveByteNopInstruction);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
|
|
|
|
regs_.Save(masm);
|
|
|
|
|
|
|
|
if (remembered_set_action_ == EMIT_REMEMBERED_SET) {
|
|
|
|
Label dont_need_remembered_set;
|
|
|
|
|
|
|
|
__ mov(regs_.scratch0(), Operand(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,
|
|
|
|
not_zero,
|
|
|
|
&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(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) {
|
|
|
|
regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_);
|
|
|
|
int argument_count = 3;
|
|
|
|
__ PrepareCallCFunction(argument_count, regs_.scratch0());
|
|
|
|
__ mov(Operand(esp, 0 * kPointerSize), regs_.object());
|
|
|
|
if (mode == INCREMENTAL_COMPACTION) {
|
|
|
|
__ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot.
|
|
|
|
} else {
|
|
|
|
ASSERT(mode == INCREMENTAL);
|
|
|
|
__ mov(regs_.scratch0(), Operand(regs_.address(), 0));
|
|
|
|
__ mov(Operand(esp, 1 * kPointerSize), regs_.scratch0()); // Value.
|
|
|
|
}
|
|
|
|
__ mov(Operand(esp, 2 * kPointerSize),
|
|
|
|
Immediate(ExternalReference::isolate_address()));
|
|
|
|
|
|
|
|
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 object_is_black, need_incremental, need_incremental_pop_object;
|
|
|
|
|
|
|
|
// 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(),
|
|
|
|
&object_is_black,
|
|
|
|
Label::kNear);
|
|
|
|
|
|
|
|
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(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&object_is_black);
|
|
|
|
|
|
|
|
// Get the value from the slot.
|
|
|
|
__ mov(regs_.scratch0(), Operand(regs_.address(), 0));
|
|
|
|
|
|
|
|
if (mode == INCREMENTAL_COMPACTION) {
|
|
|
|
Label ensure_not_white;
|
|
|
|
|
|
|
|
__ CheckPageFlag(regs_.scratch0(), // Contains value.
|
|
|
|
regs_.scratch1(), // Scratch.
|
|
|
|
MemoryChunk::kEvacuationCandidateMask,
|
|
|
|
zero,
|
|
|
|
&ensure_not_white,
|
|
|
|
Label::kNear);
|
|
|
|
|
|
|
|
__ CheckPageFlag(regs_.object(),
|
|
|
|
regs_.scratch1(), // Scratch.
|
|
|
|
MemoryChunk::kSkipEvacuationSlotsRecordingMask,
|
|
|
|
not_zero,
|
|
|
|
&ensure_not_white,
|
|
|
|
Label::kNear);
|
|
|
|
|
|
|
|
__ jmp(&need_incremental);
|
|
|
|
|
|
|
|
__ bind(&ensure_not_white);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need an extra register for this, so we push the object register
|
|
|
|
// temporarily.
|
|
|
|
__ push(regs_.object());
|
|
|
|
__ EnsureNotWhite(regs_.scratch0(), // The value.
|
|
|
|
regs_.scratch1(), // Scratch.
|
|
|
|
regs_.object(), // Scratch.
|
|
|
|
&need_incremental_pop_object,
|
|
|
|
Label::kNear);
|
|
|
|
__ pop(regs_.object());
|
|
|
|
|
|
|
|
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(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&need_incremental_pop_object);
|
|
|
|
__ pop(regs_.object());
|
|
|
|
|
|
|
|
__ bind(&need_incremental);
|
|
|
|
|
|
|
|
// Fall through when we need to inform the incremental marker.
|
|
|
|
}
|
|
|
|
|
2011-10-31 14:42:06 +00:00
|
|
|
|
|
|
|
void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- eax : element value to store
|
|
|
|
// -- ebx : array literal
|
|
|
|
// -- edi : map of array literal
|
|
|
|
// -- ecx : element index as smi
|
|
|
|
// -- edx : array literal index in function
|
|
|
|
// -- esp[0] : return address
|
|
|
|
// -----------------------------------
|
|
|
|
|
|
|
|
Label element_done;
|
|
|
|
Label double_elements;
|
|
|
|
Label smi_element;
|
|
|
|
Label slow_elements;
|
|
|
|
Label slow_elements_from_double;
|
|
|
|
Label fast_elements;
|
|
|
|
|
2011-11-11 14:49:16 +00:00
|
|
|
__ CheckFastElements(edi, &double_elements);
|
2011-10-31 14:42:06 +00:00
|
|
|
|
2011-11-11 14:49:16 +00:00
|
|
|
// FAST_SMI_ONLY_ELEMENTS or FAST_ELEMENTS
|
|
|
|
__ JumpIfSmi(eax, &smi_element);
|
|
|
|
__ CheckFastSmiOnlyElements(edi, &fast_elements, Label::kNear);
|
2011-10-31 14:42:06 +00:00
|
|
|
|
2011-11-11 14:49:16 +00:00
|
|
|
// Store into the array literal requires a elements transition. Call into
|
|
|
|
// the runtime.
|
2011-10-31 14:42:06 +00:00
|
|
|
|
|
|
|
__ bind(&slow_elements);
|
|
|
|
__ pop(edi); // Pop return address and remember to put back later for tail
|
|
|
|
// call.
|
|
|
|
__ push(ebx);
|
|
|
|
__ push(ecx);
|
|
|
|
__ push(eax);
|
|
|
|
__ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
|
|
|
|
__ push(FieldOperand(ebx, JSFunction::kLiteralsOffset));
|
|
|
|
__ push(edx);
|
|
|
|
__ push(edi); // Return return address so that tail call returns to right
|
|
|
|
// place.
|
2011-11-08 13:16:56 +00:00
|
|
|
__ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
|
2011-10-31 14:42:06 +00:00
|
|
|
|
2011-11-11 14:49:16 +00:00
|
|
|
__ bind(&slow_elements_from_double);
|
|
|
|
__ pop(edx);
|
|
|
|
__ jmp(&slow_elements);
|
|
|
|
|
|
|
|
// Array literal has ElementsKind of FAST_ELEMENTS and value is an object.
|
|
|
|
__ bind(&fast_elements);
|
|
|
|
__ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset));
|
|
|
|
__ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size,
|
|
|
|
FixedArrayBase::kHeaderSize));
|
|
|
|
__ mov(Operand(ecx, 0), eax);
|
|
|
|
// Update the write barrier for the array store.
|
|
|
|
__ RecordWrite(ebx, ecx, eax,
|
|
|
|
kDontSaveFPRegs,
|
|
|
|
EMIT_REMEMBERED_SET,
|
|
|
|
OMIT_SMI_CHECK);
|
|
|
|
__ ret(0);
|
2011-10-31 14:42:06 +00:00
|
|
|
|
2011-11-11 14:49:16 +00:00
|
|
|
// Array literal has ElementsKind of FAST_SMI_ONLY_ELEMENTS or
|
|
|
|
// FAST_ELEMENTS, and value is Smi.
|
|
|
|
__ bind(&smi_element);
|
|
|
|
__ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset));
|
|
|
|
__ mov(FieldOperand(ebx, ecx, times_half_pointer_size,
|
|
|
|
FixedArrayBase::kHeaderSize), eax);
|
|
|
|
__ ret(0);
|
2011-10-31 14:42:06 +00:00
|
|
|
|
2011-11-11 14:49:16 +00:00
|
|
|
// Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
|
|
|
|
__ bind(&double_elements);
|
|
|
|
|
|
|
|
__ push(edx);
|
|
|
|
__ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset));
|
|
|
|
__ StoreNumberToDoubleElements(eax,
|
|
|
|
edx,
|
|
|
|
ecx,
|
|
|
|
edi,
|
|
|
|
xmm0,
|
|
|
|
&slow_elements_from_double,
|
|
|
|
false);
|
|
|
|
__ pop(edx);
|
|
|
|
__ ret(0);
|
2011-10-31 14:42:06 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
#undef __
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_TARGET_ARCH_IA32
|