]>
Commit | Line | Data |
---|---|---|
81345200 A |
1 | function foo(a, b, c) { |
2 | return (a|0) + (b|0) + (c|0); | |
3 | } | |
4 | ||
5 | function bar(o) { | |
6 | // Save a bunch of state in local variables. | |
7 | var a = o.f; | |
8 | var b = o.g; | |
9 | var c = o.h; | |
10 | var d = o.i; | |
11 | var e = o.j; | |
12 | var f = o.k; | |
13 | var g = o.l; | |
14 | // Make a call that will be subject to arity fixup and then use the saved state. We're | |
15 | // counting on LLVM to put those variables in callee-saves, since that's pretty much the | |
16 | // only sensible choice. | |
17 | return foo(42) + a + b + c + d + e + f + g; | |
18 | } | |
19 | ||
20 | noInline(foo); | |
21 | noInline(bar); | |
22 | ||
23 | for (var i = 0; i < 100000; ++i) { | |
24 | // Call bar() in such a way that all of those callee-save variables have fairly unique | |
25 | // looking values, to maximize the chances of foo() clobbering them in a recognizable | |
26 | // way. | |
27 | var result = bar({ | |
28 | f:i * 3, g:i - 1, h:(i / 2)|0, i:-i, j:13 + ((i / 5)|0), k:14 - ((i / 6)|0), | |
29 | l:1 - i}); | |
30 | ||
31 | var expected = 42 + i * 3 + i - 1 + ((i / 2)|0) - i + 13 + ((i / 5)|0) + 14 - | |
32 | ((i / 6)|0) + 1 - i; | |
33 | ||
34 | if (result != expected) | |
35 | throw "Error: for iteration " + i + " expected " + expected + " but got " + result; | |
36 | } |