Debian Codegraph @

js/src/jit-test/tests/ion/test-scalar-replacement-float32.js

raw
1 setJitCompilerOption("ion.warmup.trigger", 30);
2 var max = 40;
3
4 // This test case verify that even if we do some scalar replacement, we keep a
5 // correct computation of Float32 maths. In this case, when the object is not
6 // escaped, the "store" instruction are preventing any float32 optimization to
7 // kick-in. After Scalar Replacement, the store is removed, and the Float32
8 // optimizations can avoid Double coercions.
9 function escape_object(o) {
10 if (o.e) {
11 print(o);
12 }
13 }
14
15 var func = null;
16 var check_object_argument_func = function (i, res) {
17 with ({}) { /* trun off the jit for this function, do not inline */ };
18 if (i == max - 1)
19 return funname.arguments[1].d;
20 return res;
21 };
22
23 var test_object_ref_check = eval(`(${check_object_argument_func})`.replace("funname", "test_object_ref"));
24 function test_object_ref(x, tmp) {
25 tmp = {
26 a: Math.fround(Math.pow(2 * x / max, 0)),
27 b: Math.fround(Math.pow(2 * x / max, 25)),
28 c: Math.fround(Math.pow(2 * x / max, 50)),
29 d: 0
30 };
31
32 tmp.d = tmp.a + tmp.b;
33 assertFloat32(tmp.d, false);
34 escape_object(tmp);
35 return test_object_ref_check(x, Math.fround(tmp.c + Math.fround(tmp.d)));
36 }
37
38 var test_object_check = eval(`(${check_object_argument_func})`.replace("funname", "test_object"));
39 function test_object(x, tmp) {
40 tmp = {
41 a: Math.fround(Math.pow(2 * x / max, 0)),
42 b: Math.fround(Math.pow(2 * x / max, 25)),
43 c: Math.fround(Math.pow(2 * x / max, 50)),
44 d: 0
45 };
46
47 tmp.d = tmp.a + tmp.b;
48 assertFloat32(tmp.d, false);
49 return test_object_check(x, Math.fround(tmp.c + Math.fround(tmp.d)));
50 }
51
52 // Same test with Arrays.
53 function escape_array(o) {
54 if (o.length == 0) {
55 print(o);
56 }
57 }
58
59 var check_array_argument_func = function (i, res) {
60 with ({}) { /* trun off the jit for this function, do not inline */ };
61 if (i == max - 1) {
62 return funname.arguments[1][3];
63 }
64 return res;
65 };
66
67 var test_array_ref_check = eval(`(${check_array_argument_func})`.replace("funname", "test_array_ref"));
68 function test_array_ref(x, tmp) {
69 tmp = [
70 Math.fround(Math.pow(2 * x / max, 0)),
71 Math.fround(Math.pow(2 * x / max, 25)),
72 Math.fround(Math.pow(2 * x / max, 50)),
73 0
74 ];
75 tmp[3] = tmp[0] + tmp[1];
76 assertFloat32(tmp[3], false);
77 escape_array(tmp);
78 return test_array_ref_check(x, Math.fround(tmp[2] + Math.fround(tmp[3])));
79 }
80
81 var test_array_check = eval(`(${check_array_argument_func})`.replace("funname", "test_array"));
82 function test_array(x, tmp) {
83 tmp = [
84 Math.fround(Math.pow(2 * x / max, 0)),
85 Math.fround(Math.pow(2 * x / max, 25)),
86 Math.fround(Math.pow(2 * x / max, 50)),
87 0
88 ];
89 tmp[3] = tmp[0] + tmp[1];
90 assertFloat32(tmp[3], false);
91 return test_array_check(x, Math.fround(tmp[2] + Math.fround(tmp[3])));
92 }
93
94
95 for (var i = 0; i < max; i++) {
96 assertEq(test_object_ref(i, undefined), test_object(i, undefined));
97 assertEq(test_array_ref(i, undefined), test_array(i, undefined));
98 }