Upstream version 10.39.233.0
[platform/framework/web/crosswalk.git] / src / v8 / test / mjsunit / simd / builtin_operator.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 testArithmeticOperators() {
31   var a = SIMD.float32x4.zero();
32   var b = SIMD.float32x4.zero();
33   var c;
34
35   c = a + b;
36   assertEquals('float32x4(0,0,0,0)float32x4(0,0,0,0)', c);
37   c = a++;
38   assertEquals(NaN, c);
39   c = a - b;
40   assertEquals(NaN, c);
41   c = a--;
42   assertEquals(NaN, c);
43   c = a * b;
44   assertEquals(NaN, c);
45   c = a / b;
46   assertEquals(NaN, c);
47   c = a % b;
48   assertEquals(NaN, c);
49 }
50
51 testArithmeticOperators();
52 testArithmeticOperators();
53 %OptimizeFunctionOnNextCall(testArithmeticOperators);
54 testArithmeticOperators();
55
56
57 function testBitwiseOperators() {
58   var a = SIMD.float32x4.zero();
59   var b = SIMD.float32x4.zero();
60   var c;
61   c = a | b;
62   assertEquals(0, c);
63   c = a & b;
64   assertEquals(0, c);
65   c = a ^ b;
66   assertEquals(0, c);
67   c = ~a;
68   assertEquals(-1, c);
69   c = a << 0;
70   assertEquals(0, c);
71   c = a >> 0;
72   assertEquals(0, c);
73   c = a >>> 0;
74   assertEquals(0, c);
75 }
76
77 testBitwiseOperators();
78 testBitwiseOperators();
79 %OptimizeFunctionOnNextCall(testBitwiseOperators);
80 testBitwiseOperators();
81
82
83 function testAssignmentOperators() {
84   var a = SIMD.float32x4.zero();
85   var b = SIMD.float32x4.zero();
86   var c = a;
87   c += b;
88   assertEquals('float32x4(0,0,0,0)float32x4(0,0,0,0)', c);
89   c -= b;
90   assertEquals(NaN, c);
91   c *= b;
92   assertEquals(NaN, c);
93   c /= b;
94   assertEquals(NaN, c);
95   c %= b;
96   assertEquals(NaN, c);
97
98   c &= b;
99   assertEquals(0, c);
100   c |= b;
101   assertEquals(0, c);
102   c ^= b;
103   assertEquals(0, c);
104   c <<= b;
105   assertEquals(0, c);
106   c >>= b;
107   assertEquals(0, c);
108   c >>>= b;
109   assertEquals(0, c);
110 }
111
112 testAssignmentOperators();
113 testAssignmentOperators();
114 %OptimizeFunctionOnNextCall(testAssignmentOperators);
115 testAssignmentOperators();
116
117
118 function testStringOperators() {
119   var a = SIMD.float32x4.zero();
120   var b = "0";
121   var c = a;
122   c += b;
123   assertEquals("float32x4(0,0,0,0)0", c);
124   c = b + a;
125   assertEquals("0float32x4(0,0,0,0)", c);
126 }
127
128 testStringOperators();
129 testStringOperators();
130 %OptimizeFunctionOnNextCall(testStringOperators);
131 testStringOperators();
132
133
134 function testComparisionOperators() {
135   var a = SIMD.float32x4.zero();
136   var b = SIMD.float32x4.zero();
137   assertEquals(false, a == b);
138   assertEquals(true, a != b);
139   assertEquals(false, a === b);
140   assertEquals(true, a !== b);
141   assertEquals(false, a > b);
142   assertEquals(true, a >= b);
143   assertEquals(false, a < b);
144   assertEquals(true, a <= b);
145 }
146
147 testComparisionOperators();
148 testComparisionOperators();
149 // TODO(ningxin): optimized code will get opposite result.
150 //%OptimizeFunctionOnNextCall(testComparisionOperators);
151 testComparisionOperators();
152
153
154 function testLogicalOperators() {
155   var a = SIMD.float32x4.zero();
156   var b = SIMD.float32x4.splat(1);
157   assertEquals(1, (a && b).x);
158   assertEquals(1, (a && b).y);
159   assertEquals(1, (a && b).z);
160   assertEquals(1, (a && b).w);
161   assertEquals(0, (a || b).x);
162   assertEquals(0, (a || b).y);
163   assertEquals(0, (a || b).z);
164   assertEquals(0, (a || b).w);
165   assertEquals(false, !a);
166 }
167
168 testLogicalOperators();
169 testLogicalOperators();
170 %OptimizeFunctionOnNextCall(testLogicalOperators);
171 testLogicalOperators();
172
173
174 function testConditionalOperators() {
175   var a = SIMD.int32x4.zero();
176   var c = a ? 1 : 0;
177   assertEquals(1, c);
178 }
179
180 testConditionalOperators();
181 testConditionalOperators();
182 %OptimizeFunctionOnNextCall(testConditionalOperators);
183 testConditionalOperators();