Bug 1343007 - Wasm test case for signed modulo. r=luke
authorLars T Hansen <lhansen@mozilla.com>
Tue, 14 Mar 2017 17:33:00 +0100
changeset 348663 21223d98c2eabfb28b4ce4d13d0d86ff6a61b838
parent 348662 6b3cb80665594cd64cce48ca14da9b3f9e5064c7
child 348664 620f5ed5c91ec42874c6b725d8caddb713bbe022
push id31533
push userkwierso@gmail.com
push dateTue, 21 Mar 2017 23:08:53 +0000
treeherdermozilla-central@8744e9f8eb99 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1343007
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1343007 - Wasm test case for signed modulo. r=luke
js/src/jit-test/tests/wasm/regress/signed-unsigned-div-mod.js
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/regress/signed-unsigned-div-mod.js
@@ -0,0 +1,77 @@
+setJitCompilerOption('wasm.test-mode', 1);
+
+// The result should be -1 because it is (i32.rem_s -1 10000) and the spec
+// stipulates "result has the sign of the dividend".  This test uncovers a bug
+// in SpiderMonkey wherein the shape of the lhs (it looks like an unsigned
+// value) causes an unsigned modulo to be emitted.
+
+assertEq(wasmEvalText(
+    `(module
+      (func (result i32)
+       (i32.const -1)
+       (i32.const 0)
+       i32.shr_u
+       (i32.const 10000)
+       i32.rem_s)
+      (export "f" 0))`).exports.f(), -1);
+
+// Ditto for int64
+
+assertEqI64(wasmEvalText(
+    `(module
+      (func (result i64)
+       (i64.const -1)
+       (i64.const 0)
+       i64.shr_u
+       (i64.const 10000)
+       i64.rem_s)
+      (export "f" 0))`).exports.f(), {low:-1, high:-1});
+
+// Despite the signed shift this is 0x80000000 % 10000 (rem_u)
+// and the result is positive.
+
+assertEq(wasmEvalText(
+    `(module
+      (func (result i32)
+       (i32.const -1)
+       (i32.const 0)
+       i32.shl
+       (i32.const 10000)
+       i32.rem_u)
+      (export "f" 0))`).exports.f(), 7295);
+
+// 0x80000000 is really -0x80000000 so the result of signed division shall be
+// negative.
+
+assertEq(wasmEvalText(
+    `(module
+      (func (result i32)
+       (i32.const 0x80000000)
+       (i32.const 0)
+       i32.shr_u
+       (i32.const 10000)
+       i32.div_s)
+      (export "f" 0))`).exports.f(), -214748);
+
+assertEq(wasmEvalText(
+    `(module
+      (func (result i32)
+       (i32.const 0x80000000)
+       (i32.const 0)
+       i32.shr_u
+       (i32.const -10000)
+       i32.div_s)
+      (export "f" 0))`).exports.f(), 214748);
+
+// And the result of unsigned division shall be positive.
+
+assertEq(wasmEvalText(
+    `(module
+      (func (result i32)
+       (i32.const 0x80000000)
+       (i32.const 0)
+       i32.shr_u
+       (i32.const 10000)
+       i32.div_u)
+      (export "f" 0))`).exports.f(), 214748);
+