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 testArithmeticOperators() {
31 var a = SIMD.float32x4.zero();
32 var b = SIMD.float32x4.zero();
36 assertEquals('float32x4(0,0,0,0)float32x4(0,0,0,0)', c);
51 testArithmeticOperators();
52 testArithmeticOperators();
53 %OptimizeFunctionOnNextCall(testArithmeticOperators);
54 testArithmeticOperators();
57 function testBitwiseOperators() {
58 var a = SIMD.float32x4.zero();
59 var b = SIMD.float32x4.zero();
77 testBitwiseOperators();
78 testBitwiseOperators();
79 %OptimizeFunctionOnNextCall(testBitwiseOperators);
80 testBitwiseOperators();
83 function testAssignmentOperators() {
84 var a = SIMD.float32x4.zero();
85 var b = SIMD.float32x4.zero();
88 assertEquals('float32x4(0,0,0,0)float32x4(0,0,0,0)', c);
112 testAssignmentOperators();
113 testAssignmentOperators();
114 %OptimizeFunctionOnNextCall(testAssignmentOperators);
115 testAssignmentOperators();
118 function testStringOperators() {
119 var a = SIMD.float32x4.zero();
123 assertEquals("float32x4(0,0,0,0)0", c);
125 assertEquals("0float32x4(0,0,0,0)", c);
128 testStringOperators();
129 testStringOperators();
130 %OptimizeFunctionOnNextCall(testStringOperators);
131 testStringOperators();
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);
147 testComparisionOperators();
148 testComparisionOperators();
149 // TODO(ningxin): optimized code will get opposite result.
150 //%OptimizeFunctionOnNextCall(testComparisionOperators);
151 testComparisionOperators();
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);
168 testLogicalOperators();
169 testLogicalOperators();
170 %OptimizeFunctionOnNextCall(testLogicalOperators);
171 testLogicalOperators();
174 function testConditionalOperators() {
175 var a = SIMD.int32x4.zero();
180 testConditionalOperators();
181 testConditionalOperators();
182 %OptimizeFunctionOnNextCall(testConditionalOperators);
183 testConditionalOperators();