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

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

Issue 90643003: Experimental implementation: Exposing SIMD instructions into JavaScript Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years 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 | « test/mjsunit/simd/float32x4.js ('k') | test/mjsunit/simd/osr.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 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: --simd_object --allow-natives-syntax
29
30 function testConstructor() {
31 var u4 = int32x4(1, 2, 3, 4);
32 var new_u4 = new int32x4(1, 2, 3, 4);
33 assertEquals(1, u4.x);
34 assertEquals(2, u4.y);
35 assertEquals(3, u4.z);
36 assertEquals(4, u4.w);
37 assertEquals(1, new_u4.x);
38 assertEquals(2, new_u4.y);
39 assertEquals(3, new_u4.z);
40 assertEquals(4, new_u4.w);
41 }
42
43 testConstructor();
44
45 function testBoolConstructor() {
46 var u4 = int32x4.bool(true, false, true, false);
47 assertEquals(-1, u4.x);
48 assertEquals(0, u4.y);
49 assertEquals(-1, u4.z);
50 assertEquals(0, u4.w);
51
52 var new_u4 = int32x4.bool(false, true, false, true);
53 assertEquals(0, new_u4.x);
54 assertEquals(-1, new_u4.y);
55 assertEquals(0, new_u4.z);
56 assertEquals(-1, new_u4.w);
57 }
58
59 testBoolConstructor();
60 testBoolConstructor();
61 %OptimizeFunctionOnNextCall(testBoolConstructor);
62 testBoolConstructor();
63
64 function testSplatConstructor() {
65 var u4 = int32x4.splat(4);
66 assertEquals(4, u4.x);
67 assertEquals(4, u4.y);
68 assertEquals(4, u4.z);
69 assertEquals(4, u4.w);
70 }
71
72 testSplatConstructor();
73 testSplatConstructor();
74 %OptimizeFunctionOnNextCall(testSplatConstructor);
75 testSplatConstructor();
76
77 function testTypeof() {
78 var u4 = int32x4(1, 2, 3, 4);
79 assertEquals(typeof(u4), "int32x4");
80
81 var new_u4 = new int32x4(1, 2, 3, 4);
82 assertEquals(typeof(new_u4), "object");
83 assertEquals(typeof(new_u4.valueOf()), "int32x4");
84 assertEquals(Object.prototype.toString.call(new_u4), "[object int32x4]");
85 }
86
87 testTypeof();
88
89 function testSignMaskGetter() {
90 var a = int32x4(0x80000000 - 0xFFFFFFFF - 1, 0x7000000, -1, 0x0);
91 assertEquals(0x5, a.signMask);
92 var b = int32x4(0x0, 0x0, 0x0, 0x0);
93 assertEquals(0x0, b.signMask);
94 var c = int32x4(-1, -1, -1, -1);
95 assertEquals(0xf, c.signMask);
96 }
97
98 testSignMaskGetter();
99 testSignMaskGetter();
100 %OptimizeFunctionOnNextCall(testSignMaskGetter);
101 testSignMaskGetter();
102
103
104 function testSIMDAnd() {
105 var m = int32x4(0xAAAAAAAA - 0xFFFFFFFF - 1, 0xAAAAAAAA - 0xFFFFFFFF - 1,
106 0xAAAAAAAA - 0xFFFFFFFF - 1, 0xAAAAAAAA - 0xFFFFFFFF - 1);
107 var n = int32x4(0x55555555, 0x55555555, 0x55555555, 0x55555555);
108 assertEquals(0xAAAAAAAA - 0xFFFFFFFF - 1, m.x);
109 assertEquals(0xAAAAAAAA - 0xFFFFFFFF - 1, m.y);
110 assertEquals(0xAAAAAAAA - 0xFFFFFFFF - 1, m.z);
111 assertEquals(0xAAAAAAAA - 0xFFFFFFFF - 1, m.w);
112 assertEquals(0x55555555, n.x);
113 assertEquals(0x55555555, n.y);
114 assertEquals(0x55555555, n.z);
115 assertEquals(0x55555555, n.w);
116 assertEquals(true, n.flagX);
117 assertEquals(true, n.flagY);
118 assertEquals(true, n.flagZ);
119 assertEquals(true, n.flagW);
120 o = SIMD.int32x4.and(m,n); // and
121 assertEquals(0x0, o.x);
122 assertEquals(0x0, o.y);
123 assertEquals(0x0, o.z);
124 assertEquals(0x0, o.w);
125 assertEquals(false, o.flagX);
126 assertEquals(false, o.flagY);
127 assertEquals(false, o.flagZ);
128 assertEquals(false, o.flagW);
129 }
130
131 testSIMDAnd();
132 testSIMDAnd();
133 %OptimizeFunctionOnNextCall(testSIMDAnd);
134 testSIMDAnd();
135
136 function testSIMDOr() {
137 var m = int32x4(0xAAAAAAAA - 0xFFFFFFFF - 1, 0xAAAAAAAA - 0xFFFFFFFF - 1,
138 0xAAAAAAAA - 0xFFFFFFFF - 1, 0xAAAAAAAA - 0xFFFFFFFF - 1);
139 var n = int32x4(0x55555555, 0x55555555, 0x55555555, 0x55555555);
140 var o = SIMD.int32x4.or(m,n); // or
141 assertEquals(-1, o.x);
142 assertEquals(-1, o.y);
143 assertEquals(-1, o.z);
144 assertEquals(-1, o.w);
145 assertEquals(true, o.flagX);
146 assertEquals(true, o.flagY);
147 assertEquals(true, o.flagZ);
148 assertEquals(true, o.flagW);
149 }
150
151 testSIMDOr();
152 testSIMDOr();
153 %OptimizeFunctionOnNextCall(testSIMDOr);
154 testSIMDOr();
155
156 function testSIMDInt32x4Or() {
157 var m = int32x4(0xAAAAAAAA - 0xFFFFFFFF - 1, 0xAAAAAAAA - 0xFFFFFFFF - 1,
158 0xAAAAAAAA - 0xFFFFFFFF - 1, 0xAAAAAAAA - 0xFFFFFFFF - 1);
159 var n = int32x4(0xAAAAAAAA - 0xFFFFFFFF - 1, 0xAAAAAAAA - 0xFFFFFFFF - 1,
160 0xAAAAAAAA - 0xFFFFFFFF - 1, 0xAAAAAAAA - 0xFFFFFFFF - 1);
161 var o = SIMD.int32x4.xor(m,n); // xor
162 assertEquals(0x0, o.x);
163 assertEquals(0x0, o.y);
164 assertEquals(0x0, o.z);
165 assertEquals(0x0, o.w);
166 assertEquals(false, o.flagX);
167 assertEquals(false, o.flagY);
168 assertEquals(false, o.flagZ);
169 assertEquals(false, o.flagW);
170 }
171
172 testSIMDInt32x4Or();
173 testSIMDInt32x4Or();
174 %OptimizeFunctionOnNextCall(testSIMDInt32x4Or);
175 testSIMDInt32x4Or();
176
177 function testSIMDNot() {
178 var m = int32x4(0xAAAAAAAA - 0xFFFFFFFF - 1, 0xAAAAAAAA - 0xFFFFFFFF - 1,
179 0xAAAAAAAA - 0xFFFFFFFF - 1, 0xAAAAAAAA - 0xFFFFFFFF - 1);
180 var n = int32x4(0x55555555, 0x55555555, 0x55555555, 0x55555555);
181 m = SIMD.int32x4.not(m);
182 n = SIMD.int32x4.not(n);
183 assertEquals(0xAAAAAAAA - 0xFFFFFFFF - 1, n.x);
184 assertEquals(0xAAAAAAAA - 0xFFFFFFFF - 1, n.y);
185 assertEquals(0xAAAAAAAA - 0xFFFFFFFF - 1, n.z);
186 assertEquals(0xAAAAAAAA - 0xFFFFFFFF - 1, n.w);
187 assertEquals(0x55555555, m.x);
188 assertEquals(0x55555555, m.y);
189 assertEquals(0x55555555, m.z);
190 assertEquals(0x55555555, m.w);
191 }
192
193 testSIMDNot();
194 testSIMDNot();
195 %OptimizeFunctionOnNextCall(testSIMDNot);
196 testSIMDNot();
197
198 function testSIMDNegu32() {
199 var m = int32x4(-1, 1, -1, 1);
200 m = SIMD.int32x4.neg(m);
201 assertEquals(1, m.x);
202 assertEquals(-1, m.y);
203 assertEquals(1, m.z);
204 assertEquals(-1, m.w);
205 }
206
207 testSIMDNegu32();
208 testSIMDNegu32();
209 %OptimizeFunctionOnNextCall(testSIMDNegu32);
210 testSIMDNegu32();
211
212 function testSIMDSelect() {
213 var m = int32x4.bool(true, true, false, false);
214 var t = float32x4(1.0, 2.0, 3.0, 4.0);
215 var f = float32x4(5.0, 6.0, 7.0, 8.0);
216 var s = SIMD.int32x4.select(m, t, f);
217 assertEquals(1.0, s.x);
218 assertEquals(2.0, s.y);
219 assertEquals(7.0, s.z);
220 assertEquals(8.0, s.w);
221 }
222
223 testSIMDSelect();
224 testSIMDSelect();
225 %OptimizeFunctionOnNextCall(testSIMDSelect);
226 testSIMDSelect();
227
228
229 function testSIMDWithXu32() {
230 var a = int32x4(1, 2, 3, 4);
231 var c = SIMD.int32x4.withX(a, 20);
232 assertEquals(20, c.x);
233 assertEquals(2, c.y);
234 assertEquals(3, c.z);
235 assertEquals(4, c.w);
236 }
237
238 testSIMDWithXu32();
239 testSIMDWithXu32();
240 %OptimizeFunctionOnNextCall(testSIMDWithXu32);
241 testSIMDWithXu32();
242
243 function testSIMDWithYu32() {
244 var a = int32x4(1, 2, 3, 4);
245 var c = SIMD.int32x4.withY(a, 20);
246 assertEquals(1, c.x);
247 assertEquals(20, c.y);
248 assertEquals(3, c.z);
249 assertEquals(4, c.w);
250 }
251
252 testSIMDWithYu32();
253 testSIMDWithYu32();
254 %OptimizeFunctionOnNextCall(testSIMDWithYu32);
255 testSIMDWithYu32();
256
257 function testSIMDWithZu32() {
258 var a = int32x4(1, 2, 3, 4);
259 var c = SIMD.int32x4.withZ(a, 20);
260 assertEquals(1, c.x);
261 assertEquals(2, c.y);
262 assertEquals(20, c.z);
263 assertEquals(4, c.w);
264 }
265
266 testSIMDWithZu32();
267 testSIMDWithZu32();
268 %OptimizeFunctionOnNextCall(testSIMDWithZu32);
269 testSIMDWithZu32();
270
271 function testSIMDWithWu32() {
272 var a = int32x4(1, 2, 3, 4);
273 var c = SIMD.int32x4.withW(a, 20);
274 assertEquals(1, c.x);
275 assertEquals(2, c.y);
276 assertEquals(3, c.z);
277 assertEquals(20, c.w);
278 }
279
280 testSIMDWithWu32();
281 testSIMDWithWu32();
282 %OptimizeFunctionOnNextCall(testSIMDWithWu32);
283 testSIMDWithWu32();
284
285 function testSIMDWithFlagX() {
286 var a = int32x4.bool(true, false, true, false);
287
288 // boolean
289 var c = SIMD.int32x4.withFlagX(a, true);
290 assertEquals(true, c.flagX);
291 assertEquals(false, c.flagY);
292 assertEquals(true, c.flagZ);
293 assertEquals(false, c.flagW);
294 c = SIMD.int32x4.withFlagX(a, false);
295 assertEquals(false, c.flagX);
296 assertEquals(false, c.flagY);
297 assertEquals(true, c.flagZ);
298 assertEquals(false, c.flagW);
299 assertEquals(0x0, c.x);
300 assertEquals(0x0, c.y);
301 assertEquals(-1, c.z);
302 assertEquals(0x0, c.w);
303
304 // smi
305 c = SIMD.int32x4.withFlagX(a, 2);
306 assertEquals(true, c.flagX);
307 assertEquals(false, c.flagY);
308 assertEquals(true, c.flagZ);
309 assertEquals(false, c.flagW);
310 assertEquals(-1, c.x);
311 assertEquals(0x0, c.y);
312 assertEquals(-1, c.z);
313 assertEquals(0x0, c.w);
314 c = SIMD.int32x4.withFlagX(a, 0);
315 assertEquals(false, c.flagX);
316 assertEquals(false, c.flagY);
317 assertEquals(true, c.flagZ);
318 assertEquals(false, c.flagW);
319 assertEquals(0x0, c.x);
320 assertEquals(0x0, c.y);
321 assertEquals(-1, c.z);
322 assertEquals(0x0, c.w);
323
324 // string
325 c = SIMD.int32x4.withFlagX(a, 'true');
326 assertEquals(true, c.flagX);
327 assertEquals(false, c.flagY);
328 assertEquals(true, c.flagZ);
329 assertEquals(false, c.flagW);
330 assertEquals(-1, c.x);
331 assertEquals(0x0, c.y);
332 assertEquals(-1, c.z);
333 assertEquals(0x0, c.w);
334 c = SIMD.int32x4.withFlagX(a, '');
335 assertEquals(false, c.flagX);
336 assertEquals(false, c.flagY);
337 assertEquals(true, c.flagZ);
338 assertEquals(false, c.flagW);
339 assertEquals(0x0, c.x);
340 assertEquals(0x0, c.y);
341 assertEquals(-1, c.z);
342 assertEquals(0x0, c.w);
343
344 // heap number
345 c = SIMD.int32x4.withFlagX(a, 3.14);
346 assertEquals(true, c.flagX);
347 assertEquals(false, c.flagY);
348 assertEquals(true, c.flagZ);
349 assertEquals(false, c.flagW);
350 assertEquals(-1, c.x);
351 assertEquals(0x0, c.y);
352 assertEquals(-1, c.z);
353 assertEquals(0x0, c.w);
354 c = SIMD.int32x4.withFlagX(a, 0.0);
355 assertEquals(false, c.flagX);
356 assertEquals(false, c.flagY);
357 assertEquals(true, c.flagZ);
358 assertEquals(false, c.flagW);
359 assertEquals(0x0, c.x);
360 assertEquals(0x0, c.y);
361 assertEquals(-1, c.z);
362 assertEquals(0x0, c.w);
363
364 // JS Array
365 var array = [1];
366 c = SIMD.int32x4.withFlagX(a, array);
367 assertEquals(true, c.flagX);
368 assertEquals(false, c.flagY);
369 assertEquals(true, c.flagZ);
370 assertEquals(false, c.flagW);
371 assertEquals(-1, c.x);
372 assertEquals(0x0, c.y);
373 assertEquals(-1, c.z);
374 assertEquals(0x0, c.w);
375
376 c = SIMD.int32x4.withFlagX(a, undefined);
377 assertEquals(false, c.flagX);
378 assertEquals(false, c.flagY);
379 assertEquals(true, c.flagZ);
380 assertEquals(false, c.flagW);
381 assertEquals(0x0, c.x);
382 assertEquals(0x0, c.y);
383 assertEquals(-1, c.z);
384 assertEquals(0x0, c.w);
385 }
386
387 testSIMDWithFlagX();
388 testSIMDWithFlagX();
389 %OptimizeFunctionOnNextCall(testSIMDWithFlagX);
390 testSIMDWithFlagX();
391
392 function testSIMDWithFlagY() {
393 var a = int32x4.bool(true, false, true, false);
394 var c = SIMD.int32x4.withFlagY(a, true);
395 assertEquals(true, c.flagX);
396 assertEquals(true, c.flagY);
397 assertEquals(true, c.flagZ);
398 assertEquals(false, c.flagW);
399 c = SIMD.int32x4.withFlagY(a, false);
400 assertEquals(true, c.flagX);
401 assertEquals(false, c.flagY);
402 assertEquals(true, c.flagZ);
403 assertEquals(false, c.flagW);
404 assertEquals(-1, c.x);
405 assertEquals(0x0, c.y);
406 assertEquals(-1, c.z);
407 assertEquals(0x0, c.w);
408 }
409
410 testSIMDWithFlagY();
411 testSIMDWithFlagY();
412 %OptimizeFunctionOnNextCall(testSIMDWithFlagY);
413 testSIMDWithFlagY();
414
415 function testSIMDWithFlagZ() {
416 var a = int32x4.bool(true, false, true, false);
417 var c = SIMD.int32x4.withFlagZ(a, true);
418 assertEquals(true, c.flagX);
419 assertEquals(false, c.flagY);
420 assertEquals(true, c.flagZ);
421 assertEquals(false, c.flagW);
422 c = SIMD.int32x4.withFlagZ(a, false);
423 assertEquals(true, c.flagX);
424 assertEquals(false, c.flagY);
425 assertEquals(false, c.flagZ);
426 assertEquals(false, c.flagW);
427 assertEquals(-1, c.x);
428 assertEquals(0x0, c.y);
429 assertEquals(0x0, c.z);
430 assertEquals(0x0, c.w);
431 }
432
433 testSIMDWithFlagZ();
434 testSIMDWithFlagZ();
435 %OptimizeFunctionOnNextCall(testSIMDWithFlagZ);
436 testSIMDWithFlagZ();
437
438 function testSIMDWithFlagW() {
439 var a = int32x4.bool(true, false, true, false);
440 var c = SIMD.int32x4.withFlagW(a, true);
441 assertEquals(true, c.flagX);
442 assertEquals(false, c.flagY);
443 assertEquals(true, c.flagZ);
444 assertEquals(true, c.flagW);
445 c = SIMD.int32x4.withFlagW(a, false);
446 assertEquals(true, c.flagX);
447 assertEquals(false, c.flagY);
448 assertEquals(true, c.flagZ);
449 assertEquals(false, c.flagW);
450 assertEquals(-1, c.x);
451 assertEquals(0x0, c.y);
452 assertEquals(-1, c.z);
453 assertEquals(0x0, c.w);
454 }
455
456 testSIMDWithFlagW();
457 testSIMDWithFlagW();
458 %OptimizeFunctionOnNextCall(testSIMDWithFlagW);
459 testSIMDWithFlagW();
460
461 function testSIMDAddu32() {
462 var a = int32x4(-1, -1, 0x7fffffff, 0x0);
463 var b = int32x4(0x1, -1, 0x1, -1);
464 var c = SIMD.int32x4.add(a, b);
465 assertEquals(0x0, c.x);
466 assertEquals(-2, c.y);
467 assertEquals(0x80000000 - 0xFFFFFFFF - 1, c.z);
468 assertEquals(-1, c.w);
469 }
470
471 testSIMDAddu32();
472 testSIMDAddu32();
473 %OptimizeFunctionOnNextCall(testSIMDAddu32);
474 testSIMDAddu32();
475
476 function testSIMDSubu32() {
477 var a = int32x4(-1, -1, 0x80000000 - 0xFFFFFFFF - 1, 0x0);
478 var b = int32x4(0x1, -1, 0x1, -1);
479 var c = SIMD.int32x4.sub(a, b);
480 assertEquals(-2, c.x);
481 assertEquals(0x0, c.y);
482 assertEquals(0x7FFFFFFF, c.z);
483 assertEquals(0x1, c.w);
484 }
485
486 testSIMDSubu32();
487 testSIMDSubu32();
488 %OptimizeFunctionOnNextCall(testSIMDSubu32);
489 testSIMDSubu32();
490
491 function testSIMDMulu32() {
492 var a = int32x4(-1, -1, 0x80000000 - 0xFFFFFFFF - 1, 0x0);
493 var b = int32x4(0x1, -1, 0x80000000 - 0xFFFFFFFF - 1, -1);
494 var c = SIMD.int32x4.mul(a, b);
495 assertEquals(-1, c.x);
496 assertEquals(0x1, c.y);
497 assertEquals(0x0, c.z);
498 assertEquals(0x0, c.w);
499 }
500
501 testSIMDMulu32();
502 testSIMDMulu32();
503 %OptimizeFunctionOnNextCall(testSIMDMulu32);
504 testSIMDMulu32();
505
506 function testSIMDShuffleu32() {
507 var m = int32x4(1, 2, 3, 4);
508 var xxxx = SIMD.int32x4.shuffle(m, SIMD.XXXX);
509 assertEquals(1, xxxx.x);
510 assertEquals(1, xxxx.y);
511 assertEquals(1, xxxx.z);
512 assertEquals(1, xxxx.w);
513 var yyyy = SIMD.int32x4.shuffle(m, SIMD.YYYY);
514 assertEquals(2, yyyy.x);
515 assertEquals(2, yyyy.y);
516 assertEquals(2, yyyy.z);
517 assertEquals(2, yyyy.w);
518 var zzzz = SIMD.int32x4.shuffle(m, SIMD.ZZZZ);
519 assertEquals(3, zzzz.x);
520 assertEquals(3, zzzz.y);
521 assertEquals(3, zzzz.z);
522 assertEquals(3, zzzz.w);
523 var wwww = SIMD.int32x4.shuffle(m, SIMD.WWWW);
524 assertEquals(4, wwww.x);
525 assertEquals(4, wwww.y);
526 assertEquals(4, wwww.z);
527 assertEquals(4, wwww.w);
528 var wzyx = SIMD.int32x4.shuffle(m, SIMD.WZYX);
529 assertEquals(4, wzyx.x);
530 assertEquals(3, wzyx.y);
531 assertEquals(2, wzyx.z);
532 assertEquals(1, wzyx.w);
533 var wwzz = SIMD.int32x4.shuffle(m, SIMD.WWZZ);
534 assertEquals(4, wwzz.x);
535 assertEquals(4, wwzz.y);
536 assertEquals(3, wwzz.z);
537 assertEquals(3, wwzz.w);
538 var xxyy = SIMD.int32x4.shuffle(m, SIMD.XXYY);
539 assertEquals(1, xxyy.x);
540 assertEquals(1, xxyy.y);
541 assertEquals(2, xxyy.z);
542 assertEquals(2, xxyy.w);
543 var yyww = SIMD.int32x4.shuffle(m, SIMD.YYWW);
544 assertEquals(2, yyww.x);
545 assertEquals(2, yyww.y);
546 assertEquals(4, yyww.z);
547 assertEquals(4, yyww.w);
548 }
549
550 testSIMDShuffleu32();
551 testSIMDShuffleu32();
552 %OptimizeFunctionOnNextCall(testSIMDShuffleu32);
553 testSIMDShuffleu32();
554
555 function testInt32x4ArrayBasic() {
556 var a = new Int32x4Array(1);
557 assertEquals(1, a.length);
558 assertEquals(16, a.byteLength);
559 assertEquals(16, a.BYTES_PER_ELEMENT);
560 assertEquals(16, Int32x4Array.BYTES_PER_ELEMENT);
561 assertEquals(0, a.byteOffset);
562 assertTrue(undefined != a.buffer);
563 var b = new Int32x4Array(4);
564 assertEquals(4, b.length);
565 assertEquals(64, b.byteLength);
566 assertEquals(16, b.BYTES_PER_ELEMENT);
567 assertEquals(16, Int32x4Array.BYTES_PER_ELEMENT);
568 assertEquals(0, b.byteOffset);
569 assertTrue(undefined != b.buffer);
570 }
571
572 testInt32x4ArrayBasic();
573
574 function testInt32x4ArrayGetAndSet() {
575 var a = new Int32x4Array(4);
576 a[0] = int32x4(1, 2, 3, 4);
577 a[1] = int32x4(5, 6, 7, 8);
578 a[2] = int32x4(9, 10, 11, 12);
579 a[3] = int32x4(13, 14, 15, 16);
580 assertEquals(a[0].x, 1);
581 assertEquals(a[0].y, 2);
582 assertEquals(a[0].z, 3);
583 assertEquals(a[0].w, 4);
584
585 assertEquals(a[1].x, 5);
586 assertEquals(a[1].y, 6);
587 assertEquals(a[1].z, 7);
588 assertEquals(a[1].w, 8);
589
590 assertEquals(a[2].x, 9);
591 assertEquals(a[2].y, 10);
592 assertEquals(a[2].z, 11);
593 assertEquals(a[2].w, 12);
594
595 assertEquals(a[3].x, 13);
596 assertEquals(a[3].y, 14);
597 assertEquals(a[3].z, 15);
598 assertEquals(a[3].w, 16);
599
600 var b = new Int32x4Array(4);
601 b.setAt(0, int32x4(1, 2, 3, 4));
602 b.setAt(1, int32x4(5, 6, 7, 8));
603 b.setAt(2, int32x4(9, 10, 11, 12));
604 b.setAt(3, int32x4(13, 14, 15, 16));
605
606 assertEquals(b.getAt(0).x, 1);
607 assertEquals(b.getAt(0).y, 2);
608 assertEquals(b.getAt(0).z, 3);
609 assertEquals(b.getAt(0).w, 4);
610
611 assertEquals(b.getAt(1).x, 5);
612 assertEquals(b.getAt(1).y, 6);
613 assertEquals(b.getAt(1).z, 7);
614 assertEquals(b.getAt(1).w, 8);
615
616 assertEquals(b.getAt(2).x, 9);
617 assertEquals(b.getAt(2).y, 10);
618 assertEquals(b.getAt(2).z, 11);
619 assertEquals(b.getAt(2).w, 12);
620
621 assertEquals(b.getAt(3).x, 13);
622 assertEquals(b.getAt(3).y, 14);
623 assertEquals(b.getAt(3).z, 15);
624 assertEquals(b.getAt(3).w, 16);
625 }
626
627 testInt32x4ArrayGetAndSet();
628
629 function testInt32x4ArraySwap() {
630 var a = new Int32x4Array(4);
631 a[0] = int32x4(1, 2, 3, 4);
632 a[1] = int32x4(5, 6, 7, 8);
633 a[2] = int32x4(9, 10, 11, 12);
634 a[3] = int32x4(13, 14, 15, 16);
635
636 // Swap element 0 and element 3
637 var t = a[0];
638 a[0] = a[3];
639 a[3] = t;
640
641 assertEquals(a[3].x, 1);
642 assertEquals(a[3].y, 2);
643 assertEquals(a[3].z, 3);
644 assertEquals(a[3].w, 4);
645
646 assertEquals(a[1].x, 5);
647 assertEquals(a[1].y, 6);
648 assertEquals(a[1].z, 7);
649 assertEquals(a[1].w, 8);
650
651 assertEquals(a[2].x, 9);
652 assertEquals(a[2].y, 10);
653 assertEquals(a[2].z, 11);
654 assertEquals(a[2].w, 12);
655
656 assertEquals(a[0].x, 13);
657 assertEquals(a[0].y, 14);
658 assertEquals(a[0].z, 15);
659 assertEquals(a[0].w, 16);
660 }
661
662 testInt32x4ArraySwap();
663 testInt32x4ArraySwap();
664 %OptimizeFunctionOnNextCall(testInt32x4ArraySwap);
665 testInt32x4ArraySwap();
666
667 function testInt32x4ArrayCopy() {
668 var a = new Int32x4Array(4);
669 a[0] = int32x4(1, 2, 3, 4);
670 a[1] = int32x4(5, 6, 7, 8);
671 a[2] = int32x4(9, 10, 11, 12);
672 a[3] = int32x4(13, 14, 15, 16);
673 var b = new Int32x4Array(a);
674 assertEquals(a[0].x, b[0].x);
675 assertEquals(a[0].y, b[0].y);
676 assertEquals(a[0].z, b[0].z);
677 assertEquals(a[0].w, b[0].w);
678
679 assertEquals(a[1].x, b[1].x);
680 assertEquals(a[1].y, b[1].y);
681 assertEquals(a[1].z, b[1].z);
682 assertEquals(a[1].w, b[1].w);
683
684 assertEquals(a[2].x, b[2].x);
685 assertEquals(a[2].y, b[2].y);
686 assertEquals(a[2].z, b[2].z);
687 assertEquals(a[2].w, b[2].w);
688
689 assertEquals(a[3].x, b[3].x);
690 assertEquals(a[3].y, b[3].y);
691 assertEquals(a[3].z, b[3].z);
692 assertEquals(a[3].w, b[3].w);
693
694 a[2] = int32x4(17, 18, 19, 20);
695
696 assertEquals(a[2].x, 17);
697 assertEquals(a[2].y, 18);
698 assertEquals(a[2].z, 19);
699 assertEquals(a[2].w, 20);
700
701 assertTrue(a[2].x != b[2].x);
702 assertTrue(a[2].y != b[2].y);
703 assertTrue(a[2].z != b[2].z);
704 assertTrue(a[2].w != b[2].w);
705 }
706
707 testInt32x4ArrayCopy();
708
709 function testInt32x4ArrayViewBasic() {
710 var a = new Uint32Array(8);
711 // view with no offset.
712 var b = new Int32x4Array(a.buffer, 0);
713 // view with offset.
714 var c = new Int32x4Array(a.buffer, 16);
715 // view with no offset but shorter than original list.
716 var d = new Int32x4Array(a.buffer, 0, 1);
717 assertEquals(a.length, 8);
718 assertEquals(b.length, 2);
719 assertEquals(c.length, 1);
720 assertEquals(d.length, 1);
721 assertEquals(a.byteLength, 32);
722 assertEquals(b.byteLength, 32);
723 assertEquals(c.byteLength, 16);
724 assertEquals(d.byteLength, 16)
725 assertEquals(a.byteOffset, 0);
726 assertEquals(b.byteOffset, 0);
727 assertEquals(c.byteOffset, 16);
728 assertEquals(d.byteOffset, 0);
729 }
730
731 testInt32x4ArrayViewBasic();
732
733 function testInt32x4ArrayViewValues() {
734 var a = new Uint32Array(8);
735 var b = new Int32x4Array(a.buffer, 0);
736 var c = new Int32x4Array(a.buffer, 16);
737 var d = new Int32x4Array(a.buffer, 0, 1);
738 var start = 100;
739 for (var i = 0; i < b.length; i++) {
740 assertEquals(0, b[i].x);
741 assertEquals(0, b[i].y);
742 assertEquals(0, b[i].z);
743 assertEquals(0, b[i].w);
744 }
745 for (var i = 0; i < c.length; i++) {
746 assertEquals(0, c[i].x);
747 assertEquals(0, c[i].y);
748 assertEquals(0, c[i].z);
749 assertEquals(0, c[i].w);
750 }
751 for (var i = 0; i < d.length; i++) {
752 assertEquals(0, d[i].x);
753 assertEquals(0, d[i].y);
754 assertEquals(0, d[i].z);
755 assertEquals(0, d[i].w);
756 }
757 for (var i = 0; i < a.length; i++) {
758 a[i] = i+start;
759 }
760 for (var i = 0; i < b.length; i++) {
761 assertTrue(0 != b[i].x);
762 assertTrue(0 != b[i].y);
763 assertTrue(0 != b[i].z);
764 assertTrue(0 != b[i].w);
765 }
766 for (var i = 0; i < c.length; i++) {
767 assertTrue(0 != c[i].x);
768 assertTrue(0 != c[i].y);
769 assertTrue(0 != c[i].z);
770 assertTrue(0 != c[i].w);
771 }
772 for (var i = 0; i < d.length; i++) {
773 assertTrue(0 != d[i].x);
774 assertTrue(0 != d[i].y);
775 assertTrue(0 != d[i].z);
776 assertTrue(0 != d[i].w);
777 }
778 assertEquals(start+0, b[0].x);
779 assertEquals(start+1, b[0].y);
780 assertEquals(start+2, b[0].z);
781 assertEquals(start+3, b[0].w);
782 assertEquals(start+4, b[1].x);
783 assertEquals(start+5, b[1].y);
784 assertEquals(start+6, b[1].z);
785 assertEquals(start+7, b[1].w);
786
787 assertEquals(start+4, c[0].x);
788 assertEquals(start+5, c[0].y);
789 assertEquals(start+6, c[0].z);
790 assertEquals(start+7, c[0].w);
791
792 assertEquals(start+0, d[0].x);
793 assertEquals(start+1, d[0].y);
794 assertEquals(start+2, d[0].z);
795 assertEquals(start+3, d[0].w);
796 }
797
798 testInt32x4ArrayViewValues();
799
800 function testViewOnInt32x4Array() {
801 var a = new Int32x4Array(4);
802 a[0] = int32x4(1, 2, 3, 4);
803 a[1] = int32x4(5, 6, 7, 8);
804 a[2] = int32x4(9, 10, 11, 12);
805 a[3] = int32x4(13, 14, 15, 16);
806 assertEquals(a[0].x, 1);
807 assertEquals(a[0].y, 2);
808 assertEquals(a[0].z, 3);
809 assertEquals(a[0].w, 4);
810
811 assertEquals(a[1].x, 5);
812 assertEquals(a[1].y, 6);
813 assertEquals(a[1].z, 7);
814 assertEquals(a[1].w, 8);
815
816 assertEquals(a[2].x, 9);
817 assertEquals(a[2].y, 10);
818 assertEquals(a[2].z, 11);
819 assertEquals(a[2].w, 12);
820
821 assertEquals(a[3].x, 13);
822 assertEquals(a[3].y, 14);
823 assertEquals(a[3].z, 15);
824 assertEquals(a[3].w, 16);
825
826 // Create view on a.
827 var b = new Uint32Array(a.buffer);
828 assertEquals(b.length, 16);
829 assertEquals(b.byteLength, 64);
830 b[2] = 99.0;
831 b[6] = 1.0;
832
833 // Observe changes in "a"
834 assertEquals(a[0].x, 1);
835 assertEquals(a[0].y, 2);
836 assertEquals(a[0].z, 99);
837 assertEquals(a[0].w, 4);
838
839 assertEquals(a[1].x, 5);
840 assertEquals(a[1].y, 6);
841 assertEquals(a[1].z, 1);
842 assertEquals(a[1].w, 8);
843
844 assertEquals(a[2].x, 9);
845 assertEquals(a[2].y, 10);
846 assertEquals(a[2].z, 11);
847 assertEquals(a[2].w, 12);
848
849 assertEquals(a[3].x, 13);
850 assertEquals(a[3].y, 14);
851 assertEquals(a[3].z, 15);
852 assertEquals(a[3].w, 16);
853 }
854
855 testViewOnInt32x4Array();
856
857 function testArrayOfInt32x4() {
858 var a = [];
859 var a4 = new Int32x4Array(2);
860 for (var i = 0; i < a4.length; i++) {
861 a[i] = int32x4(i, i + 1, i + 2, i + 3);
862 a4[i] = int32x4(i, i + 1, i + 2, i + 3);
863 }
864
865 for (var i = 0; i < a4.length; i++) {
866 assertEquals(a[i].x, a4[i].x);
867 assertEquals(a[i].y, a4[i].y);
868 assertEquals(a[i].z, a4[i].z);
869 assertEquals(a[i].w, a4[i].w);
870 }
871 }
872
873 testArrayOfInt32x4();
OLDNEW
« no previous file with comments | « test/mjsunit/simd/float32x4.js ('k') | test/mjsunit/simd/osr.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698