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

Side by Side Diff: test/mjsunit/harmony/simd.js

Issue 1239423004: SIMD.js: Update Float32x4 and tests to current spec. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Skip tests that haven't been updated to new spec. Created 5 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
« no previous file with comments | « test/cctest/test-heap-profiler.cc ('k') | test/mjsunit/messages.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --harmony-simd --harmony-tostring --harmony-reflect 5 // Flags: --harmony-simd --harmony-tostring --harmony-reflect
6 // Flags: --allow-natives-syntax --expose-natives-as natives --noalways-opt 6 // Flags: --allow-natives-syntax --expose-natives-as natives --noalways-opt
7 7
8 function lanesForType(typeName) { 8 function lanesForType(typeName) {
9 // The lane count follows the first 'x' in the type name, which begins with 9 // The lane count follows the first 'x' in the type name, which begins with
10 // 'float', 'int', or 'bool'. 10 // 'float', 'int', or 'bool'.
11 return Number.parseInt(typeName[typeName.indexOf('x') + 1]); 11 return Number.parseInt(typeName[typeName.indexOf('x') + 1]);
12 } 12 }
13 13
14 14
15 function isValidSimdString(string, value, type, lanes) { 15 function isValidSimdString(string, value, type, lanes) {
16 var simdFn = SIMD[type], 16 var simdFn = SIMD[type],
17 parseFn = 17 parseFn =
18 type.indexOf('float') === 0 ? Number.parseFloat : Number.parseInt, 18 type.indexOf('Float') === 0 ? Number.parseFloat : Number.parseInt,
19 indexOfOpenParen = string.indexOf('('); 19 indexOfOpenParen = string.indexOf('(');
20 // Check prefix for correct type name. 20 // Check prefix (e.g. SIMD.Float32x4.)
21 if (string.substr(0, indexOfOpenParen).toUpperCase() !== type.toUpperCase()) 21 if (string.substr(0, indexOfOpenParen) !== 'SIMD.' + type)
22 return false; 22 return false;
23 // Remove type name and open parenthesis. 23 // Remove type name (e.g. SIMD.Float32x4) and open parenthesis.
24 string = string.substr(indexOfOpenParen + 1); 24 string = string.substr(indexOfOpenParen + 1);
25 var laneStrings = string.split(','); 25 var laneStrings = string.split(',');
26 if (laneStrings.length !== lanes) 26 if (laneStrings.length !== lanes)
27 return false; 27 return false;
28 for (var i = 0; i < lanes; i++) { 28 for (var i = 0; i < lanes; i++) {
29 var fromString = parseFn(laneStrings[i]), 29 var fromString = parseFn(laneStrings[i]),
30 fromValue = simdFn.extractLane(value, i); 30 fromValue = simdFn.extractLane(value, i);
31 if (Math.abs(fromString - fromValue) > Number.EPSILON) 31 if (Math.abs(fromString - fromValue) > Number.EPSILON)
32 return false; 32 return false;
33 } 33 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 function TestConstructor(type, lanes) { 83 function TestConstructor(type, lanes) {
84 var simdFn = SIMD[type]; 84 var simdFn = SIMD[type];
85 assertFalse(Object === simdFn.prototype.constructor) 85 assertFalse(Object === simdFn.prototype.constructor)
86 assertFalse(simdFn === Object.prototype.constructor) 86 assertFalse(simdFn === Object.prototype.constructor)
87 assertSame(simdFn, simdFn.prototype.constructor) 87 assertSame(simdFn, simdFn.prototype.constructor)
88 88
89 values = [] 89 values = []
90 90
91 // The constructor expects values for all lanes. 91 // The constructor expects values for all lanes.
92 switch (type) { 92 switch (type) {
93 case 'float32x4': 93 case 'Float32x4':
94 // The constructor expects values for all lanes. 94 // The constructor expects values for all lanes.
95 assertThrows(function () { simdFn() }, TypeError) 95 assertThrows(function () { simdFn() }, TypeError)
96 assertThrows(function () { simdFn(0) }, TypeError) 96 assertThrows(function () { simdFn(0) }, TypeError)
97 assertThrows(function () { simdFn(0, 1) }, TypeError) 97 assertThrows(function () { simdFn(0, 1) }, TypeError)
98 assertThrows(function () { simdFn(0, 1, 2) }, TypeError) 98 assertThrows(function () { simdFn(0, 1, 2) }, TypeError)
99 99
100 values.push(simdFn(1, 2, 3, 4)) 100 values.push(simdFn(1, 2, 3, 4))
101 values.push(simdFn(1, 2, 3, 4)) // test structural equivalence 101 values.push(simdFn(1, 2, 3, 4)) // test structural equivalence
102 values.push(simdFn(-0, NaN, 0, 0.5)) 102 values.push(simdFn(-0, NaN, 0, 0.5))
103 values.push(simdFn(-0, NaN, 0, 0.5)) // test structural equivalence 103 values.push(simdFn(-0, NaN, 0, 0.5)) // test structural equivalence
104 values.push(simdFn(3, 2, 1, 0)) 104 values.push(simdFn(3, 2, 1, 0))
105 values.push(simdFn(0, 0, 0, 0)) 105 values.push(simdFn(0, 0, 0, 0))
106 break 106 break
107 } 107 }
108 for (var i in values) { 108 for (var i in values) {
109 assertSame(simdFn, values[i].__proto__.constructor) 109 assertSame(simdFn, values[i].__proto__.constructor)
110 assertSame(simdFn, Object(values[i]).__proto__.constructor) 110 assertSame(simdFn, Object(values[i]).__proto__.constructor)
111 assertSame(simdFn.prototype, values[i].__proto__) 111 assertSame(simdFn.prototype, values[i].__proto__)
112 assertSame(simdFn.prototype, Object(values[i]).__proto__) 112 assertSame(simdFn.prototype, Object(values[i]).__proto__)
113 } 113 }
114 } 114 }
115 115
116 116
117 function TestType(type, lanes) { 117 function TestType(type, lanes) {
118 var typeofString = type.charAt(0).toLowerCase() + type.slice(1);
118 for (var i in values) { 119 for (var i in values) {
119 assertEquals(type, typeof values[i]) 120 assertEquals(typeofString, typeof values[i])
120 assertTrue(typeof values[i] === type) 121 assertTrue(typeof values[i] === typeofString)
121 assertTrue(typeof Object(values[i]) === 'object') 122 assertTrue(typeof Object(values[i]) === 'object')
122 assertEquals(null, %_ClassOf(values[i])) 123 assertEquals(null, %_ClassOf(values[i]))
123 assertEquals("Float32x4", %_ClassOf(Object(values[i]))) 124 assertEquals(type, %_ClassOf(Object(values[i])))
124 } 125 }
125 } 126 }
126 127
127 128
128 function TestPrototype(type, lanes) { 129 function TestPrototype(type, lanes) {
129 var simdFn = SIMD[type]; 130 var simdFn = SIMD[type];
130 assertSame(Object.prototype, simdFn.prototype.__proto__) 131 assertSame(Object.prototype, simdFn.prototype.__proto__)
131 for (var i in values) { 132 for (var i in values) {
132 assertSame(simdFn.prototype, values[i].__proto__) 133 assertSame(simdFn.prototype, values[i].__proto__)
133 assertSame(simdFn.prototype, Object(values[i]).__proto__) 134 assertSame(simdFn.prototype, Object(values[i]).__proto__)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 assertFalse(others[j] == values[i]) 239 assertFalse(others[j] == values[i])
239 } 240 }
240 } 241 }
241 } 242 }
242 243
243 244
244 function TestSameValue(type, lanes) { 245 function TestSameValue(type, lanes) {
245 // SIMD value types. 246 // SIMD value types.
246 // All lanes checked. 247 // All lanes checked.
247 // TODO(bbudge): use loops to test lanes when replaceLane is defined. 248 // TODO(bbudge): use loops to test lanes when replaceLane is defined.
248 assertTrue(sameValueBoth(SIMD.float32x4(1, 2, 3, 4), 249 assertTrue(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
249 SIMD.float32x4(1, 2, 3, 4))); 250 SIMD.Float32x4(1, 2, 3, 4)));
250 assertFalse(sameValueBoth(SIMD.float32x4(1, 2, 3, 4), 251 assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
251 SIMD.float32x4(NaN, 2, 3, 4))); 252 SIMD.Float32x4(NaN, 2, 3, 4)));
252 assertFalse(sameValueBoth(SIMD.float32x4(1, 2, 3, 4), 253 assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
253 SIMD.float32x4(1, NaN, 3, 4))); 254 SIMD.Float32x4(1, NaN, 3, 4)));
254 assertFalse(sameValueBoth(SIMD.float32x4(1, 2, 3, 4), 255 assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
255 SIMD.float32x4(1, 2, NaN, 4))); 256 SIMD.Float32x4(1, 2, NaN, 4)));
256 assertFalse(sameValueBoth(SIMD.float32x4(1, 2, 3, 4), 257 assertFalse(sameValueBoth(SIMD.Float32x4(1, 2, 3, 4),
257 SIMD.float32x4(1, 2, 3, NaN))); 258 SIMD.Float32x4(1, 2, 3, NaN)));
258 // Special values. 259 // Special values.
259 // TODO(bbudge): use loops to test lanes when replaceLane is defined. 260 // TODO(bbudge): use loops to test lanes when replaceLane is defined.
260 assertTrue(sameValueBoth(SIMD.float32x4(NaN, 2, 3, 4), 261 assertTrue(sameValueBoth(SIMD.Float32x4(NaN, 2, 3, 4),
261 SIMD.float32x4(NaN, 2, 3, 4))); 262 SIMD.Float32x4(NaN, 2, 3, 4)));
262 assertTrue(sameValueBoth(SIMD.float32x4(+0, 2, 3, 4), 263 assertTrue(sameValueBoth(SIMD.Float32x4(+0, 2, 3, 4),
263 SIMD.float32x4(+0, 2, 3, 4))); 264 SIMD.Float32x4(+0, 2, 3, 4)));
264 assertTrue(sameValueBoth(SIMD.float32x4(-0, 2, 3, 4), 265 assertTrue(sameValueBoth(SIMD.Float32x4(-0, 2, 3, 4),
265 SIMD.float32x4(-0, 2, 3, 4))); 266 SIMD.Float32x4(-0, 2, 3, 4)));
266 assertTrue(sameValueZeroOnly(SIMD.float32x4(+0, 2, 3, 4), 267 assertTrue(sameValueZeroOnly(SIMD.Float32x4(+0, 2, 3, 4),
267 SIMD.float32x4(-0, 2, 3, 4))); 268 SIMD.Float32x4(-0, 2, 3, 4)));
268 assertTrue(sameValueZeroOnly(SIMD.float32x4(-0, 2, 3, 4), 269 assertTrue(sameValueZeroOnly(SIMD.Float32x4(-0, 2, 3, 4),
269 SIMD.float32x4(+0, 2, 3, 4))); 270 SIMD.Float32x4(+0, 2, 3, 4)));
270 } 271 }
271 272
272 273
273 function TestComparison(type, lanes) { 274 function TestComparison(type, lanes) {
274 var a = values[0], b = values[1]; 275 var a = values[0], b = values[1];
275 276
276 function lt() { a < b; } 277 function lt() { a < b; }
277 function gt() { a > b; } 278 function gt() { a > b; }
278 function le() { a <= b; } 279 function le() { a <= b; }
279 function ge() { a >= b; } 280 function ge() { a >= b; }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 function() { Reflect.apply(values[i]); }, TypeError); 376 function() { Reflect.apply(values[i]); }, TypeError);
376 assertThrows( 377 assertThrows(
377 function() { Reflect.apply(noopStrict, R, values[i]); }, TypeError); 378 function() { Reflect.apply(noopStrict, R, values[i]); }, TypeError);
378 assertThrows( 379 assertThrows(
379 function() { Reflect.apply(noop, R, values[i]); }, TypeError); 380 function() { Reflect.apply(noop, R, values[i]); }, TypeError);
380 } 381 }
381 } 382 }
382 383
383 384
384 function TestSIMDTypes() { 385 function TestSIMDTypes() {
385 var types = [ 'float32x4' ]; 386 var types = [ 'Float32x4' ];
386 for (var i = 0; i < types.length; ++i) { 387 for (var i = 0; i < types.length; ++i) {
387 var type = types[i], 388 var type = types[i],
388 lanes = lanesForType(type); 389 lanes = lanesForType(type);
389 TestConstructor(type, lanes); 390 TestConstructor(type, lanes);
390 TestType(type, lanes); 391 TestType(type, lanes);
391 TestPrototype(type, lanes); 392 TestPrototype(type, lanes);
392 TestValueOf(type, lanes); 393 TestValueOf(type, lanes);
393 TestGet(type, lanes); 394 TestGet(type, lanes);
394 TestToBoolean(type, lanes); 395 TestToBoolean(type, lanes);
395 TestToString(type, lanes); 396 TestToString(type, lanes);
396 TestToNumber(type, lanes); 397 TestToNumber(type, lanes);
397 TestEquality(type, lanes); 398 TestEquality(type, lanes);
398 TestSameValue(type, lanes); 399 TestSameValue(type, lanes);
399 TestComparison(type, lanes); 400 TestComparison(type, lanes);
400 TestCall(type, lanes); 401 TestCall(type, lanes);
401 TestAsSetKey(type, lanes, new Set); 402 TestAsSetKey(type, lanes, new Set);
402 TestAsSetKey(type, lanes, new WeakSet); 403 TestAsSetKey(type, lanes, new WeakSet);
403 TestAsMapKey(type, lanes, new Map); 404 TestAsMapKey(type, lanes, new Map);
404 TestAsMapKey(type, lanes, new WeakMap); 405 TestAsMapKey(type, lanes, new WeakMap);
405 TestReflectApply(type); 406 TestReflectApply(type);
406 } 407 }
407 } 408 }
408 TestSIMDTypes(); 409 TestSIMDTypes();
OLDNEW
« no previous file with comments | « test/cctest/test-heap-profiler.cc ('k') | test/mjsunit/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698