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