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