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

Unified Diff: src/builtins/builtins-number.cc

Issue 2313073002: [builtins] Migrate Number predicates and make them optimizable. (Closed)
Patch Set: Created 4 years, 3 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/builtins/builtins-global.cc ('k') | src/compiler/js-builtin-reducer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-number.cc
diff --git a/src/builtins/builtins-number.cc b/src/builtins/builtins-number.cc
index c2af0fdecf4eba706b89fad971641669418f48b7..17628445d116930c04e439314e097d91f84c8d93 100644
--- a/src/builtins/builtins-number.cc
+++ b/src/builtins/builtins-number.cc
@@ -11,6 +11,144 @@ namespace internal {
// -----------------------------------------------------------------------------
// ES6 section 20.1 Number Objects
+// ES6 section 20.1.2.2 Number.isFinite ( number )
+void Builtins::Generate_NumberIsFinite(CodeStubAssembler* assembler) {
+ typedef CodeStubAssembler::Label Label;
+ typedef compiler::Node Node;
+
+ Node* number = assembler->Parameter(1);
+
+ Label return_true(assembler), return_false(assembler);
+
+ // Check if {number} is a Smi.
+ assembler->GotoIf(assembler->WordIsSmi(number), &return_true);
+
+ // Check if {number} is a HeapNumber.
+ assembler->GotoUnless(
+ assembler->WordEqual(assembler->LoadMap(number),
+ assembler->HeapNumberMapConstant()),
+ &return_false);
+
+ // Check if {number} contains a finite, non-NaN value.
+ Node* number_value = assembler->LoadHeapNumberValue(number);
+ assembler->BranchIfFloat64IsNaN(
+ assembler->Float64Sub(number_value, number_value), &return_false,
+ &return_true);
+
+ assembler->Bind(&return_true);
+ assembler->Return(assembler->BooleanConstant(true));
+
+ assembler->Bind(&return_false);
+ assembler->Return(assembler->BooleanConstant(false));
+}
+
+// ES6 section 20.1.2.3 Number.isInteger ( number )
+void Builtins::Generate_NumberIsInteger(CodeStubAssembler* assembler) {
+ typedef CodeStubAssembler::Label Label;
+ typedef compiler::Node Node;
+
+ Node* number = assembler->Parameter(1);
+
+ Label return_true(assembler), return_false(assembler);
+
+ // Check if {number} is a Smi.
+ assembler->GotoIf(assembler->WordIsSmi(number), &return_true);
+
+ // Check if {number} is a HeapNumber.
+ assembler->GotoUnless(
+ assembler->WordEqual(assembler->LoadMap(number),
+ assembler->HeapNumberMapConstant()),
+ &return_false);
+
+ // Load the actual value of {number}.
+ Node* number_value = assembler->LoadHeapNumberValue(number);
+
+ // Truncate the value of {number} to an integer (or an infinity).
+ Node* integer = assembler->Float64Trunc(number_value);
+
+ // Check if {number}s value matches the integer (ruling out the infinities).
+ assembler->BranchIfFloat64Equal(assembler->Float64Sub(number_value, integer),
+ assembler->Float64Constant(0.0), &return_true,
+ &return_false);
+
+ assembler->Bind(&return_true);
+ assembler->Return(assembler->BooleanConstant(true));
+
+ assembler->Bind(&return_false);
+ assembler->Return(assembler->BooleanConstant(false));
+}
+
+// ES6 section 20.1.2.4 Number.isNaN ( number )
+void Builtins::Generate_NumberIsNaN(CodeStubAssembler* assembler) {
+ typedef CodeStubAssembler::Label Label;
+ typedef compiler::Node Node;
+
+ Node* number = assembler->Parameter(1);
+
+ Label return_true(assembler), return_false(assembler);
+
+ // Check if {number} is a Smi.
+ assembler->GotoIf(assembler->WordIsSmi(number), &return_false);
+
+ // Check if {number} is a HeapNumber.
+ assembler->GotoUnless(
+ assembler->WordEqual(assembler->LoadMap(number),
+ assembler->HeapNumberMapConstant()),
+ &return_false);
+
+ // Check if {number} contains a NaN value.
+ Node* number_value = assembler->LoadHeapNumberValue(number);
+ assembler->BranchIfFloat64IsNaN(number_value, &return_true, &return_false);
+
+ assembler->Bind(&return_true);
+ assembler->Return(assembler->BooleanConstant(true));
+
+ assembler->Bind(&return_false);
+ assembler->Return(assembler->BooleanConstant(false));
+}
+
+// ES6 section 20.1.2.5 Number.isSafeInteger ( number )
+void Builtins::Generate_NumberIsSafeInteger(CodeStubAssembler* assembler) {
+ typedef CodeStubAssembler::Label Label;
+ typedef compiler::Node Node;
+
+ Node* number = assembler->Parameter(1);
+
+ Label return_true(assembler), return_false(assembler);
+
+ // Check if {number} is a Smi.
+ assembler->GotoIf(assembler->WordIsSmi(number), &return_true);
+
+ // Check if {number} is a HeapNumber.
+ assembler->GotoUnless(
+ assembler->WordEqual(assembler->LoadMap(number),
+ assembler->HeapNumberMapConstant()),
+ &return_false);
+
+ // Load the actual value of {number}.
+ Node* number_value = assembler->LoadHeapNumberValue(number);
+
+ // Truncate the value of {number} to an integer (or an infinity).
+ Node* integer = assembler->Float64Trunc(number_value);
+
+ // Check if {number}s value matches the integer (ruling out the infinities).
+ assembler->GotoUnless(
+ assembler->Float64Equal(assembler->Float64Sub(number_value, integer),
+ assembler->Float64Constant(0.0)),
+ &return_false);
+
+ // Check if the {integer} value is in safe integer range.
+ assembler->BranchIfFloat64LessThanOrEqual(
+ assembler->Float64Abs(integer),
+ assembler->Float64Constant(kMaxSafeInteger), &return_true, &return_false);
+
+ assembler->Bind(&return_true);
+ assembler->Return(assembler->BooleanConstant(true));
+
+ assembler->Bind(&return_false);
+ assembler->Return(assembler->BooleanConstant(false));
+}
+
// ES6 section 20.1.3.2 Number.prototype.toExponential ( fractionDigits )
BUILTIN(NumberPrototypeToExponential) {
HandleScope scope(isolate);
« no previous file with comments | « src/builtins/builtins-global.cc ('k') | src/compiler/js-builtin-reducer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698