1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @modules jdk.incubator.vector 27 * @run testng/othervm -ea -esa Short128VectorTests 28 */ 29 30 import jdk.incubator.vector.Vector.Shape; 31 import jdk.incubator.vector.Vector; 32 33 import jdk.incubator.vector.ShortVector; 34 35 import org.testng.Assert; 36 import org.testng.annotations.DataProvider; 37 import org.testng.annotations.Test; 38 39 import java.lang.Integer; 40 import java.util.List; 41 import java.util.function.BiFunction; 42 import java.util.function.IntFunction; 43 import java.util.stream.Collectors; 44 import java.util.stream.Stream; 45 46 @Test 47 public class Short128VectorTests extends AbstractVectorTest { 48 49 static final ShortVector.ShortSpecies SPECIES = 50 ShortVector.species(Shape.S_128_BIT); 51 52 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); 53 54 interface FUnOp { 55 short apply(short a); 56 } 57 58 static void assertArraysEquals(short[] a, short[] r, FUnOp f) { 59 int i = 0; 60 try { 61 for (; i < a.length; i++) { 62 Assert.assertEquals(r[i], f.apply(a[i])); 63 } 64 } catch (AssertionError e) { 65 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]); 66 } 67 } 68 69 static void assertArraysEquals(short[] a, short[] r, boolean[] mask, FUnOp f) { 70 int i = 0; 71 try { 72 for (; i < a.length; i++) { 73 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]); 74 } 75 } catch (AssertionError e) { 76 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i], "at index #" + i + ", input = " + a[i] + ", mask = " + mask[i % SPECIES.length()]); 77 } 78 } 79 80 interface FReductionOp { 81 short apply(short[] a, int idx); 82 } 83 84 interface FReductionAllOp { 85 short apply(short[] a); 86 } 87 88 static void assertReductionArraysEquals(short[] a, short[] b, short c, 89 FReductionOp f, FReductionAllOp fa) { 90 int i = 0; 91 try { 92 Assert.assertEquals(c, fa.apply(a)); 93 for (; i < a.length; i += SPECIES.length()) { 94 Assert.assertEquals(b[i], f.apply(a, i)); 95 } 96 } catch (AssertionError e) { 97 Assert.assertEquals(c, fa.apply(a), "Final result is incorrect!"); 98 Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i); 99 } 100 } 101 102 interface FBoolReductionOp { 103 boolean apply(boolean[] a, int idx); 104 } 105 106 static void assertReductionBoolArraysEquals(boolean[] a, boolean[] b, FBoolReductionOp f) { 107 int i = 0; 108 try { 109 for (; i < a.length; i += SPECIES.length()) { 110 Assert.assertEquals(f.apply(a, i), b[i]); 111 } 112 } catch (AssertionError e) { 113 Assert.assertEquals(f.apply(a, i), b[i], "at index #" + i); 114 } 115 } 116 117 static void assertInsertArraysEquals(short[] a, short[] b, short element, int index) { 118 int i = 0; 119 try { 120 for (; i < a.length; i += 1) { 121 if(i%SPECIES.length() == index) { 122 Assert.assertEquals(b[i], element); 123 } else { 124 Assert.assertEquals(b[i], a[i]); 125 } 126 } 127 } catch (AssertionError e) { 128 if (i%SPECIES.length() == index) { 129 Assert.assertEquals(b[i], element, "at index #" + i); 130 } else { 131 Assert.assertEquals(b[i], a[i], "at index #" + i); 132 } 133 } 134 } 135 136 static void assertRearrangeArraysEquals(short[] a, short[] r, int[] order, int vector_len) { 137 int i = 0, j = 0; 138 try { 139 for (; i < a.length; i += vector_len) { 140 for (j = 0; j < vector_len; j++) { 141 Assert.assertEquals(r[i+j], a[i+order[i+j]]); 142 } 143 } 144 } catch (AssertionError e) { 145 int idx = i + j; 146 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]); 147 } 148 } 149 150 interface FBinOp { 151 short apply(short a, short b); 152 } 153 154 interface FBinMaskOp { 155 short apply(short a, short b, boolean m); 156 157 static FBinMaskOp lift(FBinOp f) { 158 return (a, b, m) -> m ? f.apply(a, b) : a; 159 } 160 } 161 162 static void assertArraysEquals(short[] a, short[] b, short[] r, FBinOp f) { 163 int i = 0; 164 try { 165 for (; i < a.length; i++) { 166 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 167 } 168 } catch (AssertionError e) { 169 Assert.assertEquals(f.apply(a[i], b[i]), r[i], "(" + a[i] + ", " + b[i] + ") at index #" + i); 170 } 171 } 172 173 static void assertArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) { 174 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 175 } 176 177 static void assertArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinMaskOp f) { 178 int i = 0; 179 try { 180 for (; i < a.length; i++) { 181 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 182 } 183 } catch (AssertionError err) { 184 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", mask = " + mask[i % SPECIES.length()]); 185 } 186 } 187 188 static void assertShiftArraysEquals(short[] a, short[] b, short[] r, FBinOp f) { 189 int i = 0; 190 int j = 0; 191 try { 192 for (; j < a.length; j += SPECIES.length()) { 193 for (i = 0; i < SPECIES.length(); i++) { 194 Assert.assertEquals(f.apply(a[i+j], b[j]), r[i+j]); 195 } 196 } 197 } catch (AssertionError e) { 198 Assert.assertEquals(f.apply(a[i+j], b[j]), r[i+j], "at index #" + i + ", " + j); 199 } 200 } 201 202 static void assertShiftArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) { 203 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 204 } 205 206 static void assertShiftArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinMaskOp f) { 207 int i = 0; 208 int j = 0; 209 try { 210 for (; j < a.length; j += SPECIES.length()) { 211 for (i = 0; i < SPECIES.length(); i++) { 212 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i])); 213 } 214 } 215 } catch (AssertionError err) { 216 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i]), "at index #" + i + ", input1 = " + a[i+j] + ", input2 = " + b[j] + ", mask = " + mask[i]); 217 } 218 } 219 220 221 interface FBinArrayOp { 222 short apply(short[] a, int b); 223 } 224 225 static void assertArraysEquals(short[] a, short[] r, FBinArrayOp f) { 226 int i = 0; 227 try { 228 for (; i < a.length; i++) { 229 Assert.assertEquals(f.apply(a, i), r[i]); 230 } 231 } catch (AssertionError e) { 232 Assert.assertEquals(f.apply(a,i), r[i], "at index #" + i); 233 } 234 } 235 236 static final List<IntFunction<short[]>> SHORT_GENERATORS = List.of( 237 withToString("short[-i * 5]", (int s) -> { 238 return fill(s * 1000, 239 i -> (short)(-i * 5)); 240 }), 241 withToString("short[i * 5]", (int s) -> { 242 return fill(s * 1000, 243 i -> (short)(i * 5)); 244 }), 245 withToString("short[i + 1]", (int s) -> { 246 return fill(s * 1000, 247 i -> (((short)(i + 1) == 0) ? 1 : (short)(i + 1))); 248 }), 249 withToString("short[cornerCaseValue(i)]", (int s) -> { 250 return fill(s * 1000, 251 i -> cornerCaseValue(i)); 252 }) 253 ); 254 255 // Create combinations of pairs 256 // @@@ Might be sensitive to order e.g. div by 0 257 static final List<List<IntFunction<short[]>>> SHORT_GENERATOR_PAIRS = 258 Stream.of(SHORT_GENERATORS.get(0)). 259 flatMap(fa -> SHORT_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))). 260 collect(Collectors.toList()); 261 262 @DataProvider 263 public Object[][] boolUnaryOpProvider() { 264 return BOOL_ARRAY_GENERATORS.stream(). 265 map(f -> new Object[]{f}). 266 toArray(Object[][]::new); 267 } 268 269 270 @DataProvider 271 public Object[][] shortBinaryOpProvider() { 272 return SHORT_GENERATOR_PAIRS.stream().map(List::toArray). 273 toArray(Object[][]::new); 274 } 275 276 @DataProvider 277 public Object[][] shortIndexedOpProvider() { 278 return SHORT_GENERATOR_PAIRS.stream().map(List::toArray). 279 toArray(Object[][]::new); 280 } 281 282 @DataProvider 283 public Object[][] shortBinaryOpMaskProvider() { 284 return BOOLEAN_MASK_GENERATORS.stream(). 285 flatMap(fm -> SHORT_GENERATOR_PAIRS.stream().map(lfa -> { 286 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 287 })). 288 toArray(Object[][]::new); 289 } 290 291 292 @DataProvider 293 public Object[][] shortUnaryOpProvider() { 294 return SHORT_GENERATORS.stream(). 295 map(f -> new Object[]{f}). 296 toArray(Object[][]::new); 297 } 298 299 @DataProvider 300 public Object[][] shortUnaryOpMaskProvider() { 301 return BOOLEAN_MASK_GENERATORS.stream(). 302 flatMap(fm -> SHORT_GENERATORS.stream().map(fa -> { 303 return new Object[] {fa, fm}; 304 })). 305 toArray(Object[][]::new); 306 } 307 308 @DataProvider 309 public Object[][] shortUnaryOpShuffleProvider() { 310 return INT_SHUFFLE_GENERATORS.stream(). 311 flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { 312 return new Object[] {fa, fs}; 313 })). 314 toArray(Object[][]::new); 315 } 316 317 @DataProvider 318 public Object[][] shortUnaryOpIndexProvider() { 319 return INT_INDEX_GENERATORS.stream(). 320 flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { 321 return new Object[] {fa, fs}; 322 })). 323 toArray(Object[][]::new); 324 } 325 326 327 static final List<IntFunction<short[]>> SHORT_COMPARE_GENERATORS = List.of( 328 withToString("short[i]", (int s) -> { 329 return fill(s * 1000, 330 i -> (short)i); 331 }), 332 withToString("short[i + 1]", (int s) -> { 333 return fill(s * 1000, 334 i -> (short)(i + 1)); 335 }), 336 withToString("short[i - 2]", (int s) -> { 337 return fill(s * 1000, 338 i -> (short)(i - 2)); 339 }), 340 withToString("short[zigZag(i)]", (int s) -> { 341 return fill(s * 1000, 342 i -> i%3 == 0 ? (short)i : (i%3 == 1 ? (short)(i + 1) : (short)(i - 2))); 343 }), 344 withToString("short[cornerCaseValue(i)]", (int s) -> { 345 return fill(s * 1000, 346 i -> cornerCaseValue(i)); 347 }) 348 ); 349 350 static final List<List<IntFunction<short[]>>> SHORT_COMPARE_GENERATOR_PAIRS = 351 SHORT_COMPARE_GENERATORS.stream(). 352 flatMap(fa -> SHORT_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))). 353 collect(Collectors.toList()); 354 355 @DataProvider 356 public Object[][] shortCompareOpProvider() { 357 return SHORT_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 358 toArray(Object[][]::new); 359 } 360 361 interface ToShortF { 362 short apply(int i); 363 } 364 365 static short[] fill(int s , ToShortF f) { 366 return fill(new short[s], f); 367 } 368 369 static short[] fill(short[] a, ToShortF f) { 370 for (int i = 0; i < a.length; i++) { 371 a[i] = f.apply(i); 372 } 373 return a; 374 } 375 376 static short cornerCaseValue(int i) { 377 switch(i % 5) { 378 case 0: 379 return Short.MAX_VALUE; 380 case 1: 381 return Short.MIN_VALUE; 382 case 2: 383 return Short.MIN_VALUE; 384 case 3: 385 return Short.MAX_VALUE; 386 default: 387 return (short)0; 388 } 389 } 390 static short get(short[] a, int i) { 391 return (short) a[i]; 392 } 393 394 static final IntFunction<short[]> fr = (vl) -> { 395 int length = 1000 * vl; 396 return new short[length]; 397 }; 398 399 static final IntFunction<boolean[]> fmr = (vl) -> { 400 int length = 1000 * vl; 401 return new boolean[length]; 402 }; 403 static short add(short a, short b) { 404 return (short)(a + b); 405 } 406 407 @Test(dataProvider = "shortBinaryOpProvider") 408 static void addShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 409 short[] a = fa.apply(SPECIES.length()); 410 short[] b = fb.apply(SPECIES.length()); 411 short[] r = fr.apply(SPECIES.length()); 412 413 for (int ic = 0; ic < INVOC_COUNT; ic++) { 414 for (int i = 0; i < a.length; i += SPECIES.length()) { 415 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 416 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 417 av.add(bv).intoArray(r, i); 418 } 419 } 420 421 assertArraysEquals(a, b, r, Short128VectorTests::add); 422 } 423 424 @Test(dataProvider = "shortBinaryOpMaskProvider") 425 static void addShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, 426 IntFunction<boolean[]> fm) { 427 short[] a = fa.apply(SPECIES.length()); 428 short[] b = fb.apply(SPECIES.length()); 429 short[] r = fr.apply(SPECIES.length()); 430 boolean[] mask = fm.apply(SPECIES.length()); 431 Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask); 432 433 for (int ic = 0; ic < INVOC_COUNT; ic++) { 434 for (int i = 0; i < a.length; i += SPECIES.length()) { 435 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 436 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 437 av.add(bv, vmask).intoArray(r, i); 438 } 439 } 440 441 assertArraysEquals(a, b, r, mask, Short128VectorTests::add); 442 } 443 static short sub(short a, short b) { 444 return (short)(a - b); 445 } 446 447 @Test(dataProvider = "shortBinaryOpProvider") 448 static void subShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 449 short[] a = fa.apply(SPECIES.length()); 450 short[] b = fb.apply(SPECIES.length()); 451 short[] r = fr.apply(SPECIES.length()); 452 453 for (int ic = 0; ic < INVOC_COUNT; ic++) { 454 for (int i = 0; i < a.length; i += SPECIES.length()) { 455 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 456 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 457 av.sub(bv).intoArray(r, i); 458 } 459 } 460 461 assertArraysEquals(a, b, r, Short128VectorTests::sub); 462 } 463 464 @Test(dataProvider = "shortBinaryOpMaskProvider") 465 static void subShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, 466 IntFunction<boolean[]> fm) { 467 short[] a = fa.apply(SPECIES.length()); 468 short[] b = fb.apply(SPECIES.length()); 469 short[] r = fr.apply(SPECIES.length()); 470 boolean[] mask = fm.apply(SPECIES.length()); 471 Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask); 472 473 for (int ic = 0; ic < INVOC_COUNT; ic++) { 474 for (int i = 0; i < a.length; i += SPECIES.length()) { 475 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 476 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 477 av.sub(bv, vmask).intoArray(r, i); 478 } 479 } 480 481 assertArraysEquals(a, b, r, mask, Short128VectorTests::sub); 482 } 483 484 485 static short mul(short a, short b) { 486 return (short)(a * b); 487 } 488 489 @Test(dataProvider = "shortBinaryOpProvider") 490 static void mulShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 491 short[] a = fa.apply(SPECIES.length()); 492 short[] b = fb.apply(SPECIES.length()); 493 short[] r = fr.apply(SPECIES.length()); 494 495 for (int ic = 0; ic < INVOC_COUNT; ic++) { 496 for (int i = 0; i < a.length; i += SPECIES.length()) { 497 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 498 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 499 av.mul(bv).intoArray(r, i); 500 } 501 } 502 503 assertArraysEquals(a, b, r, Short128VectorTests::mul); 504 } 505 506 @Test(dataProvider = "shortBinaryOpMaskProvider") 507 static void mulShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, 508 IntFunction<boolean[]> fm) { 509 short[] a = fa.apply(SPECIES.length()); 510 short[] b = fb.apply(SPECIES.length()); 511 short[] r = fr.apply(SPECIES.length()); 512 boolean[] mask = fm.apply(SPECIES.length()); 513 Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask); 514 515 for (int ic = 0; ic < INVOC_COUNT; ic++) { 516 for (int i = 0; i < a.length; i += SPECIES.length()) { 517 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 518 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 519 av.mul(bv, vmask).intoArray(r, i); 520 } 521 } 522 523 assertArraysEquals(a, b, r, mask, Short128VectorTests::mul); 524 } 525 526 static short and(short a, short b) { 527 return (short)(a & b); 528 } 529 530 @Test(dataProvider = "shortBinaryOpProvider") 531 static void andShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 532 short[] a = fa.apply(SPECIES.length()); 533 short[] b = fb.apply(SPECIES.length()); 534 short[] r = fr.apply(SPECIES.length()); 535 536 for (int ic = 0; ic < INVOC_COUNT; ic++) { 537 for (int i = 0; i < a.length; i += SPECIES.length()) { 538 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 539 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 540 av.and(bv).intoArray(r, i); 541 } 542 } 543 544 assertArraysEquals(a, b, r, Short128VectorTests::and); 545 } 546 547 548 549 @Test(dataProvider = "shortBinaryOpMaskProvider") 550 static void andShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, 551 IntFunction<boolean[]> fm) { 552 short[] a = fa.apply(SPECIES.length()); 553 short[] b = fb.apply(SPECIES.length()); 554 short[] r = fr.apply(SPECIES.length()); 555 boolean[] mask = fm.apply(SPECIES.length()); 556 Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask); 557 558 for (int ic = 0; ic < INVOC_COUNT; ic++) { 559 for (int i = 0; i < a.length; i += SPECIES.length()) { 560 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 561 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 562 av.and(bv, vmask).intoArray(r, i); 563 } 564 } 565 566 assertArraysEquals(a, b, r, mask, Short128VectorTests::and); 567 } 568 569 570 static short or(short a, short b) { 571 return (short)(a | b); 572 } 573 574 @Test(dataProvider = "shortBinaryOpProvider") 575 static void orShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 576 short[] a = fa.apply(SPECIES.length()); 577 short[] b = fb.apply(SPECIES.length()); 578 short[] r = fr.apply(SPECIES.length()); 579 580 for (int ic = 0; ic < INVOC_COUNT; ic++) { 581 for (int i = 0; i < a.length; i += SPECIES.length()) { 582 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 583 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 584 av.or(bv).intoArray(r, i); 585 } 586 } 587 588 assertArraysEquals(a, b, r, Short128VectorTests::or); 589 } 590 591 592 593 @Test(dataProvider = "shortBinaryOpMaskProvider") 594 static void orShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, 595 IntFunction<boolean[]> fm) { 596 short[] a = fa.apply(SPECIES.length()); 597 short[] b = fb.apply(SPECIES.length()); 598 short[] r = fr.apply(SPECIES.length()); 599 boolean[] mask = fm.apply(SPECIES.length()); 600 Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask); 601 602 for (int ic = 0; ic < INVOC_COUNT; ic++) { 603 for (int i = 0; i < a.length; i += SPECIES.length()) { 604 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 605 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 606 av.or(bv, vmask).intoArray(r, i); 607 } 608 } 609 610 assertArraysEquals(a, b, r, mask, Short128VectorTests::or); 611 } 612 613 614 static short xor(short a, short b) { 615 return (short)(a ^ b); 616 } 617 618 @Test(dataProvider = "shortBinaryOpProvider") 619 static void xorShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 620 short[] a = fa.apply(SPECIES.length()); 621 short[] b = fb.apply(SPECIES.length()); 622 short[] r = fr.apply(SPECIES.length()); 623 624 for (int ic = 0; ic < INVOC_COUNT; ic++) { 625 for (int i = 0; i < a.length; i += SPECIES.length()) { 626 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 627 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 628 av.xor(bv).intoArray(r, i); 629 } 630 } 631 632 assertArraysEquals(a, b, r, Short128VectorTests::xor); 633 } 634 635 636 637 @Test(dataProvider = "shortBinaryOpMaskProvider") 638 static void xorShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, 639 IntFunction<boolean[]> fm) { 640 short[] a = fa.apply(SPECIES.length()); 641 short[] b = fb.apply(SPECIES.length()); 642 short[] r = fr.apply(SPECIES.length()); 643 boolean[] mask = fm.apply(SPECIES.length()); 644 Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask); 645 646 for (int ic = 0; ic < INVOC_COUNT; ic++) { 647 for (int i = 0; i < a.length; i += SPECIES.length()) { 648 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 649 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 650 av.xor(bv, vmask).intoArray(r, i); 651 } 652 } 653 654 assertArraysEquals(a, b, r, mask, Short128VectorTests::xor); 655 } 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 static short aShiftR_unary(short a, short b) { 677 return (short)((a >> (b & 15))); 678 } 679 680 @Test(dataProvider = "shortBinaryOpProvider") 681 static void aShiftRShort128VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) { 682 short[] a = fa.apply(SPECIES.length()); 683 short[] b = fb.apply(SPECIES.length()); 684 short[] r = fr.apply(SPECIES.length()); 685 686 for (int ic = 0; ic < INVOC_COUNT; ic++) { 687 for (int i = 0; i < a.length; i += SPECIES.length()) { 688 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 689 av.aShiftR((int)b[i]).intoArray(r, i); 690 } 691 } 692 693 assertShiftArraysEquals(a, b, r, Short128VectorTests::aShiftR_unary); 694 } 695 696 697 698 @Test(dataProvider = "shortBinaryOpMaskProvider") 699 static void aShiftRShort128VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb, 700 IntFunction<boolean[]> fm) { 701 short[] a = fa.apply(SPECIES.length()); 702 short[] b = fb.apply(SPECIES.length()); 703 short[] r = fr.apply(SPECIES.length()); 704 boolean[] mask = fm.apply(SPECIES.length()); 705 Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask); 706 707 for (int ic = 0; ic < INVOC_COUNT; ic++) { 708 for (int i = 0; i < a.length; i += SPECIES.length()) { 709 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 710 av.aShiftR((int)b[i], vmask).intoArray(r, i); 711 } 712 } 713 714 assertShiftArraysEquals(a, b, r, mask, Short128VectorTests::aShiftR_unary); 715 } 716 717 718 static short shiftL_unary(short a, short b) { 719 return (short)((a << (b & 15))); 720 } 721 722 @Test(dataProvider = "shortBinaryOpProvider") 723 static void shiftLShort128VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) { 724 short[] a = fa.apply(SPECIES.length()); 725 short[] b = fb.apply(SPECIES.length()); 726 short[] r = fr.apply(SPECIES.length()); 727 728 for (int ic = 0; ic < INVOC_COUNT; ic++) { 729 for (int i = 0; i < a.length; i += SPECIES.length()) { 730 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 731 av.shiftL((int)b[i]).intoArray(r, i); 732 } 733 } 734 735 assertShiftArraysEquals(a, b, r, Short128VectorTests::shiftL_unary); 736 } 737 738 739 740 @Test(dataProvider = "shortBinaryOpMaskProvider") 741 static void shiftLShort128VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb, 742 IntFunction<boolean[]> fm) { 743 short[] a = fa.apply(SPECIES.length()); 744 short[] b = fb.apply(SPECIES.length()); 745 short[] r = fr.apply(SPECIES.length()); 746 boolean[] mask = fm.apply(SPECIES.length()); 747 Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask); 748 749 for (int ic = 0; ic < INVOC_COUNT; ic++) { 750 for (int i = 0; i < a.length; i += SPECIES.length()) { 751 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 752 av.shiftL((int)b[i], vmask).intoArray(r, i); 753 } 754 } 755 756 assertShiftArraysEquals(a, b, r, mask, Short128VectorTests::shiftL_unary); 757 } 758 759 760 static short shiftR_unary(short a, short b) { 761 return (short)(((a & 0xFFFF) >>> (b & 15))); 762 } 763 764 @Test(dataProvider = "shortBinaryOpProvider") 765 static void shiftRShort128VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) { 766 short[] a = fa.apply(SPECIES.length()); 767 short[] b = fb.apply(SPECIES.length()); 768 short[] r = fr.apply(SPECIES.length()); 769 770 for (int ic = 0; ic < INVOC_COUNT; ic++) { 771 for (int i = 0; i < a.length; i += SPECIES.length()) { 772 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 773 av.shiftR((int)b[i]).intoArray(r, i); 774 } 775 } 776 777 assertShiftArraysEquals(a, b, r, Short128VectorTests::shiftR_unary); 778 } 779 780 781 782 @Test(dataProvider = "shortBinaryOpMaskProvider") 783 static void shiftRShort128VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb, 784 IntFunction<boolean[]> fm) { 785 short[] a = fa.apply(SPECIES.length()); 786 short[] b = fb.apply(SPECIES.length()); 787 short[] r = fr.apply(SPECIES.length()); 788 boolean[] mask = fm.apply(SPECIES.length()); 789 Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask); 790 791 for (int ic = 0; ic < INVOC_COUNT; ic++) { 792 for (int i = 0; i < a.length; i += SPECIES.length()) { 793 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 794 av.shiftR((int)b[i], vmask).intoArray(r, i); 795 } 796 } 797 798 assertShiftArraysEquals(a, b, r, mask, Short128VectorTests::shiftR_unary); 799 } 800 801 static short max(short a, short b) { 802 return (short)(Math.max(a, b)); 803 } 804 805 @Test(dataProvider = "shortBinaryOpProvider") 806 static void maxShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 807 short[] a = fa.apply(SPECIES.length()); 808 short[] b = fb.apply(SPECIES.length()); 809 short[] r = fr.apply(SPECIES.length()); 810 811 for (int ic = 0; ic < INVOC_COUNT; ic++) { 812 for (int i = 0; i < a.length; i += SPECIES.length()) { 813 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 814 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 815 av.max(bv).intoArray(r, i); 816 } 817 } 818 819 assertArraysEquals(a, b, r, Short128VectorTests::max); 820 } 821 static short min(short a, short b) { 822 return (short)(Math.min(a, b)); 823 } 824 825 @Test(dataProvider = "shortBinaryOpProvider") 826 static void minShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 827 short[] a = fa.apply(SPECIES.length()); 828 short[] b = fb.apply(SPECIES.length()); 829 short[] r = fr.apply(SPECIES.length()); 830 831 for (int ic = 0; ic < INVOC_COUNT; ic++) { 832 for (int i = 0; i < a.length; i += SPECIES.length()) { 833 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 834 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 835 av.min(bv).intoArray(r, i); 836 } 837 } 838 839 assertArraysEquals(a, b, r, Short128VectorTests::min); 840 } 841 842 static short andAll(short[] a, int idx) { 843 short res = -1; 844 for (int i = idx; i < (idx + SPECIES.length()); i++) { 845 res &= a[i]; 846 } 847 848 return res; 849 } 850 851 static short andAll(short[] a) { 852 short res = -1; 853 for (int i = 0; i < a.length; i += SPECIES.length()) { 854 short tmp = -1; 855 for (int j = 0; j < SPECIES.length(); j++) { 856 tmp &= a[i + j]; 857 } 858 res &= tmp; 859 } 860 861 return res; 862 } 863 864 865 @Test(dataProvider = "shortUnaryOpProvider") 866 static void andAllShort128VectorTests(IntFunction<short[]> fa) { 867 short[] a = fa.apply(SPECIES.length()); 868 short[] r = fr.apply(SPECIES.length()); 869 short ra = -1; 870 871 for (int ic = 0; ic < INVOC_COUNT; ic++) { 872 for (int i = 0; i < a.length; i += SPECIES.length()) { 873 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 874 r[i] = av.andAll(); 875 } 876 } 877 878 for (int ic = 0; ic < INVOC_COUNT; ic++) { 879 ra = -1; 880 for (int i = 0; i < a.length; i += SPECIES.length()) { 881 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 882 ra &= av.andAll(); 883 } 884 } 885 886 assertReductionArraysEquals(a, r, ra, Short128VectorTests::andAll, Short128VectorTests::andAll); 887 } 888 889 890 static short orAll(short[] a, int idx) { 891 short res = 0; 892 for (int i = idx; i < (idx + SPECIES.length()); i++) { 893 res |= a[i]; 894 } 895 896 return res; 897 } 898 899 static short orAll(short[] a) { 900 short res = 0; 901 for (int i = 0; i < a.length; i += SPECIES.length()) { 902 short tmp = 0; 903 for (int j = 0; j < SPECIES.length(); j++) { 904 tmp |= a[i + j]; 905 } 906 res |= tmp; 907 } 908 909 return res; 910 } 911 912 913 @Test(dataProvider = "shortUnaryOpProvider") 914 static void orAllShort128VectorTests(IntFunction<short[]> fa) { 915 short[] a = fa.apply(SPECIES.length()); 916 short[] r = fr.apply(SPECIES.length()); 917 short ra = 0; 918 919 for (int ic = 0; ic < INVOC_COUNT; ic++) { 920 for (int i = 0; i < a.length; i += SPECIES.length()) { 921 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 922 r[i] = av.orAll(); 923 } 924 } 925 926 for (int ic = 0; ic < INVOC_COUNT; ic++) { 927 ra = 0; 928 for (int i = 0; i < a.length; i += SPECIES.length()) { 929 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 930 ra |= av.orAll(); 931 } 932 } 933 934 assertReductionArraysEquals(a, r, ra, Short128VectorTests::orAll, Short128VectorTests::orAll); 935 } 936 937 938 static short xorAll(short[] a, int idx) { 939 short res = 0; 940 for (int i = idx; i < (idx + SPECIES.length()); i++) { 941 res ^= a[i]; 942 } 943 944 return res; 945 } 946 947 static short xorAll(short[] a) { 948 short res = 0; 949 for (int i = 0; i < a.length; i += SPECIES.length()) { 950 short tmp = 0; 951 for (int j = 0; j < SPECIES.length(); j++) { 952 tmp ^= a[i + j]; 953 } 954 res ^= tmp; 955 } 956 957 return res; 958 } 959 960 961 @Test(dataProvider = "shortUnaryOpProvider") 962 static void xorAllShort128VectorTests(IntFunction<short[]> fa) { 963 short[] a = fa.apply(SPECIES.length()); 964 short[] r = fr.apply(SPECIES.length()); 965 short ra = 0; 966 967 for (int ic = 0; ic < INVOC_COUNT; ic++) { 968 for (int i = 0; i < a.length; i += SPECIES.length()) { 969 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 970 r[i] = av.xorAll(); 971 } 972 } 973 974 for (int ic = 0; ic < INVOC_COUNT; ic++) { 975 ra = 0; 976 for (int i = 0; i < a.length; i += SPECIES.length()) { 977 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 978 ra ^= av.xorAll(); 979 } 980 } 981 982 assertReductionArraysEquals(a, r, ra, Short128VectorTests::xorAll, Short128VectorTests::xorAll); 983 } 984 985 static short addAll(short[] a, int idx) { 986 short res = 0; 987 for (int i = idx; i < (idx + SPECIES.length()); i++) { 988 res += a[i]; 989 } 990 991 return res; 992 } 993 994 static short addAll(short[] a) { 995 short res = 0; 996 for (int i = 0; i < a.length; i += SPECIES.length()) { 997 short tmp = 0; 998 for (int j = 0; j < SPECIES.length(); j++) { 999 tmp += a[i + j]; 1000 } 1001 res += tmp; 1002 } 1003 1004 return res; 1005 } 1006 @Test(dataProvider = "shortUnaryOpProvider") 1007 static void addAllShort128VectorTests(IntFunction<short[]> fa) { 1008 short[] a = fa.apply(SPECIES.length()); 1009 short[] r = fr.apply(SPECIES.length()); 1010 short ra = 0; 1011 1012 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1013 for (int i = 0; i < a.length; i += SPECIES.length()) { 1014 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1015 r[i] = av.addAll(); 1016 } 1017 } 1018 1019 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1020 ra = 0; 1021 for (int i = 0; i < a.length; i += SPECIES.length()) { 1022 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1023 ra += av.addAll(); 1024 } 1025 } 1026 1027 assertReductionArraysEquals(a, r, ra, Short128VectorTests::addAll, Short128VectorTests::addAll); 1028 } 1029 static short mulAll(short[] a, int idx) { 1030 short res = 1; 1031 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1032 res *= a[i]; 1033 } 1034 1035 return res; 1036 } 1037 1038 static short mulAll(short[] a) { 1039 short res = 1; 1040 for (int i = 0; i < a.length; i += SPECIES.length()) { 1041 short tmp = 1; 1042 for (int j = 0; j < SPECIES.length(); j++) { 1043 tmp *= a[i + j]; 1044 } 1045 res *= tmp; 1046 } 1047 1048 return res; 1049 } 1050 @Test(dataProvider = "shortUnaryOpProvider") 1051 static void mulAllShort128VectorTests(IntFunction<short[]> fa) { 1052 short[] a = fa.apply(SPECIES.length()); 1053 short[] r = fr.apply(SPECIES.length()); 1054 short ra = 1; 1055 1056 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1057 for (int i = 0; i < a.length; i += SPECIES.length()) { 1058 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1059 r[i] = av.mulAll(); 1060 } 1061 } 1062 1063 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1064 ra = 1; 1065 for (int i = 0; i < a.length; i += SPECIES.length()) { 1066 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1067 ra *= av.mulAll(); 1068 } 1069 } 1070 1071 assertReductionArraysEquals(a, r, ra, Short128VectorTests::mulAll, Short128VectorTests::mulAll); 1072 } 1073 static short minAll(short[] a, int idx) { 1074 short res = Short.MAX_VALUE; 1075 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1076 res = (short)Math.min(res, a[i]); 1077 } 1078 1079 return res; 1080 } 1081 1082 static short minAll(short[] a) { 1083 short res = Short.MAX_VALUE; 1084 for (int i = 0; i < a.length; i++) { 1085 res = (short)Math.min(res, a[i]); 1086 } 1087 1088 return res; 1089 } 1090 @Test(dataProvider = "shortUnaryOpProvider") 1091 static void minAllShort128VectorTests(IntFunction<short[]> fa) { 1092 short[] a = fa.apply(SPECIES.length()); 1093 short[] r = fr.apply(SPECIES.length()); 1094 short ra = Short.MAX_VALUE; 1095 1096 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1097 for (int i = 0; i < a.length; i += SPECIES.length()) { 1098 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1099 r[i] = av.minAll(); 1100 } 1101 } 1102 1103 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1104 ra = Short.MAX_VALUE; 1105 for (int i = 0; i < a.length; i += SPECIES.length()) { 1106 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1107 ra = (short)Math.min(ra, av.minAll()); 1108 } 1109 } 1110 1111 assertReductionArraysEquals(a, r, ra, Short128VectorTests::minAll, Short128VectorTests::minAll); 1112 } 1113 static short maxAll(short[] a, int idx) { 1114 short res = Short.MIN_VALUE; 1115 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1116 res = (short)Math.max(res, a[i]); 1117 } 1118 1119 return res; 1120 } 1121 1122 static short maxAll(short[] a) { 1123 short res = Short.MIN_VALUE; 1124 for (int i = 0; i < a.length; i++) { 1125 res = (short)Math.max(res, a[i]); 1126 } 1127 1128 return res; 1129 } 1130 @Test(dataProvider = "shortUnaryOpProvider") 1131 static void maxAllShort128VectorTests(IntFunction<short[]> fa) { 1132 short[] a = fa.apply(SPECIES.length()); 1133 short[] r = fr.apply(SPECIES.length()); 1134 short ra = Short.MIN_VALUE; 1135 1136 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1137 for (int i = 0; i < a.length; i += SPECIES.length()) { 1138 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1139 r[i] = av.maxAll(); 1140 } 1141 } 1142 1143 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1144 ra = Short.MIN_VALUE; 1145 for (int i = 0; i < a.length; i += SPECIES.length()) { 1146 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1147 ra = (short)Math.max(ra, av.maxAll()); 1148 } 1149 } 1150 1151 assertReductionArraysEquals(a, r, ra, Short128VectorTests::maxAll, Short128VectorTests::maxAll); 1152 } 1153 1154 static boolean anyTrue(boolean[] a, int idx) { 1155 boolean res = false; 1156 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1157 res |= a[i]; 1158 } 1159 1160 return res; 1161 } 1162 1163 1164 @Test(dataProvider = "boolUnaryOpProvider") 1165 static void anyTrueShort128VectorTests(IntFunction<boolean[]> fm) { 1166 boolean[] mask = fm.apply(SPECIES.length()); 1167 boolean[] r = fmr.apply(SPECIES.length()); 1168 1169 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1170 for (int i = 0; i < mask.length; i += SPECIES.length()) { 1171 Vector.Mask<Short> vmask = ShortVector.maskFromArray(SPECIES, mask, i); 1172 r[i] = vmask.anyTrue(); 1173 } 1174 } 1175 1176 assertReductionBoolArraysEquals(mask, r, Short128VectorTests::anyTrue); 1177 } 1178 1179 1180 static boolean allTrue(boolean[] a, int idx) { 1181 boolean res = true; 1182 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1183 res &= a[i]; 1184 } 1185 1186 return res; 1187 } 1188 1189 1190 @Test(dataProvider = "boolUnaryOpProvider") 1191 static void allTrueShort128VectorTests(IntFunction<boolean[]> fm) { 1192 boolean[] mask = fm.apply(SPECIES.length()); 1193 boolean[] r = fmr.apply(SPECIES.length()); 1194 1195 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1196 for (int i = 0; i < mask.length; i += SPECIES.length()) { 1197 Vector.Mask<Short> vmask = ShortVector.maskFromArray(SPECIES, mask, i); 1198 r[i] = vmask.allTrue(); 1199 } 1200 } 1201 1202 assertReductionBoolArraysEquals(mask, r, Short128VectorTests::allTrue); 1203 } 1204 1205 1206 @Test(dataProvider = "shortUnaryOpProvider") 1207 static void withShort128VectorTests(IntFunction<short []> fa) { 1208 short[] a = fa.apply(SPECIES.length()); 1209 short[] r = fr.apply(SPECIES.length()); 1210 1211 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1212 for (int i = 0; i < a.length; i += SPECIES.length()) { 1213 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1214 av.with(0, (short)4).intoArray(r, i); 1215 } 1216 } 1217 1218 assertInsertArraysEquals(a, r, (short)4, 0); 1219 } 1220 1221 @Test(dataProvider = "shortCompareOpProvider") 1222 static void lessThanShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1223 short[] a = fa.apply(SPECIES.length()); 1224 short[] b = fb.apply(SPECIES.length()); 1225 1226 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1227 for (int i = 0; i < a.length; i += SPECIES.length()) { 1228 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1229 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1230 Vector.Mask<Short> mv = av.lessThan(bv); 1231 1232 // Check results as part of computation. 1233 for (int j = 0; j < SPECIES.length(); j++) { 1234 Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]); 1235 } 1236 } 1237 } 1238 } 1239 1240 1241 @Test(dataProvider = "shortCompareOpProvider") 1242 static void greaterThanShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1243 short[] a = fa.apply(SPECIES.length()); 1244 short[] b = fb.apply(SPECIES.length()); 1245 1246 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1247 for (int i = 0; i < a.length; i += SPECIES.length()) { 1248 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1249 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1250 Vector.Mask<Short> mv = av.greaterThan(bv); 1251 1252 // Check results as part of computation. 1253 for (int j = 0; j < SPECIES.length(); j++) { 1254 Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]); 1255 } 1256 } 1257 } 1258 } 1259 1260 1261 @Test(dataProvider = "shortCompareOpProvider") 1262 static void equalShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1263 short[] a = fa.apply(SPECIES.length()); 1264 short[] b = fb.apply(SPECIES.length()); 1265 1266 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1267 for (int i = 0; i < a.length; i += SPECIES.length()) { 1268 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1269 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1270 Vector.Mask<Short> mv = av.equal(bv); 1271 1272 // Check results as part of computation. 1273 for (int j = 0; j < SPECIES.length(); j++) { 1274 Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]); 1275 } 1276 } 1277 } 1278 } 1279 1280 1281 @Test(dataProvider = "shortCompareOpProvider") 1282 static void notEqualShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1283 short[] a = fa.apply(SPECIES.length()); 1284 short[] b = fb.apply(SPECIES.length()); 1285 1286 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1287 for (int i = 0; i < a.length; i += SPECIES.length()) { 1288 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1289 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1290 Vector.Mask<Short> mv = av.notEqual(bv); 1291 1292 // Check results as part of computation. 1293 for (int j = 0; j < SPECIES.length(); j++) { 1294 Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]); 1295 } 1296 } 1297 } 1298 } 1299 1300 1301 @Test(dataProvider = "shortCompareOpProvider") 1302 static void lessThanEqShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1303 short[] a = fa.apply(SPECIES.length()); 1304 short[] b = fb.apply(SPECIES.length()); 1305 1306 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1307 for (int i = 0; i < a.length; i += SPECIES.length()) { 1308 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1309 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1310 Vector.Mask<Short> mv = av.lessThanEq(bv); 1311 1312 // Check results as part of computation. 1313 for (int j = 0; j < SPECIES.length(); j++) { 1314 Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]); 1315 } 1316 } 1317 } 1318 } 1319 1320 1321 @Test(dataProvider = "shortCompareOpProvider") 1322 static void greaterThanEqShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1323 short[] a = fa.apply(SPECIES.length()); 1324 short[] b = fb.apply(SPECIES.length()); 1325 1326 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1327 for (int i = 0; i < a.length; i += SPECIES.length()) { 1328 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1329 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1330 Vector.Mask<Short> mv = av.greaterThanEq(bv); 1331 1332 // Check results as part of computation. 1333 for (int j = 0; j < SPECIES.length(); j++) { 1334 Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]); 1335 } 1336 } 1337 } 1338 } 1339 1340 1341 static short blend(short a, short b, boolean mask) { 1342 return mask ? b : a; 1343 } 1344 1345 @Test(dataProvider = "shortBinaryOpMaskProvider") 1346 static void blendShort128VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, 1347 IntFunction<boolean[]> fm) { 1348 short[] a = fa.apply(SPECIES.length()); 1349 short[] b = fb.apply(SPECIES.length()); 1350 short[] r = fr.apply(SPECIES.length()); 1351 boolean[] mask = fm.apply(SPECIES.length()); 1352 Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask); 1353 1354 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1355 for (int i = 0; i < a.length; i += SPECIES.length()) { 1356 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1357 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1358 av.blend(bv, vmask).intoArray(r, i); 1359 } 1360 } 1361 1362 assertArraysEquals(a, b, r, mask, Short128VectorTests::blend); 1363 } 1364 1365 @Test(dataProvider = "shortUnaryOpShuffleProvider") 1366 static void RearrangeShort128VectorTests(IntFunction<short[]> fa, 1367 BiFunction<Integer,Integer,int[]> fs) { 1368 short[] a = fa.apply(SPECIES.length()); 1369 int[] order = fs.apply(a.length, SPECIES.length()); 1370 short[] r = fr.apply(SPECIES.length()); 1371 1372 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1373 for (int i = 0; i < a.length; i += SPECIES.length()) { 1374 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1375 av.rearrange(ShortVector.shuffleFromArray(SPECIES, order, i)).intoArray(r, i); 1376 } 1377 } 1378 1379 assertRearrangeArraysEquals(a, r, order, SPECIES.length()); 1380 } 1381 1382 1383 1384 1385 @Test(dataProvider = "shortUnaryOpProvider") 1386 static void getShort128VectorTests(IntFunction<short[]> fa) { 1387 short[] a = fa.apply(SPECIES.length()); 1388 short[] r = fr.apply(SPECIES.length()); 1389 1390 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1391 for (int i = 0; i < a.length; i += SPECIES.length()) { 1392 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1393 int num_lanes = SPECIES.length(); 1394 // Manually unroll because full unroll happens after intrinsification. 1395 // Unroll is needed because get intrinsic requires for index to be a known constant. 1396 if (num_lanes == 1) { 1397 r[i]=av.get(0); 1398 } else if (num_lanes == 2) { 1399 r[i]=av.get(0); 1400 r[i+1]=av.get(1); 1401 } else if (num_lanes == 4) { 1402 r[i]=av.get(0); 1403 r[i+1]=av.get(1); 1404 r[i+2]=av.get(2); 1405 r[i+3]=av.get(3); 1406 } else if (num_lanes == 8) { 1407 r[i]=av.get(0); 1408 r[i+1]=av.get(1); 1409 r[i+2]=av.get(2); 1410 r[i+3]=av.get(3); 1411 r[i+4]=av.get(4); 1412 r[i+5]=av.get(5); 1413 r[i+6]=av.get(6); 1414 r[i+7]=av.get(7); 1415 } else if (num_lanes == 16) { 1416 r[i]=av.get(0); 1417 r[i+1]=av.get(1); 1418 r[i+2]=av.get(2); 1419 r[i+3]=av.get(3); 1420 r[i+4]=av.get(4); 1421 r[i+5]=av.get(5); 1422 r[i+6]=av.get(6); 1423 r[i+7]=av.get(7); 1424 r[i+8]=av.get(8); 1425 r[i+9]=av.get(9); 1426 r[i+10]=av.get(10); 1427 r[i+11]=av.get(11); 1428 r[i+12]=av.get(12); 1429 r[i+13]=av.get(13); 1430 r[i+14]=av.get(14); 1431 r[i+15]=av.get(15); 1432 } else if (num_lanes == 32) { 1433 r[i]=av.get(0); 1434 r[i+1]=av.get(1); 1435 r[i+2]=av.get(2); 1436 r[i+3]=av.get(3); 1437 r[i+4]=av.get(4); 1438 r[i+5]=av.get(5); 1439 r[i+6]=av.get(6); 1440 r[i+7]=av.get(7); 1441 r[i+8]=av.get(8); 1442 r[i+9]=av.get(9); 1443 r[i+10]=av.get(10); 1444 r[i+11]=av.get(11); 1445 r[i+12]=av.get(12); 1446 r[i+13]=av.get(13); 1447 r[i+14]=av.get(14); 1448 r[i+15]=av.get(15); 1449 r[i+16]=av.get(16); 1450 r[i+17]=av.get(17); 1451 r[i+18]=av.get(18); 1452 r[i+19]=av.get(19); 1453 r[i+20]=av.get(20); 1454 r[i+21]=av.get(21); 1455 r[i+22]=av.get(22); 1456 r[i+23]=av.get(23); 1457 r[i+24]=av.get(24); 1458 r[i+25]=av.get(25); 1459 r[i+26]=av.get(26); 1460 r[i+27]=av.get(27); 1461 r[i+28]=av.get(28); 1462 r[i+29]=av.get(29); 1463 r[i+30]=av.get(30); 1464 r[i+31]=av.get(31); 1465 } else if (num_lanes == 64) { 1466 r[i]=av.get(0); 1467 r[i+1]=av.get(1); 1468 r[i+2]=av.get(2); 1469 r[i+3]=av.get(3); 1470 r[i+4]=av.get(4); 1471 r[i+5]=av.get(5); 1472 r[i+6]=av.get(6); 1473 r[i+7]=av.get(7); 1474 r[i+8]=av.get(8); 1475 r[i+9]=av.get(9); 1476 r[i+10]=av.get(10); 1477 r[i+11]=av.get(11); 1478 r[i+12]=av.get(12); 1479 r[i+13]=av.get(13); 1480 r[i+14]=av.get(14); 1481 r[i+15]=av.get(15); 1482 r[i+16]=av.get(16); 1483 r[i+17]=av.get(17); 1484 r[i+18]=av.get(18); 1485 r[i+19]=av.get(19); 1486 r[i+20]=av.get(20); 1487 r[i+21]=av.get(21); 1488 r[i+22]=av.get(22); 1489 r[i+23]=av.get(23); 1490 r[i+24]=av.get(24); 1491 r[i+25]=av.get(25); 1492 r[i+26]=av.get(26); 1493 r[i+27]=av.get(27); 1494 r[i+28]=av.get(28); 1495 r[i+29]=av.get(29); 1496 r[i+30]=av.get(30); 1497 r[i+31]=av.get(31); 1498 r[i+32]=av.get(32); 1499 r[i+33]=av.get(33); 1500 r[i+34]=av.get(34); 1501 r[i+35]=av.get(35); 1502 r[i+36]=av.get(36); 1503 r[i+37]=av.get(37); 1504 r[i+38]=av.get(38); 1505 r[i+39]=av.get(39); 1506 r[i+40]=av.get(40); 1507 r[i+41]=av.get(41); 1508 r[i+42]=av.get(42); 1509 r[i+43]=av.get(43); 1510 r[i+44]=av.get(44); 1511 r[i+45]=av.get(45); 1512 r[i+46]=av.get(46); 1513 r[i+47]=av.get(47); 1514 r[i+48]=av.get(48); 1515 r[i+49]=av.get(49); 1516 r[i+50]=av.get(50); 1517 r[i+51]=av.get(51); 1518 r[i+52]=av.get(52); 1519 r[i+53]=av.get(53); 1520 r[i+54]=av.get(54); 1521 r[i+55]=av.get(55); 1522 r[i+56]=av.get(56); 1523 r[i+57]=av.get(57); 1524 r[i+58]=av.get(58); 1525 r[i+59]=av.get(59); 1526 r[i+60]=av.get(60); 1527 r[i+61]=av.get(61); 1528 r[i+62]=av.get(62); 1529 r[i+63]=av.get(63); 1530 } else { 1531 for (int j = 0; j < SPECIES.length(); j++) { 1532 r[i+j]=av.get(j); 1533 } 1534 } 1535 } 1536 } 1537 1538 assertArraysEquals(a, r, Short128VectorTests::get); 1539 } 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 static short neg(short a) { 1563 return (short)(-((short)a)); 1564 } 1565 1566 @Test(dataProvider = "shortUnaryOpProvider") 1567 static void negShort128VectorTests(IntFunction<short[]> fa) { 1568 short[] a = fa.apply(SPECIES.length()); 1569 short[] r = fr.apply(SPECIES.length()); 1570 1571 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1572 for (int i = 0; i < a.length; i += SPECIES.length()) { 1573 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1574 av.neg().intoArray(r, i); 1575 } 1576 } 1577 1578 assertArraysEquals(a, r, Short128VectorTests::neg); 1579 } 1580 1581 @Test(dataProvider = "shortUnaryOpMaskProvider") 1582 static void negMaskedShort128VectorTests(IntFunction<short[]> fa, 1583 IntFunction<boolean[]> fm) { 1584 short[] a = fa.apply(SPECIES.length()); 1585 short[] r = fr.apply(SPECIES.length()); 1586 boolean[] mask = fm.apply(SPECIES.length()); 1587 Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask); 1588 1589 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1590 for (int i = 0; i < a.length; i += SPECIES.length()) { 1591 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1592 av.neg(vmask).intoArray(r, i); 1593 } 1594 } 1595 1596 assertArraysEquals(a, r, mask, Short128VectorTests::neg); 1597 } 1598 1599 static short abs(short a) { 1600 return (short)(Math.abs((short)a)); 1601 } 1602 1603 @Test(dataProvider = "shortUnaryOpProvider") 1604 static void absShort128VectorTests(IntFunction<short[]> fa) { 1605 short[] a = fa.apply(SPECIES.length()); 1606 short[] r = fr.apply(SPECIES.length()); 1607 1608 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1609 for (int i = 0; i < a.length; i += SPECIES.length()) { 1610 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1611 av.abs().intoArray(r, i); 1612 } 1613 } 1614 1615 assertArraysEquals(a, r, Short128VectorTests::abs); 1616 } 1617 1618 @Test(dataProvider = "shortUnaryOpMaskProvider") 1619 static void absMaskedShort128VectorTests(IntFunction<short[]> fa, 1620 IntFunction<boolean[]> fm) { 1621 short[] a = fa.apply(SPECIES.length()); 1622 short[] r = fr.apply(SPECIES.length()); 1623 boolean[] mask = fm.apply(SPECIES.length()); 1624 Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask); 1625 1626 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1627 for (int i = 0; i < a.length; i += SPECIES.length()) { 1628 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1629 av.abs(vmask).intoArray(r, i); 1630 } 1631 } 1632 1633 assertArraysEquals(a, r, mask, Short128VectorTests::abs); 1634 } 1635 1636 1637 static short not(short a) { 1638 return (short)(~((short)a)); 1639 } 1640 1641 1642 1643 @Test(dataProvider = "shortUnaryOpProvider") 1644 static void notShort128VectorTests(IntFunction<short[]> fa) { 1645 short[] a = fa.apply(SPECIES.length()); 1646 short[] r = fr.apply(SPECIES.length()); 1647 1648 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1649 for (int i = 0; i < a.length; i += SPECIES.length()) { 1650 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1651 av.not().intoArray(r, i); 1652 } 1653 } 1654 1655 assertArraysEquals(a, r, Short128VectorTests::not); 1656 } 1657 1658 1659 1660 @Test(dataProvider = "shortUnaryOpMaskProvider") 1661 static void notMaskedShort128VectorTests(IntFunction<short[]> fa, 1662 IntFunction<boolean[]> fm) { 1663 short[] a = fa.apply(SPECIES.length()); 1664 short[] r = fr.apply(SPECIES.length()); 1665 boolean[] mask = fm.apply(SPECIES.length()); 1666 Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask); 1667 1668 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1669 for (int i = 0; i < a.length; i += SPECIES.length()) { 1670 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1671 av.not(vmask).intoArray(r, i); 1672 } 1673 } 1674 1675 assertArraysEquals(a, r, mask, Short128VectorTests::not); 1676 } 1677 1678 1679 1680 1681 1682 1683 } 1684