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