Bug 876916 - Hook up Math.sqrt to MSqrt in asm.js. r=luke

This commit is contained in:
Dan Gohman 2013-05-29 20:37:36 -04:00
parent 3ba81379fd
commit 285c5366c0
2 changed files with 27 additions and 1 deletions

View File

@ -3341,6 +3341,28 @@ CheckMathAbs(FunctionCompiler &f, ParseNode *call, MDefinition **def, Type *type
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)
{
@ -3541,7 +3563,7 @@ CheckMathBuiltinCall(FunctionCompiler &f, ParseNode *callNode, AsmJSMathBuiltin
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;
}

View File

@ -3030,6 +3030,10 @@ class MSqrt
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);
}