Revert "Reland "[builtins] [turbofan] Refactor Float64Pow to use single implementation""

This reverts commit d7def9003d.

Reason for revert: Breaks UBSan:
https://ci.chromium.org/p/v8/builders/luci.v8.ci/V8%20Linux64%20UBSan/4542

Besides undefined behavior, things were looking good!


Original change's description:
> Reland "[builtins] [turbofan] Refactor Float64Pow to use single implementation"
> 
> This is a reland of I968a08cef6a6d49350aa79185b2c6fb856d15f23
> 
> Original change's description:
> > [builtins] [turbofan] Refactor Float64Pow to use single implementation
> >
> > Remove platform-specific Float64Pow implementations and utils Pow in
> > favor of a base::ieee754::pow implementation.
> >
> > This unifies the implementation of pow for the compiler, wasm, and
> > runtime.
> >
> > Bug: v8:5848, v8:5086
> > Change-Id: I968a08cef6a6d49350aa79185b2c6fb856d15f23
> > Reviewed-on: https://chromium-review.googlesource.com/c/1403018
> > Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
> > Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
> > Reviewed-by: Georg Neis <neis@chromium.org>
> > Reviewed-by: Yang Guo <yangguo@chromium.org>
> > Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#59229}
> 
> Bug: v8:5848, v8:5086
> Change-Id: I92f22ae03adafd9ad042e8d4bb406cbd5b5fb51e
> Cq-Include-Trybots: luci.chromium.try:linux_chromium_ubsan_rel_ng
> Reviewed-on: https://chromium-review.googlesource.com/c/1447854
> Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
> Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
> Reviewed-by: Georg Neis <neis@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#59411}

TBR=jkummerow@chromium.org,jarin@chromium.org,neis@chromium.org,jgruber@chromium.org,clemensh@chromium.org,bmeurer@chromium.org,me@gus.host

Change-Id: I65c4bbd3ab7aaa1c396d182467c5a1fe6a639df5
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:5848, v8:5086
Cq-Include-Trybots: luci.chromium.try:linux_chromium_ubsan_rel_ng
Reviewed-on: https://chromium-review.googlesource.com/c/1456107
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59419}
This commit is contained in:
Sigurd Schneider 2019-02-06 15:49:32 +00:00 committed by Commit Bot
parent 69d26c73cf
commit d691fde360
28 changed files with 904 additions and 384 deletions

View File

@ -2647,326 +2647,6 @@ double cosh(double x) {
return huge * huge;
}
/*
* ES2019 Draft 2019-01-02 12.6.4
* Math.pow & Exponentiation Operator
*
* Return X raised to the Yth power
*
* Method:
* Let x = 2 * (1+f)
* 1. Compute and return log2(x) in two pieces:
* log2(x) = w1 + w2,
* where w1 has 53-24 = 29 bit trailing zeros.
* 2. Perform y*log2(x) = n+y' by simulating muti-precision
* arithmetic, where |y'|<=0.5.
* 3. Return x**y = 2**n*exp(y'*log2)
*
* Special cases:
* 1. (anything) ** 0 is 1
* 2. (anything) ** 1 is itself
* 3. (anything) ** NAN is NAN
* 4. NAN ** (anything except 0) is NAN
* 5. +-(|x| > 1) ** +INF is +INF
* 6. +-(|x| > 1) ** -INF is +0
* 7. +-(|x| < 1) ** +INF is +0
* 8. +-(|x| < 1) ** -INF is +INF
* 9. +-1 ** +-INF is NAN
* 10. +0 ** (+anything except 0, NAN) is +0
* 11. -0 ** (+anything except 0, NAN, odd integer) is +0
* 12. +0 ** (-anything except 0, NAN) is +INF
* 13. -0 ** (-anything except 0, NAN, odd integer) is +INF
* 14. -0 ** (odd integer) = -( +0 ** (odd integer) )
* 15. +INF ** (+anything except 0,NAN) is +INF
* 16. +INF ** (-anything except 0,NAN) is +0
* 17. -INF ** (anything) = -0 ** (-anything)
* 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
* 19. (-anything except 0 and inf) ** (non-integer) is NAN
*
* Accuracy:
* pow(x,y) returns x**y nearly rounded. In particular,
* pow(integer, integer) always returns the correct integer provided it is
* representable.
*
* Constants:
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
#ifdef V8_TARGET_LITTLE_ENDIAN
#define __HI(x) *(1 + reinterpret_cast<int*>(&x))
#define __LO(x) *reinterpret_cast<int*>(&x)
#else
#define __HI(x) *reinterpret_cast<int*>(&x)
#define __LO(x) *(1 + reinterpret_cast<int*>(&x))
#endif
static_assert(std::numeric_limits<double>::is_iec559,
"IEC-599/IEEE 754 support is required");
CLANG_NO_SANITIZE("float-divide-by-zero")
double pow(double x, double y) {
static const double
bp[] = {1.0, 1.5},
dp_h[] = {0.0, 5.84962487220764160156e-01}, // 0x3FE2B803, 0x40000000
dp_l[] = {0.0, 1.35003920212974897128e-08}, // 0x3E4CFDEB, 0x43CFD006
zero = 0.0, one = 1.0, two = 2.0,
two53 = 9007199254740992.0, // 0x43400000, 0x00000000
huge = 1.0e300, tiny = 1.0e-300,
// poly coefs for (3/2)*(log(x)-2s-2/3*s**3
L1 = 5.99999999999994648725e-01, // 0x3FE33333, 0x33333303
L2 = 4.28571428578550184252e-01, // 0x3FDB6DB6, 0xDB6FABFF
L3 = 3.33333329818377432918e-01, // 0x3FD55555, 0x518F264D
L4 = 2.72728123808534006489e-01, // 0x3FD17460, 0xA91D4101
L5 = 2.30660745775561754067e-01, // 0x3FCD864A, 0x93C9DB65
L6 = 2.06975017800338417784e-01, // 0x3FCA7E28, 0x4A454EEF
P1 = 1.66666666666666019037e-01, // 0x3FC55555, 0x5555553E
P2 = -2.77777777770155933842e-03, // 0xBF66C16C, 0x16BEBD93
P3 = 6.61375632143793436117e-05, // 0x3F11566A, 0xAF25DE2C
P4 = -1.65339022054652515390e-06, // 0xBEBBBD41, 0xC5D26BF1
P5 = 4.13813679705723846039e-08, // 0x3E663769, 0x72BEA4D0
lg2 = 6.93147180559945286227e-01, // 0x3FE62E42, 0xFEFA39EF
lg2_h = 6.93147182464599609375e-01, // 0x3FE62E43, 0x00000000
lg2_l = -1.90465429995776804525e-09, // 0xBE205C61, 0x0CA86C39
ovt = 8.0085662595372944372e-0017, // -(1024-log2(ovfl+.5ulp))
cp = 9.61796693925975554329e-01, // 0x3FEEC709, 0xDC3A03FD =2/(3ln2)
cp_h = 9.61796700954437255859e-01, // 0x3FEEC709, 0xE0000000 =(float)cp
cp_l = -7.02846165095275826516e-09, // 0xBE3E2FE0, 0x145B01F5 =tail cp_h
ivln2 = 1.44269504088896338700e+00, // 0x3FF71547, 0x652B82FE =1/ln2
ivln2_h =
1.44269502162933349609e+00, // 0x3FF71547, 0x60000000 =24b 1/ln2
ivln2_l =
1.92596299112661746887e-08; // 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail
double z, ax, z_h, z_l, p_h, p_l;
double y1, t1, t2, r, s, t, u, v, w;
int i, j, k, yisint, n;
int hx, hy, ix, iy;
unsigned lx, ly;
hx = __HI(x);
lx = __LO(x);
hy = __HI(y);
ly = __LO(y);
ix = hx & 0x7fffffff;
iy = hy & 0x7fffffff;
/* y==zero: x**0 = 1 */
if ((iy | ly) == 0) return one;
/* +-NaN return x+y */
if (ix > 0x7ff00000 || ((ix == 0x7ff00000) && (lx != 0)) || iy > 0x7ff00000 ||
((iy == 0x7ff00000) && (ly != 0)))
return x + y;
/* determine if y is an odd int when x < 0
* yisint = 0 ... y is not an integer
* yisint = 1 ... y is an odd int
* yisint = 2 ... y is an even int
*/
yisint = 0;
if (hx < 0) {
if (iy >= 0x43400000) {
yisint = 2; /* even integer y */
} else if (iy >= 0x3ff00000) {
k = (iy >> 20) - 0x3ff; /* exponent */
if (k > 20) {
j = ly >> (52 - k);
if ((j << (52 - k)) == static_cast<int>(ly)) yisint = 2 - (j & 1);
} else if (ly == 0) {
j = iy >> (20 - k);
if ((j << (20 - k)) == iy) yisint = 2 - (j & 1);
}
}
}
/* special value of y */
if (ly == 0) {
if (iy == 0x7ff00000) { /* y is +-inf */
if (((ix - 0x3ff00000) | lx) == 0)
return y - y; /* inf**+-1 is NaN */
else if (ix >= 0x3ff00000) /* (|x|>1)**+-inf = inf,0 */
return (hy >= 0) ? y : zero;
else /* (|x|<1)**-,+inf = inf,0 */
return (hy < 0) ? -y : zero;
}
if (iy == 0x3ff00000) { /* y is +-1 */
if (hy < 0)
return one / x;
else
return x;
}
if (hy == 0x40000000) return x * x; /* y is 2 */
if (hy == 0x3fe00000) { /* y is 0.5 */
if (hx >= 0) /* x >= +0 */
return sqrt(x);
}
}
ax = fabs(x);
/* special value of x */
if (lx == 0) {
if (ix == 0x7ff00000 || ix == 0 || ix == 0x3ff00000) {
z = ax; /*x is +-0,+-inf,+-1*/
if (hy < 0) z = one / z; /* z = (1/|x|) */
if (hx < 0) {
if (((ix - 0x3ff00000) | yisint) == 0) {
/* (-1)**non-int is NaN */
z = std::numeric_limits<double>::signaling_NaN();
} else if (yisint == 1) {
z = -z; /* (x<0)**odd = -(|x|**odd) */
}
}
return z;
}
}
n = (hx >> 31) + 1;
/* (x<0)**(non-int) is NaN */
if ((n | yisint) == 0) {
return std::numeric_limits<double>::signaling_NaN();
}
s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
if ((n | (yisint - 1)) == 0) s = -one; /* (-ve)**(odd int) */
/* |y| is huge */
if (iy > 0x41e00000) { /* if |y| > 2**31 */
if (iy > 0x43f00000) { /* if |y| > 2**64, must o/uflow */
if (ix <= 0x3fefffff) return (hy < 0) ? huge * huge : tiny * tiny;
if (ix >= 0x3ff00000) return (hy > 0) ? huge * huge : tiny * tiny;
}
/* over/underflow if x is not close to one */
if (ix < 0x3fefffff) return (hy < 0) ? s * huge * huge : s * tiny * tiny;
if (ix > 0x3ff00000) return (hy > 0) ? s * huge * huge : s * tiny * tiny;
/* now |1-x| is tiny <= 2**-20, suffice to compute
log(x) by x-x^2/2+x^3/3-x^4/4 */
t = ax - one; /* t has 20 trailing zeros */
w = (t * t) * (0.5 - t * (0.3333333333333333333333 - t * 0.25));
u = ivln2_h * t; /* ivln2_h has 21 sig. bits */
v = t * ivln2_l - w * ivln2;
t1 = u + v;
__LO(t1) = 0;
t2 = v - (t1 - u);
} else {
double ss, s2, s_h, s_l, t_h, t_l;
n = 0;
/* take care subnormal number */
if (ix < 0x00100000) {
ax *= two53;
n -= 53;
ix = __HI(ax);
}
n += ((ix) >> 20) - 0x3ff;
j = ix & 0x000fffff;
/* determine interval */
ix = j | 0x3ff00000; /* normalize ix */
if (j <= 0x3988E) {
k = 0; /* |x|<sqrt(3/2) */
} else if (j < 0xBB67A) {
k = 1; /* |x|<sqrt(3) */
} else {
k = 0;
n += 1;
ix -= 0x00100000;
}
__HI(ax) = ix;
/* compute ss = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
u = ax - bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
v = one / (ax + bp[k]);
ss = u * v;
s_h = ss;
__LO(s_h) = 0;
/* t_h=ax+bp[k] High */
t_h = zero;
__HI(t_h) = ((ix >> 1) | 0x20000000) + 0x00080000 + (k << 18);
t_l = ax - (t_h - bp[k]);
s_l = v * ((u - s_h * t_h) - s_h * t_l);
/* compute log(ax) */
s2 = ss * ss;
r = s2 * s2 *
(L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6)))));
r += s_l * (s_h + ss);
s2 = s_h * s_h;
t_h = 3.0 + s2 + r;
__LO(t_h) = 0;
t_l = r - ((t_h - 3.0) - s2);
/* u+v = ss*(1+...) */
u = s_h * t_h;
v = s_l * t_h + t_l * ss;
/* 2/(3log2)*(ss+...) */
p_h = u + v;
__LO(p_h) = 0;
p_l = v - (p_h - u);
z_h = cp_h * p_h; /* cp_h+cp_l = 2/(3*log2) */
z_l = cp_l * p_h + p_l * cp + dp_l[k];
/* log2(ax) = (ss+..)*2/(3*log2) = n + dp_h + z_h + z_l */
t = static_cast<double>(n);
t1 = (((z_h + z_l) + dp_h[k]) + t);
__LO(t1) = 0;
t2 = z_l - (((t1 - t) - dp_h[k]) - z_h);
}
/* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
y1 = y;
__LO(y1) = 0;
p_l = (y - y1) * t1 + y * t2;
p_h = y1 * t1;
z = p_l + p_h;
j = __HI(z);
i = __LO(z);
if (j >= 0x40900000) { /* z >= 1024 */
if (((j - 0x40900000) | i) != 0) { /* if z > 1024 */
return s * huge * huge; /* overflow */
} else {
if (p_l + ovt > z - p_h) return s * huge * huge; /* overflow */
}
} else if ((j & 0x7fffffff) >= 0x4090cc00) { /* z <= -1075 */
if (((j - 0xc090cc00) | i) != 0) { /* z < -1075 */
return s * tiny * tiny; /* underflow */
} else {
if (p_l <= z - p_h) return s * tiny * tiny; /* underflow */
}
}
/*
* compute 2**(p_h+p_l)
*/
i = j & 0x7fffffff;
k = (i >> 20) - 0x3ff;
n = 0;
if (i > 0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */
n = j + (0x00100000 >> (k + 1));
k = ((n & 0x7fffffff) >> 20) - 0x3ff; /* new k for n */
t = zero;
__HI(t) = (n & ~(0x000fffff >> k));
n = ((n & 0x000fffff) | 0x00100000) >> (20 - k);
if (j < 0) n = -n;
p_h -= t;
}
t = p_l + p_h;
__LO(t) = 0;
u = t * lg2_h;
v = (p_l - (t - p_h)) * lg2 + t * lg2_l;
z = u + v;
w = v - (z - u);
t = z * z;
t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5))));
r = (z * t1) / (t1 - two) - (w + z * w);
z = one - (r - z);
j = __HI(z);
j += (n << 20);
if ((j >> 20) <= 0)
z = scalbn(z, n); /* subnormal output */
else
__HI(z) += (n << 20);
return s * z;
}
#undef __HI
#undef __LO
/*
* ES6 draft 09-27-13, section 20.2.2.30.
* Math.sinh
@ -3078,16 +2758,6 @@ double tanh(double x) {
return (jx >= 0) ? z : -z;
}
#undef EXTRACT_WORDS
#undef EXTRACT_WORD64
#undef GET_HIGH_WORD
#undef GET_LOW_WORD
#undef INSERT_WORDS
#undef INSERT_WORD64
#undef SET_HIGH_WORD
#undef SET_LOW_WORD
#undef STRICT_ASSIGN
} // namespace ieee754
} // namespace base
} // namespace v8

View File

@ -60,14 +60,6 @@ V8_BASE_EXPORT double cbrt(double x);
// Returns exp(x)-1, the exponential of |x| minus 1.
V8_BASE_EXPORT double expm1(double x);
// Returns |x| to the power of |y|.
// The result of base ** exponent when base is 1 or -1 and exponent is
// +Infinity or -Infinity differs from IEEE 754-2008. The first edition
// of ECMAScript specified a result of NaN for this operation, whereas
// later versions of IEEE 754-2008 specified 1. The historical ECMAScript
// behaviour is preserved for compatibility reasons.
V8_BASE_EXPORT double pow(double x, double y);
// Returns the sine of |x|, where |x| is given in radians.
V8_BASE_EXPORT double sin(double x);

View File

@ -2706,6 +2706,80 @@ void Builtins::Generate_DoubleToI(MacroAssembler* masm) {
__ Ret();
}
void Builtins::Generate_MathPowInternal(MacroAssembler* masm) {
const LowDwVfpRegister double_base = d0;
const LowDwVfpRegister double_exponent = d1;
const LowDwVfpRegister double_result = d2;
const LowDwVfpRegister double_scratch = d3;
const SwVfpRegister single_scratch = s6;
// Avoid using Registers r0-r3 as they may be needed when calling to C if the
// ABI is softfloat.
const Register integer_exponent = r4;
const Register scratch = r5;
Label done, int_exponent;
// Detect integer exponents stored as double.
__ TryDoubleToInt32Exact(integer_exponent, double_exponent, double_scratch);
__ b(eq, &int_exponent);
__ push(lr);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(0, 2);
__ MovToFloatParameters(double_base, double_exponent);
__ CallCFunction(ExternalReference::power_double_double_function(), 0, 2);
}
__ pop(lr);
__ MovFromFloatResult(double_result);
__ b(&done);
// Calculate power with integer exponent.
__ bind(&int_exponent);
__ vmov(double_scratch, double_base); // Back up base.
__ vmov(double_result, Double(1.0), scratch);
// Get absolute value of exponent.
__ cmp(integer_exponent, Operand::Zero());
__ mov(scratch, integer_exponent);
__ rsb(scratch, integer_exponent, Operand::Zero(), LeaveCC, mi);
Label while_true;
__ bind(&while_true);
__ mov(scratch, Operand(scratch, LSR, 1), SetCC);
__ vmul(double_result, double_result, double_scratch, cs);
__ vmul(double_scratch, double_scratch, double_scratch, ne);
__ b(ne, &while_true);
__ cmp(integer_exponent, Operand::Zero());
__ b(ge, &done);
__ vmov(double_scratch, Double(1.0), scratch);
__ vdiv(double_result, double_scratch, double_result);
// Test whether result is zero. Bail out to check for subnormal result.
// Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
__ VFPCompareAndSetFlags(double_result, 0.0);
__ b(ne, &done);
// double_exponent may not containe the exponent value if the input was a
// smi. We set it with exponent value before bailing out.
__ vmov(single_scratch, integer_exponent);
__ vcvt_f64_s32(double_exponent, single_scratch);
// Returning or bailing out.
__ push(lr);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(0, 2);
__ MovToFloatParameters(double_base, double_exponent);
__ CallCFunction(ExternalReference::power_double_double_function(), 0, 2);
}
__ pop(lr);
__ MovFromFloatResult(double_result);
__ bind(&done);
__ Ret();
}
void Builtins::Generate_InternalArrayConstructorImpl(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- r0 : argc

View File

@ -3231,6 +3231,98 @@ void Builtins::Generate_DoubleToI(MacroAssembler* masm) {
__ Ret();
}
void Builtins::Generate_MathPowInternal(MacroAssembler* masm) {
Register exponent_integer = x12;
Register saved_lr = x19;
VRegister result_double = d0;
VRegister base_double = d0;
VRegister exponent_double = d1;
VRegister base_double_copy = d2;
VRegister scratch1_double = d6;
VRegister scratch0_double = d7;
// A fast-path for integer exponents.
Label exponent_is_integer;
// Allocate a heap number for the result, and return it.
Label done;
// Unpack the inputs.
// Handle double (heap number) exponents.
// Detect integer exponents stored as doubles and handle those in the
// integer fast-path.
__ TryRepresentDoubleAsInt64(exponent_integer, exponent_double,
scratch0_double, &exponent_is_integer);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ Mov(saved_lr, lr);
__ CallCFunction(ExternalReference::power_double_double_function(), 0, 2);
__ Mov(lr, saved_lr);
__ B(&done);
}
__ Bind(&exponent_is_integer);
// Find abs(exponent). For negative exponents, we can find the inverse later.
Register exponent_abs = x13;
__ Cmp(exponent_integer, 0);
__ Cneg(exponent_abs, exponent_integer, mi);
// Repeatedly multiply to calculate the power.
// result = 1.0;
// For each bit n (exponent_integer{n}) {
// if (exponent_integer{n}) {
// result *= base;
// }
// base *= base;
// if (remaining bits in exponent_integer are all zero) {
// break;
// }
// }
Label power_loop, power_loop_entry, power_loop_exit;
__ Fmov(scratch1_double, base_double);
__ Fmov(base_double_copy, base_double);
__ Fmov(result_double, 1.0);
__ B(&power_loop_entry);
__ Bind(&power_loop);
__ Fmul(scratch1_double, scratch1_double, scratch1_double);
__ Lsr(exponent_abs, exponent_abs, 1);
__ Cbz(exponent_abs, &power_loop_exit);
__ Bind(&power_loop_entry);
__ Tbz(exponent_abs, 0, &power_loop);
__ Fmul(result_double, result_double, scratch1_double);
__ B(&power_loop);
__ Bind(&power_loop_exit);
// If the exponent was positive, result_double holds the result.
__ Tbz(exponent_integer, kXSignBit, &done);
// The exponent was negative, so find the inverse.
__ Fmov(scratch0_double, 1.0);
__ Fdiv(result_double, scratch0_double, result_double);
// ECMA-262 only requires Math.pow to return an 'implementation-dependent
// approximation' of base^exponent. However, mjsunit/math-pow uses Math.pow
// to calculate the subnormal value 2^-1074. This method of calculating
// negative powers doesn't work because 2^1074 overflows to infinity. To
// catch this corner-case, we bail out if the result was 0. (This can only
// occur if the divisor is infinity or the base is zero.)
__ Fcmp(result_double, 0.0);
__ B(&done, ne);
AllowExternalCallThatCantCauseGC scope(masm);
__ Mov(saved_lr, lr);
__ Fmov(base_double, base_double_copy);
__ Scvtf(exponent_double, exponent_integer);
__ CallCFunction(ExternalReference::power_double_double_function(), 0, 2);
__ Mov(lr, saved_lr);
__ Bind(&done);
__ Ret();
}
void Builtins::Generate_InternalArrayConstructorImpl(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- x0 : argc

View File

@ -1337,6 +1337,7 @@ namespace internal {
TFC(GetProperty, GetProperty, 1) \
TFS(SetProperty, kReceiver, kKey, kValue) \
TFS(SetPropertyInLiteral, kReceiver, kKey, kValue) \
ASM(MathPowInternal, Dummy) \
ASM(MemCopyUint8Uint8, CCall) \
ASM(MemCopyUint16Uint8, CCall) \
ASM(MemMove, CCall) \

View File

@ -2885,6 +2885,137 @@ void Builtins::Generate_DoubleToI(MacroAssembler* masm) {
__ ret(0);
}
void Builtins::Generate_MathPowInternal(MacroAssembler* masm) {
const Register exponent = eax;
const Register scratch = ecx;
const XMMRegister double_result = xmm3;
const XMMRegister double_base = xmm2;
const XMMRegister double_exponent = xmm1;
const XMMRegister double_scratch = xmm4;
Label call_runtime, done, int_exponent;
// Save 1 in double_result - we need this several times later on.
__ mov(scratch, Immediate(1));
__ Cvtsi2sd(double_result, scratch);
Label fast_power, try_arithmetic_simplification;
__ DoubleToI(exponent, double_exponent, double_scratch,
&try_arithmetic_simplification, &try_arithmetic_simplification);
__ jmp(&int_exponent);
__ bind(&try_arithmetic_simplification);
// Skip to runtime if possibly NaN (indicated by the indefinite integer).
__ cvttsd2si(exponent, Operand(double_exponent));
__ cmp(exponent, Immediate(0x1));
__ j(overflow, &call_runtime);
// Using FPU instructions to calculate power.
Label fast_power_failed;
__ bind(&fast_power);
__ fnclex(); // Clear flags to catch exceptions later.
// Transfer (B)ase and (E)xponent onto the FPU register stack.
__ sub(esp, Immediate(kDoubleSize));
__ movsd(Operand(esp, 0), double_exponent);
__ fld_d(Operand(esp, 0)); // E
__ movsd(Operand(esp, 0), double_base);
__ fld_d(Operand(esp, 0)); // B, E
// Exponent is in st(1) and base is in st(0)
// B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B)
// FYL2X calculates st(1) * log2(st(0))
__ fyl2x(); // X
__ fld(0); // X, X
__ frndint(); // rnd(X), X
__ fsub(1); // rnd(X), X-rnd(X)
__ fxch(1); // X - rnd(X), rnd(X)
// F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1
__ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X)
__ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X)
__ faddp(1); // 2^(X-rnd(X)), rnd(X)
// FSCALE calculates st(0) * 2^st(1)
__ fscale(); // 2^X, rnd(X)
__ fstp(1); // 2^X
// Bail out to runtime in case of exceptions in the status word.
__ fnstsw_ax();
__ test_b(eax, Immediate(0x5F)); // We check for all but precision exception.
__ j(not_zero, &fast_power_failed, Label::kNear);
__ fstp_d(Operand(esp, 0));
__ movsd(double_result, Operand(esp, 0));
__ add(esp, Immediate(kDoubleSize));
__ jmp(&done);
__ bind(&fast_power_failed);
__ fninit();
__ add(esp, Immediate(kDoubleSize));
__ jmp(&call_runtime);
// Calculate power with integer exponent.
__ bind(&int_exponent);
const XMMRegister double_scratch2 = double_exponent;
__ mov(scratch, exponent); // Back up exponent.
__ movsd(double_scratch, double_base); // Back up base.
__ movsd(double_scratch2, double_result); // Load double_exponent with 1.
// Get absolute value of exponent.
Label no_neg, while_true, while_false;
__ test(scratch, scratch);
__ j(positive, &no_neg, Label::kNear);
__ neg(scratch);
__ bind(&no_neg);
__ j(zero, &while_false, Label::kNear);
__ shr(scratch, 1);
// Above condition means CF==0 && ZF==0. This means that the
// bit that has been shifted out is 0 and the result is not 0.
__ j(above, &while_true, Label::kNear);
__ movsd(double_result, double_scratch);
__ j(zero, &while_false, Label::kNear);
__ bind(&while_true);
__ shr(scratch, 1);
__ mulsd(double_scratch, double_scratch);
__ j(above, &while_true, Label::kNear);
__ mulsd(double_result, double_scratch);
__ j(not_zero, &while_true);
__ bind(&while_false);
// scratch has the original value of the exponent - if the exponent is
// negative, return 1/result.
__ test(exponent, exponent);
__ j(positive, &done);
__ divsd(double_scratch2, double_result);
__ movsd(double_result, double_scratch2);
// Test whether result is zero. Bail out to check for subnormal result.
// Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
__ xorps(double_scratch2, double_scratch2);
__ ucomisd(double_scratch2, double_result); // Result cannot be NaN.
// double_exponent aliased as double_scratch2 has already been overwritten
// and may not have contained the exponent value in the first place when the
// exponent is a smi. We reset it with exponent value before bailing out.
__ j(not_equal, &done);
__ Cvtsi2sd(double_exponent, exponent);
// Returning or bailing out.
__ bind(&call_runtime);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(4, scratch);
__ movsd(Operand(esp, 0 * kDoubleSize), double_base);
__ movsd(Operand(esp, 1 * kDoubleSize), double_exponent);
__ CallCFunction(ExternalReference::power_double_double_function(), 4);
}
// Return value is in st(0) on ia32.
// Store it into the (fixed) result register.
__ sub(esp, Immediate(kDoubleSize));
__ fstp_d(Operand(esp, 0));
__ movsd(double_result, Operand(esp, 0));
__ add(esp, Immediate(kDoubleSize));
__ bind(&done);
__ ret(0);
}
void Builtins::Generate_InternalArrayConstructorImpl(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- eax : argc

View File

@ -2760,6 +2760,106 @@ void Builtins::Generate_DoubleToI(MacroAssembler* masm) {
__ Ret();
}
void Builtins::Generate_MathPowInternal(MacroAssembler* masm) {
const Register exponent = a2;
const DoubleRegister double_base = f2;
const DoubleRegister double_exponent = f4;
const DoubleRegister double_result = f0;
const DoubleRegister double_scratch = f6;
const FPURegister single_scratch = f8;
const Register scratch = t5;
const Register scratch2 = t3;
Label call_runtime, done, int_exponent;
Label int_exponent_convert;
// Detect integer exponents stored as double.
__ EmitFPUTruncate(kRoundToMinusInf, scratch, double_exponent, kScratchReg,
double_scratch, scratch2, kCheckForInexactConversion);
// scratch2 == 0 means there was no conversion error.
__ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg));
__ push(ra);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(0, 2, scratch2);
__ MovToFloatParameters(double_base, double_exponent);
__ CallCFunction(ExternalReference::power_double_double_function(), 0, 2);
}
__ pop(ra);
__ MovFromFloatResult(double_result);
__ jmp(&done);
__ bind(&int_exponent_convert);
// Calculate power with integer exponent.
__ bind(&int_exponent);
// Get two copies of exponent in the registers scratch and exponent.
// Exponent has previously been stored into scratch as untagged integer.
__ mov(exponent, scratch);
__ mov_d(double_scratch, double_base); // Back up base.
__ Move(double_result, 1.0);
// Get absolute value of exponent.
Label positive_exponent, bail_out;
__ Branch(&positive_exponent, ge, scratch, Operand(zero_reg));
__ Subu(scratch, zero_reg, scratch);
// Check when Subu overflows and we get negative result
// (happens only when input is MIN_INT).
__ Branch(&bail_out, gt, zero_reg, Operand(scratch));
__ bind(&positive_exponent);
__ Assert(ge, AbortReason::kUnexpectedNegativeValue, scratch,
Operand(zero_reg));
Label while_true, no_carry, loop_end;
__ bind(&while_true);
__ And(scratch2, scratch, 1);
__ Branch(&no_carry, eq, scratch2, Operand(zero_reg));
__ mul_d(double_result, double_result, double_scratch);
__ bind(&no_carry);
__ sra(scratch, scratch, 1);
__ Branch(&loop_end, eq, scratch, Operand(zero_reg));
__ mul_d(double_scratch, double_scratch, double_scratch);
__ Branch(&while_true);
__ bind(&loop_end);
__ Branch(&done, ge, exponent, Operand(zero_reg));
__ Move(double_scratch, 1.0);
__ div_d(double_result, double_scratch, double_result);
// Test whether result is zero. Bail out to check for subnormal result.
// Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
__ CompareF64(EQ, double_result, kDoubleRegZero);
__ BranchFalseShortF(&done);
// double_exponent may not contain the exponent value if the input was a
// smi. We set it with exponent value before bailing out.
__ bind(&bail_out);
__ mtc1(exponent, single_scratch);
__ cvt_d_w(double_exponent, single_scratch);
// Returning or bailing out.
__ push(ra);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(0, 2, scratch);
__ MovToFloatParameters(double_base, double_exponent);
__ CallCFunction(ExternalReference::power_double_double_function(), 0, 2);
}
__ pop(ra);
__ MovFromFloatResult(double_result);
__ bind(&done);
__ Ret();
}
void Builtins::Generate_InternalArrayConstructorImpl(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- a0 : argc

View File

@ -2797,6 +2797,106 @@ void Builtins::Generate_DoubleToI(MacroAssembler* masm) {
__ Ret();
}
void Builtins::Generate_MathPowInternal(MacroAssembler* masm) {
const Register exponent = a2;
const DoubleRegister double_base = f2;
const DoubleRegister double_exponent = f4;
const DoubleRegister double_result = f0;
const DoubleRegister double_scratch = f6;
const FPURegister single_scratch = f8;
const Register scratch = t1;
const Register scratch2 = a7;
Label call_runtime, done, int_exponent;
Label int_exponent_convert;
// Detect integer exponents stored as double.
__ EmitFPUTruncate(kRoundToMinusInf, scratch, double_exponent, kScratchReg,
double_scratch, scratch2, kCheckForInexactConversion);
// scratch2 == 0 means there was no conversion error.
__ Branch(&int_exponent_convert, eq, scratch2, Operand(zero_reg));
__ push(ra);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(0, 2, scratch2);
__ MovToFloatParameters(double_base, double_exponent);
__ CallCFunction(ExternalReference::power_double_double_function(), 0, 2);
}
__ pop(ra);
__ MovFromFloatResult(double_result);
__ jmp(&done);
__ bind(&int_exponent_convert);
// Calculate power with integer exponent.
__ bind(&int_exponent);
// Get two copies of exponent in the registers scratch and exponent.
// Exponent has previously been stored into scratch as untagged integer.
__ mov(exponent, scratch);
__ mov_d(double_scratch, double_base); // Back up base.
__ Move(double_result, 1.0);
// Get absolute value of exponent.
Label positive_exponent, bail_out;
__ Branch(&positive_exponent, ge, scratch, Operand(zero_reg));
__ Dsubu(scratch, zero_reg, scratch);
// Check when Dsubu overflows and we get negative result
// (happens only when input is MIN_INT).
__ Branch(&bail_out, gt, zero_reg, Operand(scratch));
__ bind(&positive_exponent);
__ Assert(ge, AbortReason::kUnexpectedNegativeValue, scratch,
Operand(zero_reg));
Label while_true, no_carry, loop_end;
__ bind(&while_true);
__ And(scratch2, scratch, 1);
__ Branch(&no_carry, eq, scratch2, Operand(zero_reg));
__ mul_d(double_result, double_result, double_scratch);
__ bind(&no_carry);
__ dsra(scratch, scratch, 1);
__ Branch(&loop_end, eq, scratch, Operand(zero_reg));
__ mul_d(double_scratch, double_scratch, double_scratch);
__ Branch(&while_true);
__ bind(&loop_end);
__ Branch(&done, ge, exponent, Operand(zero_reg));
__ Move(double_scratch, 1.0);
__ div_d(double_result, double_scratch, double_result);
// Test whether result is zero. Bail out to check for subnormal result.
// Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
__ CompareF64(EQ, double_result, kDoubleRegZero);
__ BranchFalseShortF(&done);
// double_exponent may not contain the exponent value if the input was a
// smi. We set it with exponent value before bailing out.
__ bind(&bail_out);
__ mtc1(exponent, single_scratch);
__ cvt_d_w(double_exponent, single_scratch);
// Returning or bailing out.
__ push(ra);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(0, 2, scratch);
__ MovToFloatParameters(double_base, double_exponent);
__ CallCFunction(ExternalReference::power_double_double_function(), 0, 2);
}
__ pop(ra);
__ MovFromFloatResult(double_result);
__ bind(&done);
__ Ret();
}
void Builtins::Generate_InternalArrayConstructorImpl(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- a0 : argc

View File

@ -2834,6 +2834,100 @@ void Builtins::Generate_DoubleToI(MacroAssembler* masm) {
__ Ret();
}
void Builtins::Generate_MathPowInternal(MacroAssembler* masm) {
const Register exponent = r5;
const DoubleRegister double_base = d1;
const DoubleRegister double_exponent = d2;
const DoubleRegister double_result = d3;
const DoubleRegister double_scratch = d0;
const Register scratch = r11;
const Register scratch2 = r10;
Label done, int_exponent;
// Detect integer exponents stored as double.
__ TryDoubleToInt32Exact(scratch, double_exponent, scratch2, double_scratch);
__ beq(&int_exponent);
__ mflr(r0);
__ push(r0);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(0, 2, scratch);
__ MovToFloatParameters(double_base, double_exponent);
__ CallCFunction(ExternalReference::power_double_double_function(), 0, 2);
}
__ pop(r0);
__ mtlr(r0);
__ MovFromFloatResult(double_result);
__ b(&done);
// Calculate power with integer exponent.
__ bind(&int_exponent);
// Get two copies of exponent in the registers scratch and exponent.
// Exponent has previously been stored into scratch as untagged integer.
__ mr(exponent, scratch);
__ fmr(double_scratch, double_base); // Back up base.
__ li(scratch2, Operand(1));
__ ConvertIntToDouble(scratch2, double_result);
// Get absolute value of exponent.
__ cmpi(scratch, Operand::Zero());
if (CpuFeatures::IsSupported(ISELECT)) {
__ neg(scratch2, scratch);
__ isel(lt, scratch, scratch2, scratch);
} else {
Label positive_exponent;
__ bge(&positive_exponent);
__ neg(scratch, scratch);
__ bind(&positive_exponent);
}
Label while_true, no_carry, loop_end;
__ bind(&while_true);
__ andi(scratch2, scratch, Operand(1));
__ beq(&no_carry, cr0);
__ fmul(double_result, double_result, double_scratch);
__ bind(&no_carry);
__ ShiftRightImm(scratch, scratch, Operand(1), SetRC);
__ beq(&loop_end, cr0);
__ fmul(double_scratch, double_scratch, double_scratch);
__ b(&while_true);
__ bind(&loop_end);
__ cmpi(exponent, Operand::Zero());
__ bge(&done);
__ li(scratch2, Operand(1));
__ ConvertIntToDouble(scratch2, double_scratch);
__ fdiv(double_result, double_scratch, double_result);
// Test whether result is zero. Bail out to check for subnormal result.
// Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
__ fcmpu(double_result, kDoubleRegZero);
__ bne(&done);
// double_exponent may not containe the exponent value if the input was a
// smi. We set it with exponent value before bailing out.
__ ConvertIntToDouble(exponent, double_exponent);
// Returning or bailing out.
__ mflr(r0);
__ push(r0);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(0, 2, scratch);
__ MovToFloatParameters(double_base, double_exponent);
__ CallCFunction(ExternalReference::power_double_double_function(), 0, 2);
}
__ pop(r0);
__ mtlr(r0);
__ MovFromFloatResult(double_result);
__ bind(&done);
__ Ret();
}
void Builtins::Generate_InternalArrayConstructorImpl(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- r3 : argc

View File

@ -2868,6 +2868,97 @@ void Builtins::Generate_DoubleToI(MacroAssembler* masm) {
__ Ret();
}
void Builtins::Generate_MathPowInternal(MacroAssembler* masm) {
const Register exponent = r4;
const DoubleRegister double_base = d1;
const DoubleRegister double_exponent = d2;
const DoubleRegister double_result = d3;
const DoubleRegister double_scratch = d0;
const Register scratch = r1;
const Register scratch2 = r9;
Label done, int_exponent;
// Detect integer exponents stored as double.
__ TryDoubleToInt32Exact(scratch, double_exponent, scratch2, double_scratch);
__ beq(&int_exponent, Label::kNear);
__ push(r14);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(0, 2, scratch);
__ MovToFloatParameters(double_base, double_exponent);
__ CallCFunction(ExternalReference::power_double_double_function(), 0, 2);
}
__ pop(r14);
__ MovFromFloatResult(double_result);
__ b(&done);
// Calculate power with integer exponent.
__ bind(&int_exponent);
// Get two copies of exponent in the registers scratch and exponent.
// Exponent has previously been stored into scratch as untagged integer.
__ LoadRR(exponent, scratch);
__ ldr(double_scratch, double_base); // Back up base.
__ LoadImmP(scratch2, Operand(1));
__ ConvertIntToDouble(double_result, scratch2);
// Get absolute value of exponent.
Label positive_exponent;
__ CmpP(scratch, Operand::Zero());
__ bge(&positive_exponent, Label::kNear);
__ LoadComplementRR(scratch, scratch);
__ bind(&positive_exponent);
Label while_true, no_carry, loop_end;
__ bind(&while_true);
__ mov(scratch2, Operand(1));
__ AndP(scratch2, scratch);
__ beq(&no_carry, Label::kNear);
__ mdbr(double_result, double_scratch);
__ bind(&no_carry);
__ ShiftRightP(scratch, scratch, Operand(1));
__ LoadAndTestP(scratch, scratch);
__ beq(&loop_end, Label::kNear);
__ mdbr(double_scratch, double_scratch);
__ b(&while_true);
__ bind(&loop_end);
__ CmpP(exponent, Operand::Zero());
__ bge(&done);
// get 1/double_result:
__ ldr(double_scratch, double_result);
__ LoadImmP(scratch2, Operand(1));
__ ConvertIntToDouble(double_result, scratch2);
__ ddbr(double_result, double_scratch);
// Test whether result is zero. Bail out to check for subnormal result.
// Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
__ lzdr(kDoubleRegZero);
__ cdbr(double_result, kDoubleRegZero);
__ bne(&done, Label::kNear);
// double_exponent may not containe the exponent value if the input was a
// smi. We set it with exponent value before bailing out.
__ ConvertIntToDouble(double_exponent, exponent);
// Returning or bailing out.
__ push(r14);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(0, 2, scratch);
__ MovToFloatParameters(double_base, double_exponent);
__ CallCFunction(ExternalReference::power_double_double_function(), 0, 2);
}
__ pop(r14);
__ MovFromFloatResult(double_result);
__ bind(&done);
__ Ret();
}
void Builtins::Generate_InternalArrayConstructorImpl(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- r2 : argc

View File

@ -2934,6 +2934,135 @@ void Builtins::Generate_DoubleToI(MacroAssembler* masm) {
__ ret(0);
}
void Builtins::Generate_MathPowInternal(MacroAssembler* masm) {
const Register exponent = rdx;
const Register scratch = rcx;
const XMMRegister double_result = xmm3;
const XMMRegister double_base = xmm2;
const XMMRegister double_exponent = xmm1;
const XMMRegister double_scratch = xmm4;
Label call_runtime, done, int_exponent;
// Save 1 in double_result - we need this several times later on.
__ movq(scratch, Immediate(1));
__ Cvtlsi2sd(double_result, scratch);
Label fast_power, try_arithmetic_simplification;
// Detect integer exponents stored as double.
__ DoubleToI(exponent, double_exponent, double_scratch,
&try_arithmetic_simplification, &try_arithmetic_simplification);
__ jmp(&int_exponent);
__ bind(&try_arithmetic_simplification);
__ Cvttsd2si(exponent, double_exponent);
// Skip to runtime if possibly NaN (indicated by the indefinite integer).
__ cmpl(exponent, Immediate(0x1));
__ j(overflow, &call_runtime);
// Using FPU instructions to calculate power.
Label fast_power_failed;
__ bind(&fast_power);
__ fnclex(); // Clear flags to catch exceptions later.
// Transfer (B)ase and (E)xponent onto the FPU register stack.
__ subq(rsp, Immediate(kDoubleSize));
__ Movsd(Operand(rsp, 0), double_exponent);
__ fld_d(Operand(rsp, 0)); // E
__ Movsd(Operand(rsp, 0), double_base);
__ fld_d(Operand(rsp, 0)); // B, E
// Exponent is in st(1) and base is in st(0)
// B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B)
// FYL2X calculates st(1) * log2(st(0))
__ fyl2x(); // X
__ fld(0); // X, X
__ frndint(); // rnd(X), X
__ fsub(1); // rnd(X), X-rnd(X)
__ fxch(1); // X - rnd(X), rnd(X)
// F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1
__ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X)
__ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X)
__ faddp(1); // 2^(X-rnd(X)), rnd(X)
// FSCALE calculates st(0) * 2^st(1)
__ fscale(); // 2^X, rnd(X)
__ fstp(1);
// Bail out to runtime in case of exceptions in the status word.
__ fnstsw_ax();
__ testb(rax, Immediate(0x5F)); // Check for all but precision exception.
__ j(not_zero, &fast_power_failed, Label::kNear);
__ fstp_d(Operand(rsp, 0));
__ Movsd(double_result, Operand(rsp, 0));
__ addq(rsp, Immediate(kDoubleSize));
__ jmp(&done);
__ bind(&fast_power_failed);
__ fninit();
__ addq(rsp, Immediate(kDoubleSize));
__ jmp(&call_runtime);
// Calculate power with integer exponent.
__ bind(&int_exponent);
const XMMRegister double_scratch2 = double_exponent;
// Back up exponent as we need to check if exponent is negative later.
__ movq(scratch, exponent); // Back up exponent.
__ Movsd(double_scratch, double_base); // Back up base.
__ Movsd(double_scratch2, double_result); // Load double_exponent with 1.
// Get absolute value of exponent.
Label no_neg, while_true, while_false;
__ testl(scratch, scratch);
__ j(positive, &no_neg, Label::kNear);
__ negl(scratch);
__ bind(&no_neg);
__ j(zero, &while_false, Label::kNear);
__ shrl(scratch, Immediate(1));
// Above condition means CF==0 && ZF==0. This means that the
// bit that has been shifted out is 0 and the result is not 0.
__ j(above, &while_true, Label::kNear);
__ Movsd(double_result, double_scratch);
__ j(zero, &while_false, Label::kNear);
__ bind(&while_true);
__ shrl(scratch, Immediate(1));
__ Mulsd(double_scratch, double_scratch);
__ j(above, &while_true, Label::kNear);
__ Mulsd(double_result, double_scratch);
__ j(not_zero, &while_true);
__ bind(&while_false);
// If the exponent is negative, return 1/result.
__ testl(exponent, exponent);
__ j(greater, &done);
__ Divsd(double_scratch2, double_result);
__ Movsd(double_result, double_scratch2);
// Test whether result is zero. Bail out to check for subnormal result.
// Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
__ Xorpd(double_scratch2, double_scratch2);
__ Ucomisd(double_scratch2, double_result);
// double_exponent aliased as double_scratch2 has already been overwritten
// and may not have contained the exponent value in the first place when the
// input was a smi. We reset it with exponent value before bailing out.
__ j(not_equal, &done);
__ Cvtlsi2sd(double_exponent, exponent);
// Returning or bailing out.
__ bind(&call_runtime);
// Move base to the correct argument register. Exponent is already in xmm1.
__ Movsd(xmm0, double_base);
DCHECK(double_exponent == xmm1);
{
AllowExternalCallThatCantCauseGC scope(masm);
__ PrepareCallCFunction(2);
__ CallCFunction(ExternalReference::power_double_double_function(), 2);
}
// Return value is in xmm0.
__ Movsd(double_result, xmm0);
__ bind(&done);
__ ret(0);
}
void Builtins::Generate_InternalArrayConstructorImpl(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- rax : argc

View File

@ -1051,9 +1051,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Log10:
ASSEMBLE_IEEE754_UNOP(log10);
break;
case kIeee754Float64Pow:
ASSEMBLE_IEEE754_BINOP(pow);
case kIeee754Float64Pow: {
__ Call(BUILTIN_CODE(isolate(), MathPowInternal), RelocInfo::CODE_TARGET);
__ vmov(d0, d2);
break;
}
case kIeee754Float64Sin:
ASSEMBLE_IEEE754_UNOP(sin);
break;

View File

@ -918,9 +918,10 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Log10:
ASSEMBLE_IEEE754_UNOP(log10);
break;
case kIeee754Float64Pow:
ASSEMBLE_IEEE754_BINOP(pow);
case kIeee754Float64Pow: {
__ Call(BUILTIN_CODE(isolate(), MathPowInternal), RelocInfo::CODE_TARGET);
break;
}
case kIeee754Float64Sin:
ASSEMBLE_IEEE754_UNOP(sin);
break;

View File

@ -982,9 +982,20 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Log10:
ASSEMBLE_IEEE754_UNOP(log10);
break;
case kIeee754Float64Pow:
ASSEMBLE_IEEE754_BINOP(pow);
case kIeee754Float64Pow: {
// TODO(bmeurer): Improve integration of the stub.
if (i.InputDoubleRegister(1) != xmm2) {
__ movaps(xmm2, i.InputDoubleRegister(0));
__ movaps(xmm1, i.InputDoubleRegister(1));
} else {
__ movaps(xmm0, i.InputDoubleRegister(0));
__ movaps(xmm1, xmm2);
__ movaps(xmm2, xmm0);
}
__ Call(BUILTIN_CODE(isolate(), MathPowInternal), RelocInfo::CODE_TARGET);
__ movaps(i.OutputDoubleRegister(), xmm3);
break;
}
case kIeee754Float64Sin:
ASSEMBLE_IEEE754_UNOP(sin);
break;

View File

@ -970,9 +970,10 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Log2:
ASSEMBLE_IEEE754_UNOP(log2);
break;
case kIeee754Float64Pow:
ASSEMBLE_IEEE754_BINOP(pow);
case kIeee754Float64Pow: {
__ Call(BUILTIN_CODE(isolate(), MathPowInternal), RelocInfo::CODE_TARGET);
break;
}
case kIeee754Float64Sin:
ASSEMBLE_IEEE754_UNOP(sin);
break;

View File

@ -948,9 +948,10 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Log10:
ASSEMBLE_IEEE754_UNOP(log10);
break;
case kIeee754Float64Pow:
ASSEMBLE_IEEE754_BINOP(pow);
case kIeee754Float64Pow: {
__ Call(BUILTIN_CODE(isolate(), MathPowInternal), RelocInfo::CODE_TARGET);
break;
}
case kIeee754Float64Sin:
ASSEMBLE_IEEE754_UNOP(sin);
break;

View File

@ -1554,9 +1554,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Log10:
ASSEMBLE_IEEE754_UNOP(log10);
break;
case kIeee754Float64Pow:
ASSEMBLE_IEEE754_BINOP(pow);
case kIeee754Float64Pow: {
__ Call(BUILTIN_CODE(isolate(), MathPowInternal), RelocInfo::CODE_TARGET);
__ Move(d1, d3);
break;
}
case kPPC_Neg:
__ neg(i.OutputRegister(), i.InputRegister(0), LeaveOE, i.OutputRCBit());
break;

View File

@ -2066,9 +2066,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Log10:
ASSEMBLE_IEEE754_UNOP(log10);
break;
case kIeee754Float64Pow:
ASSEMBLE_IEEE754_BINOP(pow);
case kIeee754Float64Pow: {
__ Call(BUILTIN_CODE(isolate(), MathPowInternal), RelocInfo::CODE_TARGET);
__ Move(d1, d3);
break;
}
case kS390_Neg32:
__ lcr(i.OutputRegister(), i.InputRegister(0));
CHECK_AND_ZERO_EXT_OUTPUT(1);

View File

@ -1084,9 +1084,13 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Log10:
ASSEMBLE_IEEE754_UNOP(log10);
break;
case kIeee754Float64Pow:
ASSEMBLE_IEEE754_BINOP(pow);
case kIeee754Float64Pow: {
// TODO(bmeurer): Improve integration of the stub.
__ Movsd(xmm2, xmm0);
__ Call(BUILTIN_CODE(isolate(), MathPowInternal), RelocInfo::CODE_TARGET);
__ Movsd(xmm0, xmm3);
break;
}
case kIeee754Float64Sin:
ASSEMBLE_IEEE754_UNOP(sin);
break;

View File

@ -563,8 +563,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
case IrOpcode::kFloat64Pow: {
Float64BinopMatcher m(node);
if (m.IsFoldable()) {
return ReplaceFloat64(
base::ieee754::pow(m.left().Value(), m.right().Value()));
return ReplaceFloat64(Pow(m.left().Value(), m.right().Value()));
} else if (m.right().Is(0.0)) { // x ** +-0.0 => 1.0
return ReplaceFloat64(1.0);
} else if (m.right().Is(-2.0)) { // x ** -2.0 => 1 / (x * x)

View File

@ -949,6 +949,7 @@ static bool TransitivelyCalledBuiltinHasNoSideEffect(Builtins::Name caller,
case Builtins::kFlattenIntoArray:
case Builtins::kGetProperty:
case Builtins::kHasProperty:
case Builtins::kMathPowInternal:
case Builtins::kNonNumberToNumber:
case Builtins::kNonPrimitiveToPrimitive_Number:
case Builtins::kNumberToString:

View File

@ -567,8 +567,6 @@ FUNCTION_REFERENCE_WITH_TYPE(ieee754_tan_function, base::ieee754::tan,
BUILTIN_FP_CALL)
FUNCTION_REFERENCE_WITH_TYPE(ieee754_tanh_function, base::ieee754::tanh,
BUILTIN_FP_CALL)
FUNCTION_REFERENCE_WITH_TYPE(ieee754_pow_function, base::ieee754::pow,
BUILTIN_FP_FP_CALL)
void* libc_memchr(void* string, int character, size_t search_length) {
return memchr(string, character, search_length);
@ -760,8 +758,19 @@ static Address InvalidatePrototypeChainsWrapper(Address raw_map) {
FUNCTION_REFERENCE(invalidate_prototype_chains_function,
InvalidatePrototypeChainsWrapper)
double power_double_double(double x, double y) {
// The checks for special cases can be dropped in ia32 because it has already
// been done in generated code before bailing out here.
if (std::isnan(y) || ((x == 1 || x == -1) && std::isinf(y))) {
return std::numeric_limits<double>::quiet_NaN();
}
return Pow(x, y);
}
double modulo_double_double(double x, double y) { return Modulo(x, y); }
FUNCTION_REFERENCE_WITH_TYPE(power_double_double_function, power_double_double,
BUILTIN_FP_FP_CALL)
FUNCTION_REFERENCE_WITH_TYPE(mod_two_doubles_operation, modulo_double_double,
BUILTIN_FP_FP_CALL)

View File

@ -129,7 +129,6 @@ class StatsCounter;
V(ieee754_log10_function, "base::ieee754::log10") \
V(ieee754_log1p_function, "base::ieee754::log1p") \
V(ieee754_log2_function, "base::ieee754::log2") \
V(ieee754_pow_function, "base::ieee754::pow") \
V(ieee754_sin_function, "base::ieee754::sin") \
V(ieee754_sinh_function, "base::ieee754::sinh") \
V(ieee754_tan_function, "base::ieee754::tan") \
@ -152,6 +151,7 @@ class StatsCounter;
V(mod_two_doubles_operation, "mod_two_doubles") \
V(new_deoptimizer_function, "Deoptimizer::New()") \
V(orderedhashmap_gethash_raw, "orderedhashmap_gethash_raw") \
V(power_double_double_function, "power_double_double_function") \
V(printf_function, "printf") \
V(refill_math_random, "MathRandom::RefillCache") \
V(search_string_raw_one_one, "search_string_raw_one_one") \
@ -325,6 +325,9 @@ V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, ExternalReference);
void abort_with_reason(int reason);
// Computes pow(x, y) with the special cases in the spec for Math.pow.
double power_double_double(double x, double y);
} // namespace internal
} // namespace v8

View File

@ -12,7 +12,6 @@
#include "src/ast/ast.h"
#include "src/ast/source-range-ast-visitor.h"
#include "src/bailout-reason.h"
#include "src/base/ieee754.h"
#include "src/base/overflowing-math.h"
#include "src/base/platform/platform.h"
#include "src/char-predicates-inl.h"
@ -197,9 +196,10 @@ bool Parser::ShortcutNumericLiteralBinaryExpression(Expression** x,
*x = factory()->NewNumberLiteral(value, pos);
return true;
}
case Token::EXP:
*x = factory()->NewNumberLiteral(base::ieee754::pow(x_val, y_val), pos);
case Token::EXP: {
*x = factory()->NewNumberLiteral(Pow(x_val, y_val), pos);
return true;
}
default:
break;
}

View File

@ -253,6 +253,35 @@ inline double Modulo(double x, double y) {
#endif
}
inline double Pow(double x, double y) {
if (y == 0.0) return 1.0;
if (std::isnan(y) || ((x == 1 || x == -1) && std::isinf(y))) {
return std::numeric_limits<double>::quiet_NaN();
}
#if (defined(__MINGW64_VERSION_MAJOR) && \
(!defined(__MINGW64_VERSION_RC) || __MINGW64_VERSION_RC < 1)) || \
defined(V8_OS_AIX)
// MinGW64 and AIX have a custom implementation for pow. This handles certain
// special cases that are different.
if ((x == 0.0 || std::isinf(x)) && y != 0.0 && std::isfinite(y)) {
double f;
double result = ((x == 0.0) ^ (y > 0)) ? V8_INFINITY : 0;
/* retain sign if odd integer exponent */
return ((std::modf(y, &f) == 0.0) && (static_cast<int64_t>(y) & 1))
? copysign(result, x)
: result;
}
if (x == 2.0) {
int y_int = static_cast<int>(y);
if (y == y_int) {
return std::ldexp(1.0, y_int);
}
}
#endif
return std::pow(x, y);
}
template <typename T>
T SaturateAdd(T a, T b) {
if (std::is_signed<T>::value) {

View File

@ -10,7 +10,6 @@
#include "include/v8config.h"
#include "src/base/bits.h"
#include "src/base/ieee754.h"
#include "src/memcopy.h"
#include "src/utils.h"
#include "src/v8memory.h"
@ -246,7 +245,7 @@ uint32_t word32_ror_wrapper(Address data) {
void float64_pow_wrapper(Address data) {
double x = ReadUnalignedValue<double>(data);
double y = ReadUnalignedValue<double>(data + sizeof(x));
WriteUnalignedValue<double>(data, base::ieee754::pow(x, y));
WriteUnalignedValue<double>(data, Pow(x, y));
}
void memory_copy_wrapper(Address dst, Address src, uint32_t size) {

View File

@ -1,17 +0,0 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const inlineFromParser = 50 ** 50;
const i = 50;
const fromRuntimePowOp = i ** i;
const fromRuntimeMath = Math.pow(i, i);
// inlineFromParser === fromRuntimeOp === fromRuntimeMath
assertEquals(inlineFromParser, fromRuntimePowOp);
assertEquals(inlineFromParser - fromRuntimePowOp, 0);
assertEquals(inlineFromParser, fromRuntimeMath);
assertEquals(inlineFromParser - fromRuntimeMath, 0);

View File

@ -1959,9 +1959,8 @@ TEST_F(MachineOperatorReducerTest, Float64PowWithConstant) {
Reduction const r = Reduce(graph()->NewNode(
machine()->Float64Pow(), Float64Constant(x), Float64Constant(y)));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(
r.replacement(),
IsFloat64Constant(NanSensitiveDoubleEq(base::ieee754::pow(x, y))));
EXPECT_THAT(r.replacement(),
IsFloat64Constant(NanSensitiveDoubleEq(Pow(x, y))));
}
}
}