Upstream version 11.40.271.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 test1ArgumentConstructor() {
46   var f2 = SIMD.float64x2(1.0, 2.0);
47   var f2_new = SIMD.float64x2(f2);
48   assertEquals(f2_new.x, f2.x);
49   assertEquals(f2_new.y, f2.y);
50
51   f2 = SIMD.float64x2(1.1, 2.2);
52   f2_new = SIMD.float64x2(f2);
53   assertEquals(f2_new.x, f2.x);
54   assertEquals(f2_new.y, f2.y);
55 }
56
57 test1ArgumentConstructor();
58 test1ArgumentConstructor();
59 %OptimizeFunctionOnNextCall(test1ArgumentConstructor);
60 test1ArgumentConstructor();
61
62 function testZeroConstructor() {
63   var z4 = SIMD.float64x2.zero();
64   assertEquals(0.0, z4.x);
65   assertEquals(0.0, z4.y);
66 }
67
68 testZeroConstructor();
69 testZeroConstructor();
70 %OptimizeFunctionOnNextCall(testZeroConstructor);
71 testZeroConstructor();
72
73 function testSplatConstructor() {
74   var z4 = SIMD.float64x2.splat(5.0);
75   assertEquals(5.0, z4.x);
76   assertEquals(5.0, z4.y);
77 }
78
79 testSplatConstructor();
80 testSplatConstructor();
81 %OptimizeFunctionOnNextCall(testSplatConstructor);
82 testSplatConstructor();
83
84 function testTypeof() {
85   var z4 = SIMD.float64x2.zero();
86   assertEquals(typeof(z4), "object");
87
88   var new_z4 = new SIMD.float64x2(0, 0);
89   assertEquals(typeof(new_z4), "object");
90   assertEquals(typeof(new_z4.valueOf()), "object");
91   assertEquals(Object.prototype.toString.call(new_z4), "[object Object]");
92 }
93
94 testTypeof();
95
96 function testSignMaskGetter() {
97   var a = SIMD.float64x2(-1.0, -2.0);
98   assertEquals(0x3, a.signMask);
99   var b = SIMD.float64x2(1.0, 2.0);
100   assertEquals(0x0, b.signMask);
101   var c = SIMD.float64x2(1.0, -2.0);
102   assertEquals(0x2, c.signMask);
103 }
104
105 testSignMaskGetter();
106 testSignMaskGetter();
107 %OptimizeFunctionOnNextCall(testSignMaskGetter);
108 testSignMaskGetter();
109
110 function testSIMDAbs() {
111   var a4 = SIMD.float64x2(1.0, -1.0);
112   var b4 = SIMD.float64x2.abs(a4);
113
114   assertEquals(1.0, b4.x);
115   assertEquals(1.0, b4.y);
116 }
117
118 testSIMDAbs();
119 testSIMDAbs();
120 %OptimizeFunctionOnNextCall(testSIMDAbs);
121 testSIMDAbs();
122
123 function testSIMDNeg() {
124   var a4 = SIMD.float64x2(1.0, -1.0);
125   var b4 = SIMD.float64x2.neg(a4);
126
127   assertEquals(-1.0, b4.x);
128   assertEquals(1.0, b4.y);
129 }
130
131 testSIMDNeg();
132 testSIMDNeg();
133 %OptimizeFunctionOnNextCall(testSIMDNeg);
134 testSIMDNeg();
135
136 function testSIMDAdd() {
137   var a4 = SIMD.float64x2(1.0, 1.0);
138   var b4 = SIMD.float64x2(2.0, 2.0);
139   var c4 = SIMD.float64x2.add(a4, b4);
140
141   assertEquals(3.0, c4.x);
142   assertEquals(3.0, c4.y);
143 }
144
145 testSIMDAdd();
146 testSIMDAdd();
147 %OptimizeFunctionOnNextCall(testSIMDAdd);
148 testSIMDAdd();
149
150 function testSIMDSub() {
151   var a4 = SIMD.float64x2(1.0, 1.0);
152   var b4 = SIMD.float64x2(2.0, 2.0);
153   var c4 = SIMD.float64x2.sub(a4, b4);
154
155   assertEquals(-1.0, c4.x);
156   assertEquals(-1.0, c4.y);
157 }
158
159 testSIMDSub();
160 testSIMDSub();
161 %OptimizeFunctionOnNextCall(testSIMDSub);
162 testSIMDSub();
163
164 function testSIMDMul() {
165   var a4 = SIMD.float64x2(1.0, 1.0);
166   var b4 = SIMD.float64x2(2.0, 2.0);
167   var c4 = SIMD.float64x2.mul(a4, b4);
168
169   assertEquals(2.0, c4.x);
170   assertEquals(2.0, c4.y);
171 }
172
173 testSIMDMul();
174 testSIMDMul();
175 %OptimizeFunctionOnNextCall(testSIMDMul);
176 testSIMDMul();
177
178 function testSIMDDiv() {
179   var a4 = SIMD.float64x2(1.0, 1.0);
180   var b4 = SIMD.float64x2(2.0, 2.0);
181   var c4 = SIMD.float64x2.div(a4, b4);
182
183   assertEquals(0.5, c4.x);
184   assertEquals(0.5, c4.y);
185 }
186
187 testSIMDDiv();
188 testSIMDDiv();
189 %OptimizeFunctionOnNextCall(testSIMDDiv);
190 testSIMDDiv();
191
192 function testSIMDClamp() {
193   var m = SIMD.float64x2(1.0, -2.0);
194   var lo = SIMD.float64x2(0.0, 0.0);
195   var hi = SIMD.float64x2(2.0, 2.0);
196   m = SIMD.float64x2.clamp(m, lo, hi);
197   assertEquals(1.0, m.x);
198   assertEquals(0.0, m.y);
199 }
200
201 testSIMDClamp();
202 testSIMDClamp();
203 %OptimizeFunctionOnNextCall(testSIMDClamp);
204 testSIMDClamp();
205
206 function testSIMDMin() {
207   var m = SIMD.float64x2(1.0, 2.0);
208   var n = SIMD.float64x2(1.0, 0.0);
209   m = SIMD.float64x2.min(m, n);
210   assertEquals(1.0, m.x);
211   assertEquals(0.0, m.y);
212 }
213
214 testSIMDMin();
215 testSIMDMin();
216 %OptimizeFunctionOnNextCall(testSIMDMin);
217 testSIMDMin();
218
219 function testSIMDMax() {
220   var m = SIMD.float64x2(1.0, 2.0);
221   var n = SIMD.float64x2(1.0, 0.0);
222   m = SIMD.float64x2.max(m, n);
223   assertEquals(1.0, m.x);
224   assertEquals(2.0, m.y);
225 }
226
227 testSIMDMax();
228 testSIMDMax();
229 %OptimizeFunctionOnNextCall(testSIMDMax);
230 testSIMDMax();
231
232 function testSIMDScale() {
233   var m = SIMD.float64x2(1.0, -2.0);
234   m = SIMD.float64x2.scale(m, 20.0);
235   assertEquals(20.0, m.x);
236   assertEquals(-40.0, m.y);
237 }
238
239 testSIMDScale();
240 testSIMDScale();
241 %OptimizeFunctionOnNextCall(testSIMDScale);
242 testSIMDScale();
243
244 function testSIMDSqrt() {
245   var m = SIMD.float64x2(1.0, 4.0);
246   m = SIMD.float64x2.sqrt(m);
247   assertEquals(1.0, m.x);
248   assertEquals(2.0, m.y);
249 }
250
251 testSIMDSqrt();
252 testSIMDSqrt();
253 %OptimizeFunctionOnNextCall(testSIMDSqrt);
254 testSIMDSqrt();
255
256 function testSIMDSetters() {
257   var f = SIMD.float64x2.zero();
258   assertEquals(0.0, f.x);
259   assertEquals(0.0, f.y);
260   f = SIMD.float64x2.withX(f, 4.0);
261   assertEquals(4.0, f.x);
262   f = SIMD.float64x2.withY(f, 3.0);
263   assertEquals(3.0, f.y);
264 }
265
266 testSIMDSetters();
267 testSIMDSetters();
268 %OptimizeFunctionOnNextCall(testSIMDSetters);
269 testSIMDSetters();
270
271 function testFloat64x2ArrayBasic() {
272   var a = new Float64x2Array(1);
273   assertEquals(1, a.length);
274   assertEquals(16, a.byteLength);
275   assertEquals(16, a.BYTES_PER_ELEMENT);
276   assertEquals(16, Float64x2Array.BYTES_PER_ELEMENT);
277   assertEquals(0, a.byteOffset);
278   assertTrue(undefined != a.buffer);
279   var b = new Float64x2Array(4);
280   assertEquals(4, b.length);
281   assertEquals(64, b.byteLength);
282   assertEquals(16, b.BYTES_PER_ELEMENT);
283   assertEquals(16, Float64x2Array.BYTES_PER_ELEMENT);
284   assertEquals(0, b.byteOffset);
285   assertTrue(undefined != b.buffer);
286 }
287
288 testFloat64x2ArrayBasic();
289
290 function testFloat64x2ArrayGetAndSet() {
291   var a = new Float64x2Array(4);
292   a[0] = SIMD.float64x2(1, 2);
293   a[1] = SIMD.float64x2(5, 6);
294   a[2] = SIMD.float64x2(9, 10);
295   a[3] = SIMD.float64x2(13, 14);
296   assertEquals(a[0].x, 1);
297   assertEquals(a[0].y, 2);
298
299   assertEquals(a[1].x, 5);
300   assertEquals(a[1].y, 6);
301
302   assertEquals(a[2].x, 9);
303   assertEquals(a[2].y, 10);
304
305   assertEquals(a[3].x, 13);
306   assertEquals(a[3].y, 14);
307
308   var b = new Float64x2Array(4);
309   b.setAt(0,SIMD.float64x2(1, 2));
310   b.setAt(1,SIMD.float64x2(5, 6));
311   b.setAt(2,SIMD.float64x2(9, 10));
312   b.setAt(3,SIMD.float64x2(13, 14));
313
314   assertEquals(b.getAt(0).x, 1);
315   assertEquals(b.getAt(0).y, 2);
316
317   assertEquals(b.getAt(1).x, 5);
318   assertEquals(b.getAt(1).y, 6);
319
320   assertEquals(b.getAt(2).x, 9);
321   assertEquals(b.getAt(2).y, 10);
322
323   assertEquals(b.getAt(3).x, 13);
324   assertEquals(b.getAt(3).y, 14);
325 }
326
327 testFloat64x2ArrayGetAndSet();
328
329 function testFloat64x2ArraySwap() {
330   var a = new Float64x2Array(4);
331   a[0] = SIMD.float64x2(1, 2);
332   a[1] = SIMD.float64x2(5, 6);
333   a[2] = SIMD.float64x2(9, 10);
334   a[3] = SIMD.float64x2(13, 14);
335
336   // Swap element 0 and element 3
337   var t = a[0];
338   a[0] = a[3];
339   a[3] = t;
340
341   assertEquals(a[3].x, 1);
342   assertEquals(a[3].y, 2);
343
344   assertEquals(a[1].x, 5);
345   assertEquals(a[1].y, 6);
346
347   assertEquals(a[2].x, 9);
348   assertEquals(a[2].y, 10);
349
350   assertEquals(a[0].x, 13);
351   assertEquals(a[0].y, 14);
352 }
353
354 testFloat64x2ArraySwap();
355
356 function testFloat64x2ArrayCopy() {
357   var a = new Float64x2Array(4);
358   a[0] = SIMD.float64x2(1, 2);
359   a[1] = SIMD.float64x2(5, 6);
360   a[2] = SIMD.float64x2(9, 10);
361   a[3] = SIMD.float64x2(13, 14);
362   var b = new Float64x2Array(a);
363   assertEquals(a[0].x, b[0].x);
364   assertEquals(a[0].y, b[0].y);
365
366   assertEquals(a[1].x, b[1].x);
367   assertEquals(a[1].y, b[1].y);
368
369   assertEquals(a[2].x, b[2].x);
370   assertEquals(a[2].y, b[2].y);
371
372   assertEquals(a[3].x, b[3].x);
373   assertEquals(a[3].y, b[3].y);
374
375   a[2] = SIMD.float64x2(17, 18);
376
377   assertEquals(a[2].x, 17);
378   assertEquals(a[2].y, 18);
379
380   assertTrue(a[2].x != b[2].x);
381   assertTrue(a[2].y != b[2].y);
382 }
383
384 testFloat64x2ArrayCopy();
385
386 function testFloat64x2ArrayViewBasic() {
387   var a = new Float64Array(8);
388   // view with no offset.
389   var b = new Float64x2Array(a.buffer, 0);
390   // view with offset.
391   var c = new Float64x2Array(a.buffer, 16);
392   // view with no offset but shorter than original list.
393   var d = new Float64x2Array(a.buffer, 0, 1);
394   assertEquals(a.length, 8);
395   assertEquals(b.length, 4);
396   assertEquals(c.length, 3);
397   assertEquals(d.length, 1);
398   assertEquals(a.byteLength, 64);
399   assertEquals(b.byteLength, 64);
400   assertEquals(c.byteLength, 48);
401   assertEquals(d.byteLength, 16)
402   assertEquals(a.byteOffset, 0);
403   assertEquals(b.byteOffset, 0);
404   assertEquals(c.byteOffset, 16);
405   assertEquals(d.byteOffset, 0);
406 }
407
408 testFloat64x2ArrayViewBasic();
409
410 function testFloat64x2ArrayViewValues() {
411   var a = new Float64Array(8);
412   var b = new Float64x2Array(a.buffer, 0);
413   var c = new Float64x2Array(a.buffer, 16);
414   var d = new Float64x2Array(a.buffer, 0, 1);
415   var start = 100;
416   for (var i = 0; i < b.length; i++) {
417     assertEquals(0.0, b[i].x);
418     assertEquals(0.0, b[i].y);
419   }
420   for (var i = 0; i < c.length; i++) {
421     assertEquals(0.0, c[i].x);
422     assertEquals(0.0, c[i].y);
423   }
424   for (var i = 0; i < d.length; i++) {
425     assertEquals(0.0, d[i].x);
426     assertEquals(0.0, d[i].y);
427   }
428   for (var i = 0; i < a.length; i++) {
429     a[i] = i+start;
430   }
431   for (var i = 0; i < b.length; i++) {
432     assertTrue(0.0 != b[i].x);
433     assertTrue(0.0 != b[i].y);
434   }
435   for (var i = 0; i < c.length; i++) {
436     assertTrue(0.0 != c[i].x);
437     assertTrue(0.0 != c[i].y);
438   }
439   for (var i = 0; i < d.length; i++) {
440     assertTrue(0.0 != d[i].x);
441     assertTrue(0.0 != d[i].y);
442   }
443   assertEquals(start+0, b[0].x);
444   assertEquals(start+1, b[0].y);
445   assertEquals(start+2, b[1].x);
446   assertEquals(start+3, b[1].y);
447   assertEquals(start+4, b[2].x);
448   assertEquals(start+5, b[2].y);
449   assertEquals(start+6, b[3].x);
450   assertEquals(start+7, b[3].y);
451
452   assertEquals(start+2, c[0].x);
453   assertEquals(start+3, c[0].y);
454   assertEquals(start+4, c[1].x);
455   assertEquals(start+5, c[1].y);
456   assertEquals(start+6, c[2].x);
457   assertEquals(start+7, c[2].y);
458
459   assertEquals(start+0, d[0].x);
460   assertEquals(start+1, d[0].y);
461 }
462
463 testFloat64x2ArrayViewValues();
464
465 function testViewOnFloat64x2Array() {
466   var a = new Float64x2Array(4);
467   a[0] = SIMD.float64x2(1, 2);
468   a[1] = SIMD.float64x2(5, 6);
469   a[2] = SIMD.float64x2(9, 10);
470   a[3] = SIMD.float64x2(13, 14);
471   assertEquals(a[0].x, 1);
472   assertEquals(a[0].y, 2);
473
474   assertEquals(a[1].x, 5);
475   assertEquals(a[1].y, 6);
476
477   assertEquals(a[2].x, 9);
478   assertEquals(a[2].y, 10);
479
480   assertEquals(a[3].x, 13);
481   assertEquals(a[3].y, 14);
482
483   // Create view on a.
484   var b = new Float64Array(a.buffer);
485   assertEquals(b.length, 8);
486   assertEquals(b.byteLength, 64);
487   b[2] = 99.0;
488   b[6] = 1.0;
489
490   // Observe changes in "a"
491   assertEquals(a[0].x, 1);
492   assertEquals(a[0].y, 2);
493
494   assertEquals(a[1].x, 99.0);
495   assertEquals(a[1].y, 6);
496
497   assertEquals(a[2].x, 9);
498   assertEquals(a[2].y, 10);
499
500   assertEquals(a[3].x, 1.0);
501   assertEquals(a[3].y, 14);
502 }
503
504 testViewOnFloat64x2Array();
505
506 function testArrayOfFloat64x2() {
507   var a = [];
508   var a4 = new Float64x2Array(2);
509   for (var i = 0; i < a4.length; i++) {
510     a[i] = SIMD.float64x2(i, i + 1);
511     a4[i] = SIMD.float64x2(i, i + 1);
512   }
513
514   for (var i = 0; i < a4.length; i++) {
515     assertEquals(a[i].x, a4[i].x);
516     assertEquals(a[i].y, a4[i].y);
517   }
518 }
519
520 testArrayOfFloat64x2();