Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Unified Diff: src/code-stubs.cc

Issue 1756793002: [compiler] Introduce proper StrictNotEqualStub. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/code-stubs.h ('k') | src/compiler/js-generic-lowering.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/code-stubs.cc
diff --git a/src/code-stubs.cc b/src/code-stubs.cc
index c5f7fb4fa1273f945115eae0e3bd9d48d60fb191..11e3fafa49ed74aba7cee4ba820c3e3f271a8f3d 100644
--- a/src/code-stubs.cc
+++ b/src/code-stubs.cc
@@ -473,9 +473,14 @@ void StringLengthStub::GenerateAssembly(
assembler->Return(result);
}
-void StrictEqualStub::GenerateAssembly(
- compiler::CodeStubAssembler* assembler) const {
- // Here's pseudo-code for the algorithm below:
+namespace {
+
+enum StrictEqualMode { kStrictEqual, kStrictNotEqual };
+
+void GenerateStrictEqual(compiler::CodeStubAssembler* assembler,
+ StrictEqualMode mode) {
+ // Here's pseudo-code for the algorithm below in case of kStrictEqual mode;
+ // for kStrictNotEqual mode we properly negate the result.
//
// if (lhs == rhs) {
// if (lhs->IsHeapNumber()) return HeapNumber::cast(lhs)->value() != NaN;
@@ -529,7 +534,7 @@ void StrictEqualStub::GenerateAssembly(
Node* rhs = assembler->Parameter(1);
Node* context = assembler->Parameter(2);
- Label if_true(assembler), if_false(assembler);
+ Label if_equal(assembler), if_notequal(assembler);
// Check if {lhs} and {rhs} refer to the same object.
Label if_same(assembler), if_notsame(assembler);
@@ -563,15 +568,15 @@ void StrictEqualStub::GenerateAssembly(
Node* lhs_value = assembler->LoadHeapNumberValue(lhs);
// Check if the HeapNumber value is a NaN.
- assembler->BranchIfFloat64IsNaN(lhs_value, &if_false, &if_true);
+ assembler->BranchIfFloat64IsNaN(lhs_value, &if_notequal, &if_equal);
}
assembler->Bind(&if_lhsisnotnumber);
- assembler->Goto(&if_true);
+ assembler->Goto(&if_equal);
}
assembler->Bind(&if_lhsissmi);
- assembler->Goto(&if_true);
+ assembler->Goto(&if_equal);
}
assembler->Bind(&if_notsame);
@@ -608,8 +613,8 @@ void StrictEqualStub::GenerateAssembly(
Node* rhs_value = assembler->SmiToFloat64(rhs);
// Perform a floating point comparison of {lhs} and {rhs}.
- assembler->BranchIfFloat64Equal(lhs_value, rhs_value, &if_true,
- &if_false);
+ assembler->BranchIfFloat64Equal(lhs_value, rhs_value, &if_equal,
+ &if_notequal);
}
assembler->Bind(&if_rhsisnotsmi);
@@ -630,12 +635,12 @@ void StrictEqualStub::GenerateAssembly(
Node* rhs_value = assembler->LoadHeapNumberValue(rhs);
// Perform a floating point comparison of {lhs} and {rhs}.
- assembler->BranchIfFloat64Equal(lhs_value, rhs_value, &if_true,
- &if_false);
+ assembler->BranchIfFloat64Equal(lhs_value, rhs_value, &if_equal,
+ &if_notequal);
}
assembler->Bind(&if_rhsisnotnumber);
- assembler->Goto(&if_false);
+ assembler->Goto(&if_notequal);
}
}
@@ -647,7 +652,7 @@ void StrictEqualStub::GenerateAssembly(
&if_rhsisnotsmi);
assembler->Bind(&if_rhsissmi);
- assembler->Goto(&if_false);
+ assembler->Goto(&if_notequal);
assembler->Bind(&if_rhsisnotsmi);
{
@@ -677,12 +682,14 @@ void StrictEqualStub::GenerateAssembly(
{
// TODO(bmeurer): Optimize this further once the StringEqual
// functionality is available in TurboFan land.
- assembler->TailCallRuntime(Runtime::kStringEqual, context, lhs,
- rhs);
+ Runtime::FunctionId function_id = (mode == kStrictEqual)
+ ? Runtime::kStringEqual
+ : Runtime::kStringNotEqual;
+ assembler->TailCallRuntime(function_id, context, lhs, rhs);
}
assembler->Bind(&if_rhsisnotstring);
- assembler->Goto(&if_false);
+ assembler->Goto(&if_notequal);
}
assembler->Bind(&if_lhsisnotstring);
@@ -698,12 +705,14 @@ void StrictEqualStub::GenerateAssembly(
assembler->Bind(&if_lhsissimd128value);
{
// TODO(bmeurer): Inline the Simd128Value equality check.
- assembler->TailCallRuntime(Runtime::kStrictEqual, context, lhs,
- rhs);
+ Runtime::FunctionId function_id = (mode == kStrictEqual)
+ ? Runtime::kStrictEqual
+ : Runtime::kStrictNotEqual;
+ assembler->TailCallRuntime(function_id, context, lhs, rhs);
}
assembler->Bind(&if_lhsisnotsimd128value);
- assembler->Goto(&if_false);
+ assembler->Goto(&if_notequal);
}
}
}
@@ -721,7 +730,7 @@ void StrictEqualStub::GenerateAssembly(
&if_rhsisnotsmi);
assembler->Bind(&if_rhsissmi);
- assembler->Goto(&if_false);
+ assembler->Goto(&if_notequal);
assembler->Bind(&if_rhsisnotsmi);
{
@@ -740,21 +749,33 @@ void StrictEqualStub::GenerateAssembly(
Node* rhs_value = assembler->LoadHeapNumberValue(rhs);
// Perform a floating point comparison of {lhs} and {rhs}.
- assembler->BranchIfFloat64Equal(lhs_value, rhs_value, &if_true,
- &if_false);
+ assembler->BranchIfFloat64Equal(lhs_value, rhs_value, &if_equal,
+ &if_notequal);
}
assembler->Bind(&if_rhsisnotnumber);
- assembler->Goto(&if_false);
+ assembler->Goto(&if_notequal);
}
}
}
- assembler->Bind(&if_true);
- assembler->Return(assembler->BooleanConstant(true));
+ assembler->Bind(&if_equal);
+ assembler->Return(assembler->BooleanConstant(mode == kStrictEqual));
+
+ assembler->Bind(&if_notequal);
+ assembler->Return(assembler->BooleanConstant(mode == kStrictNotEqual));
+}
+
+} // namespace
+
+void StrictEqualStub::GenerateAssembly(
+ compiler::CodeStubAssembler* assembler) const {
+ GenerateStrictEqual(assembler, kStrictEqual);
+}
- assembler->Bind(&if_false);
- assembler->Return(assembler->BooleanConstant(false));
+void StrictNotEqualStub::GenerateAssembly(
+ compiler::CodeStubAssembler* assembler) const {
+ GenerateStrictEqual(assembler, kStrictNotEqual);
}
void ToBooleanStub::GenerateAssembly(
« no previous file with comments | « src/code-stubs.h ('k') | src/compiler/js-generic-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698