Upstream version 8.37.186.0
[platform/framework/web/crosswalk.git] / src / v8 / test / mjsunit / simd / float64x2.js
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 f4 = SIMD.float64x2(1.0, 2.0);
32   assertEquals(1.0, f4.x);
33   assertEquals(2.0, f4.y);
34
35   f4 = SIMD.float64x2(1.1, 2.2);
36   assertEquals(1.1, f4.x);
37   assertEquals(2.2, f4.y);
38 }
39
40 testConstructor();
41 testConstructor();
42 %OptimizeFunctionOnNextCall(testConstructor);
43 testConstructor();
44
45 function testZeroConstructor() {
46   var z4 = SIMD.float64x2.zero();
47   assertEquals(0.0, z4.x);
48   assertEquals(0.0, z4.y);
49 }
50
51 testZeroConstructor();
52 testZeroConstructor();
53 %OptimizeFunctionOnNextCall(testZeroConstructor);
54 testZeroConstructor();
55
56 function testSplatConstructor() {
57   var z4 = SIMD.float64x2.splat(5.0);
58   assertEquals(5.0, z4.x);
59   assertEquals(5.0, z4.y);
60 }
61
62 testSplatConstructor();
63 testSplatConstructor();
64 %OptimizeFunctionOnNextCall(testSplatConstructor);
65 testSplatConstructor();
66
67 function testTypeof() {
68   var z4 = SIMD.float64x2.zero();
69   assertEquals(typeof(z4), "object");
70
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]");
75 }
76
77 testTypeof();
78
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);
86 }
87
88 testSignMaskGetter();
89 testSignMaskGetter();
90 %OptimizeFunctionOnNextCall(testSignMaskGetter);
91 testSignMaskGetter();
92
93 function testSIMDAbs() {
94   var a4 = SIMD.float64x2(1.0, -1.0);
95   var b4 = SIMD.float64x2.abs(a4);
96
97   assertEquals(1.0, b4.x);
98   assertEquals(1.0, b4.y);
99 }
100
101 testSIMDAbs();
102 testSIMDAbs();
103 %OptimizeFunctionOnNextCall(testSIMDAbs);
104 testSIMDAbs();
105
106 function testSIMDNeg() {
107   var a4 = SIMD.float64x2(1.0, -1.0);
108   var b4 = SIMD.float64x2.neg(a4);
109
110   assertEquals(-1.0, b4.x);
111   assertEquals(1.0, b4.y);
112 }
113
114 testSIMDNeg();
115 testSIMDNeg();
116 %OptimizeFunctionOnNextCall(testSIMDNeg);
117 testSIMDNeg();
118
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);
123
124   assertEquals(3.0, c4.x);
125   assertEquals(3.0, c4.y);
126 }
127
128 testSIMDAdd();
129 testSIMDAdd();
130 %OptimizeFunctionOnNextCall(testSIMDAdd);
131 testSIMDAdd();
132
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);
137
138   assertEquals(-1.0, c4.x);
139   assertEquals(-1.0, c4.y);
140 }
141
142 testSIMDSub();
143 testSIMDSub();
144 %OptimizeFunctionOnNextCall(testSIMDSub);
145 testSIMDSub();
146
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);
151
152   assertEquals(2.0, c4.x);
153   assertEquals(2.0, c4.y);
154 }
155
156 testSIMDMul();
157 testSIMDMul();
158 %OptimizeFunctionOnNextCall(testSIMDMul);
159 testSIMDMul();
160
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);
165
166   assertEquals(0.5, c4.x);
167   assertEquals(0.5, c4.y);
168 }
169
170 testSIMDDiv();
171 testSIMDDiv();
172 %OptimizeFunctionOnNextCall(testSIMDDiv);
173 testSIMDDiv();
174
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);
182 }
183
184 testSIMDClamp();
185 testSIMDClamp();
186 %OptimizeFunctionOnNextCall(testSIMDClamp);
187 testSIMDClamp();
188
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);
195 }
196
197 testSIMDMin();
198 testSIMDMin();
199 %OptimizeFunctionOnNextCall(testSIMDMin);
200 testSIMDMin();
201
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);
208 }
209
210 testSIMDMax();
211 testSIMDMax();
212 %OptimizeFunctionOnNextCall(testSIMDMax);
213 testSIMDMax();
214
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);
220 }
221
222 testSIMDScale();
223 testSIMDScale();
224 %OptimizeFunctionOnNextCall(testSIMDScale);
225 testSIMDScale();
226
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);
232 }
233
234 testSIMDSqrt();
235 testSIMDSqrt();
236 %OptimizeFunctionOnNextCall(testSIMDSqrt);
237 testSIMDSqrt();
238
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);
247 }
248
249 testSIMDSetters();
250 testSIMDSetters();
251 %OptimizeFunctionOnNextCall(testSIMDSetters);
252 testSIMDSetters();
253
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);
269 }
270
271 testFloat64x2ArrayBasic();
272
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);
281
282   assertEquals(a[1].x, 5);
283   assertEquals(a[1].y, 6);
284
285   assertEquals(a[2].x, 9);
286   assertEquals(a[2].y, 10);
287
288   assertEquals(a[3].x, 13);
289   assertEquals(a[3].y, 14);
290
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));
296
297   assertEquals(b.getAt(0).x, 1);
298   assertEquals(b.getAt(0).y, 2);
299
300   assertEquals(b.getAt(1).x, 5);
301   assertEquals(b.getAt(1).y, 6);
302
303   assertEquals(b.getAt(2).x, 9);
304   assertEquals(b.getAt(2).y, 10);
305
306   assertEquals(b.getAt(3).x, 13);
307   assertEquals(b.getAt(3).y, 14);
308 }
309
310 testFloat64x2ArrayGetAndSet();
311
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);
318
319   // Swap element 0 and element 3
320   var t = a[0];
321   a[0] = a[3];
322   a[3] = t;
323
324   assertEquals(a[3].x, 1);
325   assertEquals(a[3].y, 2);
326
327   assertEquals(a[1].x, 5);
328   assertEquals(a[1].y, 6);
329
330   assertEquals(a[2].x, 9);
331   assertEquals(a[2].y, 10);
332
333   assertEquals(a[0].x, 13);
334   assertEquals(a[0].y, 14);
335 }
336
337 testFloat64x2ArraySwap();
338
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);
348
349   assertEquals(a[1].x, b[1].x);
350   assertEquals(a[1].y, b[1].y);
351
352   assertEquals(a[2].x, b[2].x);
353   assertEquals(a[2].y, b[2].y);
354
355   assertEquals(a[3].x, b[3].x);
356   assertEquals(a[3].y, b[3].y);
357
358   a[2] = SIMD.float64x2(17, 18);
359
360   assertEquals(a[2].x, 17);
361   assertEquals(a[2].y, 18);
362
363   assertTrue(a[2].x != b[2].x);
364   assertTrue(a[2].y != b[2].y);
365 }
366
367 testFloat64x2ArrayCopy();
368
369 function testFloat64x2ArrayViewBasic() {
370   var a = new Float64Array(8);
371   // view with no offset.
372   var b = new Float64x2Array(a.buffer, 0);
373   // view with offset.
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);
389 }
390
391 testFloat64x2ArrayViewBasic();
392
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);
398   var start = 100;
399   for (var i = 0; i < b.length; i++) {
400     assertEquals(0.0, b[i].x);
401     assertEquals(0.0, b[i].y);
402   }
403   for (var i = 0; i < c.length; i++) {
404     assertEquals(0.0, c[i].x);
405     assertEquals(0.0, c[i].y);
406   }
407   for (var i = 0; i < d.length; i++) {
408     assertEquals(0.0, d[i].x);
409     assertEquals(0.0, d[i].y);
410   }
411   for (var i = 0; i < a.length; i++) {
412     a[i] = i+start;
413   }
414   for (var i = 0; i < b.length; i++) {
415     assertTrue(0.0 != b[i].x);
416     assertTrue(0.0 != b[i].y);
417   }
418   for (var i = 0; i < c.length; i++) {
419     assertTrue(0.0 != c[i].x);
420     assertTrue(0.0 != c[i].y);
421   }
422   for (var i = 0; i < d.length; i++) {
423     assertTrue(0.0 != d[i].x);
424     assertTrue(0.0 != d[i].y);
425   }
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);
434
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);
441
442   assertEquals(start+0, d[0].x);
443   assertEquals(start+1, d[0].y);
444 }
445
446 testFloat64x2ArrayViewValues();
447
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);
456
457   assertEquals(a[1].x, 5);
458   assertEquals(a[1].y, 6);
459
460   assertEquals(a[2].x, 9);
461   assertEquals(a[2].y, 10);
462
463   assertEquals(a[3].x, 13);
464   assertEquals(a[3].y, 14);
465
466   // Create view on a.
467   var b = new Float64Array(a.buffer);
468   assertEquals(b.length, 8);
469   assertEquals(b.byteLength, 64);
470   b[2] = 99.0;
471   b[6] = 1.0;
472
473   // Observe changes in "a"
474   assertEquals(a[0].x, 1);
475   assertEquals(a[0].y, 2);
476
477   assertEquals(a[1].x, 99.0);
478   assertEquals(a[1].y, 6);
479
480   assertEquals(a[2].x, 9);
481   assertEquals(a[2].y, 10);
482
483   assertEquals(a[3].x, 1.0);
484   assertEquals(a[3].y, 14);
485 }
486
487 testViewOnFloat64x2Array();
488
489 function testArrayOfFloat64x2() {
490   var a = [];
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);
495   }
496
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);
500   }
501 }
502
503 testArrayOfFloat64x2();