summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/cacheir/binaryarith-mod-int32.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/cacheir/binaryarith-mod-int32.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/cacheir/binaryarith-mod-int32.js')
-rw-r--r--js/src/jit-test/tests/cacheir/binaryarith-mod-int32.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/cacheir/binaryarith-mod-int32.js b/js/src/jit-test/tests/cacheir/binaryarith-mod-int32.js
new file mode 100644
index 0000000000..0801606808
--- /dev/null
+++ b/js/src/jit-test/tests/cacheir/binaryarith-mod-int32.js
@@ -0,0 +1,70 @@
+setJitCompilerOption("ion.forceinlineCaches", 1);
+
+function runTest(dividend, divisor) {
+ function test(dividend, divisor, expected) {
+ for (var i = 0; i < dividend.length; i++) {
+ var x = dividend[i];
+ for (var j = 0; j < divisor.length; j++) {
+ var y = divisor[j];
+ var result = x % y;
+
+ assertEq(result, expected[i * divisor.length + j]);
+ }
+ }
+ }
+
+ var f = Function(`return ${test}`)();
+
+ // Seed the IC to ensure we're using Int32Mod.
+ var ones = Array(8).fill(1);
+ var zeros = Array(8 * 8).fill(0);
+ for (var i = 0; i < 2; ++i) {
+ f(ones, ones, zeros);
+ }
+
+ var expected = dividend.map(x => divisor.map(y => x % y)).flat();
+ for (var i = 0; i < 10; ++i) {
+ f(dividend, divisor, expected);
+ }
+}
+
+const positiveInt32 = [
+ 1, 2, 3, 4, 5, 6, 7, 8,
+ 2**31 - 8,
+ 2**31 - 7,
+ 2**31 - 6,
+ 2**31 - 5,
+ 2**31 - 4,
+ 2**31 - 3,
+ 2**31 - 2,
+ 2**31 - 1,
+];
+
+const negativeInt32 = [
+ -1, -2, -3, -4, -5, -6, -7, -8,
+ -(2**31 - 8),
+ -(2**31 - 7),
+ -(2**31 - 6),
+ -(2**31 - 5),
+ -(2**31 - 4),
+ -(2**31 - 3),
+ -(2**31 - 2),
+ -(2**31 - 1),
+ -(2**31),
+];
+
+const zero = [0];
+
+const cases = [positiveInt32, zero, negativeInt32];
+
+for (let a of cases) {
+ for (let b of cases) {
+ runTest(a, b);
+ }
+}
+
+// Test some "interesting" cases.
+
+// |-2147483648 % -1| may internally compute |-2147483648 / -1|, which isn't an int32 and
+// may trigger a floating point exception on some architectures.
+runTest([-2147483648], [-1]);