summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/asm.js/bug941877.js
blob: c2033cf8d90eb295f1f9f3bac7ae12c39c760ec2 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
load(libdir + "asm.js");

function FunctionBody(f) {
    var str = f.toString();
    var firstBrace = str.indexOf('{');
    var lastBrace = str.lastIndexOf('}');
    return str.substr(firstBrace + 1, lastBrace - firstBrace - 1);
}

var F = (function (stdlib, n, heap) {
    var Int16ArrayView = new stdlib.Int16Array(heap);
    function f(i0, d1) {
        i0 = i0 | 0
        d1 = +d1
        var d2 = 1.
        var i3 = 0
        Int16ArrayView[0] = i0
        d2 = (.0 / .0)
        switch ((i0 + i0) | 0) {
            case 0:
                d2 = .0
                break
        };
        (((i3 - (0 < 0)) >>> ((.0 < -0) + (.0 > .0))) / 0) >> (0 + (((0 + 0) ^
(9 > 0)) | 0))
    }
    return f;
});

var compiled = asmCompile('stdlib', 'n', 'heap', USE_ASM + FunctionBody(F));
asmLink(compiled, this, null, new ArrayBuffer(BUF_MIN))();

var F = (function(stdlib, n, heap) {
    var Float64ArrayView = new stdlib.Float64Array(heap)
    function f() {
        Float64ArrayView[0] = +(0xffffffff / 0xffffffff >> 0)
    }
    return f;
});

var compiled = asmCompile('stdlib', 'n', 'heap', USE_ASM + FunctionBody(F));
asmLink(compiled, this, null, new ArrayBuffer(BUF_MIN))();

function test0(x)
{
   return (x >>> 0) % 10;
}
assertEq(test0(25), 5);
assertEq(test0(24), 4);
assertEq(test0(23), 3);
assertEq(test0(0), 0);
assertEq(test0(4294967295), 5);

function test1(x)
{
   return (x >>> 2) % 10;
}
assertEq(test1(25), 6);
assertEq(test1(24), 6);
assertEq(test1(23), 5);
assertEq(test1(4294967295), 3);

function test2(x, y)
{
   return (x >>> 0) % (y >>> 0);
}
assertEq(test2(25, 3), 1);
assertEq(test2(24, 4), 0);
assertEq(test2(4294967295, 10), 5);
assertEq(test2(23, 0), NaN);

function test3()
{
    function f(x, y)
    {
        x = x|0;
        y = y|0;
        var t = 0;
        t = (((x|0) % (y|0))|0) > -2;
        return t|0;
    }
    return f;
}
var compiled = asmCompile(USE_ASM + FunctionBody(test3));
var linked = asmLink(compiled);
assertEq(linked(4294967290, 4294967295), 1);
assertEq(linked(4294967290, 4294967295), 1);

function test4()
{
    function f(x, y)
    {
        x = x|0;
        y = y|0;
        var t = 0;
        t = (((x>>>0) % (y>>>0)) >>> 0) > 0;
        return t|0;
    }
    return f;
}
var compiled = asmCompile(USE_ASM + FunctionBody(test4));
var linked = asmLink(compiled);
assertEq(linked(4294967290, 4294967295), 1);
assertEq(linked(4294967290, 4294967295), 1);

function test5()
{
    function f(x, y)
    {
        x = x|0;
        y = y|0;
        var t = 0.;
        t = +(((x>>>0) % (y>>>0)) >>> 0) * 1.01;
        return +t;
    }
    return f;
}
var compiled = asmCompile(USE_ASM + FunctionBody(test5));
var linked = asmLink(compiled);
assertEq(linked(4294967290, 4294967295), 4337916962.9);
assertEq(linked(4294967290, 4294967295), 4337916962.9);

function test6()
{
    function f(x, y)
    {
        x = x|0;
        y = y|0;
        return ((x>>>1) % (y>>>1))|0;
    }
    return f;
}
var compiled = asmCompile(USE_ASM + FunctionBody(test6));
var linked = asmLink(compiled);
assertEq(linked(23847, 7), 1);
assertEq(linked(23848, 7), 2);

function test7()
{
    function f(x)
    {
        x = x|0;
        return ((x>>>0) / 8)|0;
    }
    return f;
}
var compiled = asmCompile(USE_ASM + FunctionBody(test7));
var linked = asmLink(compiled);
assertEq(linked(23847, 7), 2980);
assertEq(linked(23848, 7), 2981);

function test8()
{
    function f(i,j)
    {
        i=i|0;j=j|0;
        return ((i>>>0)/(j>>>0))|0;
    }
    return f;
}
var compiled = asmCompile(USE_ASM + FunctionBody(test8));
var linked = asmLink(compiled);
assertEq(linked(2147483647, 0), 0);
assertEq(linked(2147483646, 0), 0);