зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1010698 - SpiderMonkey: Include the function in the math cache hash computation. r=luke
This commit is contained in:
Родитель
180d6030ce
Коммит
1899dc35a5
|
@ -67,7 +67,7 @@ MathCache::MathCache() {
|
|||
/* See comments in lookup(). */
|
||||
JS_ASSERT(IsNegativeZero(-0.0));
|
||||
JS_ASSERT(!IsNegativeZero(+0.0));
|
||||
JS_ASSERT(hash(-0.0) != hash(+0.0));
|
||||
JS_ASSERT(hash(-0.0, MathCache::Sin) != hash(+0.0, MathCache::Sin));
|
||||
}
|
||||
|
||||
size_t
|
||||
|
@ -117,7 +117,7 @@ double
|
|||
js::math_acos_impl(MathCache *cache, double x)
|
||||
{
|
||||
ACOS_IF_OUT_OF_RANGE(x);
|
||||
return cache->lookup(acos, x);
|
||||
return cache->lookup(acos, x, MathCache::Acos);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -162,7 +162,7 @@ double
|
|||
js::math_asin_impl(MathCache *cache, double x)
|
||||
{
|
||||
ASIN_IF_OUT_OF_RANGE(x);
|
||||
return cache->lookup(asin, x);
|
||||
return cache->lookup(asin, x, MathCache::Asin);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -200,7 +200,7 @@ js::math_asin(JSContext *cx, unsigned argc, Value *vp)
|
|||
double
|
||||
js::math_atan_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(atan, x);
|
||||
return cache->lookup(atan, x, MathCache::Atan);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -335,7 +335,7 @@ js::math_clz32(JSContext *cx, unsigned argc, Value *vp)
|
|||
double
|
||||
js::math_cos_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(cos, x);
|
||||
return cache->lookup(cos, x, MathCache::Cos);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -383,7 +383,7 @@ double
|
|||
js::math_exp_impl(MathCache *cache, double x)
|
||||
{
|
||||
EXP_IF_OUT_OF_RANGE(x);
|
||||
return cache->lookup(exp, x);
|
||||
return cache->lookup(exp, x, MathCache::Exp);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -510,7 +510,7 @@ double
|
|||
js::math_log_impl(MathCache *cache, double x)
|
||||
{
|
||||
LOG_IF_OUT_OF_RANGE(x);
|
||||
return cache->lookup(log, x);
|
||||
return cache->lookup(log, x, MathCache::Log);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -826,7 +826,7 @@ js::math_round(JSContext *cx, unsigned argc, Value *vp)
|
|||
double
|
||||
js::math_sin_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(sin, x);
|
||||
return cache->lookup(sin, x, MathCache::Sin);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -876,7 +876,7 @@ js_math_sqrt(JSContext *cx, unsigned argc, Value *vp)
|
|||
if (!mathCache)
|
||||
return false;
|
||||
|
||||
double z = mathCache->lookup(sqrt, x);
|
||||
double z = mathCache->lookup(sqrt, x, MathCache::Sqrt);
|
||||
args.rval().setDouble(z);
|
||||
return true;
|
||||
}
|
||||
|
@ -884,7 +884,7 @@ js_math_sqrt(JSContext *cx, unsigned argc, Value *vp)
|
|||
double
|
||||
js::math_tan_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(tan, x);
|
||||
return cache->lookup(tan, x, MathCache::Tan);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -946,7 +946,7 @@ static bool math_function(JSContext *cx, unsigned argc, Value *vp)
|
|||
double
|
||||
js::math_log10_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(log10, x);
|
||||
return cache->lookup(log10, x, MathCache::Log10);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -971,7 +971,7 @@ double log2(double x)
|
|||
double
|
||||
js::math_log2_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(log2, x);
|
||||
return cache->lookup(log2, x, MathCache::Log2);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -1014,7 +1014,7 @@ double
|
|||
js::math_log1p_impl(MathCache *cache, double x)
|
||||
{
|
||||
LOG1P_IF_OUT_OF_RANGE(x);
|
||||
return cache->lookup(log1p, x);
|
||||
return cache->lookup(log1p, x, MathCache::Log1p);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -1056,7 +1056,7 @@ double expm1(double x)
|
|||
double
|
||||
js::math_expm1_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(expm1, x);
|
||||
return cache->lookup(expm1, x, MathCache::Expm1);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -1086,7 +1086,7 @@ double sqrt1pm1(double x)
|
|||
double
|
||||
js::math_cosh_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(cosh, x);
|
||||
return cache->lookup(cosh, x, MathCache::Cosh);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -1104,7 +1104,7 @@ js::math_cosh(JSContext *cx, unsigned argc, Value *vp)
|
|||
double
|
||||
js::math_sinh_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(sinh, x);
|
||||
return cache->lookup(sinh, x, MathCache::Sinh);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -1122,7 +1122,7 @@ js::math_sinh(JSContext *cx, unsigned argc, Value *vp)
|
|||
double
|
||||
js::math_tanh_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(tanh, x);
|
||||
return cache->lookup(tanh, x, MathCache::Tanh);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -1171,7 +1171,7 @@ double acosh(double x)
|
|||
double
|
||||
js::math_acosh_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(acosh, x);
|
||||
return cache->lookup(acosh, x, MathCache::Acosh);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -1225,9 +1225,9 @@ double
|
|||
js::math_asinh_impl(MathCache *cache, double x)
|
||||
{
|
||||
#ifdef HAVE_ASINH
|
||||
return cache->lookup(asinh, x);
|
||||
return cache->lookup(asinh, x, MathCache::Asinh);
|
||||
#else
|
||||
return cache->lookup(my_asinh, x);
|
||||
return cache->lookup(my_asinh, x, MathCache::Asinh);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1278,7 +1278,7 @@ double atanh(double x)
|
|||
double
|
||||
js::math_atanh_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(atanh, x);
|
||||
return cache->lookup(atanh, x, MathCache::Atanh);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -1369,7 +1369,7 @@ double trunc(double x)
|
|||
double
|
||||
js::math_trunc_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(trunc, x);
|
||||
return cache->lookup(trunc, x, MathCache::Trunc);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -1395,7 +1395,7 @@ static double sign(double x)
|
|||
double
|
||||
js::math_sign_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(sign, x);
|
||||
return cache->lookup(sign, x, MathCache::Sign);
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -1426,7 +1426,7 @@ double cbrt(double x)
|
|||
double
|
||||
js::math_cbrt_impl(MathCache *cache, double x)
|
||||
{
|
||||
return cache->lookup(cbrt, x);
|
||||
return cache->lookup(cbrt, x, MathCache::Cbrt);
|
||||
}
|
||||
|
||||
double
|
||||
|
|
|
@ -42,17 +42,26 @@ typedef double (*UnaryFunType)(double);
|
|||
|
||||
class MathCache
|
||||
{
|
||||
public:
|
||||
enum MathFuncId {
|
||||
Zero,
|
||||
Sin, Cos, Tan, Sinh, Cosh, Tanh, Asin, Acos, Atan, Asinh, Acosh, Atanh,
|
||||
Sqrt, Log, Log10, Log2, Log1p, Exp, Expm1, Cbrt, Trunc, Sign
|
||||
};
|
||||
|
||||
private:
|
||||
static const unsigned SizeLog2 = 12;
|
||||
static const unsigned Size = 1 << SizeLog2;
|
||||
struct Entry { double in; UnaryFunType f; double out; };
|
||||
struct Entry { double in; MathFuncId id; double out; };
|
||||
Entry table[Size];
|
||||
|
||||
public:
|
||||
MathCache();
|
||||
|
||||
unsigned hash(double x) {
|
||||
unsigned hash(double x, MathFuncId id) {
|
||||
union { double d; struct { uint32_t one, two; } s; } u = { x };
|
||||
uint32_t hash32 = u.s.one ^ u.s.two;
|
||||
hash32 += uint32_t(id) << 8;
|
||||
uint16_t hash16 = uint16_t(hash32 ^ (hash32 >> 16));
|
||||
return (hash16 & (Size - 1)) ^ (hash16 >> (16 - SizeLog2));
|
||||
}
|
||||
|
@ -61,13 +70,13 @@ class MathCache
|
|||
* N.B. lookup uses double-equality. This is only safe if hash() maps +0
|
||||
* and -0 to different table entries, which is asserted in MathCache().
|
||||
*/
|
||||
double lookup(UnaryFunType f, double x) {
|
||||
unsigned index = hash(x);
|
||||
double lookup(UnaryFunType f, double x, MathFuncId id) {
|
||||
unsigned index = hash(x, id);
|
||||
Entry &e = table[index];
|
||||
if (e.in == x && e.f == f)
|
||||
if (e.in == x && e.id == id)
|
||||
return e.out;
|
||||
e.in = x;
|
||||
e.f = f;
|
||||
e.id = id;
|
||||
return e.out = f(x);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче