summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/udiv-by-u32-constant.js
blob: f73a6f6465330777a5fc31db19c3048b15a104f0 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function uint_seq(count) {
    with({}){}
    var arr = [];
    var x = 0xfac83126;
    while (count--) {
        x ^= x << 13;
        x ^= x >> 17;
        x ^= x << 5;
        arr.push(x >>> 0);
    }
    return arr;
}

function test(name, asm, ion, int) {
    with({}){}
    let count = 10000;
    let seq = uint_seq(count);
    for (let x of seq) {
        let rint = int(x);
        let rasm = asm(x);
        let rion = ion(x);
        // console.log(name, x, rint, rasm, rion);
        assertEq(rasm, rint);
        assertEq(rion, rint);
    }
}

var asmdiv2 = (function(m) {
    "use asm"
    function f(x) {
        x = x|0;
        var z = 0;
        z = ((x>>>0) / 2)>>>0;
        return z|0;
    }
    return f;
})()

var plaindiv2 = function(x) {
    x = x|0;
    var z = 0;
    z = ((x>>>0) / 2)>>>0;
    return z|0;
}

var interpdiv2 = function(x) {
    with({}){};
    x = x|0;
    var z = 0;
    z = ((x>>>0) / 2)>>>0;
    return z|0;
}

test("div2", asmdiv2, plaindiv2, interpdiv2);

var asmdiv3 = (function(m) {
    "use asm"
    function f(x) {
        x = x|0;
        var z = 0;
        z = ((x>>>0) / 3)>>>0;
        return z|0;
    }
    return f;
})()

var plaindiv3 = function(x) {
    x = x|0;
    var z = 0;
    z = ((x>>>0) / 3)>>>0;
    return z|0;
}

var interpdiv3 = function(x) {
    with({}){};
    x = x|0;
    var z = 0;
    z = ((x>>>0) / 3)>>>0;
    return z|0;
}

test("div3", asmdiv3, plaindiv3, interpdiv3);

var asmdiv7 = (function(m) {
    "use asm"
    function f(x) {
        x = x|0;
        var z = 0;
        z = ((x>>>0) / 7)>>>0;
        return z|0;
    }
    return f;
})()

var plaindiv7 = function(x) {
    x = x|0;
    var z = 0;
    z = ((x>>>0) / 7)>>>0;
    return z|0;
}

var interpdiv7 = function(x) {
    with({}){};
    x = x|0;
    var z = 0;
    z = ((x>>>0) / 7)>>>0;
    return z|0;
}

test("div7", asmdiv7, plaindiv7, interpdiv7);