summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/mathTrunc.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/ion/mathTrunc.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/ion/mathTrunc.js')
-rw-r--r--js/src/jit-test/tests/ion/mathTrunc.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/ion/mathTrunc.js b/js/src/jit-test/tests/ion/mathTrunc.js
new file mode 100644
index 0000000000..35c0369a00
--- /dev/null
+++ b/js/src/jit-test/tests/ion/mathTrunc.js
@@ -0,0 +1,76 @@
+// Test Math.trunc() for IonMonkey.
+// Requires --ion-eager to enter at the top of each loop.
+
+var truncDITests = [
+ [0.49999999999999997, 0],
+ [0.5, 0],
+ [1.0, 1],
+ [1.5, 1],
+ [792.8, 792],
+ [-1.0001, -1],
+ [-3.14, -3],
+ [2137483649.5, 2137483649],
+ [2137483648.5, 2137483648],
+ [2137483647.1, 2137483647],
+ [-2147483647.8, -2147483647],
+];
+
+var truncDITests_bailout = [
+ ...truncDITests,
+
+ // Bailout in bailoutCvttsd2si: https://bugzil.la/1379626#c1
+ [-2147483648.8, -2147483648],
+];
+
+var truncDTests = [
+ [-0, -0],
+ [0.49999999999999997, 0],
+ [0.5, 0],
+ [1.0, 1],
+ [1.5, 1],
+ [792.8, 792],
+ [-0.1, -0],
+ [-1.0001, -1],
+ [-3.14, -3],
+ [2137483649.5, 2137483649],
+ [2137483648.5, 2137483648],
+ [2137483647.1, 2137483647],
+ [900000000000, 900000000000],
+ [-0, -0],
+ [-Infinity, -Infinity],
+ [Infinity, Infinity],
+ [NaN, NaN],
+ [-2147483648.8, -2147483648],
+ [-2147483649.8, -2147483649],
+];
+
+var truncITests = [
+ [0, 0],
+ [4, 4],
+ [-1, -1],
+ [-7, -7],
+ [2147483647, 2147483647],
+];
+
+// Typed functions to be compiled by Ion.
+function truncDI(x) { return Math.trunc(x); }
+function truncDI_bailout(x) { return Math.trunc(x); }
+function truncD(x) { return Math.trunc(x); }
+function truncI(x) { return Math.trunc(x); }
+
+function test() {
+ // Always run this function in the interpreter.
+ with ({}) {}
+
+ for (var i = 0; i < truncDITests.length; i++)
+ assertEq(truncDI(truncDITests[i][0]), truncDITests[i][1]);
+ for (var i = 0; i < truncDITests_bailout.length; i++)
+ assertEq(truncDI_bailout(truncDITests_bailout[i][0]), truncDITests_bailout[i][1]);
+ for (var i = 0; i < truncDTests.length; i++)
+ assertEq(truncD(truncDTests[i][0]), truncDTests[i][1]);
+ for (var i = 0; i < truncITests.length; i++)
+ assertEq(truncI(truncITests[i][0]), truncITests[i][1]);
+}
+
+for (var i = 0; i < 40; i++)
+ test();