OLD | NEW |
(Empty) | |
| 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 = float32x4(1.0, 2.0, 3.0, 4.0); |
| 32 assertEquals(1.0, f4.x); |
| 33 assertEquals(2.0, f4.y); |
| 34 assertEquals(3.0, f4.z); |
| 35 assertEquals(4.0, f4.w); |
| 36 |
| 37 var new_f4 = new float32x4(1.0, 2.0, 3.0, 4.0); |
| 38 assertEquals(1.0, new_f4.x); |
| 39 assertEquals(2.0, new_f4.y); |
| 40 assertEquals(3.0, new_f4.z); |
| 41 assertEquals(4.0, new_f4.w); |
| 42 |
| 43 f4 = float32x4(1.1, 2.2, 3.3, 4.4); |
| 44 assertEquals(1.100000023841858, f4.x); |
| 45 assertEquals(2.200000047683716, f4.y); |
| 46 assertEquals(3.299999952316284, f4.z); |
| 47 assertEquals(4.400000095367432, f4.w); |
| 48 |
| 49 new_f4 = new float32x4(1.1, 2.2, 3.3, 4.4); |
| 50 assertEquals(1.100000023841858, new_f4.x); |
| 51 assertEquals(2.200000047683716, new_f4.y); |
| 52 assertEquals(3.299999952316284, new_f4.z); |
| 53 assertEquals(4.400000095367432, new_f4.w); |
| 54 } |
| 55 |
| 56 testConstructor(); |
| 57 |
| 58 function testZeroConstructor() { |
| 59 var z4 = float32x4.zero(); |
| 60 assertEquals(0.0, z4.x); |
| 61 assertEquals(0.0, z4.y); |
| 62 assertEquals(0.0, z4.z); |
| 63 assertEquals(0.0, z4.w); |
| 64 |
| 65 var new_z4 = new float32x4.zero(); |
| 66 assertEquals(0.0, new_z4.x); |
| 67 assertEquals(0.0, new_z4.y); |
| 68 assertEquals(0.0, new_z4.z); |
| 69 assertEquals(0.0, new_z4.w); |
| 70 } |
| 71 |
| 72 testZeroConstructor(); |
| 73 testZeroConstructor(); |
| 74 %OptimizeFunctionOnNextCall(testZeroConstructor); |
| 75 testZeroConstructor(); |
| 76 |
| 77 function testSplatConstructor() { |
| 78 var z4 = float32x4.splat(5.0); |
| 79 assertEquals(5.0, z4.x); |
| 80 assertEquals(5.0, z4.y); |
| 81 assertEquals(5.0, z4.z); |
| 82 assertEquals(5.0, z4.w); |
| 83 } |
| 84 |
| 85 testSplatConstructor(); |
| 86 testSplatConstructor(); |
| 87 %OptimizeFunctionOnNextCall(testSplatConstructor); |
| 88 testSplatConstructor(); |
| 89 |
| 90 function testTypeof() { |
| 91 var z4 = float32x4.zero(); |
| 92 assertEquals(typeof(z4), "float32x4"); |
| 93 |
| 94 var new_z4 = new float32x4.zero(); |
| 95 assertEquals(typeof(new_z4), "object"); |
| 96 assertEquals(typeof(new_z4.valueOf()), "float32x4"); |
| 97 assertEquals(Object.prototype.toString.call(new_z4), "[object float32x4]"); |
| 98 } |
| 99 |
| 100 testTypeof(); |
| 101 |
| 102 function testSignMaskGetter() { |
| 103 var a = float32x4(-1.0, -2.0, -3.0, -4.0); |
| 104 assertEquals(0xf, a.signMask); |
| 105 var b = float32x4(1.0, 2.0, 3.0, 4.0); |
| 106 assertEquals(0x0, b.signMask); |
| 107 var c = float32x4(1.0, -2.0, -3.0, 4.0); |
| 108 assertEquals(0x6, c.signMask); |
| 109 } |
| 110 |
| 111 testSignMaskGetter(); |
| 112 testSignMaskGetter(); |
| 113 %OptimizeFunctionOnNextCall(testSignMaskGetter); |
| 114 testSignMaskGetter(); |
| 115 |
| 116 function testSIMDAbs() { |
| 117 var a4 = float32x4(1.0, -1.0, 1.0, -1.0); |
| 118 var b4 = SIMD.float32x4.abs(a4); |
| 119 |
| 120 assertEquals(1.0, b4.x); |
| 121 assertEquals(1.0, b4.y); |
| 122 assertEquals(1.0, b4.z); |
| 123 assertEquals(1.0, b4.w); |
| 124 |
| 125 var new_a4 = new float32x4(1.0, -1.0, 1.0, -1.0); |
| 126 var new_b4 = SIMD.float32x4.abs(new_a4); |
| 127 |
| 128 assertEquals(1.0, new_b4.x); |
| 129 assertEquals(1.0, new_b4.y); |
| 130 assertEquals(1.0, new_b4.z); |
| 131 assertEquals(1.0, new_b4.w); |
| 132 } |
| 133 |
| 134 testSIMDAbs(); |
| 135 testSIMDAbs(); |
| 136 %OptimizeFunctionOnNextCall(testSIMDAbs); |
| 137 testSIMDAbs(); |
| 138 |
| 139 function testSIMDNeg() { |
| 140 var a4 = float32x4(1.0, -1.0, 1.0, -1.0); |
| 141 var b4 = SIMD.float32x4.neg(a4); |
| 142 |
| 143 assertEquals(-1.0, b4.x); |
| 144 assertEquals(1.0, b4.y); |
| 145 assertEquals(-1.0, b4.z); |
| 146 assertEquals(1.0, b4.w); |
| 147 |
| 148 var new_a4 = new float32x4(1.0, -1.0, 1.0, -1.0); |
| 149 b4 = SIMD.float32x4.neg(new_a4); |
| 150 |
| 151 assertEquals(-1.0, b4.x); |
| 152 assertEquals(1.0, b4.y); |
| 153 assertEquals(-1.0, b4.z); |
| 154 assertEquals(1.0, b4.w); |
| 155 } |
| 156 |
| 157 testSIMDNeg(); |
| 158 testSIMDNeg(); |
| 159 %OptimizeFunctionOnNextCall(testSIMDNeg); |
| 160 testSIMDNeg(); |
| 161 |
| 162 function testSIMDAdd() { |
| 163 var a4 = float32x4(1.0, 1.0, 1.0, 1.0); |
| 164 var b4 = float32x4(2.0, 2.0, 2.0, 2.0); |
| 165 var c4 = SIMD.float32x4.add(a4, b4); |
| 166 |
| 167 assertEquals(3.0, c4.x); |
| 168 assertEquals(3.0, c4.y); |
| 169 assertEquals(3.0, c4.z); |
| 170 assertEquals(3.0, c4.w); |
| 171 |
| 172 var new_a4 = new float32x4(1.0, 1.0, 1.0, 1.0); |
| 173 var new_b4 = new float32x4(2.0, 2.0, 2.0, 2.0); |
| 174 c4 = SIMD.float32x4.add(new_a4, new_b4); |
| 175 |
| 176 assertEquals(3.0, c4.x); |
| 177 assertEquals(3.0, c4.y); |
| 178 assertEquals(3.0, c4.z); |
| 179 assertEquals(3.0, c4.w); |
| 180 } |
| 181 |
| 182 testSIMDAdd(); |
| 183 testSIMDAdd(); |
| 184 %OptimizeFunctionOnNextCall(testSIMDAdd); |
| 185 testSIMDAdd(); |
| 186 |
| 187 function testSIMDSub() { |
| 188 var a4 = float32x4(1.0, 1.0, 1.0, 1.0); |
| 189 var b4 = float32x4(2.0, 2.0, 2.0, 2.0); |
| 190 var c4 = SIMD.float32x4.sub(a4, b4); |
| 191 |
| 192 assertEquals(-1.0, c4.x); |
| 193 assertEquals(-1.0, c4.y); |
| 194 assertEquals(-1.0, c4.z); |
| 195 assertEquals(-1.0, c4.w); |
| 196 |
| 197 var new_a4 = new float32x4(1.0, 1.0, 1.0, 1.0); |
| 198 var new_b4 = new float32x4(2.0, 2.0, 2.0, 2.0); |
| 199 c4 = SIMD.float32x4.sub(new_a4, new_b4); |
| 200 |
| 201 assertEquals(-1.0, c4.x); |
| 202 assertEquals(-1.0, c4.y); |
| 203 assertEquals(-1.0, c4.z); |
| 204 assertEquals(-1.0, c4.w); |
| 205 } |
| 206 |
| 207 testSIMDSub(); |
| 208 testSIMDSub(); |
| 209 %OptimizeFunctionOnNextCall(testSIMDSub); |
| 210 testSIMDSub(); |
| 211 |
| 212 function testSIMDMul() { |
| 213 var a4 = float32x4(1.0, 1.0, 1.0, 1.0); |
| 214 var b4 = float32x4(2.0, 2.0, 2.0, 2.0); |
| 215 var c4 = SIMD.float32x4.mul(a4, b4); |
| 216 |
| 217 assertEquals(2.0, c4.x); |
| 218 assertEquals(2.0, c4.y); |
| 219 assertEquals(2.0, c4.z); |
| 220 assertEquals(2.0, c4.w); |
| 221 |
| 222 var new_a4 = new float32x4(1.0, 1.0, 1.0, 1.0); |
| 223 var new_b4 = new float32x4(2.0, 2.0, 2.0, 2.0); |
| 224 c4 = SIMD.float32x4.mul(new_a4, new_b4); |
| 225 |
| 226 assertEquals(2.0, c4.x); |
| 227 assertEquals(2.0, c4.y); |
| 228 assertEquals(2.0, c4.z); |
| 229 assertEquals(2.0, c4.w); |
| 230 } |
| 231 |
| 232 testSIMDMul(); |
| 233 testSIMDMul(); |
| 234 %OptimizeFunctionOnNextCall(testSIMDMul); |
| 235 testSIMDMul(); |
| 236 |
| 237 function testSIMDDiv() { |
| 238 var a4 = float32x4(1.0, 1.0, 1.0, 1.0); |
| 239 var b4 = float32x4(2.0, 2.0, 2.0, 2.0); |
| 240 var c4 = SIMD.float32x4.div(a4, b4); |
| 241 |
| 242 assertEquals(0.5, c4.x); |
| 243 assertEquals(0.5, c4.y); |
| 244 assertEquals(0.5, c4.z); |
| 245 assertEquals(0.5, c4.w); |
| 246 |
| 247 var new_a4 = new float32x4(1.0, 1.0, 1.0, 1.0); |
| 248 var new_b4 = new float32x4(2.0, 2.0, 2.0, 2.0); |
| 249 c4 = SIMD.float32x4.div(new_a4, new_b4); |
| 250 |
| 251 assertEquals(0.5, c4.x); |
| 252 assertEquals(0.5, c4.y); |
| 253 assertEquals(0.5, c4.z); |
| 254 assertEquals(0.5, c4.w); |
| 255 } |
| 256 |
| 257 testSIMDDiv(); |
| 258 testSIMDDiv(); |
| 259 %OptimizeFunctionOnNextCall(testSIMDDiv); |
| 260 testSIMDDiv(); |
| 261 |
| 262 function testSIMDClamp() { |
| 263 var m = float32x4(1.0, -2.0, 3.0, -4.0); |
| 264 var lo = float32x4(0.0, 0.0, 0.0, 0.0); |
| 265 var hi = float32x4(2.0, 2.0, 2.0, 2.0); |
| 266 m = SIMD.float32x4.clamp(m, lo, hi); |
| 267 assertEquals(1.0, m.x); |
| 268 assertEquals(0.0, m.y); |
| 269 assertEquals(2.0, m.z); |
| 270 assertEquals(0.0, m.w); |
| 271 } |
| 272 |
| 273 testSIMDClamp(); |
| 274 testSIMDClamp(); |
| 275 %OptimizeFunctionOnNextCall(testSIMDClamp); |
| 276 testSIMDClamp(); |
| 277 |
| 278 function testSIMDMin() { |
| 279 var m = float32x4(1.0, 2.0, 3.0, 4.0); |
| 280 var n = float32x4(1.0, 0.0, 2.5, 5.0); |
| 281 m = SIMD.float32x4.min(m, n); |
| 282 assertEquals(1.0, m.x); |
| 283 assertEquals(0.0, m.y); |
| 284 assertEquals(2.5, m.z); |
| 285 assertEquals(4.0, m.w); |
| 286 } |
| 287 |
| 288 testSIMDMin(); |
| 289 testSIMDMin(); |
| 290 %OptimizeFunctionOnNextCall(testSIMDMin); |
| 291 testSIMDMin(); |
| 292 |
| 293 function testSIMDMax() { |
| 294 var m = float32x4(1.0, 2.0, 3.0, 4.0); |
| 295 var n = float32x4(1.0, 0.0, 2.5, 5.0); |
| 296 m = SIMD.float32x4.max(m, n); |
| 297 assertEquals(1.0, m.x); |
| 298 assertEquals(2.0, m.y); |
| 299 assertEquals(3.0, m.z); |
| 300 assertEquals(5.0, m.w); |
| 301 } |
| 302 |
| 303 testSIMDMax(); |
| 304 testSIMDMax(); |
| 305 %OptimizeFunctionOnNextCall(testSIMDMax); |
| 306 testSIMDMax(); |
| 307 |
| 308 function testSIMDReciprocal() { |
| 309 var m = float32x4(1.0, 4.0, 9.0, 16.0); |
| 310 m = SIMD.float32x4.reciprocal(m); |
| 311 assertTrue(Math.abs(1.0 - m.x) <= 0.001); |
| 312 assertTrue(Math.abs(0.25 - m.y) <= 0.001); |
| 313 assertTrue(Math.abs(0.1111111 - m.z) <= 0.001); |
| 314 assertTrue(Math.abs(0.0625 - m.w) <= 0.001); |
| 315 } |
| 316 |
| 317 testSIMDReciprocal(); |
| 318 testSIMDReciprocal(); |
| 319 %OptimizeFunctionOnNextCall(testSIMDReciprocal); |
| 320 testSIMDReciprocal(); |
| 321 |
| 322 function testSIMDReciprocalSqrt() { |
| 323 var m = float32x4(1.0, 0.25, 0.111111, 0.0625); |
| 324 m = SIMD.float32x4.reciprocalSqrt(m); |
| 325 assertTrue(Math.abs(1.0 - m.x) <= 0.001); |
| 326 assertTrue(Math.abs(2.0 - m.y) <= 0.001); |
| 327 assertTrue(Math.abs(3.0 - m.z) <= 0.001); |
| 328 assertTrue(Math.abs(4.0 - m.w) <= 0.001); |
| 329 } |
| 330 |
| 331 testSIMDReciprocalSqrt(); |
| 332 testSIMDReciprocalSqrt(); |
| 333 %OptimizeFunctionOnNextCall(testSIMDReciprocalSqrt); |
| 334 testSIMDReciprocalSqrt(); |
| 335 |
| 336 function testSIMDScale() { |
| 337 var m = float32x4(1.0, -2.0, 3.0, -4.0); |
| 338 m = SIMD.float32x4.scale(m, 20.0); |
| 339 assertEquals(20.0, m.x); |
| 340 assertEquals(-40.0, m.y); |
| 341 assertEquals(60.0, m.z); |
| 342 assertEquals(-80.0, m.w); |
| 343 } |
| 344 |
| 345 testSIMDScale(); |
| 346 testSIMDScale(); |
| 347 %OptimizeFunctionOnNextCall(testSIMDScale); |
| 348 testSIMDScale(); |
| 349 |
| 350 function testSIMDSqrt() { |
| 351 var m = float32x4(1.0, 4.0, 9.0, 16.0); |
| 352 m = SIMD.float32x4.sqrt(m); |
| 353 assertEquals(1.0, m.x); |
| 354 assertEquals(2.0, m.y); |
| 355 assertEquals(3.0, m.z); |
| 356 assertEquals(4.0, m.w); |
| 357 } |
| 358 |
| 359 testSIMDSqrt(); |
| 360 testSIMDSqrt(); |
| 361 %OptimizeFunctionOnNextCall(testSIMDSqrt); |
| 362 testSIMDSqrt(); |
| 363 |
| 364 function testSIMDShuffle() { |
| 365 var m = float32x4(1.0, 2.0, 3.0, 4.0); |
| 366 var xxxx = SIMD.float32x4.shuffle(m, SIMD.XXXX); |
| 367 assertEquals(1.0, xxxx.x); |
| 368 assertEquals(1.0, xxxx.y); |
| 369 assertEquals(1.0, xxxx.z); |
| 370 assertEquals(1.0, xxxx.w); |
| 371 var yyyy = SIMD.float32x4.shuffle(m, SIMD.YYYY); |
| 372 assertEquals(2.0, yyyy.x); |
| 373 assertEquals(2.0, yyyy.y); |
| 374 assertEquals(2.0, yyyy.z); |
| 375 assertEquals(2.0, yyyy.w); |
| 376 var zzzz = SIMD.float32x4.shuffle(m, SIMD.ZZZZ); |
| 377 assertEquals(3.0, zzzz.x); |
| 378 assertEquals(3.0, zzzz.y); |
| 379 assertEquals(3.0, zzzz.z); |
| 380 assertEquals(3.0, zzzz.w); |
| 381 var wwww = SIMD.float32x4.shuffle(m, SIMD.WWWW); |
| 382 assertEquals(4.0, wwww.x); |
| 383 assertEquals(4.0, wwww.y); |
| 384 assertEquals(4.0, wwww.z); |
| 385 assertEquals(4.0, wwww.w); |
| 386 var wzyx = SIMD.float32x4.shuffle(m, SIMD.WZYX); |
| 387 assertEquals(4.0, wzyx.x); |
| 388 assertEquals(3.0, wzyx.y); |
| 389 assertEquals(2.0, wzyx.z); |
| 390 assertEquals(1.0, wzyx.w); |
| 391 var wwzz = SIMD.float32x4.shuffle(m, SIMD.WWZZ); |
| 392 assertEquals(4.0, wwzz.x); |
| 393 assertEquals(4.0, wwzz.y); |
| 394 assertEquals(3.0, wwzz.z); |
| 395 assertEquals(3.0, wwzz.w); |
| 396 var xxyy = SIMD.float32x4.shuffle(m, SIMD.XXYY); |
| 397 assertEquals(1.0, xxyy.x); |
| 398 assertEquals(1.0, xxyy.y); |
| 399 assertEquals(2.0, xxyy.z); |
| 400 assertEquals(2.0, xxyy.w); |
| 401 var yyww = SIMD.float32x4.shuffle(m, SIMD.YYWW); |
| 402 assertEquals(2.0, yyww.x); |
| 403 assertEquals(2.0, yyww.y); |
| 404 assertEquals(4.0, yyww.z); |
| 405 assertEquals(4.0, yyww.w); |
| 406 } |
| 407 |
| 408 testSIMDShuffle(); |
| 409 testSIMDShuffle(); |
| 410 %OptimizeFunctionOnNextCall(testSIMDShuffle); |
| 411 testSIMDShuffle(); |
| 412 |
| 413 function testSIMDShuffleMix() { |
| 414 var a = float32x4(1.0, 2.0, 3.0, 4.0); |
| 415 var b = float32x4(5.0, 6.0, 7.0, 8.0); |
| 416 var xxxx = SIMD.float32x4.shuffleMix(a, b, SIMD.XXXX); |
| 417 assertEquals(1.0, xxxx.x); |
| 418 assertEquals(1.0, xxxx.y); |
| 419 assertEquals(5.0, xxxx.z); |
| 420 assertEquals(5.0, xxxx.w); |
| 421 var yyyy = SIMD.float32x4.shuffleMix(a, b, SIMD.YYYY); |
| 422 assertEquals(2.0, yyyy.x); |
| 423 assertEquals(2.0, yyyy.y); |
| 424 assertEquals(6.0, yyyy.z); |
| 425 assertEquals(6.0, yyyy.w); |
| 426 var zzzz = SIMD.float32x4.shuffleMix(a, b, SIMD.ZZZZ); |
| 427 assertEquals(3.0, zzzz.x); |
| 428 assertEquals(3.0, zzzz.y); |
| 429 assertEquals(7.0, zzzz.z); |
| 430 assertEquals(7.0, zzzz.w); |
| 431 var wwww = SIMD.float32x4.shuffleMix(a, b, SIMD.WWWW); |
| 432 assertEquals(4.0, wwww.x); |
| 433 assertEquals(4.0, wwww.y); |
| 434 assertEquals(8.0, wwww.z); |
| 435 assertEquals(8.0, wwww.w); |
| 436 var wzyx = SIMD.float32x4.shuffleMix(a, b, SIMD.WZYX); |
| 437 assertEquals(4.0, wzyx.x); |
| 438 assertEquals(3.0, wzyx.y); |
| 439 assertEquals(6.0, wzyx.z); |
| 440 assertEquals(5.0, wzyx.w); |
| 441 var wwzz = SIMD.float32x4.shuffleMix(a, b, SIMD.WWZZ); |
| 442 assertEquals(4.0, wwzz.x); |
| 443 assertEquals(4.0, wwzz.y); |
| 444 assertEquals(7.0, wwzz.z); |
| 445 assertEquals(7.0, wwzz.w); |
| 446 var xxyy = SIMD.float32x4.shuffleMix(a, b, SIMD.XXYY); |
| 447 assertEquals(1.0, xxyy.x); |
| 448 assertEquals(1.0, xxyy.y); |
| 449 assertEquals(6.0, xxyy.z); |
| 450 assertEquals(6.0, xxyy.w); |
| 451 var yyww = SIMD.float32x4.shuffleMix(a, b, SIMD.YYWW); |
| 452 assertEquals(2.0, yyww.x); |
| 453 assertEquals(2.0, yyww.y); |
| 454 assertEquals(8.0, yyww.z); |
| 455 assertEquals(8.0, yyww.w); |
| 456 } |
| 457 |
| 458 testSIMDShuffleMix(); |
| 459 testSIMDShuffleMix(); |
| 460 %OptimizeFunctionOnNextCall(testSIMDShuffleMix); |
| 461 testSIMDShuffleMix(); |
| 462 |
| 463 function testSIMDSetters() { |
| 464 var f = float32x4.zero(); |
| 465 assertEquals(0.0, f.x); |
| 466 assertEquals(0.0, f.y); |
| 467 assertEquals(0.0, f.z); |
| 468 assertEquals(0.0, f.w); |
| 469 f = SIMD.float32x4.withX(f, 4.0); |
| 470 assertEquals(4.0, f.x); |
| 471 f = SIMD.float32x4.withY(f, 3.0); |
| 472 assertEquals(3.0, f.y); |
| 473 f = SIMD.float32x4.withZ(f, 2.0); |
| 474 assertEquals(2.0, f.z); |
| 475 f = SIMD.float32x4.withW(f, 1.0); |
| 476 assertEquals(1.0, f.w); |
| 477 f = float32x4.zero(); |
| 478 } |
| 479 |
| 480 testSIMDSetters(); |
| 481 testSIMDSetters(); |
| 482 %OptimizeFunctionOnNextCall(testSIMDSetters); |
| 483 testSIMDSetters(); |
| 484 |
| 485 function testSIMDConversion() { |
| 486 var m = int32x4(0x3F800000, 0x40000000, 0x40400000, 0x40800000); |
| 487 var n = SIMD.int32x4.bitsToFloat32x4(m); |
| 488 assertEquals(1.0, n.x); |
| 489 assertEquals(2.0, n.y); |
| 490 assertEquals(3.0, n.z); |
| 491 assertEquals(4.0, n.w); |
| 492 n = float32x4(5.0, 6.0, 7.0, 8.0); |
| 493 m = SIMD.float32x4.bitsToInt32x4(n); |
| 494 assertEquals(0x40A00000, m.x); |
| 495 assertEquals(0x40C00000, m.y); |
| 496 assertEquals(0x40E00000, m.z); |
| 497 assertEquals(0x41000000, m.w); |
| 498 // Flip sign using bit-wise operators. |
| 499 n = float32x4(9.0, 10.0, 11.0, 12.0); |
| 500 m = int32x4(0x80000000, 0x80000000, 0x80000000, 0x80000000); |
| 501 var nMask = SIMD.float32x4.bitsToInt32x4(n); |
| 502 nMask = SIMD.int32x4.xor(nMask, m); // flip sign. |
| 503 n = SIMD.int32x4.bitsToFloat32x4(nMask); |
| 504 assertEquals(-9.0, n.x); |
| 505 assertEquals(-10.0, n.y); |
| 506 assertEquals(-11.0, n.z); |
| 507 assertEquals(-12.0, n.w); |
| 508 nMask = SIMD.float32x4.bitsToInt32x4(n); |
| 509 nMask = SIMD.int32x4.xor(nMask, m); // flip sign. |
| 510 n = SIMD.int32x4.bitsToFloat32x4(nMask); |
| 511 assertEquals(9.0, n.x); |
| 512 assertEquals(10.0, n.y); |
| 513 assertEquals(11.0, n.z); |
| 514 assertEquals(12.0, n.w); |
| 515 } |
| 516 |
| 517 testSIMDConversion(); |
| 518 testSIMDConversion(); |
| 519 %OptimizeFunctionOnNextCall(testSIMDConversion); |
| 520 testSIMDConversion(); |
| 521 |
| 522 function testSIMDConversion2() { |
| 523 var m = int32x4(1, 2, 3, 4); |
| 524 var n = SIMD.int32x4.toFloat32x4(m); |
| 525 assertEquals(1.0, n.x); |
| 526 assertEquals(2.0, n.y); |
| 527 assertEquals(3.0, n.z); |
| 528 assertEquals(4.0, n.w); |
| 529 n = float32x4(5.0, 6.0, 7.0, 8.0); |
| 530 m = SIMD.float32x4.toInt32x4(n); |
| 531 assertEquals(5, m.x); |
| 532 assertEquals(6, m.y); |
| 533 assertEquals(7, m.z); |
| 534 assertEquals(8, m.w); |
| 535 } |
| 536 |
| 537 testSIMDConversion2(); |
| 538 testSIMDConversion2(); |
| 539 %OptimizeFunctionOnNextCall(testSIMDConversion2); |
| 540 testSIMDConversion2(); |
| 541 |
| 542 |
| 543 function testSIMDComparisons() { |
| 544 var m = float32x4(1.0, 2.0, 0.1, 0.001); |
| 545 var n = float32x4(2.0, 2.0, 0.001, 0.1); |
| 546 var cmp; |
| 547 cmp = SIMD.float32x4.lessThan(m, n); |
| 548 assertEquals(-1, cmp.x); |
| 549 assertEquals(0x0, cmp.y); |
| 550 assertEquals(0x0, cmp.z); |
| 551 assertEquals(-1, cmp.w); |
| 552 |
| 553 cmp = SIMD.float32x4.lessThanOrEqual(m, n); |
| 554 assertEquals(-1, cmp.x); |
| 555 assertEquals(-1, cmp.y); |
| 556 assertEquals(0x0, cmp.z); |
| 557 assertEquals(-1, cmp.w); |
| 558 |
| 559 cmp = SIMD.float32x4.equal(m, n); |
| 560 assertEquals(0x0, cmp.x); |
| 561 assertEquals(-1, cmp.y); |
| 562 assertEquals(0x0, cmp.z); |
| 563 assertEquals(0x0, cmp.w); |
| 564 |
| 565 cmp = SIMD.float32x4.notEqual(m, n); |
| 566 assertEquals(-1, cmp.x); |
| 567 assertEquals(0x0, cmp.y); |
| 568 assertEquals(-1, cmp.z); |
| 569 assertEquals(-1, cmp.w); |
| 570 |
| 571 cmp = SIMD.float32x4.greaterThanOrEqual(m, n); |
| 572 assertEquals(0x0, cmp.x); |
| 573 assertEquals(-1, cmp.y); |
| 574 assertEquals(-1, cmp.z); |
| 575 assertEquals(0x0, cmp.w); |
| 576 |
| 577 cmp = SIMD.float32x4.greaterThan(m, n); |
| 578 assertEquals(0x0, cmp.x); |
| 579 assertEquals(0x0, cmp.y); |
| 580 assertEquals(-1, cmp.z); |
| 581 assertEquals(0x0, cmp.w); |
| 582 } |
| 583 |
| 584 testSIMDComparisons(); |
| 585 testSIMDComparisons(); |
| 586 %OptimizeFunctionOnNextCall(testSIMDComparisons); |
| 587 testSIMDComparisons(); |
| 588 |
| 589 function testFloat32x4ArrayBasic() { |
| 590 var a = new Float32x4Array(1); |
| 591 assertEquals(1, a.length); |
| 592 assertEquals(16, a.byteLength); |
| 593 assertEquals(16, a.BYTES_PER_ELEMENT); |
| 594 assertEquals(16, Float32x4Array.BYTES_PER_ELEMENT); |
| 595 assertEquals(0, a.byteOffset); |
| 596 assertTrue(undefined != a.buffer); |
| 597 var b = new Float32x4Array(4); |
| 598 assertEquals(4, b.length); |
| 599 assertEquals(64, b.byteLength); |
| 600 assertEquals(16, b.BYTES_PER_ELEMENT); |
| 601 assertEquals(16, Float32x4Array.BYTES_PER_ELEMENT); |
| 602 assertEquals(0, b.byteOffset); |
| 603 assertTrue(undefined != b.buffer); |
| 604 } |
| 605 |
| 606 testFloat32x4ArrayBasic(); |
| 607 |
| 608 function testFloat32x4ArrayGetAndSet() { |
| 609 var a = new Float32x4Array(4); |
| 610 a[0] = float32x4(1, 2, 3, 4); |
| 611 a[1] = float32x4(5, 6, 7, 8); |
| 612 a[2] = float32x4(9, 10, 11, 12); |
| 613 a[3] = float32x4(13, 14, 15, 16); |
| 614 assertEquals(a[0].x, 1); |
| 615 assertEquals(a[0].y, 2); |
| 616 assertEquals(a[0].z, 3); |
| 617 assertEquals(a[0].w, 4); |
| 618 |
| 619 assertEquals(a[1].x, 5); |
| 620 assertEquals(a[1].y, 6); |
| 621 assertEquals(a[1].z, 7); |
| 622 assertEquals(a[1].w, 8); |
| 623 |
| 624 assertEquals(a[2].x, 9); |
| 625 assertEquals(a[2].y, 10); |
| 626 assertEquals(a[2].z, 11); |
| 627 assertEquals(a[2].w, 12); |
| 628 |
| 629 assertEquals(a[3].x, 13); |
| 630 assertEquals(a[3].y, 14); |
| 631 assertEquals(a[3].z, 15); |
| 632 assertEquals(a[3].w, 16); |
| 633 |
| 634 var b = new Float32x4Array(4); |
| 635 b.setAt(0, float32x4(1, 2, 3, 4)); |
| 636 b.setAt(1, float32x4(5, 6, 7, 8)); |
| 637 b.setAt(2, float32x4(9, 10, 11, 12)); |
| 638 b.setAt(3, float32x4(13, 14, 15, 16)); |
| 639 |
| 640 assertEquals(b.getAt(0).x, 1); |
| 641 assertEquals(b.getAt(0).y, 2); |
| 642 assertEquals(b.getAt(0).z, 3); |
| 643 assertEquals(b.getAt(0).w, 4); |
| 644 |
| 645 assertEquals(b.getAt(1).x, 5); |
| 646 assertEquals(b.getAt(1).y, 6); |
| 647 assertEquals(b.getAt(1).z, 7); |
| 648 assertEquals(b.getAt(1).w, 8); |
| 649 |
| 650 assertEquals(b.getAt(2).x, 9); |
| 651 assertEquals(b.getAt(2).y, 10); |
| 652 assertEquals(b.getAt(2).z, 11); |
| 653 assertEquals(b.getAt(2).w, 12); |
| 654 |
| 655 assertEquals(b.getAt(3).x, 13); |
| 656 assertEquals(b.getAt(3).y, 14); |
| 657 assertEquals(b.getAt(3).z, 15); |
| 658 assertEquals(b.getAt(3).w, 16); |
| 659 } |
| 660 |
| 661 testFloat32x4ArrayGetAndSet(); |
| 662 testFloat32x4ArrayGetAndSet(); |
| 663 %OptimizeFunctionOnNextCall(testFloat32x4ArrayGetAndSet); |
| 664 testFloat32x4ArrayGetAndSet(); |
| 665 |
| 666 function testFloat32x4ArraySwap() { |
| 667 var a = new Float32x4Array(4); |
| 668 a[0] = float32x4(1, 2, 3, 4); |
| 669 a[1] = float32x4(5, 6, 7, 8); |
| 670 a[2] = float32x4(9, 10, 11, 12); |
| 671 a[3] = float32x4(13, 14, 15, 16); |
| 672 |
| 673 // Swap element 0 and element 3 |
| 674 var t = a[0]; |
| 675 a[0] = a[3]; |
| 676 a[3] = t; |
| 677 |
| 678 assertEquals(a[3].x, 1); |
| 679 assertEquals(a[3].y, 2); |
| 680 assertEquals(a[3].z, 3); |
| 681 assertEquals(a[3].w, 4); |
| 682 |
| 683 assertEquals(a[1].x, 5); |
| 684 assertEquals(a[1].y, 6); |
| 685 assertEquals(a[1].z, 7); |
| 686 assertEquals(a[1].w, 8); |
| 687 |
| 688 assertEquals(a[2].x, 9); |
| 689 assertEquals(a[2].y, 10); |
| 690 assertEquals(a[2].z, 11); |
| 691 assertEquals(a[2].w, 12); |
| 692 |
| 693 assertEquals(a[0].x, 13); |
| 694 assertEquals(a[0].y, 14); |
| 695 assertEquals(a[0].z, 15); |
| 696 assertEquals(a[0].w, 16); |
| 697 } |
| 698 |
| 699 testFloat32x4ArraySwap(); |
| 700 |
| 701 function testFloat32x4ArrayCopy() { |
| 702 var a = new Float32x4Array(4); |
| 703 a[0] = float32x4(1, 2, 3, 4); |
| 704 a[1] = float32x4(5, 6, 7, 8); |
| 705 a[2] = float32x4(9, 10, 11, 12); |
| 706 a[3] = float32x4(13, 14, 15, 16); |
| 707 var b = new Float32x4Array(a); |
| 708 assertEquals(a[0].x, b[0].x); |
| 709 assertEquals(a[0].y, b[0].y); |
| 710 assertEquals(a[0].z, b[0].z); |
| 711 assertEquals(a[0].w, b[0].w); |
| 712 |
| 713 assertEquals(a[1].x, b[1].x); |
| 714 assertEquals(a[1].y, b[1].y); |
| 715 assertEquals(a[1].z, b[1].z); |
| 716 assertEquals(a[1].w, b[1].w); |
| 717 |
| 718 assertEquals(a[2].x, b[2].x); |
| 719 assertEquals(a[2].y, b[2].y); |
| 720 assertEquals(a[2].z, b[2].z); |
| 721 assertEquals(a[2].w, b[2].w); |
| 722 |
| 723 assertEquals(a[3].x, b[3].x); |
| 724 assertEquals(a[3].y, b[3].y); |
| 725 assertEquals(a[3].z, b[3].z); |
| 726 assertEquals(a[3].w, b[3].w); |
| 727 |
| 728 a[2] = float32x4(17, 18, 19, 20); |
| 729 |
| 730 assertEquals(a[2].x, 17); |
| 731 assertEquals(a[2].y, 18); |
| 732 assertEquals(a[2].z, 19); |
| 733 assertEquals(a[2].w, 20); |
| 734 |
| 735 assertTrue(a[2].x != b[2].x); |
| 736 assertTrue(a[2].y != b[2].y); |
| 737 assertTrue(a[2].z != b[2].z); |
| 738 assertTrue(a[2].w != b[2].w); |
| 739 } |
| 740 |
| 741 testFloat32x4ArrayCopy(); |
| 742 |
| 743 function testFloat32x4ArrayViewBasic() { |
| 744 var a = new Float32Array(8); |
| 745 // view with no offset. |
| 746 var b = new Float32x4Array(a.buffer, 0); |
| 747 // view with offset. |
| 748 var c = new Float32x4Array(a.buffer, 16); |
| 749 // view with no offset but shorter than original list. |
| 750 var d = new Float32x4Array(a.buffer, 0, 1); |
| 751 assertEquals(a.length, 8); |
| 752 assertEquals(b.length, 2); |
| 753 assertEquals(c.length, 1); |
| 754 assertEquals(d.length, 1); |
| 755 assertEquals(a.byteLength, 32); |
| 756 assertEquals(b.byteLength, 32); |
| 757 assertEquals(c.byteLength, 16); |
| 758 assertEquals(d.byteLength, 16) |
| 759 assertEquals(a.byteOffset, 0); |
| 760 assertEquals(b.byteOffset, 0); |
| 761 assertEquals(c.byteOffset, 16); |
| 762 assertEquals(d.byteOffset, 0); |
| 763 } |
| 764 |
| 765 testFloat32x4ArrayViewBasic(); |
| 766 |
| 767 function testFloat32x4ArrayViewValues() { |
| 768 var a = new Float32Array(8); |
| 769 var b = new Float32x4Array(a.buffer, 0); |
| 770 var c = new Float32x4Array(a.buffer, 16); |
| 771 var d = new Float32x4Array(a.buffer, 0, 1); |
| 772 var start = 100; |
| 773 for (var i = 0; i < b.length; i++) { |
| 774 assertEquals(0.0, b[i].x); |
| 775 assertEquals(0.0, b[i].y); |
| 776 assertEquals(0.0, b[i].z); |
| 777 assertEquals(0.0, b[i].w); |
| 778 } |
| 779 for (var i = 0; i < c.length; i++) { |
| 780 assertEquals(0.0, c[i].x); |
| 781 assertEquals(0.0, c[i].y); |
| 782 assertEquals(0.0, c[i].z); |
| 783 assertEquals(0.0, c[i].w); |
| 784 } |
| 785 for (var i = 0; i < d.length; i++) { |
| 786 assertEquals(0.0, d[i].x); |
| 787 assertEquals(0.0, d[i].y); |
| 788 assertEquals(0.0, d[i].z); |
| 789 assertEquals(0.0, d[i].w); |
| 790 } |
| 791 for (var i = 0; i < a.length; i++) { |
| 792 a[i] = i+start; |
| 793 } |
| 794 for (var i = 0; i < b.length; i++) { |
| 795 assertTrue(0.0 != b[i].x); |
| 796 assertTrue(0.0 != b[i].y); |
| 797 assertTrue(0.0 != b[i].z); |
| 798 assertTrue(0.0 != b[i].w); |
| 799 } |
| 800 for (var i = 0; i < c.length; i++) { |
| 801 assertTrue(0.0 != c[i].x); |
| 802 assertTrue(0.0 != c[i].y); |
| 803 assertTrue(0.0 != c[i].z); |
| 804 assertTrue(0.0 != c[i].w); |
| 805 } |
| 806 for (var i = 0; i < d.length; i++) { |
| 807 assertTrue(0.0 != d[i].x); |
| 808 assertTrue(0.0 != d[i].y); |
| 809 assertTrue(0.0 != d[i].z); |
| 810 assertTrue(0.0 != d[i].w); |
| 811 } |
| 812 assertEquals(start+0, b[0].x); |
| 813 assertEquals(start+1, b[0].y); |
| 814 assertEquals(start+2, b[0].z); |
| 815 assertEquals(start+3, b[0].w); |
| 816 assertEquals(start+4, b[1].x); |
| 817 assertEquals(start+5, b[1].y); |
| 818 assertEquals(start+6, b[1].z); |
| 819 assertEquals(start+7, b[1].w); |
| 820 |
| 821 assertEquals(start+4, c[0].x); |
| 822 assertEquals(start+5, c[0].y); |
| 823 assertEquals(start+6, c[0].z); |
| 824 assertEquals(start+7, c[0].w); |
| 825 |
| 826 assertEquals(start+0, d[0].x); |
| 827 assertEquals(start+1, d[0].y); |
| 828 assertEquals(start+2, d[0].z); |
| 829 assertEquals(start+3, d[0].w); |
| 830 } |
| 831 |
| 832 testFloat32x4ArrayViewValues(); |
| 833 |
| 834 function testViewOnFloat32x4Array() { |
| 835 var a = new Float32x4Array(4); |
| 836 a[0] = float32x4(1, 2, 3, 4); |
| 837 a[1] = float32x4(5, 6, 7, 8); |
| 838 a[2] = float32x4(9, 10, 11, 12); |
| 839 a[3] = float32x4(13, 14, 15, 16); |
| 840 assertEquals(a[0].x, 1); |
| 841 assertEquals(a[0].y, 2); |
| 842 assertEquals(a[0].z, 3); |
| 843 assertEquals(a[0].w, 4); |
| 844 |
| 845 assertEquals(a[1].x, 5); |
| 846 assertEquals(a[1].y, 6); |
| 847 assertEquals(a[1].z, 7); |
| 848 assertEquals(a[1].w, 8); |
| 849 |
| 850 assertEquals(a[2].x, 9); |
| 851 assertEquals(a[2].y, 10); |
| 852 assertEquals(a[2].z, 11); |
| 853 assertEquals(a[2].w, 12); |
| 854 |
| 855 assertEquals(a[3].x, 13); |
| 856 assertEquals(a[3].y, 14); |
| 857 assertEquals(a[3].z, 15); |
| 858 assertEquals(a[3].w, 16); |
| 859 |
| 860 // Create view on a. |
| 861 var b = new Float32Array(a.buffer); |
| 862 assertEquals(b.length, 16); |
| 863 assertEquals(b.byteLength, 64); |
| 864 b[2] = 99.0; |
| 865 b[6] = 1.0; |
| 866 |
| 867 // Observe changes in "a" |
| 868 assertEquals(a[0].x, 1); |
| 869 assertEquals(a[0].y, 2); |
| 870 assertEquals(a[0].z, 99); |
| 871 assertEquals(a[0].w, 4); |
| 872 |
| 873 assertEquals(a[1].x, 5); |
| 874 assertEquals(a[1].y, 6); |
| 875 assertEquals(a[1].z, 1); |
| 876 assertEquals(a[1].w, 8); |
| 877 |
| 878 assertEquals(a[2].x, 9); |
| 879 assertEquals(a[2].y, 10); |
| 880 assertEquals(a[2].z, 11); |
| 881 assertEquals(a[2].w, 12); |
| 882 |
| 883 assertEquals(a[3].x, 13); |
| 884 assertEquals(a[3].y, 14); |
| 885 assertEquals(a[3].z, 15); |
| 886 assertEquals(a[3].w, 16); |
| 887 } |
| 888 |
| 889 testViewOnFloat32x4Array(); |
| 890 |
| 891 function testArrayOfFloat32x4() { |
| 892 var a = []; |
| 893 var a4 = new Float32x4Array(2); |
| 894 for (var i = 0; i < a4.length; i++) { |
| 895 a[i] = float32x4(i, i + 1, i + 2, i + 3); |
| 896 a4[i] = float32x4(i, i + 1, i + 2, i + 3); |
| 897 } |
| 898 |
| 899 for (var i = 0; i < a4.length; i++) { |
| 900 assertEquals(a[i].x, a4[i].x); |
| 901 assertEquals(a[i].y, a4[i].y); |
| 902 assertEquals(a[i].z, a4[i].z); |
| 903 assertEquals(a[i].w, a4[i].w); |
| 904 } |
| 905 } |
| 906 |
| 907 testArrayOfFloat32x4(); |
OLD | NEW |