OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 the V8 project authors. All rights reserved. | |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | |
28 // Flags: --allow-natives-syntax | |
29 | |
30 // A regression test for a register allocation bug triggered by | |
31 // http://n3emscripten.appspot.com/dragons_asmjs.html. Note that the test is | |
32 // very fragile, but without a proper testing infrastructure for the register | |
33 // allocator we can't really do much better. | |
34 // | |
35 // The code below is a slighty modified version of Emscripten-translated C++ | |
36 // code for the standard textbook algorithm for frustum culling of an object | |
37 // with a given bounding box. | |
38 // | |
39 // The key problem for the underlying bug was a value with a long live range | |
40 // which is used often (a context) and a lot of live ranges starting at the same | |
41 // point. The bug was that none of the ranges were allowed to be spilled, so the | |
42 // allocator tried to split of an empty range, making no progress at all. | |
Vyacheslav Egorov (Chromium)
2013/03/11 08:43:15
register allocator was splitting live range at its
Sven Panne
2013/03/11 09:48:03
Done.
| |
43 | |
44 (function () { | |
45 function __ZNK4Math5plane3dotERKNS_6float4E(i1, i2) { | |
46 i1 = i1 | 0; | |
47 i2 = i2 | 0; | |
48 return +(+HEAPF32[i1 >> 2] * +HEAPF32[i2 >> 2] + +HEAPF32[i1 + 4 >> 2] * +HE APF32[i2 + 4 >> 2] + +HEAPF32[i1 + 8 >> 2] * +HEAPF32[i2 + 8 >> 2] + +HEAPF32[i1 + 12 >> 2] * +HEAPF32[i2 + 12 >> 2]); | |
danno
2013/03/11 08:39:57
nits: 80 col here and below
Sven Panne
2013/03/11 09:48:03
As discussed offline, let's keep this as it is if
| |
49 } | |
50 | |
51 function __ZNK4Math7frustum8clipmaskERKNS_5pointE(i1, i2) { | |
52 i1 = i1 | 0; | |
53 i2 = i2 | 0; | |
54 var i3 = 0, i4 = 0; | |
55 i3 = i2 | 0; | |
56 i2 = +__ZNK4Math5plane3dotERKNS_6float4E(i1 | 0, i3) > 0.0 & 1; | |
57 i4 = +__ZNK4Math5plane3dotERKNS_6float4E(i1 + 16 | 0, i3) > 0.0 ? i2 | 2 : i 2; | |
58 i2 = +__ZNK4Math5plane3dotERKNS_6float4E(i1 + 32 | 0, i3) > 0.0 ? i4 | 4 : i 4; | |
59 i4 = +__ZNK4Math5plane3dotERKNS_6float4E(i1 + 48 | 0, i3) > 0.0 ? i2 | 8 : i 2; | |
60 i2 = +__ZNK4Math5plane3dotERKNS_6float4E(i1 + 64 | 0, i3) > 0.0 ? i4 | 16 : i4; | |
61 return (+__ZNK4Math5plane3dotERKNS_6float4E(i1 + 80 | 0, i3) > 0.0 ? i2 | 32 : i2) | 0; | |
62 } | |
63 | |
64 function __ZNK4Math7frustum10clipstatusERKNS_4bboxE(i1, i2) { | |
65 i1 = i1 | 0; | |
66 i2 = i2 | 0; | |
67 var i3 = 0, i4 = 0, i5 = 0, i6 = 0, i7 = 0, i8 = 0, i9 = 0, i10 = 0, i11 = 0 , i12 = 0, i13 = 0, i14 = 0, i15 = 0, i16 = 0, d17 = 0.0, d18 = 0.0, i19 = 0, i2 0 = 0, i21 = 0, i22 = 0; | |
68 i3 = STACKTOP; | |
69 STACKTOP = STACKTOP + 16 | 0; | |
70 i4 = i3 | 0; | |
71 i5 = i4 | 0; | |
72 HEAPF32[i5 >> 2] = 0.0; | |
73 i6 = i4 + 4 | 0; | |
74 HEAPF32[i6 >> 2] = 0.0; | |
75 i7 = i4 + 8 | 0; | |
76 HEAPF32[i7 >> 2] = 0.0; | |
77 i8 = i4 + 12 | 0; | |
78 HEAPF32[i8 >> 2] = 1.0; | |
79 i9 = i2 | 0; | |
80 i10 = i2 + 4 | 0; | |
81 i11 = i2 + 8 | 0; | |
82 i12 = i2 + 20 | 0; | |
83 i13 = i2 + 16 | 0; | |
84 i14 = i2 + 24 | 0; | |
85 i2 = 65535; | |
86 i15 = 0; | |
87 i16 = 0; | |
88 while (1) { | |
89 if ((i16 | 0) == 1) { | |
90 d17 = +HEAPF32[i12 >> 2]; | |
91 d18 = +HEAPF32[i11 >> 2]; | |
92 HEAPF32[i5 >> 2] = +HEAPF32[i9 >> 2]; | |
93 HEAPF32[i6 >> 2] = d17; | |
94 HEAPF32[i7 >> 2] = d18; | |
95 HEAPF32[i8 >> 2] = 1.0; | |
96 } else if ((i16 | 0) == 4) { | |
97 HEAPF32[i5 >> 2] = +HEAPF32[i13 >> 2]; | |
98 HEAPF32[i6 >> 2] = +HEAPF32[i12 >> 2]; | |
99 HEAPF32[i7 >> 2] = +HEAPF32[i14 >> 2]; | |
100 HEAPF32[i8 >> 2] = 1.0; | |
101 } else if ((i16 | 0) == 6) { | |
102 d18 = +HEAPF32[i10 >> 2]; | |
103 d17 = +HEAPF32[i14 >> 2]; | |
104 HEAPF32[i5 >> 2] = +HEAPF32[i9 >> 2]; | |
105 HEAPF32[i6 >> 2] = d18; | |
106 HEAPF32[i7 >> 2] = d17; | |
107 HEAPF32[i8 >> 2] = 1.0; | |
108 } else if ((i16 | 0) == 5) { | |
109 d17 = +HEAPF32[i12 >> 2]; | |
110 d18 = +HEAPF32[i14 >> 2]; | |
111 HEAPF32[i5 >> 2] = +HEAPF32[i9 >> 2]; | |
112 HEAPF32[i6 >> 2] = d17; | |
113 HEAPF32[i7 >> 2] = d18; | |
114 HEAPF32[i8 >> 2] = 1.0; | |
115 } else if ((i16 | 0) == 3) { | |
116 d18 = +HEAPF32[i10 >> 2]; | |
117 d17 = +HEAPF32[i11 >> 2]; | |
118 HEAPF32[i5 >> 2] = +HEAPF32[i13 >> 2]; | |
119 HEAPF32[i6 >> 2] = d18; | |
120 HEAPF32[i7 >> 2] = d17; | |
121 HEAPF32[i8 >> 2] = 1.0; | |
122 } else if ((i16 | 0) == 0) { | |
123 HEAPF32[i5 >> 2] = +HEAPF32[i9 >> 2]; | |
124 HEAPF32[i6 >> 2] = +HEAPF32[i10 >> 2]; | |
125 HEAPF32[i7 >> 2] = +HEAPF32[i11 >> 2]; | |
126 HEAPF32[i8 >> 2] = 1.0; | |
127 } else if ((i16 | 0) == 2) { | |
128 d17 = +HEAPF32[i12 >> 2]; | |
129 d18 = +HEAPF32[i11 >> 2]; | |
130 HEAPF32[i5 >> 2] = +HEAPF32[i13 >> 2]; | |
131 HEAPF32[i6 >> 2] = d17; | |
132 HEAPF32[i7 >> 2] = d18; | |
133 HEAPF32[i8 >> 2] = 1.0; | |
134 } else if ((i16 | 0) == 7) { | |
135 d18 = +HEAPF32[i10 >> 2]; | |
136 d17 = +HEAPF32[i14 >> 2]; | |
137 HEAPF32[i5 >> 2] = +HEAPF32[i13 >> 2]; | |
138 HEAPF32[i6 >> 2] = d18; | |
139 HEAPF32[i7 >> 2] = d17; | |
140 HEAPF32[i8 >> 2] = 1.0; | |
141 } | |
142 i19 = __ZNK4Math7frustum8clipmaskERKNS_5pointE(i1, i4) | 0; | |
143 i20 = i19 & i2; | |
144 i21 = i19 | i15; | |
145 i19 = i16 + 1 | 0; | |
146 if ((i19 | 0) == 8) { | |
147 break; | |
148 } else { | |
149 i2 = i20; | |
150 i15 = i21; | |
151 i16 = i19; | |
152 } | |
153 } | |
154 if ((i21 | 0) == 0) { | |
155 i22 = 0; | |
156 STACKTOP = i3; | |
157 return i22 | 0; | |
158 } | |
159 i22 = (i20 | 0) == 0 ? 2 : 1; | |
160 STACKTOP = i3; | |
161 return i22 | 0; | |
162 } | |
163 | |
164 // ----------------------------------------------------------------- | |
165 | |
166 var STACKTOP = 0; | |
167 var HEAPF32 = new Float32Array(1000); | |
168 | |
169 for (var i = 0; i < HEAPF32.length; i++) { | |
170 HEAPF32[i] = 1.0; | |
171 } | |
172 | |
173 __ZNK4Math7frustum10clipstatusERKNS_4bboxE(0, 0); | |
174 __ZNK4Math7frustum10clipstatusERKNS_4bboxE(0, 0); | |
175 __ZNK4Math7frustum10clipstatusERKNS_4bboxE(0, 0); | |
176 %OptimizeFunctionOnNextCall(__ZNK4Math7frustum10clipstatusERKNS_4bboxE); | |
177 __ZNK4Math7frustum10clipstatusERKNS_4bboxE(0, 0); | |
178 })(); | |
OLD | NEW |