< prev index next >

test/jdk/jdk/incubator/vector/ShortMaxVectorTests.java

Print this page
rev 54658 : refactored mask and shuffle creation methods, moved classes to top-level


  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 ShortMaxVectorTests
  28  */
  29 
  30 import jdk.incubator.vector.Vector.Shape;
  31 import jdk.incubator.vector.Vector.Species;


  32 import jdk.incubator.vector.Vector;
  33 
  34 import jdk.incubator.vector.ShortVector;
  35 
  36 import org.testng.Assert;
  37 import org.testng.annotations.DataProvider;
  38 import org.testng.annotations.Test;
  39 
  40 import java.lang.Integer;
  41 import java.util.List;
  42 import java.util.function.BiFunction;
  43 import java.util.function.IntFunction;
  44 import java.util.stream.Collectors;
  45 import java.util.stream.Stream;
  46 
  47 @Test
  48 public class ShortMaxVectorTests extends AbstractVectorTest {
  49 
  50     static final Species<Short> SPECIES =
  51                 ShortVector.SPECIES_MAX;
  52 
  53     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  54 
  55     static Shape getMaxBit() {
  56         return Shape.S_Max_BIT;
  57     }
  58 
  59     interface FUnOp {
  60         short apply(short a);
  61     }
  62 
  63     static void assertArraysEquals(short[] a, short[] r, FUnOp f) {
  64         int i = 0;
  65         try {
  66             for (; i < a.length; i++) {
  67                 Assert.assertEquals(r[i], f.apply(a[i]));
  68             }
  69         } catch (AssertionError e) {
  70             Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
  71         }
  72     }
  73 
  74     static void assertArraysEquals(short[] a, short[] r, boolean[] mask, FUnOp f) {
  75         int i = 0;
  76         try {


 416         short[] r = fr.apply(SPECIES.length());
 417 
 418         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 419             for (int i = 0; i < a.length; i += SPECIES.length()) {
 420                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 421                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 422                 av.add(bv).intoArray(r, i);
 423             }
 424         }
 425 
 426         assertArraysEquals(a, b, r, ShortMaxVectorTests::add);
 427     }
 428 
 429     @Test(dataProvider = "shortBinaryOpMaskProvider")
 430     static void addShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 431                                           IntFunction<boolean[]> fm) {
 432         short[] a = fa.apply(SPECIES.length());
 433         short[] b = fb.apply(SPECIES.length());
 434         short[] r = fr.apply(SPECIES.length());
 435         boolean[] mask = fm.apply(SPECIES.length());
 436         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 437 
 438         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 439             for (int i = 0; i < a.length; i += SPECIES.length()) {
 440                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 441                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 442                 av.add(bv, vmask).intoArray(r, i);
 443             }
 444         }
 445 
 446         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::add);
 447     }
 448     static short sub(short a, short b) {
 449         return (short)(a - b);
 450     }
 451 
 452     @Test(dataProvider = "shortBinaryOpProvider")
 453     static void subShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 454         short[] a = fa.apply(SPECIES.length());
 455         short[] b = fb.apply(SPECIES.length());
 456         short[] r = fr.apply(SPECIES.length());
 457 
 458         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 459             for (int i = 0; i < a.length; i += SPECIES.length()) {
 460                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 461                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 462                 av.sub(bv).intoArray(r, i);
 463             }
 464         }
 465 
 466         assertArraysEquals(a, b, r, ShortMaxVectorTests::sub);
 467     }
 468 
 469     @Test(dataProvider = "shortBinaryOpMaskProvider")
 470     static void subShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 471                                           IntFunction<boolean[]> fm) {
 472         short[] a = fa.apply(SPECIES.length());
 473         short[] b = fb.apply(SPECIES.length());
 474         short[] r = fr.apply(SPECIES.length());
 475         boolean[] mask = fm.apply(SPECIES.length());
 476         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 477 
 478         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 479             for (int i = 0; i < a.length; i += SPECIES.length()) {
 480                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 481                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 482                 av.sub(bv, vmask).intoArray(r, i);
 483             }
 484         }
 485 
 486         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::sub);
 487     }
 488 
 489 
 490     static short mul(short a, short b) {
 491         return (short)(a * b);
 492     }
 493 
 494     @Test(dataProvider = "shortBinaryOpProvider")
 495     static void mulShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 496         short[] a = fa.apply(SPECIES.length());


 498         short[] r = fr.apply(SPECIES.length());
 499 
 500         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 501             for (int i = 0; i < a.length; i += SPECIES.length()) {
 502                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 503                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 504                 av.mul(bv).intoArray(r, i);
 505             }
 506         }
 507 
 508         assertArraysEquals(a, b, r, ShortMaxVectorTests::mul);
 509     }
 510 
 511     @Test(dataProvider = "shortBinaryOpMaskProvider")
 512     static void mulShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 513                                           IntFunction<boolean[]> fm) {
 514         short[] a = fa.apply(SPECIES.length());
 515         short[] b = fb.apply(SPECIES.length());
 516         short[] r = fr.apply(SPECIES.length());
 517         boolean[] mask = fm.apply(SPECIES.length());
 518         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 519 
 520         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 521             for (int i = 0; i < a.length; i += SPECIES.length()) {
 522                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 523                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 524                 av.mul(bv, vmask).intoArray(r, i);
 525             }
 526         }
 527 
 528         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::mul);
 529     }
 530 
 531     static short and(short a, short b) {
 532         return (short)(a & b);
 533     }
 534 
 535     @Test(dataProvider = "shortBinaryOpProvider")
 536     static void andShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 537         short[] a = fa.apply(SPECIES.length());
 538         short[] b = fb.apply(SPECIES.length());


 541         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 542             for (int i = 0; i < a.length; i += SPECIES.length()) {
 543                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 544                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 545                 av.and(bv).intoArray(r, i);
 546             }
 547         }
 548 
 549         assertArraysEquals(a, b, r, ShortMaxVectorTests::and);
 550     }
 551 
 552 
 553 
 554     @Test(dataProvider = "shortBinaryOpMaskProvider")
 555     static void andShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 556                                           IntFunction<boolean[]> fm) {
 557         short[] a = fa.apply(SPECIES.length());
 558         short[] b = fb.apply(SPECIES.length());
 559         short[] r = fr.apply(SPECIES.length());
 560         boolean[] mask = fm.apply(SPECIES.length());
 561         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 562 
 563         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 564             for (int i = 0; i < a.length; i += SPECIES.length()) {
 565                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 566                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 567                 av.and(bv, vmask).intoArray(r, i);
 568             }
 569         }
 570 
 571         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::and);
 572     }
 573 
 574 
 575     static short or(short a, short b) {
 576         return (short)(a | b);
 577     }
 578 
 579     @Test(dataProvider = "shortBinaryOpProvider")
 580     static void orShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 581         short[] a = fa.apply(SPECIES.length());


 585         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 586             for (int i = 0; i < a.length; i += SPECIES.length()) {
 587                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 588                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 589                 av.or(bv).intoArray(r, i);
 590             }
 591         }
 592 
 593         assertArraysEquals(a, b, r, ShortMaxVectorTests::or);
 594     }
 595 
 596 
 597 
 598     @Test(dataProvider = "shortBinaryOpMaskProvider")
 599     static void orShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 600                                           IntFunction<boolean[]> fm) {
 601         short[] a = fa.apply(SPECIES.length());
 602         short[] b = fb.apply(SPECIES.length());
 603         short[] r = fr.apply(SPECIES.length());
 604         boolean[] mask = fm.apply(SPECIES.length());
 605         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 606 
 607         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 608             for (int i = 0; i < a.length; i += SPECIES.length()) {
 609                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 610                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 611                 av.or(bv, vmask).intoArray(r, i);
 612             }
 613         }
 614 
 615         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::or);
 616     }
 617 
 618 
 619     static short xor(short a, short b) {
 620         return (short)(a ^ b);
 621     }
 622 
 623     @Test(dataProvider = "shortBinaryOpProvider")
 624     static void xorShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 625         short[] a = fa.apply(SPECIES.length());


 629         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 630             for (int i = 0; i < a.length; i += SPECIES.length()) {
 631                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 632                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 633                 av.xor(bv).intoArray(r, i);
 634             }
 635         }
 636 
 637         assertArraysEquals(a, b, r, ShortMaxVectorTests::xor);
 638     }
 639 
 640 
 641 
 642     @Test(dataProvider = "shortBinaryOpMaskProvider")
 643     static void xorShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 644                                           IntFunction<boolean[]> fm) {
 645         short[] a = fa.apply(SPECIES.length());
 646         short[] b = fb.apply(SPECIES.length());
 647         short[] r = fr.apply(SPECIES.length());
 648         boolean[] mask = fm.apply(SPECIES.length());
 649         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 650 
 651         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 652             for (int i = 0; i < a.length; i += SPECIES.length()) {
 653                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 654                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 655                 av.xor(bv, vmask).intoArray(r, i);
 656             }
 657         }
 658 
 659         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::xor);
 660     }
 661 
 662 
 663 
 664 
 665 
 666 
 667 
 668 
 669 


 690 
 691         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 692             for (int i = 0; i < a.length; i += SPECIES.length()) {
 693                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 694                 av.aShiftR((int)b[i]).intoArray(r, i);
 695             }
 696         }
 697 
 698         assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::aShiftR_unary);
 699     }
 700 
 701 
 702 
 703     @Test(dataProvider = "shortBinaryOpMaskProvider")
 704     static void aShiftRShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
 705                                           IntFunction<boolean[]> fm) {
 706         short[] a = fa.apply(SPECIES.length());
 707         short[] b = fb.apply(SPECIES.length());
 708         short[] r = fr.apply(SPECIES.length());
 709         boolean[] mask = fm.apply(SPECIES.length());
 710         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 711 
 712         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 713             for (int i = 0; i < a.length; i += SPECIES.length()) {
 714                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 715                 av.aShiftR((int)b[i], vmask).intoArray(r, i);
 716             }
 717         }
 718 
 719         assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::aShiftR_unary);
 720     }
 721 
 722 
 723     static short shiftL_unary(short a, short b) {
 724         return (short)((a << (b & 15)));
 725     }
 726 
 727     @Test(dataProvider = "shortBinaryOpProvider")
 728     static void shiftLShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 729         short[] a = fa.apply(SPECIES.length());
 730         short[] b = fb.apply(SPECIES.length());


 732 
 733         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 734             for (int i = 0; i < a.length; i += SPECIES.length()) {
 735                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 736                 av.shiftL((int)b[i]).intoArray(r, i);
 737             }
 738         }
 739 
 740         assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::shiftL_unary);
 741     }
 742 
 743 
 744 
 745     @Test(dataProvider = "shortBinaryOpMaskProvider")
 746     static void shiftLShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
 747                                           IntFunction<boolean[]> fm) {
 748         short[] a = fa.apply(SPECIES.length());
 749         short[] b = fb.apply(SPECIES.length());
 750         short[] r = fr.apply(SPECIES.length());
 751         boolean[] mask = fm.apply(SPECIES.length());
 752         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 753 
 754         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 755             for (int i = 0; i < a.length; i += SPECIES.length()) {
 756                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 757                 av.shiftL((int)b[i], vmask).intoArray(r, i);
 758             }
 759         }
 760 
 761         assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftL_unary);
 762     }
 763 
 764 
 765     static short shiftR_unary(short a, short b) {
 766         return (short)(((a & 0xFFFF) >>> (b & 15)));
 767     }
 768 
 769     @Test(dataProvider = "shortBinaryOpProvider")
 770     static void shiftRShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 771         short[] a = fa.apply(SPECIES.length());
 772         short[] b = fb.apply(SPECIES.length());


 774 
 775         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 776             for (int i = 0; i < a.length; i += SPECIES.length()) {
 777                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 778                 av.shiftR((int)b[i]).intoArray(r, i);
 779             }
 780         }
 781 
 782         assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::shiftR_unary);
 783     }
 784 
 785 
 786 
 787     @Test(dataProvider = "shortBinaryOpMaskProvider")
 788     static void shiftRShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
 789                                           IntFunction<boolean[]> fm) {
 790         short[] a = fa.apply(SPECIES.length());
 791         short[] b = fb.apply(SPECIES.length());
 792         short[] r = fr.apply(SPECIES.length());
 793         boolean[] mask = fm.apply(SPECIES.length());
 794         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 795 
 796         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 797             for (int i = 0; i < a.length; i += SPECIES.length()) {
 798                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 799                 av.shiftR((int)b[i], vmask).intoArray(r, i);
 800             }
 801         }
 802 
 803         assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftR_unary);
 804     }
 805 
 806     static short max(short a, short b) {
 807         return (short)(Math.max(a, b));
 808     }
 809 
 810     @Test(dataProvider = "shortBinaryOpProvider")
 811     static void maxShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 812         short[] a = fa.apply(SPECIES.length());
 813         short[] b = fb.apply(SPECIES.length());
 814         short[] r = fr.apply(SPECIES.length());


1156         assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::maxAll, ShortMaxVectorTests::maxAll);
1157     }
1158 
1159     static boolean anyTrue(boolean[] a, int idx) {
1160         boolean res = false;
1161         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1162             res |= a[i];
1163         }
1164 
1165         return res;
1166     }
1167 
1168 
1169     @Test(dataProvider = "boolUnaryOpProvider")
1170     static void anyTrueShortMaxVectorTests(IntFunction<boolean[]> fm) {
1171         boolean[] mask = fm.apply(SPECIES.length());
1172         boolean[] r = fmr.apply(SPECIES.length());
1173 
1174         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1175             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1176                 Vector.Mask<Short> vmask = ShortVector.maskFromArray(SPECIES, mask, i);
1177                 r[i] = vmask.anyTrue();
1178             }
1179         }
1180 
1181         assertReductionBoolArraysEquals(mask, r, ShortMaxVectorTests::anyTrue);
1182     }
1183 
1184 
1185     static boolean allTrue(boolean[] a, int idx) {
1186         boolean res = true;
1187         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1188             res &= a[i];
1189         }
1190 
1191         return res;
1192     }
1193 
1194 
1195     @Test(dataProvider = "boolUnaryOpProvider")
1196     static void allTrueShortMaxVectorTests(IntFunction<boolean[]> fm) {
1197         boolean[] mask = fm.apply(SPECIES.length());
1198         boolean[] r = fmr.apply(SPECIES.length());
1199 
1200         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1201             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1202                 Vector.Mask<Short> vmask = ShortVector.maskFromArray(SPECIES, mask, i);
1203                 r[i] = vmask.allTrue();
1204             }
1205         }
1206 
1207         assertReductionBoolArraysEquals(mask, r, ShortMaxVectorTests::allTrue);
1208     }
1209 
1210 
1211     @Test(dataProvider = "shortUnaryOpProvider")
1212     static void withShortMaxVectorTests(IntFunction<short []> fa) {
1213         short[] a = fa.apply(SPECIES.length());
1214         short[] r = fr.apply(SPECIES.length());
1215 
1216         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1217             for (int i = 0; i < a.length; i += SPECIES.length()) {
1218                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1219                 av.with(0, (short)4).intoArray(r, i);
1220             }
1221         }
1222 
1223         assertInsertArraysEquals(a, r, (short)4, 0);
1224     }
1225 
1226     @Test(dataProvider = "shortCompareOpProvider")
1227     static void lessThanShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1228         short[] a = fa.apply(SPECIES.length());
1229         short[] b = fb.apply(SPECIES.length());
1230 
1231         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1232             for (int i = 0; i < a.length; i += SPECIES.length()) {
1233                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1234                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1235                 Vector.Mask<Short> mv = av.lessThan(bv);
1236 
1237                 // Check results as part of computation.
1238                 for (int j = 0; j < SPECIES.length(); j++) {
1239                     Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]);
1240                 }
1241             }
1242         }
1243     }
1244 
1245 
1246     @Test(dataProvider = "shortCompareOpProvider")
1247     static void greaterThanShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1248         short[] a = fa.apply(SPECIES.length());
1249         short[] b = fb.apply(SPECIES.length());
1250 
1251         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1252             for (int i = 0; i < a.length; i += SPECIES.length()) {
1253                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1254                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1255                 Vector.Mask<Short> mv = av.greaterThan(bv);
1256 
1257                 // Check results as part of computation.
1258                 for (int j = 0; j < SPECIES.length(); j++) {
1259                     Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]);
1260                 }
1261             }
1262         }
1263     }
1264 
1265 
1266     @Test(dataProvider = "shortCompareOpProvider")
1267     static void equalShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1268         short[] a = fa.apply(SPECIES.length());
1269         short[] b = fb.apply(SPECIES.length());
1270 
1271         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1272             for (int i = 0; i < a.length; i += SPECIES.length()) {
1273                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1274                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1275                 Vector.Mask<Short> mv = av.equal(bv);
1276 
1277                 // Check results as part of computation.
1278                 for (int j = 0; j < SPECIES.length(); j++) {
1279                     Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]);
1280                 }
1281             }
1282         }
1283     }
1284 
1285 
1286     @Test(dataProvider = "shortCompareOpProvider")
1287     static void notEqualShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1288         short[] a = fa.apply(SPECIES.length());
1289         short[] b = fb.apply(SPECIES.length());
1290 
1291         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1292             for (int i = 0; i < a.length; i += SPECIES.length()) {
1293                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1294                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1295                 Vector.Mask<Short> mv = av.notEqual(bv);
1296 
1297                 // Check results as part of computation.
1298                 for (int j = 0; j < SPECIES.length(); j++) {
1299                     Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]);
1300                 }
1301             }
1302         }
1303     }
1304 
1305 
1306     @Test(dataProvider = "shortCompareOpProvider")
1307     static void lessThanEqShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1308         short[] a = fa.apply(SPECIES.length());
1309         short[] b = fb.apply(SPECIES.length());
1310 
1311         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1312             for (int i = 0; i < a.length; i += SPECIES.length()) {
1313                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1314                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1315                 Vector.Mask<Short> mv = av.lessThanEq(bv);
1316 
1317                 // Check results as part of computation.
1318                 for (int j = 0; j < SPECIES.length(); j++) {
1319                     Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]);
1320                 }
1321             }
1322         }
1323     }
1324 
1325 
1326     @Test(dataProvider = "shortCompareOpProvider")
1327     static void greaterThanEqShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1328         short[] a = fa.apply(SPECIES.length());
1329         short[] b = fb.apply(SPECIES.length());
1330 
1331         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1332             for (int i = 0; i < a.length; i += SPECIES.length()) {
1333                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1334                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1335                 Vector.Mask<Short> mv = av.greaterThanEq(bv);
1336 
1337                 // Check results as part of computation.
1338                 for (int j = 0; j < SPECIES.length(); j++) {
1339                     Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]);
1340                 }
1341             }
1342         }
1343     }
1344 
1345 
1346     static short blend(short a, short b, boolean mask) {
1347         return mask ? b : a;
1348     }
1349 
1350     @Test(dataProvider = "shortBinaryOpMaskProvider")
1351     static void blendShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
1352                                           IntFunction<boolean[]> fm) {
1353         short[] a = fa.apply(SPECIES.length());
1354         short[] b = fb.apply(SPECIES.length());
1355         short[] r = fr.apply(SPECIES.length());
1356         boolean[] mask = fm.apply(SPECIES.length());
1357         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
1358 
1359         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1360             for (int i = 0; i < a.length; i += SPECIES.length()) {
1361                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1362                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1363                 av.blend(bv, vmask).intoArray(r, i);
1364             }
1365         }
1366 
1367         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::blend);
1368     }
1369 
1370     @Test(dataProvider = "shortUnaryOpShuffleProvider")
1371     static void RearrangeShortMaxVectorTests(IntFunction<short[]> fa,
1372                                            BiFunction<Integer,Integer,int[]> fs) {
1373         short[] a = fa.apply(SPECIES.length());
1374         int[] order = fs.apply(a.length, SPECIES.length());
1375         short[] r = fr.apply(SPECIES.length());
1376 
1377         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1378             for (int i = 0; i < a.length; i += SPECIES.length()) {
1379                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1380                 av.rearrange(ShortVector.shuffleFromArray(SPECIES, order, i)).intoArray(r, i);
1381             }
1382         }
1383 
1384         assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1385     }
1386 
1387 
1388 
1389 
1390     @Test(dataProvider = "shortUnaryOpProvider")
1391     static void getShortMaxVectorTests(IntFunction<short[]> fa) {
1392         short[] a = fa.apply(SPECIES.length());
1393         short[] r = fr.apply(SPECIES.length());
1394 
1395         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1396             for (int i = 0; i < a.length; i += SPECIES.length()) {
1397                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1398                 int num_lanes = SPECIES.length();
1399                 // Manually unroll because full unroll happens after intrinsification.
1400                 // Unroll is needed because get intrinsic requires for index to be a known constant.


1572     static void negShortMaxVectorTests(IntFunction<short[]> fa) {
1573         short[] a = fa.apply(SPECIES.length());
1574         short[] r = fr.apply(SPECIES.length());
1575 
1576         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1577             for (int i = 0; i < a.length; i += SPECIES.length()) {
1578                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1579                 av.neg().intoArray(r, i);
1580             }
1581         }
1582 
1583         assertArraysEquals(a, r, ShortMaxVectorTests::neg);
1584     }
1585 
1586     @Test(dataProvider = "shortUnaryOpMaskProvider")
1587     static void negMaskedShortMaxVectorTests(IntFunction<short[]> fa,
1588                                                 IntFunction<boolean[]> fm) {
1589         short[] a = fa.apply(SPECIES.length());
1590         short[] r = fr.apply(SPECIES.length());
1591         boolean[] mask = fm.apply(SPECIES.length());
1592         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
1593 
1594         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1595             for (int i = 0; i < a.length; i += SPECIES.length()) {
1596                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1597                 av.neg(vmask).intoArray(r, i);
1598             }
1599         }
1600 
1601         assertArraysEquals(a, r, mask, ShortMaxVectorTests::neg);
1602     }
1603 
1604     static short abs(short a) {
1605         return (short)(Math.abs((short)a));
1606     }
1607 
1608     @Test(dataProvider = "shortUnaryOpProvider")
1609     static void absShortMaxVectorTests(IntFunction<short[]> fa) {
1610         short[] a = fa.apply(SPECIES.length());
1611         short[] r = fr.apply(SPECIES.length());
1612 
1613         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1614             for (int i = 0; i < a.length; i += SPECIES.length()) {
1615                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1616                 av.abs().intoArray(r, i);
1617             }
1618         }
1619 
1620         assertArraysEquals(a, r, ShortMaxVectorTests::abs);
1621     }
1622 
1623     @Test(dataProvider = "shortUnaryOpMaskProvider")
1624     static void absMaskedShortMaxVectorTests(IntFunction<short[]> fa,
1625                                                 IntFunction<boolean[]> fm) {
1626         short[] a = fa.apply(SPECIES.length());
1627         short[] r = fr.apply(SPECIES.length());
1628         boolean[] mask = fm.apply(SPECIES.length());
1629         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
1630 
1631         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1632             for (int i = 0; i < a.length; i += SPECIES.length()) {
1633                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1634                 av.abs(vmask).intoArray(r, i);
1635             }
1636         }
1637 
1638         assertArraysEquals(a, r, mask, ShortMaxVectorTests::abs);
1639     }
1640 
1641 
1642     static short not(short a) {
1643         return (short)(~((short)a));
1644     }
1645 
1646 
1647 
1648     @Test(dataProvider = "shortUnaryOpProvider")
1649     static void notShortMaxVectorTests(IntFunction<short[]> fa) {


1651         short[] r = fr.apply(SPECIES.length());
1652 
1653         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1654             for (int i = 0; i < a.length; i += SPECIES.length()) {
1655                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1656                 av.not().intoArray(r, i);
1657             }
1658         }
1659 
1660         assertArraysEquals(a, r, ShortMaxVectorTests::not);
1661     }
1662 
1663 
1664 
1665     @Test(dataProvider = "shortUnaryOpMaskProvider")
1666     static void notMaskedShortMaxVectorTests(IntFunction<short[]> fa,
1667                                                 IntFunction<boolean[]> fm) {
1668         short[] a = fa.apply(SPECIES.length());
1669         short[] r = fr.apply(SPECIES.length());
1670         boolean[] mask = fm.apply(SPECIES.length());
1671         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
1672 
1673         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1674             for (int i = 0; i < a.length; i += SPECIES.length()) {
1675                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1676                 av.not(vmask).intoArray(r, i);
1677             }
1678         }
1679 
1680         assertArraysEquals(a, r, mask, ShortMaxVectorTests::not);
1681     }
1682 
1683 
1684 
1685 
1686 
1687 
1688 }
1689 


  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 ShortMaxVectorTests
  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 ShortMaxVectorTests extends AbstractVectorTest {
  51 
  52     static final VectorSpecies<Short> SPECIES =
  53                 ShortVector.SPECIES_MAX;
  54 
  55     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  56 
  57     static VectorShape getMaxBit() {
  58         return VectorShape.S_Max_BIT;
  59     }
  60 
  61     interface FUnOp {
  62         short apply(short a);
  63     }
  64 
  65     static void assertArraysEquals(short[] a, short[] r, FUnOp f) {
  66         int i = 0;
  67         try {
  68             for (; i < a.length; i++) {
  69                 Assert.assertEquals(r[i], f.apply(a[i]));
  70             }
  71         } catch (AssertionError e) {
  72             Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
  73         }
  74     }
  75 
  76     static void assertArraysEquals(short[] a, short[] r, boolean[] mask, FUnOp f) {
  77         int i = 0;
  78         try {


 418         short[] r = fr.apply(SPECIES.length());
 419 
 420         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 421             for (int i = 0; i < a.length; i += SPECIES.length()) {
 422                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 423                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 424                 av.add(bv).intoArray(r, i);
 425             }
 426         }
 427 
 428         assertArraysEquals(a, b, r, ShortMaxVectorTests::add);
 429     }
 430 
 431     @Test(dataProvider = "shortBinaryOpMaskProvider")
 432     static void addShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 433                                           IntFunction<boolean[]> fm) {
 434         short[] a = fa.apply(SPECIES.length());
 435         short[] b = fb.apply(SPECIES.length());
 436         short[] r = fr.apply(SPECIES.length());
 437         boolean[] mask = fm.apply(SPECIES.length());
 438         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 439 
 440         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 441             for (int i = 0; i < a.length; i += SPECIES.length()) {
 442                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 443                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 444                 av.add(bv, vmask).intoArray(r, i);
 445             }
 446         }
 447 
 448         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::add);
 449     }
 450     static short sub(short a, short b) {
 451         return (short)(a - b);
 452     }
 453 
 454     @Test(dataProvider = "shortBinaryOpProvider")
 455     static void subShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 456         short[] a = fa.apply(SPECIES.length());
 457         short[] b = fb.apply(SPECIES.length());
 458         short[] r = fr.apply(SPECIES.length());
 459 
 460         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 461             for (int i = 0; i < a.length; i += SPECIES.length()) {
 462                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 463                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 464                 av.sub(bv).intoArray(r, i);
 465             }
 466         }
 467 
 468         assertArraysEquals(a, b, r, ShortMaxVectorTests::sub);
 469     }
 470 
 471     @Test(dataProvider = "shortBinaryOpMaskProvider")
 472     static void subShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 473                                           IntFunction<boolean[]> fm) {
 474         short[] a = fa.apply(SPECIES.length());
 475         short[] b = fb.apply(SPECIES.length());
 476         short[] r = fr.apply(SPECIES.length());
 477         boolean[] mask = fm.apply(SPECIES.length());
 478         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 479 
 480         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 481             for (int i = 0; i < a.length; i += SPECIES.length()) {
 482                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 483                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 484                 av.sub(bv, vmask).intoArray(r, i);
 485             }
 486         }
 487 
 488         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::sub);
 489     }
 490 
 491 
 492     static short mul(short a, short b) {
 493         return (short)(a * b);
 494     }
 495 
 496     @Test(dataProvider = "shortBinaryOpProvider")
 497     static void mulShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 498         short[] a = fa.apply(SPECIES.length());


 500         short[] r = fr.apply(SPECIES.length());
 501 
 502         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 503             for (int i = 0; i < a.length; i += SPECIES.length()) {
 504                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 505                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 506                 av.mul(bv).intoArray(r, i);
 507             }
 508         }
 509 
 510         assertArraysEquals(a, b, r, ShortMaxVectorTests::mul);
 511     }
 512 
 513     @Test(dataProvider = "shortBinaryOpMaskProvider")
 514     static void mulShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 515                                           IntFunction<boolean[]> fm) {
 516         short[] a = fa.apply(SPECIES.length());
 517         short[] b = fb.apply(SPECIES.length());
 518         short[] r = fr.apply(SPECIES.length());
 519         boolean[] mask = fm.apply(SPECIES.length());
 520         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 521 
 522         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 523             for (int i = 0; i < a.length; i += SPECIES.length()) {
 524                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 525                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 526                 av.mul(bv, vmask).intoArray(r, i);
 527             }
 528         }
 529 
 530         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::mul);
 531     }
 532 
 533     static short and(short a, short b) {
 534         return (short)(a & b);
 535     }
 536 
 537     @Test(dataProvider = "shortBinaryOpProvider")
 538     static void andShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 539         short[] a = fa.apply(SPECIES.length());
 540         short[] b = fb.apply(SPECIES.length());


 543         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 544             for (int i = 0; i < a.length; i += SPECIES.length()) {
 545                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 546                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 547                 av.and(bv).intoArray(r, i);
 548             }
 549         }
 550 
 551         assertArraysEquals(a, b, r, ShortMaxVectorTests::and);
 552     }
 553 
 554 
 555 
 556     @Test(dataProvider = "shortBinaryOpMaskProvider")
 557     static void andShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 558                                           IntFunction<boolean[]> fm) {
 559         short[] a = fa.apply(SPECIES.length());
 560         short[] b = fb.apply(SPECIES.length());
 561         short[] r = fr.apply(SPECIES.length());
 562         boolean[] mask = fm.apply(SPECIES.length());
 563         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 564 
 565         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 566             for (int i = 0; i < a.length; i += SPECIES.length()) {
 567                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 568                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 569                 av.and(bv, vmask).intoArray(r, i);
 570             }
 571         }
 572 
 573         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::and);
 574     }
 575 
 576 
 577     static short or(short a, short b) {
 578         return (short)(a | b);
 579     }
 580 
 581     @Test(dataProvider = "shortBinaryOpProvider")
 582     static void orShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 583         short[] a = fa.apply(SPECIES.length());


 587         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 588             for (int i = 0; i < a.length; i += SPECIES.length()) {
 589                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 590                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 591                 av.or(bv).intoArray(r, i);
 592             }
 593         }
 594 
 595         assertArraysEquals(a, b, r, ShortMaxVectorTests::or);
 596     }
 597 
 598 
 599 
 600     @Test(dataProvider = "shortBinaryOpMaskProvider")
 601     static void orShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 602                                           IntFunction<boolean[]> fm) {
 603         short[] a = fa.apply(SPECIES.length());
 604         short[] b = fb.apply(SPECIES.length());
 605         short[] r = fr.apply(SPECIES.length());
 606         boolean[] mask = fm.apply(SPECIES.length());
 607         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 608 
 609         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 610             for (int i = 0; i < a.length; i += SPECIES.length()) {
 611                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 612                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 613                 av.or(bv, vmask).intoArray(r, i);
 614             }
 615         }
 616 
 617         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::or);
 618     }
 619 
 620 
 621     static short xor(short a, short b) {
 622         return (short)(a ^ b);
 623     }
 624 
 625     @Test(dataProvider = "shortBinaryOpProvider")
 626     static void xorShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 627         short[] a = fa.apply(SPECIES.length());


 631         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 632             for (int i = 0; i < a.length; i += SPECIES.length()) {
 633                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 634                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 635                 av.xor(bv).intoArray(r, i);
 636             }
 637         }
 638 
 639         assertArraysEquals(a, b, r, ShortMaxVectorTests::xor);
 640     }
 641 
 642 
 643 
 644     @Test(dataProvider = "shortBinaryOpMaskProvider")
 645     static void xorShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 646                                           IntFunction<boolean[]> fm) {
 647         short[] a = fa.apply(SPECIES.length());
 648         short[] b = fb.apply(SPECIES.length());
 649         short[] r = fr.apply(SPECIES.length());
 650         boolean[] mask = fm.apply(SPECIES.length());
 651         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 652 
 653         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 654             for (int i = 0; i < a.length; i += SPECIES.length()) {
 655                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 656                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 657                 av.xor(bv, vmask).intoArray(r, i);
 658             }
 659         }
 660 
 661         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::xor);
 662     }
 663 
 664 
 665 
 666 
 667 
 668 
 669 
 670 
 671 


 692 
 693         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 694             for (int i = 0; i < a.length; i += SPECIES.length()) {
 695                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 696                 av.aShiftR((int)b[i]).intoArray(r, i);
 697             }
 698         }
 699 
 700         assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::aShiftR_unary);
 701     }
 702 
 703 
 704 
 705     @Test(dataProvider = "shortBinaryOpMaskProvider")
 706     static void aShiftRShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
 707                                           IntFunction<boolean[]> fm) {
 708         short[] a = fa.apply(SPECIES.length());
 709         short[] b = fb.apply(SPECIES.length());
 710         short[] r = fr.apply(SPECIES.length());
 711         boolean[] mask = fm.apply(SPECIES.length());
 712         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 713 
 714         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 715             for (int i = 0; i < a.length; i += SPECIES.length()) {
 716                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 717                 av.aShiftR((int)b[i], vmask).intoArray(r, i);
 718             }
 719         }
 720 
 721         assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::aShiftR_unary);
 722     }
 723 
 724 
 725     static short shiftL_unary(short a, short b) {
 726         return (short)((a << (b & 15)));
 727     }
 728 
 729     @Test(dataProvider = "shortBinaryOpProvider")
 730     static void shiftLShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 731         short[] a = fa.apply(SPECIES.length());
 732         short[] b = fb.apply(SPECIES.length());


 734 
 735         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 736             for (int i = 0; i < a.length; i += SPECIES.length()) {
 737                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 738                 av.shiftL((int)b[i]).intoArray(r, i);
 739             }
 740         }
 741 
 742         assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::shiftL_unary);
 743     }
 744 
 745 
 746 
 747     @Test(dataProvider = "shortBinaryOpMaskProvider")
 748     static void shiftLShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
 749                                           IntFunction<boolean[]> fm) {
 750         short[] a = fa.apply(SPECIES.length());
 751         short[] b = fb.apply(SPECIES.length());
 752         short[] r = fr.apply(SPECIES.length());
 753         boolean[] mask = fm.apply(SPECIES.length());
 754         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 755 
 756         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 757             for (int i = 0; i < a.length; i += SPECIES.length()) {
 758                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 759                 av.shiftL((int)b[i], vmask).intoArray(r, i);
 760             }
 761         }
 762 
 763         assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftL_unary);
 764     }
 765 
 766 
 767     static short shiftR_unary(short a, short b) {
 768         return (short)(((a & 0xFFFF) >>> (b & 15)));
 769     }
 770 
 771     @Test(dataProvider = "shortBinaryOpProvider")
 772     static void shiftRShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 773         short[] a = fa.apply(SPECIES.length());
 774         short[] b = fb.apply(SPECIES.length());


 776 
 777         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 778             for (int i = 0; i < a.length; i += SPECIES.length()) {
 779                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 780                 av.shiftR((int)b[i]).intoArray(r, i);
 781             }
 782         }
 783 
 784         assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::shiftR_unary);
 785     }
 786 
 787 
 788 
 789     @Test(dataProvider = "shortBinaryOpMaskProvider")
 790     static void shiftRShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
 791                                           IntFunction<boolean[]> fm) {
 792         short[] a = fa.apply(SPECIES.length());
 793         short[] b = fb.apply(SPECIES.length());
 794         short[] r = fr.apply(SPECIES.length());
 795         boolean[] mask = fm.apply(SPECIES.length());
 796         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 797 
 798         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 799             for (int i = 0; i < a.length; i += SPECIES.length()) {
 800                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 801                 av.shiftR((int)b[i], vmask).intoArray(r, i);
 802             }
 803         }
 804 
 805         assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftR_unary);
 806     }
 807 
 808     static short max(short a, short b) {
 809         return (short)(Math.max(a, b));
 810     }
 811 
 812     @Test(dataProvider = "shortBinaryOpProvider")
 813     static void maxShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 814         short[] a = fa.apply(SPECIES.length());
 815         short[] b = fb.apply(SPECIES.length());
 816         short[] r = fr.apply(SPECIES.length());


1158         assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::maxAll, ShortMaxVectorTests::maxAll);
1159     }
1160 
1161     static boolean anyTrue(boolean[] a, int idx) {
1162         boolean res = false;
1163         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1164             res |= a[i];
1165         }
1166 
1167         return res;
1168     }
1169 
1170 
1171     @Test(dataProvider = "boolUnaryOpProvider")
1172     static void anyTrueShortMaxVectorTests(IntFunction<boolean[]> fm) {
1173         boolean[] mask = fm.apply(SPECIES.length());
1174         boolean[] r = fmr.apply(SPECIES.length());
1175 
1176         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1177             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1178                 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, i);
1179                 r[i] = vmask.anyTrue();
1180             }
1181         }
1182 
1183         assertReductionBoolArraysEquals(mask, r, ShortMaxVectorTests::anyTrue);
1184     }
1185 
1186 
1187     static boolean allTrue(boolean[] a, int idx) {
1188         boolean res = true;
1189         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1190             res &= a[i];
1191         }
1192 
1193         return res;
1194     }
1195 
1196 
1197     @Test(dataProvider = "boolUnaryOpProvider")
1198     static void allTrueShortMaxVectorTests(IntFunction<boolean[]> fm) {
1199         boolean[] mask = fm.apply(SPECIES.length());
1200         boolean[] r = fmr.apply(SPECIES.length());
1201 
1202         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1203             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1204                 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, i);
1205                 r[i] = vmask.allTrue();
1206             }
1207         }
1208 
1209         assertReductionBoolArraysEquals(mask, r, ShortMaxVectorTests::allTrue);
1210     }
1211 
1212 
1213     @Test(dataProvider = "shortUnaryOpProvider")
1214     static void withShortMaxVectorTests(IntFunction<short []> fa) {
1215         short[] a = fa.apply(SPECIES.length());
1216         short[] r = fr.apply(SPECIES.length());
1217 
1218         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1219             for (int i = 0; i < a.length; i += SPECIES.length()) {
1220                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1221                 av.with(0, (short)4).intoArray(r, i);
1222             }
1223         }
1224 
1225         assertInsertArraysEquals(a, r, (short)4, 0);
1226     }
1227 
1228     @Test(dataProvider = "shortCompareOpProvider")
1229     static void lessThanShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1230         short[] a = fa.apply(SPECIES.length());
1231         short[] b = fb.apply(SPECIES.length());
1232 
1233         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1234             for (int i = 0; i < a.length; i += SPECIES.length()) {
1235                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1236                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1237                 VectorMask<Short> mv = av.lessThan(bv);
1238 
1239                 // Check results as part of computation.
1240                 for (int j = 0; j < SPECIES.length(); j++) {
1241                     Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]);
1242                 }
1243             }
1244         }
1245     }
1246 
1247 
1248     @Test(dataProvider = "shortCompareOpProvider")
1249     static void greaterThanShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1250         short[] a = fa.apply(SPECIES.length());
1251         short[] b = fb.apply(SPECIES.length());
1252 
1253         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1254             for (int i = 0; i < a.length; i += SPECIES.length()) {
1255                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1256                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1257                 VectorMask<Short> mv = av.greaterThan(bv);
1258 
1259                 // Check results as part of computation.
1260                 for (int j = 0; j < SPECIES.length(); j++) {
1261                     Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]);
1262                 }
1263             }
1264         }
1265     }
1266 
1267 
1268     @Test(dataProvider = "shortCompareOpProvider")
1269     static void equalShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1270         short[] a = fa.apply(SPECIES.length());
1271         short[] b = fb.apply(SPECIES.length());
1272 
1273         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1274             for (int i = 0; i < a.length; i += SPECIES.length()) {
1275                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1276                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1277                 VectorMask<Short> mv = av.equal(bv);
1278 
1279                 // Check results as part of computation.
1280                 for (int j = 0; j < SPECIES.length(); j++) {
1281                     Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]);
1282                 }
1283             }
1284         }
1285     }
1286 
1287 
1288     @Test(dataProvider = "shortCompareOpProvider")
1289     static void notEqualShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1290         short[] a = fa.apply(SPECIES.length());
1291         short[] b = fb.apply(SPECIES.length());
1292 
1293         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1294             for (int i = 0; i < a.length; i += SPECIES.length()) {
1295                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1296                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1297                 VectorMask<Short> mv = av.notEqual(bv);
1298 
1299                 // Check results as part of computation.
1300                 for (int j = 0; j < SPECIES.length(); j++) {
1301                     Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]);
1302                 }
1303             }
1304         }
1305     }
1306 
1307 
1308     @Test(dataProvider = "shortCompareOpProvider")
1309     static void lessThanEqShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1310         short[] a = fa.apply(SPECIES.length());
1311         short[] b = fb.apply(SPECIES.length());
1312 
1313         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1314             for (int i = 0; i < a.length; i += SPECIES.length()) {
1315                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1316                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1317                 VectorMask<Short> mv = av.lessThanEq(bv);
1318 
1319                 // Check results as part of computation.
1320                 for (int j = 0; j < SPECIES.length(); j++) {
1321                     Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]);
1322                 }
1323             }
1324         }
1325     }
1326 
1327 
1328     @Test(dataProvider = "shortCompareOpProvider")
1329     static void greaterThanEqShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1330         short[] a = fa.apply(SPECIES.length());
1331         short[] b = fb.apply(SPECIES.length());
1332 
1333         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1334             for (int i = 0; i < a.length; i += SPECIES.length()) {
1335                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1336                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1337                 VectorMask<Short> mv = av.greaterThanEq(bv);
1338 
1339                 // Check results as part of computation.
1340                 for (int j = 0; j < SPECIES.length(); j++) {
1341                     Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]);
1342                 }
1343             }
1344         }
1345     }
1346 
1347 
1348     static short blend(short a, short b, boolean mask) {
1349         return mask ? b : a;
1350     }
1351 
1352     @Test(dataProvider = "shortBinaryOpMaskProvider")
1353     static void blendShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
1354                                           IntFunction<boolean[]> fm) {
1355         short[] a = fa.apply(SPECIES.length());
1356         short[] b = fb.apply(SPECIES.length());
1357         short[] r = fr.apply(SPECIES.length());
1358         boolean[] mask = fm.apply(SPECIES.length());
1359         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
1360 
1361         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1362             for (int i = 0; i < a.length; i += SPECIES.length()) {
1363                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1364                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1365                 av.blend(bv, vmask).intoArray(r, i);
1366             }
1367         }
1368 
1369         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::blend);
1370     }
1371 
1372     @Test(dataProvider = "shortUnaryOpShuffleProvider")
1373     static void RearrangeShortMaxVectorTests(IntFunction<short[]> fa,
1374                                            BiFunction<Integer,Integer,int[]> fs) {
1375         short[] a = fa.apply(SPECIES.length());
1376         int[] order = fs.apply(a.length, SPECIES.length());
1377         short[] r = fr.apply(SPECIES.length());
1378 
1379         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1380             for (int i = 0; i < a.length; i += SPECIES.length()) {
1381                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1382                 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
1383             }
1384         }
1385 
1386         assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1387     }
1388 
1389 
1390 
1391 
1392     @Test(dataProvider = "shortUnaryOpProvider")
1393     static void getShortMaxVectorTests(IntFunction<short[]> fa) {
1394         short[] a = fa.apply(SPECIES.length());
1395         short[] r = fr.apply(SPECIES.length());
1396 
1397         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1398             for (int i = 0; i < a.length; i += SPECIES.length()) {
1399                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1400                 int num_lanes = SPECIES.length();
1401                 // Manually unroll because full unroll happens after intrinsification.
1402                 // Unroll is needed because get intrinsic requires for index to be a known constant.


1574     static void negShortMaxVectorTests(IntFunction<short[]> fa) {
1575         short[] a = fa.apply(SPECIES.length());
1576         short[] r = fr.apply(SPECIES.length());
1577 
1578         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1579             for (int i = 0; i < a.length; i += SPECIES.length()) {
1580                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1581                 av.neg().intoArray(r, i);
1582             }
1583         }
1584 
1585         assertArraysEquals(a, r, ShortMaxVectorTests::neg);
1586     }
1587 
1588     @Test(dataProvider = "shortUnaryOpMaskProvider")
1589     static void negMaskedShortMaxVectorTests(IntFunction<short[]> fa,
1590                                                 IntFunction<boolean[]> fm) {
1591         short[] a = fa.apply(SPECIES.length());
1592         short[] r = fr.apply(SPECIES.length());
1593         boolean[] mask = fm.apply(SPECIES.length());
1594         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
1595 
1596         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1597             for (int i = 0; i < a.length; i += SPECIES.length()) {
1598                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1599                 av.neg(vmask).intoArray(r, i);
1600             }
1601         }
1602 
1603         assertArraysEquals(a, r, mask, ShortMaxVectorTests::neg);
1604     }
1605 
1606     static short abs(short a) {
1607         return (short)(Math.abs((short)a));
1608     }
1609 
1610     @Test(dataProvider = "shortUnaryOpProvider")
1611     static void absShortMaxVectorTests(IntFunction<short[]> fa) {
1612         short[] a = fa.apply(SPECIES.length());
1613         short[] r = fr.apply(SPECIES.length());
1614 
1615         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1616             for (int i = 0; i < a.length; i += SPECIES.length()) {
1617                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1618                 av.abs().intoArray(r, i);
1619             }
1620         }
1621 
1622         assertArraysEquals(a, r, ShortMaxVectorTests::abs);
1623     }
1624 
1625     @Test(dataProvider = "shortUnaryOpMaskProvider")
1626     static void absMaskedShortMaxVectorTests(IntFunction<short[]> fa,
1627                                                 IntFunction<boolean[]> fm) {
1628         short[] a = fa.apply(SPECIES.length());
1629         short[] r = fr.apply(SPECIES.length());
1630         boolean[] mask = fm.apply(SPECIES.length());
1631         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
1632 
1633         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1634             for (int i = 0; i < a.length; i += SPECIES.length()) {
1635                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1636                 av.abs(vmask).intoArray(r, i);
1637             }
1638         }
1639 
1640         assertArraysEquals(a, r, mask, ShortMaxVectorTests::abs);
1641     }
1642 
1643 
1644     static short not(short a) {
1645         return (short)(~((short)a));
1646     }
1647 
1648 
1649 
1650     @Test(dataProvider = "shortUnaryOpProvider")
1651     static void notShortMaxVectorTests(IntFunction<short[]> fa) {


1653         short[] r = fr.apply(SPECIES.length());
1654 
1655         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1656             for (int i = 0; i < a.length; i += SPECIES.length()) {
1657                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1658                 av.not().intoArray(r, i);
1659             }
1660         }
1661 
1662         assertArraysEquals(a, r, ShortMaxVectorTests::not);
1663     }
1664 
1665 
1666 
1667     @Test(dataProvider = "shortUnaryOpMaskProvider")
1668     static void notMaskedShortMaxVectorTests(IntFunction<short[]> fa,
1669                                                 IntFunction<boolean[]> fm) {
1670         short[] a = fa.apply(SPECIES.length());
1671         short[] r = fr.apply(SPECIES.length());
1672         boolean[] mask = fm.apply(SPECIES.length());
1673         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
1674 
1675         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1676             for (int i = 0; i < a.length; i += SPECIES.length()) {
1677                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1678                 av.not(vmask).intoArray(r, i);
1679             }
1680         }
1681 
1682         assertArraysEquals(a, r, mask, ShortMaxVectorTests::not);
1683     }
1684 
1685 
1686 
1687 
1688 
1689 
1690 }
1691 
< prev index next >