Revision: 4235
Author: whe...@chromium.org
Date: Tue Mar 23 08:18:00 2010
Log: Fix an error in optimized modulus operator, add unit test.
Review URL: http://codereview.chromium.org/1118008
http://code.google.com/p/v8/source/detail?r=4235

Modified:
 /branches/bleeding_edge/src/ia32/codegen-ia32.cc
 /branches/bleeding_edge/test/mjsunit/div-mod.js

=======================================
--- /branches/bleeding_edge/src/ia32/codegen-ia32.cc Tue Mar 23 07:59:36 2010 +++ /branches/bleeding_edge/src/ia32/codegen-ia32.cc Tue Mar 23 08:18:00 2010
@@ -7380,6 +7380,15 @@
       __ cdq();  // Sign-extend eax into edx:eax
       __ idiv(right_reg);
       if (op == Token::MOD) {
+ // Negative zero can arise as a negative divident with a zero result.
+        if (!node->no_negative_zero()) {
+          Label not_negative_zero;
+          __ test(edx, Operand(edx));
+          __ j(not_zero, &not_negative_zero);
+          __ test(eax, Operand(eax));
+          unsafe_bailout_->Branch(negative);
+          __ bind(&not_negative_zero);
+        }
         Result edx_result(edx, NumberInfo::Integer32());
         edx_result.set_untagged_int32(true);
         frame_->Push(&edx_result);
=======================================
--- /branches/bleeding_edge/test/mjsunit/div-mod.js     Fri Feb 12 05:37:10 2010
+++ /branches/bleeding_edge/test/mjsunit/div-mod.js     Tue Mar 23 08:18:00 2010
@@ -169,3 +169,24 @@
   assertEquals(somenum, somenum % -0x40000000, "%minsmi-32");
   assertEquals(somenum, somenum % -0x80000000, "%minsmi-64");
 })();
+
+
+// Side-effect-free expressions containing bit operations use
+// an optimized compiler with int32 values.   Ensure that modulus
+// produces negative zeros correctly.
+function negative_zero_modulus_test() {
+  var x = 4;
+  var y = -4;
+  x = x + x - x;
+  y = y + y - y;
+  var z = (y | y | y | y) % x;
+  assertEquals(-1 / 0, 1 / z);
+  z = (x | x | x | x) % x;
+  assertEquals(1 / 0, 1 / z);
+  z = (y | y | y | y) % y;
+  assertEquals(-1 / 0, 1 / z);
+  z = (x | x | x | x) % y;
+  assertEquals(1 / 0, 1 / z);
+}
+
+negative_zero_modulus_test();

--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev

To unsubscribe from this group, send email to v8-dev+unsubscribegooglegroups.com or reply 
to this email with the words "REMOVE ME" as the subject.

Reply via email to