Commit 97ecc503 authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

ARM: Correctness fix to Math.pow optimization

The change in r4990 contained a bug in Math.pow when then exponent was a large negative smi. In that case calculating 1/Math.pow(x,-y) did not provide the correct result as Math.pow(x,-y) would overflow ti infinity. This was caught by Sputnik test S8.5_A13_T1.
Review URL: http://codereview.chromium.org/2815039

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4994 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent bbb26484
......@@ -4346,10 +4346,20 @@ void CodeGenerator::GenerateMathPow(ZoneList<Expression*>* args) {
__ vmul(d1, d1, d1, ne); // Don't bother calculating next d1 if done.
__ b(ne, &more_bits);
// If exponent is negative result is 1/result (d2 already holds 1.0 in that
// case).
// If exponent is positive we are done.
__ cmp(exponent, Operand(0));
__ vdiv(d0, d2, d0, mi);
__ b(ge, &allocate_return);
// If exponent is negative result is 1/result (d2 already holds 1.0 in that
// case). However if d0 has reached infinity this will not provide the
// correct result, so call runtime if that is the case.
__ mov(scratch2, Operand(0x7FF00000));
__ mov(scratch1, Operand(0));
__ vmov(d1, scratch1, scratch2); // Load infinity into d1.
__ vcmp(d0, d1);
__ vmrs(pc);
runtime.Branch(eq); // d0 reached infinity.
__ vdiv(d0, d2, d0);
__ b(&allocate_return);
__ bind(&exponent_nonsmi);
......
......@@ -122,3 +122,8 @@ assertEquals(NaN, Math.pow(-2, 1.1));
assertEquals(NaN, Math.pow(-2, -1.1));
assertEquals(NaN, Math.pow(-1000, 1.1));
assertEquals(NaN, Math.pow(-1000, -1.1));
// Tests from Sputnik S8.5_A13_T1.
assertTrue((1*((Math.pow(2,53))-1)*(Math.pow(2,-1074))) === 4.4501477170144023e-308);
assertTrue((1*(Math.pow(2,52))*(Math.pow(2,-1074))) === 2.2250738585072014e-308);
assertTrue((-1*(Math.pow(2,52))*(Math.pow(2,-1074))) === -2.2250738585072014e-308);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment