Commit 2bdb74f7 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[cleanup] Refactor parts of builtins-number-gen.cc

Bug: v8:6474

Change-Id: I24d067ac77c2cb557d0b3f6e2c8c512761c160f1
Reviewed-on: https://chromium-review.googlesource.com/531384
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45944}
parent b5f16bba
......@@ -53,6 +53,11 @@ class NumberBuiltinsAssembler : public CodeStubAssembler {
Return(RelationalComparison(mode, lhs, rhs, context));
}
template <typename Descriptor>
void BinaryOp(Label* smis, Variable* var_left, Variable* var_right,
Label* doubles, Variable* var_left_double,
Variable* var_right_double);
};
// ES6 #sec-number.isfinite
......@@ -347,682 +352,356 @@ TF_BUILTIN(NumberPrototypeValueOf, CodeStubAssembler) {
Return(result);
}
TF_BUILTIN(Add, CodeStubAssembler) {
class AddStubAssembler : public CodeStubAssembler {
public:
explicit AddStubAssembler(compiler::CodeAssemblerState* state)
: CodeStubAssembler(state) {}
protected:
void ConvertReceiverAndLoop(Variable* var_value, Label* loop, Node* context) {
// Call ToPrimitive explicitly without hint (whereas ToNumber
// would pass a "number" hint).
Callable callable = CodeFactory::NonPrimitiveToPrimitive(isolate());
var_value->Bind(CallStub(callable, context, var_value->value()));
Goto(loop);
}
void ConvertNonReceiverAndLoop(Variable* var_value, Label* loop,
Node* context) {
var_value->Bind(
CallBuiltin(Builtins::kNonNumberToNumber, context, var_value->value()));
Goto(loop);
}
void ConvertAndLoop(Variable* var_value, Node* instance_type, Label* loop,
Node* context) {
Label is_not_receiver(this, Label::kDeferred);
GotoIfNot(IsJSReceiverInstanceType(instance_type), &is_not_receiver);
ConvertReceiverAndLoop(var_value, loop, context);
BIND(&is_not_receiver);
ConvertNonReceiverAndLoop(var_value, loop, context);
}
};
TF_BUILTIN(Add, AddStubAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* left = Parameter(Descriptor::kLeft);
Node* right = Parameter(Descriptor::kRight);
VARIABLE(var_left, MachineRepresentation::kTagged,
Parameter(Descriptor::kLeft));
VARIABLE(var_right, MachineRepresentation::kTagged,
Parameter(Descriptor::kRight));
// Shared entry for floating point addition.
Label do_fadd(this);
VARIABLE(var_fadd_lhs, MachineRepresentation::kFloat64);
VARIABLE(var_fadd_rhs, MachineRepresentation::kFloat64);
Label do_double_add(this);
VARIABLE(var_left_double, MachineRepresentation::kFloat64);
VARIABLE(var_right_double, MachineRepresentation::kFloat64);
// We might need to loop several times due to ToPrimitive, ToString and/or
// ToNumber conversions.
VARIABLE(var_lhs, MachineRepresentation::kTagged);
VARIABLE(var_rhs, MachineRepresentation::kTagged);
VARIABLE(var_result, MachineRepresentation::kTagged);
Variable* loop_vars[2] = {&var_lhs, &var_rhs};
Label loop(this, 2, loop_vars), end(this),
Variable* loop_vars[2] = {&var_left, &var_right};
Label loop(this, 2, loop_vars),
string_add_convert_left(this, Label::kDeferred),
string_add_convert_right(this, Label::kDeferred);
var_lhs.Bind(left);
var_rhs.Bind(right);
Goto(&loop);
BIND(&loop);
{
// Load the current {lhs} and {rhs} values.
Node* lhs = var_lhs.value();
Node* rhs = var_rhs.value();
Node* left = var_left.value();
Node* right = var_right.value();
// Check if the {lhs} is a Smi or a HeapObject.
Label if_lhsissmi(this), if_lhsisnotsmi(this);
Branch(TaggedIsSmi(lhs), &if_lhsissmi, &if_lhsisnotsmi);
Label if_left_smi(this), if_left_heapobject(this);
Branch(TaggedIsSmi(left), &if_left_smi, &if_left_heapobject);
BIND(&if_lhsissmi);
BIND(&if_left_smi);
{
// Check if the {rhs} is also a Smi.
Label if_rhsissmi(this), if_rhsisnotsmi(this);
Branch(TaggedIsSmi(rhs), &if_rhsissmi, &if_rhsisnotsmi);
Label if_right_smi(this), if_right_heapobject(this);
Branch(TaggedIsSmi(right), &if_right_smi, &if_right_heapobject);
BIND(&if_rhsissmi);
BIND(&if_right_smi);
{
// Try fast Smi addition first.
Node* pair = IntPtrAddWithOverflow(BitcastTaggedToWord(lhs),
BitcastTaggedToWord(rhs));
// Try fast Smi addition first, bail out if it overflows.
Node* pair = IntPtrAddWithOverflow(BitcastTaggedToWord(left),
BitcastTaggedToWord(right));
Node* overflow = Projection(1, pair);
// Check if the Smi additon overflowed.
Label if_overflow(this), if_notoverflow(this);
Branch(overflow, &if_overflow, &if_notoverflow);
Label if_overflow(this);
GotoIf(overflow, &if_overflow);
Return(BitcastWordToTaggedSigned(Projection(0, pair)));
BIND(&if_overflow);
{
var_fadd_lhs.Bind(SmiToFloat64(lhs));
var_fadd_rhs.Bind(SmiToFloat64(rhs));
Goto(&do_fadd);
var_left_double.Bind(SmiToFloat64(left));
var_right_double.Bind(SmiToFloat64(right));
Goto(&do_double_add);
}
} // if_right_smi
BIND(&if_notoverflow);
var_result.Bind(BitcastWordToTaggedSigned(Projection(0, pair)));
Goto(&end);
}
BIND(&if_rhsisnotsmi);
BIND(&if_right_heapobject);
{
// Load the map of {rhs}.
Node* rhs_map = LoadMap(rhs);
// Check if the {rhs} is a HeapNumber.
Label if_rhsisnumber(this), if_rhsisnotnumber(this, Label::kDeferred);
Branch(IsHeapNumberMap(rhs_map), &if_rhsisnumber, &if_rhsisnotnumber);
Node* right_map = LoadMap(right);
BIND(&if_rhsisnumber);
{
var_fadd_lhs.Bind(SmiToFloat64(lhs));
var_fadd_rhs.Bind(LoadHeapNumberValue(rhs));
Goto(&do_fadd);
}
BIND(&if_rhsisnotnumber);
{
// Load the instance type of {rhs}.
Node* rhs_instance_type = LoadMapInstanceType(rhs_map);
Label if_right_not_number(this, Label::kDeferred);
GotoIfNot(IsHeapNumberMap(right_map), &if_right_not_number);
// Check if the {rhs} is a String.
Label if_rhsisstring(this, Label::kDeferred),
if_rhsisnotstring(this, Label::kDeferred);
Branch(IsStringInstanceType(rhs_instance_type), &if_rhsisstring,
&if_rhsisnotstring);
// {right} is a HeapNumber.
var_left_double.Bind(SmiToFloat64(left));
var_right_double.Bind(LoadHeapNumberValue(right));
Goto(&do_double_add);
BIND(&if_rhsisstring);
BIND(&if_right_not_number);
{
var_lhs.Bind(lhs);
var_rhs.Bind(rhs);
Goto(&string_add_convert_left);
Node* right_instance_type = LoadMapInstanceType(right_map);
GotoIf(IsStringInstanceType(right_instance_type),
&string_add_convert_left);
ConvertAndLoop(&var_right, right_instance_type, &loop, context);
}
} // if_right_heapobject
} // if_left_smi
BIND(&if_rhsisnotstring);
BIND(&if_left_heapobject);
{
// Check if {rhs} is a JSReceiver.
Label if_rhsisreceiver(this, Label::kDeferred),
if_rhsisnotreceiver(this, Label::kDeferred);
Branch(IsJSReceiverInstanceType(rhs_instance_type),
&if_rhsisreceiver, &if_rhsisnotreceiver);
Node* left_map = LoadMap(left);
Label if_right_smi(this), if_right_heapobject(this);
Branch(TaggedIsSmi(right), &if_right_smi, &if_right_heapobject);
BIND(&if_rhsisreceiver);
BIND(&if_right_smi);
{
// Convert {rhs} to a primitive first passing no hint.
Callable callable =
CodeFactory::NonPrimitiveToPrimitive(isolate());
var_rhs.Bind(CallStub(callable, context, rhs));
Goto(&loop);
}
Label if_left_not_number(this, Label::kDeferred);
GotoIfNot(IsHeapNumberMap(left_map), &if_left_not_number);
BIND(&if_rhsisnotreceiver);
{
// Convert {rhs} to a Number first.
var_rhs.Bind(
CallBuiltin(Builtins::kNonNumberToNumber, context, rhs));
Goto(&loop);
}
}
}
}
}
BIND(&if_lhsisnotsmi);
{
// Load the map and instance type of {lhs}.
Node* lhs_instance_type = LoadInstanceType(lhs);
// Check if {lhs} is a String.
Label if_lhsisstring(this), if_lhsisnotstring(this);
Branch(IsStringInstanceType(lhs_instance_type), &if_lhsisstring,
&if_lhsisnotstring);
BIND(&if_lhsisstring);
{
var_lhs.Bind(lhs);
var_rhs.Bind(rhs);
Goto(&string_add_convert_right);
}
BIND(&if_lhsisnotstring);
{
// Check if {rhs} is a Smi.
Label if_rhsissmi(this), if_rhsisnotsmi(this);
Branch(TaggedIsSmi(rhs), &if_rhsissmi, &if_rhsisnotsmi);
BIND(&if_rhsissmi);
{
// Check if {lhs} is a Number.
Label if_lhsisnumber(this), if_lhsisnotnumber(this, Label::kDeferred);
Branch(
Word32Equal(lhs_instance_type, Int32Constant(HEAP_NUMBER_TYPE)),
&if_lhsisnumber, &if_lhsisnotnumber);
BIND(&if_lhsisnumber);
{
// The {lhs} is a HeapNumber, the {rhs} is a Smi, just add them.
var_fadd_lhs.Bind(LoadHeapNumberValue(lhs));
var_fadd_rhs.Bind(SmiToFloat64(rhs));
Goto(&do_fadd);
}
BIND(&if_lhsisnotnumber);
{
// The {lhs} is neither a Number nor a String, and the {rhs} is a
// Smi.
Label if_lhsisreceiver(this, Label::kDeferred),
if_lhsisnotreceiver(this, Label::kDeferred);
Branch(IsJSReceiverInstanceType(lhs_instance_type),
&if_lhsisreceiver, &if_lhsisnotreceiver);
BIND(&if_lhsisreceiver);
{
// Convert {lhs} to a primitive first passing no hint.
Callable callable =
CodeFactory::NonPrimitiveToPrimitive(isolate());
var_lhs.Bind(CallStub(callable, context, lhs));
Goto(&loop);
}
BIND(&if_lhsisnotreceiver);
{
// Convert {lhs} to a Number first.
var_lhs.Bind(
CallBuiltin(Builtins::kNonNumberToNumber, context, lhs));
Goto(&loop);
}
}
}
BIND(&if_rhsisnotsmi);
{
// Load the instance type of {rhs}.
Node* rhs_instance_type = LoadInstanceType(rhs);
// Check if {rhs} is a String.
Label if_rhsisstring(this), if_rhsisnotstring(this);
Branch(IsStringInstanceType(rhs_instance_type), &if_rhsisstring,
&if_rhsisnotstring);
// {left} is a HeapNumber, {right} is a Smi.
var_left_double.Bind(LoadHeapNumberValue(left));
var_right_double.Bind(SmiToFloat64(right));
Goto(&do_double_add);
BIND(&if_rhsisstring);
BIND(&if_left_not_number);
{
var_lhs.Bind(lhs);
var_rhs.Bind(rhs);
Goto(&string_add_convert_left);
Node* left_instance_type = LoadMapInstanceType(left_map);
GotoIf(IsStringInstanceType(left_instance_type),
&string_add_convert_right);
// {left} is neither a Number nor a String, and {right} is a Smi.
ConvertAndLoop(&var_left, left_instance_type, &loop, context);
}
} // if_right_smi
BIND(&if_rhsisnotstring);
BIND(&if_right_heapobject);
{
// Check if {lhs} is a HeapNumber.
Label if_lhsisnumber(this), if_lhsisnotnumber(this);
Branch(
Word32Equal(lhs_instance_type, Int32Constant(HEAP_NUMBER_TYPE)),
&if_lhsisnumber, &if_lhsisnotnumber);
Node* right_map = LoadMap(right);
BIND(&if_lhsisnumber);
{
// Check if {rhs} is also a HeapNumber.
Label if_rhsisnumber(this),
if_rhsisnotnumber(this, Label::kDeferred);
Branch(Word32Equal(rhs_instance_type,
Int32Constant(HEAP_NUMBER_TYPE)),
&if_rhsisnumber, &if_rhsisnotnumber);
BIND(&if_rhsisnumber);
{
// Perform a floating point addition.
var_fadd_lhs.Bind(LoadHeapNumberValue(lhs));
var_fadd_rhs.Bind(LoadHeapNumberValue(rhs));
Goto(&do_fadd);
}
BIND(&if_rhsisnotnumber);
{
// Check if {rhs} is a JSReceiver.
Label if_rhsisreceiver(this, Label::kDeferred),
if_rhsisnotreceiver(this, Label::kDeferred);
Branch(IsJSReceiverInstanceType(rhs_instance_type),
&if_rhsisreceiver, &if_rhsisnotreceiver);
BIND(&if_rhsisreceiver);
{
// Convert {rhs} to a primitive first passing no hint.
Callable callable =
CodeFactory::NonPrimitiveToPrimitive(isolate());
var_rhs.Bind(CallStub(callable, context, rhs));
Goto(&loop);
}
Label if_left_number(this), if_left_not_number(this, Label::kDeferred);
Branch(IsHeapNumberMap(left_map), &if_left_number, &if_left_not_number);
BIND(&if_rhsisnotreceiver);
BIND(&if_left_number);
{
// Convert {rhs} to a Number first.
var_rhs.Bind(
CallBuiltin(Builtins::kNonNumberToNumber, context, rhs));
Goto(&loop);
}
}
}
Label if_right_not_number(this, Label::kDeferred);
GotoIfNot(IsHeapNumberMap(right_map), &if_right_not_number);
BIND(&if_lhsisnotnumber);
{
// Check if {lhs} is a JSReceiver.
Label if_lhsisreceiver(this, Label::kDeferred),
if_lhsisnotreceiver(this);
Branch(IsJSReceiverInstanceType(lhs_instance_type),
&if_lhsisreceiver, &if_lhsisnotreceiver);
// Both {left} and {right} are HeapNumbers.
var_left_double.Bind(LoadHeapNumberValue(left));
var_right_double.Bind(LoadHeapNumberValue(right));
Goto(&do_double_add);
BIND(&if_lhsisreceiver);
BIND(&if_right_not_number);
{
// Convert {lhs} to a primitive first passing no hint.
Callable callable =
CodeFactory::NonPrimitiveToPrimitive(isolate());
var_lhs.Bind(CallStub(callable, context, lhs));
Goto(&loop);
Node* right_instance_type = LoadMapInstanceType(right_map);
GotoIf(IsStringInstanceType(right_instance_type),
&string_add_convert_left);
// {left} is a HeapNumber, {right} is neither Number nor String.
ConvertAndLoop(&var_right, right_instance_type, &loop, context);
}
} // if_left_number
BIND(&if_lhsisnotreceiver);
BIND(&if_left_not_number);
{
// Check if {rhs} is a JSReceiver.
Label if_rhsisreceiver(this, Label::kDeferred),
if_rhsisnotreceiver(this, Label::kDeferred);
Branch(IsJSReceiverInstanceType(rhs_instance_type),
&if_rhsisreceiver, &if_rhsisnotreceiver);
Node* left_instance_type = LoadMapInstanceType(left_map);
GotoIf(IsStringInstanceType(left_instance_type),
&string_add_convert_right);
Node* right_instance_type = LoadMapInstanceType(right_map);
GotoIf(IsStringInstanceType(right_instance_type),
&string_add_convert_left);
Label if_left_not_receiver(this, Label::kDeferred);
Label if_right_not_receiver(this, Label::kDeferred);
GotoIfNot(IsJSReceiverInstanceType(left_instance_type),
&if_left_not_receiver);
// {left} is a JSReceiver, convert it first.
ConvertReceiverAndLoop(&var_left, &loop, context);
BIND(&if_rhsisreceiver);
{
// Convert {rhs} to a primitive first passing no hint.
Callable callable =
CodeFactory::NonPrimitiveToPrimitive(isolate());
var_rhs.Bind(CallStub(callable, context, rhs));
Goto(&loop);
}
BIND(&if_left_not_receiver);
GotoIfNot(IsJSReceiverInstanceType(right_instance_type),
&if_right_not_receiver);
// {left} is a Primitive, but {right} is a JSReceiver, so convert
// {right} with priority.
ConvertReceiverAndLoop(&var_right, &loop, context);
BIND(&if_rhsisnotreceiver);
{
// Convert {lhs} to a Number first.
var_lhs.Bind(
CallBuiltin(Builtins::kNonNumberToNumber, context, lhs));
Goto(&loop);
}
}
}
}
}
}
BIND(&if_right_not_receiver);
// Neither {left} nor {right} are JSReceivers.
ConvertNonReceiverAndLoop(&var_left, &loop, context);
}
} // if_right_heapobject
} // if_left_heapobject
}
BIND(&string_add_convert_left);
{
// Convert {lhs}, which is a Smi, to a String and concatenate the
// resulting string with the String {rhs}.
// Convert {left} to a String and concatenate it with the String {right}.
Callable callable =
CodeFactory::StringAdd(isolate(), STRING_ADD_CONVERT_LEFT, NOT_TENURED);
var_result.Bind(
CallStub(callable, context, var_lhs.value(), var_rhs.value()));
Goto(&end);
Return(CallStub(callable, context, var_left.value(), var_right.value()));
}
BIND(&string_add_convert_right);
{
// Convert {lhs}, which is a Smi, to a String and concatenate the
// resulting string with the String {rhs}.
// Convert {right} to a String and concatenate it with the String {left}.
Callable callable = CodeFactory::StringAdd(
isolate(), STRING_ADD_CONVERT_RIGHT, NOT_TENURED);
var_result.Bind(
CallStub(callable, context, var_lhs.value(), var_rhs.value()));
Goto(&end);
Return(CallStub(callable, context, var_left.value(), var_right.value()));
}
BIND(&do_fadd);
BIND(&do_double_add);
{
Node* lhs_value = var_fadd_lhs.value();
Node* rhs_value = var_fadd_rhs.value();
Node* value = Float64Add(lhs_value, rhs_value);
Node* result = AllocateHeapNumberWithValue(value);
var_result.Bind(result);
Goto(&end);
Node* value = Float64Add(var_left_double.value(), var_right_double.value());
Return(AllocateHeapNumberWithValue(value));
}
BIND(&end);
Return(var_result.value());
}
TF_BUILTIN(Subtract, CodeStubAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* left = Parameter(Descriptor::kLeft);
Node* right = Parameter(Descriptor::kRight);
template <typename Descriptor>
void NumberBuiltinsAssembler::BinaryOp(Label* smis, Variable* var_left,
Variable* var_right, Label* doubles,
Variable* var_left_double,
Variable* var_right_double) {
DCHECK(var_left->rep() == MachineRepresentation::kTagged);
DCHECK(var_right->rep() == MachineRepresentation::kTagged);
// Shared entry for floating point subtraction.
Label do_fsub(this), end(this);
VARIABLE(var_fsub_lhs, MachineRepresentation::kFloat64);
VARIABLE(var_fsub_rhs, MachineRepresentation::kFloat64);
Node* context = Parameter(Descriptor::kContext);
var_left->Bind(Parameter(Descriptor::kLeft));
var_right->Bind(Parameter(Descriptor::kRight));
// We might need to loop several times due to ToPrimitive and/or ToNumber
// conversions.
VARIABLE(var_lhs, MachineRepresentation::kTagged);
VARIABLE(var_rhs, MachineRepresentation::kTagged);
VARIABLE(var_result, MachineRepresentation::kTagged);
Variable* loop_vars[2] = {&var_lhs, &var_rhs};
Label loop(this, 2, loop_vars);
var_lhs.Bind(left);
var_rhs.Bind(right);
// We might need to loop for ToNumber conversions.
Label loop(this, {var_left, var_right});
Goto(&loop);
BIND(&loop);
{
// Load the current {lhs} and {rhs} values.
Node* lhs = var_lhs.value();
Node* rhs = var_rhs.value();
// Check if the {lhs} is a Smi or a HeapObject.
Label if_lhsissmi(this), if_lhsisnotsmi(this);
Branch(TaggedIsSmi(lhs), &if_lhsissmi, &if_lhsisnotsmi);
Label left_not_smi(this), right_not_smi(this);
Label left_not_number(this), right_not_number(this);
GotoIfNot(TaggedIsSmi(var_left->value()), &left_not_smi);
GotoIf(TaggedIsSmi(var_right->value()), smis);
BIND(&if_lhsissmi);
{
// Check if the {rhs} is also a Smi.
Label if_rhsissmi(this), if_rhsisnotsmi(this);
Branch(TaggedIsSmi(rhs), &if_rhsissmi, &if_rhsisnotsmi);
// At this point, var_left is a Smi but var_right is not.
GotoIfNot(IsHeapNumber(var_right->value()), &right_not_number);
var_left_double->Bind(SmiToFloat64(var_left->value()));
var_right_double->Bind(LoadHeapNumberValue(var_right->value()));
Goto(doubles);
BIND(&if_rhsissmi);
BIND(&left_not_smi);
{
// Try a fast Smi subtraction first.
Node* pair = IntPtrSubWithOverflow(BitcastTaggedToWord(lhs),
BitcastTaggedToWord(rhs));
Node* overflow = Projection(1, pair);
// Check if the Smi subtraction overflowed.
Label if_overflow(this), if_notoverflow(this);
Branch(overflow, &if_overflow, &if_notoverflow);
GotoIfNot(IsHeapNumber(var_left->value()), &left_not_number);
GotoIfNot(TaggedIsSmi(var_right->value()), &right_not_smi);
BIND(&if_overflow);
{
// The result doesn't fit into Smi range.
var_fsub_lhs.Bind(SmiToFloat64(lhs));
var_fsub_rhs.Bind(SmiToFloat64(rhs));
Goto(&do_fsub);
// At this point, var_left is a HeapNumber and var_right is a Smi.
var_left_double->Bind(LoadHeapNumberValue(var_left->value()));
var_right_double->Bind(SmiToFloat64(var_right->value()));
Goto(doubles);
}
BIND(&if_notoverflow);
var_result.Bind(BitcastWordToTaggedSigned(Projection(0, pair)));
Goto(&end);
}
BIND(&if_rhsisnotsmi);
{
// Load the map of the {rhs}.
Node* rhs_map = LoadMap(rhs);
// Check if {rhs} is a HeapNumber.
Label if_rhsisnumber(this), if_rhsisnotnumber(this, Label::kDeferred);
Branch(IsHeapNumberMap(rhs_map), &if_rhsisnumber, &if_rhsisnotnumber);
BIND(&if_rhsisnumber);
{
// Perform a floating point subtraction.
var_fsub_lhs.Bind(SmiToFloat64(lhs));
var_fsub_rhs.Bind(LoadHeapNumberValue(rhs));
Goto(&do_fsub);
}
BIND(&if_rhsisnotnumber);
{
// Convert the {rhs} to a Number first.
var_rhs.Bind(CallBuiltin(Builtins::kNonNumberToNumber, context, rhs));
Goto(&loop);
}
}
}
BIND(&if_lhsisnotsmi);
{
// Load the map of the {lhs}.
Node* lhs_map = LoadMap(lhs);
// Check if the {lhs} is a HeapNumber.
Label if_lhsisnumber(this), if_lhsisnotnumber(this, Label::kDeferred);
Branch(IsHeapNumberMap(lhs_map), &if_lhsisnumber, &if_lhsisnotnumber);
BIND(&if_lhsisnumber);
{
// Check if the {rhs} is a Smi.
Label if_rhsissmi(this), if_rhsisnotsmi(this);
Branch(TaggedIsSmi(rhs), &if_rhsissmi, &if_rhsisnotsmi);
BIND(&if_rhsissmi);
BIND(&right_not_smi);
{
// Perform a floating point subtraction.
var_fsub_lhs.Bind(LoadHeapNumberValue(lhs));
var_fsub_rhs.Bind(SmiToFloat64(rhs));
Goto(&do_fsub);
GotoIfNot(IsHeapNumber(var_right->value()), &right_not_number);
var_left_double->Bind(LoadHeapNumberValue(var_left->value()));
var_right_double->Bind(LoadHeapNumberValue(var_right->value()));
Goto(doubles);
}
BIND(&if_rhsisnotsmi);
BIND(&left_not_number);
{
// Load the map of the {rhs}.
Node* rhs_map = LoadMap(rhs);
// Check if the {rhs} is a HeapNumber.
Label if_rhsisnumber(this), if_rhsisnotnumber(this, Label::kDeferred);
Branch(IsHeapNumberMap(rhs_map), &if_rhsisnumber, &if_rhsisnotnumber);
BIND(&if_rhsisnumber);
{
// Perform a floating point subtraction.
var_fsub_lhs.Bind(LoadHeapNumberValue(lhs));
var_fsub_rhs.Bind(LoadHeapNumberValue(rhs));
Goto(&do_fsub);
}
BIND(&if_rhsisnotnumber);
{
// Convert the {rhs} to a Number first.
var_rhs.Bind(
CallBuiltin(Builtins::kNonNumberToNumber, context, rhs));
var_left->Bind(
CallBuiltin(Builtins::kNonNumberToNumber, context, var_left->value()));
Goto(&loop);
}
}
}
BIND(&if_lhsisnotnumber);
BIND(&right_not_number);
{
// Convert the {lhs} to a Number first.
var_lhs.Bind(CallBuiltin(Builtins::kNonNumberToNumber, context, lhs));
var_right->Bind(
CallBuiltin(Builtins::kNonNumberToNumber, context, var_right->value()));
Goto(&loop);
}
}
}
BIND(&do_fsub);
{
Node* lhs_value = var_fsub_lhs.value();
Node* rhs_value = var_fsub_rhs.value();
Node* value = Float64Sub(lhs_value, rhs_value);
var_result.Bind(AllocateHeapNumberWithValue(value));
Goto(&end);
}
BIND(&end);
Return(var_result.value());
}
TF_BUILTIN(Multiply, CodeStubAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* left = Parameter(Descriptor::kLeft);
Node* right = Parameter(Descriptor::kRight);
// Shared entry point for floating point multiplication.
Label do_fmul(this), return_result(this);
VARIABLE(var_lhs_float64, MachineRepresentation::kFloat64);
VARIABLE(var_rhs_float64, MachineRepresentation::kFloat64);
// We might need to loop one or two times due to ToNumber conversions.
VARIABLE(var_lhs, MachineRepresentation::kTagged);
VARIABLE(var_rhs, MachineRepresentation::kTagged);
VARIABLE(var_result, MachineRepresentation::kTagged);
Variable* loop_variables[] = {&var_lhs, &var_rhs};
Label loop(this, 2, loop_variables);
var_lhs.Bind(left);
var_rhs.Bind(right);
Goto(&loop);
BIND(&loop);
{
Node* lhs = var_lhs.value();
Node* rhs = var_rhs.value();
TF_BUILTIN(Subtract, NumberBuiltinsAssembler) {
VARIABLE(var_left, MachineRepresentation::kTagged);
VARIABLE(var_right, MachineRepresentation::kTagged);
VARIABLE(var_left_double, MachineRepresentation::kFloat64);
VARIABLE(var_right_double, MachineRepresentation::kFloat64);
Label do_smi_sub(this), do_double_sub(this);
Label lhs_is_smi(this), lhs_is_not_smi(this);
Branch(TaggedIsSmi(lhs), &lhs_is_smi, &lhs_is_not_smi);
BinaryOp<Descriptor>(&do_smi_sub, &var_left, &var_right, &do_double_sub,
&var_left_double, &var_right_double);
BIND(&lhs_is_smi);
BIND(&do_smi_sub);
{
Label rhs_is_smi(this), rhs_is_not_smi(this);
Branch(TaggedIsSmi(rhs), &rhs_is_smi, &rhs_is_not_smi);
// Try a fast Smi subtraction first, bail out if it overflows.
Node* pair = IntPtrSubWithOverflow(BitcastTaggedToWord(var_left.value()),
BitcastTaggedToWord(var_right.value()));
Node* overflow = Projection(1, pair);
Label if_overflow(this), if_notoverflow(this);
Branch(overflow, &if_overflow, &if_notoverflow);
BIND(&rhs_is_smi);
BIND(&if_overflow);
{
// Both {lhs} and {rhs} are Smis. The result is not necessarily a smi,
// in case of overflow.
var_result.Bind(SmiMul(lhs, rhs));
Goto(&return_result);
var_left_double.Bind(SmiToFloat64(var_left.value()));
var_right_double.Bind(SmiToFloat64(var_right.value()));
Goto(&do_double_sub);
}
BIND(&rhs_is_not_smi);
{
Node* rhs_map = LoadMap(rhs);
// Check if {rhs} is a HeapNumber.
Label rhs_is_number(this), rhs_is_not_number(this, Label::kDeferred);
Branch(IsHeapNumberMap(rhs_map), &rhs_is_number, &rhs_is_not_number);
BIND(&rhs_is_number);
{
// Convert {lhs} to a double and multiply it with the value of {rhs}.
var_lhs_float64.Bind(SmiToFloat64(lhs));
var_rhs_float64.Bind(LoadHeapNumberValue(rhs));
Goto(&do_fmul);
BIND(&if_notoverflow);
Return(BitcastWordToTaggedSigned(Projection(0, pair)));
}
BIND(&rhs_is_not_number);
BIND(&do_double_sub);
{
// Multiplication is commutative, swap {lhs} with {rhs} and loop.
var_lhs.Bind(rhs);
var_rhs.Bind(lhs);
Goto(&loop);
}
Node* value = Float64Sub(var_left_double.value(), var_right_double.value());
Return(AllocateHeapNumberWithValue(value));
}
}
BIND(&lhs_is_not_smi);
{
Node* lhs_map = LoadMap(lhs);
// Check if {lhs} is a HeapNumber.
Label lhs_is_number(this), lhs_is_not_number(this, Label::kDeferred);
Branch(IsHeapNumberMap(lhs_map), &lhs_is_number, &lhs_is_not_number);
BIND(&lhs_is_number);
{
// Check if {rhs} is a Smi.
Label rhs_is_smi(this), rhs_is_not_smi(this);
Branch(TaggedIsSmi(rhs), &rhs_is_smi, &rhs_is_not_smi);
BIND(&rhs_is_smi);
{
// Convert {rhs} to a double and multiply it with the value of {lhs}.
var_lhs_float64.Bind(LoadHeapNumberValue(lhs));
var_rhs_float64.Bind(SmiToFloat64(rhs));
Goto(&do_fmul);
}
BIND(&rhs_is_not_smi);
{
Node* rhs_map = LoadMap(rhs);
}
// Check if {rhs} is a HeapNumber.
Label rhs_is_number(this), rhs_is_not_number(this, Label::kDeferred);
Branch(IsHeapNumberMap(rhs_map), &rhs_is_number, &rhs_is_not_number);
TF_BUILTIN(Multiply, NumberBuiltinsAssembler) {
VARIABLE(var_left, MachineRepresentation::kTagged);
VARIABLE(var_right, MachineRepresentation::kTagged);
VARIABLE(var_left_double, MachineRepresentation::kFloat64);
VARIABLE(var_right_double, MachineRepresentation::kFloat64);
Label do_smi_mul(this), do_double_mul(this);
BIND(&rhs_is_number);
{
// Both {lhs} and {rhs} are HeapNumbers. Load their values and
// multiply them.
var_lhs_float64.Bind(LoadHeapNumberValue(lhs));
var_rhs_float64.Bind(LoadHeapNumberValue(rhs));
Goto(&do_fmul);
}
BinaryOp<Descriptor>(&do_smi_mul, &var_left, &var_right, &do_double_mul,
&var_left_double, &var_right_double);
BIND(&rhs_is_not_number);
{
// Multiplication is commutative, swap {lhs} with {rhs} and loop.
var_lhs.Bind(rhs);
var_rhs.Bind(lhs);
Goto(&loop);
}
}
}
BIND(&do_smi_mul);
// The result is not necessarily a smi, in case of overflow.
Return(SmiMul(var_left.value(), var_right.value()));
BIND(&lhs_is_not_number);
{
// Convert {lhs} to a Number and loop.
var_lhs.Bind(CallBuiltin(Builtins::kNonNumberToNumber, context, lhs));
Goto(&loop);
}
}
}
BIND(&do_fmul);
{
Node* value = Float64Mul(var_lhs_float64.value(), var_rhs_float64.value());
Node* result = AllocateHeapNumberWithValue(value);
var_result.Bind(result);
Goto(&return_result);
}
BIND(&return_result);
Return(var_result.value());
BIND(&do_double_mul);
Node* value = Float64Mul(var_left_double.value(), var_right_double.value());
Return(AllocateHeapNumberWithValue(value));
}
TF_BUILTIN(Divide, CodeStubAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* left = Parameter(Descriptor::kLeft);
Node* right = Parameter(Descriptor::kRight);
// Shared entry point for floating point division.
Label do_fdiv(this), end(this);
VARIABLE(var_dividend_float64, MachineRepresentation::kFloat64);
VARIABLE(var_divisor_float64, MachineRepresentation::kFloat64);
TF_BUILTIN(Divide, NumberBuiltinsAssembler) {
VARIABLE(var_left, MachineRepresentation::kTagged);
VARIABLE(var_right, MachineRepresentation::kTagged);
VARIABLE(var_left_double, MachineRepresentation::kFloat64);
VARIABLE(var_right_double, MachineRepresentation::kFloat64);
Label do_smi_div(this), do_double_div(this);
// We might need to loop one or two times due to ToNumber conversions.
VARIABLE(var_dividend, MachineRepresentation::kTagged);
VARIABLE(var_divisor, MachineRepresentation::kTagged);
VARIABLE(var_result, MachineRepresentation::kTagged);
Variable* loop_variables[] = {&var_dividend, &var_divisor};
Label loop(this, 2, loop_variables);
var_dividend.Bind(left);
var_divisor.Bind(right);
Goto(&loop);
BIND(&loop);
{
Node* dividend = var_dividend.value();
Node* divisor = var_divisor.value();
BinaryOp<Descriptor>(&do_smi_div, &var_left, &var_right, &do_double_div,
&var_left_double, &var_right_double);
Label dividend_is_smi(this), dividend_is_not_smi(this);
Branch(TaggedIsSmi(dividend), &dividend_is_smi, &dividend_is_not_smi);
BIND(&dividend_is_smi);
{
Label divisor_is_smi(this), divisor_is_not_smi(this);
Branch(TaggedIsSmi(divisor), &divisor_is_smi, &divisor_is_not_smi);
BIND(&divisor_is_smi);
BIND(&do_smi_div);
{
// TODO(jkummerow): Consider just always doing a double division.
Label bailout(this);
Node* dividend = var_left.value();
Node* divisor = var_right.value();
// Do floating point division if {divisor} is zero.
GotoIf(SmiEqual(divisor, SmiConstant(0)), &bailout);
// Do floating point division {dividend} is zero and {divisor} is
// Do floating point division if {dividend} is zero and {divisor} is
// negative.
Label dividend_is_zero(this), dividend_is_not_zero(this);
Branch(SmiEqual(dividend, SmiConstant(0)), &dividend_is_zero,
......@@ -1046,10 +725,9 @@ TF_BUILTIN(Divide, CodeStubAssembler) {
BIND(&divisor_is_minus_one);
{
GotoIf(
Word32Equal(untagged_dividend,
Int32Constant(kSmiValueSize == 32 ? kMinInt
: (kMinInt >> 1))),
GotoIf(Word32Equal(
untagged_dividend,
Int32Constant(kSmiValueSize == 32 ? kMinInt : (kMinInt >> 1))),
&bailout);
Goto(&divisor_is_not_minus_one);
}
......@@ -1061,268 +739,41 @@ TF_BUILTIN(Divide, CodeStubAssembler) {
Node* truncated = Int32Mul(untagged_result, untagged_divisor);
// Do floating point division if the remainder is not 0.
GotoIf(Word32NotEqual(untagged_dividend, truncated), &bailout);
var_result.Bind(SmiFromWord32(untagged_result));
Goto(&end);
Return(SmiFromWord32(untagged_result));
// Bailout: convert {dividend} and {divisor} to double and do double
// division.
BIND(&bailout);
{
var_dividend_float64.Bind(SmiToFloat64(dividend));
var_divisor_float64.Bind(SmiToFloat64(divisor));
Goto(&do_fdiv);
}
}
BIND(&divisor_is_not_smi);
{
Node* divisor_map = LoadMap(divisor);
// Check if {divisor} is a HeapNumber.
Label divisor_is_number(this),
divisor_is_not_number(this, Label::kDeferred);
Branch(IsHeapNumberMap(divisor_map), &divisor_is_number,
&divisor_is_not_number);
BIND(&divisor_is_number);
{
// Convert {dividend} to a double and divide it with the value of
// {divisor}.
var_dividend_float64.Bind(SmiToFloat64(dividend));
var_divisor_float64.Bind(LoadHeapNumberValue(divisor));
Goto(&do_fdiv);
}
BIND(&divisor_is_not_number);
{
// Convert {divisor} to a number and loop.
var_divisor.Bind(
CallBuiltin(Builtins::kNonNumberToNumber, context, divisor));
Goto(&loop);
}
}
}
BIND(&dividend_is_not_smi);
{
Node* dividend_map = LoadMap(dividend);
// Check if {dividend} is a HeapNumber.
Label dividend_is_number(this),
dividend_is_not_number(this, Label::kDeferred);
Branch(IsHeapNumberMap(dividend_map), &dividend_is_number,
&dividend_is_not_number);
BIND(&dividend_is_number);
{
// Check if {divisor} is a Smi.
Label divisor_is_smi(this), divisor_is_not_smi(this);
Branch(TaggedIsSmi(divisor), &divisor_is_smi, &divisor_is_not_smi);
BIND(&divisor_is_smi);
{
// Convert {divisor} to a double and use it for a floating point
// division.
var_dividend_float64.Bind(LoadHeapNumberValue(dividend));
var_divisor_float64.Bind(SmiToFloat64(divisor));
Goto(&do_fdiv);
var_left_double.Bind(SmiToFloat64(dividend));
var_right_double.Bind(SmiToFloat64(divisor));
Goto(&do_double_div);
}
BIND(&divisor_is_not_smi);
{
Node* divisor_map = LoadMap(divisor);
// Check if {divisor} is a HeapNumber.
Label divisor_is_number(this),
divisor_is_not_number(this, Label::kDeferred);
Branch(IsHeapNumberMap(divisor_map), &divisor_is_number,
&divisor_is_not_number);
BIND(&divisor_is_number);
{
// Both {dividend} and {divisor} are HeapNumbers. Load their values
// and divide them.
var_dividend_float64.Bind(LoadHeapNumberValue(dividend));
var_divisor_float64.Bind(LoadHeapNumberValue(divisor));
Goto(&do_fdiv);
}
BIND(&divisor_is_not_number);
BIND(&do_double_div);
{
// Convert {divisor} to a number and loop.
var_divisor.Bind(
CallBuiltin(Builtins::kNonNumberToNumber, context, divisor));
Goto(&loop);
}
Node* value = Float64Div(var_left_double.value(), var_right_double.value());
Return(AllocateHeapNumberWithValue(value));
}
}
BIND(&dividend_is_not_number);
{
// Convert {dividend} to a Number and loop.
var_dividend.Bind(
CallBuiltin(Builtins::kNonNumberToNumber, context, dividend));
Goto(&loop);
}
}
}
BIND(&do_fdiv);
{
Node* value =
Float64Div(var_dividend_float64.value(), var_divisor_float64.value());
var_result.Bind(AllocateHeapNumberWithValue(value));
Goto(&end);
}
BIND(&end);
Return(var_result.value());
}
TF_BUILTIN(Modulus, CodeStubAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* left = Parameter(Descriptor::kLeft);
Node* right = Parameter(Descriptor::kRight);
VARIABLE(var_result, MachineRepresentation::kTagged);
Label return_result(this, &var_result);
// Shared entry point for floating point modulus.
Label do_fmod(this);
VARIABLE(var_dividend_float64, MachineRepresentation::kFloat64);
VARIABLE(var_divisor_float64, MachineRepresentation::kFloat64);
// We might need to loop one or two times due to ToNumber conversions.
VARIABLE(var_dividend, MachineRepresentation::kTagged);
VARIABLE(var_divisor, MachineRepresentation::kTagged);
Variable* loop_variables[] = {&var_dividend, &var_divisor};
Label loop(this, 2, loop_variables);
var_dividend.Bind(left);
var_divisor.Bind(right);
Goto(&loop);
BIND(&loop);
{
Node* dividend = var_dividend.value();
Node* divisor = var_divisor.value();
Label dividend_is_smi(this), dividend_is_not_smi(this);
Branch(TaggedIsSmi(dividend), &dividend_is_smi, &dividend_is_not_smi);
BIND(&dividend_is_smi);
{
Label dividend_is_not_zero(this);
Label divisor_is_smi(this), divisor_is_not_smi(this);
Branch(TaggedIsSmi(divisor), &divisor_is_smi, &divisor_is_not_smi);
TF_BUILTIN(Modulus, NumberBuiltinsAssembler) {
VARIABLE(var_left, MachineRepresentation::kTagged);
VARIABLE(var_right, MachineRepresentation::kTagged);
VARIABLE(var_left_double, MachineRepresentation::kFloat64);
VARIABLE(var_right_double, MachineRepresentation::kFloat64);
Label do_smi_mod(this), do_double_mod(this);
BIND(&divisor_is_smi);
{
// Compute the modulus of two Smis.
var_result.Bind(SmiMod(dividend, divisor));
Goto(&return_result);
}
BinaryOp<Descriptor>(&do_smi_mod, &var_left, &var_right, &do_double_mod,
&var_left_double, &var_right_double);
BIND(&divisor_is_not_smi);
{
Node* divisor_map = LoadMap(divisor);
// Check if {divisor} is a HeapNumber.
Label divisor_is_number(this),
divisor_is_not_number(this, Label::kDeferred);
Branch(IsHeapNumberMap(divisor_map), &divisor_is_number,
&divisor_is_not_number);
BIND(&divisor_is_number);
{
// Convert {dividend} to a double and compute its modulus with the
// value of {dividend}.
var_dividend_float64.Bind(SmiToFloat64(dividend));
var_divisor_float64.Bind(LoadHeapNumberValue(divisor));
Goto(&do_fmod);
}
BIND(&divisor_is_not_number);
{
// Convert {divisor} to a number and loop.
var_divisor.Bind(
CallBuiltin(Builtins::kNonNumberToNumber, context, divisor));
Goto(&loop);
}
}
}
BIND(&dividend_is_not_smi);
{
Node* dividend_map = LoadMap(dividend);
// Check if {dividend} is a HeapNumber.
Label dividend_is_number(this),
dividend_is_not_number(this, Label::kDeferred);
Branch(IsHeapNumberMap(dividend_map), &dividend_is_number,
&dividend_is_not_number);
BIND(&dividend_is_number);
{
// Check if {divisor} is a Smi.
Label divisor_is_smi(this), divisor_is_not_smi(this);
Branch(TaggedIsSmi(divisor), &divisor_is_smi, &divisor_is_not_smi);
BIND(&divisor_is_smi);
{
// Convert {divisor} to a double and compute {dividend}'s modulus with
// it.
var_dividend_float64.Bind(LoadHeapNumberValue(dividend));
var_divisor_float64.Bind(SmiToFloat64(divisor));
Goto(&do_fmod);
}
BIND(&divisor_is_not_smi);
{
Node* divisor_map = LoadMap(divisor);
// Check if {divisor} is a HeapNumber.
Label divisor_is_number(this),
divisor_is_not_number(this, Label::kDeferred);
Branch(IsHeapNumberMap(divisor_map), &divisor_is_number,
&divisor_is_not_number);
BIND(&divisor_is_number);
{
// Both {dividend} and {divisor} are HeapNumbers. Load their values
// and compute their modulus.
var_dividend_float64.Bind(LoadHeapNumberValue(dividend));
var_divisor_float64.Bind(LoadHeapNumberValue(divisor));
Goto(&do_fmod);
}
BIND(&divisor_is_not_number);
{
// Convert {divisor} to a number and loop.
var_divisor.Bind(
CallBuiltin(Builtins::kNonNumberToNumber, context, divisor));
Goto(&loop);
}
}
}
BIND(&dividend_is_not_number);
{
// Convert {dividend} to a Number and loop.
var_dividend.Bind(
CallBuiltin(Builtins::kNonNumberToNumber, context, dividend));
Goto(&loop);
}
}
}
BIND(&do_fmod);
{
Node* value =
Float64Mod(var_dividend_float64.value(), var_divisor_float64.value());
var_result.Bind(AllocateHeapNumberWithValue(value));
Goto(&return_result);
}
BIND(&do_smi_mod);
Return(SmiMod(var_left.value(), var_right.value()));
BIND(&return_result);
Return(var_result.value());
BIND(&do_double_mod);
Node* value = Float64Mod(var_left_double.value(), var_right_double.value());
Return(AllocateHeapNumberWithValue(value));
}
TF_BUILTIN(ShiftLeft, NumberBuiltinsAssembler) {
......
......@@ -244,7 +244,8 @@ class Config(object):
return_code, output = _CallWithOutput("ninja -C %s %s %s" %
(path, BUILD_OPTS, targets))
if return_code != 0 and "FAILED: gen/snapshot.cc" in output:
print("Detected mksnapshot failure, re-running in GDB...")
_Notify("V8 build requires your attention",
"Detected mksnapshot failure, re-running in GDB...")
_Call("gdb -args %(path)s/mksnapshot "
"--startup_src %(path)s/gen/snapshot.cc "
"--random-seed 314159265 "
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment