< prev index next >

test/jdk/jdk/incubator/vector/Int128VectorTests.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 Int128VectorTests
  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.IntVector;
  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.Arrays;
  43 import java.util.function.BiFunction;
  44 import java.util.function.IntFunction;
  45 import java.util.stream.Collectors;
  46 import java.util.stream.Stream;
  47 
  48 @Test
  49 public class Int128VectorTests extends AbstractVectorTest {
  50 
  51     static final Species<Integer> SPECIES =
  52                 IntVector.SPECIES_128;
  53 
  54     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  55 
  56     interface FUnOp {
  57         int apply(int a);
  58     }
  59 
  60     static void assertArraysEquals(int[] a, int[] r, FUnOp f) {
  61         int i = 0;
  62         try {
  63             for (; i < a.length; i++) {
  64                 Assert.assertEquals(r[i], f.apply(a[i]));
  65             }
  66         } catch (AssertionError e) {
  67             Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
  68         }
  69     }
  70 
  71     static void assertArraysEquals(int[] a, int[] r, boolean[] mask, FUnOp f) {


 436         int[] r = fr.apply(SPECIES.length());
 437 
 438         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 439             for (int i = 0; i < a.length; i += SPECIES.length()) {
 440                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 441                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 442                 av.add(bv).intoArray(r, i);
 443             }
 444         }
 445 
 446         assertArraysEquals(a, b, r, Int128VectorTests::add);
 447     }
 448 
 449     @Test(dataProvider = "intBinaryOpMaskProvider")
 450     static void addInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 451                                           IntFunction<boolean[]> fm) {
 452         int[] a = fa.apply(SPECIES.length());
 453         int[] b = fb.apply(SPECIES.length());
 454         int[] r = fr.apply(SPECIES.length());
 455         boolean[] mask = fm.apply(SPECIES.length());
 456         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
 457 
 458         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 459             for (int i = 0; i < a.length; i += SPECIES.length()) {
 460                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 461                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 462                 av.add(bv, vmask).intoArray(r, i);
 463             }
 464         }
 465 
 466         assertArraysEquals(a, b, r, mask, Int128VectorTests::add);
 467     }
 468     static int sub(int a, int b) {
 469         return (int)(a - b);
 470     }
 471 
 472     @Test(dataProvider = "intBinaryOpProvider")
 473     static void subInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 474         int[] a = fa.apply(SPECIES.length());
 475         int[] b = fb.apply(SPECIES.length());
 476         int[] r = fr.apply(SPECIES.length());
 477 
 478         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 479             for (int i = 0; i < a.length; i += SPECIES.length()) {
 480                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 481                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 482                 av.sub(bv).intoArray(r, i);
 483             }
 484         }
 485 
 486         assertArraysEquals(a, b, r, Int128VectorTests::sub);
 487     }
 488 
 489     @Test(dataProvider = "intBinaryOpMaskProvider")
 490     static void subInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 491                                           IntFunction<boolean[]> fm) {
 492         int[] a = fa.apply(SPECIES.length());
 493         int[] b = fb.apply(SPECIES.length());
 494         int[] r = fr.apply(SPECIES.length());
 495         boolean[] mask = fm.apply(SPECIES.length());
 496         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
 497 
 498         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 499             for (int i = 0; i < a.length; i += SPECIES.length()) {
 500                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 501                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 502                 av.sub(bv, vmask).intoArray(r, i);
 503             }
 504         }
 505 
 506         assertArraysEquals(a, b, r, mask, Int128VectorTests::sub);
 507     }
 508 
 509 
 510     static int mul(int a, int b) {
 511         return (int)(a * b);
 512     }
 513 
 514     @Test(dataProvider = "intBinaryOpProvider")
 515     static void mulInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 516         int[] a = fa.apply(SPECIES.length());


 518         int[] r = fr.apply(SPECIES.length());
 519 
 520         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 521             for (int i = 0; i < a.length; i += SPECIES.length()) {
 522                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 523                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 524                 av.mul(bv).intoArray(r, i);
 525             }
 526         }
 527 
 528         assertArraysEquals(a, b, r, Int128VectorTests::mul);
 529     }
 530 
 531     @Test(dataProvider = "intBinaryOpMaskProvider")
 532     static void mulInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 533                                           IntFunction<boolean[]> fm) {
 534         int[] a = fa.apply(SPECIES.length());
 535         int[] b = fb.apply(SPECIES.length());
 536         int[] r = fr.apply(SPECIES.length());
 537         boolean[] mask = fm.apply(SPECIES.length());
 538         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
 539 
 540         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 541             for (int i = 0; i < a.length; i += SPECIES.length()) {
 542                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 543                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 544                 av.mul(bv, vmask).intoArray(r, i);
 545             }
 546         }
 547 
 548         assertArraysEquals(a, b, r, mask, Int128VectorTests::mul);
 549     }
 550 
 551     static int and(int a, int b) {
 552         return (int)(a & b);
 553     }
 554 
 555     @Test(dataProvider = "intBinaryOpProvider")
 556     static void andInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 557         int[] a = fa.apply(SPECIES.length());
 558         int[] b = fb.apply(SPECIES.length());


 561         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 562             for (int i = 0; i < a.length; i += SPECIES.length()) {
 563                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 564                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 565                 av.and(bv).intoArray(r, i);
 566             }
 567         }
 568 
 569         assertArraysEquals(a, b, r, Int128VectorTests::and);
 570     }
 571 
 572 
 573 
 574     @Test(dataProvider = "intBinaryOpMaskProvider")
 575     static void andInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 576                                           IntFunction<boolean[]> fm) {
 577         int[] a = fa.apply(SPECIES.length());
 578         int[] b = fb.apply(SPECIES.length());
 579         int[] r = fr.apply(SPECIES.length());
 580         boolean[] mask = fm.apply(SPECIES.length());
 581         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
 582 
 583         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 584             for (int i = 0; i < a.length; i += SPECIES.length()) {
 585                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 586                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 587                 av.and(bv, vmask).intoArray(r, i);
 588             }
 589         }
 590 
 591         assertArraysEquals(a, b, r, mask, Int128VectorTests::and);
 592     }
 593 
 594 
 595     static int or(int a, int b) {
 596         return (int)(a | b);
 597     }
 598 
 599     @Test(dataProvider = "intBinaryOpProvider")
 600     static void orInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 601         int[] a = fa.apply(SPECIES.length());


 605         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 606             for (int i = 0; i < a.length; i += SPECIES.length()) {
 607                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 608                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 609                 av.or(bv).intoArray(r, i);
 610             }
 611         }
 612 
 613         assertArraysEquals(a, b, r, Int128VectorTests::or);
 614     }
 615 
 616 
 617 
 618     @Test(dataProvider = "intBinaryOpMaskProvider")
 619     static void orInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 620                                           IntFunction<boolean[]> fm) {
 621         int[] a = fa.apply(SPECIES.length());
 622         int[] b = fb.apply(SPECIES.length());
 623         int[] r = fr.apply(SPECIES.length());
 624         boolean[] mask = fm.apply(SPECIES.length());
 625         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
 626 
 627         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 628             for (int i = 0; i < a.length; i += SPECIES.length()) {
 629                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 630                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 631                 av.or(bv, vmask).intoArray(r, i);
 632             }
 633         }
 634 
 635         assertArraysEquals(a, b, r, mask, Int128VectorTests::or);
 636     }
 637 
 638 
 639     static int xor(int a, int b) {
 640         return (int)(a ^ b);
 641     }
 642 
 643     @Test(dataProvider = "intBinaryOpProvider")
 644     static void xorInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 645         int[] a = fa.apply(SPECIES.length());


 649         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 650             for (int i = 0; i < a.length; i += SPECIES.length()) {
 651                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 652                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 653                 av.xor(bv).intoArray(r, i);
 654             }
 655         }
 656 
 657         assertArraysEquals(a, b, r, Int128VectorTests::xor);
 658     }
 659 
 660 
 661 
 662     @Test(dataProvider = "intBinaryOpMaskProvider")
 663     static void xorInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 664                                           IntFunction<boolean[]> fm) {
 665         int[] a = fa.apply(SPECIES.length());
 666         int[] b = fb.apply(SPECIES.length());
 667         int[] r = fr.apply(SPECIES.length());
 668         boolean[] mask = fm.apply(SPECIES.length());
 669         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
 670 
 671         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 672             for (int i = 0; i < a.length; i += SPECIES.length()) {
 673                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 674                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 675                 av.xor(bv, vmask).intoArray(r, i);
 676             }
 677         }
 678 
 679         assertArraysEquals(a, b, r, mask, Int128VectorTests::xor);
 680     }
 681 
 682 
 683     static int shiftR(int a, int b) {
 684         return (int)((a >>> b));
 685     }
 686 
 687     @Test(dataProvider = "intBinaryOpProvider")
 688     static void shiftRInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 689         int[] a = fa.apply(SPECIES.length());


 693         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 694             for (int i = 0; i < a.length; i += SPECIES.length()) {
 695                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 696                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 697                 av.shiftR(bv).intoArray(r, i);
 698             }
 699         }
 700 
 701         assertArraysEquals(a, b, r, Int128VectorTests::shiftR);
 702     }
 703 
 704 
 705 
 706     @Test(dataProvider = "intBinaryOpMaskProvider")
 707     static void shiftRInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 708                                           IntFunction<boolean[]> fm) {
 709         int[] a = fa.apply(SPECIES.length());
 710         int[] b = fb.apply(SPECIES.length());
 711         int[] r = fr.apply(SPECIES.length());
 712         boolean[] mask = fm.apply(SPECIES.length());
 713         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
 714 
 715         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 716             for (int i = 0; i < a.length; i += SPECIES.length()) {
 717                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 718                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 719                 av.shiftR(bv, vmask).intoArray(r, i);
 720             }
 721         }
 722 
 723         assertArraysEquals(a, b, r, mask, Int128VectorTests::shiftR);
 724     }
 725 
 726 
 727     static int shiftL(int a, int b) {
 728         return (int)((a << b));
 729     }
 730 
 731     @Test(dataProvider = "intBinaryOpProvider")
 732     static void shiftLInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 733         int[] a = fa.apply(SPECIES.length());


 737         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 738             for (int i = 0; i < a.length; i += SPECIES.length()) {
 739                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 740                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 741                 av.shiftL(bv).intoArray(r, i);
 742             }
 743         }
 744 
 745         assertArraysEquals(a, b, r, Int128VectorTests::shiftL);
 746     }
 747 
 748 
 749 
 750     @Test(dataProvider = "intBinaryOpMaskProvider")
 751     static void shiftLInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 752                                           IntFunction<boolean[]> fm) {
 753         int[] a = fa.apply(SPECIES.length());
 754         int[] b = fb.apply(SPECIES.length());
 755         int[] r = fr.apply(SPECIES.length());
 756         boolean[] mask = fm.apply(SPECIES.length());
 757         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
 758 
 759         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 760             for (int i = 0; i < a.length; i += SPECIES.length()) {
 761                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 762                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 763                 av.shiftL(bv, vmask).intoArray(r, i);
 764             }
 765         }
 766 
 767         assertArraysEquals(a, b, r, mask, Int128VectorTests::shiftL);
 768     }
 769 
 770 
 771     static int aShiftR(int a, int b) {
 772         return (int)((a >> b));
 773     }
 774 
 775     @Test(dataProvider = "intBinaryOpProvider")
 776     static void aShiftRInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 777         int[] a = fa.apply(SPECIES.length());


 781         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 782             for (int i = 0; i < a.length; i += SPECIES.length()) {
 783                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 784                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 785                 av.aShiftR(bv).intoArray(r, i);
 786             }
 787         }
 788 
 789         assertArraysEquals(a, b, r, Int128VectorTests::aShiftR);
 790     }
 791 
 792 
 793 
 794     @Test(dataProvider = "intBinaryOpMaskProvider")
 795     static void aShiftRInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 796                                           IntFunction<boolean[]> fm) {
 797         int[] a = fa.apply(SPECIES.length());
 798         int[] b = fb.apply(SPECIES.length());
 799         int[] r = fr.apply(SPECIES.length());
 800         boolean[] mask = fm.apply(SPECIES.length());
 801         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
 802 
 803         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 804             for (int i = 0; i < a.length; i += SPECIES.length()) {
 805                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 806                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 807                 av.aShiftR(bv, vmask).intoArray(r, i);
 808             }
 809         }
 810 
 811         assertArraysEquals(a, b, r, mask, Int128VectorTests::aShiftR);
 812     }
 813 
 814 
 815     static int aShiftR_unary(int a, int b) {
 816         return (int)((a >> b));
 817     }
 818 
 819     @Test(dataProvider = "intBinaryOpProvider")
 820     static void aShiftRInt128VectorTestsShift(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 821         int[] a = fa.apply(SPECIES.length());


 824 
 825         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 826             for (int i = 0; i < a.length; i += SPECIES.length()) {
 827                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 828                 av.aShiftR((int)b[i]).intoArray(r, i);
 829             }
 830         }
 831 
 832         assertShiftArraysEquals(a, b, r, Int128VectorTests::aShiftR_unary);
 833     }
 834 
 835 
 836 
 837     @Test(dataProvider = "intBinaryOpMaskProvider")
 838     static void aShiftRInt128VectorTestsShift(IntFunction<int[]> fa, IntFunction<int[]> fb,
 839                                           IntFunction<boolean[]> fm) {
 840         int[] a = fa.apply(SPECIES.length());
 841         int[] b = fb.apply(SPECIES.length());
 842         int[] r = fr.apply(SPECIES.length());
 843         boolean[] mask = fm.apply(SPECIES.length());
 844         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
 845 
 846         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 847             for (int i = 0; i < a.length; i += SPECIES.length()) {
 848                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 849                 av.aShiftR((int)b[i], vmask).intoArray(r, i);
 850             }
 851         }
 852 
 853         assertShiftArraysEquals(a, b, r, mask, Int128VectorTests::aShiftR_unary);
 854     }
 855 
 856 
 857     static int shiftR_unary(int a, int b) {
 858         return (int)((a >>> b));
 859     }
 860 
 861     @Test(dataProvider = "intBinaryOpProvider")
 862     static void shiftRInt128VectorTestsShift(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 863         int[] a = fa.apply(SPECIES.length());
 864         int[] b = fb.apply(SPECIES.length());


 866 
 867         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 868             for (int i = 0; i < a.length; i += SPECIES.length()) {
 869                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 870                 av.shiftR((int)b[i]).intoArray(r, i);
 871             }
 872         }
 873 
 874         assertShiftArraysEquals(a, b, r, Int128VectorTests::shiftR_unary);
 875     }
 876 
 877 
 878 
 879     @Test(dataProvider = "intBinaryOpMaskProvider")
 880     static void shiftRInt128VectorTestsShift(IntFunction<int[]> fa, IntFunction<int[]> fb,
 881                                           IntFunction<boolean[]> fm) {
 882         int[] a = fa.apply(SPECIES.length());
 883         int[] b = fb.apply(SPECIES.length());
 884         int[] r = fr.apply(SPECIES.length());
 885         boolean[] mask = fm.apply(SPECIES.length());
 886         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
 887 
 888         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 889             for (int i = 0; i < a.length; i += SPECIES.length()) {
 890                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 891                 av.shiftR((int)b[i], vmask).intoArray(r, i);
 892             }
 893         }
 894 
 895         assertShiftArraysEquals(a, b, r, mask, Int128VectorTests::shiftR_unary);
 896     }
 897 
 898 
 899     static int shiftL_unary(int a, int b) {
 900         return (int)((a << b));
 901     }
 902 
 903     @Test(dataProvider = "intBinaryOpProvider")
 904     static void shiftLInt128VectorTestsShift(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 905         int[] a = fa.apply(SPECIES.length());
 906         int[] b = fb.apply(SPECIES.length());


 908 
 909         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 910             for (int i = 0; i < a.length; i += SPECIES.length()) {
 911                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 912                 av.shiftL((int)b[i]).intoArray(r, i);
 913             }
 914         }
 915 
 916         assertShiftArraysEquals(a, b, r, Int128VectorTests::shiftL_unary);
 917     }
 918 
 919 
 920 
 921     @Test(dataProvider = "intBinaryOpMaskProvider")
 922     static void shiftLInt128VectorTestsShift(IntFunction<int[]> fa, IntFunction<int[]> fb,
 923                                           IntFunction<boolean[]> fm) {
 924         int[] a = fa.apply(SPECIES.length());
 925         int[] b = fb.apply(SPECIES.length());
 926         int[] r = fr.apply(SPECIES.length());
 927         boolean[] mask = fm.apply(SPECIES.length());
 928         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
 929 
 930         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 931             for (int i = 0; i < a.length; i += SPECIES.length()) {
 932                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 933                 av.shiftL((int)b[i], vmask).intoArray(r, i);
 934             }
 935         }
 936 
 937         assertShiftArraysEquals(a, b, r, mask, Int128VectorTests::shiftL_unary);
 938     }
 939 
 940 
 941 
 942 
 943 
 944 
 945 
 946 
 947 
 948 


1302         assertReductionArraysEquals(a, r, ra, Int128VectorTests::maxAll, Int128VectorTests::maxAll);
1303     }
1304 
1305     static boolean anyTrue(boolean[] a, int idx) {
1306         boolean res = false;
1307         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1308             res |= a[i];
1309         }
1310 
1311         return res;
1312     }
1313 
1314 
1315     @Test(dataProvider = "boolUnaryOpProvider")
1316     static void anyTrueInt128VectorTests(IntFunction<boolean[]> fm) {
1317         boolean[] mask = fm.apply(SPECIES.length());
1318         boolean[] r = fmr.apply(SPECIES.length());
1319 
1320         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1321             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1322                 Vector.Mask<Integer> vmask = IntVector.maskFromArray(SPECIES, mask, i);
1323                 r[i] = vmask.anyTrue();
1324             }
1325         }
1326 
1327         assertReductionBoolArraysEquals(mask, r, Int128VectorTests::anyTrue);
1328     }
1329 
1330 
1331     static boolean allTrue(boolean[] a, int idx) {
1332         boolean res = true;
1333         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1334             res &= a[i];
1335         }
1336 
1337         return res;
1338     }
1339 
1340 
1341     @Test(dataProvider = "boolUnaryOpProvider")
1342     static void allTrueInt128VectorTests(IntFunction<boolean[]> fm) {
1343         boolean[] mask = fm.apply(SPECIES.length());
1344         boolean[] r = fmr.apply(SPECIES.length());
1345 
1346         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1347             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1348                 Vector.Mask<Integer> vmask = IntVector.maskFromArray(SPECIES, mask, i);
1349                 r[i] = vmask.allTrue();
1350             }
1351         }
1352 
1353         assertReductionBoolArraysEquals(mask, r, Int128VectorTests::allTrue);
1354     }
1355 
1356 
1357     @Test(dataProvider = "intUnaryOpProvider")
1358     static void withInt128VectorTests(IntFunction<int []> fa) {
1359         int[] a = fa.apply(SPECIES.length());
1360         int[] r = fr.apply(SPECIES.length());
1361 
1362         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1363             for (int i = 0; i < a.length; i += SPECIES.length()) {
1364                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1365                 av.with(0, (int)4).intoArray(r, i);
1366             }
1367         }
1368 
1369         assertInsertArraysEquals(a, r, (int)4, 0);
1370     }
1371 
1372     @Test(dataProvider = "intCompareOpProvider")
1373     static void lessThanInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1374         int[] a = fa.apply(SPECIES.length());
1375         int[] b = fb.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1380                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1381                 Vector.Mask<Integer> mv = av.lessThan(bv);
1382 
1383                 // Check results as part of computation.
1384                 for (int j = 0; j < SPECIES.length(); j++) {
1385                     Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]);
1386                 }
1387             }
1388         }
1389     }
1390 
1391 
1392     @Test(dataProvider = "intCompareOpProvider")
1393     static void greaterThanInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1394         int[] a = fa.apply(SPECIES.length());
1395         int[] b = fb.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1400                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1401                 Vector.Mask<Integer> mv = av.greaterThan(bv);
1402 
1403                 // Check results as part of computation.
1404                 for (int j = 0; j < SPECIES.length(); j++) {
1405                     Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]);
1406                 }
1407             }
1408         }
1409     }
1410 
1411 
1412     @Test(dataProvider = "intCompareOpProvider")
1413     static void equalInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1414         int[] a = fa.apply(SPECIES.length());
1415         int[] b = fb.apply(SPECIES.length());
1416 
1417         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1418             for (int i = 0; i < a.length; i += SPECIES.length()) {
1419                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1420                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1421                 Vector.Mask<Integer> mv = av.equal(bv);
1422 
1423                 // Check results as part of computation.
1424                 for (int j = 0; j < SPECIES.length(); j++) {
1425                     Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]);
1426                 }
1427             }
1428         }
1429     }
1430 
1431 
1432     @Test(dataProvider = "intCompareOpProvider")
1433     static void notEqualInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1434         int[] a = fa.apply(SPECIES.length());
1435         int[] b = fb.apply(SPECIES.length());
1436 
1437         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1438             for (int i = 0; i < a.length; i += SPECIES.length()) {
1439                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1440                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1441                 Vector.Mask<Integer> mv = av.notEqual(bv);
1442 
1443                 // Check results as part of computation.
1444                 for (int j = 0; j < SPECIES.length(); j++) {
1445                     Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]);
1446                 }
1447             }
1448         }
1449     }
1450 
1451 
1452     @Test(dataProvider = "intCompareOpProvider")
1453     static void lessThanEqInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1454         int[] a = fa.apply(SPECIES.length());
1455         int[] b = fb.apply(SPECIES.length());
1456 
1457         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1458             for (int i = 0; i < a.length; i += SPECIES.length()) {
1459                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1460                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1461                 Vector.Mask<Integer> mv = av.lessThanEq(bv);
1462 
1463                 // Check results as part of computation.
1464                 for (int j = 0; j < SPECIES.length(); j++) {
1465                     Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]);
1466                 }
1467             }
1468         }
1469     }
1470 
1471 
1472     @Test(dataProvider = "intCompareOpProvider")
1473     static void greaterThanEqInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1474         int[] a = fa.apply(SPECIES.length());
1475         int[] b = fb.apply(SPECIES.length());
1476 
1477         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1478             for (int i = 0; i < a.length; i += SPECIES.length()) {
1479                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1480                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1481                 Vector.Mask<Integer> mv = av.greaterThanEq(bv);
1482 
1483                 // Check results as part of computation.
1484                 for (int j = 0; j < SPECIES.length(); j++) {
1485                     Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]);
1486                 }
1487             }
1488         }
1489     }
1490 
1491 
1492     static int blend(int a, int b, boolean mask) {
1493         return mask ? b : a;
1494     }
1495 
1496     @Test(dataProvider = "intBinaryOpMaskProvider")
1497     static void blendInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
1498                                           IntFunction<boolean[]> fm) {
1499         int[] a = fa.apply(SPECIES.length());
1500         int[] b = fb.apply(SPECIES.length());
1501         int[] r = fr.apply(SPECIES.length());
1502         boolean[] mask = fm.apply(SPECIES.length());
1503         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
1504 
1505         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1506             for (int i = 0; i < a.length; i += SPECIES.length()) {
1507                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1508                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1509                 av.blend(bv, vmask).intoArray(r, i);
1510             }
1511         }
1512 
1513         assertArraysEquals(a, b, r, mask, Int128VectorTests::blend);
1514     }
1515 
1516     @Test(dataProvider = "intUnaryOpShuffleProvider")
1517     static void RearrangeInt128VectorTests(IntFunction<int[]> fa,
1518                                            BiFunction<Integer,Integer,int[]> fs) {
1519         int[] a = fa.apply(SPECIES.length());
1520         int[] order = fs.apply(a.length, SPECIES.length());
1521         int[] r = fr.apply(SPECIES.length());
1522 
1523         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1524             for (int i = 0; i < a.length; i += SPECIES.length()) {
1525                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1526                 av.rearrange(IntVector.shuffleFromArray(SPECIES, order, i)).intoArray(r, i);
1527             }
1528         }
1529 
1530         assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1531     }
1532 
1533 
1534 
1535 
1536     @Test(dataProvider = "intUnaryOpProvider")
1537     static void getInt128VectorTests(IntFunction<int[]> fa) {
1538         int[] a = fa.apply(SPECIES.length());
1539         int[] r = fr.apply(SPECIES.length());
1540 
1541         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1542             for (int i = 0; i < a.length; i += SPECIES.length()) {
1543                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1544                 int num_lanes = SPECIES.length();
1545                 // Manually unroll because full unroll happens after intrinsification.
1546                 // Unroll is needed because get intrinsic requires for index to be a known constant.


1718     static void negInt128VectorTests(IntFunction<int[]> fa) {
1719         int[] a = fa.apply(SPECIES.length());
1720         int[] r = fr.apply(SPECIES.length());
1721 
1722         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1723             for (int i = 0; i < a.length; i += SPECIES.length()) {
1724                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1725                 av.neg().intoArray(r, i);
1726             }
1727         }
1728 
1729         assertArraysEquals(a, r, Int128VectorTests::neg);
1730     }
1731 
1732     @Test(dataProvider = "intUnaryOpMaskProvider")
1733     static void negMaskedInt128VectorTests(IntFunction<int[]> fa,
1734                                                 IntFunction<boolean[]> fm) {
1735         int[] a = fa.apply(SPECIES.length());
1736         int[] r = fr.apply(SPECIES.length());
1737         boolean[] mask = fm.apply(SPECIES.length());
1738         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
1739 
1740         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1741             for (int i = 0; i < a.length; i += SPECIES.length()) {
1742                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1743                 av.neg(vmask).intoArray(r, i);
1744             }
1745         }
1746 
1747         assertArraysEquals(a, r, mask, Int128VectorTests::neg);
1748     }
1749 
1750     static int abs(int a) {
1751         return (int)(Math.abs((int)a));
1752     }
1753 
1754     @Test(dataProvider = "intUnaryOpProvider")
1755     static void absInt128VectorTests(IntFunction<int[]> fa) {
1756         int[] a = fa.apply(SPECIES.length());
1757         int[] r = fr.apply(SPECIES.length());
1758 
1759         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1760             for (int i = 0; i < a.length; i += SPECIES.length()) {
1761                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1762                 av.abs().intoArray(r, i);
1763             }
1764         }
1765 
1766         assertArraysEquals(a, r, Int128VectorTests::abs);
1767     }
1768 
1769     @Test(dataProvider = "intUnaryOpMaskProvider")
1770     static void absMaskedInt128VectorTests(IntFunction<int[]> fa,
1771                                                 IntFunction<boolean[]> fm) {
1772         int[] a = fa.apply(SPECIES.length());
1773         int[] r = fr.apply(SPECIES.length());
1774         boolean[] mask = fm.apply(SPECIES.length());
1775         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
1776 
1777         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1778             for (int i = 0; i < a.length; i += SPECIES.length()) {
1779                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1780                 av.abs(vmask).intoArray(r, i);
1781             }
1782         }
1783 
1784         assertArraysEquals(a, r, mask, Int128VectorTests::abs);
1785     }
1786 
1787 
1788     static int not(int a) {
1789         return (int)(~((int)a));
1790     }
1791 
1792 
1793 
1794     @Test(dataProvider = "intUnaryOpProvider")
1795     static void notInt128VectorTests(IntFunction<int[]> fa) {


1797         int[] r = fr.apply(SPECIES.length());
1798 
1799         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1800             for (int i = 0; i < a.length; i += SPECIES.length()) {
1801                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1802                 av.not().intoArray(r, i);
1803             }
1804         }
1805 
1806         assertArraysEquals(a, r, Int128VectorTests::not);
1807     }
1808 
1809 
1810 
1811     @Test(dataProvider = "intUnaryOpMaskProvider")
1812     static void notMaskedInt128VectorTests(IntFunction<int[]> fa,
1813                                                 IntFunction<boolean[]> fm) {
1814         int[] a = fa.apply(SPECIES.length());
1815         int[] r = fr.apply(SPECIES.length());
1816         boolean[] mask = fm.apply(SPECIES.length());
1817         Vector.Mask<Integer> vmask = IntVector.maskFromValues(SPECIES, mask);
1818 
1819         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1820             for (int i = 0; i < a.length; i += SPECIES.length()) {
1821                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1822                 av.not(vmask).intoArray(r, i);
1823             }
1824         }
1825 
1826         assertArraysEquals(a, r, mask, Int128VectorTests::not);
1827     }
1828 
1829 
1830 
1831 
1832 
1833     static int[] gather(int a[], int ix, int[] b, int iy) {
1834         int[] res = new int[SPECIES.length()];
1835         for (int i = 0; i < SPECIES.length(); i++) {
1836             int bi = iy + i;
1837             res[i] = a[b[bi] + ix];




  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 Int128VectorTests
  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.IntVector;
  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.Arrays;
  45 import java.util.function.BiFunction;
  46 import java.util.function.IntFunction;
  47 import java.util.stream.Collectors;
  48 import java.util.stream.Stream;
  49 
  50 @Test
  51 public class Int128VectorTests extends AbstractVectorTest {
  52 
  53     static final VectorSpecies<Integer> SPECIES =
  54                 IntVector.SPECIES_128;
  55 
  56     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  57 
  58     interface FUnOp {
  59         int apply(int a);
  60     }
  61 
  62     static void assertArraysEquals(int[] a, int[] r, FUnOp f) {
  63         int i = 0;
  64         try {
  65             for (; i < a.length; i++) {
  66                 Assert.assertEquals(r[i], f.apply(a[i]));
  67             }
  68         } catch (AssertionError e) {
  69             Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
  70         }
  71     }
  72 
  73     static void assertArraysEquals(int[] a, int[] r, boolean[] mask, FUnOp f) {


 438         int[] r = fr.apply(SPECIES.length());
 439 
 440         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 441             for (int i = 0; i < a.length; i += SPECIES.length()) {
 442                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 443                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 444                 av.add(bv).intoArray(r, i);
 445             }
 446         }
 447 
 448         assertArraysEquals(a, b, r, Int128VectorTests::add);
 449     }
 450 
 451     @Test(dataProvider = "intBinaryOpMaskProvider")
 452     static void addInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 453                                           IntFunction<boolean[]> fm) {
 454         int[] a = fa.apply(SPECIES.length());
 455         int[] b = fb.apply(SPECIES.length());
 456         int[] r = fr.apply(SPECIES.length());
 457         boolean[] mask = fm.apply(SPECIES.length());
 458         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
 459 
 460         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 461             for (int i = 0; i < a.length; i += SPECIES.length()) {
 462                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 463                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 464                 av.add(bv, vmask).intoArray(r, i);
 465             }
 466         }
 467 
 468         assertArraysEquals(a, b, r, mask, Int128VectorTests::add);
 469     }
 470     static int sub(int a, int b) {
 471         return (int)(a - b);
 472     }
 473 
 474     @Test(dataProvider = "intBinaryOpProvider")
 475     static void subInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 476         int[] a = fa.apply(SPECIES.length());
 477         int[] b = fb.apply(SPECIES.length());
 478         int[] r = fr.apply(SPECIES.length());
 479 
 480         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 481             for (int i = 0; i < a.length; i += SPECIES.length()) {
 482                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 483                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 484                 av.sub(bv).intoArray(r, i);
 485             }
 486         }
 487 
 488         assertArraysEquals(a, b, r, Int128VectorTests::sub);
 489     }
 490 
 491     @Test(dataProvider = "intBinaryOpMaskProvider")
 492     static void subInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 493                                           IntFunction<boolean[]> fm) {
 494         int[] a = fa.apply(SPECIES.length());
 495         int[] b = fb.apply(SPECIES.length());
 496         int[] r = fr.apply(SPECIES.length());
 497         boolean[] mask = fm.apply(SPECIES.length());
 498         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
 499 
 500         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 501             for (int i = 0; i < a.length; i += SPECIES.length()) {
 502                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 503                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 504                 av.sub(bv, vmask).intoArray(r, i);
 505             }
 506         }
 507 
 508         assertArraysEquals(a, b, r, mask, Int128VectorTests::sub);
 509     }
 510 
 511 
 512     static int mul(int a, int b) {
 513         return (int)(a * b);
 514     }
 515 
 516     @Test(dataProvider = "intBinaryOpProvider")
 517     static void mulInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 518         int[] a = fa.apply(SPECIES.length());


 520         int[] r = fr.apply(SPECIES.length());
 521 
 522         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 523             for (int i = 0; i < a.length; i += SPECIES.length()) {
 524                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 525                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 526                 av.mul(bv).intoArray(r, i);
 527             }
 528         }
 529 
 530         assertArraysEquals(a, b, r, Int128VectorTests::mul);
 531     }
 532 
 533     @Test(dataProvider = "intBinaryOpMaskProvider")
 534     static void mulInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 535                                           IntFunction<boolean[]> fm) {
 536         int[] a = fa.apply(SPECIES.length());
 537         int[] b = fb.apply(SPECIES.length());
 538         int[] r = fr.apply(SPECIES.length());
 539         boolean[] mask = fm.apply(SPECIES.length());
 540         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
 541 
 542         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 543             for (int i = 0; i < a.length; i += SPECIES.length()) {
 544                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 545                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 546                 av.mul(bv, vmask).intoArray(r, i);
 547             }
 548         }
 549 
 550         assertArraysEquals(a, b, r, mask, Int128VectorTests::mul);
 551     }
 552 
 553     static int and(int a, int b) {
 554         return (int)(a & b);
 555     }
 556 
 557     @Test(dataProvider = "intBinaryOpProvider")
 558     static void andInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 559         int[] a = fa.apply(SPECIES.length());
 560         int[] b = fb.apply(SPECIES.length());


 563         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 564             for (int i = 0; i < a.length; i += SPECIES.length()) {
 565                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 566                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 567                 av.and(bv).intoArray(r, i);
 568             }
 569         }
 570 
 571         assertArraysEquals(a, b, r, Int128VectorTests::and);
 572     }
 573 
 574 
 575 
 576     @Test(dataProvider = "intBinaryOpMaskProvider")
 577     static void andInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 578                                           IntFunction<boolean[]> fm) {
 579         int[] a = fa.apply(SPECIES.length());
 580         int[] b = fb.apply(SPECIES.length());
 581         int[] r = fr.apply(SPECIES.length());
 582         boolean[] mask = fm.apply(SPECIES.length());
 583         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
 584 
 585         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 586             for (int i = 0; i < a.length; i += SPECIES.length()) {
 587                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 588                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 589                 av.and(bv, vmask).intoArray(r, i);
 590             }
 591         }
 592 
 593         assertArraysEquals(a, b, r, mask, Int128VectorTests::and);
 594     }
 595 
 596 
 597     static int or(int a, int b) {
 598         return (int)(a | b);
 599     }
 600 
 601     @Test(dataProvider = "intBinaryOpProvider")
 602     static void orInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 603         int[] a = fa.apply(SPECIES.length());


 607         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 608             for (int i = 0; i < a.length; i += SPECIES.length()) {
 609                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 610                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 611                 av.or(bv).intoArray(r, i);
 612             }
 613         }
 614 
 615         assertArraysEquals(a, b, r, Int128VectorTests::or);
 616     }
 617 
 618 
 619 
 620     @Test(dataProvider = "intBinaryOpMaskProvider")
 621     static void orInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 622                                           IntFunction<boolean[]> fm) {
 623         int[] a = fa.apply(SPECIES.length());
 624         int[] b = fb.apply(SPECIES.length());
 625         int[] r = fr.apply(SPECIES.length());
 626         boolean[] mask = fm.apply(SPECIES.length());
 627         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
 628 
 629         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 630             for (int i = 0; i < a.length; i += SPECIES.length()) {
 631                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 632                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 633                 av.or(bv, vmask).intoArray(r, i);
 634             }
 635         }
 636 
 637         assertArraysEquals(a, b, r, mask, Int128VectorTests::or);
 638     }
 639 
 640 
 641     static int xor(int a, int b) {
 642         return (int)(a ^ b);
 643     }
 644 
 645     @Test(dataProvider = "intBinaryOpProvider")
 646     static void xorInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 647         int[] a = fa.apply(SPECIES.length());


 651         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 652             for (int i = 0; i < a.length; i += SPECIES.length()) {
 653                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 654                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 655                 av.xor(bv).intoArray(r, i);
 656             }
 657         }
 658 
 659         assertArraysEquals(a, b, r, Int128VectorTests::xor);
 660     }
 661 
 662 
 663 
 664     @Test(dataProvider = "intBinaryOpMaskProvider")
 665     static void xorInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 666                                           IntFunction<boolean[]> fm) {
 667         int[] a = fa.apply(SPECIES.length());
 668         int[] b = fb.apply(SPECIES.length());
 669         int[] r = fr.apply(SPECIES.length());
 670         boolean[] mask = fm.apply(SPECIES.length());
 671         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
 672 
 673         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 674             for (int i = 0; i < a.length; i += SPECIES.length()) {
 675                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 676                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 677                 av.xor(bv, vmask).intoArray(r, i);
 678             }
 679         }
 680 
 681         assertArraysEquals(a, b, r, mask, Int128VectorTests::xor);
 682     }
 683 
 684 
 685     static int shiftR(int a, int b) {
 686         return (int)((a >>> b));
 687     }
 688 
 689     @Test(dataProvider = "intBinaryOpProvider")
 690     static void shiftRInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 691         int[] a = fa.apply(SPECIES.length());


 695         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 696             for (int i = 0; i < a.length; i += SPECIES.length()) {
 697                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 698                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 699                 av.shiftR(bv).intoArray(r, i);
 700             }
 701         }
 702 
 703         assertArraysEquals(a, b, r, Int128VectorTests::shiftR);
 704     }
 705 
 706 
 707 
 708     @Test(dataProvider = "intBinaryOpMaskProvider")
 709     static void shiftRInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 710                                           IntFunction<boolean[]> fm) {
 711         int[] a = fa.apply(SPECIES.length());
 712         int[] b = fb.apply(SPECIES.length());
 713         int[] r = fr.apply(SPECIES.length());
 714         boolean[] mask = fm.apply(SPECIES.length());
 715         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
 716 
 717         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 718             for (int i = 0; i < a.length; i += SPECIES.length()) {
 719                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 720                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 721                 av.shiftR(bv, vmask).intoArray(r, i);
 722             }
 723         }
 724 
 725         assertArraysEquals(a, b, r, mask, Int128VectorTests::shiftR);
 726     }
 727 
 728 
 729     static int shiftL(int a, int b) {
 730         return (int)((a << b));
 731     }
 732 
 733     @Test(dataProvider = "intBinaryOpProvider")
 734     static void shiftLInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 735         int[] a = fa.apply(SPECIES.length());


 739         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 740             for (int i = 0; i < a.length; i += SPECIES.length()) {
 741                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 742                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 743                 av.shiftL(bv).intoArray(r, i);
 744             }
 745         }
 746 
 747         assertArraysEquals(a, b, r, Int128VectorTests::shiftL);
 748     }
 749 
 750 
 751 
 752     @Test(dataProvider = "intBinaryOpMaskProvider")
 753     static void shiftLInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 754                                           IntFunction<boolean[]> fm) {
 755         int[] a = fa.apply(SPECIES.length());
 756         int[] b = fb.apply(SPECIES.length());
 757         int[] r = fr.apply(SPECIES.length());
 758         boolean[] mask = fm.apply(SPECIES.length());
 759         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
 760 
 761         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 762             for (int i = 0; i < a.length; i += SPECIES.length()) {
 763                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 764                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 765                 av.shiftL(bv, vmask).intoArray(r, i);
 766             }
 767         }
 768 
 769         assertArraysEquals(a, b, r, mask, Int128VectorTests::shiftL);
 770     }
 771 
 772 
 773     static int aShiftR(int a, int b) {
 774         return (int)((a >> b));
 775     }
 776 
 777     @Test(dataProvider = "intBinaryOpProvider")
 778     static void aShiftRInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 779         int[] a = fa.apply(SPECIES.length());


 783         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 784             for (int i = 0; i < a.length; i += SPECIES.length()) {
 785                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 786                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 787                 av.aShiftR(bv).intoArray(r, i);
 788             }
 789         }
 790 
 791         assertArraysEquals(a, b, r, Int128VectorTests::aShiftR);
 792     }
 793 
 794 
 795 
 796     @Test(dataProvider = "intBinaryOpMaskProvider")
 797     static void aShiftRInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
 798                                           IntFunction<boolean[]> fm) {
 799         int[] a = fa.apply(SPECIES.length());
 800         int[] b = fb.apply(SPECIES.length());
 801         int[] r = fr.apply(SPECIES.length());
 802         boolean[] mask = fm.apply(SPECIES.length());
 803         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
 804 
 805         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 806             for (int i = 0; i < a.length; i += SPECIES.length()) {
 807                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 808                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
 809                 av.aShiftR(bv, vmask).intoArray(r, i);
 810             }
 811         }
 812 
 813         assertArraysEquals(a, b, r, mask, Int128VectorTests::aShiftR);
 814     }
 815 
 816 
 817     static int aShiftR_unary(int a, int b) {
 818         return (int)((a >> b));
 819     }
 820 
 821     @Test(dataProvider = "intBinaryOpProvider")
 822     static void aShiftRInt128VectorTestsShift(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 823         int[] a = fa.apply(SPECIES.length());


 826 
 827         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 828             for (int i = 0; i < a.length; i += SPECIES.length()) {
 829                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 830                 av.aShiftR((int)b[i]).intoArray(r, i);
 831             }
 832         }
 833 
 834         assertShiftArraysEquals(a, b, r, Int128VectorTests::aShiftR_unary);
 835     }
 836 
 837 
 838 
 839     @Test(dataProvider = "intBinaryOpMaskProvider")
 840     static void aShiftRInt128VectorTestsShift(IntFunction<int[]> fa, IntFunction<int[]> fb,
 841                                           IntFunction<boolean[]> fm) {
 842         int[] a = fa.apply(SPECIES.length());
 843         int[] b = fb.apply(SPECIES.length());
 844         int[] r = fr.apply(SPECIES.length());
 845         boolean[] mask = fm.apply(SPECIES.length());
 846         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
 847 
 848         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 849             for (int i = 0; i < a.length; i += SPECIES.length()) {
 850                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 851                 av.aShiftR((int)b[i], vmask).intoArray(r, i);
 852             }
 853         }
 854 
 855         assertShiftArraysEquals(a, b, r, mask, Int128VectorTests::aShiftR_unary);
 856     }
 857 
 858 
 859     static int shiftR_unary(int a, int b) {
 860         return (int)((a >>> b));
 861     }
 862 
 863     @Test(dataProvider = "intBinaryOpProvider")
 864     static void shiftRInt128VectorTestsShift(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 865         int[] a = fa.apply(SPECIES.length());
 866         int[] b = fb.apply(SPECIES.length());


 868 
 869         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 870             for (int i = 0; i < a.length; i += SPECIES.length()) {
 871                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 872                 av.shiftR((int)b[i]).intoArray(r, i);
 873             }
 874         }
 875 
 876         assertShiftArraysEquals(a, b, r, Int128VectorTests::shiftR_unary);
 877     }
 878 
 879 
 880 
 881     @Test(dataProvider = "intBinaryOpMaskProvider")
 882     static void shiftRInt128VectorTestsShift(IntFunction<int[]> fa, IntFunction<int[]> fb,
 883                                           IntFunction<boolean[]> fm) {
 884         int[] a = fa.apply(SPECIES.length());
 885         int[] b = fb.apply(SPECIES.length());
 886         int[] r = fr.apply(SPECIES.length());
 887         boolean[] mask = fm.apply(SPECIES.length());
 888         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
 889 
 890         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 891             for (int i = 0; i < a.length; i += SPECIES.length()) {
 892                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 893                 av.shiftR((int)b[i], vmask).intoArray(r, i);
 894             }
 895         }
 896 
 897         assertShiftArraysEquals(a, b, r, mask, Int128VectorTests::shiftR_unary);
 898     }
 899 
 900 
 901     static int shiftL_unary(int a, int b) {
 902         return (int)((a << b));
 903     }
 904 
 905     @Test(dataProvider = "intBinaryOpProvider")
 906     static void shiftLInt128VectorTestsShift(IntFunction<int[]> fa, IntFunction<int[]> fb) {
 907         int[] a = fa.apply(SPECIES.length());
 908         int[] b = fb.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 914                 av.shiftL((int)b[i]).intoArray(r, i);
 915             }
 916         }
 917 
 918         assertShiftArraysEquals(a, b, r, Int128VectorTests::shiftL_unary);
 919     }
 920 
 921 
 922 
 923     @Test(dataProvider = "intBinaryOpMaskProvider")
 924     static void shiftLInt128VectorTestsShift(IntFunction<int[]> fa, IntFunction<int[]> fb,
 925                                           IntFunction<boolean[]> fm) {
 926         int[] a = fa.apply(SPECIES.length());
 927         int[] b = fb.apply(SPECIES.length());
 928         int[] r = fr.apply(SPECIES.length());
 929         boolean[] mask = fm.apply(SPECIES.length());
 930         VectorMask<Integer> 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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
 935                 av.shiftL((int)b[i], vmask).intoArray(r, i);
 936             }
 937         }
 938 
 939         assertShiftArraysEquals(a, b, r, mask, Int128VectorTests::shiftL_unary);
 940     }
 941 
 942 
 943 
 944 
 945 
 946 
 947 
 948 
 949 
 950 


1304         assertReductionArraysEquals(a, r, ra, Int128VectorTests::maxAll, Int128VectorTests::maxAll);
1305     }
1306 
1307     static boolean anyTrue(boolean[] a, int idx) {
1308         boolean res = false;
1309         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1310             res |= a[i];
1311         }
1312 
1313         return res;
1314     }
1315 
1316 
1317     @Test(dataProvider = "boolUnaryOpProvider")
1318     static void anyTrueInt128VectorTests(IntFunction<boolean[]> fm) {
1319         boolean[] mask = fm.apply(SPECIES.length());
1320         boolean[] r = fmr.apply(SPECIES.length());
1321 
1322         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1323             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1324                 VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, i);
1325                 r[i] = vmask.anyTrue();
1326             }
1327         }
1328 
1329         assertReductionBoolArraysEquals(mask, r, Int128VectorTests::anyTrue);
1330     }
1331 
1332 
1333     static boolean allTrue(boolean[] a, int idx) {
1334         boolean res = true;
1335         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1336             res &= a[i];
1337         }
1338 
1339         return res;
1340     }
1341 
1342 
1343     @Test(dataProvider = "boolUnaryOpProvider")
1344     static void allTrueInt128VectorTests(IntFunction<boolean[]> fm) {
1345         boolean[] mask = fm.apply(SPECIES.length());
1346         boolean[] r = fmr.apply(SPECIES.length());
1347 
1348         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1349             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1350                 VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, i);
1351                 r[i] = vmask.allTrue();
1352             }
1353         }
1354 
1355         assertReductionBoolArraysEquals(mask, r, Int128VectorTests::allTrue);
1356     }
1357 
1358 
1359     @Test(dataProvider = "intUnaryOpProvider")
1360     static void withInt128VectorTests(IntFunction<int []> fa) {
1361         int[] a = fa.apply(SPECIES.length());
1362         int[] r = fr.apply(SPECIES.length());
1363 
1364         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1365             for (int i = 0; i < a.length; i += SPECIES.length()) {
1366                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1367                 av.with(0, (int)4).intoArray(r, i);
1368             }
1369         }
1370 
1371         assertInsertArraysEquals(a, r, (int)4, 0);
1372     }
1373 
1374     @Test(dataProvider = "intCompareOpProvider")
1375     static void lessThanInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1376         int[] a = fa.apply(SPECIES.length());
1377         int[] b = fb.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                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1382                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1383                 VectorMask<Integer> mv = av.lessThan(bv);
1384 
1385                 // Check results as part of computation.
1386                 for (int j = 0; j < SPECIES.length(); j++) {
1387                     Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]);
1388                 }
1389             }
1390         }
1391     }
1392 
1393 
1394     @Test(dataProvider = "intCompareOpProvider")
1395     static void greaterThanInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1396         int[] a = fa.apply(SPECIES.length());
1397         int[] b = fb.apply(SPECIES.length());
1398 
1399         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1400             for (int i = 0; i < a.length; i += SPECIES.length()) {
1401                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1402                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1403                 VectorMask<Integer> mv = av.greaterThan(bv);
1404 
1405                 // Check results as part of computation.
1406                 for (int j = 0; j < SPECIES.length(); j++) {
1407                     Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]);
1408                 }
1409             }
1410         }
1411     }
1412 
1413 
1414     @Test(dataProvider = "intCompareOpProvider")
1415     static void equalInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1416         int[] a = fa.apply(SPECIES.length());
1417         int[] b = fb.apply(SPECIES.length());
1418 
1419         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1420             for (int i = 0; i < a.length; i += SPECIES.length()) {
1421                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1422                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1423                 VectorMask<Integer> mv = av.equal(bv);
1424 
1425                 // Check results as part of computation.
1426                 for (int j = 0; j < SPECIES.length(); j++) {
1427                     Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]);
1428                 }
1429             }
1430         }
1431     }
1432 
1433 
1434     @Test(dataProvider = "intCompareOpProvider")
1435     static void notEqualInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1436         int[] a = fa.apply(SPECIES.length());
1437         int[] b = fb.apply(SPECIES.length());
1438 
1439         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1440             for (int i = 0; i < a.length; i += SPECIES.length()) {
1441                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1442                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1443                 VectorMask<Integer> mv = av.notEqual(bv);
1444 
1445                 // Check results as part of computation.
1446                 for (int j = 0; j < SPECIES.length(); j++) {
1447                     Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]);
1448                 }
1449             }
1450         }
1451     }
1452 
1453 
1454     @Test(dataProvider = "intCompareOpProvider")
1455     static void lessThanEqInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1456         int[] a = fa.apply(SPECIES.length());
1457         int[] b = fb.apply(SPECIES.length());
1458 
1459         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1460             for (int i = 0; i < a.length; i += SPECIES.length()) {
1461                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1462                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1463                 VectorMask<Integer> mv = av.lessThanEq(bv);
1464 
1465                 // Check results as part of computation.
1466                 for (int j = 0; j < SPECIES.length(); j++) {
1467                     Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]);
1468                 }
1469             }
1470         }
1471     }
1472 
1473 
1474     @Test(dataProvider = "intCompareOpProvider")
1475     static void greaterThanEqInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1476         int[] a = fa.apply(SPECIES.length());
1477         int[] b = fb.apply(SPECIES.length());
1478 
1479         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1480             for (int i = 0; i < a.length; i += SPECIES.length()) {
1481                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1482                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1483                 VectorMask<Integer> mv = av.greaterThanEq(bv);
1484 
1485                 // Check results as part of computation.
1486                 for (int j = 0; j < SPECIES.length(); j++) {
1487                     Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]);
1488                 }
1489             }
1490         }
1491     }
1492 
1493 
1494     static int blend(int a, int b, boolean mask) {
1495         return mask ? b : a;
1496     }
1497 
1498     @Test(dataProvider = "intBinaryOpMaskProvider")
1499     static void blendInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
1500                                           IntFunction<boolean[]> fm) {
1501         int[] a = fa.apply(SPECIES.length());
1502         int[] b = fb.apply(SPECIES.length());
1503         int[] r = fr.apply(SPECIES.length());
1504         boolean[] mask = fm.apply(SPECIES.length());
1505         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
1506 
1507         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1508             for (int i = 0; i < a.length; i += SPECIES.length()) {
1509                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1510                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1511                 av.blend(bv, vmask).intoArray(r, i);
1512             }
1513         }
1514 
1515         assertArraysEquals(a, b, r, mask, Int128VectorTests::blend);
1516     }
1517 
1518     @Test(dataProvider = "intUnaryOpShuffleProvider")
1519     static void RearrangeInt128VectorTests(IntFunction<int[]> fa,
1520                                            BiFunction<Integer,Integer,int[]> fs) {
1521         int[] a = fa.apply(SPECIES.length());
1522         int[] order = fs.apply(a.length, SPECIES.length());
1523         int[] r = fr.apply(SPECIES.length());
1524 
1525         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1526             for (int i = 0; i < a.length; i += SPECIES.length()) {
1527                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1528                 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
1529             }
1530         }
1531 
1532         assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1533     }
1534 
1535 
1536 
1537 
1538     @Test(dataProvider = "intUnaryOpProvider")
1539     static void getInt128VectorTests(IntFunction<int[]> fa) {
1540         int[] a = fa.apply(SPECIES.length());
1541         int[] r = fr.apply(SPECIES.length());
1542 
1543         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1544             for (int i = 0; i < a.length; i += SPECIES.length()) {
1545                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1546                 int num_lanes = SPECIES.length();
1547                 // Manually unroll because full unroll happens after intrinsification.
1548                 // Unroll is needed because get intrinsic requires for index to be a known constant.


1720     static void negInt128VectorTests(IntFunction<int[]> fa) {
1721         int[] a = fa.apply(SPECIES.length());
1722         int[] r = fr.apply(SPECIES.length());
1723 
1724         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1725             for (int i = 0; i < a.length; i += SPECIES.length()) {
1726                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1727                 av.neg().intoArray(r, i);
1728             }
1729         }
1730 
1731         assertArraysEquals(a, r, Int128VectorTests::neg);
1732     }
1733 
1734     @Test(dataProvider = "intUnaryOpMaskProvider")
1735     static void negMaskedInt128VectorTests(IntFunction<int[]> fa,
1736                                                 IntFunction<boolean[]> fm) {
1737         int[] a = fa.apply(SPECIES.length());
1738         int[] r = fr.apply(SPECIES.length());
1739         boolean[] mask = fm.apply(SPECIES.length());
1740         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
1741 
1742         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1743             for (int i = 0; i < a.length; i += SPECIES.length()) {
1744                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1745                 av.neg(vmask).intoArray(r, i);
1746             }
1747         }
1748 
1749         assertArraysEquals(a, r, mask, Int128VectorTests::neg);
1750     }
1751 
1752     static int abs(int a) {
1753         return (int)(Math.abs((int)a));
1754     }
1755 
1756     @Test(dataProvider = "intUnaryOpProvider")
1757     static void absInt128VectorTests(IntFunction<int[]> fa) {
1758         int[] a = fa.apply(SPECIES.length());
1759         int[] r = fr.apply(SPECIES.length());
1760 
1761         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1762             for (int i = 0; i < a.length; i += SPECIES.length()) {
1763                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1764                 av.abs().intoArray(r, i);
1765             }
1766         }
1767 
1768         assertArraysEquals(a, r, Int128VectorTests::abs);
1769     }
1770 
1771     @Test(dataProvider = "intUnaryOpMaskProvider")
1772     static void absMaskedInt128VectorTests(IntFunction<int[]> fa,
1773                                                 IntFunction<boolean[]> fm) {
1774         int[] a = fa.apply(SPECIES.length());
1775         int[] r = fr.apply(SPECIES.length());
1776         boolean[] mask = fm.apply(SPECIES.length());
1777         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
1778 
1779         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1780             for (int i = 0; i < a.length; i += SPECIES.length()) {
1781                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1782                 av.abs(vmask).intoArray(r, i);
1783             }
1784         }
1785 
1786         assertArraysEquals(a, r, mask, Int128VectorTests::abs);
1787     }
1788 
1789 
1790     static int not(int a) {
1791         return (int)(~((int)a));
1792     }
1793 
1794 
1795 
1796     @Test(dataProvider = "intUnaryOpProvider")
1797     static void notInt128VectorTests(IntFunction<int[]> fa) {


1799         int[] r = fr.apply(SPECIES.length());
1800 
1801         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1802             for (int i = 0; i < a.length; i += SPECIES.length()) {
1803                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1804                 av.not().intoArray(r, i);
1805             }
1806         }
1807 
1808         assertArraysEquals(a, r, Int128VectorTests::not);
1809     }
1810 
1811 
1812 
1813     @Test(dataProvider = "intUnaryOpMaskProvider")
1814     static void notMaskedInt128VectorTests(IntFunction<int[]> fa,
1815                                                 IntFunction<boolean[]> fm) {
1816         int[] a = fa.apply(SPECIES.length());
1817         int[] r = fr.apply(SPECIES.length());
1818         boolean[] mask = fm.apply(SPECIES.length());
1819         VectorMask<Integer> vmask = VectorMask.fromValues(SPECIES, mask);
1820 
1821         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1822             for (int i = 0; i < a.length; i += SPECIES.length()) {
1823                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1824                 av.not(vmask).intoArray(r, i);
1825             }
1826         }
1827 
1828         assertArraysEquals(a, r, mask, Int128VectorTests::not);
1829     }
1830 
1831 
1832 
1833 
1834 
1835     static int[] gather(int a[], int ix, int[] b, int iy) {
1836         int[] res = new int[SPECIES.length()];
1837         for (int i = 0; i < SPECIES.length(); i++) {
1838             int bi = iy + i;
1839             res[i] = a[b[bi] + ix];


< prev index next >