Reviewers: Yang,

Description:
[turbofan] More inlinable Math builtins.

Turn Math.acos, Math.asin, Math.atan, Math.atan2, Math.sign and Math.trunc
into inlinable builtins.

[email protected]
BUG=v8:3952
LOG=n

Please review this at https://codereview.chromium.org/1027713002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+20, -8 lines):
  M src/compiler/typer.cc
  M src/math.js


Index: src/compiler/typer.cc
diff --git a/src/compiler/typer.cc b/src/compiler/typer.cc
index 89c1f9945e06ecd72821c2590b774e8a346757f0..a64e5a9c6e3df0af9fe750adce54838dfa0d60ed 100644
--- a/src/compiler/typer.cc
+++ b/src/compiler/typer.cc
@@ -1536,6 +1536,10 @@ Bounds Typer::Visitor::TypeJSCallRuntime(Node* node) {
     case Runtime::kInlineConstructDouble:
     case Runtime::kInlineMathFloor:
     case Runtime::kInlineMathSqrt:
+    case Runtime::kInlineMathAcos:
+    case Runtime::kInlineMathAsin:
+    case Runtime::kInlineMathAtan:
+    case Runtime::kInlineMathAtan2:
       return Bounds(Type::None(zone()), Type::Number());
     case Runtime::kInlineMathClz32:
       return Bounds(Type::None(), Type::Range(0, 32, zone()));
Index: src/math.js
diff --git a/src/math.js b/src/math.js
index f2eaa14bf9bd547817497651e859f045b57276cc..b802de0f461130cf01cb71e864e9ae69e0af1829 100644
--- a/src/math.js
+++ b/src/math.js
@@ -30,24 +30,26 @@ function MathAbs(x) {

 // ECMA 262 - 15.8.2.2
 function MathAcosJS(x) {
-  return %MathAcos(TO_NUMBER_INLINE(x));
+  return %_MathAcos(+x);
 }

 // ECMA 262 - 15.8.2.3
 function MathAsinJS(x) {
-  return %MathAsin(TO_NUMBER_INLINE(x));
+  return %_MathAsin(+x);
 }

 // ECMA 262 - 15.8.2.4
 function MathAtanJS(x) {
-  return %MathAtan(TO_NUMBER_INLINE(x));
+  return %_MathAtan(+x);
 }

 // ECMA 262 - 15.8.2.5
 // The naming of y and x matches the spec, as does the order in which
 // ToNumber (valueOf) is called.
 function MathAtan2JS(y, x) {
-  return %MathAtan2(TO_NUMBER_INLINE(y), TO_NUMBER_INLINE(x));
+  y = +y;
+  x = +x;
+  return %_MathAtan2(y, x);
 }

 // ECMA 262 - 15.8.2.6
@@ -157,7 +159,7 @@ function MathImul(x, y) {

 // ES6 draft 09-27-13, section 20.2.2.28.
 function MathSign(x) {
-  x = TO_NUMBER_INLINE(x);
+  x = +x;
   if (x > 0) return 1;
   if (x < 0) return -1;
   // -0, 0 or NaN.
@@ -166,9 +168,9 @@ function MathSign(x) {

 // ES6 draft 09-27-13, section 20.2.2.34.
 function MathTrunc(x) {
-  x = TO_NUMBER_INLINE(x);
-  if (x > 0) return MathFloorJS(x);
-  if (x < 0) return MathCeil(x);
+  x = +x;
+  if (x > 0) return %_MathFloor(x);
+  if (x < 0) return -%_MathFloor(-x);
   // -0, 0 or NaN.
   return x;
 }
@@ -341,11 +343,17 @@ InstallFunctions(Math, DONT_ENUM, GlobalArray(
 ));

 %SetInlineBuiltinFlag(MathAbs);
+%SetInlineBuiltinFlag(MathAcosJS);
+%SetInlineBuiltinFlag(MathAsinJS);
+%SetInlineBuiltinFlag(MathAtanJS);
+%SetInlineBuiltinFlag(MathAtan2JS);
 %SetInlineBuiltinFlag(MathCeil);
 %SetInlineBuiltinFlag(MathClz32JS);
 %SetInlineBuiltinFlag(MathFloorJS);
 %SetInlineBuiltinFlag(MathRandom);
+%SetInlineBuiltinFlag(MathSign);
 %SetInlineBuiltinFlag(MathSqrtJS);
+%SetInlineBuiltinFlag(MathTrunc);

 // Expose to the global scope.
 $abs = MathAbs;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to