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

Unified Diff: src/compiler/js-builtin-reducer.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/compiler/js-builtin-reducer.h ('k') | src/compiler/opcodes.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/js-builtin-reducer.cc
diff --git a/src/compiler/js-builtin-reducer.cc b/src/compiler/js-builtin-reducer.cc
index 4a284cc8dbeba8faf5472fed54c25a98097e21ea..c7a2326254fcde55a150d552746b747c887152ef 100644
--- a/src/compiler/js-builtin-reducer.cc
+++ b/src/compiler/js-builtin-reducer.cc
@@ -130,6 +130,17 @@ Reduction JSBuiltinReducer::ReduceMathImul(Node* node) {
}
// ES6 draft 08-24-14, section 20.2.2.16.
+Reduction JSBuiltinReducer::ReduceMathCeil(Node* node) {
+ JSCallReduction r(node);
+ if (r.InputsMatchOne(Type::Number())) {
+ // Math.ceil(a:number) -> NumberCeil(a)
+ Node* value = graph()->NewNode(simplified()->NumberCeil(), r.left());
+ return Replace(value);
+ }
+ return NoChange();
+}
+
+// ES6 draft 08-24-14, section 20.2.2.16.
Reduction JSBuiltinReducer::ReduceMathFloor(Node* node) {
JSCallReduction r(node);
if (r.InputsMatchOne(Type::Number())) {
@@ -155,25 +166,10 @@ Reduction JSBuiltinReducer::ReduceMathFround(Node* node) {
// ES6 section 20.2.2.28 Math.round ( x )
Reduction JSBuiltinReducer::ReduceMathRound(Node* node) {
JSCallReduction r(node);
- if (r.InputsMatchOne(type_cache_.kIntegerOrMinusZeroOrNaN)) {
- // Math.round(a:integer \/ -0 \/ NaN) -> a
- return Replace(r.left());
- }
- if (r.InputsMatchOne(Type::Number()) &&
- machine()->Float64RoundUp().IsSupported()) {
- // Math.round(a:number) -> Select(Float64LessThan(#0.5, Float64Sub(i, a)),
- // Float64Sub(i, #1.0), i)
- // where i = Float64RoundUp(a)
- Node* value = r.left();
- Node* integer = graph()->NewNode(machine()->Float64RoundUp().op(), value);
- Node* real = graph()->NewNode(machine()->Float64Sub(), integer, value);
- return Replace(graph()->NewNode(
- common()->Select(MachineRepresentation::kFloat64),
- graph()->NewNode(machine()->Float64LessThan(),
- jsgraph()->Float64Constant(0.5), real),
- graph()->NewNode(machine()->Float64Sub(), integer,
- jsgraph()->Float64Constant(1.0)),
- integer));
+ if (r.InputsMatchOne(Type::Number())) {
+ // Math.round(a:number) -> NumberRound(a)
+ Node* value = graph()->NewNode(simplified()->NumberRound(), r.left());
+ return Replace(value);
}
return NoChange();
}
@@ -189,6 +185,17 @@ Reduction JSBuiltinReducer::ReduceMathSqrt(Node* node) {
return NoChange();
}
+// ES6 section 20.2.2.35 Math.trunc ( x )
+Reduction JSBuiltinReducer::ReduceMathTrunc(Node* node) {
+ JSCallReduction r(node);
+ if (r.InputsMatchOne(Type::Number())) {
+ // Math.trunc(a:number) -> NumberTrunc(a)
+ Node* value = graph()->NewNode(simplified()->NumberTrunc(), r.left());
+ return Replace(value);
+ }
+ return NoChange();
+}
+
Reduction JSBuiltinReducer::Reduce(Node* node) {
Reduction reduction = NoChange();
JSCallReduction r(node);
@@ -202,6 +209,9 @@ Reduction JSBuiltinReducer::Reduce(Node* node) {
case kMathImul:
reduction = ReduceMathImul(node);
break;
+ case kMathCeil:
+ reduction = ReduceMathCeil(node);
+ break;
case kMathFloor:
reduction = ReduceMathFloor(node);
break;
@@ -214,6 +224,9 @@ Reduction JSBuiltinReducer::Reduce(Node* node) {
case kMathSqrt:
reduction = ReduceMathSqrt(node);
break;
+ case kMathTrunc:
+ reduction = ReduceMathTrunc(node);
+ break;
default:
break;
}
« no previous file with comments | « src/compiler/js-builtin-reducer.h ('k') | src/compiler/opcodes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698