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

Side by Side Diff: test/mjsunit/es6/array-iterator-turbo.js

Issue 2484003002: [builtins] implement JSBuiltinReducer for ArrayIteratorNext() (Closed)
Patch Set: and fix mjsunit.status.. Created 4 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Flags: --turbo --turbo-escape --allow-natives-syntax
6
7 "use strict";
8
9 const kDeoptimized = 2;
10 const kTurbofanned = 7;
11 let global = this;
12 let tests = {
13 FastElementsKind() {
14 let runners = {
15 FAST_SMI_ELEMENTS(array) {
16 let sum = 0;
17 for (let x of array) sum += x;
18 return sum;
19 },
20
21 FAST_HOLEY_SMI_ELEMENTS(array) {
22 let sum = 0;
23 for (let x of array) {
24 if (x) sum += x;
25 }
26 return sum;
27 },
28
29 FAST_ELEMENTS(array) {
30 let ret = "";
31 for (let str of array) ret += `> ${str}`;
32 return ret;
33 },
34
35 FAST_HOLEY_ELEMENTS(array) {
36 let ret = "";
37 for (let str of array) ret += `> ${str}`;
38 return ret;
39 },
40
41 FAST_DOUBLE_ELEMENTS(array) {
42 let sum = 0.0;
43 for (let x of array) sum += x;
44 return sum;
45 },
46
47 FAST_HOLEY_DOUBLE_ELEMENTS(array) {
48 let sum = 0.0;
49 for (let x of array) {
50 if (x) sum += x;
51 }
52 return sum;
53 }
54 };
55
56 let tests = {
57 FAST_SMI_ELEMENTS: {
58 array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
59 expected: 55,
60 array2: [1, 2, 3],
61 expected2: 6
62 },
63 FAST_HOLEY_SMI_ELEMENTS: {
64 array: [1, , 3, , 5, , 7, , 9, ,],
65 expected: 25,
66 array2: [1, , 3],
67 expected2: 4
68 },
69 FAST_ELEMENTS: {
70 array: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"],
71 expected: "> a> b> c> d> e> f> g> h> i> j",
72 array2: ["a", "b", "c"],
73 expected2: "> a> b> c"
74 },
75 FAST_HOLEY_ELEMENTS: {
76 array: ["a", , "c", , "e", , "g", , "i", ,],
77 expected: "> a> undefined> c> undefined> e> undefined> g" +
78 "> undefined> i> undefined",
79 array2: ["a", , "c"],
80 expected2: "> a> undefined> c"
81 },
82 FAST_DOUBLE_ELEMENTS: {
83 array: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0],
84 expected: 5.5,
85 array2: [0.6, 0.4, 0.2],
86 expected2: 1.2
87 },
88 FAST_HOLEY_DOUBLE_ELEMENTS: {
89 array: [0.1, , 0.3, , 0.5, , 0.7, , 0.9, ,],
90 expected: 2.5,
91 array2: [0.1, , 0.3],
92 expected2: 0.4
93 }
94 };
95
96 for (let key of Object.keys(runners)) {
97 let fn = runners[key];
98 let { array, expected, array2, expected2 } = tests[key];
99
100 // Warmup:
101 fn(array);
102 fn(array);
103 %OptimizeFunctionOnNextCall(fn);
104 fn(array);
105
106 // TODO(bmeurer): FAST_HOLEY_DOUBLE_ELEMENTS maps generally deopt when
107 // a hole is encountered. Test should be fixed once that is corrected.
108 let status = /HOLEY_DOUBLE/.test(key) ? kDeoptimized : kTurbofanned;
109
110 assertEquals(status, %GetOptimizationStatus(fn), key);
111 assertEquals(expected, fn(array), key);
112 assertEquals(status, %GetOptimizationStatus(fn), key);
113
114 // Check no deopt when another arra with the same map is used
115 assertTrue(%HaveSameMap(array, array2), key);
116 assertEquals(status, %GetOptimizationStatus(fn), key);
117 assertEquals(expected2, fn(array2), key);
118
119 // CheckMaps bailout
120 let newArray = Object.defineProperty(
121 [1, 2, 3], 2, { enumerable: false, configurable: false,
122 get() { return 7; } });
123 fn(newArray);
124 assertEquals(kDeoptimized, %GetOptimizationStatus(fn), key);
125 }
126 },
127
128 TypedArrays() {
129 let tests = {
130 Uint8Array: {
131 array: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, -1, 256]),
132 expected: 291,
133 array2: new Uint8Array([1, 2, 3]),
134 expected2: 6
135 },
136
137 Int8Array: {
138 array: new Int8Array([1, 2, 3, 4, 5, 6, 7, 8, -129, 128]),
139 expected: 35,
140 array2: new Int8Array([1, 2, 3]),
141 expected2: 6
142 },
143
144 Uint16Array: {
145 array: new Uint16Array([1, 2, 3, 4, 5, 6, 7, 8, -1, 0x10000]),
146 expected: 65571,
147 array2: new Uint16Array([1, 2, 3]),
148 expected2: 6
149 },
150
151 Int16Array: {
152 array: new Int16Array([1, 2, 3, 4, 5, 6, 7, 8, -32769, 0x7FFF]),
153 expected: 65570,
154 array2: new Int16Array([1, 2, 3]),
155 expected2: 6
156 },
157
158 Uint32Array: {
159 array: new Uint32Array([1, 2, 3, 4, 5, 6, 7, 8, -1, 0x100000000]),
160 expected: 4294967331,
161 array2: new Uint32Array([1, 2, 3]),
162 expected2: 6
163 },
164
165 Int32Array: {
166 array: new Int32Array([1, 2, 3, 4, 5, 6, 7, 8,
167 -2147483649, 0x7FFFFFFF]),
168 expected: 4294967330,
169 array2: new Int32Array([1, 2, 3]),
170 expected2: 6
171 },
172
173 Float32Array: {
174 array: new Float32Array([9.5, 8.0, 7.0, 7.0, 5.0, 4.0, 3.0, 2.0]),
175 expected: 45.5,
176 array2: new Float32Array([10.5, 5.5, 1.5]),
177 expected2: 17.5
178 },
179
180 Float64Array: {
181 array: new Float64Array([9.5, 8.0, 7.0, 7.0, 5.0, 4.0, 3.0, 2.0]),
182 expected: 45.5,
183 array2: new Float64Array([10.5, 5.5, 1.5]),
184 expected2: 17.5
185 },
186
187 Uint8ClampedArray: {
188 array: new Uint8ClampedArray([4.3, 7.45632, 3.14, 4.61, 5.0004, 6.493,
189 7.12, 8, 1.7, 3.6]),
190 expected: 51,
191 array2: new Uint8ClampedArray([1, 2, 3]),
192 expected2: 6
193 }
194 };
195
196 for (let key of Object.keys(tests)) {
197 let test = tests[key];
198 let { array, expected, array2, expected2 } = test;
199
200 let sum = function(array) {
201 let ret = 0;
202 for (let x of array) ret += x;
203 return ret;
204 };
205
206 // Warmup
207 sum(array);
208 sum(array);
209 %OptimizeFunctionOnNextCall(sum);
210 assertEquals(expected, sum(array), key);
211
212 assertEquals(kTurbofanned, %GetOptimizationStatus(sum), key);
213
214 // Not deoptimized when called on typed array of same type / map
215 assertTrue(%HaveSameMap(array, array2));
216 assertEquals(expected2, sum(array2), key);
217 assertEquals(kTurbofanned, %GetOptimizationStatus(sum), key);
218
219 // Throw when detached
220 let clone = new array.constructor(array);
221 %ArrayBufferNeuter(clone.buffer);
222 assertThrows(() => sum(clone), TypeError);
223 }
224 }
225 };
226
227 for (let name of Object.keys(tests)) {
228 let test = tests[name];
229 test();
230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698