OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 assertEquals(2.5, get(array, 0)); | 80 assertEquals(2.5, get(array, 0)); |
81 assertEquals(3.5, get(array, 1)); | 81 assertEquals(3.5, get(array, 1)); |
82 } | 82 } |
83 | 83 |
84 // Test loads and stores. | 84 // Test loads and stores. |
85 types = [Array, Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, | 85 types = [Array, Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, |
86 Uint32Array, PixelArray, Float32Array, Float64Array]; | 86 Uint32Array, PixelArray, Float32Array, Float64Array]; |
87 | 87 |
88 test_result_nan = [NaN, 0, 0, 0, 0, 0, 0, 0, NaN, NaN]; | 88 test_result_nan = [NaN, 0, 0, 0, 0, 0, 0, 0, NaN, NaN]; |
89 test_result_low_int = [-1, -1, 255, -1, 65535, -1, 0xFFFFFFFF, 0, -1, -1]; | 89 test_result_low_int = [-1, -1, 255, -1, 65535, -1, 0xFFFFFFFF, 0, -1, -1]; |
| 90 test_result_low_double = [-1.25, -1, 255, -1, 65535, -1, 0xFFFFFFFF, 0, -1.25, -
1.25]; |
90 test_result_middle = [253.75, -3, 253, 253, 253, 253, 253, 254, 253.75, 253.75]; | 91 test_result_middle = [253.75, -3, 253, 253, 253, 253, 253, 254, 253.75, 253.75]; |
91 test_result_high_int = [256, 0, 0, 256, 256, 256, 256, 255, 256, 256]; | 92 test_result_high_int = [256, 0, 0, 256, 256, 256, 256, 255, 256, 256]; |
| 93 test_result_high_double = [256.25, 0, 0, 256, 256, 256, 256, 255, 256.25, 256.25
]; |
92 | 94 |
93 const kElementCount = 40; | 95 const kElementCount = 40; |
94 | 96 |
95 function test_load(array, sum) { | 97 function test_load(array, sum) { |
96 for (var i = 0; i < kElementCount; i++) { | 98 for (var i = 0; i < kElementCount; i++) { |
97 sum += array[i]; | 99 sum += array[i]; |
98 } | 100 } |
99 return sum; | 101 return sum; |
100 } | 102 } |
101 | 103 |
(...skipping 11 matching lines...) Expand all Loading... |
113 return sum; | 115 return sum; |
114 } | 116 } |
115 | 117 |
116 function test_store_const_key(array, sum) { | 118 function test_store_const_key(array, sum) { |
117 sum += array[0] = 1; | 119 sum += array[0] = 1; |
118 sum += array[1] = 2; | 120 sum += array[1] = 2; |
119 sum += array[2] = 3; | 121 sum += array[2] = 3; |
120 return sum; | 122 return sum; |
121 } | 123 } |
122 | 124 |
| 125 function zero() { |
| 126 return 0.0; |
| 127 } |
123 | 128 |
124 function test_store_middle_double(array, sum) { | 129 function test_store_middle_tagged(array, sum) { |
125 array[0] = 253.75; | 130 array[0] = 253.75; |
126 return array[0]; | 131 return array[0]; |
127 } | 132 } |
128 | 133 |
129 | 134 function test_store_high_tagged(array, sum) { |
130 function test_store_high_double(array, sum) { | |
131 array[0] = 256.25; | 135 array[0] = 256.25; |
132 return array[0]; | 136 return array[0]; |
133 } | 137 } |
134 | 138 |
| 139 function test_store_middle_double(array, sum) { |
| 140 array[0] = 253.75 + zero(); // + forces double type feedback |
| 141 return array[0]; |
| 142 } |
| 143 |
| 144 function test_store_high_double(array, sum) { |
| 145 array[0] = 256.25 + zero(); // + forces double type feedback |
| 146 return array[0]; |
| 147 } |
| 148 |
135 function test_store_high_double(array, sum) { | 149 function test_store_high_double(array, sum) { |
136 array[0] = 256.25; | 150 array[0] = 256.25; |
137 return array[0]; | 151 return array[0]; |
138 } | 152 } |
139 | 153 |
140 function test_store_low_int(array, sum) { | 154 function test_store_low_int(array, sum) { |
141 array[0] = -1; | 155 array[0] = -1; |
142 return array[0]; | 156 return array[0]; |
143 } | 157 } |
144 | 158 |
| 159 function test_store_low_tagged(array, sum) { |
| 160 array[0] = -1.25; |
| 161 return array[0]; |
| 162 } |
| 163 |
| 164 function test_store_low_double(array, sum) { |
| 165 array[0] = -1.25 + zero(); // + forces double type feedback |
| 166 return array[0]; |
| 167 } |
| 168 |
145 function test_store_high_int(array, sum) { | 169 function test_store_high_int(array, sum) { |
146 array[0] = 256; | 170 array[0] = 256; |
147 return array[0]; | 171 return array[0]; |
148 } | 172 } |
149 | 173 |
150 function test_store_nan(array, sum) { | 174 function test_store_nan(array, sum) { |
151 array[0] = NaN; | 175 array[0] = NaN; |
152 return array[0]; | 176 return array[0]; |
153 } | 177 } |
154 | 178 |
155 const kRuns = 10; | 179 const kRuns = 10; |
156 | 180 |
157 function run_test(test_func, array, expected_result) { | 181 function run_test(test_func, array, expected_result) { |
158 for (var i = 0; i < 5; i++) test_func(array, 0); | 182 for (var i = 0; i < 5; i++) test_func(array, 0); |
159 %OptimizeFunctionOnNextCall(test_func); | 183 %OptimizeFunctionOnNextCall(test_func); |
160 var sum = 0; | 184 var sum = 0; |
161 for (var i = 0; i < kRuns; i++) { | 185 for (var i = 0; i < kRuns; i++) { |
162 sum = test_func(array, sum); | 186 sum = test_func(array, sum); |
163 } | 187 } |
164 assertEquals(expected_result, sum); | 188 assertEquals(expected_result, sum); |
165 %DeoptimizeFunction(test_func); | 189 %DeoptimizeFunction(test_func); |
166 gc(); // Makes V8 forget about type information for test_func. | 190 gc(); // Makes V8 forget about type information for test_func. |
167 } | 191 } |
168 | 192 |
169 for (var t = 0; t < types.length; t++) { | 193 for (var t = 0; t < types.length; t++) { |
170 var type = types[t]; | 194 var type = types[t]; |
171 print ("type = " + t); | |
172 var a = new type(kElementCount); | 195 var a = new type(kElementCount); |
173 for (var i = 0; i < kElementCount; i++) { | 196 for (var i = 0; i < kElementCount; i++) { |
174 a[i] = i; | 197 a[i] = i; |
175 } | 198 } |
176 | 199 |
177 // Run test functions defined above. | 200 // Run test functions defined above. |
178 run_test(test_load, a, 780 * kRuns); | 201 run_test(test_load, a, 780 * kRuns); |
179 run_test(test_load_const_key, a, 3 * kRuns); | 202 run_test(test_load_const_key, a, 3 * kRuns); |
180 run_test(test_store, a, 820 * kRuns); | 203 run_test(test_store, a, 820 * kRuns); |
181 run_test(test_store_const_key, a, 6 * kRuns); | 204 run_test(test_store_const_key, a, 6 * kRuns); |
182 run_test(test_store_low_int, a, test_result_low_int[t]); | 205 run_test(test_store_low_int, a, test_result_low_int[t]); |
| 206 run_test(test_store_low_double, a, test_result_low_double[t]); |
| 207 run_test(test_store_low_tagged, a, test_result_low_double[t]); |
183 run_test(test_store_high_int, a, test_result_high_int[t]); | 208 run_test(test_store_high_int, a, test_result_high_int[t]); |
184 run_test(test_store_nan, a, test_result_nan[t]); | 209 run_test(test_store_nan, a, test_result_nan[t]); |
185 run_test(test_store_middle_double, a, test_result_middle[t]); | 210 run_test(test_store_middle_double, a, test_result_middle[t]); |
| 211 run_test(test_store_middle_tagged, a, test_result_middle[t]); |
| 212 run_test(test_store_high_double, a, test_result_high_double[t]); |
| 213 run_test(test_store_high_tagged, a, test_result_high_double[t]); |
186 | 214 |
187 // Test the correct behavior of the |length| property (which is read-only). | 215 // Test the correct behavior of the |length| property (which is read-only). |
188 if (t != 0) { | 216 if (t != 0) { |
189 assertEquals(kElementCount, a.length); | 217 assertEquals(kElementCount, a.length); |
190 a.length = 2; | 218 a.length = 2; |
191 assertEquals(kElementCount, a.length); | 219 assertEquals(kElementCount, a.length); |
192 assertTrue(delete a.length); | 220 assertTrue(delete a.length); |
193 a.length = 2; | 221 a.length = 2; |
194 assertEquals(2, a.length); | 222 assertEquals(2, a.length); |
195 } | 223 } |
196 | 224 |
197 function array_load_set_smi_check(a) { | 225 function array_load_set_smi_check(a) { |
198 return a[0] = a[0] = 1; | 226 return a[0] = a[0] = 1; |
199 } | 227 } |
200 | 228 |
201 array_load_set_smi_check(a); | 229 array_load_set_smi_check(a); |
202 array_load_set_smi_check(0); | 230 array_load_set_smi_check(0); |
203 | 231 |
204 function array_load_set_smi_check2(a) { | 232 function array_load_set_smi_check2(a) { |
205 return a[0] = a[0] = 1; | 233 return a[0] = a[0] = 1; |
206 } | 234 } |
207 | 235 |
208 array_load_set_smi_check2(a); | 236 array_load_set_smi_check2(a); |
209 %OptimizeFunctionOnNextCall(array_load_set_smi_check2); | 237 %OptimizeFunctionOnNextCall(array_load_set_smi_check2); |
210 array_load_set_smi_check2(a); | 238 array_load_set_smi_check2(a); |
211 array_load_set_smi_check2(0); | 239 array_load_set_smi_check2(0); |
212 %DeoptimizeFunction(array_load_set_smi_check2); | 240 %DeoptimizeFunction(array_load_set_smi_check2); |
213 gc(); // Makes V8 forget about type information for array_load_set_smi_check. | 241 gc(); // Makes V8 forget about type information for array_load_set_smi_check. |
214 } | 242 } |
OLD | NEW |