< prev index next >

test/jdk/jdk/incubator/vector/Float256VectorTests.java

Print this page
rev 55894 : 8222897: [vector] Renaming of shift, rotate operations. Few other api changes.
Summary: Renaming of shift, rotate operations. Few other api changes.
Reviewed-by: jrose, briangoetz


 713 
 714 
 715 
 716 
 717 
 718 
 719 
 720 
 721 
 722 
 723 
 724 
 725 
 726 
 727 
 728 
 729 
 730 
 731 
 732 












 733     static float max(float a, float b) {
 734         return (float)(Math.max(a, b));
 735     }
 736 
 737     @Test(dataProvider = "floatBinaryOpProvider")
 738     static void maxFloat256VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
 739         float[] a = fa.apply(SPECIES.length());
 740         float[] b = fb.apply(SPECIES.length());
 741         float[] r = fr.apply(SPECIES.length());
 742 
 743         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 744             for (int i = 0; i < a.length; i += SPECIES.length()) {
 745                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 746                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 747                 av.max(bv).intoArray(r, i);
 748             }
 749         }
 750 
 751         assertArraysEquals(a, b, r, Float256VectorTests::max);
 752     }


 759         float[] a = fa.apply(SPECIES.length());
 760         float[] b = fb.apply(SPECIES.length());
 761         float[] r = fr.apply(SPECIES.length());
 762 
 763         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 764             for (int i = 0; i < a.length; i += SPECIES.length()) {
 765                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 766                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 767                 av.min(bv).intoArray(r, i);
 768             }
 769         }
 770 
 771         assertArraysEquals(a, b, r, Float256VectorTests::min);
 772     }
 773 
 774 
 775 
 776 
 777 
 778 
 779     static float addAll(float[] a, int idx) {
 780         float res = 0;
 781         for (int i = idx; i < (idx + SPECIES.length()); i++) {
 782             res += a[i];
 783         }
 784 
 785         return res;
 786     }
 787 
 788     static float addAll(float[] a) {
 789         float res = 0;
 790         for (int i = 0; i < a.length; i += SPECIES.length()) {
 791             float tmp = 0;
 792             for (int j = 0; j < SPECIES.length(); j++) {
 793                 tmp += a[i + j];
 794             }
 795             res += tmp;
 796         }
 797 
 798         return res;
 799     }
 800     @Test(dataProvider = "floatUnaryOpProvider")
 801     static void addAllFloat256VectorTests(IntFunction<float[]> fa) {
 802         float[] a = fa.apply(SPECIES.length());
 803         float[] r = fr.apply(SPECIES.length());
 804         float ra = 0;
 805 
 806         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 807             for (int i = 0; i < a.length; i += SPECIES.length()) {
 808                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 809                 r[i] = av.addAll();
 810             }
 811         }
 812 
 813         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 814             ra = 0;
 815             for (int i = 0; i < a.length; i += SPECIES.length()) {
 816                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 817                 ra += av.addAll();
 818             }
 819         }
 820 
 821         assertReductionArraysEquals(a, r, ra, Float256VectorTests::addAll, Float256VectorTests::addAll);
 822     }
 823     static float mulAll(float[] a, int idx) {
 824         float res = 1;
 825         for (int i = idx; i < (idx + SPECIES.length()); i++) {
 826             res *= a[i];
 827         }
 828 
 829         return res;
 830     }
 831 
 832     static float mulAll(float[] a) {
 833         float res = 1;
 834         for (int i = 0; i < a.length; i += SPECIES.length()) {
 835             float tmp = 1;
 836             for (int j = 0; j < SPECIES.length(); j++) {
 837                 tmp *= a[i + j];
 838             }
 839             res *= tmp;
 840         }
 841 
 842         return res;
 843     }
 844     @Test(dataProvider = "floatUnaryOpProvider")
 845     static void mulAllFloat256VectorTests(IntFunction<float[]> fa) {
 846         float[] a = fa.apply(SPECIES.length());
 847         float[] r = fr.apply(SPECIES.length());
 848         float ra = 1;
 849 
 850         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 851             for (int i = 0; i < a.length; i += SPECIES.length()) {
 852                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 853                 r[i] = av.mulAll();
 854             }
 855         }
 856 
 857         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 858             ra = 1;
 859             for (int i = 0; i < a.length; i += SPECIES.length()) {
 860                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 861                 ra *= av.mulAll();
 862             }
 863         }
 864 
 865         assertReductionArraysEquals(a, r, ra, Float256VectorTests::mulAll, Float256VectorTests::mulAll);
 866     }
 867     static float minAll(float[] a, int idx) {
 868         float res = Float.POSITIVE_INFINITY;
 869         for (int i = idx; i < (idx + SPECIES.length()); i++) {
 870             res = (float)Math.min(res, a[i]);
 871         }
 872 
 873         return res;
 874     }
 875 
 876     static float minAll(float[] a) {
 877         float res = Float.POSITIVE_INFINITY;
 878         for (int i = 0; i < a.length; i++) {
 879             res = (float)Math.min(res, a[i]);
 880         }
 881 
 882         return res;
 883     }
 884     @Test(dataProvider = "floatUnaryOpProvider")
 885     static void minAllFloat256VectorTests(IntFunction<float[]> fa) {
 886         float[] a = fa.apply(SPECIES.length());
 887         float[] r = fr.apply(SPECIES.length());
 888         float ra = Float.POSITIVE_INFINITY;
 889 
 890         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 891             for (int i = 0; i < a.length; i += SPECIES.length()) {
 892                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 893                 r[i] = av.minAll();
 894             }
 895         }
 896 
 897         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 898             ra = Float.POSITIVE_INFINITY;
 899             for (int i = 0; i < a.length; i += SPECIES.length()) {
 900                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 901                 ra = (float)Math.min(ra, av.minAll());
 902             }
 903         }
 904 
 905         assertReductionArraysEquals(a, r, ra, Float256VectorTests::minAll, Float256VectorTests::minAll);
 906     }
 907     static float maxAll(float[] a, int idx) {
 908         float res = Float.NEGATIVE_INFINITY;
 909         for (int i = idx; i < (idx + SPECIES.length()); i++) {
 910             res = (float)Math.max(res, a[i]);
 911         }
 912 
 913         return res;
 914     }
 915 
 916     static float maxAll(float[] a) {
 917         float res = Float.NEGATIVE_INFINITY;
 918         for (int i = 0; i < a.length; i++) {
 919             res = (float)Math.max(res, a[i]);
 920         }
 921 
 922         return res;
 923     }
 924     @Test(dataProvider = "floatUnaryOpProvider")
 925     static void maxAllFloat256VectorTests(IntFunction<float[]> fa) {
 926         float[] a = fa.apply(SPECIES.length());
 927         float[] r = fr.apply(SPECIES.length());
 928         float ra = Float.NEGATIVE_INFINITY;
 929 
 930         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 931             for (int i = 0; i < a.length; i += SPECIES.length()) {
 932                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 933                 r[i] = av.maxAll();
 934             }
 935         }
 936 
 937         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 938             ra = Float.NEGATIVE_INFINITY;
 939             for (int i = 0; i < a.length; i += SPECIES.length()) {
 940                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 941                 ra = (float)Math.max(ra, av.maxAll());
 942             }
 943         }
 944 
 945         assertReductionArraysEquals(a, r, ra, Float256VectorTests::maxAll, Float256VectorTests::maxAll);
 946     }
 947 
 948 
 949 
 950 
 951 
 952     @Test(dataProvider = "floatUnaryOpProvider")
 953     static void withFloat256VectorTests(IntFunction<float []> fa) {
 954         float[] a = fa.apply(SPECIES.length());
 955         float[] r = fr.apply(SPECIES.length());
 956 
 957         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 958             for (int i = 0; i < a.length; i += SPECIES.length()) {
 959                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 960                 av.with(0, (float)4).intoArray(r, i);
 961             }
 962         }
 963 
 964         assertInsertArraysEquals(a, r, (float)4, 0);
 965     }




 713 
 714 
 715 
 716 
 717 
 718 
 719 
 720 
 721 
 722 
 723 
 724 
 725 
 726 
 727 
 728 
 729 
 730 
 731 
 732 
 733 
 734 
 735 
 736 
 737 
 738 
 739 
 740 
 741 
 742 
 743 
 744 
 745     static float max(float a, float b) {
 746         return (float)(Math.max(a, b));
 747     }
 748 
 749     @Test(dataProvider = "floatBinaryOpProvider")
 750     static void maxFloat256VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
 751         float[] a = fa.apply(SPECIES.length());
 752         float[] b = fb.apply(SPECIES.length());
 753         float[] r = fr.apply(SPECIES.length());
 754 
 755         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 756             for (int i = 0; i < a.length; i += SPECIES.length()) {
 757                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 758                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 759                 av.max(bv).intoArray(r, i);
 760             }
 761         }
 762 
 763         assertArraysEquals(a, b, r, Float256VectorTests::max);
 764     }


 771         float[] a = fa.apply(SPECIES.length());
 772         float[] b = fb.apply(SPECIES.length());
 773         float[] r = fr.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                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 778                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 779                 av.min(bv).intoArray(r, i);
 780             }
 781         }
 782 
 783         assertArraysEquals(a, b, r, Float256VectorTests::min);
 784     }
 785 
 786 
 787 
 788 
 789 
 790 
 791     static float addLanes(float[] a, int idx) {
 792         float res = 0;
 793         for (int i = idx; i < (idx + SPECIES.length()); i++) {
 794             res += a[i];
 795         }
 796 
 797         return res;
 798     }
 799 
 800     static float addLanes(float[] a) {
 801         float res = 0;
 802         for (int i = 0; i < a.length; i += SPECIES.length()) {
 803             float tmp = 0;
 804             for (int j = 0; j < SPECIES.length(); j++) {
 805                 tmp += a[i + j];
 806             }
 807             res += tmp;
 808         }
 809 
 810         return res;
 811     }
 812     @Test(dataProvider = "floatUnaryOpProvider")
 813     static void addLanesFloat256VectorTests(IntFunction<float[]> fa) {
 814         float[] a = fa.apply(SPECIES.length());
 815         float[] r = fr.apply(SPECIES.length());
 816         float ra = 0;
 817 
 818         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 819             for (int i = 0; i < a.length; i += SPECIES.length()) {
 820                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 821                 r[i] = av.addLanes();
 822             }
 823         }
 824 
 825         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 826             ra = 0;
 827             for (int i = 0; i < a.length; i += SPECIES.length()) {
 828                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 829                 ra += av.addLanes();
 830             }
 831         }
 832 
 833         assertReductionArraysEquals(a, r, ra, Float256VectorTests::addLanes, Float256VectorTests::addLanes);
 834     }
 835     static float mulLanes(float[] a, int idx) {
 836         float res = 1;
 837         for (int i = idx; i < (idx + SPECIES.length()); i++) {
 838             res *= a[i];
 839         }
 840 
 841         return res;
 842     }
 843 
 844     static float mulLanes(float[] a) {
 845         float res = 1;
 846         for (int i = 0; i < a.length; i += SPECIES.length()) {
 847             float tmp = 1;
 848             for (int j = 0; j < SPECIES.length(); j++) {
 849                 tmp *= a[i + j];
 850             }
 851             res *= tmp;
 852         }
 853 
 854         return res;
 855     }
 856     @Test(dataProvider = "floatUnaryOpProvider")
 857     static void mulLanesFloat256VectorTests(IntFunction<float[]> fa) {
 858         float[] a = fa.apply(SPECIES.length());
 859         float[] r = fr.apply(SPECIES.length());
 860         float ra = 1;
 861 
 862         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 863             for (int i = 0; i < a.length; i += SPECIES.length()) {
 864                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 865                 r[i] = av.mulLanes();
 866             }
 867         }
 868 
 869         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 870             ra = 1;
 871             for (int i = 0; i < a.length; i += SPECIES.length()) {
 872                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 873                 ra *= av.mulLanes();
 874             }
 875         }
 876 
 877         assertReductionArraysEquals(a, r, ra, Float256VectorTests::mulLanes, Float256VectorTests::mulLanes);
 878     }
 879     static float minLanes(float[] a, int idx) {
 880         float res = Float.POSITIVE_INFINITY;
 881         for (int i = idx; i < (idx + SPECIES.length()); i++) {
 882             res = (float)Math.min(res, a[i]);
 883         }
 884 
 885         return res;
 886     }
 887 
 888     static float minLanes(float[] a) {
 889         float res = Float.POSITIVE_INFINITY;
 890         for (int i = 0; i < a.length; i++) {
 891             res = (float)Math.min(res, a[i]);
 892         }
 893 
 894         return res;
 895     }
 896     @Test(dataProvider = "floatUnaryOpProvider")
 897     static void minLanesFloat256VectorTests(IntFunction<float[]> fa) {
 898         float[] a = fa.apply(SPECIES.length());
 899         float[] r = fr.apply(SPECIES.length());
 900         float ra = Float.POSITIVE_INFINITY;
 901 
 902         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 903             for (int i = 0; i < a.length; i += SPECIES.length()) {
 904                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 905                 r[i] = av.minLanes();
 906             }
 907         }
 908 
 909         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 910             ra = Float.POSITIVE_INFINITY;
 911             for (int i = 0; i < a.length; i += SPECIES.length()) {
 912                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 913                 ra = (float)Math.min(ra, av.minLanes());
 914             }
 915         }
 916 
 917         assertReductionArraysEquals(a, r, ra, Float256VectorTests::minLanes, Float256VectorTests::minLanes);
 918     }
 919     static float maxLanes(float[] a, int idx) {
 920         float res = Float.NEGATIVE_INFINITY;
 921         for (int i = idx; i < (idx + SPECIES.length()); i++) {
 922             res = (float)Math.max(res, a[i]);
 923         }
 924 
 925         return res;
 926     }
 927 
 928     static float maxLanes(float[] a) {
 929         float res = Float.NEGATIVE_INFINITY;
 930         for (int i = 0; i < a.length; i++) {
 931             res = (float)Math.max(res, a[i]);
 932         }
 933 
 934         return res;
 935     }
 936     @Test(dataProvider = "floatUnaryOpProvider")
 937     static void maxLanesFloat256VectorTests(IntFunction<float[]> fa) {
 938         float[] a = fa.apply(SPECIES.length());
 939         float[] r = fr.apply(SPECIES.length());
 940         float ra = Float.NEGATIVE_INFINITY;
 941 
 942         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 943             for (int i = 0; i < a.length; i += SPECIES.length()) {
 944                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 945                 r[i] = av.maxLanes();
 946             }
 947         }
 948 
 949         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 950             ra = Float.NEGATIVE_INFINITY;
 951             for (int i = 0; i < a.length; i += SPECIES.length()) {
 952                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 953                 ra = (float)Math.max(ra, av.maxLanes());
 954             }
 955         }
 956 
 957         assertReductionArraysEquals(a, r, ra, Float256VectorTests::maxLanes, Float256VectorTests::maxLanes);
 958     }
 959 
 960 
 961 
 962 
 963 
 964     @Test(dataProvider = "floatUnaryOpProvider")
 965     static void withFloat256VectorTests(IntFunction<float []> fa) {
 966         float[] a = fa.apply(SPECIES.length());
 967         float[] r = fr.apply(SPECIES.length());
 968 
 969         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 970             for (int i = 0; i < a.length; i += SPECIES.length()) {
 971                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 972                 av.with(0, (float)4).intoArray(r, i);
 973             }
 974         }
 975 
 976         assertInsertArraysEquals(a, r, (float)4, 0);
 977     }


< prev index next >