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 static short shiftLeft(short a, short b) { 666 return (short)((a << (b & 0xF))); 667 } 668 669 @Test(dataProvider = "shortBinaryOpProvider") 670 static void shiftLeftShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 671 short[] a = fa.apply(SPECIES.length()); 672 short[] b = fb.apply(SPECIES.length()); 673 short[] r = fr.apply(SPECIES.length()); 674 675 for (int ic = 0; ic < INVOC_COUNT; ic++) { 676 for (int i = 0; i < a.length; i += SPECIES.length()) { 677 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 678 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 679 av.shiftLeft(bv).intoArray(r, i); 680 } 681 } 682 683 assertArraysEquals(a, b, r, Short512VectorTests::shiftLeft); 684 } 685 686 687 688 @Test(dataProvider = "shortBinaryOpMaskProvider") 689 static void shiftLeftShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, 690 IntFunction<boolean[]> fm) { 691 short[] a = fa.apply(SPECIES.length()); 692 short[] b = fb.apply(SPECIES.length()); 693 short[] r = fr.apply(SPECIES.length()); 694 boolean[] mask = fm.apply(SPECIES.length()); 695 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask); 696 697 for (int ic = 0; ic < INVOC_COUNT; ic++) { 698 for (int i = 0; i < a.length; i += SPECIES.length()) { 699 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 700 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 701 av.shiftLeft(bv, vmask).intoArray(r, i); 702 } 703 } 704 705 assertArraysEquals(a, b, r, mask, Short512VectorTests::shiftLeft); 706 } 707 708 709 710 711 712 713 static short shiftRight(short a, short b) { 714 return (short)((a >>> (b & 0xF))); 715 } 716 717 @Test(dataProvider = "shortBinaryOpProvider") 718 static void shiftRightShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 719 short[] a = fa.apply(SPECIES.length()); 720 short[] b = fb.apply(SPECIES.length()); 721 short[] r = fr.apply(SPECIES.length()); 722 723 for (int ic = 0; ic < INVOC_COUNT; ic++) { 724 for (int i = 0; i < a.length; i += SPECIES.length()) { 725 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 726 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 727 av.shiftRight(bv).intoArray(r, i); 728 } 729 } 730 731 assertArraysEquals(a, b, r, Short512VectorTests::shiftRight); 732 } 733 734 735 736 @Test(dataProvider = "shortBinaryOpMaskProvider") 737 static void shiftRightShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, 738 IntFunction<boolean[]> fm) { 739 short[] a = fa.apply(SPECIES.length()); 740 short[] b = fb.apply(SPECIES.length()); 741 short[] r = fr.apply(SPECIES.length()); 742 boolean[] mask = fm.apply(SPECIES.length()); 743 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask); 744 745 for (int ic = 0; ic < INVOC_COUNT; ic++) { 746 for (int i = 0; i < a.length; i += SPECIES.length()) { 747 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 748 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 749 av.shiftRight(bv, vmask).intoArray(r, i); 750 } 751 } 752 753 assertArraysEquals(a, b, r, mask, Short512VectorTests::shiftRight); 754 } 755 756 757 758 759 760 761 static short shiftArithmeticRight(short a, short b) { 762 return (short)((a >> (b & 0xF))); 763 } 764 765 @Test(dataProvider = "shortBinaryOpProvider") 766 static void shiftArithmeticRightShort512VectorTests(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 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 775 av.shiftArithmeticRight(bv).intoArray(r, i); 776 } 777 } 778 779 assertArraysEquals(a, b, r, Short512VectorTests::shiftArithmeticRight); 780 } 781 782 783 784 @Test(dataProvider = "shortBinaryOpMaskProvider") 785 static void shiftArithmeticRightShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, 786 IntFunction<boolean[]> fm) { 787 short[] a = fa.apply(SPECIES.length()); 788 short[] b = fb.apply(SPECIES.length()); 789 short[] r = fr.apply(SPECIES.length()); 790 boolean[] mask = fm.apply(SPECIES.length()); 791 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask); 792 793 for (int ic = 0; ic < INVOC_COUNT; ic++) { 794 for (int i = 0; i < a.length; i += SPECIES.length()) { 795 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 796 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 797 av.shiftArithmeticRight(bv, vmask).intoArray(r, i); 798 } 799 } 800 801 assertArraysEquals(a, b, r, mask, Short512VectorTests::shiftArithmeticRight); 802 } 803 804 805 806 807 808 809 static short shiftLeft_unary(short a, short b) { 810 return (short)((a << (b & 15))); 811 } 812 813 @Test(dataProvider = "shortBinaryOpProvider") 814 static void shiftLeftShort512VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) { 815 short[] a = fa.apply(SPECIES.length()); 816 short[] b = fb.apply(SPECIES.length()); 817 short[] r = fr.apply(SPECIES.length()); 818 819 for (int ic = 0; ic < INVOC_COUNT; ic++) { 820 for (int i = 0; i < a.length; i += SPECIES.length()) { 821 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 822 av.shiftLeft((int)b[i]).intoArray(r, i); 823 } 824 } 825 826 assertShiftArraysEquals(a, b, r, Short512VectorTests::shiftLeft_unary); 827 } 828 829 830 831 @Test(dataProvider = "shortBinaryOpMaskProvider") 832 static void shiftLeftShort512VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb, 833 IntFunction<boolean[]> fm) { 834 short[] a = fa.apply(SPECIES.length()); 835 short[] b = fb.apply(SPECIES.length()); 836 short[] r = fr.apply(SPECIES.length()); 837 boolean[] mask = fm.apply(SPECIES.length()); 838 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask); 839 840 for (int ic = 0; ic < INVOC_COUNT; ic++) { 841 for (int i = 0; i < a.length; i += SPECIES.length()) { 842 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 843 av.shiftLeft((int)b[i], vmask).intoArray(r, i); 844 } 845 } 846 847 assertShiftArraysEquals(a, b, r, mask, Short512VectorTests::shiftLeft_unary); 848 } 849 850 851 852 853 854 855 static short shiftRight_unary(short a, short b) { 856 return (short)(((a & 0xFFFF) >>> (b & 15))); 857 } 858 859 @Test(dataProvider = "shortBinaryOpProvider") 860 static void shiftRightShort512VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) { 861 short[] a = fa.apply(SPECIES.length()); 862 short[] b = fb.apply(SPECIES.length()); 863 short[] r = fr.apply(SPECIES.length()); 864 865 for (int ic = 0; ic < INVOC_COUNT; ic++) { 866 for (int i = 0; i < a.length; i += SPECIES.length()) { 867 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 868 av.shiftRight((int)b[i]).intoArray(r, i); 869 } 870 } 871 872 assertShiftArraysEquals(a, b, r, Short512VectorTests::shiftRight_unary); 873 } 874 875 876 877 @Test(dataProvider = "shortBinaryOpMaskProvider") 878 static void shiftRightShort512VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb, 879 IntFunction<boolean[]> fm) { 880 short[] a = fa.apply(SPECIES.length()); 881 short[] b = fb.apply(SPECIES.length()); 882 short[] r = fr.apply(SPECIES.length()); 883 boolean[] mask = fm.apply(SPECIES.length()); 884 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask); 885 886 for (int ic = 0; ic < INVOC_COUNT; ic++) { 887 for (int i = 0; i < a.length; i += SPECIES.length()) { 888 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 889 av.shiftRight((int)b[i], vmask).intoArray(r, i); 890 } 891 } 892 893 assertShiftArraysEquals(a, b, r, mask, Short512VectorTests::shiftRight_unary); 894 } 895 896 897 898 899 900 901 static short shiftArithmeticRight_unary(short a, short b) { 902 return (short)((a >> (b & 15))); 903 } 904 905 @Test(dataProvider = "shortBinaryOpProvider") 906 static void shiftArithmeticRightShort512VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) { 907 short[] a = fa.apply(SPECIES.length()); 908 short[] b = fb.apply(SPECIES.length()); 909 short[] r = fr.apply(SPECIES.length()); 910 911 for (int ic = 0; ic < INVOC_COUNT; ic++) { 912 for (int i = 0; i < a.length; i += SPECIES.length()) { 913 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 914 av.shiftArithmeticRight((int)b[i]).intoArray(r, i); 915 } 916 } 917 918 assertShiftArraysEquals(a, b, r, Short512VectorTests::shiftArithmeticRight_unary); 919 } 920 921 922 923 @Test(dataProvider = "shortBinaryOpMaskProvider") 924 static void shiftArithmeticRightShort512VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb, 925 IntFunction<boolean[]> fm) { 926 short[] a = fa.apply(SPECIES.length()); 927 short[] b = fb.apply(SPECIES.length()); 928 short[] r = fr.apply(SPECIES.length()); 929 boolean[] mask = fm.apply(SPECIES.length()); 930 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask); 931 932 for (int ic = 0; ic < INVOC_COUNT; ic++) { 933 for (int i = 0; i < a.length; i += SPECIES.length()) { 934 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 935 av.shiftArithmeticRight((int)b[i], vmask).intoArray(r, i); 936 } 937 } 938 939 assertShiftArraysEquals(a, b, r, mask, Short512VectorTests::shiftArithmeticRight_unary); 940 } 941 942 static short max(short a, short b) { 943 return (short)(Math.max(a, b)); 944 } 945 946 @Test(dataProvider = "shortBinaryOpProvider") 947 static void maxShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 948 short[] a = fa.apply(SPECIES.length()); 949 short[] b = fb.apply(SPECIES.length()); 950 short[] r = fr.apply(SPECIES.length()); 951 952 for (int ic = 0; ic < INVOC_COUNT; ic++) { 953 for (int i = 0; i < a.length; i += SPECIES.length()) { 954 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 955 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 956 av.max(bv).intoArray(r, i); 957 } 958 } 959 960 assertArraysEquals(a, b, r, Short512VectorTests::max); 961 } 962 static short min(short a, short b) { 963 return (short)(Math.min(a, b)); 964 } 965 966 @Test(dataProvider = "shortBinaryOpProvider") 967 static void minShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 968 short[] a = fa.apply(SPECIES.length()); 969 short[] b = fb.apply(SPECIES.length()); 970 short[] r = fr.apply(SPECIES.length()); 971 972 for (int ic = 0; ic < INVOC_COUNT; ic++) { 973 for (int i = 0; i < a.length; i += SPECIES.length()) { 974 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 975 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 976 av.min(bv).intoArray(r, i); 977 } 978 } 979 980 assertArraysEquals(a, b, r, Short512VectorTests::min); 981 } 982 983 static short andLanes(short[] a, int idx) { 984 short res = -1; 985 for (int i = idx; i < (idx + SPECIES.length()); i++) { 986 res &= a[i]; 987 } 988 989 return res; 990 } 991 992 static short andLanes(short[] a) { 993 short res = -1; 994 for (int i = 0; i < a.length; i += SPECIES.length()) { 995 short tmp = -1; 996 for (int j = 0; j < SPECIES.length(); j++) { 997 tmp &= a[i + j]; 998 } 999 res &= tmp; 1000 } 1001 1002 return res; 1003 } 1004 1005 1006 @Test(dataProvider = "shortUnaryOpProvider") 1007 static void andLanesShort512VectorTests(IntFunction<short[]> fa) { 1008 short[] a = fa.apply(SPECIES.length()); 1009 short[] r = fr.apply(SPECIES.length()); 1010 short ra = -1; 1011 1012 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1013 for (int i = 0; i < a.length; i += SPECIES.length()) { 1014 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1015 r[i] = av.andLanes(); 1016 } 1017 } 1018 1019 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1020 ra = -1; 1021 for (int i = 0; i < a.length; i += SPECIES.length()) { 1022 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1023 ra &= av.andLanes(); 1024 } 1025 } 1026 1027 assertReductionArraysEquals(a, r, ra, Short512VectorTests::andLanes, Short512VectorTests::andLanes); 1028 } 1029 1030 1031 static short orLanes(short[] a, int idx) { 1032 short res = 0; 1033 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1034 res |= a[i]; 1035 } 1036 1037 return res; 1038 } 1039 1040 static short orLanes(short[] a) { 1041 short res = 0; 1042 for (int i = 0; i < a.length; i += SPECIES.length()) { 1043 short tmp = 0; 1044 for (int j = 0; j < SPECIES.length(); j++) { 1045 tmp |= a[i + j]; 1046 } 1047 res |= tmp; 1048 } 1049 1050 return res; 1051 } 1052 1053 1054 @Test(dataProvider = "shortUnaryOpProvider") 1055 static void orLanesShort512VectorTests(IntFunction<short[]> fa) { 1056 short[] a = fa.apply(SPECIES.length()); 1057 short[] r = fr.apply(SPECIES.length()); 1058 short ra = 0; 1059 1060 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1061 for (int i = 0; i < a.length; i += SPECIES.length()) { 1062 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1063 r[i] = av.orLanes(); 1064 } 1065 } 1066 1067 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1068 ra = 0; 1069 for (int i = 0; i < a.length; i += SPECIES.length()) { 1070 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1071 ra |= av.orLanes(); 1072 } 1073 } 1074 1075 assertReductionArraysEquals(a, r, ra, Short512VectorTests::orLanes, Short512VectorTests::orLanes); 1076 } 1077 1078 1079 static short xorLanes(short[] a, int idx) { 1080 short res = 0; 1081 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1082 res ^= a[i]; 1083 } 1084 1085 return res; 1086 } 1087 1088 static short xorLanes(short[] a) { 1089 short res = 0; 1090 for (int i = 0; i < a.length; i += SPECIES.length()) { 1091 short tmp = 0; 1092 for (int j = 0; j < SPECIES.length(); j++) { 1093 tmp ^= a[i + j]; 1094 } 1095 res ^= tmp; 1096 } 1097 1098 return res; 1099 } 1100 1101 1102 @Test(dataProvider = "shortUnaryOpProvider") 1103 static void xorLanesShort512VectorTests(IntFunction<short[]> fa) { 1104 short[] a = fa.apply(SPECIES.length()); 1105 short[] r = fr.apply(SPECIES.length()); 1106 short ra = 0; 1107 1108 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1109 for (int i = 0; i < a.length; i += SPECIES.length()) { 1110 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1111 r[i] = av.xorLanes(); 1112 } 1113 } 1114 1115 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1116 ra = 0; 1117 for (int i = 0; i < a.length; i += SPECIES.length()) { 1118 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1119 ra ^= av.xorLanes(); 1120 } 1121 } 1122 1123 assertReductionArraysEquals(a, r, ra, Short512VectorTests::xorLanes, Short512VectorTests::xorLanes); 1124 } 1125 1126 static short addLanes(short[] a, int idx) { 1127 short res = 0; 1128 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1129 res += a[i]; 1130 } 1131 1132 return res; 1133 } 1134 1135 static short addLanes(short[] a) { 1136 short res = 0; 1137 for (int i = 0; i < a.length; i += SPECIES.length()) { 1138 short tmp = 0; 1139 for (int j = 0; j < SPECIES.length(); j++) { 1140 tmp += a[i + j]; 1141 } 1142 res += tmp; 1143 } 1144 1145 return res; 1146 } 1147 @Test(dataProvider = "shortUnaryOpProvider") 1148 static void addLanesShort512VectorTests(IntFunction<short[]> fa) { 1149 short[] a = fa.apply(SPECIES.length()); 1150 short[] r = fr.apply(SPECIES.length()); 1151 short ra = 0; 1152 1153 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1154 for (int i = 0; i < a.length; i += SPECIES.length()) { 1155 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1156 r[i] = av.addLanes(); 1157 } 1158 } 1159 1160 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1161 ra = 0; 1162 for (int i = 0; i < a.length; i += SPECIES.length()) { 1163 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1164 ra += av.addLanes(); 1165 } 1166 } 1167 1168 assertReductionArraysEquals(a, r, ra, Short512VectorTests::addLanes, Short512VectorTests::addLanes); 1169 } 1170 static short mulLanes(short[] a, int idx) { 1171 short res = 1; 1172 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1173 res *= a[i]; 1174 } 1175 1176 return res; 1177 } 1178 1179 static short mulLanes(short[] a) { 1180 short res = 1; 1181 for (int i = 0; i < a.length; i += SPECIES.length()) { 1182 short tmp = 1; 1183 for (int j = 0; j < SPECIES.length(); j++) { 1184 tmp *= a[i + j]; 1185 } 1186 res *= tmp; 1187 } 1188 1189 return res; 1190 } 1191 @Test(dataProvider = "shortUnaryOpProvider") 1192 static void mulLanesShort512VectorTests(IntFunction<short[]> fa) { 1193 short[] a = fa.apply(SPECIES.length()); 1194 short[] r = fr.apply(SPECIES.length()); 1195 short ra = 1; 1196 1197 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1198 for (int i = 0; i < a.length; i += SPECIES.length()) { 1199 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1200 r[i] = av.mulLanes(); 1201 } 1202 } 1203 1204 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1205 ra = 1; 1206 for (int i = 0; i < a.length; i += SPECIES.length()) { 1207 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1208 ra *= av.mulLanes(); 1209 } 1210 } 1211 1212 assertReductionArraysEquals(a, r, ra, Short512VectorTests::mulLanes, Short512VectorTests::mulLanes); 1213 } 1214 static short minLanes(short[] a, int idx) { 1215 short res = Short.MAX_VALUE; 1216 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1217 res = (short)Math.min(res, a[i]); 1218 } 1219 1220 return res; 1221 } 1222 1223 static short minLanes(short[] a) { 1224 short res = Short.MAX_VALUE; 1225 for (int i = 0; i < a.length; i++) { 1226 res = (short)Math.min(res, a[i]); 1227 } 1228 1229 return res; 1230 } 1231 @Test(dataProvider = "shortUnaryOpProvider") 1232 static void minLanesShort512VectorTests(IntFunction<short[]> fa) { 1233 short[] a = fa.apply(SPECIES.length()); 1234 short[] r = fr.apply(SPECIES.length()); 1235 short ra = Short.MAX_VALUE; 1236 1237 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1238 for (int i = 0; i < a.length; i += SPECIES.length()) { 1239 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1240 r[i] = av.minLanes(); 1241 } 1242 } 1243 1244 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1245 ra = Short.MAX_VALUE; 1246 for (int i = 0; i < a.length; i += SPECIES.length()) { 1247 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1248 ra = (short)Math.min(ra, av.minLanes()); 1249 } 1250 } 1251 1252 assertReductionArraysEquals(a, r, ra, Short512VectorTests::minLanes, Short512VectorTests::minLanes); 1253 } 1254 static short maxLanes(short[] a, int idx) { 1255 short res = Short.MIN_VALUE; 1256 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1257 res = (short)Math.max(res, a[i]); 1258 } 1259 1260 return res; 1261 } 1262 1263 static short maxLanes(short[] a) { 1264 short res = Short.MIN_VALUE; 1265 for (int i = 0; i < a.length; i++) { 1266 res = (short)Math.max(res, a[i]); 1267 } 1268 1269 return res; 1270 } 1271 @Test(dataProvider = "shortUnaryOpProvider") 1272 static void maxLanesShort512VectorTests(IntFunction<short[]> fa) { 1273 short[] a = fa.apply(SPECIES.length()); 1274 short[] r = fr.apply(SPECIES.length()); 1275 short ra = Short.MIN_VALUE; 1276 1277 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1278 for (int i = 0; i < a.length; i += SPECIES.length()) { 1279 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1280 r[i] = av.maxLanes(); 1281 } 1282 } 1283 1284 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1285 ra = Short.MIN_VALUE; 1286 for (int i = 0; i < a.length; i += SPECIES.length()) { 1287 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1288 ra = (short)Math.max(ra, av.maxLanes()); 1289 } 1290 } 1291 1292 assertReductionArraysEquals(a, r, ra, Short512VectorTests::maxLanes, Short512VectorTests::maxLanes); 1293 } 1294 1295 static boolean anyTrue(boolean[] a, int idx) { 1296 boolean res = false; 1297 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1298 res |= a[i]; 1299 } 1300 1301 return res; 1302 } 1303 1304 1305 @Test(dataProvider = "boolUnaryOpProvider") 1306 static void anyTrueShort512VectorTests(IntFunction<boolean[]> fm) { 1307 boolean[] mask = fm.apply(SPECIES.length()); 1308 boolean[] r = fmr.apply(SPECIES.length()); 1309 1310 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1311 for (int i = 0; i < mask.length; i += SPECIES.length()) { 1312 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, i); 1313 r[i] = vmask.anyTrue(); 1314 } 1315 } 1316 1317 assertReductionBoolArraysEquals(mask, r, Short512VectorTests::anyTrue); 1318 } 1319 1320 1321 static boolean allTrue(boolean[] a, int idx) { 1322 boolean res = true; 1323 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1324 res &= a[i]; 1325 } 1326 1327 return res; 1328 } 1329 1330 1331 @Test(dataProvider = "boolUnaryOpProvider") 1332 static void allTrueShort512VectorTests(IntFunction<boolean[]> fm) { 1333 boolean[] mask = fm.apply(SPECIES.length()); 1334 boolean[] r = fmr.apply(SPECIES.length()); 1335 1336 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1337 for (int i = 0; i < mask.length; i += SPECIES.length()) { 1338 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, i); 1339 r[i] = vmask.allTrue(); 1340 } 1341 } 1342 1343 assertReductionBoolArraysEquals(mask, r, Short512VectorTests::allTrue); 1344 } 1345 1346 1347 @Test(dataProvider = "shortUnaryOpProvider") 1348 static void withShort512VectorTests(IntFunction<short []> fa) { 1349 short[] a = fa.apply(SPECIES.length()); 1350 short[] r = fr.apply(SPECIES.length()); 1351 1352 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1353 for (int i = 0; i < a.length; i += SPECIES.length()) { 1354 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1355 av.with(0, (short)4).intoArray(r, i); 1356 } 1357 } 1358 1359 assertInsertArraysEquals(a, r, (short)4, 0); 1360 } 1361 1362 @Test(dataProvider = "shortCompareOpProvider") 1363 static void lessThanShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1364 short[] a = fa.apply(SPECIES.length()); 1365 short[] b = fb.apply(SPECIES.length()); 1366 1367 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1368 for (int i = 0; i < a.length; i += SPECIES.length()) { 1369 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1370 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1371 VectorMask<Short> mv = av.lessThan(bv); 1372 1373 // Check results as part of computation. 1374 for (int j = 0; j < SPECIES.length(); j++) { 1375 Assert.assertEquals(mv.lane(j), a[i + j] < b[i + j]); 1376 } 1377 } 1378 } 1379 } 1380 1381 1382 @Test(dataProvider = "shortCompareOpProvider") 1383 static void greaterThanShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1384 short[] a = fa.apply(SPECIES.length()); 1385 short[] b = fb.apply(SPECIES.length()); 1386 1387 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1388 for (int i = 0; i < a.length; i += SPECIES.length()) { 1389 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1390 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1391 VectorMask<Short> mv = av.greaterThan(bv); 1392 1393 // Check results as part of computation. 1394 for (int j = 0; j < SPECIES.length(); j++) { 1395 Assert.assertEquals(mv.lane(j), a[i + j] > b[i + j]); 1396 } 1397 } 1398 } 1399 } 1400 1401 1402 @Test(dataProvider = "shortCompareOpProvider") 1403 static void equalShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1404 short[] a = fa.apply(SPECIES.length()); 1405 short[] b = fb.apply(SPECIES.length()); 1406 1407 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1408 for (int i = 0; i < a.length; i += SPECIES.length()) { 1409 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1410 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1411 VectorMask<Short> mv = av.equal(bv); 1412 1413 // Check results as part of computation. 1414 for (int j = 0; j < SPECIES.length(); j++) { 1415 Assert.assertEquals(mv.lane(j), a[i + j] == b[i + j]); 1416 } 1417 } 1418 } 1419 } 1420 1421 1422 @Test(dataProvider = "shortCompareOpProvider") 1423 static void notEqualShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1424 short[] a = fa.apply(SPECIES.length()); 1425 short[] b = fb.apply(SPECIES.length()); 1426 1427 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1428 for (int i = 0; i < a.length; i += SPECIES.length()) { 1429 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1430 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1431 VectorMask<Short> mv = av.notEqual(bv); 1432 1433 // Check results as part of computation. 1434 for (int j = 0; j < SPECIES.length(); j++) { 1435 Assert.assertEquals(mv.lane(j), a[i + j] != b[i + j]); 1436 } 1437 } 1438 } 1439 } 1440 1441 1442 @Test(dataProvider = "shortCompareOpProvider") 1443 static void lessThanEqShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1444 short[] a = fa.apply(SPECIES.length()); 1445 short[] b = fb.apply(SPECIES.length()); 1446 1447 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1448 for (int i = 0; i < a.length; i += SPECIES.length()) { 1449 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1450 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1451 VectorMask<Short> mv = av.lessThanEq(bv); 1452 1453 // Check results as part of computation. 1454 for (int j = 0; j < SPECIES.length(); j++) { 1455 Assert.assertEquals(mv.lane(j), a[i + j] <= b[i + j]); 1456 } 1457 } 1458 } 1459 } 1460 1461 1462 @Test(dataProvider = "shortCompareOpProvider") 1463 static void greaterThanEqShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1464 short[] a = fa.apply(SPECIES.length()); 1465 short[] b = fb.apply(SPECIES.length()); 1466 1467 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1468 for (int i = 0; i < a.length; i += SPECIES.length()) { 1469 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1470 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1471 VectorMask<Short> mv = av.greaterThanEq(bv); 1472 1473 // Check results as part of computation. 1474 for (int j = 0; j < SPECIES.length(); j++) { 1475 Assert.assertEquals(mv.lane(j), a[i + j] >= b[i + j]); 1476 } 1477 } 1478 } 1479 } 1480 1481 1482 static short blend(short a, short b, boolean mask) { 1483 return mask ? b : a; 1484 } 1485 1486 @Test(dataProvider = "shortBinaryOpMaskProvider") 1487 static void blendShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, 1488 IntFunction<boolean[]> fm) { 1489 short[] a = fa.apply(SPECIES.length()); 1490 short[] b = fb.apply(SPECIES.length()); 1491 short[] r = fr.apply(SPECIES.length()); 1492 boolean[] mask = fm.apply(SPECIES.length()); 1493 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask); 1494 1495 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1496 for (int i = 0; i < a.length; i += SPECIES.length()) { 1497 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1498 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1499 av.blend(bv, vmask).intoArray(r, i); 1500 } 1501 } 1502 1503 assertArraysEquals(a, b, r, mask, Short512VectorTests::blend); 1504 } 1505 1506 @Test(dataProvider = "shortUnaryOpShuffleProvider") 1507 static void RearrangeShort512VectorTests(IntFunction<short[]> fa, 1508 BiFunction<Integer,Integer,int[]> fs) { 1509 short[] a = fa.apply(SPECIES.length()); 1510 int[] order = fs.apply(a.length, SPECIES.length()); 1511 short[] r = fr.apply(SPECIES.length()); 1512 1513 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1514 for (int i = 0; i < a.length; i += SPECIES.length()) { 1515 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1516 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i); 1517 } 1518 } 1519 1520 assertRearrangeArraysEquals(a, r, order, SPECIES.length()); 1521 } 1522 1523 1524 1525 1526 @Test(dataProvider = "shortUnaryOpProvider") 1527 static void getShort512VectorTests(IntFunction<short[]> fa) { 1528 short[] a = fa.apply(SPECIES.length()); 1529 short[] r = fr.apply(SPECIES.length()); 1530 1531 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1532 for (int i = 0; i < a.length; i += SPECIES.length()) { 1533 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1534 int num_lanes = SPECIES.length(); 1535 // Manually unroll because full unroll happens after intrinsification. 1536 // Unroll is needed because get intrinsic requires for index to be a known constant. 1537 if (num_lanes == 1) { 1538 r[i]=av.lane(0); 1539 } else if (num_lanes == 2) { 1540 r[i]=av.lane(0); 1541 r[i+1]=av.lane(1); 1542 } else if (num_lanes == 4) { 1543 r[i]=av.lane(0); 1544 r[i+1]=av.lane(1); 1545 r[i+2]=av.lane(2); 1546 r[i+3]=av.lane(3); 1547 } else if (num_lanes == 8) { 1548 r[i]=av.lane(0); 1549 r[i+1]=av.lane(1); 1550 r[i+2]=av.lane(2); 1551 r[i+3]=av.lane(3); 1552 r[i+4]=av.lane(4); 1553 r[i+5]=av.lane(5); 1554 r[i+6]=av.lane(6); 1555 r[i+7]=av.lane(7); 1556 } else if (num_lanes == 16) { 1557 r[i]=av.lane(0); 1558 r[i+1]=av.lane(1); 1559 r[i+2]=av.lane(2); 1560 r[i+3]=av.lane(3); 1561 r[i+4]=av.lane(4); 1562 r[i+5]=av.lane(5); 1563 r[i+6]=av.lane(6); 1564 r[i+7]=av.lane(7); 1565 r[i+8]=av.lane(8); 1566 r[i+9]=av.lane(9); 1567 r[i+10]=av.lane(10); 1568 r[i+11]=av.lane(11); 1569 r[i+12]=av.lane(12); 1570 r[i+13]=av.lane(13); 1571 r[i+14]=av.lane(14); 1572 r[i+15]=av.lane(15); 1573 } else if (num_lanes == 32) { 1574 r[i]=av.lane(0); 1575 r[i+1]=av.lane(1); 1576 r[i+2]=av.lane(2); 1577 r[i+3]=av.lane(3); 1578 r[i+4]=av.lane(4); 1579 r[i+5]=av.lane(5); 1580 r[i+6]=av.lane(6); 1581 r[i+7]=av.lane(7); 1582 r[i+8]=av.lane(8); 1583 r[i+9]=av.lane(9); 1584 r[i+10]=av.lane(10); 1585 r[i+11]=av.lane(11); 1586 r[i+12]=av.lane(12); 1587 r[i+13]=av.lane(13); 1588 r[i+14]=av.lane(14); 1589 r[i+15]=av.lane(15); 1590 r[i+16]=av.lane(16); 1591 r[i+17]=av.lane(17); 1592 r[i+18]=av.lane(18); 1593 r[i+19]=av.lane(19); 1594 r[i+20]=av.lane(20); 1595 r[i+21]=av.lane(21); 1596 r[i+22]=av.lane(22); 1597 r[i+23]=av.lane(23); 1598 r[i+24]=av.lane(24); 1599 r[i+25]=av.lane(25); 1600 r[i+26]=av.lane(26); 1601 r[i+27]=av.lane(27); 1602 r[i+28]=av.lane(28); 1603 r[i+29]=av.lane(29); 1604 r[i+30]=av.lane(30); 1605 r[i+31]=av.lane(31); 1606 } else if (num_lanes == 64) { 1607 r[i]=av.lane(0); 1608 r[i+1]=av.lane(1); 1609 r[i+2]=av.lane(2); 1610 r[i+3]=av.lane(3); 1611 r[i+4]=av.lane(4); 1612 r[i+5]=av.lane(5); 1613 r[i+6]=av.lane(6); 1614 r[i+7]=av.lane(7); 1615 r[i+8]=av.lane(8); 1616 r[i+9]=av.lane(9); 1617 r[i+10]=av.lane(10); 1618 r[i+11]=av.lane(11); 1619 r[i+12]=av.lane(12); 1620 r[i+13]=av.lane(13); 1621 r[i+14]=av.lane(14); 1622 r[i+15]=av.lane(15); 1623 r[i+16]=av.lane(16); 1624 r[i+17]=av.lane(17); 1625 r[i+18]=av.lane(18); 1626 r[i+19]=av.lane(19); 1627 r[i+20]=av.lane(20); 1628 r[i+21]=av.lane(21); 1629 r[i+22]=av.lane(22); 1630 r[i+23]=av.lane(23); 1631 r[i+24]=av.lane(24); 1632 r[i+25]=av.lane(25); 1633 r[i+26]=av.lane(26); 1634 r[i+27]=av.lane(27); 1635 r[i+28]=av.lane(28); 1636 r[i+29]=av.lane(29); 1637 r[i+30]=av.lane(30); 1638 r[i+31]=av.lane(31); 1639 r[i+32]=av.lane(32); 1640 r[i+33]=av.lane(33); 1641 r[i+34]=av.lane(34); 1642 r[i+35]=av.lane(35); 1643 r[i+36]=av.lane(36); 1644 r[i+37]=av.lane(37); 1645 r[i+38]=av.lane(38); 1646 r[i+39]=av.lane(39); 1647 r[i+40]=av.lane(40); 1648 r[i+41]=av.lane(41); 1649 r[i+42]=av.lane(42); 1650 r[i+43]=av.lane(43); 1651 r[i+44]=av.lane(44); 1652 r[i+45]=av.lane(45); 1653 r[i+46]=av.lane(46); 1654 r[i+47]=av.lane(47); 1655 r[i+48]=av.lane(48); 1656 r[i+49]=av.lane(49); 1657 r[i+50]=av.lane(50); 1658 r[i+51]=av.lane(51); 1659 r[i+52]=av.lane(52); 1660 r[i+53]=av.lane(53); 1661 r[i+54]=av.lane(54); 1662 r[i+55]=av.lane(55); 1663 r[i+56]=av.lane(56); 1664 r[i+57]=av.lane(57); 1665 r[i+58]=av.lane(58); 1666 r[i+59]=av.lane(59); 1667 r[i+60]=av.lane(60); 1668 r[i+61]=av.lane(61); 1669 r[i+62]=av.lane(62); 1670 r[i+63]=av.lane(63); 1671 } else { 1672 for (int j = 0; j < SPECIES.length(); j++) { 1673 r[i+j]=av.lane(j); 1674 } 1675 } 1676 } 1677 } 1678 1679 assertArraysEquals(a, r, Short512VectorTests::get); 1680 } 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 static short neg(short a) { 1704 return (short)(-((short)a)); 1705 } 1706 1707 @Test(dataProvider = "shortUnaryOpProvider") 1708 static void negShort512VectorTests(IntFunction<short[]> fa) { 1709 short[] a = fa.apply(SPECIES.length()); 1710 short[] r = fr.apply(SPECIES.length()); 1711 1712 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1713 for (int i = 0; i < a.length; i += SPECIES.length()) { 1714 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1715 av.neg().intoArray(r, i); 1716 } 1717 } 1718 1719 assertArraysEquals(a, r, Short512VectorTests::neg); 1720 } 1721 1722 @Test(dataProvider = "shortUnaryOpMaskProvider") 1723 static void negMaskedShort512VectorTests(IntFunction<short[]> fa, 1724 IntFunction<boolean[]> fm) { 1725 short[] a = fa.apply(SPECIES.length()); 1726 short[] r = fr.apply(SPECIES.length()); 1727 boolean[] mask = fm.apply(SPECIES.length()); 1728 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask); 1729 1730 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1731 for (int i = 0; i < a.length; i += SPECIES.length()) { 1732 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1733 av.neg(vmask).intoArray(r, i); 1734 } 1735 } 1736 1737 assertArraysEquals(a, r, mask, Short512VectorTests::neg); 1738 } 1739 1740 static short abs(short a) { 1741 return (short)(Math.abs((short)a)); 1742 } 1743 1744 @Test(dataProvider = "shortUnaryOpProvider") 1745 static void absShort512VectorTests(IntFunction<short[]> fa) { 1746 short[] a = fa.apply(SPECIES.length()); 1747 short[] r = fr.apply(SPECIES.length()); 1748 1749 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1750 for (int i = 0; i < a.length; i += SPECIES.length()) { 1751 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1752 av.abs().intoArray(r, i); 1753 } 1754 } 1755 1756 assertArraysEquals(a, r, Short512VectorTests::abs); 1757 } 1758 1759 @Test(dataProvider = "shortUnaryOpMaskProvider") 1760 static void absMaskedShort512VectorTests(IntFunction<short[]> fa, 1761 IntFunction<boolean[]> fm) { 1762 short[] a = fa.apply(SPECIES.length()); 1763 short[] r = fr.apply(SPECIES.length()); 1764 boolean[] mask = fm.apply(SPECIES.length()); 1765 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask); 1766 1767 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1768 for (int i = 0; i < a.length; i += SPECIES.length()) { 1769 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1770 av.abs(vmask).intoArray(r, i); 1771 } 1772 } 1773 1774 assertArraysEquals(a, r, mask, Short512VectorTests::abs); 1775 } 1776 1777 1778 static short not(short a) { 1779 return (short)(~((short)a)); 1780 } 1781 1782 1783 1784 @Test(dataProvider = "shortUnaryOpProvider") 1785 static void notShort512VectorTests(IntFunction<short[]> fa) { 1786 short[] a = fa.apply(SPECIES.length()); 1787 short[] r = fr.apply(SPECIES.length()); 1788 1789 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1790 for (int i = 0; i < a.length; i += SPECIES.length()) { 1791 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1792 av.not().intoArray(r, i); 1793 } 1794 } 1795 1796 assertArraysEquals(a, r, Short512VectorTests::not); 1797 } 1798 1799 1800 1801 @Test(dataProvider = "shortUnaryOpMaskProvider") 1802 static void notMaskedShort512VectorTests(IntFunction<short[]> fa, 1803 IntFunction<boolean[]> fm) { 1804 short[] a = fa.apply(SPECIES.length()); 1805 short[] r = fr.apply(SPECIES.length()); 1806 boolean[] mask = fm.apply(SPECIES.length()); 1807 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask); 1808 1809 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1810 for (int i = 0; i < a.length; i += SPECIES.length()) { 1811 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1812 av.not(vmask).intoArray(r, i); 1813 } 1814 } 1815 1816 assertArraysEquals(a, r, mask, Short512VectorTests::not); 1817 } 1818 1819 1820 1821 1822 1823 1824 } 1825