Reviewers: ulan,
Message:
Comparing NaN and -Infinity sets the zero flag so it looks like they were
equal...
Please take a look.
Description:
Fixing mozilla test failures regarding Math.pow.
BUG=
TEST=
Please review this at http://codereview.chromium.org/8820011/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/ia32/code-stubs-ia32.cc
M src/ia32/lithium-codegen-ia32.cc
M src/x64/lithium-codegen-x64.cc
M test/mjsunit/math-pow.js
Index: src/ia32/code-stubs-ia32.cc
diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc
index
aa70c5ff6653338caf25d6f170eec7909694f342..334dd493498e90e4d09359ce3039e2797cfe9219
100644
--- a/src/ia32/code-stubs-ia32.cc
+++ b/src/ia32/code-stubs-ia32.cc
@@ -3022,7 +3022,10 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ movd(xmm4, ecx);
__ cvtss2sd(xmm4, xmm4);
__ ucomisd(xmm1, xmm4);
+ // Comparing -Infinity with NaN results in "unordered", which sets
the
+ // zero flag as if both were equal. However, it also sets the carry
flag.
__ j(not_equal, &continue_sqrt, Label::kNear);
+ __ j(carry, &continue_sqrt, Label::kNear);
// Set result to Infinity in the special case.
__ xorps(xmm3, xmm3);
@@ -3053,7 +3056,10 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ movd(xmm4, ecx);
__ cvtss2sd(xmm4, xmm4);
__ ucomisd(xmm1, xmm4);
+ // Comparing -Infinity with NaN results in "unordered", which sets
the
+ // zero flag as if both were equal. However, it also sets the carry
flag.
__ j(not_equal, &continue_rsqrt, Label::kNear);
+ __ j(carry, &continue_rsqrt, Label::kNear);
// Set result to 0 in the special case.
__ xorps(xmm3, xmm3);
Index: src/ia32/lithium-codegen-ia32.cc
diff --git a/src/ia32/lithium-codegen-ia32.cc
b/src/ia32/lithium-codegen-ia32.cc
index
2925dcde950175485607cf4e42f50c03366334fb..67feb333e083ae06c971078cbdb457e9e0ee78b5
100644
--- a/src/ia32/lithium-codegen-ia32.cc
+++ b/src/ia32/lithium-codegen-ia32.cc
@@ -2950,7 +2950,10 @@ void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) {
__ movd(xmm_scratch, scratch);
__ cvtss2sd(xmm_scratch, xmm_scratch);
__ ucomisd(input_reg, xmm_scratch);
+ // Comparing -Infinity with NaN results in "unordered", which sets the
+ // zero flag as if both were equal. However, it also sets the carry
flag.
__ j(not_equal, &sqrt, Label::kNear);
+ __ j(carry, &sqrt, Label::kNear);
// If input is -Infinity, return Infinity.
__ xorps(input_reg, input_reg);
__ subsd(input_reg, xmm_scratch);
Index: src/x64/lithium-codegen-x64.cc
diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc
index
160db3bd91959475457aae6c7d19245d191333b0..f2cf9cf762012c339b882813a5ac4ae4ea921dca
100644
--- a/src/x64/lithium-codegen-x64.cc
+++ b/src/x64/lithium-codegen-x64.cc
@@ -2862,7 +2862,10 @@ void LCodeGen::DoMathPowHalf(LUnaryMathOperation*
instr) {
__ movq(kScratchRegister, V8_INT64_C(0xFFF0000000000000),
RelocInfo::NONE);
__ movq(xmm_scratch, kScratchRegister);
__ ucomisd(xmm_scratch, input_reg);
+ // Comparing -Infinity with NaN results in "unordered", which sets the
+ // zero flag as if both were equal. However, it also sets the carry
flag.
__ j(not_equal, &sqrt, Label::kNear);
+ __ j(carry, &sqrt, Label::kNear);
// If input is -Infinity, return Infinity.
__ xorps(input_reg, input_reg);
__ subsd(input_reg, xmm_scratch);
Index: test/mjsunit/math-pow.js
diff --git a/test/mjsunit/math-pow.js b/test/mjsunit/math-pow.js
index
96d4eb4fdd0aff7c043da5b66d9d94d48dc8c965..bcf62702fe33ee1d843e899d648126f61ceb9f7e
100644
--- a/test/mjsunit/math-pow.js
+++ b/test/mjsunit/math-pow.js
@@ -140,6 +140,9 @@ function test() {
assertEquals(NaN, Math.pow(-16, 0.5));
assertEquals(0.25, Math.pow(16, -0.5));
assertEquals(NaN, Math.pow(-16, -0.5));
+
+ assertEquals(NaN, Math.pow(NaN, 0.5));
+ assertEquals(NaN, Math.pow(NaN, -0.5));
// Tests from Sputnik S8.5_A13_T1.
assertTrue(
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev