649 short[] r = fr.apply(SPECIES.length());
650 boolean[] mask = fm.apply(SPECIES.length());
651 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
652
653 for (int ic = 0; ic < INVOC_COUNT; ic++) {
654 for (int i = 0; i < a.length; i += SPECIES.length()) {
655 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
656 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
657 av.xor(bv, vmask).intoArray(r, i);
658 }
659 }
660
661 assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::xor);
662 }
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683 static short aShiftR_unary(short a, short b) {
684 return (short)((a >> (b & 15)));
685 }
686
687 @Test(dataProvider = "shortBinaryOpProvider")
688 static void aShiftRShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
689 short[] a = fa.apply(SPECIES.length());
690 short[] b = fb.apply(SPECIES.length());
691 short[] r = fr.apply(SPECIES.length());
692
693 for (int ic = 0; ic < INVOC_COUNT; ic++) {
694 for (int i = 0; i < a.length; i += SPECIES.length()) {
695 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
696 av.aShiftR((int)b[i]).intoArray(r, i);
697 }
698 }
699
700 assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::aShiftR_unary);
701 }
702
703
704
705 @Test(dataProvider = "shortBinaryOpMaskProvider")
706 static void aShiftRShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
707 IntFunction<boolean[]> fm) {
708 short[] a = fa.apply(SPECIES.length());
709 short[] b = fb.apply(SPECIES.length());
710 short[] r = fr.apply(SPECIES.length());
711 boolean[] mask = fm.apply(SPECIES.length());
712 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
713
714 for (int ic = 0; ic < INVOC_COUNT; ic++) {
715 for (int i = 0; i < a.length; i += SPECIES.length()) {
716 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
717 av.aShiftR((int)b[i], vmask).intoArray(r, i);
718 }
719 }
720
721 assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::aShiftR_unary);
722 }
723
724
725 static short shiftL_unary(short a, short b) {
726 return (short)((a << (b & 15)));
727 }
728
729 @Test(dataProvider = "shortBinaryOpProvider")
730 static void shiftLShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
731 short[] a = fa.apply(SPECIES.length());
732 short[] b = fb.apply(SPECIES.length());
733 short[] r = fr.apply(SPECIES.length());
734
735 for (int ic = 0; ic < INVOC_COUNT; ic++) {
736 for (int i = 0; i < a.length; i += SPECIES.length()) {
737 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
738 av.shiftL((int)b[i]).intoArray(r, i);
739 }
740 }
741
742 assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::shiftL_unary);
743 }
744
745
746
747 @Test(dataProvider = "shortBinaryOpMaskProvider")
748 static void shiftLShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
749 IntFunction<boolean[]> fm) {
750 short[] a = fa.apply(SPECIES.length());
751 short[] b = fb.apply(SPECIES.length());
752 short[] r = fr.apply(SPECIES.length());
753 boolean[] mask = fm.apply(SPECIES.length());
754 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
755
756 for (int ic = 0; ic < INVOC_COUNT; ic++) {
757 for (int i = 0; i < a.length; i += SPECIES.length()) {
758 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
759 av.shiftL((int)b[i], vmask).intoArray(r, i);
760 }
761 }
762
763 assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftL_unary);
764 }
765
766
767 static short shiftR_unary(short a, short b) {
768 return (short)(((a & 0xFFFF) >>> (b & 15)));
769 }
770
771 @Test(dataProvider = "shortBinaryOpProvider")
772 static void shiftRShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
773 short[] a = fa.apply(SPECIES.length());
774 short[] b = fb.apply(SPECIES.length());
775 short[] r = fr.apply(SPECIES.length());
776
777 for (int ic = 0; ic < INVOC_COUNT; ic++) {
778 for (int i = 0; i < a.length; i += SPECIES.length()) {
779 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
780 av.shiftR((int)b[i]).intoArray(r, i);
781 }
782 }
783
784 assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::shiftR_unary);
785 }
786
787
788
789 @Test(dataProvider = "shortBinaryOpMaskProvider")
790 static void shiftRShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
791 IntFunction<boolean[]> fm) {
792 short[] a = fa.apply(SPECIES.length());
793 short[] b = fb.apply(SPECIES.length());
794 short[] r = fr.apply(SPECIES.length());
795 boolean[] mask = fm.apply(SPECIES.length());
796 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
797
798 for (int ic = 0; ic < INVOC_COUNT; ic++) {
799 for (int i = 0; i < a.length; i += SPECIES.length()) {
800 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
801 av.shiftR((int)b[i], vmask).intoArray(r, i);
802 }
803 }
804
805 assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftR_unary);
806 }
807
808 static short max(short a, short b) {
809 return (short)(Math.max(a, b));
810 }
811
812 @Test(dataProvider = "shortBinaryOpProvider")
813 static void maxShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
814 short[] a = fa.apply(SPECIES.length());
815 short[] b = fb.apply(SPECIES.length());
816 short[] r = fr.apply(SPECIES.length());
817
818 for (int ic = 0; ic < INVOC_COUNT; ic++) {
819 for (int i = 0; i < a.length; i += SPECIES.length()) {
820 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
821 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
822 av.max(bv).intoArray(r, i);
823 }
824 }
825
829 return (short)(Math.min(a, b));
830 }
831
832 @Test(dataProvider = "shortBinaryOpProvider")
833 static void minShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
834 short[] a = fa.apply(SPECIES.length());
835 short[] b = fb.apply(SPECIES.length());
836 short[] r = fr.apply(SPECIES.length());
837
838 for (int ic = 0; ic < INVOC_COUNT; ic++) {
839 for (int i = 0; i < a.length; i += SPECIES.length()) {
840 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
841 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
842 av.min(bv).intoArray(r, i);
843 }
844 }
845
846 assertArraysEquals(a, b, r, ShortMaxVectorTests::min);
847 }
848
849 static short andAll(short[] a, int idx) {
850 short res = -1;
851 for (int i = idx; i < (idx + SPECIES.length()); i++) {
852 res &= a[i];
853 }
854
855 return res;
856 }
857
858 static short andAll(short[] a) {
859 short res = -1;
860 for (int i = 0; i < a.length; i += SPECIES.length()) {
861 short tmp = -1;
862 for (int j = 0; j < SPECIES.length(); j++) {
863 tmp &= a[i + j];
864 }
865 res &= tmp;
866 }
867
868 return res;
869 }
870
871
872 @Test(dataProvider = "shortUnaryOpProvider")
873 static void andAllShortMaxVectorTests(IntFunction<short[]> fa) {
874 short[] a = fa.apply(SPECIES.length());
875 short[] r = fr.apply(SPECIES.length());
876 short ra = -1;
877
878 for (int ic = 0; ic < INVOC_COUNT; ic++) {
879 for (int i = 0; i < a.length; i += SPECIES.length()) {
880 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
881 r[i] = av.andAll();
882 }
883 }
884
885 for (int ic = 0; ic < INVOC_COUNT; ic++) {
886 ra = -1;
887 for (int i = 0; i < a.length; i += SPECIES.length()) {
888 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
889 ra &= av.andAll();
890 }
891 }
892
893 assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::andAll, ShortMaxVectorTests::andAll);
894 }
895
896
897 static short orAll(short[] a, int idx) {
898 short res = 0;
899 for (int i = idx; i < (idx + SPECIES.length()); i++) {
900 res |= a[i];
901 }
902
903 return res;
904 }
905
906 static short orAll(short[] a) {
907 short res = 0;
908 for (int i = 0; i < a.length; i += SPECIES.length()) {
909 short tmp = 0;
910 for (int j = 0; j < SPECIES.length(); j++) {
911 tmp |= a[i + j];
912 }
913 res |= tmp;
914 }
915
916 return res;
917 }
918
919
920 @Test(dataProvider = "shortUnaryOpProvider")
921 static void orAllShortMaxVectorTests(IntFunction<short[]> fa) {
922 short[] a = fa.apply(SPECIES.length());
923 short[] r = fr.apply(SPECIES.length());
924 short ra = 0;
925
926 for (int ic = 0; ic < INVOC_COUNT; ic++) {
927 for (int i = 0; i < a.length; i += SPECIES.length()) {
928 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
929 r[i] = av.orAll();
930 }
931 }
932
933 for (int ic = 0; ic < INVOC_COUNT; ic++) {
934 ra = 0;
935 for (int i = 0; i < a.length; i += SPECIES.length()) {
936 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
937 ra |= av.orAll();
938 }
939 }
940
941 assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::orAll, ShortMaxVectorTests::orAll);
942 }
943
944
945 static short xorAll(short[] a, int idx) {
946 short res = 0;
947 for (int i = idx; i < (idx + SPECIES.length()); i++) {
948 res ^= a[i];
949 }
950
951 return res;
952 }
953
954 static short xorAll(short[] a) {
955 short res = 0;
956 for (int i = 0; i < a.length; i += SPECIES.length()) {
957 short tmp = 0;
958 for (int j = 0; j < SPECIES.length(); j++) {
959 tmp ^= a[i + j];
960 }
961 res ^= tmp;
962 }
963
964 return res;
965 }
966
967
968 @Test(dataProvider = "shortUnaryOpProvider")
969 static void xorAllShortMaxVectorTests(IntFunction<short[]> fa) {
970 short[] a = fa.apply(SPECIES.length());
971 short[] r = fr.apply(SPECIES.length());
972 short ra = 0;
973
974 for (int ic = 0; ic < INVOC_COUNT; ic++) {
975 for (int i = 0; i < a.length; i += SPECIES.length()) {
976 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
977 r[i] = av.xorAll();
978 }
979 }
980
981 for (int ic = 0; ic < INVOC_COUNT; ic++) {
982 ra = 0;
983 for (int i = 0; i < a.length; i += SPECIES.length()) {
984 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
985 ra ^= av.xorAll();
986 }
987 }
988
989 assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::xorAll, ShortMaxVectorTests::xorAll);
990 }
991
992 static short addAll(short[] a, int idx) {
993 short res = 0;
994 for (int i = idx; i < (idx + SPECIES.length()); i++) {
995 res += a[i];
996 }
997
998 return res;
999 }
1000
1001 static short addAll(short[] a) {
1002 short res = 0;
1003 for (int i = 0; i < a.length; i += SPECIES.length()) {
1004 short tmp = 0;
1005 for (int j = 0; j < SPECIES.length(); j++) {
1006 tmp += a[i + j];
1007 }
1008 res += tmp;
1009 }
1010
1011 return res;
1012 }
1013 @Test(dataProvider = "shortUnaryOpProvider")
1014 static void addAllShortMaxVectorTests(IntFunction<short[]> fa) {
1015 short[] a = fa.apply(SPECIES.length());
1016 short[] r = fr.apply(SPECIES.length());
1017 short ra = 0;
1018
1019 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1020 for (int i = 0; i < a.length; i += SPECIES.length()) {
1021 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1022 r[i] = av.addAll();
1023 }
1024 }
1025
1026 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1027 ra = 0;
1028 for (int i = 0; i < a.length; i += SPECIES.length()) {
1029 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1030 ra += av.addAll();
1031 }
1032 }
1033
1034 assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::addAll, ShortMaxVectorTests::addAll);
1035 }
1036 static short mulAll(short[] a, int idx) {
1037 short res = 1;
1038 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1039 res *= a[i];
1040 }
1041
1042 return res;
1043 }
1044
1045 static short mulAll(short[] a) {
1046 short res = 1;
1047 for (int i = 0; i < a.length; i += SPECIES.length()) {
1048 short tmp = 1;
1049 for (int j = 0; j < SPECIES.length(); j++) {
1050 tmp *= a[i + j];
1051 }
1052 res *= tmp;
1053 }
1054
1055 return res;
1056 }
1057 @Test(dataProvider = "shortUnaryOpProvider")
1058 static void mulAllShortMaxVectorTests(IntFunction<short[]> fa) {
1059 short[] a = fa.apply(SPECIES.length());
1060 short[] r = fr.apply(SPECIES.length());
1061 short ra = 1;
1062
1063 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1064 for (int i = 0; i < a.length; i += SPECIES.length()) {
1065 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1066 r[i] = av.mulAll();
1067 }
1068 }
1069
1070 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1071 ra = 1;
1072 for (int i = 0; i < a.length; i += SPECIES.length()) {
1073 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1074 ra *= av.mulAll();
1075 }
1076 }
1077
1078 assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::mulAll, ShortMaxVectorTests::mulAll);
1079 }
1080 static short minAll(short[] a, int idx) {
1081 short res = Short.MAX_VALUE;
1082 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1083 res = (short)Math.min(res, a[i]);
1084 }
1085
1086 return res;
1087 }
1088
1089 static short minAll(short[] a) {
1090 short res = Short.MAX_VALUE;
1091 for (int i = 0; i < a.length; i++) {
1092 res = (short)Math.min(res, a[i]);
1093 }
1094
1095 return res;
1096 }
1097 @Test(dataProvider = "shortUnaryOpProvider")
1098 static void minAllShortMaxVectorTests(IntFunction<short[]> fa) {
1099 short[] a = fa.apply(SPECIES.length());
1100 short[] r = fr.apply(SPECIES.length());
1101 short ra = Short.MAX_VALUE;
1102
1103 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1104 for (int i = 0; i < a.length; i += SPECIES.length()) {
1105 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1106 r[i] = av.minAll();
1107 }
1108 }
1109
1110 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1111 ra = Short.MAX_VALUE;
1112 for (int i = 0; i < a.length; i += SPECIES.length()) {
1113 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1114 ra = (short)Math.min(ra, av.minAll());
1115 }
1116 }
1117
1118 assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::minAll, ShortMaxVectorTests::minAll);
1119 }
1120 static short maxAll(short[] a, int idx) {
1121 short res = Short.MIN_VALUE;
1122 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1123 res = (short)Math.max(res, a[i]);
1124 }
1125
1126 return res;
1127 }
1128
1129 static short maxAll(short[] a) {
1130 short res = Short.MIN_VALUE;
1131 for (int i = 0; i < a.length; i++) {
1132 res = (short)Math.max(res, a[i]);
1133 }
1134
1135 return res;
1136 }
1137 @Test(dataProvider = "shortUnaryOpProvider")
1138 static void maxAllShortMaxVectorTests(IntFunction<short[]> fa) {
1139 short[] a = fa.apply(SPECIES.length());
1140 short[] r = fr.apply(SPECIES.length());
1141 short ra = Short.MIN_VALUE;
1142
1143 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1144 for (int i = 0; i < a.length; i += SPECIES.length()) {
1145 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1146 r[i] = av.maxAll();
1147 }
1148 }
1149
1150 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1151 ra = Short.MIN_VALUE;
1152 for (int i = 0; i < a.length; i += SPECIES.length()) {
1153 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1154 ra = (short)Math.max(ra, av.maxAll());
1155 }
1156 }
1157
1158 assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::maxAll, ShortMaxVectorTests::maxAll);
1159 }
1160
1161 static boolean anyTrue(boolean[] a, int idx) {
1162 boolean res = false;
1163 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1164 res |= a[i];
1165 }
1166
1167 return res;
1168 }
1169
1170
1171 @Test(dataProvider = "boolUnaryOpProvider")
1172 static void anyTrueShortMaxVectorTests(IntFunction<boolean[]> fm) {
1173 boolean[] mask = fm.apply(SPECIES.length());
1174 boolean[] r = fmr.apply(SPECIES.length());
1175
1176 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1177 for (int i = 0; i < mask.length; i += SPECIES.length()) {
1178 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, i);
|
649 short[] r = fr.apply(SPECIES.length());
650 boolean[] mask = fm.apply(SPECIES.length());
651 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
652
653 for (int ic = 0; ic < INVOC_COUNT; ic++) {
654 for (int i = 0; i < a.length; i += SPECIES.length()) {
655 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
656 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
657 av.xor(bv, vmask).intoArray(r, i);
658 }
659 }
660
661 assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::xor);
662 }
663
664
665
666
667
668
669 static short shiftLeft(short a, short b) {
670 return (short)((a << (b & 0xF)));
671 }
672
673 @Test(dataProvider = "shortBinaryOpProvider")
674 static void shiftLeftShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
675 short[] a = fa.apply(SPECIES.length());
676 short[] b = fb.apply(SPECIES.length());
677 short[] r = fr.apply(SPECIES.length());
678
679 for (int ic = 0; ic < INVOC_COUNT; ic++) {
680 for (int i = 0; i < a.length; i += SPECIES.length()) {
681 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
682 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
683 av.shiftLeft(bv).intoArray(r, i);
684 }
685 }
686
687 assertArraysEquals(a, b, r, ShortMaxVectorTests::shiftLeft);
688 }
689
690
691
692 @Test(dataProvider = "shortBinaryOpMaskProvider")
693 static void shiftLeftShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
694 IntFunction<boolean[]> fm) {
695 short[] a = fa.apply(SPECIES.length());
696 short[] b = fb.apply(SPECIES.length());
697 short[] r = fr.apply(SPECIES.length());
698 boolean[] mask = fm.apply(SPECIES.length());
699 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
700
701 for (int ic = 0; ic < INVOC_COUNT; ic++) {
702 for (int i = 0; i < a.length; i += SPECIES.length()) {
703 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
704 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
705 av.shiftLeft(bv, vmask).intoArray(r, i);
706 }
707 }
708
709 assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftLeft);
710 }
711
712
713
714
715
716
717 static short shiftRight(short a, short b) {
718 return (short)((a >>> (b & 0xF)));
719 }
720
721 @Test(dataProvider = "shortBinaryOpProvider")
722 static void shiftRightShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
723 short[] a = fa.apply(SPECIES.length());
724 short[] b = fb.apply(SPECIES.length());
725 short[] r = fr.apply(SPECIES.length());
726
727 for (int ic = 0; ic < INVOC_COUNT; ic++) {
728 for (int i = 0; i < a.length; i += SPECIES.length()) {
729 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
730 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
731 av.shiftRight(bv).intoArray(r, i);
732 }
733 }
734
735 assertArraysEquals(a, b, r, ShortMaxVectorTests::shiftRight);
736 }
737
738
739
740 @Test(dataProvider = "shortBinaryOpMaskProvider")
741 static void shiftRightShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
742 IntFunction<boolean[]> fm) {
743 short[] a = fa.apply(SPECIES.length());
744 short[] b = fb.apply(SPECIES.length());
745 short[] r = fr.apply(SPECIES.length());
746 boolean[] mask = fm.apply(SPECIES.length());
747 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
748
749 for (int ic = 0; ic < INVOC_COUNT; ic++) {
750 for (int i = 0; i < a.length; i += SPECIES.length()) {
751 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
752 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
753 av.shiftRight(bv, vmask).intoArray(r, i);
754 }
755 }
756
757 assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftRight);
758 }
759
760
761
762
763
764
765 static short shiftArithmeticRight(short a, short b) {
766 return (short)((a >> (b & 0xF)));
767 }
768
769 @Test(dataProvider = "shortBinaryOpProvider")
770 static void shiftArithmeticRightShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
771 short[] a = fa.apply(SPECIES.length());
772 short[] b = fb.apply(SPECIES.length());
773 short[] 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 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
778 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
779 av.shiftArithmeticRight(bv).intoArray(r, i);
780 }
781 }
782
783 assertArraysEquals(a, b, r, ShortMaxVectorTests::shiftArithmeticRight);
784 }
785
786
787
788 @Test(dataProvider = "shortBinaryOpMaskProvider")
789 static void shiftArithmeticRightShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
790 IntFunction<boolean[]> fm) {
791 short[] a = fa.apply(SPECIES.length());
792 short[] b = fb.apply(SPECIES.length());
793 short[] r = fr.apply(SPECIES.length());
794 boolean[] mask = fm.apply(SPECIES.length());
795 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
796
797 for (int ic = 0; ic < INVOC_COUNT; ic++) {
798 for (int i = 0; i < a.length; i += SPECIES.length()) {
799 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
800 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
801 av.shiftArithmeticRight(bv, vmask).intoArray(r, i);
802 }
803 }
804
805 assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftArithmeticRight);
806 }
807
808
809
810
811
812
813 static short shiftLeft_unary(short a, short b) {
814 return (short)((a << (b & 15)));
815 }
816
817 @Test(dataProvider = "shortBinaryOpProvider")
818 static void shiftLeftShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
819 short[] a = fa.apply(SPECIES.length());
820 short[] b = fb.apply(SPECIES.length());
821 short[] r = fr.apply(SPECIES.length());
822
823 for (int ic = 0; ic < INVOC_COUNT; ic++) {
824 for (int i = 0; i < a.length; i += SPECIES.length()) {
825 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
826 av.shiftLeft((int)b[i]).intoArray(r, i);
827 }
828 }
829
830 assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::shiftLeft_unary);
831 }
832
833
834
835 @Test(dataProvider = "shortBinaryOpMaskProvider")
836 static void shiftLeftShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
837 IntFunction<boolean[]> fm) {
838 short[] a = fa.apply(SPECIES.length());
839 short[] b = fb.apply(SPECIES.length());
840 short[] r = fr.apply(SPECIES.length());
841 boolean[] mask = fm.apply(SPECIES.length());
842 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
843
844 for (int ic = 0; ic < INVOC_COUNT; ic++) {
845 for (int i = 0; i < a.length; i += SPECIES.length()) {
846 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
847 av.shiftLeft((int)b[i], vmask).intoArray(r, i);
848 }
849 }
850
851 assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftLeft_unary);
852 }
853
854
855
856
857
858
859 static short shiftRight_unary(short a, short b) {
860 return (short)(((a & 0xFFFF) >>> (b & 15)));
861 }
862
863 @Test(dataProvider = "shortBinaryOpProvider")
864 static void shiftRightShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
865 short[] a = fa.apply(SPECIES.length());
866 short[] b = fb.apply(SPECIES.length());
867 short[] r = fr.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 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
872 av.shiftRight((int)b[i]).intoArray(r, i);
873 }
874 }
875
876 assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::shiftRight_unary);
877 }
878
879
880
881 @Test(dataProvider = "shortBinaryOpMaskProvider")
882 static void shiftRightShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
883 IntFunction<boolean[]> fm) {
884 short[] a = fa.apply(SPECIES.length());
885 short[] b = fb.apply(SPECIES.length());
886 short[] r = fr.apply(SPECIES.length());
887 boolean[] mask = fm.apply(SPECIES.length());
888 VectorMask<Short> 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 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
893 av.shiftRight((int)b[i], vmask).intoArray(r, i);
894 }
895 }
896
897 assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftRight_unary);
898 }
899
900
901
902
903
904
905 static short shiftArithmeticRight_unary(short a, short b) {
906 return (short)((a >> (b & 15)));
907 }
908
909 @Test(dataProvider = "shortBinaryOpProvider")
910 static void shiftArithmeticRightShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
911 short[] a = fa.apply(SPECIES.length());
912 short[] b = fb.apply(SPECIES.length());
913 short[] r = fr.apply(SPECIES.length());
914
915 for (int ic = 0; ic < INVOC_COUNT; ic++) {
916 for (int i = 0; i < a.length; i += SPECIES.length()) {
917 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
918 av.shiftArithmeticRight((int)b[i]).intoArray(r, i);
919 }
920 }
921
922 assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::shiftArithmeticRight_unary);
923 }
924
925
926
927 @Test(dataProvider = "shortBinaryOpMaskProvider")
928 static void shiftArithmeticRightShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
929 IntFunction<boolean[]> fm) {
930 short[] a = fa.apply(SPECIES.length());
931 short[] b = fb.apply(SPECIES.length());
932 short[] r = fr.apply(SPECIES.length());
933 boolean[] mask = fm.apply(SPECIES.length());
934 VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
935
936 for (int ic = 0; ic < INVOC_COUNT; ic++) {
937 for (int i = 0; i < a.length; i += SPECIES.length()) {
938 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
939 av.shiftArithmeticRight((int)b[i], vmask).intoArray(r, i);
940 }
941 }
942
943 assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftArithmeticRight_unary);
944 }
945
946 static short max(short a, short b) {
947 return (short)(Math.max(a, b));
948 }
949
950 @Test(dataProvider = "shortBinaryOpProvider")
951 static void maxShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
952 short[] a = fa.apply(SPECIES.length());
953 short[] b = fb.apply(SPECIES.length());
954 short[] r = fr.apply(SPECIES.length());
955
956 for (int ic = 0; ic < INVOC_COUNT; ic++) {
957 for (int i = 0; i < a.length; i += SPECIES.length()) {
958 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
959 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
960 av.max(bv).intoArray(r, i);
961 }
962 }
963
967 return (short)(Math.min(a, b));
968 }
969
970 @Test(dataProvider = "shortBinaryOpProvider")
971 static void minShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
972 short[] a = fa.apply(SPECIES.length());
973 short[] b = fb.apply(SPECIES.length());
974 short[] r = fr.apply(SPECIES.length());
975
976 for (int ic = 0; ic < INVOC_COUNT; ic++) {
977 for (int i = 0; i < a.length; i += SPECIES.length()) {
978 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
979 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
980 av.min(bv).intoArray(r, i);
981 }
982 }
983
984 assertArraysEquals(a, b, r, ShortMaxVectorTests::min);
985 }
986
987 static short andLanes(short[] a, int idx) {
988 short res = -1;
989 for (int i = idx; i < (idx + SPECIES.length()); i++) {
990 res &= a[i];
991 }
992
993 return res;
994 }
995
996 static short andLanes(short[] a) {
997 short res = -1;
998 for (int i = 0; i < a.length; i += SPECIES.length()) {
999 short tmp = -1;
1000 for (int j = 0; j < SPECIES.length(); j++) {
1001 tmp &= a[i + j];
1002 }
1003 res &= tmp;
1004 }
1005
1006 return res;
1007 }
1008
1009
1010 @Test(dataProvider = "shortUnaryOpProvider")
1011 static void andLanesShortMaxVectorTests(IntFunction<short[]> fa) {
1012 short[] a = fa.apply(SPECIES.length());
1013 short[] r = fr.apply(SPECIES.length());
1014 short ra = -1;
1015
1016 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1017 for (int i = 0; i < a.length; i += SPECIES.length()) {
1018 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1019 r[i] = av.andLanes();
1020 }
1021 }
1022
1023 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1024 ra = -1;
1025 for (int i = 0; i < a.length; i += SPECIES.length()) {
1026 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1027 ra &= av.andLanes();
1028 }
1029 }
1030
1031 assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::andLanes, ShortMaxVectorTests::andLanes);
1032 }
1033
1034
1035 static short orLanes(short[] a, int idx) {
1036 short res = 0;
1037 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1038 res |= a[i];
1039 }
1040
1041 return res;
1042 }
1043
1044 static short orLanes(short[] a) {
1045 short res = 0;
1046 for (int i = 0; i < a.length; i += SPECIES.length()) {
1047 short tmp = 0;
1048 for (int j = 0; j < SPECIES.length(); j++) {
1049 tmp |= a[i + j];
1050 }
1051 res |= tmp;
1052 }
1053
1054 return res;
1055 }
1056
1057
1058 @Test(dataProvider = "shortUnaryOpProvider")
1059 static void orLanesShortMaxVectorTests(IntFunction<short[]> fa) {
1060 short[] a = fa.apply(SPECIES.length());
1061 short[] r = fr.apply(SPECIES.length());
1062 short ra = 0;
1063
1064 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1065 for (int i = 0; i < a.length; i += SPECIES.length()) {
1066 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1067 r[i] = av.orLanes();
1068 }
1069 }
1070
1071 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1072 ra = 0;
1073 for (int i = 0; i < a.length; i += SPECIES.length()) {
1074 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1075 ra |= av.orLanes();
1076 }
1077 }
1078
1079 assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::orLanes, ShortMaxVectorTests::orLanes);
1080 }
1081
1082
1083 static short xorLanes(short[] a, int idx) {
1084 short res = 0;
1085 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1086 res ^= a[i];
1087 }
1088
1089 return res;
1090 }
1091
1092 static short xorLanes(short[] a) {
1093 short res = 0;
1094 for (int i = 0; i < a.length; i += SPECIES.length()) {
1095 short tmp = 0;
1096 for (int j = 0; j < SPECIES.length(); j++) {
1097 tmp ^= a[i + j];
1098 }
1099 res ^= tmp;
1100 }
1101
1102 return res;
1103 }
1104
1105
1106 @Test(dataProvider = "shortUnaryOpProvider")
1107 static void xorLanesShortMaxVectorTests(IntFunction<short[]> fa) {
1108 short[] a = fa.apply(SPECIES.length());
1109 short[] r = fr.apply(SPECIES.length());
1110 short ra = 0;
1111
1112 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1113 for (int i = 0; i < a.length; i += SPECIES.length()) {
1114 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1115 r[i] = av.xorLanes();
1116 }
1117 }
1118
1119 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1120 ra = 0;
1121 for (int i = 0; i < a.length; i += SPECIES.length()) {
1122 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1123 ra ^= av.xorLanes();
1124 }
1125 }
1126
1127 assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::xorLanes, ShortMaxVectorTests::xorLanes);
1128 }
1129
1130 static short addLanes(short[] a, int idx) {
1131 short res = 0;
1132 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1133 res += a[i];
1134 }
1135
1136 return res;
1137 }
1138
1139 static short addLanes(short[] a) {
1140 short res = 0;
1141 for (int i = 0; i < a.length; i += SPECIES.length()) {
1142 short tmp = 0;
1143 for (int j = 0; j < SPECIES.length(); j++) {
1144 tmp += a[i + j];
1145 }
1146 res += tmp;
1147 }
1148
1149 return res;
1150 }
1151 @Test(dataProvider = "shortUnaryOpProvider")
1152 static void addLanesShortMaxVectorTests(IntFunction<short[]> fa) {
1153 short[] a = fa.apply(SPECIES.length());
1154 short[] r = fr.apply(SPECIES.length());
1155 short ra = 0;
1156
1157 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1158 for (int i = 0; i < a.length; i += SPECIES.length()) {
1159 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1160 r[i] = av.addLanes();
1161 }
1162 }
1163
1164 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1165 ra = 0;
1166 for (int i = 0; i < a.length; i += SPECIES.length()) {
1167 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1168 ra += av.addLanes();
1169 }
1170 }
1171
1172 assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::addLanes, ShortMaxVectorTests::addLanes);
1173 }
1174 static short mulLanes(short[] a, int idx) {
1175 short res = 1;
1176 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1177 res *= a[i];
1178 }
1179
1180 return res;
1181 }
1182
1183 static short mulLanes(short[] a) {
1184 short res = 1;
1185 for (int i = 0; i < a.length; i += SPECIES.length()) {
1186 short tmp = 1;
1187 for (int j = 0; j < SPECIES.length(); j++) {
1188 tmp *= a[i + j];
1189 }
1190 res *= tmp;
1191 }
1192
1193 return res;
1194 }
1195 @Test(dataProvider = "shortUnaryOpProvider")
1196 static void mulLanesShortMaxVectorTests(IntFunction<short[]> fa) {
1197 short[] a = fa.apply(SPECIES.length());
1198 short[] r = fr.apply(SPECIES.length());
1199 short ra = 1;
1200
1201 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1202 for (int i = 0; i < a.length; i += SPECIES.length()) {
1203 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1204 r[i] = av.mulLanes();
1205 }
1206 }
1207
1208 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1209 ra = 1;
1210 for (int i = 0; i < a.length; i += SPECIES.length()) {
1211 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1212 ra *= av.mulLanes();
1213 }
1214 }
1215
1216 assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::mulLanes, ShortMaxVectorTests::mulLanes);
1217 }
1218 static short minLanes(short[] a, int idx) {
1219 short res = Short.MAX_VALUE;
1220 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1221 res = (short)Math.min(res, a[i]);
1222 }
1223
1224 return res;
1225 }
1226
1227 static short minLanes(short[] a) {
1228 short res = Short.MAX_VALUE;
1229 for (int i = 0; i < a.length; i++) {
1230 res = (short)Math.min(res, a[i]);
1231 }
1232
1233 return res;
1234 }
1235 @Test(dataProvider = "shortUnaryOpProvider")
1236 static void minLanesShortMaxVectorTests(IntFunction<short[]> fa) {
1237 short[] a = fa.apply(SPECIES.length());
1238 short[] r = fr.apply(SPECIES.length());
1239 short ra = Short.MAX_VALUE;
1240
1241 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1242 for (int i = 0; i < a.length; i += SPECIES.length()) {
1243 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1244 r[i] = av.minLanes();
1245 }
1246 }
1247
1248 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1249 ra = Short.MAX_VALUE;
1250 for (int i = 0; i < a.length; i += SPECIES.length()) {
1251 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1252 ra = (short)Math.min(ra, av.minLanes());
1253 }
1254 }
1255
1256 assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::minLanes, ShortMaxVectorTests::minLanes);
1257 }
1258 static short maxLanes(short[] a, int idx) {
1259 short res = Short.MIN_VALUE;
1260 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1261 res = (short)Math.max(res, a[i]);
1262 }
1263
1264 return res;
1265 }
1266
1267 static short maxLanes(short[] a) {
1268 short res = Short.MIN_VALUE;
1269 for (int i = 0; i < a.length; i++) {
1270 res = (short)Math.max(res, a[i]);
1271 }
1272
1273 return res;
1274 }
1275 @Test(dataProvider = "shortUnaryOpProvider")
1276 static void maxLanesShortMaxVectorTests(IntFunction<short[]> fa) {
1277 short[] a = fa.apply(SPECIES.length());
1278 short[] r = fr.apply(SPECIES.length());
1279 short ra = Short.MIN_VALUE;
1280
1281 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1282 for (int i = 0; i < a.length; i += SPECIES.length()) {
1283 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1284 r[i] = av.maxLanes();
1285 }
1286 }
1287
1288 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1289 ra = Short.MIN_VALUE;
1290 for (int i = 0; i < a.length; i += SPECIES.length()) {
1291 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1292 ra = (short)Math.max(ra, av.maxLanes());
1293 }
1294 }
1295
1296 assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::maxLanes, ShortMaxVectorTests::maxLanes);
1297 }
1298
1299 static boolean anyTrue(boolean[] a, int idx) {
1300 boolean res = false;
1301 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1302 res |= a[i];
1303 }
1304
1305 return res;
1306 }
1307
1308
1309 @Test(dataProvider = "boolUnaryOpProvider")
1310 static void anyTrueShortMaxVectorTests(IntFunction<boolean[]> fm) {
1311 boolean[] mask = fm.apply(SPECIES.length());
1312 boolean[] r = fmr.apply(SPECIES.length());
1313
1314 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1315 for (int i = 0; i < mask.length; i += SPECIES.length()) {
1316 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, i);
|