summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/udiv.js
blob: 446f23c2024d656bd6b2ae47c8676f7b95b7e1fb (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
function test_i32_udiv_n2() {
    return wasmEvalText(
      `(module
         (type (;0;) (func (param i32) (result i32)))
         (func (;0;) (type 0) (param i32) (result i32)
           local.get 0
           i32.const -2
           i32.div_u)
         (export "main" (func 0)))`
    ).exports["main"];
}
function test_i32_udiv_n1() {
    return wasmEvalText(
      `(module
         (type (;0;) (func (param i32) (result i32)))
         (func (;0;) (type 0) (param i32) (result i32)
           local.get 0
           i32.const -1
           i32.div_u)
         (export "main" (func 0)))`
    ).exports["main"];
}
function test_i32_udiv_p2() {
    return wasmEvalText(
      `(module
         (type (;0;) (func (param i32) (result i32)))
         (func (;0;) (type 0) (param i32) (result i32)
           local.get 0
           i32.const 2
           i32.div_u)
         (export "main" (func 0)))`
    ).exports["main"];
}
function test_i32_udiv_p1() {
    return wasmEvalText(
      `(module
         (type (;0;) (func (param i32) (result i32)))
         (func (;0;) (type 0) (param i32) (result i32)
           local.get 0
           i32.const 1
           i32.div_u)
         (export "main" (func 0)))`
    ).exports["main"];
}

let udiv_p1 = test_i32_udiv_p1();
assertEq(udiv_p1(1), 1);
assertEq(udiv_p1(2), 2);
assertEq(udiv_p1(0x7fffffff), 0x7fffffff);
assertEq(udiv_p1(-1), -1); // results are converted to i32.

let udiv_p2 = test_i32_udiv_p2();
assertEq(udiv_p2(1), 0);
assertEq(udiv_p2(2), 1);
assertEq(udiv_p2(0x7fffffff), 0x7fffffff >> 1);
assertEq(udiv_p2(-1), 0x7fffffff); // -1 is converted to u32.

let udiv_n1 = test_i32_udiv_n1();
assertEq(udiv_n1(1), 0);
assertEq(udiv_n1(2), 0);
assertEq(udiv_n1(0x7fffffff), 0);
assertEq(udiv_n1(-1), 1);

let udiv_n2 = test_i32_udiv_n2();
assertEq(udiv_n2(1), 0);
assertEq(udiv_n2(2), 0);
assertEq(udiv_n2(0x7fffffff), 0);
assertEq(udiv_n2(-1), 1);