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

Unified Diff: src/builtins.cc

Issue 1841993002: [builtins] Make Math.ceil, Math.trunc and Math.round optimizable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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.h ('k') | src/compiler/code-stub-assembler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index d34d6c2c9787af3c26b226fdf8eea020c4b98943..87097b05f082929f554c94ac687a78d92a4fe158 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -2007,8 +2007,12 @@ BUILTIN(MathAtan) {
return *isolate->factory()->NewHeapNumber(std::atan(x->Number()));
}
-// ES6 section 20.2.2.16 Math.floor ( x )
-void Builtins::Generate_MathFloor(compiler::CodeStubAssembler* assembler) {
+namespace {
+
+void Generate_MathRoundingOperation(
+ compiler::CodeStubAssembler* assembler,
+ compiler::Node* (compiler::CodeStubAssembler::*float64op)(
+ compiler::Node*)) {
typedef compiler::CodeStubAssembler::Label Label;
typedef compiler::Node Node;
typedef compiler::CodeStubAssembler::Variable Variable;
@@ -2048,7 +2052,7 @@ void Builtins::Generate_MathFloor(compiler::CodeStubAssembler* assembler) {
assembler->Bind(&if_xisheapnumber);
{
Node* x_value = assembler->LoadHeapNumberValue(x);
- Node* value = assembler->Float64Floor(x_value);
+ Node* value = (assembler->*float64op)(x_value);
Node* result = assembler->ChangeFloat64ToTagged(value);
assembler->Return(result);
}
@@ -2065,6 +2069,20 @@ void Builtins::Generate_MathFloor(compiler::CodeStubAssembler* assembler) {
}
}
+} // namespace
+
+// ES6 section 20.2.2.10 Math.ceil ( x )
+void Builtins::Generate_MathCeil(compiler::CodeStubAssembler* assembler) {
+ Generate_MathRoundingOperation(assembler,
+ &compiler::CodeStubAssembler::Float64Ceil);
+}
+
+// ES6 section 20.2.2.16 Math.floor ( x )
+void Builtins::Generate_MathFloor(compiler::CodeStubAssembler* assembler) {
+ Generate_MathRoundingOperation(assembler,
+ &compiler::CodeStubAssembler::Float64Floor);
+}
+
// ES6 section 20.2.2.17 Math.fround ( x )
BUILTIN(MathFround) {
HandleScope scope(isolate);
@@ -2087,6 +2105,12 @@ BUILTIN(MathImul) {
return *isolate->factory()->NewNumberFromInt(product);
}
+// ES6 section 20.2.2.28 Math.round ( x )
+void Builtins::Generate_MathRound(compiler::CodeStubAssembler* assembler) {
+ Generate_MathRoundingOperation(assembler,
+ &compiler::CodeStubAssembler::Float64Round);
+}
+
// ES6 section 20.2.2.32 Math.sqrt ( x )
void Builtins::Generate_MathSqrt(compiler::CodeStubAssembler* assembler) {
using compiler::Node;
@@ -2099,6 +2123,12 @@ void Builtins::Generate_MathSqrt(compiler::CodeStubAssembler* assembler) {
assembler->Return(result);
}
+// ES6 section 20.2.2.35 Math.trunc ( x )
+void Builtins::Generate_MathTrunc(compiler::CodeStubAssembler* assembler) {
+ Generate_MathRoundingOperation(assembler,
+ &compiler::CodeStubAssembler::Float64Trunc);
+}
+
// -----------------------------------------------------------------------------
// ES6 section 26.1 The Reflect Object
« no previous file with comments | « src/builtins.h ('k') | src/compiler/code-stub-assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698