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
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.
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.
28 // Flags: --simd_object --allow-natives-syntax
30 function testConstructor() {
31 var f4 = SIMD.float64x2(1.0, 2.0);
32 assertEquals(1.0, f4.x);
33 assertEquals(2.0, f4.y);
35 f4 = SIMD.float64x2(1.1, 2.2);
36 assertEquals(1.1, f4.x);
37 assertEquals(2.2, f4.y);
42 %OptimizeFunctionOnNextCall(testConstructor);
45 function testZeroConstructor() {
46 var z4 = SIMD.float64x2.zero();
47 assertEquals(0.0, z4.x);
48 assertEquals(0.0, z4.y);
51 testZeroConstructor();
52 testZeroConstructor();
53 %OptimizeFunctionOnNextCall(testZeroConstructor);
54 testZeroConstructor();
56 function testSplatConstructor() {
57 var z4 = SIMD.float64x2.splat(5.0);
58 assertEquals(5.0, z4.x);
59 assertEquals(5.0, z4.y);
62 testSplatConstructor();
63 testSplatConstructor();
64 %OptimizeFunctionOnNextCall(testSplatConstructor);
65 testSplatConstructor();
67 function testTypeof() {
68 var z4 = SIMD.float64x2.zero();
69 assertEquals(typeof(z4), "object");
71 var new_z4 = new SIMD.float64x2(0, 0);
72 assertEquals(typeof(new_z4), "object");
73 assertEquals(typeof(new_z4.valueOf()), "object");
74 assertEquals(Object.prototype.toString.call(new_z4), "[object Object]");
79 function testSignMaskGetter() {
80 var a = SIMD.float64x2(-1.0, -2.0);
81 assertEquals(0x3, a.signMask);
82 var b = SIMD.float64x2(1.0, 2.0);
83 assertEquals(0x0, b.signMask);
84 var c = SIMD.float64x2(1.0, -2.0);
85 assertEquals(0x2, c.signMask);
90 %OptimizeFunctionOnNextCall(testSignMaskGetter);
93 function testSIMDAbs() {
94 var a4 = SIMD.float64x2(1.0, -1.0);
95 var b4 = SIMD.float64x2.abs(a4);
97 assertEquals(1.0, b4.x);
98 assertEquals(1.0, b4.y);
103 %OptimizeFunctionOnNextCall(testSIMDAbs);
106 function testSIMDNeg() {
107 var a4 = SIMD.float64x2(1.0, -1.0);
108 var b4 = SIMD.float64x2.neg(a4);
110 assertEquals(-1.0, b4.x);
111 assertEquals(1.0, b4.y);
116 %OptimizeFunctionOnNextCall(testSIMDNeg);
119 function testSIMDAdd() {
120 var a4 = SIMD.float64x2(1.0, 1.0);
121 var b4 = SIMD.float64x2(2.0, 2.0);
122 var c4 = SIMD.float64x2.add(a4, b4);
124 assertEquals(3.0, c4.x);
125 assertEquals(3.0, c4.y);
130 %OptimizeFunctionOnNextCall(testSIMDAdd);
133 function testSIMDSub() {
134 var a4 = SIMD.float64x2(1.0, 1.0);
135 var b4 = SIMD.float64x2(2.0, 2.0);
136 var c4 = SIMD.float64x2.sub(a4, b4);
138 assertEquals(-1.0, c4.x);
139 assertEquals(-1.0, c4.y);
144 %OptimizeFunctionOnNextCall(testSIMDSub);
147 function testSIMDMul() {
148 var a4 = SIMD.float64x2(1.0, 1.0);
149 var b4 = SIMD.float64x2(2.0, 2.0);
150 var c4 = SIMD.float64x2.mul(a4, b4);
152 assertEquals(2.0, c4.x);
153 assertEquals(2.0, c4.y);
158 %OptimizeFunctionOnNextCall(testSIMDMul);
161 function testSIMDDiv() {
162 var a4 = SIMD.float64x2(1.0, 1.0);
163 var b4 = SIMD.float64x2(2.0, 2.0);
164 var c4 = SIMD.float64x2.div(a4, b4);
166 assertEquals(0.5, c4.x);
167 assertEquals(0.5, c4.y);
172 %OptimizeFunctionOnNextCall(testSIMDDiv);
175 function testSIMDClamp() {
176 var m = SIMD.float64x2(1.0, -2.0);
177 var lo = SIMD.float64x2(0.0, 0.0);
178 var hi = SIMD.float64x2(2.0, 2.0);
179 m = SIMD.float64x2.clamp(m, lo, hi);
180 assertEquals(1.0, m.x);
181 assertEquals(0.0, m.y);
186 %OptimizeFunctionOnNextCall(testSIMDClamp);
189 function testSIMDMin() {
190 var m = SIMD.float64x2(1.0, 2.0);
191 var n = SIMD.float64x2(1.0, 0.0);
192 m = SIMD.float64x2.min(m, n);
193 assertEquals(1.0, m.x);
194 assertEquals(0.0, m.y);
199 %OptimizeFunctionOnNextCall(testSIMDMin);
202 function testSIMDMax() {
203 var m = SIMD.float64x2(1.0, 2.0);
204 var n = SIMD.float64x2(1.0, 0.0);
205 m = SIMD.float64x2.max(m, n);
206 assertEquals(1.0, m.x);
207 assertEquals(2.0, m.y);
212 %OptimizeFunctionOnNextCall(testSIMDMax);
215 function testSIMDScale() {
216 var m = SIMD.float64x2(1.0, -2.0);
217 m = SIMD.float64x2.scale(m, 20.0);
218 assertEquals(20.0, m.x);
219 assertEquals(-40.0, m.y);
224 %OptimizeFunctionOnNextCall(testSIMDScale);
227 function testSIMDSqrt() {
228 var m = SIMD.float64x2(1.0, 4.0);
229 m = SIMD.float64x2.sqrt(m);
230 assertEquals(1.0, m.x);
231 assertEquals(2.0, m.y);
236 %OptimizeFunctionOnNextCall(testSIMDSqrt);
239 function testSIMDSetters() {
240 var f = SIMD.float64x2.zero();
241 assertEquals(0.0, f.x);
242 assertEquals(0.0, f.y);
243 f = SIMD.float64x2.withX(f, 4.0);
244 assertEquals(4.0, f.x);
245 f = SIMD.float64x2.withY(f, 3.0);
246 assertEquals(3.0, f.y);
251 %OptimizeFunctionOnNextCall(testSIMDSetters);
254 function testFloat64x2ArrayBasic() {
255 var a = new Float64x2Array(1);
256 assertEquals(1, a.length);
257 assertEquals(16, a.byteLength);
258 assertEquals(16, a.BYTES_PER_ELEMENT);
259 assertEquals(16, Float64x2Array.BYTES_PER_ELEMENT);
260 assertEquals(0, a.byteOffset);
261 assertTrue(undefined != a.buffer);
262 var b = new Float64x2Array(4);
263 assertEquals(4, b.length);
264 assertEquals(64, b.byteLength);
265 assertEquals(16, b.BYTES_PER_ELEMENT);
266 assertEquals(16, Float64x2Array.BYTES_PER_ELEMENT);
267 assertEquals(0, b.byteOffset);
268 assertTrue(undefined != b.buffer);
271 testFloat64x2ArrayBasic();
273 function testFloat64x2ArrayGetAndSet() {
274 var a = new Float64x2Array(4);
275 a[0] = SIMD.float64x2(1, 2);
276 a[1] = SIMD.float64x2(5, 6);
277 a[2] = SIMD.float64x2(9, 10);
278 a[3] = SIMD.float64x2(13, 14);
279 assertEquals(a[0].x, 1);
280 assertEquals(a[0].y, 2);
282 assertEquals(a[1].x, 5);
283 assertEquals(a[1].y, 6);
285 assertEquals(a[2].x, 9);
286 assertEquals(a[2].y, 10);
288 assertEquals(a[3].x, 13);
289 assertEquals(a[3].y, 14);
291 var b = new Float64x2Array(4);
292 b.setAt(0,SIMD.float64x2(1, 2));
293 b.setAt(1,SIMD.float64x2(5, 6));
294 b.setAt(2,SIMD.float64x2(9, 10));
295 b.setAt(3,SIMD.float64x2(13, 14));
297 assertEquals(b.getAt(0).x, 1);
298 assertEquals(b.getAt(0).y, 2);
300 assertEquals(b.getAt(1).x, 5);
301 assertEquals(b.getAt(1).y, 6);
303 assertEquals(b.getAt(2).x, 9);
304 assertEquals(b.getAt(2).y, 10);
306 assertEquals(b.getAt(3).x, 13);
307 assertEquals(b.getAt(3).y, 14);
310 testFloat64x2ArrayGetAndSet();
312 function testFloat64x2ArraySwap() {
313 var a = new Float64x2Array(4);
314 a[0] = SIMD.float64x2(1, 2);
315 a[1] = SIMD.float64x2(5, 6);
316 a[2] = SIMD.float64x2(9, 10);
317 a[3] = SIMD.float64x2(13, 14);
319 // Swap element 0 and element 3
324 assertEquals(a[3].x, 1);
325 assertEquals(a[3].y, 2);
327 assertEquals(a[1].x, 5);
328 assertEquals(a[1].y, 6);
330 assertEquals(a[2].x, 9);
331 assertEquals(a[2].y, 10);
333 assertEquals(a[0].x, 13);
334 assertEquals(a[0].y, 14);
337 testFloat64x2ArraySwap();
339 function testFloat64x2ArrayCopy() {
340 var a = new Float64x2Array(4);
341 a[0] = SIMD.float64x2(1, 2);
342 a[1] = SIMD.float64x2(5, 6);
343 a[2] = SIMD.float64x2(9, 10);
344 a[3] = SIMD.float64x2(13, 14);
345 var b = new Float64x2Array(a);
346 assertEquals(a[0].x, b[0].x);
347 assertEquals(a[0].y, b[0].y);
349 assertEquals(a[1].x, b[1].x);
350 assertEquals(a[1].y, b[1].y);
352 assertEquals(a[2].x, b[2].x);
353 assertEquals(a[2].y, b[2].y);
355 assertEquals(a[3].x, b[3].x);
356 assertEquals(a[3].y, b[3].y);
358 a[2] = SIMD.float64x2(17, 18);
360 assertEquals(a[2].x, 17);
361 assertEquals(a[2].y, 18);
363 assertTrue(a[2].x != b[2].x);
364 assertTrue(a[2].y != b[2].y);
367 testFloat64x2ArrayCopy();
369 function testFloat64x2ArrayViewBasic() {
370 var a = new Float64Array(8);
371 // view with no offset.
372 var b = new Float64x2Array(a.buffer, 0);
374 var c = new Float64x2Array(a.buffer, 16);
375 // view with no offset but shorter than original list.
376 var d = new Float64x2Array(a.buffer, 0, 1);
377 assertEquals(a.length, 8);
378 assertEquals(b.length, 4);
379 assertEquals(c.length, 3);
380 assertEquals(d.length, 1);
381 assertEquals(a.byteLength, 64);
382 assertEquals(b.byteLength, 64);
383 assertEquals(c.byteLength, 48);
384 assertEquals(d.byteLength, 16)
385 assertEquals(a.byteOffset, 0);
386 assertEquals(b.byteOffset, 0);
387 assertEquals(c.byteOffset, 16);
388 assertEquals(d.byteOffset, 0);
391 testFloat64x2ArrayViewBasic();
393 function testFloat64x2ArrayViewValues() {
394 var a = new Float64Array(8);
395 var b = new Float64x2Array(a.buffer, 0);
396 var c = new Float64x2Array(a.buffer, 16);
397 var d = new Float64x2Array(a.buffer, 0, 1);
399 for (var i = 0; i < b.length; i++) {
400 assertEquals(0.0, b[i].x);
401 assertEquals(0.0, b[i].y);
403 for (var i = 0; i < c.length; i++) {
404 assertEquals(0.0, c[i].x);
405 assertEquals(0.0, c[i].y);
407 for (var i = 0; i < d.length; i++) {
408 assertEquals(0.0, d[i].x);
409 assertEquals(0.0, d[i].y);
411 for (var i = 0; i < a.length; i++) {
414 for (var i = 0; i < b.length; i++) {
415 assertTrue(0.0 != b[i].x);
416 assertTrue(0.0 != b[i].y);
418 for (var i = 0; i < c.length; i++) {
419 assertTrue(0.0 != c[i].x);
420 assertTrue(0.0 != c[i].y);
422 for (var i = 0; i < d.length; i++) {
423 assertTrue(0.0 != d[i].x);
424 assertTrue(0.0 != d[i].y);
426 assertEquals(start+0, b[0].x);
427 assertEquals(start+1, b[0].y);
428 assertEquals(start+2, b[1].x);
429 assertEquals(start+3, b[1].y);
430 assertEquals(start+4, b[2].x);
431 assertEquals(start+5, b[2].y);
432 assertEquals(start+6, b[3].x);
433 assertEquals(start+7, b[3].y);
435 assertEquals(start+2, c[0].x);
436 assertEquals(start+3, c[0].y);
437 assertEquals(start+4, c[1].x);
438 assertEquals(start+5, c[1].y);
439 assertEquals(start+6, c[2].x);
440 assertEquals(start+7, c[2].y);
442 assertEquals(start+0, d[0].x);
443 assertEquals(start+1, d[0].y);
446 testFloat64x2ArrayViewValues();
448 function testViewOnFloat64x2Array() {
449 var a = new Float64x2Array(4);
450 a[0] = SIMD.float64x2(1, 2);
451 a[1] = SIMD.float64x2(5, 6);
452 a[2] = SIMD.float64x2(9, 10);
453 a[3] = SIMD.float64x2(13, 14);
454 assertEquals(a[0].x, 1);
455 assertEquals(a[0].y, 2);
457 assertEquals(a[1].x, 5);
458 assertEquals(a[1].y, 6);
460 assertEquals(a[2].x, 9);
461 assertEquals(a[2].y, 10);
463 assertEquals(a[3].x, 13);
464 assertEquals(a[3].y, 14);
467 var b = new Float64Array(a.buffer);
468 assertEquals(b.length, 8);
469 assertEquals(b.byteLength, 64);
473 // Observe changes in "a"
474 assertEquals(a[0].x, 1);
475 assertEquals(a[0].y, 2);
477 assertEquals(a[1].x, 99.0);
478 assertEquals(a[1].y, 6);
480 assertEquals(a[2].x, 9);
481 assertEquals(a[2].y, 10);
483 assertEquals(a[3].x, 1.0);
484 assertEquals(a[3].y, 14);
487 testViewOnFloat64x2Array();
489 function testArrayOfFloat64x2() {
491 var a4 = new Float64x2Array(2);
492 for (var i = 0; i < a4.length; i++) {
493 a[i] = SIMD.float64x2(i, i + 1);
494 a4[i] = SIMD.float64x2(i, i + 1);
497 for (var i = 0; i < a4.length; i++) {
498 assertEquals(a[i].x, a4[i].x);
499 assertEquals(a[i].y, a4[i].y);
503 testArrayOfFloat64x2();