Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: test/mjsunit/unbox-double-arrays.js

Issue 7307030: Implement ICs for FastDoubleArray loads and stores (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix asserts Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Test dictionary -> double elements -> dictionary elements round trip 28 // Test dictionary -> double elements -> dictionary elements round trip
29 29
30 var foo = new Array(500000); 30 // Flags: --allow-natives-syntax --unbox-double-arrays
31 31 var large_array_size = 500000;
32 function func(a) { 32 var approx_dict_to_elements_threshold = 69000;
33 for (var i= 0; i < 100000; ++i ) { 33
34 a[i] = i+0.5; 34 function expected_array_value(i) {
35 if ((i % 2) == 0) {
36 return i;
37 } else {
38 return i + 0.5;
35 } 39 }
36 } 40 }
37 41
38 func(foo); 42 function force_to_fast_double_array(a) {
39 43 for (var i= 0; i < approx_dict_to_elements_threshold; ++i ) {
40 for (var i= 0; i < 100000; i += 500 ) { 44 a[i] = expected_array_value(i);
41 assertEquals(i+0.5, foo[i]); 45 }
46 assertTrue(%HasFastDoubleElements(a));
42 } 47 }
43 48
44 delete foo[5]; 49 function testOneArrayType(allocator) {
45 // Don't use assertEquals for comparison to undefined due to 50 var large_array = new allocator(500000);
46 assertTrue(undefined === foo[5]); 51 force_to_fast_double_array(large_array);
47 assertTrue(undefined === foo[500000-1]); 52
48 assertTrue(undefined === foo[-1]); 53 for (var i= 0; i < approx_dict_to_elements_threshold; i += 501 ) {
49 assertEquals(500000, foo.length); 54 assertEquals(expected_array_value(i), large_array[i]);
50 55 }
51 // Cause the array to grow beyond it's JSArray length. This will double the 56
52 // size of the capacity and force the array into "slow" dictionary case. 57 function get_test_various_loads() {
53 foo[500001] = 50; 58 return function test_various_loads(a, value_5, value_6, value_7) {
54 assertEquals(50, foo[500001]); 59 assertTrue(%HasFastDoubleElements(a));
55 assertEquals(500002, foo.length); 60 assertEquals(value_5, a[5]);
56 assertTrue(undefined === foo[5]) 61 assertEquals(value_6, a[6]);
57 assertTrue(undefined === foo[500000-1]) 62 assertEquals(value_7, a[7]);
58 assertTrue(undefined === foo[-1]) 63 assertEquals(undefined, a[large_array_size-1]);
59 assertEquals(500002, foo.length); 64 assertEquals(undefined, a[-1]);
60 65 assertEquals(large_array_size, a.length);
61 // Test dictionary -> double elements -> fast elements. 66 assertTrue(%HasFastDoubleElements(a));
62 67 }
63 var foo2 = new Array(500000); 68 }
64 func(foo2); 69
65 delete foo2[5]; 70 function get_test_various_stores() {
66 71 return function test_various_stores(a, value_5, value_6, value_7) {
67 // Convert back to fast elements and make sure the contents of the array are 72 assertTrue(%HasFastDoubleElements(a));
68 // unchanged. 73 a[5] = value_5;
69 foo2[25] = new Object(); 74 a[6] = value_6;
70 for (var i= 0; i < 100000; i += 500 ) { 75 a[7] = value_7;
71 if (i != 25 && i != 5) { 76 assertTrue(%HasFastDoubleElements(a));
72 assertEquals(i+0.5, foo2[i]); 77 }
73 } 78 }
79
80 // Run tests up to three times to make sure both runtime and IC implementation
81 // (premonomorphic and monomorphic) of KeyedLoad access works in various
82 // cases.
83
84 // Test double and integer values
85 test_various_loads = get_test_various_loads();
86 test_various_loads(large_array,
87 expected_array_value(5),
88 expected_array_value(6),
89 expected_array_value(7));
90 test_various_loads(large_array,
91 expected_array_value(5),
92 expected_array_value(6),
93 expected_array_value(7));
94 test_various_loads(large_array,
95 expected_array_value(5),
96 expected_array_value(6),
97 expected_array_value(7));
98
99 // Test NaN values
100 test_various_stores = get_test_various_stores();
101 test_various_stores(large_array, NaN, -NaN, expected_array_value(7));
102
103 test_various_loads(large_array,
104 NaN,
105 -NaN,
106 expected_array_value(7));
107 test_various_loads(large_array,
108 NaN,
109 -NaN,
110 expected_array_value(7));
111 test_various_loads(large_array,
112 NaN,
113 -NaN,
114 expected_array_value(7));
115
116 // Test Infinity values
117 test_various_stores = get_test_various_stores();
118 test_various_stores(large_array,
119 Infinity,
120 -Infinity,
121 expected_array_value(7));
122
123 test_various_loads(large_array,
124 Infinity,
125 -Infinity,
126 expected_array_value(7));
127 test_various_loads(large_array,
128 Infinity,
129 -Infinity,
130 expected_array_value(7));
131 test_various_loads(large_array,
132 Infinity,
133 -Infinity,
134 expected_array_value(7));
135
136 // Test the hole for the default runtime implementation.
137 delete large_array[5];
138 delete large_array[6];
139 test_various_loads = get_test_various_loads();
140 test_various_loads(large_array,
141 undefined,
142 undefined,
143 expected_array_value(7));
144
145 // Test the keyed load IC implementation when the value is the hole.
146 test_various_loads = get_test_various_loads();
147 test_various_stores(large_array,
148 expected_array_value(5),
149 expected_array_value(6),
150 expected_array_value(7));
151 test_various_loads(large_array,
152 expected_array_value(5),
153 expected_array_value(6),
154 expected_array_value(7));
155 test_various_loads(large_array,
156 expected_array_value(5),
157 expected_array_value(6),
158 expected_array_value(7));
159 delete large_array[5];
160 delete large_array[6];
161 test_various_loads(large_array,
162 undefined,
163 undefined,
164 expected_array_value(7));
165 test_various_loads(large_array,
166 undefined,
167 undefined,
168 expected_array_value(7));
169
170 // Test both runtime and IC variants of double array stores for normal
171 // values (double and integer).
172 test_various_stores = get_test_various_stores();
173 test_various_stores(large_array,
174 expected_array_value(4),
175 expected_array_value(5),
176 expected_array_value(6));
177 test_various_loads(large_array,
178 expected_array_value(4),
179 expected_array_value(5),
180 expected_array_value(6));
181 test_various_stores(large_array,
182 expected_array_value(5),
183 expected_array_value(6),
184 expected_array_value(7));
185 test_various_loads(large_array,
186 expected_array_value(5),
187 expected_array_value(6),
188 expected_array_value(7));
189
190 // Test stores of NaN to make sure they don't get mistaken for the
191 // hole. Test both runtime and IC implementation.
192 test_various_stores = get_test_various_stores();
193 test_various_stores(large_array,
194 NaN,
195 -NaN,
196 expected_array_value(6));
197 test_various_loads(large_array,
198 NaN,
199 -NaN,
200 expected_array_value(6));
201 test_various_stores(large_array,
202 expected_array_value(5),
203 expected_array_value(6),
204 expected_array_value(7));
205 test_various_loads(large_array,
206 expected_array_value(5),
207 expected_array_value(6),
208 expected_array_value(7));
209 test_various_stores(large_array,
210 NaN,
211 -NaN,
212 expected_array_value(7));
213 test_various_loads(large_array,
214 NaN,
215 -NaN,
216 expected_array_value(7));
217
218 // Test stores of Infinity to make sure they don't get mistaken for the
219 // hole. Test both runtime and IC implementation.
220 test_various_stores = get_test_various_stores();
221 test_various_stores(large_array,
222 Infinity,
223 -Infinity,
224 expected_array_value(6));
225 test_various_loads(large_array,
226 Infinity,
227 -Infinity,
228 expected_array_value(6));
229 test_various_stores(large_array,
230 expected_array_value(5),
231 expected_array_value(6),
232 expected_array_value(7));
233 test_various_loads(large_array,
234 expected_array_value(5),
235 expected_array_value(6),
236 expected_array_value(7));
237 test_various_stores(large_array,
238 Infinity,
239 -Infinity,
240 expected_array_value(7));
241 test_various_loads(large_array,
242 Infinity,
243 -Infinity,
244 expected_array_value(7));
245
246 delete large_array[5];
247
248 // Make sure that we haven't converted from fast double.
249 assertTrue(%HasFastDoubleElements(large_array));
250 // Cause the array to grow beyond it's JSArray length. This will double the
251 // size of the capacity and force the array into "slow" dictionary case.
252 large_array[large_array_size+1] = 50;
253 assertTrue(%HasDictionaryElements(large_array));
254 assertEquals(50, large_array[large_array_size+1]);
255 assertEquals(large_array_size+2, large_array.length);
256 assertEquals(undefined, large_array[5]);
257 assertEquals(undefined, large_array[large_array_size-1]);
258 assertEquals(undefined, large_array[-1]);
259 assertEquals(large_array_size+2, large_array.length);
260
261 // Test dictionary -> double elements -> fast elements.
262 var large_array2 = new allocator(large_array_size);
263 force_to_fast_double_array(large_array2);
264 delete large_array2[5];
265
266 // Convert back to fast elements and make sure the contents of the array are
267 // unchanged.
268 large_array2[25] = new Object();
269 assertTrue(%HasFastElements(large_array2));
270 for (var i= 0; i < approx_dict_to_elements_threshold; i += 500 ) {
271 if (i != 25 && i != 5) {
272 assertEquals(expected_array_value(i), large_array2[i]);
273 }
274 }
275 assertEquals(undefined, large_array2[5])
276 assertEquals(undefined, large_array2[large_array_size-1])
277 assertEquals(undefined, large_array2[-1])
278 assertEquals(large_array_size, large_array2.length);
74 } 279 }
75 assertTrue(undefined === foo2[5]) 280
76 assertTrue(undefined === foo2[500000-1]) 281 testOneArrayType(Array);
77 assertTrue(undefined === foo2[-1])
78 assertEquals(500000, foo2.length);
OLDNEW
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698