Commit 40aed979 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[stubs] Cleanup binary op stubs.

... and introduce BinaryOpAssembler.

BUG=v8:6116

Change-Id: I86b0afedbe6ac11fda286b877fe55cda746f5347
Reviewed-on: https://chromium-review.googlesource.com/458278
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44029}
parent e27d18c9
......@@ -491,966 +491,906 @@ TF_STUB(StringLengthStub, CodeStubAssembler) {
Return(result);
}
#define BINARY_OP_STUB(StubName) \
TF_STUB(StubName, CodeStubAssembler) { \
Return(StubName::Generate( \
this, Parameter(Descriptor::kLeft), Parameter(Descriptor::kRight), \
ChangeUint32ToWord(Parameter(Descriptor::kSlot)), \
Parameter(Descriptor::kVector), Parameter(Descriptor::kContext))); \
}
// TODO(ishell): don't have to be stubs. Move generators to BinaryOpICAssembler.
BINARY_OP_STUB(AddWithFeedbackStub)
BINARY_OP_STUB(SubtractWithFeedbackStub)
BINARY_OP_STUB(MultiplyWithFeedbackStub)
BINARY_OP_STUB(DivideWithFeedbackStub)
BINARY_OP_STUB(ModulusWithFeedbackStub)
#undef BINARY_OP_STUB
// static
compiler::Node* AddWithFeedbackStub::Generate(CodeStubAssembler* assembler,
compiler::Node* lhs,
compiler::Node* rhs,
compiler::Node* slot_id,
compiler::Node* feedback_vector,
compiler::Node* context) {
typedef CodeStubAssembler::Label Label;
// TODO(ishell): Move to appropriate file.
class BinaryOpAssembler : public CodeStubAssembler {
public:
typedef compiler::Node Node;
typedef CodeStubAssembler::Variable Variable;
explicit BinaryOpAssembler(compiler::CodeAssemblerState* state)
: CodeStubAssembler(state) {}
void GenerateConstructor(Node* context, Node* array_function, Node* array_map,
Node* array_size, Node* allocation_site,
ElementsKind elements_kind, AllocationSiteMode mode);
Node* Generate_AddWithFeedback(Node* context, Node* lhs, Node* rhs,
Node* slot_id, Node* feedback_vector);
Node* Generate_SubtractWithFeedback(Node* context, Node* lhs, Node* rhs,
Node* slot_id, Node* feedback_vector);
Node* Generate_MultiplyWithFeedback(Node* context, Node* lhs, Node* rhs,
Node* slot_id, Node* feedback_vector);
Node* Generate_DivideWithFeedback(Node* context, Node* dividend,
Node* divisor, Node* slot_id,
Node* feedback_vector);
Node* Generate_ModulusWithFeedback(Node* context, Node* dividend,
Node* divisor, Node* slot_id,
Node* feedback_vector);
};
compiler::Node* BinaryOpAssembler::Generate_AddWithFeedback(
Node* context, Node* lhs, Node* rhs, Node* slot_id, Node* feedback_vector) {
// Shared entry for floating point addition.
Label do_fadd(assembler), if_lhsisnotnumber(assembler, Label::kDeferred),
check_rhsisoddball(assembler, Label::kDeferred),
call_with_oddball_feedback(assembler), call_with_any_feedback(assembler),
call_add_stub(assembler), end(assembler);
Variable var_fadd_lhs(assembler, MachineRepresentation::kFloat64),
var_fadd_rhs(assembler, MachineRepresentation::kFloat64),
var_type_feedback(assembler, MachineRepresentation::kTaggedSigned),
var_result(assembler, MachineRepresentation::kTagged);
Label do_fadd(this), if_lhsisnotnumber(this, Label::kDeferred),
check_rhsisoddball(this, Label::kDeferred),
call_with_oddball_feedback(this), call_with_any_feedback(this),
call_add_stub(this), end(this);
Variable var_fadd_lhs(this, MachineRepresentation::kFloat64),
var_fadd_rhs(this, MachineRepresentation::kFloat64),
var_type_feedback(this, MachineRepresentation::kTaggedSigned),
var_result(this, MachineRepresentation::kTagged);
// Check if the {lhs} is a Smi or a HeapObject.
Label if_lhsissmi(assembler), if_lhsisnotsmi(assembler);
assembler->Branch(assembler->TaggedIsSmi(lhs), &if_lhsissmi, &if_lhsisnotsmi);
Label if_lhsissmi(this), if_lhsisnotsmi(this);
Branch(TaggedIsSmi(lhs), &if_lhsissmi, &if_lhsisnotsmi);
assembler->Bind(&if_lhsissmi);
Bind(&if_lhsissmi);
{
// Check if the {rhs} is also a Smi.
Label if_rhsissmi(assembler), if_rhsisnotsmi(assembler);
assembler->Branch(assembler->TaggedIsSmi(rhs), &if_rhsissmi,
&if_rhsisnotsmi);
Label if_rhsissmi(this), if_rhsisnotsmi(this);
Branch(TaggedIsSmi(rhs), &if_rhsissmi, &if_rhsisnotsmi);
assembler->Bind(&if_rhsissmi);
Bind(&if_rhsissmi);
{
// Try fast Smi addition first.
Node* pair =
assembler->IntPtrAddWithOverflow(assembler->BitcastTaggedToWord(lhs),
assembler->BitcastTaggedToWord(rhs));
Node* overflow = assembler->Projection(1, pair);
Node* pair = IntPtrAddWithOverflow(BitcastTaggedToWord(lhs),
BitcastTaggedToWord(rhs));
Node* overflow = Projection(1, pair);
// Check if the Smi additon overflowed.
Label if_overflow(assembler), if_notoverflow(assembler);
assembler->Branch(overflow, &if_overflow, &if_notoverflow);
Label if_overflow(this), if_notoverflow(this);
Branch(overflow, &if_overflow, &if_notoverflow);
assembler->Bind(&if_overflow);
Bind(&if_overflow);
{
var_fadd_lhs.Bind(assembler->SmiToFloat64(lhs));
var_fadd_rhs.Bind(assembler->SmiToFloat64(rhs));
assembler->Goto(&do_fadd);
var_fadd_lhs.Bind(SmiToFloat64(lhs));
var_fadd_rhs.Bind(SmiToFloat64(rhs));
Goto(&do_fadd);
}
assembler->Bind(&if_notoverflow);
Bind(&if_notoverflow);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kSignedSmall));
var_result.Bind(assembler->BitcastWordToTaggedSigned(
assembler->Projection(0, pair)));
assembler->Goto(&end);
SmiConstant(BinaryOperationFeedback::kSignedSmall));
var_result.Bind(BitcastWordToTaggedSigned(Projection(0, pair)));
Goto(&end);
}
}
assembler->Bind(&if_rhsisnotsmi);
Bind(&if_rhsisnotsmi);
{
// Load the map of {rhs}.
Node* rhs_map = assembler->LoadMap(rhs);
Node* rhs_map = LoadMap(rhs);
// Check if the {rhs} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(rhs_map),
&check_rhsisoddball);
GotoIfNot(IsHeapNumberMap(rhs_map), &check_rhsisoddball);
var_fadd_lhs.Bind(assembler->SmiToFloat64(lhs));
var_fadd_rhs.Bind(assembler->LoadHeapNumberValue(rhs));
assembler->Goto(&do_fadd);
var_fadd_lhs.Bind(SmiToFloat64(lhs));
var_fadd_rhs.Bind(LoadHeapNumberValue(rhs));
Goto(&do_fadd);
}
}
assembler->Bind(&if_lhsisnotsmi);
Bind(&if_lhsisnotsmi);
{
// Load the map of {lhs}.
Node* lhs_map = assembler->LoadMap(lhs);
Node* lhs_map = LoadMap(lhs);
// Check if {lhs} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(lhs_map),
&if_lhsisnotnumber);
GotoIfNot(IsHeapNumberMap(lhs_map), &if_lhsisnotnumber);
// Check if the {rhs} is Smi.
Label if_rhsissmi(assembler), if_rhsisnotsmi(assembler);
assembler->Branch(assembler->TaggedIsSmi(rhs), &if_rhsissmi,
&if_rhsisnotsmi);
Label if_rhsissmi(this), if_rhsisnotsmi(this);
Branch(TaggedIsSmi(rhs), &if_rhsissmi, &if_rhsisnotsmi);
assembler->Bind(&if_rhsissmi);
Bind(&if_rhsissmi);
{
var_fadd_lhs.Bind(assembler->LoadHeapNumberValue(lhs));
var_fadd_rhs.Bind(assembler->SmiToFloat64(rhs));
assembler->Goto(&do_fadd);
var_fadd_lhs.Bind(LoadHeapNumberValue(lhs));
var_fadd_rhs.Bind(SmiToFloat64(rhs));
Goto(&do_fadd);
}
assembler->Bind(&if_rhsisnotsmi);
Bind(&if_rhsisnotsmi);
{
// Load the map of {rhs}.
Node* rhs_map = assembler->LoadMap(rhs);
Node* rhs_map = LoadMap(rhs);
// Check if the {rhs} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(rhs_map),
&check_rhsisoddball);
GotoIfNot(IsHeapNumberMap(rhs_map), &check_rhsisoddball);
var_fadd_lhs.Bind(assembler->LoadHeapNumberValue(lhs));
var_fadd_rhs.Bind(assembler->LoadHeapNumberValue(rhs));
assembler->Goto(&do_fadd);
var_fadd_lhs.Bind(LoadHeapNumberValue(lhs));
var_fadd_rhs.Bind(LoadHeapNumberValue(rhs));
Goto(&do_fadd);
}
}
assembler->Bind(&do_fadd);
Bind(&do_fadd);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kNumber));
Node* value =
assembler->Float64Add(var_fadd_lhs.value(), var_fadd_rhs.value());
Node* result = assembler->AllocateHeapNumberWithValue(value);
var_type_feedback.Bind(SmiConstant(BinaryOperationFeedback::kNumber));
Node* value = Float64Add(var_fadd_lhs.value(), var_fadd_rhs.value());
Node* result = AllocateHeapNumberWithValue(value);
var_result.Bind(result);
assembler->Goto(&end);
Goto(&end);
}
assembler->Bind(&if_lhsisnotnumber);
Bind(&if_lhsisnotnumber);
{
// No checks on rhs are done yet. We just know lhs is not a number or Smi.
Label if_lhsisoddball(assembler), if_lhsisnotoddball(assembler);
Node* lhs_instance_type = assembler->LoadInstanceType(lhs);
Node* lhs_is_oddball = assembler->Word32Equal(
lhs_instance_type, assembler->Int32Constant(ODDBALL_TYPE));
assembler->Branch(lhs_is_oddball, &if_lhsisoddball, &if_lhsisnotoddball);
Label if_lhsisoddball(this), if_lhsisnotoddball(this);
Node* lhs_instance_type = LoadInstanceType(lhs);
Node* lhs_is_oddball =
Word32Equal(lhs_instance_type, Int32Constant(ODDBALL_TYPE));
Branch(lhs_is_oddball, &if_lhsisoddball, &if_lhsisnotoddball);
assembler->Bind(&if_lhsisoddball);
Bind(&if_lhsisoddball);
{
assembler->GotoIf(assembler->TaggedIsSmi(rhs),
&call_with_oddball_feedback);
GotoIf(TaggedIsSmi(rhs), &call_with_oddball_feedback);
// Load the map of the {rhs}.
Node* rhs_map = assembler->LoadMap(rhs);
Node* rhs_map = LoadMap(rhs);
// Check if {rhs} is a HeapNumber.
assembler->Branch(assembler->IsHeapNumberMap(rhs_map),
&call_with_oddball_feedback, &check_rhsisoddball);
Branch(IsHeapNumberMap(rhs_map), &call_with_oddball_feedback,
&check_rhsisoddball);
}
assembler->Bind(&if_lhsisnotoddball);
Bind(&if_lhsisnotoddball);
{
// Exit unless {lhs} is a string
assembler->GotoIfNot(assembler->IsStringInstanceType(lhs_instance_type),
&call_with_any_feedback);
GotoIfNot(IsStringInstanceType(lhs_instance_type),
&call_with_any_feedback);
// Check if the {rhs} is a smi, and exit the string check early if it is.
assembler->GotoIf(assembler->TaggedIsSmi(rhs), &call_with_any_feedback);
GotoIf(TaggedIsSmi(rhs), &call_with_any_feedback);
Node* rhs_instance_type = assembler->LoadInstanceType(rhs);
Node* rhs_instance_type = LoadInstanceType(rhs);
// Exit unless {rhs} is a string. Since {lhs} is a string we no longer
// need an Oddball check.
assembler->GotoIfNot(assembler->IsStringInstanceType(rhs_instance_type),
&call_with_any_feedback);
GotoIfNot(IsStringInstanceType(rhs_instance_type),
&call_with_any_feedback);
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kString));
Callable callable = CodeFactory::StringAdd(
assembler->isolate(), STRING_ADD_CHECK_NONE, NOT_TENURED);
var_result.Bind(assembler->CallStub(callable, context, lhs, rhs));
var_type_feedback.Bind(SmiConstant(BinaryOperationFeedback::kString));
Callable callable =
CodeFactory::StringAdd(isolate(), STRING_ADD_CHECK_NONE, NOT_TENURED);
var_result.Bind(CallStub(callable, context, lhs, rhs));
assembler->Goto(&end);
Goto(&end);
}
}
assembler->Bind(&check_rhsisoddball);
Bind(&check_rhsisoddball);
{
// Check if rhs is an oddball. At this point we know lhs is either a
// Smi or number or oddball and rhs is not a number or Smi.
Node* rhs_instance_type = assembler->LoadInstanceType(rhs);
Node* rhs_is_oddball = assembler->Word32Equal(
rhs_instance_type, assembler->Int32Constant(ODDBALL_TYPE));
assembler->Branch(rhs_is_oddball, &call_with_oddball_feedback,
&call_with_any_feedback);
Node* rhs_instance_type = LoadInstanceType(rhs);
Node* rhs_is_oddball =
Word32Equal(rhs_instance_type, Int32Constant(ODDBALL_TYPE));
Branch(rhs_is_oddball, &call_with_oddball_feedback,
&call_with_any_feedback);
}
assembler->Bind(&call_with_oddball_feedback);
Bind(&call_with_oddball_feedback);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kNumberOrOddball));
assembler->Goto(&call_add_stub);
SmiConstant(BinaryOperationFeedback::kNumberOrOddball));
Goto(&call_add_stub);
}
assembler->Bind(&call_with_any_feedback);
Bind(&call_with_any_feedback);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kAny));
assembler->Goto(&call_add_stub);
var_type_feedback.Bind(SmiConstant(BinaryOperationFeedback::kAny));
Goto(&call_add_stub);
}
assembler->Bind(&call_add_stub);
Bind(&call_add_stub);
{
Callable callable = CodeFactory::Add(assembler->isolate());
var_result.Bind(assembler->CallStub(callable, context, lhs, rhs));
assembler->Goto(&end);
Callable callable = CodeFactory::Add(isolate());
var_result.Bind(CallStub(callable, context, lhs, rhs));
Goto(&end);
}
assembler->Bind(&end);
assembler->UpdateFeedback(var_type_feedback.value(), feedback_vector,
slot_id);
Bind(&end);
UpdateFeedback(var_type_feedback.value(), feedback_vector, slot_id);
return var_result.value();
}
// static
compiler::Node* SubtractWithFeedbackStub::Generate(
CodeStubAssembler* assembler, compiler::Node* lhs, compiler::Node* rhs,
compiler::Node* slot_id, compiler::Node* feedback_vector,
compiler::Node* context) {
typedef CodeStubAssembler::Label Label;
typedef compiler::Node Node;
typedef CodeStubAssembler::Variable Variable;
compiler::Node* BinaryOpAssembler::Generate_SubtractWithFeedback(
Node* context, Node* lhs, Node* rhs, Node* slot_id, Node* feedback_vector) {
// Shared entry for floating point subtraction.
Label do_fsub(assembler), end(assembler), call_subtract_stub(assembler),
if_lhsisnotnumber(assembler), check_rhsisoddball(assembler),
call_with_any_feedback(assembler);
Variable var_fsub_lhs(assembler, MachineRepresentation::kFloat64),
var_fsub_rhs(assembler, MachineRepresentation::kFloat64),
var_type_feedback(assembler, MachineRepresentation::kTaggedSigned),
var_result(assembler, MachineRepresentation::kTagged);
Label do_fsub(this), end(this), call_subtract_stub(this),
if_lhsisnotnumber(this), check_rhsisoddball(this),
call_with_any_feedback(this);
Variable var_fsub_lhs(this, MachineRepresentation::kFloat64),
var_fsub_rhs(this, MachineRepresentation::kFloat64),
var_type_feedback(this, MachineRepresentation::kTaggedSigned),
var_result(this, MachineRepresentation::kTagged);
// Check if the {lhs} is a Smi or a HeapObject.
Label if_lhsissmi(assembler), if_lhsisnotsmi(assembler);
assembler->Branch(assembler->TaggedIsSmi(lhs), &if_lhsissmi, &if_lhsisnotsmi);
Label if_lhsissmi(this), if_lhsisnotsmi(this);
Branch(TaggedIsSmi(lhs), &if_lhsissmi, &if_lhsisnotsmi);
assembler->Bind(&if_lhsissmi);
Bind(&if_lhsissmi);
{
// Check if the {rhs} is also a Smi.
Label if_rhsissmi(assembler), if_rhsisnotsmi(assembler);
assembler->Branch(assembler->TaggedIsSmi(rhs), &if_rhsissmi,
&if_rhsisnotsmi);
Label if_rhsissmi(this), if_rhsisnotsmi(this);
Branch(TaggedIsSmi(rhs), &if_rhsissmi, &if_rhsisnotsmi);
assembler->Bind(&if_rhsissmi);
Bind(&if_rhsissmi);
{
// Try a fast Smi subtraction first.
Node* pair =
assembler->IntPtrSubWithOverflow(assembler->BitcastTaggedToWord(lhs),
assembler->BitcastTaggedToWord(rhs));
Node* overflow = assembler->Projection(1, pair);
Node* pair = IntPtrSubWithOverflow(BitcastTaggedToWord(lhs),
BitcastTaggedToWord(rhs));
Node* overflow = Projection(1, pair);
// Check if the Smi subtraction overflowed.
Label if_overflow(assembler), if_notoverflow(assembler);
assembler->Branch(overflow, &if_overflow, &if_notoverflow);
Label if_overflow(this), if_notoverflow(this);
Branch(overflow, &if_overflow, &if_notoverflow);
assembler->Bind(&if_overflow);
Bind(&if_overflow);
{
// lhs, rhs - smi and result - number. combined - number.
// The result doesn't fit into Smi range.
var_fsub_lhs.Bind(assembler->SmiToFloat64(lhs));
var_fsub_rhs.Bind(assembler->SmiToFloat64(rhs));
assembler->Goto(&do_fsub);
var_fsub_lhs.Bind(SmiToFloat64(lhs));
var_fsub_rhs.Bind(SmiToFloat64(rhs));
Goto(&do_fsub);
}
assembler->Bind(&if_notoverflow);
Bind(&if_notoverflow);
// lhs, rhs, result smi. combined - smi.
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kSignedSmall));
var_result.Bind(
assembler->BitcastWordToTaggedSigned(assembler->Projection(0, pair)));
assembler->Goto(&end);
SmiConstant(BinaryOperationFeedback::kSignedSmall));
var_result.Bind(BitcastWordToTaggedSigned(Projection(0, pair)));
Goto(&end);
}
assembler->Bind(&if_rhsisnotsmi);
Bind(&if_rhsisnotsmi);
{
// Load the map of the {rhs}.
Node* rhs_map = assembler->LoadMap(rhs);
Node* rhs_map = LoadMap(rhs);
// Check if {rhs} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(rhs_map),
&check_rhsisoddball);
GotoIfNot(IsHeapNumberMap(rhs_map), &check_rhsisoddball);
// Perform a floating point subtraction.
var_fsub_lhs.Bind(assembler->SmiToFloat64(lhs));
var_fsub_rhs.Bind(assembler->LoadHeapNumberValue(rhs));
assembler->Goto(&do_fsub);
var_fsub_lhs.Bind(SmiToFloat64(lhs));
var_fsub_rhs.Bind(LoadHeapNumberValue(rhs));
Goto(&do_fsub);
}
}
assembler->Bind(&if_lhsisnotsmi);
Bind(&if_lhsisnotsmi);
{
// Load the map of the {lhs}.
Node* lhs_map = assembler->LoadMap(lhs);
Node* lhs_map = LoadMap(lhs);
// Check if the {lhs} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(lhs_map),
&if_lhsisnotnumber);
GotoIfNot(IsHeapNumberMap(lhs_map), &if_lhsisnotnumber);
// Check if the {rhs} is a Smi.
Label if_rhsissmi(assembler), if_rhsisnotsmi(assembler);
assembler->Branch(assembler->TaggedIsSmi(rhs), &if_rhsissmi,
&if_rhsisnotsmi);
Label if_rhsissmi(this), if_rhsisnotsmi(this);
Branch(TaggedIsSmi(rhs), &if_rhsissmi, &if_rhsisnotsmi);
assembler->Bind(&if_rhsissmi);
Bind(&if_rhsissmi);
{
// Perform a floating point subtraction.
var_fsub_lhs.Bind(assembler->LoadHeapNumberValue(lhs));
var_fsub_rhs.Bind(assembler->SmiToFloat64(rhs));
assembler->Goto(&do_fsub);
var_fsub_lhs.Bind(LoadHeapNumberValue(lhs));
var_fsub_rhs.Bind(SmiToFloat64(rhs));
Goto(&do_fsub);
}
assembler->Bind(&if_rhsisnotsmi);
Bind(&if_rhsisnotsmi);
{
// Load the map of the {rhs}.
Node* rhs_map = assembler->LoadMap(rhs);
Node* rhs_map = LoadMap(rhs);
// Check if the {rhs} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(rhs_map),
&check_rhsisoddball);
GotoIfNot(IsHeapNumberMap(rhs_map), &check_rhsisoddball);
// Perform a floating point subtraction.
var_fsub_lhs.Bind(assembler->LoadHeapNumberValue(lhs));
var_fsub_rhs.Bind(assembler->LoadHeapNumberValue(rhs));
assembler->Goto(&do_fsub);
var_fsub_lhs.Bind(LoadHeapNumberValue(lhs));
var_fsub_rhs.Bind(LoadHeapNumberValue(rhs));
Goto(&do_fsub);
}
}
assembler->Bind(&do_fsub);
Bind(&do_fsub);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kNumber));
var_type_feedback.Bind(SmiConstant(BinaryOperationFeedback::kNumber));
Node* lhs_value = var_fsub_lhs.value();
Node* rhs_value = var_fsub_rhs.value();
Node* value = assembler->Float64Sub(lhs_value, rhs_value);
var_result.Bind(assembler->AllocateHeapNumberWithValue(value));
assembler->Goto(&end);
Node* value = Float64Sub(lhs_value, rhs_value);
var_result.Bind(AllocateHeapNumberWithValue(value));
Goto(&end);
}
assembler->Bind(&if_lhsisnotnumber);
Bind(&if_lhsisnotnumber);
{
// No checks on rhs are done yet. We just know lhs is not a number or Smi.
// Check if lhs is an oddball.
Node* lhs_instance_type = assembler->LoadInstanceType(lhs);
Node* lhs_is_oddball = assembler->Word32Equal(
lhs_instance_type, assembler->Int32Constant(ODDBALL_TYPE));
assembler->GotoIfNot(lhs_is_oddball, &call_with_any_feedback);
Node* lhs_instance_type = LoadInstanceType(lhs);
Node* lhs_is_oddball =
Word32Equal(lhs_instance_type, Int32Constant(ODDBALL_TYPE));
GotoIfNot(lhs_is_oddball, &call_with_any_feedback);
Label if_rhsissmi(assembler), if_rhsisnotsmi(assembler);
assembler->Branch(assembler->TaggedIsSmi(rhs), &if_rhsissmi,
&if_rhsisnotsmi);
Label if_rhsissmi(this), if_rhsisnotsmi(this);
Branch(TaggedIsSmi(rhs), &if_rhsissmi, &if_rhsisnotsmi);
assembler->Bind(&if_rhsissmi);
Bind(&if_rhsissmi);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kNumberOrOddball));
assembler->Goto(&call_subtract_stub);
SmiConstant(BinaryOperationFeedback::kNumberOrOddball));
Goto(&call_subtract_stub);
}
assembler->Bind(&if_rhsisnotsmi);
Bind(&if_rhsisnotsmi);
{
// Load the map of the {rhs}.
Node* rhs_map = assembler->LoadMap(rhs);
Node* rhs_map = LoadMap(rhs);
// Check if {rhs} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(rhs_map),
&check_rhsisoddball);
GotoIfNot(IsHeapNumberMap(rhs_map), &check_rhsisoddball);
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kNumberOrOddball));
assembler->Goto(&call_subtract_stub);
SmiConstant(BinaryOperationFeedback::kNumberOrOddball));
Goto(&call_subtract_stub);
}
}
assembler->Bind(&check_rhsisoddball);
Bind(&check_rhsisoddball);
{
// Check if rhs is an oddball. At this point we know lhs is either a
// Smi or number or oddball and rhs is not a number or Smi.
Node* rhs_instance_type = assembler->LoadInstanceType(rhs);
Node* rhs_is_oddball = assembler->Word32Equal(
rhs_instance_type, assembler->Int32Constant(ODDBALL_TYPE));
assembler->GotoIfNot(rhs_is_oddball, &call_with_any_feedback);
Node* rhs_instance_type = LoadInstanceType(rhs);
Node* rhs_is_oddball =
Word32Equal(rhs_instance_type, Int32Constant(ODDBALL_TYPE));
GotoIfNot(rhs_is_oddball, &call_with_any_feedback);
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kNumberOrOddball));
assembler->Goto(&call_subtract_stub);
SmiConstant(BinaryOperationFeedback::kNumberOrOddball));
Goto(&call_subtract_stub);
}
assembler->Bind(&call_with_any_feedback);
Bind(&call_with_any_feedback);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kAny));
assembler->Goto(&call_subtract_stub);
var_type_feedback.Bind(SmiConstant(BinaryOperationFeedback::kAny));
Goto(&call_subtract_stub);
}
assembler->Bind(&call_subtract_stub);
Bind(&call_subtract_stub);
{
Callable callable = CodeFactory::Subtract(assembler->isolate());
var_result.Bind(assembler->CallStub(callable, context, lhs, rhs));
assembler->Goto(&end);
Callable callable = CodeFactory::Subtract(isolate());
var_result.Bind(CallStub(callable, context, lhs, rhs));
Goto(&end);
}
assembler->Bind(&end);
assembler->UpdateFeedback(var_type_feedback.value(), feedback_vector,
slot_id);
Bind(&end);
UpdateFeedback(var_type_feedback.value(), feedback_vector, slot_id);
return var_result.value();
}
// static
compiler::Node* MultiplyWithFeedbackStub::Generate(
CodeStubAssembler* assembler, compiler::Node* lhs, compiler::Node* rhs,
compiler::Node* slot_id, compiler::Node* feedback_vector,
compiler::Node* context) {
using compiler::Node;
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
compiler::Node* BinaryOpAssembler::Generate_MultiplyWithFeedback(
Node* context, Node* lhs, Node* rhs, Node* slot_id, Node* feedback_vector) {
// Shared entry point for floating point multiplication.
Label do_fmul(assembler), if_lhsisnotnumber(assembler, Label::kDeferred),
check_rhsisoddball(assembler, Label::kDeferred),
call_with_oddball_feedback(assembler), call_with_any_feedback(assembler),
call_multiply_stub(assembler), end(assembler);
Variable var_lhs_float64(assembler, MachineRepresentation::kFloat64),
var_rhs_float64(assembler, MachineRepresentation::kFloat64),
var_result(assembler, MachineRepresentation::kTagged),
var_type_feedback(assembler, MachineRepresentation::kTaggedSigned);
Label lhs_is_smi(assembler), lhs_is_not_smi(assembler);
assembler->Branch(assembler->TaggedIsSmi(lhs), &lhs_is_smi, &lhs_is_not_smi);
assembler->Bind(&lhs_is_smi);
Label do_fmul(this), if_lhsisnotnumber(this, Label::kDeferred),
check_rhsisoddball(this, Label::kDeferred),
call_with_oddball_feedback(this), call_with_any_feedback(this),
call_multiply_stub(this), end(this);
Variable var_lhs_float64(this, MachineRepresentation::kFloat64),
var_rhs_float64(this, MachineRepresentation::kFloat64),
var_result(this, MachineRepresentation::kTagged),
var_type_feedback(this, MachineRepresentation::kTaggedSigned);
Label lhs_is_smi(this), lhs_is_not_smi(this);
Branch(TaggedIsSmi(lhs), &lhs_is_smi, &lhs_is_not_smi);
Bind(&lhs_is_smi);
{
Label rhs_is_smi(assembler), rhs_is_not_smi(assembler);
assembler->Branch(assembler->TaggedIsSmi(rhs), &rhs_is_smi,
&rhs_is_not_smi);
Label rhs_is_smi(this), rhs_is_not_smi(this);
Branch(TaggedIsSmi(rhs), &rhs_is_smi, &rhs_is_not_smi);
assembler->Bind(&rhs_is_smi);
Bind(&rhs_is_smi);
{
// Both {lhs} and {rhs} are Smis. The result is not necessarily a smi,
// in case of overflow.
var_result.Bind(assembler->SmiMul(lhs, rhs));
var_type_feedback.Bind(assembler->SelectSmiConstant(
assembler->TaggedIsSmi(var_result.value()),
BinaryOperationFeedback::kSignedSmall,
BinaryOperationFeedback::kNumber));
assembler->Goto(&end);
var_result.Bind(SmiMul(lhs, rhs));
var_type_feedback.Bind(
SelectSmiConstant(TaggedIsSmi(var_result.value()),
BinaryOperationFeedback::kSignedSmall,
BinaryOperationFeedback::kNumber));
Goto(&end);
}
assembler->Bind(&rhs_is_not_smi);
Bind(&rhs_is_not_smi);
{
Node* rhs_map = assembler->LoadMap(rhs);
Node* rhs_map = LoadMap(rhs);
// Check if {rhs} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(rhs_map),
&check_rhsisoddball);
GotoIfNot(IsHeapNumberMap(rhs_map), &check_rhsisoddball);
// Convert {lhs} to a double and multiply it with the value of {rhs}.
var_lhs_float64.Bind(assembler->SmiToFloat64(lhs));
var_rhs_float64.Bind(assembler->LoadHeapNumberValue(rhs));
assembler->Goto(&do_fmul);
var_lhs_float64.Bind(SmiToFloat64(lhs));
var_rhs_float64.Bind(LoadHeapNumberValue(rhs));
Goto(&do_fmul);
}
}
assembler->Bind(&lhs_is_not_smi);
Bind(&lhs_is_not_smi);
{
Node* lhs_map = assembler->LoadMap(lhs);
Node* lhs_map = LoadMap(lhs);
// Check if {lhs} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(lhs_map),
&if_lhsisnotnumber);
GotoIfNot(IsHeapNumberMap(lhs_map), &if_lhsisnotnumber);
// Check if {rhs} is a Smi.
Label rhs_is_smi(assembler), rhs_is_not_smi(assembler);
assembler->Branch(assembler->TaggedIsSmi(rhs), &rhs_is_smi,
&rhs_is_not_smi);
Label rhs_is_smi(this), rhs_is_not_smi(this);
Branch(TaggedIsSmi(rhs), &rhs_is_smi, &rhs_is_not_smi);
assembler->Bind(&rhs_is_smi);
Bind(&rhs_is_smi);
{
// Convert {rhs} to a double and multiply it with the value of {lhs}.
var_lhs_float64.Bind(assembler->LoadHeapNumberValue(lhs));
var_rhs_float64.Bind(assembler->SmiToFloat64(rhs));
assembler->Goto(&do_fmul);
var_lhs_float64.Bind(LoadHeapNumberValue(lhs));
var_rhs_float64.Bind(SmiToFloat64(rhs));
Goto(&do_fmul);
}
assembler->Bind(&rhs_is_not_smi);
Bind(&rhs_is_not_smi);
{
Node* rhs_map = assembler->LoadMap(rhs);
Node* rhs_map = LoadMap(rhs);
// Check if {rhs} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(rhs_map),
&check_rhsisoddball);
GotoIfNot(IsHeapNumberMap(rhs_map), &check_rhsisoddball);
// Both {lhs} and {rhs} are HeapNumbers. Load their values and
// multiply them.
var_lhs_float64.Bind(assembler->LoadHeapNumberValue(lhs));
var_rhs_float64.Bind(assembler->LoadHeapNumberValue(rhs));
assembler->Goto(&do_fmul);
var_lhs_float64.Bind(LoadHeapNumberValue(lhs));
var_rhs_float64.Bind(LoadHeapNumberValue(rhs));
Goto(&do_fmul);
}
}
assembler->Bind(&do_fmul);
Bind(&do_fmul);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kNumber));
Node* value =
assembler->Float64Mul(var_lhs_float64.value(), var_rhs_float64.value());
Node* result = assembler->AllocateHeapNumberWithValue(value);
var_type_feedback.Bind(SmiConstant(BinaryOperationFeedback::kNumber));
Node* value = Float64Mul(var_lhs_float64.value(), var_rhs_float64.value());
Node* result = AllocateHeapNumberWithValue(value);
var_result.Bind(result);
assembler->Goto(&end);
Goto(&end);
}
assembler->Bind(&if_lhsisnotnumber);
Bind(&if_lhsisnotnumber);
{
// No checks on rhs are done yet. We just know lhs is not a number or Smi.
// Check if lhs is an oddball.
Node* lhs_instance_type = assembler->LoadInstanceType(lhs);
Node* lhs_is_oddball = assembler->Word32Equal(
lhs_instance_type, assembler->Int32Constant(ODDBALL_TYPE));
assembler->GotoIfNot(lhs_is_oddball, &call_with_any_feedback);
Node* lhs_instance_type = LoadInstanceType(lhs);
Node* lhs_is_oddball =
Word32Equal(lhs_instance_type, Int32Constant(ODDBALL_TYPE));
GotoIfNot(lhs_is_oddball, &call_with_any_feedback);
assembler->GotoIf(assembler->TaggedIsSmi(rhs), &call_with_oddball_feedback);
GotoIf(TaggedIsSmi(rhs), &call_with_oddball_feedback);
// Load the map of the {rhs}.
Node* rhs_map = assembler->LoadMap(rhs);
Node* rhs_map = LoadMap(rhs);
// Check if {rhs} is a HeapNumber.
assembler->Branch(assembler->IsHeapNumberMap(rhs_map),
&call_with_oddball_feedback, &check_rhsisoddball);
Branch(IsHeapNumberMap(rhs_map), &call_with_oddball_feedback,
&check_rhsisoddball);
}
assembler->Bind(&check_rhsisoddball);
Bind(&check_rhsisoddball);
{
// Check if rhs is an oddball. At this point we know lhs is either a
// Smi or number or oddball and rhs is not a number or Smi.
Node* rhs_instance_type = assembler->LoadInstanceType(rhs);
Node* rhs_is_oddball = assembler->Word32Equal(
rhs_instance_type, assembler->Int32Constant(ODDBALL_TYPE));
assembler->Branch(rhs_is_oddball, &call_with_oddball_feedback,
&call_with_any_feedback);
Node* rhs_instance_type = LoadInstanceType(rhs);
Node* rhs_is_oddball =
Word32Equal(rhs_instance_type, Int32Constant(ODDBALL_TYPE));
Branch(rhs_is_oddball, &call_with_oddball_feedback,
&call_with_any_feedback);
}
assembler->Bind(&call_with_oddball_feedback);
Bind(&call_with_oddball_feedback);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kNumberOrOddball));
assembler->Goto(&call_multiply_stub);
SmiConstant(BinaryOperationFeedback::kNumberOrOddball));
Goto(&call_multiply_stub);
}
assembler->Bind(&call_with_any_feedback);
Bind(&call_with_any_feedback);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kAny));
assembler->Goto(&call_multiply_stub);
var_type_feedback.Bind(SmiConstant(BinaryOperationFeedback::kAny));
Goto(&call_multiply_stub);
}
assembler->Bind(&call_multiply_stub);
Bind(&call_multiply_stub);
{
Callable callable = CodeFactory::Multiply(assembler->isolate());
var_result.Bind(assembler->CallStub(callable, context, lhs, rhs));
assembler->Goto(&end);
Callable callable = CodeFactory::Multiply(isolate());
var_result.Bind(CallStub(callable, context, lhs, rhs));
Goto(&end);
}
assembler->Bind(&end);
assembler->UpdateFeedback(var_type_feedback.value(), feedback_vector,
slot_id);
Bind(&end);
UpdateFeedback(var_type_feedback.value(), feedback_vector, slot_id);
return var_result.value();
}
// static
compiler::Node* DivideWithFeedbackStub::Generate(
CodeStubAssembler* assembler, compiler::Node* dividend,
compiler::Node* divisor, compiler::Node* slot_id,
compiler::Node* feedback_vector, compiler::Node* context) {
using compiler::Node;
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
compiler::Node* BinaryOpAssembler::Generate_DivideWithFeedback(
Node* context, Node* dividend, Node* divisor, Node* slot_id,
Node* feedback_vector) {
// Shared entry point for floating point division.
Label do_fdiv(assembler), dividend_is_not_number(assembler, Label::kDeferred),
check_divisor_for_oddball(assembler, Label::kDeferred),
call_with_oddball_feedback(assembler), call_with_any_feedback(assembler),
call_divide_stub(assembler), end(assembler);
Variable var_dividend_float64(assembler, MachineRepresentation::kFloat64),
var_divisor_float64(assembler, MachineRepresentation::kFloat64),
var_result(assembler, MachineRepresentation::kTagged),
var_type_feedback(assembler, MachineRepresentation::kTaggedSigned);
Label dividend_is_smi(assembler), dividend_is_not_smi(assembler);
assembler->Branch(assembler->TaggedIsSmi(dividend), &dividend_is_smi,
&dividend_is_not_smi);
assembler->Bind(&dividend_is_smi);
Label do_fdiv(this), dividend_is_not_number(this, Label::kDeferred),
check_divisor_for_oddball(this, Label::kDeferred),
call_with_oddball_feedback(this), call_with_any_feedback(this),
call_divide_stub(this), end(this);
Variable var_dividend_float64(this, MachineRepresentation::kFloat64),
var_divisor_float64(this, MachineRepresentation::kFloat64),
var_result(this, MachineRepresentation::kTagged),
var_type_feedback(this, MachineRepresentation::kTaggedSigned);
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(assembler), divisor_is_not_smi(assembler);
assembler->Branch(assembler->TaggedIsSmi(divisor), &divisor_is_smi,
&divisor_is_not_smi);
Label divisor_is_smi(this), divisor_is_not_smi(this);
Branch(TaggedIsSmi(divisor), &divisor_is_smi, &divisor_is_not_smi);
assembler->Bind(&divisor_is_smi);
Bind(&divisor_is_smi);
{
Label bailout(assembler);
Label bailout(this);
// Do floating point division if {divisor} is zero.
assembler->GotoIf(
assembler->WordEqual(divisor, assembler->SmiConstant(0)), &bailout);
GotoIf(WordEqual(divisor, SmiConstant(0)), &bailout);
// Do floating point division {dividend} is zero and {divisor} is
// negative.
Label dividend_is_zero(assembler), dividend_is_not_zero(assembler);
assembler->Branch(
assembler->WordEqual(dividend, assembler->SmiConstant(0)),
&dividend_is_zero, &dividend_is_not_zero);
Label dividend_is_zero(this), dividend_is_not_zero(this);
Branch(WordEqual(dividend, SmiConstant(0)), &dividend_is_zero,
&dividend_is_not_zero);
assembler->Bind(&dividend_is_zero);
Bind(&dividend_is_zero);
{
assembler->GotoIf(
assembler->SmiLessThan(divisor, assembler->SmiConstant(0)),
&bailout);
assembler->Goto(&dividend_is_not_zero);
GotoIf(SmiLessThan(divisor, SmiConstant(0)), &bailout);
Goto(&dividend_is_not_zero);
}
assembler->Bind(&dividend_is_not_zero);
Bind(&dividend_is_not_zero);
Node* untagged_divisor = assembler->SmiToWord32(divisor);
Node* untagged_dividend = assembler->SmiToWord32(dividend);
Node* untagged_divisor = SmiToWord32(divisor);
Node* untagged_dividend = SmiToWord32(dividend);
// Do floating point division if {dividend} is kMinInt (or kMinInt - 1
// if the Smi size is 31) and {divisor} is -1.
Label divisor_is_minus_one(assembler),
divisor_is_not_minus_one(assembler);
assembler->Branch(assembler->Word32Equal(untagged_divisor,
assembler->Int32Constant(-1)),
&divisor_is_minus_one, &divisor_is_not_minus_one);
Label divisor_is_minus_one(this), divisor_is_not_minus_one(this);
Branch(Word32Equal(untagged_divisor, Int32Constant(-1)),
&divisor_is_minus_one, &divisor_is_not_minus_one);
assembler->Bind(&divisor_is_minus_one);
Bind(&divisor_is_minus_one);
{
assembler->GotoIf(
assembler->Word32Equal(
untagged_dividend,
assembler->Int32Constant(kSmiValueSize == 32 ? kMinInt
GotoIf(Word32Equal(untagged_dividend,
Int32Constant(kSmiValueSize == 32 ? kMinInt
: (kMinInt >> 1))),
&bailout);
assembler->Goto(&divisor_is_not_minus_one);
&bailout);
Goto(&divisor_is_not_minus_one);
}
assembler->Bind(&divisor_is_not_minus_one);
Bind(&divisor_is_not_minus_one);
Node* untagged_result =
assembler->Int32Div(untagged_dividend, untagged_divisor);
Node* truncated = assembler->Int32Mul(untagged_result, untagged_divisor);
Node* untagged_result = Int32Div(untagged_dividend, untagged_divisor);
Node* truncated = Int32Mul(untagged_result, untagged_divisor);
// Do floating point division if the remainder is not 0.
assembler->GotoIf(assembler->Word32NotEqual(untagged_dividend, truncated),
&bailout);
GotoIf(Word32NotEqual(untagged_dividend, truncated), &bailout);
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kSignedSmall));
var_result.Bind(assembler->SmiFromWord32(untagged_result));
assembler->Goto(&end);
SmiConstant(BinaryOperationFeedback::kSignedSmall));
var_result.Bind(SmiFromWord32(untagged_result));
Goto(&end);
// Bailout: convert {dividend} and {divisor} to double and do double
// division.
assembler->Bind(&bailout);
Bind(&bailout);
{
var_dividend_float64.Bind(assembler->SmiToFloat64(dividend));
var_divisor_float64.Bind(assembler->SmiToFloat64(divisor));
assembler->Goto(&do_fdiv);
var_dividend_float64.Bind(SmiToFloat64(dividend));
var_divisor_float64.Bind(SmiToFloat64(divisor));
Goto(&do_fdiv);
}
}
assembler->Bind(&divisor_is_not_smi);
Bind(&divisor_is_not_smi);
{
Node* divisor_map = assembler->LoadMap(divisor);
Node* divisor_map = LoadMap(divisor);
// Check if {divisor} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(divisor_map),
&check_divisor_for_oddball);
GotoIfNot(IsHeapNumberMap(divisor_map), &check_divisor_for_oddball);
// Convert {dividend} to a double and divide it with the value of
// {divisor}.
var_dividend_float64.Bind(assembler->SmiToFloat64(dividend));
var_divisor_float64.Bind(assembler->LoadHeapNumberValue(divisor));
assembler->Goto(&do_fdiv);
var_dividend_float64.Bind(SmiToFloat64(dividend));
var_divisor_float64.Bind(LoadHeapNumberValue(divisor));
Goto(&do_fdiv);
}
assembler->Bind(&dividend_is_not_smi);
Bind(&dividend_is_not_smi);
{
Node* dividend_map = assembler->LoadMap(dividend);
Node* dividend_map = LoadMap(dividend);
// Check if {dividend} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(dividend_map),
&dividend_is_not_number);
GotoIfNot(IsHeapNumberMap(dividend_map), &dividend_is_not_number);
// Check if {divisor} is a Smi.
Label divisor_is_smi(assembler), divisor_is_not_smi(assembler);
assembler->Branch(assembler->TaggedIsSmi(divisor), &divisor_is_smi,
&divisor_is_not_smi);
Label divisor_is_smi(this), divisor_is_not_smi(this);
Branch(TaggedIsSmi(divisor), &divisor_is_smi, &divisor_is_not_smi);
assembler->Bind(&divisor_is_smi);
Bind(&divisor_is_smi);
{
// Convert {divisor} to a double and use it for a floating point
// division.
var_dividend_float64.Bind(assembler->LoadHeapNumberValue(dividend));
var_divisor_float64.Bind(assembler->SmiToFloat64(divisor));
assembler->Goto(&do_fdiv);
var_dividend_float64.Bind(LoadHeapNumberValue(dividend));
var_divisor_float64.Bind(SmiToFloat64(divisor));
Goto(&do_fdiv);
}
assembler->Bind(&divisor_is_not_smi);
Bind(&divisor_is_not_smi);
{
Node* divisor_map = assembler->LoadMap(divisor);
Node* divisor_map = LoadMap(divisor);
// Check if {divisor} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(divisor_map),
&check_divisor_for_oddball);
GotoIfNot(IsHeapNumberMap(divisor_map), &check_divisor_for_oddball);
// Both {dividend} and {divisor} are HeapNumbers. Load their values
// and divide them.
var_dividend_float64.Bind(assembler->LoadHeapNumberValue(dividend));
var_divisor_float64.Bind(assembler->LoadHeapNumberValue(divisor));
assembler->Goto(&do_fdiv);
var_dividend_float64.Bind(LoadHeapNumberValue(dividend));
var_divisor_float64.Bind(LoadHeapNumberValue(divisor));
Goto(&do_fdiv);
}
}
}
assembler->Bind(&do_fdiv);
Bind(&do_fdiv);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kNumber));
Node* value = assembler->Float64Div(var_dividend_float64.value(),
var_divisor_float64.value());
var_result.Bind(assembler->AllocateHeapNumberWithValue(value));
assembler->Goto(&end);
var_type_feedback.Bind(SmiConstant(BinaryOperationFeedback::kNumber));
Node* value =
Float64Div(var_dividend_float64.value(), var_divisor_float64.value());
var_result.Bind(AllocateHeapNumberWithValue(value));
Goto(&end);
}
assembler->Bind(&dividend_is_not_number);
Bind(&dividend_is_not_number);
{
// We just know dividend is not a number or Smi. No checks on divisor yet.
// Check if dividend is an oddball.
Node* dividend_instance_type = assembler->LoadInstanceType(dividend);
Node* dividend_is_oddball = assembler->Word32Equal(
dividend_instance_type, assembler->Int32Constant(ODDBALL_TYPE));
assembler->GotoIfNot(dividend_is_oddball, &call_with_any_feedback);
Node* dividend_instance_type = LoadInstanceType(dividend);
Node* dividend_is_oddball =
Word32Equal(dividend_instance_type, Int32Constant(ODDBALL_TYPE));
GotoIfNot(dividend_is_oddball, &call_with_any_feedback);
assembler->GotoIf(assembler->TaggedIsSmi(divisor),
&call_with_oddball_feedback);
GotoIf(TaggedIsSmi(divisor), &call_with_oddball_feedback);
// Load the map of the {divisor}.
Node* divisor_map = assembler->LoadMap(divisor);
Node* divisor_map = LoadMap(divisor);
// Check if {divisor} is a HeapNumber.
assembler->Branch(assembler->IsHeapNumberMap(divisor_map),
&call_with_oddball_feedback, &check_divisor_for_oddball);
Branch(IsHeapNumberMap(divisor_map), &call_with_oddball_feedback,
&check_divisor_for_oddball);
}
assembler->Bind(&check_divisor_for_oddball);
Bind(&check_divisor_for_oddball);
{
// Check if divisor is an oddball. At this point we know dividend is either
// a Smi or number or oddball and divisor is not a number or Smi.
Node* divisor_instance_type = assembler->LoadInstanceType(divisor);
Node* divisor_is_oddball = assembler->Word32Equal(
divisor_instance_type, assembler->Int32Constant(ODDBALL_TYPE));
assembler->Branch(divisor_is_oddball, &call_with_oddball_feedback,
&call_with_any_feedback);
Node* divisor_instance_type = LoadInstanceType(divisor);
Node* divisor_is_oddball =
Word32Equal(divisor_instance_type, Int32Constant(ODDBALL_TYPE));
Branch(divisor_is_oddball, &call_with_oddball_feedback,
&call_with_any_feedback);
}
assembler->Bind(&call_with_oddball_feedback);
Bind(&call_with_oddball_feedback);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kNumberOrOddball));
assembler->Goto(&call_divide_stub);
SmiConstant(BinaryOperationFeedback::kNumberOrOddball));
Goto(&call_divide_stub);
}
assembler->Bind(&call_with_any_feedback);
Bind(&call_with_any_feedback);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kAny));
assembler->Goto(&call_divide_stub);
var_type_feedback.Bind(SmiConstant(BinaryOperationFeedback::kAny));
Goto(&call_divide_stub);
}
assembler->Bind(&call_divide_stub);
Bind(&call_divide_stub);
{
Callable callable = CodeFactory::Divide(assembler->isolate());
var_result.Bind(assembler->CallStub(callable, context, dividend, divisor));
assembler->Goto(&end);
Callable callable = CodeFactory::Divide(isolate());
var_result.Bind(CallStub(callable, context, dividend, divisor));
Goto(&end);
}
assembler->Bind(&end);
assembler->UpdateFeedback(var_type_feedback.value(), feedback_vector,
slot_id);
Bind(&end);
UpdateFeedback(var_type_feedback.value(), feedback_vector, slot_id);
return var_result.value();
}
// static
compiler::Node* ModulusWithFeedbackStub::Generate(
CodeStubAssembler* assembler, compiler::Node* dividend,
compiler::Node* divisor, compiler::Node* slot_id,
compiler::Node* feedback_vector, compiler::Node* context) {
using compiler::Node;
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
compiler::Node* BinaryOpAssembler::Generate_ModulusWithFeedback(
Node* context, Node* dividend, Node* divisor, Node* slot_id,
Node* feedback_vector) {
// Shared entry point for floating point division.
Label do_fmod(assembler), dividend_is_not_number(assembler, Label::kDeferred),
check_divisor_for_oddball(assembler, Label::kDeferred),
call_with_oddball_feedback(assembler), call_with_any_feedback(assembler),
call_modulus_stub(assembler), end(assembler);
Variable var_dividend_float64(assembler, MachineRepresentation::kFloat64),
var_divisor_float64(assembler, MachineRepresentation::kFloat64),
var_result(assembler, MachineRepresentation::kTagged),
var_type_feedback(assembler, MachineRepresentation::kTaggedSigned);
Label dividend_is_smi(assembler), dividend_is_not_smi(assembler);
assembler->Branch(assembler->TaggedIsSmi(dividend), &dividend_is_smi,
&dividend_is_not_smi);
assembler->Bind(&dividend_is_smi);
Label do_fmod(this), dividend_is_not_number(this, Label::kDeferred),
check_divisor_for_oddball(this, Label::kDeferred),
call_with_oddball_feedback(this), call_with_any_feedback(this),
call_modulus_stub(this), end(this);
Variable var_dividend_float64(this, MachineRepresentation::kFloat64),
var_divisor_float64(this, MachineRepresentation::kFloat64),
var_result(this, MachineRepresentation::kTagged),
var_type_feedback(this, MachineRepresentation::kTaggedSigned);
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(assembler), divisor_is_not_smi(assembler);
assembler->Branch(assembler->TaggedIsSmi(divisor), &divisor_is_smi,
&divisor_is_not_smi);
Label divisor_is_smi(this), divisor_is_not_smi(this);
Branch(TaggedIsSmi(divisor), &divisor_is_smi, &divisor_is_not_smi);
assembler->Bind(&divisor_is_smi);
Bind(&divisor_is_smi);
{
var_result.Bind(assembler->SmiMod(dividend, divisor));
var_type_feedback.Bind(assembler->SelectSmiConstant(
assembler->TaggedIsSmi(var_result.value()),
BinaryOperationFeedback::kSignedSmall,
BinaryOperationFeedback::kNumber));
assembler->Goto(&end);
var_result.Bind(SmiMod(dividend, divisor));
var_type_feedback.Bind(
SelectSmiConstant(TaggedIsSmi(var_result.value()),
BinaryOperationFeedback::kSignedSmall,
BinaryOperationFeedback::kNumber));
Goto(&end);
}
assembler->Bind(&divisor_is_not_smi);
Bind(&divisor_is_not_smi);
{
Node* divisor_map = assembler->LoadMap(divisor);
Node* divisor_map = LoadMap(divisor);
// Check if {divisor} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(divisor_map),
&check_divisor_for_oddball);
GotoIfNot(IsHeapNumberMap(divisor_map), &check_divisor_for_oddball);
// Convert {dividend} to a double and divide it with the value of
// {divisor}.
var_dividend_float64.Bind(assembler->SmiToFloat64(dividend));
var_divisor_float64.Bind(assembler->LoadHeapNumberValue(divisor));
assembler->Goto(&do_fmod);
var_dividend_float64.Bind(SmiToFloat64(dividend));
var_divisor_float64.Bind(LoadHeapNumberValue(divisor));
Goto(&do_fmod);
}
}
assembler->Bind(&dividend_is_not_smi);
Bind(&dividend_is_not_smi);
{
Node* dividend_map = assembler->LoadMap(dividend);
Node* dividend_map = LoadMap(dividend);
// Check if {dividend} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(dividend_map),
&dividend_is_not_number);
GotoIfNot(IsHeapNumberMap(dividend_map), &dividend_is_not_number);
// Check if {divisor} is a Smi.
Label divisor_is_smi(assembler), divisor_is_not_smi(assembler);
assembler->Branch(assembler->TaggedIsSmi(divisor), &divisor_is_smi,
&divisor_is_not_smi);
Label divisor_is_smi(this), divisor_is_not_smi(this);
Branch(TaggedIsSmi(divisor), &divisor_is_smi, &divisor_is_not_smi);
assembler->Bind(&divisor_is_smi);
Bind(&divisor_is_smi);
{
// Convert {divisor} to a double and use it for a floating point
// division.
var_dividend_float64.Bind(assembler->LoadHeapNumberValue(dividend));
var_divisor_float64.Bind(assembler->SmiToFloat64(divisor));
assembler->Goto(&do_fmod);
var_dividend_float64.Bind(LoadHeapNumberValue(dividend));
var_divisor_float64.Bind(SmiToFloat64(divisor));
Goto(&do_fmod);
}
assembler->Bind(&divisor_is_not_smi);
Bind(&divisor_is_not_smi);
{
Node* divisor_map = assembler->LoadMap(divisor);
Node* divisor_map = LoadMap(divisor);
// Check if {divisor} is a HeapNumber.
assembler->GotoIfNot(assembler->IsHeapNumberMap(divisor_map),
&check_divisor_for_oddball);
GotoIfNot(IsHeapNumberMap(divisor_map), &check_divisor_for_oddball);
// Both {dividend} and {divisor} are HeapNumbers. Load their values
// and divide them.
var_dividend_float64.Bind(assembler->LoadHeapNumberValue(dividend));
var_divisor_float64.Bind(assembler->LoadHeapNumberValue(divisor));
assembler->Goto(&do_fmod);
var_dividend_float64.Bind(LoadHeapNumberValue(dividend));
var_divisor_float64.Bind(LoadHeapNumberValue(divisor));
Goto(&do_fmod);
}
}
assembler->Bind(&do_fmod);
Bind(&do_fmod);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kNumber));
Node* value = assembler->Float64Mod(var_dividend_float64.value(),
var_divisor_float64.value());
var_result.Bind(assembler->AllocateHeapNumberWithValue(value));
assembler->Goto(&end);
var_type_feedback.Bind(SmiConstant(BinaryOperationFeedback::kNumber));
Node* value =
Float64Mod(var_dividend_float64.value(), var_divisor_float64.value());
var_result.Bind(AllocateHeapNumberWithValue(value));
Goto(&end);
}
assembler->Bind(&dividend_is_not_number);
Bind(&dividend_is_not_number);
{
// No checks on divisor yet. We just know dividend is not a number or Smi.
// Check if dividend is an oddball.
Node* dividend_instance_type = assembler->LoadInstanceType(dividend);
Node* dividend_is_oddball = assembler->Word32Equal(
dividend_instance_type, assembler->Int32Constant(ODDBALL_TYPE));
assembler->GotoIfNot(dividend_is_oddball, &call_with_any_feedback);
Node* dividend_instance_type = LoadInstanceType(dividend);
Node* dividend_is_oddball =
Word32Equal(dividend_instance_type, Int32Constant(ODDBALL_TYPE));
GotoIfNot(dividend_is_oddball, &call_with_any_feedback);
assembler->GotoIf(assembler->TaggedIsSmi(divisor),
&call_with_oddball_feedback);
GotoIf(TaggedIsSmi(divisor), &call_with_oddball_feedback);
// Load the map of the {divisor}.
Node* divisor_map = assembler->LoadMap(divisor);
Node* divisor_map = LoadMap(divisor);
// Check if {divisor} is a HeapNumber.
assembler->Branch(assembler->IsHeapNumberMap(divisor_map),
&call_with_oddball_feedback, &check_divisor_for_oddball);
Branch(IsHeapNumberMap(divisor_map), &call_with_oddball_feedback,
&check_divisor_for_oddball);
}
assembler->Bind(&check_divisor_for_oddball);
Bind(&check_divisor_for_oddball);
{
// Check if divisor is an oddball. At this point we know dividend is either
// a Smi or number or oddball and divisor is not a number or Smi.
Node* divisor_instance_type = assembler->LoadInstanceType(divisor);
Node* divisor_is_oddball = assembler->Word32Equal(
divisor_instance_type, assembler->Int32Constant(ODDBALL_TYPE));
assembler->Branch(divisor_is_oddball, &call_with_oddball_feedback,
&call_with_any_feedback);
Node* divisor_instance_type = LoadInstanceType(divisor);
Node* divisor_is_oddball =
Word32Equal(divisor_instance_type, Int32Constant(ODDBALL_TYPE));
Branch(divisor_is_oddball, &call_with_oddball_feedback,
&call_with_any_feedback);
}
assembler->Bind(&call_with_oddball_feedback);
Bind(&call_with_oddball_feedback);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kNumberOrOddball));
assembler->Goto(&call_modulus_stub);
SmiConstant(BinaryOperationFeedback::kNumberOrOddball));
Goto(&call_modulus_stub);
}
assembler->Bind(&call_with_any_feedback);
Bind(&call_with_any_feedback);
{
var_type_feedback.Bind(
assembler->SmiConstant(BinaryOperationFeedback::kAny));
assembler->Goto(&call_modulus_stub);
var_type_feedback.Bind(SmiConstant(BinaryOperationFeedback::kAny));
Goto(&call_modulus_stub);
}
assembler->Bind(&call_modulus_stub);
Bind(&call_modulus_stub);
{
Callable callable = CodeFactory::Modulus(assembler->isolate());
var_result.Bind(assembler->CallStub(callable, context, dividend, divisor));
assembler->Goto(&end);
Callable callable = CodeFactory::Modulus(isolate());
var_result.Bind(CallStub(callable, context, dividend, divisor));
Goto(&end);
}
assembler->Bind(&end);
assembler->UpdateFeedback(var_type_feedback.value(), feedback_vector,
slot_id);
Bind(&end);
UpdateFeedback(var_type_feedback.value(), feedback_vector, slot_id);
return var_result.value();
}
#define BINARY_OP_STUB(Name) \
TF_STUB(Name##Stub, BinaryOpAssembler) { \
Node* context = Parameter(Descriptor::kContext); \
Node* left = Parameter(Descriptor::kLeft); \
Node* right = Parameter(Descriptor::kRight); \
Node* slot = Parameter(Descriptor::kSlot); \
Node* vector = Parameter(Descriptor::kVector); \
Return(Generate_##Name(context, left, right, ChangeUint32ToWord(slot), \
vector)); \
} \
compiler::Node* Name##Stub::Generate( \
CodeStubAssembler* assembler, compiler::Node* left, \
compiler::Node* right, compiler::Node* slot, \
compiler::Node* feedback_vector, compiler::Node* context) { \
BinaryOpAssembler basm(assembler->state()); \
return basm.Generate_##Name(context, left, right, slot, feedback_vector); \
}
// TODO(ishell): don't have to be stubs. Interpreter can use BinaryOpICAssembler
// directly.
BINARY_OP_STUB(AddWithFeedback)
BINARY_OP_STUB(SubtractWithFeedback)
BINARY_OP_STUB(MultiplyWithFeedback)
BINARY_OP_STUB(DivideWithFeedback)
BINARY_OP_STUB(ModulusWithFeedback)
#undef BINARY_OP_STUB
// TODO(ishell): move to builtins.
TF_STUB(NumberToStringStub, CodeStubAssembler) {
Node* context = Parameter(Descriptor::kContext);
......
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