2016-04-18 11:57:06 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
2015-12-02 12:35:12 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
#include "src/code-stub-assembler.h"
|
2015-12-02 12:35:12 +00:00
|
|
|
#include "src/code-factory.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2016-04-18 11:57:06 +00:00
|
|
|
|
|
|
|
using compiler::Node;
|
2015-12-02 12:35:12 +00:00
|
|
|
|
|
|
|
CodeStubAssembler::CodeStubAssembler(Isolate* isolate, Zone* zone,
|
|
|
|
const CallInterfaceDescriptor& descriptor,
|
2016-02-10 16:38:49 +00:00
|
|
|
Code::Flags flags, const char* name,
|
|
|
|
size_t result_size)
|
2016-04-18 11:57:06 +00:00
|
|
|
: compiler::CodeAssembler(isolate, zone, descriptor, flags, name,
|
|
|
|
result_size) {}
|
2015-12-02 12:35:12 +00:00
|
|
|
|
2016-03-01 22:04:55 +00:00
|
|
|
CodeStubAssembler::CodeStubAssembler(Isolate* isolate, Zone* zone,
|
|
|
|
int parameter_count, Code::Flags flags,
|
|
|
|
const char* name)
|
2016-04-18 11:57:06 +00:00
|
|
|
: compiler::CodeAssembler(isolate, zone, parameter_count, flags, name) {}
|
2015-12-02 12:35:12 +00:00
|
|
|
|
2016-04-21 06:45:44 +00:00
|
|
|
Node* CodeStubAssembler::BooleanMapConstant() {
|
|
|
|
return HeapConstant(isolate()->factory()->boolean_map());
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::EmptyStringConstant() {
|
|
|
|
return LoadRoot(Heap::kempty_stringRootIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::HeapNumberMapConstant() {
|
|
|
|
return HeapConstant(isolate()->factory()->heap_number_map());
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::NoContextConstant() {
|
|
|
|
return SmiConstant(Smi::FromInt(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::NullConstant() {
|
|
|
|
return LoadRoot(Heap::kNullValueRootIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::UndefinedConstant() {
|
|
|
|
return LoadRoot(Heap::kUndefinedValueRootIndex);
|
|
|
|
}
|
|
|
|
|
2016-04-28 14:54:39 +00:00
|
|
|
Node* CodeStubAssembler::StaleRegisterConstant() {
|
|
|
|
return LoadRoot(Heap::kStaleRegisterRootIndex);
|
|
|
|
}
|
|
|
|
|
2016-03-30 11:56:31 +00:00
|
|
|
Node* CodeStubAssembler::Float64Round(Node* x) {
|
|
|
|
Node* one = Float64Constant(1.0);
|
|
|
|
Node* one_half = Float64Constant(0.5);
|
|
|
|
|
|
|
|
Variable var_x(this, MachineRepresentation::kFloat64);
|
|
|
|
Label return_x(this);
|
|
|
|
|
|
|
|
// Round up {x} towards Infinity.
|
|
|
|
var_x.Bind(Float64Ceil(x));
|
|
|
|
|
|
|
|
GotoIf(Float64LessThanOrEqual(Float64Sub(var_x.value(), one_half), x),
|
|
|
|
&return_x);
|
|
|
|
var_x.Bind(Float64Sub(var_x.value(), one));
|
|
|
|
Goto(&return_x);
|
|
|
|
|
|
|
|
Bind(&return_x);
|
|
|
|
return var_x.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::Float64Ceil(Node* x) {
|
2016-04-18 11:57:06 +00:00
|
|
|
if (IsFloat64RoundUpSupported()) {
|
|
|
|
return Float64RoundUp(x);
|
2016-03-30 11:56:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Node* one = Float64Constant(1.0);
|
|
|
|
Node* zero = Float64Constant(0.0);
|
|
|
|
Node* two_52 = Float64Constant(4503599627370496.0E0);
|
|
|
|
Node* minus_two_52 = Float64Constant(-4503599627370496.0E0);
|
|
|
|
|
|
|
|
Variable var_x(this, MachineRepresentation::kFloat64);
|
|
|
|
Label return_x(this), return_minus_x(this);
|
|
|
|
var_x.Bind(x);
|
|
|
|
|
|
|
|
// Check if {x} is greater than zero.
|
|
|
|
Label if_xgreaterthanzero(this), if_xnotgreaterthanzero(this);
|
|
|
|
Branch(Float64GreaterThan(x, zero), &if_xgreaterthanzero,
|
|
|
|
&if_xnotgreaterthanzero);
|
|
|
|
|
|
|
|
Bind(&if_xgreaterthanzero);
|
|
|
|
{
|
|
|
|
// Just return {x} unless it's in the range ]0,2^52[.
|
|
|
|
GotoIf(Float64GreaterThanOrEqual(x, two_52), &return_x);
|
|
|
|
|
|
|
|
// Round positive {x} towards Infinity.
|
|
|
|
var_x.Bind(Float64Sub(Float64Add(two_52, x), two_52));
|
|
|
|
GotoUnless(Float64LessThan(var_x.value(), x), &return_x);
|
|
|
|
var_x.Bind(Float64Add(var_x.value(), one));
|
|
|
|
Goto(&return_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&if_xnotgreaterthanzero);
|
|
|
|
{
|
|
|
|
// Just return {x} unless it's in the range ]-2^52,0[
|
|
|
|
GotoIf(Float64LessThanOrEqual(x, minus_two_52), &return_x);
|
|
|
|
GotoUnless(Float64LessThan(x, zero), &return_x);
|
|
|
|
|
|
|
|
// Round negated {x} towards Infinity and return the result negated.
|
|
|
|
Node* minus_x = Float64Neg(x);
|
|
|
|
var_x.Bind(Float64Sub(Float64Add(two_52, minus_x), two_52));
|
|
|
|
GotoUnless(Float64GreaterThan(var_x.value(), minus_x), &return_minus_x);
|
|
|
|
var_x.Bind(Float64Sub(var_x.value(), one));
|
|
|
|
Goto(&return_minus_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&return_minus_x);
|
|
|
|
var_x.Bind(Float64Neg(var_x.value()));
|
|
|
|
Goto(&return_x);
|
|
|
|
|
|
|
|
Bind(&return_x);
|
|
|
|
return var_x.value();
|
|
|
|
}
|
|
|
|
|
2016-03-28 17:30:05 +00:00
|
|
|
Node* CodeStubAssembler::Float64Floor(Node* x) {
|
2016-04-18 11:57:06 +00:00
|
|
|
if (IsFloat64RoundDownSupported()) {
|
|
|
|
return Float64RoundDown(x);
|
2016-03-28 17:30:05 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 11:56:31 +00:00
|
|
|
Node* one = Float64Constant(1.0);
|
|
|
|
Node* zero = Float64Constant(0.0);
|
2016-03-28 17:30:05 +00:00
|
|
|
Node* two_52 = Float64Constant(4503599627370496.0E0);
|
|
|
|
Node* minus_two_52 = Float64Constant(-4503599627370496.0E0);
|
|
|
|
|
|
|
|
Variable var_x(this, MachineRepresentation::kFloat64);
|
2016-03-30 11:56:31 +00:00
|
|
|
Label return_x(this), return_minus_x(this);
|
2016-03-28 17:30:05 +00:00
|
|
|
var_x.Bind(x);
|
|
|
|
|
2016-03-30 11:56:31 +00:00
|
|
|
// Check if {x} is greater than zero.
|
|
|
|
Label if_xgreaterthanzero(this), if_xnotgreaterthanzero(this);
|
|
|
|
Branch(Float64GreaterThan(x, zero), &if_xgreaterthanzero,
|
|
|
|
&if_xnotgreaterthanzero);
|
2016-03-28 17:30:05 +00:00
|
|
|
|
2016-03-30 11:56:31 +00:00
|
|
|
Bind(&if_xgreaterthanzero);
|
2016-03-28 17:30:05 +00:00
|
|
|
{
|
2016-03-30 11:56:31 +00:00
|
|
|
// Just return {x} unless it's in the range ]0,2^52[.
|
|
|
|
GotoIf(Float64GreaterThanOrEqual(x, two_52), &return_x);
|
|
|
|
|
|
|
|
// Round positive {x} towards -Infinity.
|
|
|
|
var_x.Bind(Float64Sub(Float64Add(two_52, x), two_52));
|
|
|
|
GotoUnless(Float64GreaterThan(var_x.value(), x), &return_x);
|
|
|
|
var_x.Bind(Float64Sub(var_x.value(), one));
|
2016-03-28 17:30:05 +00:00
|
|
|
Goto(&return_x);
|
|
|
|
}
|
|
|
|
|
2016-03-30 11:56:31 +00:00
|
|
|
Bind(&if_xnotgreaterthanzero);
|
2016-03-28 17:30:05 +00:00
|
|
|
{
|
2016-03-30 11:56:31 +00:00
|
|
|
// Just return {x} unless it's in the range ]-2^52,0[
|
|
|
|
GotoIf(Float64LessThanOrEqual(x, minus_two_52), &return_x);
|
|
|
|
GotoUnless(Float64LessThan(x, zero), &return_x);
|
|
|
|
|
|
|
|
// Round negated {x} towards -Infinity and return the result negated.
|
|
|
|
Node* minus_x = Float64Neg(x);
|
|
|
|
var_x.Bind(Float64Sub(Float64Add(two_52, minus_x), two_52));
|
|
|
|
GotoUnless(Float64LessThan(var_x.value(), minus_x), &return_minus_x);
|
|
|
|
var_x.Bind(Float64Add(var_x.value(), one));
|
|
|
|
Goto(&return_minus_x);
|
|
|
|
}
|
2016-03-28 17:30:05 +00:00
|
|
|
|
2016-03-30 11:56:31 +00:00
|
|
|
Bind(&return_minus_x);
|
|
|
|
var_x.Bind(Float64Neg(var_x.value()));
|
|
|
|
Goto(&return_x);
|
2016-03-28 17:30:05 +00:00
|
|
|
|
2016-03-30 11:56:31 +00:00
|
|
|
Bind(&return_x);
|
|
|
|
return var_x.value();
|
|
|
|
}
|
2016-03-28 17:30:05 +00:00
|
|
|
|
2016-03-30 11:56:31 +00:00
|
|
|
Node* CodeStubAssembler::Float64Trunc(Node* x) {
|
2016-04-18 11:57:06 +00:00
|
|
|
if (IsFloat64RoundTruncateSupported()) {
|
|
|
|
return Float64RoundTruncate(x);
|
2016-03-30 11:56:31 +00:00
|
|
|
}
|
2016-03-28 17:30:05 +00:00
|
|
|
|
2016-03-30 11:56:31 +00:00
|
|
|
Node* one = Float64Constant(1.0);
|
|
|
|
Node* zero = Float64Constant(0.0);
|
|
|
|
Node* two_52 = Float64Constant(4503599627370496.0E0);
|
|
|
|
Node* minus_two_52 = Float64Constant(-4503599627370496.0E0);
|
2016-03-28 17:30:05 +00:00
|
|
|
|
2016-03-30 11:56:31 +00:00
|
|
|
Variable var_x(this, MachineRepresentation::kFloat64);
|
|
|
|
Label return_x(this), return_minus_x(this);
|
|
|
|
var_x.Bind(x);
|
2016-03-28 17:30:05 +00:00
|
|
|
|
2016-03-30 11:56:31 +00:00
|
|
|
// Check if {x} is greater than 0.
|
|
|
|
Label if_xgreaterthanzero(this), if_xnotgreaterthanzero(this);
|
|
|
|
Branch(Float64GreaterThan(x, zero), &if_xgreaterthanzero,
|
|
|
|
&if_xnotgreaterthanzero);
|
|
|
|
|
|
|
|
Bind(&if_xgreaterthanzero);
|
|
|
|
{
|
2016-04-18 11:57:06 +00:00
|
|
|
if (IsFloat64RoundDownSupported()) {
|
|
|
|
var_x.Bind(Float64RoundDown(x));
|
2016-03-30 11:56:31 +00:00
|
|
|
} else {
|
|
|
|
// Just return {x} unless it's in the range ]0,2^52[.
|
|
|
|
GotoIf(Float64GreaterThanOrEqual(x, two_52), &return_x);
|
|
|
|
|
|
|
|
// Round positive {x} towards -Infinity.
|
|
|
|
var_x.Bind(Float64Sub(Float64Add(two_52, x), two_52));
|
|
|
|
GotoUnless(Float64GreaterThan(var_x.value(), x), &return_x);
|
|
|
|
var_x.Bind(Float64Sub(var_x.value(), one));
|
2016-03-28 17:30:05 +00:00
|
|
|
}
|
2016-03-30 11:56:31 +00:00
|
|
|
Goto(&return_x);
|
2016-03-28 17:30:05 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 11:56:31 +00:00
|
|
|
Bind(&if_xnotgreaterthanzero);
|
|
|
|
{
|
2016-04-18 11:57:06 +00:00
|
|
|
if (IsFloat64RoundUpSupported()) {
|
|
|
|
var_x.Bind(Float64RoundUp(x));
|
2016-03-30 11:56:31 +00:00
|
|
|
Goto(&return_x);
|
|
|
|
} else {
|
|
|
|
// Just return {x} unless its in the range ]-2^52,0[.
|
|
|
|
GotoIf(Float64LessThanOrEqual(x, minus_two_52), &return_x);
|
|
|
|
GotoUnless(Float64LessThan(x, zero), &return_x);
|
|
|
|
|
|
|
|
// Round negated {x} towards -Infinity and return result negated.
|
|
|
|
Node* minus_x = Float64Neg(x);
|
|
|
|
var_x.Bind(Float64Sub(Float64Add(two_52, minus_x), two_52));
|
|
|
|
GotoUnless(Float64GreaterThan(var_x.value(), minus_x), &return_minus_x);
|
|
|
|
var_x.Bind(Float64Sub(var_x.value(), one));
|
|
|
|
Goto(&return_minus_x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&return_minus_x);
|
|
|
|
var_x.Bind(Float64Neg(var_x.value()));
|
|
|
|
Goto(&return_x);
|
|
|
|
|
2016-03-28 17:30:05 +00:00
|
|
|
Bind(&return_x);
|
|
|
|
return var_x.value();
|
|
|
|
}
|
2015-12-02 12:35:12 +00:00
|
|
|
|
2016-04-12 10:29:49 +00:00
|
|
|
Node* CodeStubAssembler::SmiFromWord32(Node* value) {
|
2016-05-03 07:58:58 +00:00
|
|
|
value = ChangeInt32ToIntPtr(value);
|
2016-04-18 11:57:06 +00:00
|
|
|
return WordShl(value, SmiShiftBitsConstant());
|
2016-04-12 10:29:49 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 06:45:44 +00:00
|
|
|
Node* CodeStubAssembler::SmiTag(Node* value) {
|
|
|
|
return WordShl(value, SmiShiftBitsConstant());
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::SmiUntag(Node* value) {
|
|
|
|
return WordSar(value, SmiShiftBitsConstant());
|
|
|
|
}
|
|
|
|
|
2016-03-24 06:05:03 +00:00
|
|
|
Node* CodeStubAssembler::SmiToWord32(Node* value) {
|
2016-04-18 11:57:06 +00:00
|
|
|
Node* result = WordSar(value, SmiShiftBitsConstant());
|
|
|
|
if (Is64()) {
|
|
|
|
result = TruncateInt64ToInt32(result);
|
2016-03-01 22:04:55 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-02 11:46:57 +00:00
|
|
|
Node* CodeStubAssembler::SmiToFloat64(Node* value) {
|
|
|
|
return ChangeInt32ToFloat64(SmiUntag(value));
|
|
|
|
}
|
|
|
|
|
2016-02-25 12:49:02 +00:00
|
|
|
Node* CodeStubAssembler::SmiAdd(Node* a, Node* b) { return IntPtrAdd(a, b); }
|
|
|
|
|
2016-03-22 15:42:24 +00:00
|
|
|
Node* CodeStubAssembler::SmiAddWithOverflow(Node* a, Node* b) {
|
|
|
|
return IntPtrAddWithOverflow(a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::SmiSub(Node* a, Node* b) { return IntPtrSub(a, b); }
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::SmiSubWithOverflow(Node* a, Node* b) {
|
|
|
|
return IntPtrSubWithOverflow(a, b);
|
|
|
|
}
|
|
|
|
|
2016-02-29 12:16:00 +00:00
|
|
|
Node* CodeStubAssembler::SmiEqual(Node* a, Node* b) { return WordEqual(a, b); }
|
|
|
|
|
2016-04-12 10:29:49 +00:00
|
|
|
Node* CodeStubAssembler::SmiAboveOrEqual(Node* a, Node* b) {
|
|
|
|
return UintPtrGreaterThanOrEqual(a, b);
|
|
|
|
}
|
|
|
|
|
2016-03-03 16:38:55 +00:00
|
|
|
Node* CodeStubAssembler::SmiLessThan(Node* a, Node* b) {
|
|
|
|
return IntPtrLessThan(a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::SmiLessThanOrEqual(Node* a, Node* b) {
|
|
|
|
return IntPtrLessThanOrEqual(a, b);
|
|
|
|
}
|
|
|
|
|
2016-03-04 09:38:31 +00:00
|
|
|
Node* CodeStubAssembler::SmiMin(Node* a, Node* b) {
|
|
|
|
// TODO(bmeurer): Consider using Select once available.
|
|
|
|
Variable min(this, MachineRepresentation::kTagged);
|
|
|
|
Label if_a(this), if_b(this), join(this);
|
|
|
|
BranchIfSmiLessThan(a, b, &if_a, &if_b);
|
|
|
|
Bind(&if_a);
|
|
|
|
min.Bind(a);
|
|
|
|
Goto(&join);
|
|
|
|
Bind(&if_b);
|
|
|
|
min.Bind(b);
|
|
|
|
Goto(&join);
|
|
|
|
Bind(&join);
|
|
|
|
return min.value();
|
|
|
|
}
|
|
|
|
|
2016-02-02 09:42:13 +00:00
|
|
|
Node* CodeStubAssembler::WordIsSmi(Node* a) {
|
2016-04-18 11:57:06 +00:00
|
|
|
return WordEqual(WordAnd(a, IntPtrConstant(kSmiTagMask)), IntPtrConstant(0));
|
2015-12-02 12:35:12 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 13:33:02 +00:00
|
|
|
Node* CodeStubAssembler::WordIsPositiveSmi(Node* a) {
|
2016-04-18 11:57:06 +00:00
|
|
|
return WordEqual(WordAnd(a, IntPtrConstant(kSmiTagMask | kSmiSignMask)),
|
|
|
|
IntPtrConstant(0));
|
2016-03-21 13:33:02 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 06:45:44 +00:00
|
|
|
Node* CodeStubAssembler::AllocateRawUnaligned(Node* size_in_bytes,
|
|
|
|
AllocationFlags flags,
|
|
|
|
Node* top_address,
|
|
|
|
Node* limit_address) {
|
|
|
|
Node* top = Load(MachineType::Pointer(), top_address);
|
|
|
|
Node* limit = Load(MachineType::Pointer(), limit_address);
|
|
|
|
|
|
|
|
// If there's not enough space, call the runtime.
|
|
|
|
Variable result(this, MachineRepresentation::kTagged);
|
|
|
|
Label runtime_call(this, Label::kDeferred), no_runtime_call(this);
|
|
|
|
Label merge_runtime(this, &result);
|
|
|
|
|
2016-04-27 17:44:15 +00:00
|
|
|
Node* new_top = IntPtrAdd(top, size_in_bytes);
|
|
|
|
Branch(UintPtrGreaterThanOrEqual(new_top, limit), &runtime_call,
|
2016-04-21 06:45:44 +00:00
|
|
|
&no_runtime_call);
|
|
|
|
|
|
|
|
Bind(&runtime_call);
|
|
|
|
// AllocateInTargetSpace does not use the context.
|
|
|
|
Node* context = IntPtrConstant(0);
|
|
|
|
Node* runtime_flags = SmiTag(Int32Constant(
|
|
|
|
AllocateDoubleAlignFlag::encode(false) |
|
|
|
|
AllocateTargetSpace::encode(flags & kPretenured
|
|
|
|
? AllocationSpace::OLD_SPACE
|
|
|
|
: AllocationSpace::NEW_SPACE)));
|
|
|
|
Node* runtime_result = CallRuntime(Runtime::kAllocateInTargetSpace, context,
|
|
|
|
SmiTag(size_in_bytes), runtime_flags);
|
|
|
|
result.Bind(runtime_result);
|
|
|
|
Goto(&merge_runtime);
|
|
|
|
|
|
|
|
// When there is enough space, return `top' and bump it up.
|
|
|
|
Bind(&no_runtime_call);
|
|
|
|
Node* no_runtime_result = top;
|
|
|
|
StoreNoWriteBarrier(MachineType::PointerRepresentation(), top_address,
|
2016-04-27 17:44:15 +00:00
|
|
|
new_top);
|
2016-04-21 11:26:20 +00:00
|
|
|
no_runtime_result = BitcastWordToTagged(
|
|
|
|
IntPtrAdd(no_runtime_result, IntPtrConstant(kHeapObjectTag)));
|
2016-04-21 06:45:44 +00:00
|
|
|
result.Bind(no_runtime_result);
|
|
|
|
Goto(&merge_runtime);
|
|
|
|
|
|
|
|
Bind(&merge_runtime);
|
|
|
|
return result.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::AllocateRawAligned(Node* size_in_bytes,
|
|
|
|
AllocationFlags flags,
|
|
|
|
Node* top_address,
|
|
|
|
Node* limit_address) {
|
|
|
|
Node* top = Load(MachineType::Pointer(), top_address);
|
|
|
|
Node* limit = Load(MachineType::Pointer(), limit_address);
|
|
|
|
Variable adjusted_size(this, MachineType::PointerRepresentation());
|
|
|
|
adjusted_size.Bind(size_in_bytes);
|
|
|
|
if (flags & kDoubleAlignment) {
|
|
|
|
// TODO(epertoso): Simd128 alignment.
|
|
|
|
Label aligned(this), not_aligned(this), merge(this, &adjusted_size);
|
|
|
|
Branch(WordAnd(top, IntPtrConstant(kDoubleAlignmentMask)), ¬_aligned,
|
|
|
|
&aligned);
|
|
|
|
|
|
|
|
Bind(¬_aligned);
|
|
|
|
Node* not_aligned_size =
|
|
|
|
IntPtrAdd(size_in_bytes, IntPtrConstant(kPointerSize));
|
|
|
|
adjusted_size.Bind(not_aligned_size);
|
|
|
|
Goto(&merge);
|
|
|
|
|
|
|
|
Bind(&aligned);
|
|
|
|
Goto(&merge);
|
|
|
|
|
|
|
|
Bind(&merge);
|
|
|
|
}
|
|
|
|
|
|
|
|
Variable address(this, MachineRepresentation::kTagged);
|
|
|
|
address.Bind(AllocateRawUnaligned(adjusted_size.value(), kNone, top, limit));
|
|
|
|
|
|
|
|
Label needs_filler(this), doesnt_need_filler(this),
|
|
|
|
merge_address(this, &address);
|
|
|
|
Branch(IntPtrEqual(adjusted_size.value(), size_in_bytes), &doesnt_need_filler,
|
|
|
|
&needs_filler);
|
|
|
|
|
|
|
|
Bind(&needs_filler);
|
|
|
|
// Store a filler and increase the address by kPointerSize.
|
|
|
|
// TODO(epertoso): this code assumes that we only align to kDoubleSize. Change
|
|
|
|
// it when Simd128 alignment is supported.
|
|
|
|
StoreNoWriteBarrier(MachineType::PointerRepresentation(), top,
|
|
|
|
LoadRoot(Heap::kOnePointerFillerMapRootIndex));
|
2016-04-21 11:26:20 +00:00
|
|
|
address.Bind(BitcastWordToTagged(
|
|
|
|
IntPtrAdd(address.value(), IntPtrConstant(kPointerSize))));
|
2016-04-21 06:45:44 +00:00
|
|
|
Goto(&merge_address);
|
|
|
|
|
|
|
|
Bind(&doesnt_need_filler);
|
|
|
|
Goto(&merge_address);
|
|
|
|
|
|
|
|
Bind(&merge_address);
|
|
|
|
// Update the top.
|
|
|
|
StoreNoWriteBarrier(MachineType::PointerRepresentation(), top_address,
|
|
|
|
IntPtrAdd(top, adjusted_size.value()));
|
|
|
|
return address.value();
|
|
|
|
}
|
|
|
|
|
2016-04-22 09:17:58 +00:00
|
|
|
Node* CodeStubAssembler::Allocate(Node* size_in_bytes, AllocationFlags flags) {
|
2016-04-21 06:45:44 +00:00
|
|
|
bool const new_space = !(flags & kPretenured);
|
|
|
|
Node* top_address = ExternalConstant(
|
|
|
|
new_space
|
|
|
|
? ExternalReference::new_space_allocation_top_address(isolate())
|
|
|
|
: ExternalReference::old_space_allocation_top_address(isolate()));
|
|
|
|
Node* limit_address = ExternalConstant(
|
|
|
|
new_space
|
|
|
|
? ExternalReference::new_space_allocation_limit_address(isolate())
|
|
|
|
: ExternalReference::old_space_allocation_limit_address(isolate()));
|
|
|
|
|
|
|
|
#ifdef V8_HOST_ARCH_32_BIT
|
|
|
|
if (flags & kDoubleAlignment) {
|
2016-04-22 09:17:58 +00:00
|
|
|
return AllocateRawAligned(size_in_bytes, flags, top_address, limit_address);
|
2016-04-21 06:45:44 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-04-22 09:17:58 +00:00
|
|
|
return AllocateRawUnaligned(size_in_bytes, flags, top_address, limit_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::Allocate(int size_in_bytes, AllocationFlags flags) {
|
|
|
|
return CodeStubAssembler::Allocate(IntPtrConstant(size_in_bytes), flags);
|
2016-04-21 06:45:44 +00:00
|
|
|
}
|
|
|
|
|
2016-04-29 14:19:22 +00:00
|
|
|
Node* CodeStubAssembler::InnerAllocate(Node* previous, Node* offset) {
|
|
|
|
return BitcastWordToTagged(IntPtrAdd(previous, offset));
|
|
|
|
}
|
|
|
|
|
2016-04-21 06:45:44 +00:00
|
|
|
Node* CodeStubAssembler::InnerAllocate(Node* previous, int offset) {
|
2016-04-29 14:19:22 +00:00
|
|
|
return InnerAllocate(previous, IntPtrConstant(offset));
|
2016-04-21 06:45:44 +00:00
|
|
|
}
|
|
|
|
|
2016-03-17 11:04:51 +00:00
|
|
|
Node* CodeStubAssembler::LoadBufferObject(Node* buffer, int offset,
|
|
|
|
MachineType rep) {
|
2016-04-18 11:57:06 +00:00
|
|
|
return Load(rep, buffer, IntPtrConstant(offset));
|
2015-12-02 12:35:12 +00:00
|
|
|
}
|
|
|
|
|
2016-03-17 11:04:51 +00:00
|
|
|
Node* CodeStubAssembler::LoadObjectField(Node* object, int offset,
|
|
|
|
MachineType rep) {
|
2016-04-18 11:57:06 +00:00
|
|
|
return Load(rep, object, IntPtrConstant(offset - kHeapObjectTag));
|
2016-04-12 10:29:49 +00:00
|
|
|
}
|
|
|
|
|
2016-03-01 22:04:55 +00:00
|
|
|
Node* CodeStubAssembler::LoadHeapNumberValue(Node* object) {
|
2016-03-02 11:46:57 +00:00
|
|
|
return Load(MachineType::Float64(), object,
|
|
|
|
IntPtrConstant(HeapNumber::kValueOffset - kHeapObjectTag));
|
|
|
|
}
|
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Node* CodeStubAssembler::LoadMap(Node* object) {
|
|
|
|
return LoadObjectField(object, HeapObject::kMapOffset);
|
2016-03-22 13:25:05 +00:00
|
|
|
}
|
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Node* CodeStubAssembler::LoadInstanceType(Node* object) {
|
|
|
|
return LoadMapInstanceType(LoadMap(object));
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::LoadElements(Node* object) {
|
|
|
|
return LoadObjectField(object, JSObject::kElementsOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::LoadFixedArrayBaseLength(Node* array) {
|
|
|
|
return LoadObjectField(array, FixedArrayBase::kLengthOffset);
|
2016-03-23 13:44:32 +00:00
|
|
|
}
|
|
|
|
|
2016-03-16 09:36:52 +00:00
|
|
|
Node* CodeStubAssembler::LoadMapBitField(Node* map) {
|
|
|
|
return Load(MachineType::Uint8(), map,
|
|
|
|
IntPtrConstant(Map::kBitFieldOffset - kHeapObjectTag));
|
|
|
|
}
|
|
|
|
|
2016-03-31 07:53:10 +00:00
|
|
|
Node* CodeStubAssembler::LoadMapBitField2(Node* map) {
|
|
|
|
return Load(MachineType::Uint8(), map,
|
|
|
|
IntPtrConstant(Map::kBitField2Offset - kHeapObjectTag));
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::LoadMapBitField3(Node* map) {
|
|
|
|
return Load(MachineType::Uint32(), map,
|
|
|
|
IntPtrConstant(Map::kBitField3Offset - kHeapObjectTag));
|
|
|
|
}
|
|
|
|
|
2016-03-02 11:46:57 +00:00
|
|
|
Node* CodeStubAssembler::LoadMapInstanceType(Node* map) {
|
|
|
|
return Load(MachineType::Uint8(), map,
|
|
|
|
IntPtrConstant(Map::kInstanceTypeOffset - kHeapObjectTag));
|
2016-03-01 22:04:55 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 07:53:10 +00:00
|
|
|
Node* CodeStubAssembler::LoadMapDescriptors(Node* map) {
|
|
|
|
return LoadObjectField(map, Map::kDescriptorsOffset);
|
|
|
|
}
|
|
|
|
|
2016-05-03 11:11:27 +00:00
|
|
|
Node* CodeStubAssembler::LoadMapPrototype(Node* map) {
|
|
|
|
return LoadObjectField(map, Map::kPrototypeOffset);
|
|
|
|
}
|
|
|
|
|
2016-03-31 07:53:10 +00:00
|
|
|
Node* CodeStubAssembler::LoadNameHash(Node* name) {
|
|
|
|
return Load(MachineType::Uint32(), name,
|
|
|
|
IntPtrConstant(Name::kHashFieldOffset - kHeapObjectTag));
|
|
|
|
}
|
|
|
|
|
2016-04-22 09:17:58 +00:00
|
|
|
Node* CodeStubAssembler::AllocateUninitializedFixedArray(Node* length) {
|
|
|
|
Node* header_size = IntPtrConstant(FixedArray::kHeaderSize);
|
|
|
|
Node* data_size = WordShl(length, IntPtrConstant(kPointerSizeLog2));
|
|
|
|
Node* total_size = IntPtrAdd(data_size, header_size);
|
|
|
|
|
|
|
|
Node* result = Allocate(total_size, kNone);
|
|
|
|
StoreMapNoWriteBarrier(result, LoadRoot(Heap::kFixedArrayMapRootIndex));
|
|
|
|
StoreObjectFieldNoWriteBarrier(result, FixedArray::kLengthOffset,
|
|
|
|
SmiTag(length));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-31 07:53:10 +00:00
|
|
|
Node* CodeStubAssembler::LoadFixedArrayElementInt32Index(
|
2016-04-12 10:29:49 +00:00
|
|
|
Node* object, Node* index, int additional_offset) {
|
2016-03-31 07:53:10 +00:00
|
|
|
Node* header_size = IntPtrConstant(additional_offset +
|
|
|
|
FixedArray::kHeaderSize - kHeapObjectTag);
|
2016-05-03 07:58:58 +00:00
|
|
|
index = ChangeInt32ToIntPtr(index);
|
2016-04-12 10:29:49 +00:00
|
|
|
Node* scaled_index = WordShl(index, IntPtrConstant(kPointerSizeLog2));
|
2016-03-31 07:53:10 +00:00
|
|
|
Node* offset = IntPtrAdd(scaled_index, header_size);
|
|
|
|
return Load(MachineType::AnyTagged(), object, offset);
|
|
|
|
}
|
|
|
|
|
2016-04-18 08:11:44 +00:00
|
|
|
Node* CodeStubAssembler::LoadMapInstanceSize(Node* map) {
|
|
|
|
return Load(MachineType::Uint8(), map,
|
|
|
|
IntPtrConstant(Map::kInstanceSizeOffset - kHeapObjectTag));
|
|
|
|
}
|
|
|
|
|
2016-02-02 09:42:13 +00:00
|
|
|
Node* CodeStubAssembler::LoadFixedArrayElementSmiIndex(Node* object,
|
|
|
|
Node* smi_index,
|
|
|
|
int additional_offset) {
|
2016-03-01 07:08:20 +00:00
|
|
|
int const kSmiShiftBits = kSmiShiftSize + kSmiTagSize;
|
|
|
|
Node* header_size = IntPtrConstant(additional_offset +
|
|
|
|
FixedArray::kHeaderSize - kHeapObjectTag);
|
2016-02-02 09:42:13 +00:00
|
|
|
Node* scaled_index =
|
2016-03-01 07:08:20 +00:00
|
|
|
(kSmiShiftBits > kPointerSizeLog2)
|
|
|
|
? WordSar(smi_index, IntPtrConstant(kSmiShiftBits - kPointerSizeLog2))
|
|
|
|
: WordShl(smi_index,
|
|
|
|
IntPtrConstant(kPointerSizeLog2 - kSmiShiftBits));
|
|
|
|
Node* offset = IntPtrAdd(scaled_index, header_size);
|
|
|
|
return Load(MachineType::AnyTagged(), object, offset);
|
2016-02-02 09:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::LoadFixedArrayElementConstantIndex(Node* object,
|
|
|
|
int index) {
|
2016-03-01 07:08:20 +00:00
|
|
|
Node* offset = IntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag +
|
|
|
|
index * kPointerSize);
|
2016-04-18 11:57:06 +00:00
|
|
|
return Load(MachineType::AnyTagged(), object, offset);
|
|
|
|
}
|
|
|
|
|
2016-05-03 07:58:58 +00:00
|
|
|
Node* CodeStubAssembler::LoadNativeContext(Node* context) {
|
|
|
|
return LoadFixedArrayElementConstantIndex(context,
|
|
|
|
Context::NATIVE_CONTEXT_INDEX);
|
|
|
|
}
|
|
|
|
|
2016-05-03 21:34:19 +00:00
|
|
|
Node* CodeStubAssembler::LoadJSArrayElementsMap(ElementsKind kind,
|
|
|
|
Node* native_context) {
|
|
|
|
return LoadFixedArrayElementConstantIndex(native_context,
|
|
|
|
Context::ArrayMapIndex(kind));
|
|
|
|
}
|
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Node* CodeStubAssembler::StoreHeapNumberValue(Node* object, Node* value) {
|
|
|
|
return StoreNoWriteBarrier(
|
|
|
|
MachineRepresentation::kFloat64, object,
|
|
|
|
IntPtrConstant(HeapNumber::kValueOffset - kHeapObjectTag), value);
|
|
|
|
}
|
|
|
|
|
2016-04-22 09:17:58 +00:00
|
|
|
Node* CodeStubAssembler::StoreObjectField(
|
|
|
|
Node* object, int offset, Node* value) {
|
|
|
|
return Store(MachineRepresentation::kTagged, object,
|
|
|
|
IntPtrConstant(offset - kHeapObjectTag), value);
|
|
|
|
}
|
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Node* CodeStubAssembler::StoreObjectFieldNoWriteBarrier(
|
|
|
|
Node* object, int offset, Node* value, MachineRepresentation rep) {
|
|
|
|
return StoreNoWriteBarrier(rep, object,
|
|
|
|
IntPtrConstant(offset - kHeapObjectTag), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::StoreMapNoWriteBarrier(Node* object, Node* map) {
|
|
|
|
return StoreNoWriteBarrier(
|
|
|
|
MachineRepresentation::kTagged, object,
|
|
|
|
IntPtrConstant(HeapNumber::kMapOffset - kHeapObjectTag), map);
|
2016-02-02 09:42:13 +00:00
|
|
|
}
|
|
|
|
|
2016-03-01 13:55:48 +00:00
|
|
|
Node* CodeStubAssembler::StoreFixedArrayElementNoWriteBarrier(Node* object,
|
|
|
|
Node* index,
|
|
|
|
Node* value) {
|
2016-05-03 07:58:58 +00:00
|
|
|
index = ChangeInt32ToIntPtr(index);
|
2016-03-01 13:55:48 +00:00
|
|
|
Node* offset =
|
|
|
|
IntPtrAdd(WordShl(index, IntPtrConstant(kPointerSizeLog2)),
|
|
|
|
IntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag));
|
|
|
|
return StoreNoWriteBarrier(MachineRepresentation::kTagged, object, offset,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
2016-04-12 10:29:49 +00:00
|
|
|
Node* CodeStubAssembler::StoreFixedArrayElementInt32Index(Node* object,
|
|
|
|
Node* index,
|
|
|
|
Node* value) {
|
2016-05-03 07:58:58 +00:00
|
|
|
index = ChangeInt32ToIntPtr(index);
|
2016-04-12 10:29:49 +00:00
|
|
|
Node* offset =
|
|
|
|
IntPtrAdd(WordShl(index, IntPtrConstant(kPointerSizeLog2)),
|
|
|
|
IntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag));
|
|
|
|
return Store(MachineRepresentation::kTagged, object, offset, value);
|
|
|
|
}
|
|
|
|
|
2016-05-03 07:58:58 +00:00
|
|
|
Node* CodeStubAssembler::StoreFixedDoubleArrayElementInt32Index(Node* object,
|
|
|
|
Node* index,
|
|
|
|
Node* value) {
|
|
|
|
index = ChangeInt32ToIntPtr(index);
|
|
|
|
Node* offset =
|
|
|
|
IntPtrAdd(WordShl(index, IntPtrConstant(kPointerSizeLog2)),
|
|
|
|
IntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag));
|
|
|
|
return StoreNoWriteBarrier(MachineRepresentation::kFloat64, object, offset,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::StoreFixedArrayElementInt32Index(Node* object,
|
|
|
|
int index,
|
|
|
|
Node* value) {
|
|
|
|
Node* offset = IntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag +
|
|
|
|
index * kPointerSize);
|
|
|
|
return Store(MachineRepresentation::kTagged, object, offset, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::StoreFixedArrayElementNoWriteBarrier(Node* object,
|
|
|
|
int index,
|
|
|
|
Node* value) {
|
|
|
|
Node* offset = IntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag +
|
|
|
|
index * kPointerSize);
|
|
|
|
return StoreNoWriteBarrier(MachineRepresentation::kTagged, object, offset,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::StoreFixedDoubleArrayElementInt32Index(Node* object,
|
|
|
|
int index,
|
|
|
|
Node* value) {
|
|
|
|
Node* offset = IntPtrConstant(FixedDoubleArray::kHeaderSize - kHeapObjectTag +
|
|
|
|
index * kDoubleSize);
|
|
|
|
return StoreNoWriteBarrier(MachineRepresentation::kFloat64, object, offset,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
2016-03-23 06:14:37 +00:00
|
|
|
Node* CodeStubAssembler::AllocateHeapNumber() {
|
|
|
|
Node* result = Allocate(HeapNumber::kSize, kNone);
|
|
|
|
StoreMapNoWriteBarrier(result, HeapNumberMapConstant());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::AllocateHeapNumberWithValue(Node* value) {
|
|
|
|
Node* result = AllocateHeapNumber();
|
|
|
|
StoreHeapNumberValue(result, value);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-04-12 10:29:49 +00:00
|
|
|
Node* CodeStubAssembler::AllocateSeqOneByteString(int length) {
|
|
|
|
Node* result = Allocate(SeqOneByteString::SizeFor(length));
|
|
|
|
StoreMapNoWriteBarrier(result, LoadRoot(Heap::kOneByteStringMapRootIndex));
|
|
|
|
StoreObjectFieldNoWriteBarrier(result, SeqOneByteString::kLengthOffset,
|
|
|
|
SmiConstant(Smi::FromInt(length)));
|
2016-04-22 18:40:10 +00:00
|
|
|
StoreObjectFieldNoWriteBarrier(result, SeqOneByteString::kHashFieldSlot,
|
2016-04-12 10:29:49 +00:00
|
|
|
IntPtrConstant(String::kEmptyHashField));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::AllocateSeqTwoByteString(int length) {
|
|
|
|
Node* result = Allocate(SeqTwoByteString::SizeFor(length));
|
|
|
|
StoreMapNoWriteBarrier(result, LoadRoot(Heap::kStringMapRootIndex));
|
|
|
|
StoreObjectFieldNoWriteBarrier(result, SeqTwoByteString::kLengthOffset,
|
|
|
|
SmiConstant(Smi::FromInt(length)));
|
2016-04-22 18:40:10 +00:00
|
|
|
StoreObjectFieldNoWriteBarrier(result, SeqTwoByteString::kHashFieldSlot,
|
2016-04-12 10:29:49 +00:00
|
|
|
IntPtrConstant(String::kEmptyHashField));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-05-03 21:34:19 +00:00
|
|
|
Node* CodeStubAssembler::AllocateJSArray(ElementsKind kind, Node* array_map,
|
|
|
|
int capacity, int length,
|
2016-05-03 07:58:58 +00:00
|
|
|
compiler::Node* allocation_site) {
|
|
|
|
bool is_double = IsFastDoubleElementsKind(kind);
|
|
|
|
int element_size = is_double ? kDoubleSize : kPointerSize;
|
|
|
|
int total_size =
|
|
|
|
JSArray::kSize + FixedArray::kHeaderSize + element_size * capacity;
|
|
|
|
int elements_offset = JSArray::kSize;
|
|
|
|
|
|
|
|
if (allocation_site != nullptr) {
|
|
|
|
total_size += AllocationMemento::kSize;
|
|
|
|
elements_offset += AllocationMemento::kSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate both array and elements object, and initialize the JSArray.
|
|
|
|
Heap* heap = isolate()->heap();
|
|
|
|
Node* array = Allocate(total_size);
|
|
|
|
StoreMapNoWriteBarrier(array, array_map);
|
|
|
|
Node* empty_properties =
|
|
|
|
HeapConstant(Handle<HeapObject>(heap->empty_fixed_array()));
|
|
|
|
StoreObjectFieldNoWriteBarrier(array, JSArray::kPropertiesOffset,
|
|
|
|
empty_properties);
|
|
|
|
StoreObjectFieldNoWriteBarrier(array, JSArray::kLengthOffset,
|
|
|
|
SmiConstant(Smi::FromInt(length)));
|
|
|
|
|
|
|
|
if (allocation_site != nullptr) {
|
|
|
|
InitializeAllocationMemento(array, JSArray::kSize, allocation_site);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup elements object.
|
|
|
|
Node* elements = InnerAllocate(array, elements_offset);
|
|
|
|
StoreObjectFieldNoWriteBarrier(array, JSArray::kElementsOffset, elements);
|
|
|
|
Handle<Map> elements_map(is_double ? heap->fixed_double_array_map()
|
|
|
|
: heap->fixed_array_map());
|
|
|
|
StoreMapNoWriteBarrier(elements, HeapConstant(elements_map));
|
|
|
|
StoreObjectFieldNoWriteBarrier(elements, FixedArray::kLengthOffset,
|
|
|
|
SmiConstant(Smi::FromInt(capacity)));
|
|
|
|
|
|
|
|
Node* double_hole = Float64Constant(bit_cast<double>(kHoleNanInt64));
|
|
|
|
Node* hole = HeapConstant(Handle<HeapObject>(heap->the_hole_value()));
|
|
|
|
if (capacity <= kElementLoopUnrollThreshold) {
|
|
|
|
for (int i = 0; i < capacity; ++i) {
|
|
|
|
if (is_double) {
|
|
|
|
StoreFixedDoubleArrayElementInt32Index(elements, i, double_hole);
|
|
|
|
} else {
|
|
|
|
StoreFixedArrayElementNoWriteBarrier(elements, i, hole);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// TODO(danno): Add a loop for initialization
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeStubAssembler::InitializeAllocationMemento(
|
|
|
|
compiler::Node* base_allocation, int base_allocation_size,
|
|
|
|
compiler::Node* allocation_site) {
|
|
|
|
StoreObjectFieldNoWriteBarrier(
|
|
|
|
base_allocation, AllocationMemento::kMapOffset + base_allocation_size,
|
|
|
|
HeapConstant(Handle<Map>(isolate()->heap()->allocation_memento_map())));
|
|
|
|
StoreObjectFieldNoWriteBarrier(
|
|
|
|
base_allocation,
|
|
|
|
AllocationMemento::kAllocationSiteOffset + base_allocation_size,
|
|
|
|
allocation_site);
|
|
|
|
if (FLAG_allocation_site_pretenuring) {
|
|
|
|
Node* count = LoadObjectField(allocation_site,
|
|
|
|
AllocationSite::kPretenureCreateCountOffset);
|
|
|
|
Node* incremented_count = IntPtrAdd(count, SmiConstant(Smi::FromInt(1)));
|
|
|
|
StoreObjectFieldNoWriteBarrier(allocation_site,
|
|
|
|
AllocationSite::kPretenureCreateCountOffset,
|
|
|
|
incremented_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Node* CodeStubAssembler::TruncateTaggedToFloat64(Node* context, Node* value) {
|
|
|
|
// We might need to loop once due to ToNumber conversion.
|
|
|
|
Variable var_value(this, MachineRepresentation::kTagged),
|
|
|
|
var_result(this, MachineRepresentation::kFloat64);
|
|
|
|
Label loop(this, &var_value), done_loop(this, &var_result);
|
|
|
|
var_value.Bind(value);
|
|
|
|
Goto(&loop);
|
|
|
|
Bind(&loop);
|
|
|
|
{
|
|
|
|
// Load the current {value}.
|
|
|
|
value = var_value.value();
|
2016-02-10 16:38:49 +00:00
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
// Check if the {value} is a Smi or a HeapObject.
|
|
|
|
Label if_valueissmi(this), if_valueisnotsmi(this);
|
|
|
|
Branch(WordIsSmi(value), &if_valueissmi, &if_valueisnotsmi);
|
2016-02-10 16:38:49 +00:00
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Bind(&if_valueissmi);
|
|
|
|
{
|
|
|
|
// Convert the Smi {value}.
|
|
|
|
var_result.Bind(SmiToFloat64(value));
|
|
|
|
Goto(&done_loop);
|
|
|
|
}
|
2016-02-10 16:38:49 +00:00
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Bind(&if_valueisnotsmi);
|
|
|
|
{
|
|
|
|
// Check if {value} is a HeapNumber.
|
|
|
|
Label if_valueisheapnumber(this),
|
|
|
|
if_valueisnotheapnumber(this, Label::kDeferred);
|
|
|
|
Branch(WordEqual(LoadMap(value), HeapNumberMapConstant()),
|
|
|
|
&if_valueisheapnumber, &if_valueisnotheapnumber);
|
2016-02-10 16:38:49 +00:00
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Bind(&if_valueisheapnumber);
|
|
|
|
{
|
|
|
|
// Load the floating point value.
|
|
|
|
var_result.Bind(LoadHeapNumberValue(value));
|
|
|
|
Goto(&done_loop);
|
|
|
|
}
|
2016-02-10 16:38:49 +00:00
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Bind(&if_valueisnotheapnumber);
|
|
|
|
{
|
|
|
|
// Convert the {value} to a Number first.
|
|
|
|
Callable callable = CodeFactory::NonNumberToNumber(isolate());
|
|
|
|
var_value.Bind(CallStub(callable, context, value));
|
|
|
|
Goto(&loop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Bind(&done_loop);
|
|
|
|
return var_result.value();
|
2016-02-10 16:38:49 +00:00
|
|
|
}
|
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Node* CodeStubAssembler::TruncateTaggedToWord32(Node* context, Node* value) {
|
|
|
|
// We might need to loop once due to ToNumber conversion.
|
|
|
|
Variable var_value(this, MachineRepresentation::kTagged),
|
|
|
|
var_result(this, MachineRepresentation::kWord32);
|
|
|
|
Label loop(this, &var_value), done_loop(this, &var_result);
|
|
|
|
var_value.Bind(value);
|
|
|
|
Goto(&loop);
|
|
|
|
Bind(&loop);
|
|
|
|
{
|
|
|
|
// Load the current {value}.
|
|
|
|
value = var_value.value();
|
2016-02-10 16:38:49 +00:00
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
// Check if the {value} is a Smi or a HeapObject.
|
|
|
|
Label if_valueissmi(this), if_valueisnotsmi(this);
|
|
|
|
Branch(WordIsSmi(value), &if_valueissmi, &if_valueisnotsmi);
|
2016-03-16 09:36:52 +00:00
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Bind(&if_valueissmi);
|
|
|
|
{
|
|
|
|
// Convert the Smi {value}.
|
|
|
|
var_result.Bind(SmiToWord32(value));
|
|
|
|
Goto(&done_loop);
|
|
|
|
}
|
2016-03-22 13:25:05 +00:00
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Bind(&if_valueisnotsmi);
|
|
|
|
{
|
|
|
|
// Check if {value} is a HeapNumber.
|
|
|
|
Label if_valueisheapnumber(this),
|
|
|
|
if_valueisnotheapnumber(this, Label::kDeferred);
|
|
|
|
Branch(WordEqual(LoadMap(value), HeapNumberMapConstant()),
|
|
|
|
&if_valueisheapnumber, &if_valueisnotheapnumber);
|
2016-03-01 22:04:55 +00:00
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Bind(&if_valueisheapnumber);
|
|
|
|
{
|
|
|
|
// Truncate the floating point value.
|
|
|
|
var_result.Bind(TruncateHeapNumberValueToWord32(value));
|
|
|
|
Goto(&done_loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&if_valueisnotheapnumber);
|
|
|
|
{
|
|
|
|
// Convert the {value} to a Number first.
|
|
|
|
Callable callable = CodeFactory::NonNumberToNumber(isolate());
|
|
|
|
var_value.Bind(CallStub(callable, context, value));
|
|
|
|
Goto(&loop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Bind(&done_loop);
|
|
|
|
return var_result.value();
|
2016-03-31 07:53:10 +00:00
|
|
|
}
|
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Node* CodeStubAssembler::TruncateHeapNumberValueToWord32(Node* object) {
|
|
|
|
Node* value = LoadHeapNumberValue(object);
|
2016-04-24 11:39:31 +00:00
|
|
|
return TruncateFloat64ToWord32(value);
|
2016-03-01 22:04:55 +00:00
|
|
|
}
|
|
|
|
|
2016-03-28 17:30:05 +00:00
|
|
|
Node* CodeStubAssembler::ChangeFloat64ToTagged(Node* value) {
|
2016-04-24 11:39:31 +00:00
|
|
|
Node* value32 = RoundFloat64ToInt32(value);
|
2016-03-28 17:30:05 +00:00
|
|
|
Node* value64 = ChangeInt32ToFloat64(value32);
|
|
|
|
|
|
|
|
Label if_valueisint32(this), if_valueisheapnumber(this), if_join(this);
|
|
|
|
|
|
|
|
Label if_valueisequal(this), if_valueisnotequal(this);
|
|
|
|
Branch(Float64Equal(value, value64), &if_valueisequal, &if_valueisnotequal);
|
|
|
|
Bind(&if_valueisequal);
|
|
|
|
{
|
2016-04-24 11:39:31 +00:00
|
|
|
GotoUnless(Word32Equal(value32, Int32Constant(0)), &if_valueisint32);
|
2016-04-18 11:57:06 +00:00
|
|
|
BranchIfInt32LessThan(Float64ExtractHighWord32(value), Int32Constant(0),
|
|
|
|
&if_valueisheapnumber, &if_valueisint32);
|
2016-03-28 17:30:05 +00:00
|
|
|
}
|
|
|
|
Bind(&if_valueisnotequal);
|
|
|
|
Goto(&if_valueisheapnumber);
|
|
|
|
|
|
|
|
Variable var_result(this, MachineRepresentation::kTagged);
|
|
|
|
Bind(&if_valueisint32);
|
|
|
|
{
|
2016-04-18 11:57:06 +00:00
|
|
|
if (Is64()) {
|
2016-03-28 17:30:05 +00:00
|
|
|
Node* result = SmiTag(ChangeInt32ToInt64(value32));
|
|
|
|
var_result.Bind(result);
|
|
|
|
Goto(&if_join);
|
|
|
|
} else {
|
|
|
|
Node* pair = Int32AddWithOverflow(value32, value32);
|
|
|
|
Node* overflow = Projection(1, pair);
|
2016-03-31 17:23:10 +00:00
|
|
|
Label if_overflow(this, Label::kDeferred), if_notoverflow(this);
|
2016-03-28 17:30:05 +00:00
|
|
|
Branch(overflow, &if_overflow, &if_notoverflow);
|
|
|
|
Bind(&if_overflow);
|
|
|
|
Goto(&if_valueisheapnumber);
|
|
|
|
Bind(&if_notoverflow);
|
|
|
|
{
|
|
|
|
Node* result = Projection(0, pair);
|
|
|
|
var_result.Bind(result);
|
|
|
|
Goto(&if_join);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Bind(&if_valueisheapnumber);
|
|
|
|
{
|
|
|
|
Node* result = AllocateHeapNumberWithValue(value);
|
|
|
|
var_result.Bind(result);
|
|
|
|
Goto(&if_join);
|
|
|
|
}
|
|
|
|
Bind(&if_join);
|
|
|
|
return var_result.value();
|
|
|
|
}
|
|
|
|
|
2016-03-23 13:44:32 +00:00
|
|
|
Node* CodeStubAssembler::ChangeInt32ToTagged(Node* value) {
|
2016-04-18 11:57:06 +00:00
|
|
|
if (Is64()) {
|
2016-03-23 13:44:32 +00:00
|
|
|
return SmiTag(ChangeInt32ToInt64(value));
|
|
|
|
}
|
|
|
|
Variable var_result(this, MachineRepresentation::kTagged);
|
|
|
|
Node* pair = Int32AddWithOverflow(value, value);
|
|
|
|
Node* overflow = Projection(1, pair);
|
|
|
|
Label if_overflow(this, Label::kDeferred), if_notoverflow(this),
|
|
|
|
if_join(this);
|
|
|
|
Branch(overflow, &if_overflow, &if_notoverflow);
|
|
|
|
Bind(&if_overflow);
|
|
|
|
{
|
|
|
|
Node* value64 = ChangeInt32ToFloat64(value);
|
|
|
|
Node* result = AllocateHeapNumberWithValue(value64);
|
|
|
|
var_result.Bind(result);
|
|
|
|
}
|
|
|
|
Goto(&if_join);
|
|
|
|
Bind(&if_notoverflow);
|
|
|
|
{
|
|
|
|
Node* result = Projection(0, pair);
|
|
|
|
var_result.Bind(result);
|
|
|
|
}
|
|
|
|
Goto(&if_join);
|
|
|
|
Bind(&if_join);
|
|
|
|
return var_result.value();
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:51:23 +00:00
|
|
|
Node* CodeStubAssembler::ChangeUint32ToTagged(Node* value) {
|
|
|
|
Label if_overflow(this, Label::kDeferred), if_not_overflow(this),
|
|
|
|
if_join(this);
|
|
|
|
Variable var_result(this, MachineRepresentation::kTagged);
|
|
|
|
// If {value} > 2^31 - 1, we need to store it in a HeapNumber.
|
|
|
|
Branch(Int32LessThan(value, Int32Constant(0)), &if_overflow,
|
|
|
|
&if_not_overflow);
|
|
|
|
Bind(&if_not_overflow);
|
|
|
|
{
|
2016-04-18 11:57:06 +00:00
|
|
|
if (Is64()) {
|
2016-04-13 13:51:23 +00:00
|
|
|
var_result.Bind(SmiTag(ChangeUint32ToUint64(value)));
|
|
|
|
} else {
|
|
|
|
// If tagging {value} results in an overflow, we need to use a HeapNumber
|
|
|
|
// to represent it.
|
|
|
|
Node* pair = Int32AddWithOverflow(value, value);
|
|
|
|
Node* overflow = Projection(1, pair);
|
|
|
|
GotoIf(overflow, &if_overflow);
|
|
|
|
|
|
|
|
Node* result = Projection(0, pair);
|
|
|
|
var_result.Bind(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Goto(&if_join);
|
|
|
|
|
|
|
|
Bind(&if_overflow);
|
|
|
|
{
|
|
|
|
Node* float64_value = ChangeUint32ToFloat64(value);
|
|
|
|
var_result.Bind(AllocateHeapNumberWithValue(float64_value));
|
|
|
|
}
|
|
|
|
Goto(&if_join);
|
|
|
|
|
|
|
|
Bind(&if_join);
|
|
|
|
return var_result.value();
|
|
|
|
}
|
|
|
|
|
2016-04-12 10:29:49 +00:00
|
|
|
Node* CodeStubAssembler::ToThisString(Node* context, Node* value,
|
|
|
|
char const* method_name) {
|
|
|
|
Variable var_value(this, MachineRepresentation::kTagged);
|
|
|
|
var_value.Bind(value);
|
|
|
|
|
|
|
|
// Check if the {value} is a Smi or a HeapObject.
|
|
|
|
Label if_valueissmi(this, Label::kDeferred), if_valueisnotsmi(this),
|
|
|
|
if_valueisstring(this);
|
|
|
|
Branch(WordIsSmi(value), &if_valueissmi, &if_valueisnotsmi);
|
|
|
|
Bind(&if_valueisnotsmi);
|
|
|
|
{
|
|
|
|
// Load the instance type of the {value}.
|
|
|
|
Node* value_instance_type = LoadInstanceType(value);
|
|
|
|
|
|
|
|
// Check if the {value} is already String.
|
|
|
|
Label if_valueisnotstring(this, Label::kDeferred);
|
|
|
|
Branch(
|
|
|
|
Int32LessThan(value_instance_type, Int32Constant(FIRST_NONSTRING_TYPE)),
|
|
|
|
&if_valueisstring, &if_valueisnotstring);
|
|
|
|
Bind(&if_valueisnotstring);
|
|
|
|
{
|
|
|
|
// Check if the {value} is null.
|
|
|
|
Label if_valueisnullorundefined(this, Label::kDeferred),
|
|
|
|
if_valueisnotnullorundefined(this, Label::kDeferred),
|
|
|
|
if_valueisnotnull(this, Label::kDeferred);
|
|
|
|
Branch(WordEqual(value, NullConstant()), &if_valueisnullorundefined,
|
|
|
|
&if_valueisnotnull);
|
|
|
|
Bind(&if_valueisnotnull);
|
|
|
|
{
|
|
|
|
// Check if the {value} is undefined.
|
|
|
|
Branch(WordEqual(value, UndefinedConstant()),
|
|
|
|
&if_valueisnullorundefined, &if_valueisnotnullorundefined);
|
|
|
|
Bind(&if_valueisnotnullorundefined);
|
|
|
|
{
|
|
|
|
// Convert the {value} to a String.
|
|
|
|
Callable callable = CodeFactory::ToString(isolate());
|
|
|
|
var_value.Bind(CallStub(callable, context, value));
|
|
|
|
Goto(&if_valueisstring);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&if_valueisnullorundefined);
|
|
|
|
{
|
|
|
|
// The {value} is either null or undefined.
|
|
|
|
CallRuntime(Runtime::kThrowCalledOnNullOrUndefined, context,
|
|
|
|
HeapConstant(factory()->NewStringFromAsciiChecked(
|
|
|
|
method_name, TENURED)));
|
|
|
|
Goto(&if_valueisstring); // Never reached.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Bind(&if_valueissmi);
|
|
|
|
{
|
|
|
|
// The {value} is a Smi, convert it to a String.
|
|
|
|
Callable callable = CodeFactory::NumberToString(isolate());
|
|
|
|
var_value.Bind(CallStub(callable, context, value));
|
|
|
|
Goto(&if_valueisstring);
|
|
|
|
}
|
|
|
|
Bind(&if_valueisstring);
|
|
|
|
return var_value.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::StringCharCodeAt(Node* string, Node* index) {
|
|
|
|
// Translate the {index} into a Word.
|
|
|
|
index = SmiToWord(index);
|
|
|
|
|
|
|
|
// We may need to loop in case of cons or sliced strings.
|
|
|
|
Variable var_index(this, MachineType::PointerRepresentation());
|
|
|
|
Variable var_result(this, MachineRepresentation::kWord32);
|
|
|
|
Variable var_string(this, MachineRepresentation::kTagged);
|
|
|
|
Variable* loop_vars[] = {&var_index, &var_string};
|
|
|
|
Label done_loop(this, &var_result), loop(this, 2, loop_vars);
|
|
|
|
var_string.Bind(string);
|
|
|
|
var_index.Bind(index);
|
|
|
|
Goto(&loop);
|
|
|
|
Bind(&loop);
|
|
|
|
{
|
|
|
|
// Load the current {index}.
|
|
|
|
index = var_index.value();
|
|
|
|
|
|
|
|
// Load the current {string}.
|
|
|
|
string = var_string.value();
|
|
|
|
|
|
|
|
// Load the instance type of the {string}.
|
|
|
|
Node* string_instance_type = LoadInstanceType(string);
|
|
|
|
|
|
|
|
// Check if the {string} is a SeqString.
|
|
|
|
Label if_stringissequential(this), if_stringisnotsequential(this);
|
|
|
|
Branch(Word32Equal(Word32And(string_instance_type,
|
|
|
|
Int32Constant(kStringRepresentationMask)),
|
|
|
|
Int32Constant(kSeqStringTag)),
|
|
|
|
&if_stringissequential, &if_stringisnotsequential);
|
|
|
|
|
|
|
|
Bind(&if_stringissequential);
|
|
|
|
{
|
|
|
|
// Check if the {string} is a TwoByteSeqString or a OneByteSeqString.
|
|
|
|
Label if_stringistwobyte(this), if_stringisonebyte(this);
|
|
|
|
Branch(Word32Equal(Word32And(string_instance_type,
|
|
|
|
Int32Constant(kStringEncodingMask)),
|
|
|
|
Int32Constant(kTwoByteStringTag)),
|
|
|
|
&if_stringistwobyte, &if_stringisonebyte);
|
|
|
|
|
|
|
|
Bind(&if_stringisonebyte);
|
|
|
|
{
|
|
|
|
var_result.Bind(
|
|
|
|
Load(MachineType::Uint8(), string,
|
|
|
|
IntPtrAdd(index, IntPtrConstant(SeqOneByteString::kHeaderSize -
|
|
|
|
kHeapObjectTag))));
|
|
|
|
Goto(&done_loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&if_stringistwobyte);
|
|
|
|
{
|
|
|
|
var_result.Bind(
|
|
|
|
Load(MachineType::Uint16(), string,
|
|
|
|
IntPtrAdd(WordShl(index, IntPtrConstant(1)),
|
|
|
|
IntPtrConstant(SeqTwoByteString::kHeaderSize -
|
|
|
|
kHeapObjectTag))));
|
|
|
|
Goto(&done_loop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&if_stringisnotsequential);
|
|
|
|
{
|
|
|
|
// Check if the {string} is a ConsString.
|
|
|
|
Label if_stringiscons(this), if_stringisnotcons(this);
|
|
|
|
Branch(Word32Equal(Word32And(string_instance_type,
|
|
|
|
Int32Constant(kStringRepresentationMask)),
|
|
|
|
Int32Constant(kConsStringTag)),
|
|
|
|
&if_stringiscons, &if_stringisnotcons);
|
|
|
|
|
|
|
|
Bind(&if_stringiscons);
|
|
|
|
{
|
|
|
|
// Check whether the right hand side is the empty string (i.e. if
|
|
|
|
// this is really a flat string in a cons string). If that is not
|
|
|
|
// the case we flatten the string first.
|
|
|
|
Label if_rhsisempty(this), if_rhsisnotempty(this, Label::kDeferred);
|
|
|
|
Node* rhs = LoadObjectField(string, ConsString::kSecondOffset);
|
|
|
|
Branch(WordEqual(rhs, EmptyStringConstant()), &if_rhsisempty,
|
|
|
|
&if_rhsisnotempty);
|
|
|
|
|
|
|
|
Bind(&if_rhsisempty);
|
|
|
|
{
|
|
|
|
// Just operate on the left hand side of the {string}.
|
|
|
|
var_string.Bind(LoadObjectField(string, ConsString::kFirstOffset));
|
|
|
|
Goto(&loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&if_rhsisnotempty);
|
|
|
|
{
|
|
|
|
// Flatten the {string} and lookup in the resulting string.
|
|
|
|
var_string.Bind(CallRuntime(Runtime::kFlattenString,
|
|
|
|
NoContextConstant(), string));
|
|
|
|
Goto(&loop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&if_stringisnotcons);
|
|
|
|
{
|
|
|
|
// Check if the {string} is an ExternalString.
|
|
|
|
Label if_stringisexternal(this), if_stringisnotexternal(this);
|
|
|
|
Branch(Word32Equal(Word32And(string_instance_type,
|
|
|
|
Int32Constant(kStringRepresentationMask)),
|
|
|
|
Int32Constant(kExternalStringTag)),
|
|
|
|
&if_stringisexternal, &if_stringisnotexternal);
|
|
|
|
|
|
|
|
Bind(&if_stringisexternal);
|
|
|
|
{
|
|
|
|
// Check if the {string} is a short external string.
|
|
|
|
Label if_stringisshort(this),
|
|
|
|
if_stringisnotshort(this, Label::kDeferred);
|
|
|
|
Branch(Word32Equal(Word32And(string_instance_type,
|
|
|
|
Int32Constant(kShortExternalStringMask)),
|
|
|
|
Int32Constant(0)),
|
|
|
|
&if_stringisshort, &if_stringisnotshort);
|
|
|
|
|
|
|
|
Bind(&if_stringisshort);
|
|
|
|
{
|
|
|
|
// Load the actual resource data from the {string}.
|
|
|
|
Node* string_resource_data =
|
|
|
|
LoadObjectField(string, ExternalString::kResourceDataOffset,
|
|
|
|
MachineType::Pointer());
|
|
|
|
|
|
|
|
// Check if the {string} is a TwoByteExternalString or a
|
|
|
|
// OneByteExternalString.
|
|
|
|
Label if_stringistwobyte(this), if_stringisonebyte(this);
|
|
|
|
Branch(Word32Equal(Word32And(string_instance_type,
|
|
|
|
Int32Constant(kStringEncodingMask)),
|
|
|
|
Int32Constant(kTwoByteStringTag)),
|
|
|
|
&if_stringistwobyte, &if_stringisonebyte);
|
|
|
|
|
|
|
|
Bind(&if_stringisonebyte);
|
|
|
|
{
|
|
|
|
var_result.Bind(
|
|
|
|
Load(MachineType::Uint8(), string_resource_data, index));
|
|
|
|
Goto(&done_loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&if_stringistwobyte);
|
|
|
|
{
|
|
|
|
var_result.Bind(Load(MachineType::Uint16(), string_resource_data,
|
|
|
|
WordShl(index, IntPtrConstant(1))));
|
|
|
|
Goto(&done_loop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&if_stringisnotshort);
|
|
|
|
{
|
|
|
|
// The {string} might be compressed, call the runtime.
|
|
|
|
var_result.Bind(SmiToWord32(
|
|
|
|
CallRuntime(Runtime::kExternalStringGetChar,
|
|
|
|
NoContextConstant(), string, SmiTag(index))));
|
|
|
|
Goto(&done_loop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&if_stringisnotexternal);
|
|
|
|
{
|
|
|
|
// The {string} is a SlicedString, continue with its parent.
|
|
|
|
Node* string_offset =
|
|
|
|
SmiToWord(LoadObjectField(string, SlicedString::kOffsetOffset));
|
|
|
|
Node* string_parent =
|
|
|
|
LoadObjectField(string, SlicedString::kParentOffset);
|
|
|
|
var_index.Bind(IntPtrAdd(index, string_offset));
|
|
|
|
var_string.Bind(string_parent);
|
|
|
|
Goto(&loop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&done_loop);
|
|
|
|
return var_result.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CodeStubAssembler::StringFromCharCode(Node* code) {
|
|
|
|
Variable var_result(this, MachineRepresentation::kTagged);
|
|
|
|
|
|
|
|
// Check if the {code} is a one-byte char code.
|
|
|
|
Label if_codeisonebyte(this), if_codeistwobyte(this, Label::kDeferred),
|
|
|
|
if_done(this);
|
|
|
|
Branch(Int32LessThanOrEqual(code, Int32Constant(String::kMaxOneByteCharCode)),
|
|
|
|
&if_codeisonebyte, &if_codeistwobyte);
|
|
|
|
Bind(&if_codeisonebyte);
|
|
|
|
{
|
|
|
|
// Load the isolate wide single character string cache.
|
|
|
|
Node* cache = LoadRoot(Heap::kSingleCharacterStringCacheRootIndex);
|
|
|
|
|
|
|
|
// Check if we have an entry for the {code} in the single character string
|
|
|
|
// cache already.
|
|
|
|
Label if_entryisundefined(this, Label::kDeferred),
|
|
|
|
if_entryisnotundefined(this);
|
|
|
|
Node* entry = LoadFixedArrayElementInt32Index(cache, code);
|
|
|
|
Branch(WordEqual(entry, UndefinedConstant()), &if_entryisundefined,
|
|
|
|
&if_entryisnotundefined);
|
|
|
|
|
|
|
|
Bind(&if_entryisundefined);
|
|
|
|
{
|
|
|
|
// Allocate a new SeqOneByteString for {code} and store it in the {cache}.
|
|
|
|
Node* result = AllocateSeqOneByteString(1);
|
|
|
|
StoreNoWriteBarrier(
|
|
|
|
MachineRepresentation::kWord8, result,
|
|
|
|
IntPtrConstant(SeqOneByteString::kHeaderSize - kHeapObjectTag), code);
|
|
|
|
StoreFixedArrayElementInt32Index(cache, code, result);
|
|
|
|
var_result.Bind(result);
|
|
|
|
Goto(&if_done);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&if_entryisnotundefined);
|
|
|
|
{
|
|
|
|
// Return the entry from the {cache}.
|
|
|
|
var_result.Bind(entry);
|
|
|
|
Goto(&if_done);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&if_codeistwobyte);
|
|
|
|
{
|
|
|
|
// Allocate a new SeqTwoByteString for {code}.
|
|
|
|
Node* result = AllocateSeqTwoByteString(1);
|
|
|
|
StoreNoWriteBarrier(
|
|
|
|
MachineRepresentation::kWord16, result,
|
|
|
|
IntPtrConstant(SeqTwoByteString::kHeaderSize - kHeapObjectTag), code);
|
|
|
|
var_result.Bind(result);
|
|
|
|
Goto(&if_done);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&if_done);
|
|
|
|
return var_result.value();
|
|
|
|
}
|
|
|
|
|
2016-04-18 11:57:06 +00:00
|
|
|
Node* CodeStubAssembler::BitFieldDecode(Node* word32, uint32_t shift,
|
|
|
|
uint32_t mask) {
|
|
|
|
return Word32Shr(Word32And(word32, Int32Constant(mask)),
|
|
|
|
Int32Constant(shift));
|
2016-02-02 09:42:13 +00:00
|
|
|
}
|
2015-12-02 12:35:12 +00:00
|
|
|
|
2016-05-03 11:11:27 +00:00
|
|
|
void CodeStubAssembler::TryToName(Node* key, Label* if_keyisindex,
|
|
|
|
Variable* var_index, Label* if_keyisunique,
|
|
|
|
Label* call_runtime) {
|
|
|
|
DCHECK_EQ(MachineRepresentation::kWord32, var_index->rep());
|
|
|
|
|
|
|
|
Label if_keyissmi(this), if_keyisnotsmi(this);
|
|
|
|
Branch(WordIsSmi(key), &if_keyissmi, &if_keyisnotsmi);
|
|
|
|
Bind(&if_keyissmi);
|
|
|
|
{
|
|
|
|
// Negative smi keys are named properties. Handle in the runtime.
|
|
|
|
Label if_keyispositive(this);
|
|
|
|
Branch(WordIsPositiveSmi(key), &if_keyispositive, call_runtime);
|
|
|
|
Bind(&if_keyispositive);
|
|
|
|
|
|
|
|
var_index->Bind(SmiToWord32(key));
|
|
|
|
Goto(if_keyisindex);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bind(&if_keyisnotsmi);
|
|
|
|
|
|
|
|
Node* key_instance_type = LoadInstanceType(key);
|
|
|
|
Label if_keyisnotsymbol(this);
|
|
|
|
Branch(Word32Equal(key_instance_type, Int32Constant(SYMBOL_TYPE)),
|
|
|
|
if_keyisunique, &if_keyisnotsymbol);
|
|
|
|
Bind(&if_keyisnotsymbol);
|
|
|
|
{
|
|
|
|
Label if_keyisinternalized(this);
|
|
|
|
Node* bits =
|
|
|
|
WordAnd(key_instance_type,
|
|
|
|
Int32Constant(kIsNotStringMask | kIsNotInternalizedMask));
|
|
|
|
Branch(Word32Equal(bits, Int32Constant(kStringTag | kInternalizedTag)),
|
|
|
|
&if_keyisinternalized, call_runtime);
|
|
|
|
Bind(&if_keyisinternalized);
|
|
|
|
|
|
|
|
// Check whether the key is an array index passed in as string. Handle
|
|
|
|
// uniform with smi keys if so.
|
|
|
|
// TODO(verwaest): Also support non-internalized strings.
|
|
|
|
Node* hash = LoadNameHash(key);
|
|
|
|
Node* bit =
|
|
|
|
Word32And(hash, Int32Constant(internal::Name::kIsNotArrayIndexMask));
|
|
|
|
Label if_isarrayindex(this);
|
|
|
|
Branch(Word32Equal(bit, Int32Constant(0)), &if_isarrayindex,
|
|
|
|
if_keyisunique);
|
|
|
|
Bind(&if_isarrayindex);
|
|
|
|
var_index->Bind(BitFieldDecode<internal::Name::ArrayIndexValueBits>(hash));
|
|
|
|
Goto(if_keyisindex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeStubAssembler::TryLookupProperty(Node* object, Node* map,
|
|
|
|
Node* instance_type, Node* name,
|
|
|
|
Label* if_found, Label* if_not_found,
|
|
|
|
Label* call_runtime) {
|
|
|
|
{
|
|
|
|
Label if_objectissimple(this);
|
|
|
|
Branch(Int32LessThanOrEqual(instance_type,
|
|
|
|
Int32Constant(LAST_SPECIAL_RECEIVER_TYPE)),
|
|
|
|
call_runtime, &if_objectissimple);
|
|
|
|
Bind(&if_objectissimple);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(verwaest): Perform a dictonary lookup on slow-mode receivers.
|
|
|
|
Node* bit_field3 = LoadMapBitField3(map);
|
|
|
|
Node* bit = BitFieldDecode<Map::DictionaryMap>(bit_field3);
|
|
|
|
Label if_isfastmap(this);
|
|
|
|
Branch(Word32Equal(bit, Int32Constant(0)), &if_isfastmap, call_runtime);
|
|
|
|
Bind(&if_isfastmap);
|
|
|
|
Node* nof = BitFieldDecode<Map::NumberOfOwnDescriptorsBits>(bit_field3);
|
|
|
|
// Bail out to the runtime for large numbers of own descriptors. The stub only
|
|
|
|
// does linear search, which becomes too expensive in that case.
|
|
|
|
{
|
|
|
|
static const int32_t kMaxLinear = 210;
|
|
|
|
Label above_max(this), below_max(this);
|
|
|
|
Branch(Int32LessThanOrEqual(nof, Int32Constant(kMaxLinear)), &below_max,
|
|
|
|
call_runtime);
|
|
|
|
Bind(&below_max);
|
|
|
|
}
|
|
|
|
Node* descriptors = LoadMapDescriptors(map);
|
|
|
|
|
|
|
|
Variable var_descriptor(this, MachineRepresentation::kWord32);
|
|
|
|
Label loop(this, &var_descriptor);
|
|
|
|
var_descriptor.Bind(Int32Constant(0));
|
|
|
|
Goto(&loop);
|
|
|
|
Bind(&loop);
|
|
|
|
{
|
|
|
|
Node* index = var_descriptor.value();
|
|
|
|
Node* offset = Int32Constant(DescriptorArray::ToKeyIndex(0));
|
|
|
|
Node* factor = Int32Constant(DescriptorArray::kDescriptorSize);
|
|
|
|
Label if_notdone(this);
|
|
|
|
Branch(Word32Equal(index, nof), if_not_found, &if_notdone);
|
|
|
|
Bind(&if_notdone);
|
|
|
|
{
|
|
|
|
Node* array_index = Int32Add(offset, Int32Mul(index, factor));
|
|
|
|
Node* current = LoadFixedArrayElementInt32Index(descriptors, array_index);
|
|
|
|
Label if_unequal(this);
|
|
|
|
Branch(WordEqual(current, name), if_found, &if_unequal);
|
|
|
|
Bind(&if_unequal);
|
|
|
|
|
|
|
|
var_descriptor.Bind(Int32Add(index, Int32Constant(1)));
|
|
|
|
Goto(&loop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeStubAssembler::TryLookupElement(Node* object, Node* map,
|
|
|
|
Node* instance_type, Node* index,
|
|
|
|
Label* if_found, Label* if_not_found,
|
|
|
|
Label* call_runtime) {
|
|
|
|
{
|
|
|
|
Label if_objectissimple(this);
|
|
|
|
Branch(Int32LessThanOrEqual(instance_type,
|
|
|
|
Int32Constant(LAST_CUSTOM_ELEMENTS_RECEIVER)),
|
|
|
|
call_runtime, &if_objectissimple);
|
|
|
|
Bind(&if_objectissimple);
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* bit_field2 = LoadMapBitField2(map);
|
|
|
|
Node* elements_kind = BitFieldDecode<Map::ElementsKindBits>(bit_field2);
|
|
|
|
|
|
|
|
// TODO(verwaest): Support other elements kinds as well.
|
|
|
|
Label if_isobjectorsmi(this);
|
|
|
|
Branch(
|
|
|
|
Int32LessThanOrEqual(elements_kind, Int32Constant(FAST_HOLEY_ELEMENTS)),
|
|
|
|
&if_isobjectorsmi, call_runtime);
|
|
|
|
Bind(&if_isobjectorsmi);
|
|
|
|
{
|
|
|
|
Node* elements = LoadElements(object);
|
|
|
|
Node* length = LoadFixedArrayBaseLength(elements);
|
|
|
|
|
|
|
|
Label if_iskeyinrange(this);
|
|
|
|
Branch(Int32LessThan(index, SmiToWord32(length)), &if_iskeyinrange,
|
|
|
|
if_not_found);
|
|
|
|
|
|
|
|
Bind(&if_iskeyinrange);
|
|
|
|
Node* element = LoadFixedArrayElementInt32Index(elements, index);
|
|
|
|
Node* the_hole = LoadRoot(Heap::kTheHoleValueRootIndex);
|
|
|
|
Branch(WordEqual(element, the_hole), if_not_found, if_found);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-02 12:35:12 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|