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
|
setJitCompilerOption("ion.warmup.trigger", 30);
var max = 40;
// This test case verify that even if we do some scalar replacement, we keep a
// correct computation of Float32 maths. In this case, when the object is not
// escaped, the "store" instruction are preventing any float32 optimization to
// kick-in. After Scalar Replacement, the store is removed, and the Float32
// optimizations can avoid Double coercions.
function escape_object(o) {
if (o.e) {
print(o);
}
}
var func = null;
var check_object_argument_func = function (i, res) {
with ({}) { /* trun off the jit for this function, do not inline */ };
if (i == max - 1)
return funname.arguments[1].d;
return res;
};
var test_object_ref_check = eval(uneval(check_object_argument_func).replace("funname", "test_object_ref"));
function test_object_ref(x, tmp) {
tmp = {
a: Math.fround(Math.pow(2 * x / max, 0)),
b: Math.fround(Math.pow(2 * x / max, 25)),
c: Math.fround(Math.pow(2 * x / max, 50)),
d: 0
};
tmp.d = tmp.a + tmp.b;
assertFloat32(tmp.d, false);
escape_object(tmp);
return test_object_ref_check(x, Math.fround(tmp.c + Math.fround(tmp.d)));
}
var test_object_check = eval(uneval(check_object_argument_func).replace("funname", "test_object"));
function test_object(x, tmp) {
tmp = {
a: Math.fround(Math.pow(2 * x / max, 0)),
b: Math.fround(Math.pow(2 * x / max, 25)),
c: Math.fround(Math.pow(2 * x / max, 50)),
d: 0
};
tmp.d = tmp.a + tmp.b;
assertFloat32(tmp.d, false);
return test_object_check(x, Math.fround(tmp.c + Math.fround(tmp.d)));
}
// Same test with Arrays.
function escape_array(o) {
if (o.length == 0) {
print(o);
}
}
var check_array_argument_func = function (i, res) {
with ({}) { /* trun off the jit for this function, do not inline */ };
if (i == max - 1) {
return funname.arguments[1][3];
}
return res;
};
var test_array_ref_check = eval(uneval(check_array_argument_func).replace("funname", "test_array_ref"));
function test_array_ref(x, tmp) {
tmp = [
Math.fround(Math.pow(2 * x / max, 0)),
Math.fround(Math.pow(2 * x / max, 25)),
Math.fround(Math.pow(2 * x / max, 50)),
0
];
tmp[3] = tmp[0] + tmp[1];
assertFloat32(tmp[3], false);
escape_array(tmp);
return test_array_ref_check(x, Math.fround(tmp[2] + Math.fround(tmp[3])));
}
var test_array_check = eval(uneval(check_array_argument_func).replace("funname", "test_array"));
function test_array(x, tmp) {
tmp = [
Math.fround(Math.pow(2 * x / max, 0)),
Math.fround(Math.pow(2 * x / max, 25)),
Math.fround(Math.pow(2 * x / max, 50)),
0
];
tmp[3] = tmp[0] + tmp[1];
assertFloat32(tmp[3], false);
return test_array_check(x, Math.fround(tmp[2] + Math.fround(tmp[3])));
}
for (var i = 0; i < max; i++) {
assertEq(test_object_ref(i, undefined), test_object(i, undefined));
assertEq(test_array_ref(i, undefined), test_array(i, undefined));
}
|