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 FloatMaxVectorTests
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.FloatVector;
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 FloatMaxVectorTests extends AbstractVectorTest {
50
51 static final Species<Float> SPECIES =
52 FloatVector.SPECIES_MAX;
53
54 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
55
56 static Shape getMaxBit() {
57 return Shape.S_Max_BIT;
58 }
59
60 interface FUnOp {
61 float apply(float a);
62 }
63
64 static void assertArraysEquals(float[] a, float[] r, FUnOp f) {
65 int i = 0;
66 try {
67 for (; i < a.length; i++) {
68 Assert.assertEquals(r[i], f.apply(a[i]));
69 }
70 } catch (AssertionError e) {
71 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
72 }
73 }
74
75 static void assertArraysEquals(float[] a, float[] r, boolean[] mask, FUnOp f) {
76 int i = 0;
77 try {
549 float[] r = fr.apply(SPECIES.length());
550
551 for (int ic = 0; ic < INVOC_COUNT; ic++) {
552 for (int i = 0; i < a.length; i += SPECIES.length()) {
553 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
554 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
555 av.add(bv).intoArray(r, i);
556 }
557 }
558
559 assertArraysEquals(a, b, r, FloatMaxVectorTests::add);
560 }
561
562 @Test(dataProvider = "floatBinaryOpMaskProvider")
563 static void addFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
564 IntFunction<boolean[]> fm) {
565 float[] a = fa.apply(SPECIES.length());
566 float[] b = fb.apply(SPECIES.length());
567 float[] r = fr.apply(SPECIES.length());
568 boolean[] mask = fm.apply(SPECIES.length());
569 Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
570
571 for (int ic = 0; ic < INVOC_COUNT; ic++) {
572 for (int i = 0; i < a.length; i += SPECIES.length()) {
573 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
574 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
575 av.add(bv, vmask).intoArray(r, i);
576 }
577 }
578
579 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::add);
580 }
581 static float sub(float a, float b) {
582 return (float)(a - b);
583 }
584
585 @Test(dataProvider = "floatBinaryOpProvider")
586 static void subFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
587 float[] a = fa.apply(SPECIES.length());
588 float[] b = fb.apply(SPECIES.length());
589 float[] r = fr.apply(SPECIES.length());
590
591 for (int ic = 0; ic < INVOC_COUNT; ic++) {
592 for (int i = 0; i < a.length; i += SPECIES.length()) {
593 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
594 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
595 av.sub(bv).intoArray(r, i);
596 }
597 }
598
599 assertArraysEquals(a, b, r, FloatMaxVectorTests::sub);
600 }
601
602 @Test(dataProvider = "floatBinaryOpMaskProvider")
603 static void subFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
604 IntFunction<boolean[]> fm) {
605 float[] a = fa.apply(SPECIES.length());
606 float[] b = fb.apply(SPECIES.length());
607 float[] r = fr.apply(SPECIES.length());
608 boolean[] mask = fm.apply(SPECIES.length());
609 Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
610
611 for (int ic = 0; ic < INVOC_COUNT; ic++) {
612 for (int i = 0; i < a.length; i += SPECIES.length()) {
613 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
614 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
615 av.sub(bv, vmask).intoArray(r, i);
616 }
617 }
618
619 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::sub);
620 }
621
622 static float div(float a, float b) {
623 return (float)(a / b);
624 }
625
626 @Test(dataProvider = "floatBinaryOpProvider")
627 static void divFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
628 float[] a = fa.apply(SPECIES.length());
629 float[] b = fb.apply(SPECIES.length());
632 for (int ic = 0; ic < INVOC_COUNT; ic++) {
633 for (int i = 0; i < a.length; i += SPECIES.length()) {
634 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
635 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
636 av.div(bv).intoArray(r, i);
637 }
638 }
639
640 assertArraysEquals(a, b, r, FloatMaxVectorTests::div);
641 }
642
643
644
645 @Test(dataProvider = "floatBinaryOpMaskProvider")
646 static void divFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
647 IntFunction<boolean[]> fm) {
648 float[] a = fa.apply(SPECIES.length());
649 float[] b = fb.apply(SPECIES.length());
650 float[] r = fr.apply(SPECIES.length());
651 boolean[] mask = fm.apply(SPECIES.length());
652 Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
653
654 for (int ic = 0; ic < INVOC_COUNT; ic++) {
655 for (int i = 0; i < a.length; i += SPECIES.length()) {
656 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
657 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
658 av.div(bv, vmask).intoArray(r, i);
659 }
660 }
661
662 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::div);
663 }
664
665 static float mul(float a, float b) {
666 return (float)(a * b);
667 }
668
669 @Test(dataProvider = "floatBinaryOpProvider")
670 static void mulFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
671 float[] a = fa.apply(SPECIES.length());
672 float[] b = fb.apply(SPECIES.length());
673 float[] r = fr.apply(SPECIES.length());
674
675 for (int ic = 0; ic < INVOC_COUNT; ic++) {
676 for (int i = 0; i < a.length; i += SPECIES.length()) {
677 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
678 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
679 av.mul(bv).intoArray(r, i);
680 }
681 }
682
683 assertArraysEquals(a, b, r, FloatMaxVectorTests::mul);
684 }
685
686 @Test(dataProvider = "floatBinaryOpMaskProvider")
687 static void mulFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
688 IntFunction<boolean[]> fm) {
689 float[] a = fa.apply(SPECIES.length());
690 float[] b = fb.apply(SPECIES.length());
691 float[] r = fr.apply(SPECIES.length());
692 boolean[] mask = fm.apply(SPECIES.length());
693 Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
694
695 for (int ic = 0; ic < INVOC_COUNT; ic++) {
696 for (int i = 0; i < a.length; i += SPECIES.length()) {
697 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
698 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
699 av.mul(bv, vmask).intoArray(r, i);
700 }
701 }
702
703 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::mul);
704 }
705
706
707
708
709
710
711
712
713
958
959 for (int ic = 0; ic < INVOC_COUNT; ic++) {
960 for (int i = 0; i < a.length; i += SPECIES.length()) {
961 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
962 av.with(0, (float)4).intoArray(r, i);
963 }
964 }
965
966 assertInsertArraysEquals(a, r, (float)4, 0);
967 }
968
969 @Test(dataProvider = "floatCompareOpProvider")
970 static void lessThanFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
971 float[] a = fa.apply(SPECIES.length());
972 float[] b = fb.apply(SPECIES.length());
973
974 for (int ic = 0; ic < INVOC_COUNT; ic++) {
975 for (int i = 0; i < a.length; i += SPECIES.length()) {
976 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
977 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
978 Vector.Mask<Float> mv = av.lessThan(bv);
979
980 // Check results as part of computation.
981 for (int j = 0; j < SPECIES.length(); j++) {
982 Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]);
983 }
984 }
985 }
986 }
987
988
989 @Test(dataProvider = "floatCompareOpProvider")
990 static void greaterThanFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
991 float[] a = fa.apply(SPECIES.length());
992 float[] b = fb.apply(SPECIES.length());
993
994 for (int ic = 0; ic < INVOC_COUNT; ic++) {
995 for (int i = 0; i < a.length; i += SPECIES.length()) {
996 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
997 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
998 Vector.Mask<Float> mv = av.greaterThan(bv);
999
1000 // Check results as part of computation.
1001 for (int j = 0; j < SPECIES.length(); j++) {
1002 Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]);
1003 }
1004 }
1005 }
1006 }
1007
1008
1009 @Test(dataProvider = "floatCompareOpProvider")
1010 static void equalFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1011 float[] a = fa.apply(SPECIES.length());
1012 float[] b = fb.apply(SPECIES.length());
1013
1014 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1015 for (int i = 0; i < a.length; i += SPECIES.length()) {
1016 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1017 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1018 Vector.Mask<Float> mv = av.equal(bv);
1019
1020 // Check results as part of computation.
1021 for (int j = 0; j < SPECIES.length(); j++) {
1022 Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]);
1023 }
1024 }
1025 }
1026 }
1027
1028
1029 @Test(dataProvider = "floatCompareOpProvider")
1030 static void notEqualFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1031 float[] a = fa.apply(SPECIES.length());
1032 float[] b = fb.apply(SPECIES.length());
1033
1034 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1035 for (int i = 0; i < a.length; i += SPECIES.length()) {
1036 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1037 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1038 Vector.Mask<Float> mv = av.notEqual(bv);
1039
1040 // Check results as part of computation.
1041 for (int j = 0; j < SPECIES.length(); j++) {
1042 Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]);
1043 }
1044 }
1045 }
1046 }
1047
1048
1049 @Test(dataProvider = "floatCompareOpProvider")
1050 static void lessThanEqFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1051 float[] a = fa.apply(SPECIES.length());
1052 float[] b = fb.apply(SPECIES.length());
1053
1054 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1055 for (int i = 0; i < a.length; i += SPECIES.length()) {
1056 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1057 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1058 Vector.Mask<Float> mv = av.lessThanEq(bv);
1059
1060 // Check results as part of computation.
1061 for (int j = 0; j < SPECIES.length(); j++) {
1062 Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]);
1063 }
1064 }
1065 }
1066 }
1067
1068
1069 @Test(dataProvider = "floatCompareOpProvider")
1070 static void greaterThanEqFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1071 float[] a = fa.apply(SPECIES.length());
1072 float[] b = fb.apply(SPECIES.length());
1073
1074 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1075 for (int i = 0; i < a.length; i += SPECIES.length()) {
1076 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1077 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1078 Vector.Mask<Float> mv = av.greaterThanEq(bv);
1079
1080 // Check results as part of computation.
1081 for (int j = 0; j < SPECIES.length(); j++) {
1082 Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]);
1083 }
1084 }
1085 }
1086 }
1087
1088
1089 static float blend(float a, float b, boolean mask) {
1090 return mask ? b : a;
1091 }
1092
1093 @Test(dataProvider = "floatBinaryOpMaskProvider")
1094 static void blendFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
1095 IntFunction<boolean[]> fm) {
1096 float[] a = fa.apply(SPECIES.length());
1097 float[] b = fb.apply(SPECIES.length());
1098 float[] r = fr.apply(SPECIES.length());
1099 boolean[] mask = fm.apply(SPECIES.length());
1100 Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
1101
1102 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1103 for (int i = 0; i < a.length; i += SPECIES.length()) {
1104 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1105 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1106 av.blend(bv, vmask).intoArray(r, i);
1107 }
1108 }
1109
1110 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::blend);
1111 }
1112
1113 @Test(dataProvider = "floatUnaryOpShuffleProvider")
1114 static void RearrangeFloatMaxVectorTests(IntFunction<float[]> fa,
1115 BiFunction<Integer,Integer,int[]> fs) {
1116 float[] a = fa.apply(SPECIES.length());
1117 int[] order = fs.apply(a.length, SPECIES.length());
1118 float[] r = fr.apply(SPECIES.length());
1119
1120 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1121 for (int i = 0; i < a.length; i += SPECIES.length()) {
1122 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1123 av.rearrange(FloatVector.shuffleFromArray(SPECIES, order, i)).intoArray(r, i);
1124 }
1125 }
1126
1127 assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1128 }
1129
1130
1131
1132
1133 @Test(dataProvider = "floatUnaryOpProvider")
1134 static void getFloatMaxVectorTests(IntFunction<float[]> fa) {
1135 float[] a = fa.apply(SPECIES.length());
1136 float[] r = fr.apply(SPECIES.length());
1137
1138 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1139 for (int i = 0; i < a.length; i += SPECIES.length()) {
1140 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1141 int num_lanes = SPECIES.length();
1142 // Manually unroll because full unroll happens after intrinsification.
1143 // Unroll is needed because get intrinsic requires for index to be a known constant.
1743 for (int i = 0; i < a.length; i += SPECIES.length()) {
1744 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1745 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1746 FloatVector cv = FloatVector.fromArray(SPECIES, c, i);
1747 av.fma(bv, cv).intoArray(r, i);
1748 }
1749 }
1750
1751 assertArraysEquals(a, b, c, r, FloatMaxVectorTests::fma);
1752 }
1753
1754
1755 @Test(dataProvider = "floatTernaryOpMaskProvider")
1756 static void fmaFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
1757 IntFunction<float[]> fc, IntFunction<boolean[]> fm) {
1758 float[] a = fa.apply(SPECIES.length());
1759 float[] b = fb.apply(SPECIES.length());
1760 float[] c = fc.apply(SPECIES.length());
1761 float[] r = fr.apply(SPECIES.length());
1762 boolean[] mask = fm.apply(SPECIES.length());
1763 Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
1764
1765 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1766 for (int i = 0; i < a.length; i += SPECIES.length()) {
1767 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1768 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1769 FloatVector cv = FloatVector.fromArray(SPECIES, c, i);
1770 av.fma(bv, cv, vmask).intoArray(r, i);
1771 }
1772 }
1773
1774 assertArraysEquals(a, b, c, r, mask, FloatMaxVectorTests::fma);
1775 }
1776
1777
1778 static float neg(float a) {
1779 return (float)(-((float)a));
1780 }
1781
1782 @Test(dataProvider = "floatUnaryOpProvider")
1783 static void negFloatMaxVectorTests(IntFunction<float[]> fa) {
1784 float[] a = fa.apply(SPECIES.length());
1785 float[] r = fr.apply(SPECIES.length());
1786
1787 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1788 for (int i = 0; i < a.length; i += SPECIES.length()) {
1789 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1790 av.neg().intoArray(r, i);
1791 }
1792 }
1793
1794 assertArraysEquals(a, r, FloatMaxVectorTests::neg);
1795 }
1796
1797 @Test(dataProvider = "floatUnaryOpMaskProvider")
1798 static void negMaskedFloatMaxVectorTests(IntFunction<float[]> fa,
1799 IntFunction<boolean[]> fm) {
1800 float[] a = fa.apply(SPECIES.length());
1801 float[] r = fr.apply(SPECIES.length());
1802 boolean[] mask = fm.apply(SPECIES.length());
1803 Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
1804
1805 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1806 for (int i = 0; i < a.length; i += SPECIES.length()) {
1807 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1808 av.neg(vmask).intoArray(r, i);
1809 }
1810 }
1811
1812 assertArraysEquals(a, r, mask, FloatMaxVectorTests::neg);
1813 }
1814
1815 static float abs(float a) {
1816 return (float)(Math.abs((float)a));
1817 }
1818
1819 @Test(dataProvider = "floatUnaryOpProvider")
1820 static void absFloatMaxVectorTests(IntFunction<float[]> fa) {
1821 float[] a = fa.apply(SPECIES.length());
1822 float[] r = fr.apply(SPECIES.length());
1823
1824 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1825 for (int i = 0; i < a.length; i += SPECIES.length()) {
1826 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1827 av.abs().intoArray(r, i);
1828 }
1829 }
1830
1831 assertArraysEquals(a, r, FloatMaxVectorTests::abs);
1832 }
1833
1834 @Test(dataProvider = "floatUnaryOpMaskProvider")
1835 static void absMaskedFloatMaxVectorTests(IntFunction<float[]> fa,
1836 IntFunction<boolean[]> fm) {
1837 float[] a = fa.apply(SPECIES.length());
1838 float[] r = fr.apply(SPECIES.length());
1839 boolean[] mask = fm.apply(SPECIES.length());
1840 Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
1841
1842 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1843 for (int i = 0; i < a.length; i += SPECIES.length()) {
1844 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1845 av.abs(vmask).intoArray(r, i);
1846 }
1847 }
1848
1849 assertArraysEquals(a, r, mask, FloatMaxVectorTests::abs);
1850 }
1851
1852
1853
1854
1855
1856 static float sqrt(float a) {
1857 return (float)(Math.sqrt((double)a));
1858 }
1859
1860
1865 float[] r = fr.apply(SPECIES.length());
1866
1867 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1868 for (int i = 0; i < a.length; i += SPECIES.length()) {
1869 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1870 av.sqrt().intoArray(r, i);
1871 }
1872 }
1873
1874 assertArraysEquals(a, r, FloatMaxVectorTests::sqrt);
1875 }
1876
1877
1878
1879 @Test(dataProvider = "floatUnaryOpMaskProvider")
1880 static void sqrtMaskedFloatMaxVectorTests(IntFunction<float[]> fa,
1881 IntFunction<boolean[]> fm) {
1882 float[] a = fa.apply(SPECIES.length());
1883 float[] r = fr.apply(SPECIES.length());
1884 boolean[] mask = fm.apply(SPECIES.length());
1885 Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
1886
1887 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1888 for (int i = 0; i < a.length; i += SPECIES.length()) {
1889 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1890 av.sqrt(vmask).intoArray(r, i);
1891 }
1892 }
1893
1894 assertArraysEquals(a, r, mask, FloatMaxVectorTests::sqrt);
1895 }
1896
1897
1898 static float[] gather(float a[], int ix, int[] b, int iy) {
1899 float[] res = new float[SPECIES.length()];
1900 for (int i = 0; i < SPECIES.length(); i++) {
1901 int bi = iy + i;
1902 res[i] = a[b[bi] + ix];
1903 }
1904 return res;
1905 }
|
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 FloatMaxVectorTests
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.FloatVector;
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 FloatMaxVectorTests extends AbstractVectorTest {
52
53 static final VectorSpecies<Float> SPECIES =
54 FloatVector.SPECIES_MAX;
55
56 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
57
58 static VectorShape getMaxBit() {
59 return VectorShape.S_Max_BIT;
60 }
61
62 interface FUnOp {
63 float apply(float a);
64 }
65
66 static void assertArraysEquals(float[] a, float[] r, FUnOp f) {
67 int i = 0;
68 try {
69 for (; i < a.length; i++) {
70 Assert.assertEquals(r[i], f.apply(a[i]));
71 }
72 } catch (AssertionError e) {
73 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
74 }
75 }
76
77 static void assertArraysEquals(float[] a, float[] r, boolean[] mask, FUnOp f) {
78 int i = 0;
79 try {
551 float[] r = fr.apply(SPECIES.length());
552
553 for (int ic = 0; ic < INVOC_COUNT; ic++) {
554 for (int i = 0; i < a.length; i += SPECIES.length()) {
555 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
556 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
557 av.add(bv).intoArray(r, i);
558 }
559 }
560
561 assertArraysEquals(a, b, r, FloatMaxVectorTests::add);
562 }
563
564 @Test(dataProvider = "floatBinaryOpMaskProvider")
565 static void addFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
566 IntFunction<boolean[]> fm) {
567 float[] a = fa.apply(SPECIES.length());
568 float[] b = fb.apply(SPECIES.length());
569 float[] r = fr.apply(SPECIES.length());
570 boolean[] mask = fm.apply(SPECIES.length());
571 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
572
573 for (int ic = 0; ic < INVOC_COUNT; ic++) {
574 for (int i = 0; i < a.length; i += SPECIES.length()) {
575 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
576 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
577 av.add(bv, vmask).intoArray(r, i);
578 }
579 }
580
581 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::add);
582 }
583 static float sub(float a, float b) {
584 return (float)(a - b);
585 }
586
587 @Test(dataProvider = "floatBinaryOpProvider")
588 static void subFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
589 float[] a = fa.apply(SPECIES.length());
590 float[] b = fb.apply(SPECIES.length());
591 float[] r = fr.apply(SPECIES.length());
592
593 for (int ic = 0; ic < INVOC_COUNT; ic++) {
594 for (int i = 0; i < a.length; i += SPECIES.length()) {
595 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
596 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
597 av.sub(bv).intoArray(r, i);
598 }
599 }
600
601 assertArraysEquals(a, b, r, FloatMaxVectorTests::sub);
602 }
603
604 @Test(dataProvider = "floatBinaryOpMaskProvider")
605 static void subFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
606 IntFunction<boolean[]> fm) {
607 float[] a = fa.apply(SPECIES.length());
608 float[] b = fb.apply(SPECIES.length());
609 float[] r = fr.apply(SPECIES.length());
610 boolean[] mask = fm.apply(SPECIES.length());
611 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
612
613 for (int ic = 0; ic < INVOC_COUNT; ic++) {
614 for (int i = 0; i < a.length; i += SPECIES.length()) {
615 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
616 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
617 av.sub(bv, vmask).intoArray(r, i);
618 }
619 }
620
621 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::sub);
622 }
623
624 static float div(float a, float b) {
625 return (float)(a / b);
626 }
627
628 @Test(dataProvider = "floatBinaryOpProvider")
629 static void divFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
630 float[] a = fa.apply(SPECIES.length());
631 float[] b = fb.apply(SPECIES.length());
634 for (int ic = 0; ic < INVOC_COUNT; ic++) {
635 for (int i = 0; i < a.length; i += SPECIES.length()) {
636 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
637 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
638 av.div(bv).intoArray(r, i);
639 }
640 }
641
642 assertArraysEquals(a, b, r, FloatMaxVectorTests::div);
643 }
644
645
646
647 @Test(dataProvider = "floatBinaryOpMaskProvider")
648 static void divFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
649 IntFunction<boolean[]> fm) {
650 float[] a = fa.apply(SPECIES.length());
651 float[] b = fb.apply(SPECIES.length());
652 float[] r = fr.apply(SPECIES.length());
653 boolean[] mask = fm.apply(SPECIES.length());
654 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
655
656 for (int ic = 0; ic < INVOC_COUNT; ic++) {
657 for (int i = 0; i < a.length; i += SPECIES.length()) {
658 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
659 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
660 av.div(bv, vmask).intoArray(r, i);
661 }
662 }
663
664 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::div);
665 }
666
667 static float mul(float a, float b) {
668 return (float)(a * b);
669 }
670
671 @Test(dataProvider = "floatBinaryOpProvider")
672 static void mulFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
673 float[] a = fa.apply(SPECIES.length());
674 float[] b = fb.apply(SPECIES.length());
675 float[] r = fr.apply(SPECIES.length());
676
677 for (int ic = 0; ic < INVOC_COUNT; ic++) {
678 for (int i = 0; i < a.length; i += SPECIES.length()) {
679 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
680 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
681 av.mul(bv).intoArray(r, i);
682 }
683 }
684
685 assertArraysEquals(a, b, r, FloatMaxVectorTests::mul);
686 }
687
688 @Test(dataProvider = "floatBinaryOpMaskProvider")
689 static void mulFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
690 IntFunction<boolean[]> fm) {
691 float[] a = fa.apply(SPECIES.length());
692 float[] b = fb.apply(SPECIES.length());
693 float[] r = fr.apply(SPECIES.length());
694 boolean[] mask = fm.apply(SPECIES.length());
695 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
696
697 for (int ic = 0; ic < INVOC_COUNT; ic++) {
698 for (int i = 0; i < a.length; i += SPECIES.length()) {
699 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
700 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
701 av.mul(bv, vmask).intoArray(r, i);
702 }
703 }
704
705 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::mul);
706 }
707
708
709
710
711
712
713
714
715
960
961 for (int ic = 0; ic < INVOC_COUNT; ic++) {
962 for (int i = 0; i < a.length; i += SPECIES.length()) {
963 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
964 av.with(0, (float)4).intoArray(r, i);
965 }
966 }
967
968 assertInsertArraysEquals(a, r, (float)4, 0);
969 }
970
971 @Test(dataProvider = "floatCompareOpProvider")
972 static void lessThanFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
973 float[] a = fa.apply(SPECIES.length());
974 float[] b = fb.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 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
979 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
980 VectorMask<Float> mv = av.lessThan(bv);
981
982 // Check results as part of computation.
983 for (int j = 0; j < SPECIES.length(); j++) {
984 Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]);
985 }
986 }
987 }
988 }
989
990
991 @Test(dataProvider = "floatCompareOpProvider")
992 static void greaterThanFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
993 float[] a = fa.apply(SPECIES.length());
994 float[] b = fb.apply(SPECIES.length());
995
996 for (int ic = 0; ic < INVOC_COUNT; ic++) {
997 for (int i = 0; i < a.length; i += SPECIES.length()) {
998 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
999 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1000 VectorMask<Float> mv = av.greaterThan(bv);
1001
1002 // Check results as part of computation.
1003 for (int j = 0; j < SPECIES.length(); j++) {
1004 Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]);
1005 }
1006 }
1007 }
1008 }
1009
1010
1011 @Test(dataProvider = "floatCompareOpProvider")
1012 static void equalFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1013 float[] a = fa.apply(SPECIES.length());
1014 float[] b = fb.apply(SPECIES.length());
1015
1016 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1017 for (int i = 0; i < a.length; i += SPECIES.length()) {
1018 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1019 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1020 VectorMask<Float> mv = av.equal(bv);
1021
1022 // Check results as part of computation.
1023 for (int j = 0; j < SPECIES.length(); j++) {
1024 Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]);
1025 }
1026 }
1027 }
1028 }
1029
1030
1031 @Test(dataProvider = "floatCompareOpProvider")
1032 static void notEqualFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1033 float[] a = fa.apply(SPECIES.length());
1034 float[] b = fb.apply(SPECIES.length());
1035
1036 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1037 for (int i = 0; i < a.length; i += SPECIES.length()) {
1038 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1039 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1040 VectorMask<Float> mv = av.notEqual(bv);
1041
1042 // Check results as part of computation.
1043 for (int j = 0; j < SPECIES.length(); j++) {
1044 Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]);
1045 }
1046 }
1047 }
1048 }
1049
1050
1051 @Test(dataProvider = "floatCompareOpProvider")
1052 static void lessThanEqFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1053 float[] a = fa.apply(SPECIES.length());
1054 float[] b = fb.apply(SPECIES.length());
1055
1056 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1057 for (int i = 0; i < a.length; i += SPECIES.length()) {
1058 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1059 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1060 VectorMask<Float> mv = av.lessThanEq(bv);
1061
1062 // Check results as part of computation.
1063 for (int j = 0; j < SPECIES.length(); j++) {
1064 Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]);
1065 }
1066 }
1067 }
1068 }
1069
1070
1071 @Test(dataProvider = "floatCompareOpProvider")
1072 static void greaterThanEqFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1073 float[] a = fa.apply(SPECIES.length());
1074 float[] b = fb.apply(SPECIES.length());
1075
1076 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1077 for (int i = 0; i < a.length; i += SPECIES.length()) {
1078 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1079 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1080 VectorMask<Float> mv = av.greaterThanEq(bv);
1081
1082 // Check results as part of computation.
1083 for (int j = 0; j < SPECIES.length(); j++) {
1084 Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]);
1085 }
1086 }
1087 }
1088 }
1089
1090
1091 static float blend(float a, float b, boolean mask) {
1092 return mask ? b : a;
1093 }
1094
1095 @Test(dataProvider = "floatBinaryOpMaskProvider")
1096 static void blendFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
1097 IntFunction<boolean[]> fm) {
1098 float[] a = fa.apply(SPECIES.length());
1099 float[] b = fb.apply(SPECIES.length());
1100 float[] r = fr.apply(SPECIES.length());
1101 boolean[] mask = fm.apply(SPECIES.length());
1102 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
1103
1104 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1105 for (int i = 0; i < a.length; i += SPECIES.length()) {
1106 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1107 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1108 av.blend(bv, vmask).intoArray(r, i);
1109 }
1110 }
1111
1112 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::blend);
1113 }
1114
1115 @Test(dataProvider = "floatUnaryOpShuffleProvider")
1116 static void RearrangeFloatMaxVectorTests(IntFunction<float[]> fa,
1117 BiFunction<Integer,Integer,int[]> fs) {
1118 float[] a = fa.apply(SPECIES.length());
1119 int[] order = fs.apply(a.length, SPECIES.length());
1120 float[] r = fr.apply(SPECIES.length());
1121
1122 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1123 for (int i = 0; i < a.length; i += SPECIES.length()) {
1124 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1125 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
1126 }
1127 }
1128
1129 assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1130 }
1131
1132
1133
1134
1135 @Test(dataProvider = "floatUnaryOpProvider")
1136 static void getFloatMaxVectorTests(IntFunction<float[]> fa) {
1137 float[] a = fa.apply(SPECIES.length());
1138 float[] r = fr.apply(SPECIES.length());
1139
1140 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1141 for (int i = 0; i < a.length; i += SPECIES.length()) {
1142 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1143 int num_lanes = SPECIES.length();
1144 // Manually unroll because full unroll happens after intrinsification.
1145 // Unroll is needed because get intrinsic requires for index to be a known constant.
1745 for (int i = 0; i < a.length; i += SPECIES.length()) {
1746 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1747 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1748 FloatVector cv = FloatVector.fromArray(SPECIES, c, i);
1749 av.fma(bv, cv).intoArray(r, i);
1750 }
1751 }
1752
1753 assertArraysEquals(a, b, c, r, FloatMaxVectorTests::fma);
1754 }
1755
1756
1757 @Test(dataProvider = "floatTernaryOpMaskProvider")
1758 static void fmaFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
1759 IntFunction<float[]> fc, IntFunction<boolean[]> fm) {
1760 float[] a = fa.apply(SPECIES.length());
1761 float[] b = fb.apply(SPECIES.length());
1762 float[] c = fc.apply(SPECIES.length());
1763 float[] r = fr.apply(SPECIES.length());
1764 boolean[] mask = fm.apply(SPECIES.length());
1765 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
1766
1767 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1768 for (int i = 0; i < a.length; i += SPECIES.length()) {
1769 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1770 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1771 FloatVector cv = FloatVector.fromArray(SPECIES, c, i);
1772 av.fma(bv, cv, vmask).intoArray(r, i);
1773 }
1774 }
1775
1776 assertArraysEquals(a, b, c, r, mask, FloatMaxVectorTests::fma);
1777 }
1778
1779
1780 static float neg(float a) {
1781 return (float)(-((float)a));
1782 }
1783
1784 @Test(dataProvider = "floatUnaryOpProvider")
1785 static void negFloatMaxVectorTests(IntFunction<float[]> fa) {
1786 float[] a = fa.apply(SPECIES.length());
1787 float[] r = fr.apply(SPECIES.length());
1788
1789 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1790 for (int i = 0; i < a.length; i += SPECIES.length()) {
1791 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1792 av.neg().intoArray(r, i);
1793 }
1794 }
1795
1796 assertArraysEquals(a, r, FloatMaxVectorTests::neg);
1797 }
1798
1799 @Test(dataProvider = "floatUnaryOpMaskProvider")
1800 static void negMaskedFloatMaxVectorTests(IntFunction<float[]> fa,
1801 IntFunction<boolean[]> fm) {
1802 float[] a = fa.apply(SPECIES.length());
1803 float[] r = fr.apply(SPECIES.length());
1804 boolean[] mask = fm.apply(SPECIES.length());
1805 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
1806
1807 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1808 for (int i = 0; i < a.length; i += SPECIES.length()) {
1809 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1810 av.neg(vmask).intoArray(r, i);
1811 }
1812 }
1813
1814 assertArraysEquals(a, r, mask, FloatMaxVectorTests::neg);
1815 }
1816
1817 static float abs(float a) {
1818 return (float)(Math.abs((float)a));
1819 }
1820
1821 @Test(dataProvider = "floatUnaryOpProvider")
1822 static void absFloatMaxVectorTests(IntFunction<float[]> fa) {
1823 float[] a = fa.apply(SPECIES.length());
1824 float[] r = fr.apply(SPECIES.length());
1825
1826 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1827 for (int i = 0; i < a.length; i += SPECIES.length()) {
1828 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1829 av.abs().intoArray(r, i);
1830 }
1831 }
1832
1833 assertArraysEquals(a, r, FloatMaxVectorTests::abs);
1834 }
1835
1836 @Test(dataProvider = "floatUnaryOpMaskProvider")
1837 static void absMaskedFloatMaxVectorTests(IntFunction<float[]> fa,
1838 IntFunction<boolean[]> fm) {
1839 float[] a = fa.apply(SPECIES.length());
1840 float[] r = fr.apply(SPECIES.length());
1841 boolean[] mask = fm.apply(SPECIES.length());
1842 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
1843
1844 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1845 for (int i = 0; i < a.length; i += SPECIES.length()) {
1846 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1847 av.abs(vmask).intoArray(r, i);
1848 }
1849 }
1850
1851 assertArraysEquals(a, r, mask, FloatMaxVectorTests::abs);
1852 }
1853
1854
1855
1856
1857
1858 static float sqrt(float a) {
1859 return (float)(Math.sqrt((double)a));
1860 }
1861
1862
1867 float[] r = fr.apply(SPECIES.length());
1868
1869 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1870 for (int i = 0; i < a.length; i += SPECIES.length()) {
1871 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1872 av.sqrt().intoArray(r, i);
1873 }
1874 }
1875
1876 assertArraysEquals(a, r, FloatMaxVectorTests::sqrt);
1877 }
1878
1879
1880
1881 @Test(dataProvider = "floatUnaryOpMaskProvider")
1882 static void sqrtMaskedFloatMaxVectorTests(IntFunction<float[]> fa,
1883 IntFunction<boolean[]> fm) {
1884 float[] a = fa.apply(SPECIES.length());
1885 float[] r = fr.apply(SPECIES.length());
1886 boolean[] mask = fm.apply(SPECIES.length());
1887 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
1888
1889 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1890 for (int i = 0; i < a.length; i += SPECIES.length()) {
1891 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1892 av.sqrt(vmask).intoArray(r, i);
1893 }
1894 }
1895
1896 assertArraysEquals(a, r, mask, FloatMaxVectorTests::sqrt);
1897 }
1898
1899
1900 static float[] gather(float a[], int ix, int[] b, int iy) {
1901 float[] res = new float[SPECIES.length()];
1902 for (int i = 0; i < SPECIES.length(); i++) {
1903 int bi = iy + i;
1904 res[i] = a[b[bi] + ix];
1905 }
1906 return res;
1907 }
|