OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2012 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 // Test uint32 handing in optimized frames. | |
31 | |
32 var K1 = 0x7fffffff; | |
33 var K2 = 0xffffffff; | |
34 | |
35 var uint32_array = new Uint32Array(2); | |
36 uint32_array[0] = K1; | |
37 uint32_array[1] = K2; | |
38 | |
39 function ChangeI2T(arr, i) { | |
40 return uint32_array[i]; | |
41 } | |
42 | |
43 assertEquals(K1, ChangeI2T(uint32_array, 0)); | |
44 assertEquals(K2, ChangeI2T(uint32_array, 1)); | |
45 %OptimizeFunctionOnNextCall(ChangeI2T); | |
46 assertEquals(K1, ChangeI2T(uint32_array, 0)); | |
47 assertEquals(K2, ChangeI2T(uint32_array, 1)); | |
48 | |
49 function SideEffect() { | |
50 with ({}) { } // not inlinable | |
51 } | |
52 | |
53 function Deopt(obj, arr, i) { | |
54 var x = arr[i]; | |
55 SideEffect(); // x will be used by HSimulate. | |
56 obj.x; | |
57 return x; | |
58 } | |
59 | |
60 assertEquals(K1, Deopt({x: 0}, uint32_array, 0)); | |
61 assertEquals(K2, Deopt({x: 0}, uint32_array, 1)); | |
62 %OptimizeFunctionOnNextCall(Deopt); | |
63 assertEquals(K2, Deopt({}, uint32_array, 1)); | |
64 | |
65 function ChangeI2D(arr) { | |
66 // This addition will have a double type feedback so ChangeI2D will | |
67 // be generated for its operands. | |
68 return arr[0] + arr[1]; | |
69 } | |
70 | |
71 assertEquals(K1 + K2, ChangeI2D(uint32_array)); | |
72 assertEquals(K1 + K2, ChangeI2D(uint32_array)); | |
73 %OptimizeFunctionOnNextCall(ChangeI2D); | |
74 assertEquals(K1 + K2, ChangeI2D(uint32_array)); | |
75 | |
76 function ShrShr(val) { | |
77 return (val >>> 0) >>> 1; | |
78 } | |
79 | |
80 assertEquals(K1, ShrShr(K2 | 0)); | |
81 assertEquals(K1, ShrShr(K2 | 0)); | |
82 %OptimizeFunctionOnNextCall(ShrShr); | |
83 assertEquals(K1, ShrShr(K2 | 0)); | |
84 | |
85 function SarShr(val) { | |
86 return val >> (-2 >>> 0); | |
87 } | |
88 | |
89 var K3 = 0x80000000; | |
90 assertEquals(-2, SarShr(K3 | 0)); | |
91 assertEquals(-2, SarShr(K3 | 0)); | |
92 %OptimizeFunctionOnNextCall(SarShr); | |
93 assertEquals(-2, SarShr(K3 | 0)); | |
94 | |
95 function Uint32Phi(a, b, c) { | |
96 var i = a ? (b >>> 0) : (c >>> 0); | |
97 return (i | 0); | |
98 } | |
99 | |
100 var K4 = 0x80000001; | |
101 assertEquals(K3 | 0, Uint32Phi(true, K3, K4)); | |
102 assertEquals(K4 | 0, Uint32Phi(false, K3, K4)); | |
103 assertEquals(K3 | 0, Uint32Phi(true, K3, K4)); | |
104 assertEquals(K4 | 0, Uint32Phi(false, K3, K4)); | |
105 %OptimizeFunctionOnNextCall(Uint32Phi); | |
106 assertEquals(K3 | 0, Uint32Phi(true, K3, K4)); | |
107 assertEquals(K4 | 0, Uint32Phi(false, K3, K4)); | |
108 | |
109 function NonUint32Phi(a, b, c) { | |
110 var i = a ? (b >>> 0) : c; | |
111 return (i | 0); | |
112 } | |
113 | |
114 assertEquals(K3 | 0, NonUint32Phi(true, K3, K4)); | |
115 assertEquals(K4 | 0, NonUint32Phi(false, K3, K4)); | |
116 assertEquals(K3 | 0, NonUint32Phi(true, K3, K4)); | |
117 assertEquals(K4 | 0, NonUint32Phi(false, K3, K4)); | |
118 %OptimizeFunctionOnNextCall(NonUint32Phi); | |
119 assertEquals(K3 | 0, NonUint32Phi(true, K3, K4)); | |
120 assertEquals(K4 | 0, NonUint32Phi(false, K3, K4)); | |
danno
2012/08/21 13:55:26
Please add tests for phi usages of phis.
| |
OLD | NEW |