summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/regress/signed-unsigned-div-mod.js
blob: 370676d2c403c64e1c622085629fc6dad36cb755 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// 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" (func 0)))`).exports.f(), -1);

// Ditto for int64

wasmAssert(
    `(module
      (func $run (result i64)
       (i64.const -1)
       (i64.const 0)
       i64.shr_u
       (i64.const 10000)
       i64.rem_s)
     )`, [{type:'i64', expected:'0xffffffffffffffff', func:'$run'}]);

// 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" (func 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" (func 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" (func 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" (func 0)))`).exports.f(), 214748);