Reviewers: fschneider,
Description:
Fix an error in optimized modulus operator, add unit test.
Please review this at http://codereview.chromium.org/1118008
SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/
Affected files:
M src/ia32/codegen-ia32.cc
M test/mjsunit/div-mod.js
Index: test/mjsunit/div-mod.js
===================================================================
--- test/mjsunit/div-mod.js (revision 4229)
+++ test/mjsunit/div-mod.js (working copy)
@@ -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();
Index: src/ia32/codegen-ia32.cc
===================================================================
--- src/ia32/codegen-ia32.cc (revision 4230)
+++ src/ia32/codegen-ia32.cc (working copy)
@@ -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, ¬_negative_zero);
+ __ test(eax, Operand(eax));
+ unsafe_bailout_->Branch(negative);
+ __ bind(¬_negative_zero);
+ }
Result edx_result(edx, NumberInfo::Integer32());
edx_result.set_untagged_int32(true);
frame_->Push(&edx_result);
--
v8-dev mailing list
[email protected]
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.