Bug 815737 - Inline MathCache-reliant functions in IonMonkey. r=sstangl

This commit is contained in:
Philipp Matthias Schäfer 2013-03-03 15:56:58 -08:00
parent 4e28c8eeeb
commit ad9066a18f
5 changed files with 93 additions and 31 deletions

View File

@ -2904,9 +2904,21 @@ CodeGenerator::visitMathFunctionD(LMathFunctionD *ins)
case MMathFunction::Cos:
funptr = JS_FUNC_TO_DATA_PTR(void *, js::math_cos_impl);
break;
case MMathFunction::Exp:
funptr = JS_FUNC_TO_DATA_PTR(void *, js::math_exp_impl);
break;
case MMathFunction::Tan:
funptr = JS_FUNC_TO_DATA_PTR(void *, js::math_tan_impl);
break;
case MMathFunction::ATan:
funptr = JS_FUNC_TO_DATA_PTR(void *, js::math_atan_impl);
break;
case MMathFunction::ASin:
funptr = JS_FUNC_TO_DATA_PTR(void *, js::math_asin_impl);
break;
case MMathFunction::ACos:
funptr = JS_FUNC_TO_DATA_PTR(void *, js::math_acos_impl);
break;
default:
JS_NOT_REACHED("Unknown math function");
}

View File

@ -57,10 +57,18 @@ IonBuilder::inlineNativeCall(CallInfo &callInfo, JSNative native)
return inlineMathFunction(callInfo, MMathFunction::Sin);
if (native == js::math_cos)
return inlineMathFunction(callInfo, MMathFunction::Cos);
if (native == js::math_exp)
return inlineMathFunction(callInfo, MMathFunction::Exp);
if (native == js::math_tan)
return inlineMathFunction(callInfo, MMathFunction::Tan);
if (native == js::math_log)
return inlineMathFunction(callInfo, MMathFunction::Log);
if (native == js::math_atan)
return inlineMathFunction(callInfo, MMathFunction::ATan);
if (native == js::math_asin)
return inlineMathFunction(callInfo, MMathFunction::ASin);
if (native == js::math_acos)
return inlineMathFunction(callInfo, MMathFunction::ACos);
// String natives.
if (native == js_String)

View File

@ -2757,7 +2757,11 @@ class MMathFunction
Log,
Sin,
Cos,
Tan
Exp,
Tan,
ACos,
ASin,
ATan
};
private:

View File

@ -107,8 +107,18 @@ js_math_abs(JSContext *cx, unsigned argc, Value *vp)
return JS_TRUE;
}
static JSBool
math_acos(JSContext *cx, unsigned argc, Value *vp)
double
js::math_acos_impl(MathCache *cache, double x)
{
#if defined(SOLARIS) && defined(__GNUC__)
if (x < -1 || 1 < x)
return js_NaN;
#endif
return cache->lookup(acos, x);
}
JSBool
js::math_acos(JSContext *cx, unsigned argc, Value *vp)
{
double x, z;
@ -118,22 +128,26 @@ math_acos(JSContext *cx, unsigned argc, Value *vp)
}
if (!ToNumber(cx, vp[2], &x))
return JS_FALSE;
#if defined(SOLARIS) && defined(__GNUC__)
if (x < -1 || 1 < x) {
vp->setDouble(js_NaN);
return JS_TRUE;
}
#endif
MathCache *mathCache = cx->runtime->getMathCache(cx);
if (!mathCache)
return JS_FALSE;
z = mathCache->lookup(acos, x);
z = math_acos_impl(mathCache, x);
vp->setDouble(z);
return JS_TRUE;
}
static JSBool
math_asin(JSContext *cx, unsigned argc, Value *vp)
double
js::math_asin_impl(MathCache *cache, double x)
{
#if defined(SOLARIS) && defined(__GNUC__)
if (x < -1 || 1 < x)
return js_NaN;
#endif
return cache->lookup(asin, x);
}
JSBool
js::math_asin(JSContext *cx, unsigned argc, Value *vp)
{
double x, z;
@ -143,22 +157,22 @@ math_asin(JSContext *cx, unsigned argc, Value *vp)
}
if (!ToNumber(cx, vp[2], &x))
return JS_FALSE;
#if defined(SOLARIS) && defined(__GNUC__)
if (x < -1 || 1 < x) {
vp->setDouble(js_NaN);
return JS_TRUE;
}
#endif
MathCache *mathCache = cx->runtime->getMathCache(cx);
if (!mathCache)
return JS_FALSE;
z = mathCache->lookup(asin, x);
z = math_asin_impl(mathCache, x);
vp->setDouble(z);
return JS_TRUE;
}
static JSBool
math_atan(JSContext *cx, unsigned argc, Value *vp)
double
js::math_atan_impl(MathCache *cache, double x)
{
return cache->lookup(atan, x);
}
JSBool
js::math_atan(JSContext *cx, unsigned argc, Value *vp)
{
double x, z;
@ -171,7 +185,7 @@ math_atan(JSContext *cx, unsigned argc, Value *vp)
MathCache *mathCache = cx->runtime->getMathCache(cx);
if (!mathCache)
return JS_FALSE;
z = mathCache->lookup(atan, x);
z = math_atan_impl(mathCache, x);
vp->setDouble(z);
return JS_TRUE;
}
@ -273,22 +287,22 @@ js::math_cos(JSContext *cx, unsigned argc, Value *vp)
return JS_TRUE;
}
static double
math_exp_body(double d)
double
js::math_exp_impl(MathCache *cache, double x)
{
#ifdef _WIN32
if (!MOZ_DOUBLE_IS_NaN(d)) {
if (d == js_PositiveInfinity)
if (!MOZ_DOUBLE_IS_NaN(x)) {
if (x == js_PositiveInfinity)
return js_PositiveInfinity;
if (d == js_NegativeInfinity)
if (x == js_NegativeInfinity)
return 0.0;
}
#endif
return exp(d);
return cache->lookup(exp, x);
}
static JSBool
math_exp(JSContext *cx, unsigned argc, Value *vp)
JSBool
js::math_exp(JSContext *cx, unsigned argc, Value *vp)
{
double x, z;
@ -301,7 +315,7 @@ math_exp(JSContext *cx, unsigned argc, Value *vp)
MathCache *mathCache = cx->runtime->getMathCache(cx);
if (!mathCache)
return JS_FALSE;
z = mathCache->lookup(math_exp_body, x);
z = math_exp_impl(mathCache, x);
vp->setNumber(z);
return JS_TRUE;
}

View File

@ -116,12 +116,36 @@ math_cos(JSContext *cx, unsigned argc, js::Value *vp);
extern double
math_cos_impl(MathCache *cache, double x);
extern JSBool
math_exp(JSContext *cx, unsigned argc, js::Value *vp);
extern double
math_exp_impl(MathCache *cache, double x);
extern JSBool
math_tan(JSContext *cx, unsigned argc, js::Value *vp);
extern double
math_tan_impl(MathCache *cache, double x);
extern double
math_atan_impl(MathCache *cache, double x);
extern JSBool
math_atan(JSContext *cx, unsigned argc, js::Value *vp);
extern double
math_asin_impl(MathCache *cache, double x);
extern JSBool
math_asin(JSContext *cx, unsigned argc, js::Value *vp);
extern double
math_acos_impl(MathCache *cache, double x);
extern JSBool
math_acos(JSContext *cx, unsigned argc, js::Value *vp);
extern double
powi(double x, int y);