summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/select-int32.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jit-test/tests/wasm/select-int32.js')
-rw-r--r--js/src/jit-test/tests/wasm/select-int32.js123
1 files changed, 123 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/wasm/select-int32.js b/js/src/jit-test/tests/wasm/select-int32.js
new file mode 100644
index 0000000000..2645b76a44
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/select-int32.js
@@ -0,0 +1,123 @@
+
+// Checks that optimised handling, via Ion, of select-of-I32-values as driven
+// by comparison-of-I32-values, works correctly. See bug 1532286 comment 7.
+
+function moduleText(cmp_kind /* "eq", "ne", "le_u" etc */)
+{
+ return `(module
+ (func (export "cmpI32_selI32")
+ (param i32) (param i32) (param i32) (param i32)
+ (result i32)
+ (select (get_local 2)
+ (get_local 3)
+ (i32.${cmp_kind} (get_local 0) (get_local 1))
+ )
+ ))`;
+}
+
+// Make sure both endpoints and the middlepoint are covered, with one value
+// either side, so as to expose both signedness and off-by-one failures.
+// Ditto quarter points for good measure.
+const vals = [0x0, 0x1,
+ 0x3fffffff, 0x40000000, 0x40000001,
+ 0x7fffffff, 0x80000000, 0x80000001,
+ 0xbfffffff, 0xC0000000, 0xC0000001,
+ 0xfffffffe, 0xffffffff];
+
+const testNames
+ = ["eq", "ne", "lt_s", "lt_u", "gt_s", "gt_u",
+ "le_s", "le_u", "ge_s", "ge_u"];
+
+const expected_eq
+ = [0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,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
+ = [0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,
+ 1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,
+ 0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,0,
+ 0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,
+ 0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0];
+
+const testExpVecs
+ = [expected_eq, expected_ne,
+ expected_lt_s, expected_lt_u, expected_gt_s, expected_gt_u,
+ expected_le_s, expected_le_u, expected_ge_s, expected_ge_u]
+
+assertEq(testNames.length, testExpVecs.length);
+
+for (i in testNames) {
+ const testExp = testExpVecs[i];
+ assertEq(testExp.length, vals.length * vals.length);
+
+ const inst = wasmEvalText(moduleText(testNames[i]));
+
+ let ctr = 0;
+ for (let a of vals) {
+ for (let b of vals) {
+ const actual = inst.exports.cmpI32_selI32(a, b, 42, 1337);
+ const expected = testExp[ctr] == 0 ? 42 : 1337;
+ assertEq(expected, actual);
+ ctr++;
+ }
+ }
+}