forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftl-polymorphic-mul.js
50 lines (44 loc) · 1.16 KB
/
ftl-polymorphic-mul.js
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
//@ runFTLNoCJIT
var o1 = {
i: 0,
valueOf: function() { return this.i; }
};
result = 0;
function foo(a, b) {
var result = 0;
for (var j = 0; j < 10; j++) {
if (a > b)
result += a * b;
else
result += b * 1;
}
// Busy work just to allow the DFG and FTL to optimize this out. If the above causes
// us to speculation fail out to the baseline, this busy work will take a lot longer
// to run.
// This loop below also gets the DFG to compile this function sooner.
var origResult = result;
for (var i = 1; i < 1000; i++)
result = result * i;
result = origResult < result ? origResult : result;
return result;
}
noInline(foo);
var iterations;
var expectedResult;
if (this.window) {
// The layout test doesn't like too many iterations and may time out.
iterations = 10000;
expectedResult = 5000495600;
} else {
iterations = 100000;
expectedResult = 500004995600;
}
for (var i = 0; i <= iterations; i++) {
o1.i = i;
if (i % 2)
result += foo(o1, 10);
else
result += foo(i, 10);
}
if (result != expectedResult)
throw "Bad result: " + result;