blob: 16b9863b360247f27cab023105ac1002ab1a7f6c [file] [log] [blame]
rniwa@webkit.orgc4705bf2015-05-13 21:05:03 +00001//@ skip if $hostOS == "windows"
2
benjamin@webkit.org1dca4332015-05-12 21:28:43 +00003// Verify that the dividend propagate the NeedsNegZero if the dividend requires it.
4function moduloWithNegativeZeroDividend(a, b, c)
5{
6 var temp = a * b;
7 return temp % c;
8}
9noInline(moduloWithNegativeZeroDividend);
10
11// Warm up with integers. The test for NegZero should not be eliminated here.
benjamin@webkit.orgee161862015-05-13 01:52:52 +000012for (var i = 1; i < 1e4; ++i) {
benjamin@webkit.org1dca4332015-05-12 21:28:43 +000013 var result = moduloWithNegativeZeroDividend(i, 5, 5);
14 if (result !== 0)
15 throw "moduloWithNegativeZeroDividend(i, 5, 5), returned: " + result;
16}
17
benjamin@webkit.orgee161862015-05-13 01:52:52 +000018for (var i = 1; i < 1e4; ++i) {
benjamin@webkit.org1dca4332015-05-12 21:28:43 +000019 // Produce negative zero in the multiplication.
20 var result = moduloWithNegativeZeroDividend(-i, 0, 2);
21 if (!(result === 0 && (1/result) === -Infinity))
22 throw "moduloWithNegativeZeroDividend(-i, 0, 2) failed, returned: " + result;
23
24 // A negative dividend can produce negative zero results.
25 var result = moduloWithNegativeZeroDividend(-i, 5, 5);
26 if (!(result === 0 && (1/result) === -Infinity))
27 throw "moduloWithNegativeZeroDividend(-i, 5, 5) failed, returned: " + result;
28}
29
30// Edge cases.
benjamin@webkit.orgee161862015-05-13 01:52:52 +000031for (var i = 1; i < 1e4; ++i) {
benjamin@webkit.org1dca4332015-05-12 21:28:43 +000032 var result = moduloWithNegativeZeroDividend(-i, 0, Infinity);
33 if (!(result === 0 && (1/result) === -Infinity))
34 throw "moduloWithNegativeZeroDividend(-i, 0, Infinity) failed, returned: " + result;
35
36 var result = moduloWithNegativeZeroDividend(-i, 0, -Infinity);
37 if (!(result === 0 && (1/result) === -Infinity))
38 throw "moduloWithNegativeZeroDividend(-i, 0, -Infinity) failed, returned: " + result;
39
40 var result = moduloWithNegativeZeroDividend(-i, 0, NaN);
41 if (result === result)
42 throw "moduloWithNegativeZeroDividend(-i, 0, NaN) failed, returned: " + result;
43}
44
45
46// In this case, the negative zero is irrelevant. The Neg Zero check can be eliminated.
47function moduloWithUnusedNegativeZeroDividend(a, b, c)
48{
49 var temp = a * b;
50 return (temp % c) | 0;
51}
52noInline(moduloWithUnusedNegativeZeroDividend);
53
benjamin@webkit.orgee161862015-05-13 01:52:52 +000054for (var i = 1; i < 1e4; ++i) {
benjamin@webkit.org1dca4332015-05-12 21:28:43 +000055 var result = moduloWithUnusedNegativeZeroDividend(i, 5, 5);
56 if (result !== 0)
57 throw "moduloWithUnusedNegativeZeroDividend(i, 5, 5), returned: " + result;
58}
59
60// Produce negative zero in the multiplication.
benjamin@webkit.orgee161862015-05-13 01:52:52 +000061for (var i = 1; i < 1e4; ++i) {
benjamin@webkit.org1dca4332015-05-12 21:28:43 +000062 var result = moduloWithUnusedNegativeZeroDividend(-i, 0, 2);
63 if (!(result === 0 && (1/result) === Infinity))
64 throw "moduloWithUnusedNegativeZeroDividend(-i, 0, 2) failed, returned: " + result;
65}
66
benjamin@webkit.orgee161862015-05-13 01:52:52 +000067for (var i = 1; i < 1e4; ++i) {
benjamin@webkit.org1dca4332015-05-12 21:28:43 +000068 var result = moduloWithUnusedNegativeZeroDividend(-i, 0, Infinity);
69 if (!(result === 0 && (1/result) === Infinity))
70 throw "moduloWithUnusedNegativeZeroDividend(-i, 0, Infinity) failed, returned: " + result;
71
72 var result = moduloWithUnusedNegativeZeroDividend(-i, 0, -Infinity);
73 if (!(result === 0 && (1/result) === Infinity))
74 throw "moduloWithUnusedNegativeZeroDividend(-i, 0, -Infinity) failed, returned: " + result;
75
76 var result = moduloWithUnusedNegativeZeroDividend(-i, 0, NaN);
77 if (result !== 0)
78 throw "moduloWithUnusedNegativeZeroDividend(-i, 0, NaN) failed, returned: " + result;
79}
80
81
82// The sign of the divisor is completely irrelevant. This should never fail on negative zero divisors.
83function moduloWithNegativeZeroDivisor(a, b, c)
84{
85 var temp = a * b;
86 return c % temp;
87}
88noInline(moduloWithNegativeZeroDivisor);
89
90// Warm up with integers.
benjamin@webkit.orgee161862015-05-13 01:52:52 +000091for (var i = 1; i < 1e4; ++i) {
benjamin@webkit.org1dca4332015-05-12 21:28:43 +000092 var result = moduloWithNegativeZeroDivisor(i, 2, i);
93 if (result !== i)
94 throw "moduloWithNegativeZeroDividend(i, 2, i), returned: " + result;
95
96 var result = moduloWithNegativeZeroDivisor(-i, 2, i);
97 if (result !== i)
98 throw "moduloWithNegativeZeroDividend(-i, 2, i), returned: " + result;
99}
100
101// Produce negative zero in the multiplication.
benjamin@webkit.orgee161862015-05-13 01:52:52 +0000102for (var i = 1; i < 1e4; ++i) {
benjamin@webkit.org1dca4332015-05-12 21:28:43 +0000103 var result = moduloWithNegativeZeroDivisor(-i, 0, 2);
104 if (result === result)
105 throw "moduloWithNegativeZeroDivisor(-i, 0, 2) failed, returned: " + result;
106}