Bug 876916 - Hook up Math.sqrt to MSqrt in asm.js. r=luke
authorDan Gohman <sunfish@google.com>
Wed, 29 May 2013 20:37:36 -0400
changeset 133355 17143afc4fab97b13075c80b2e2ca8d58d93994d
parent 133354 4f0b307026f59416af7d94d3f1eba87f4672b89d
child 133356 4a2289396667dccaea957ab8b7471315968158f5
push id28724
push userryanvm@gmail.com
push dateThu, 30 May 2013 00:37:49 +0000
treeherdermozilla-inbound@17143afc4fab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs876916
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 876916 - Hook up Math.sqrt to MSqrt in asm.js. r=luke
js/src/ion/AsmJS.cpp
js/src/ion/MIR.h
--- a/js/src/ion/AsmJS.cpp
+++ b/js/src/ion/AsmJS.cpp
@@ -3337,16 +3337,38 @@ CheckMathAbs(FunctionCompiler &f, ParseN
         *type = Type::Double;
         return true;
     }
 
     return f.failf(call, "%s is not a subtype of signed or doublish", argType.toChars());
 }
 
 static bool
+CheckMathSqrt(FunctionCompiler &f, ParseNode *call, MDefinition **def, Type *type)
+{
+    if (CallArgListLength(call) != 1)
+        return f.fail(call, "Math.sqrt must be passed 1 argument");
+
+    ParseNode *arg = CallArgList(call);
+
+    MDefinition *argDef;
+    Type argType;
+    if (!CheckExpr(f, arg, Use::ToNumber, &argDef, &argType))
+        return false;
+
+    if (argType.isDoublish()) {
+        *def = f.unary<MSqrt>(argDef, MIRType_Double);
+        *type = Type::Double;
+        return true;
+    }
+
+    return f.failf(call, "%s is not a subtype of doublish", argType.toChars());
+}
+
+static bool
 CheckCallArgs(FunctionCompiler &f, ParseNode *callNode, Use use, FunctionCompiler::Args *args)
 {
     f.startCallArgs(args);
 
     ParseNode *argNode = CallArgList(callNode);
     for (unsigned i = 0; i < CallArgListLength(callNode); i++, argNode = NextNode(argNode)) {
         MDefinition *argDef;
         Type argType;
@@ -3536,17 +3558,17 @@ CheckMathBuiltinCall(FunctionCompiler &f
       case AsmJSMathBuiltin_tan:   arity = 1; callee = UnaryMathFunCast(tan);        break;
       case AsmJSMathBuiltin_asin:  arity = 1; callee = UnaryMathFunCast(asin);       break;
       case AsmJSMathBuiltin_acos:  arity = 1; callee = UnaryMathFunCast(acos);       break;
       case AsmJSMathBuiltin_atan:  arity = 1; callee = UnaryMathFunCast(atan);       break;
       case AsmJSMathBuiltin_ceil:  arity = 1; callee = UnaryMathFunCast(ceil);       break;
       case AsmJSMathBuiltin_floor: arity = 1; callee = UnaryMathFunCast(floor);      break;
       case AsmJSMathBuiltin_exp:   arity = 1; callee = UnaryMathFunCast(exp);        break;
       case AsmJSMathBuiltin_log:   arity = 1; callee = UnaryMathFunCast(log);        break;
-      case AsmJSMathBuiltin_sqrt:  arity = 1; callee = UnaryMathFunCast(sqrt);       break;
+      case AsmJSMathBuiltin_sqrt:  return CheckMathSqrt(f, callNode, def, type);
       case AsmJSMathBuiltin_pow:   arity = 2; callee = BinaryMathFunCast(ecmaPow);   break;
       case AsmJSMathBuiltin_atan2: arity = 2; callee = BinaryMathFunCast(ecmaAtan2); break;
     }
 
     FunctionCompiler::Args args(f);
 
     if (!CheckCallArgs(f, callNode, Use::ToNumber, &args))
         return false;
--- a/js/src/ion/MIR.h
+++ b/js/src/ion/MIR.h
@@ -3025,16 +3025,20 @@ class MSqrt
         setMovable();
     }
 
   public:
     INSTRUCTION_HEADER(Sqrt)
     static MSqrt *New(MDefinition *num) {
         return new MSqrt(num);
     }
+    static MSqrt *NewAsmJS(MDefinition *num, MIRType type) {
+        JS_ASSERT(type == MIRType_Double);
+        return new MSqrt(num);
+    }
     MDefinition *num() const {
         return getOperand(0);
     }
     TypePolicy *typePolicy() {
         return this;
     }
     bool congruentTo(MDefinition *const &ins) const {
         return congruentIfOperandsEqual(ins);