< prev index next >

test/jdk/jdk/incubator/vector/Float128VectorTests.java

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


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @modules jdk.incubator.vector
  27  * @run testng/othervm -ea -esa Float128VectorTests
  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 Float128VectorTests extends AbstractVectorTest {
  50 
  51     static final Species<Float> SPECIES =
  52                 FloatVector.SPECIES_128;
  53 
  54     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  55 
  56     interface FUnOp {
  57         float apply(float a);
  58     }
  59 
  60     static void assertArraysEquals(float[] a, float[] r, FUnOp f) {
  61         int i = 0;
  62         try {
  63             for (; i < a.length; i++) {
  64                 Assert.assertEquals(r[i], f.apply(a[i]));
  65             }
  66         } catch (AssertionError e) {
  67             Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
  68         }
  69     }
  70 
  71     static void assertArraysEquals(float[] a, float[] r, boolean[] mask, FUnOp f) {


 545         float[] r = fr.apply(SPECIES.length());
 546 
 547         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 548             for (int i = 0; i < a.length; i += SPECIES.length()) {
 549                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 550                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 551                 av.add(bv).intoArray(r, i);
 552             }
 553         }
 554 
 555         assertArraysEquals(a, b, r, Float128VectorTests::add);
 556     }
 557 
 558     @Test(dataProvider = "floatBinaryOpMaskProvider")
 559     static void addFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
 560                                           IntFunction<boolean[]> fm) {
 561         float[] a = fa.apply(SPECIES.length());
 562         float[] b = fb.apply(SPECIES.length());
 563         float[] r = fr.apply(SPECIES.length());
 564         boolean[] mask = fm.apply(SPECIES.length());
 565         Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
 566 
 567         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 568             for (int i = 0; i < a.length; i += SPECIES.length()) {
 569                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 570                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 571                 av.add(bv, vmask).intoArray(r, i);
 572             }
 573         }
 574 
 575         assertArraysEquals(a, b, r, mask, Float128VectorTests::add);
 576     }
 577     static float sub(float a, float b) {
 578         return (float)(a - b);
 579     }
 580 
 581     @Test(dataProvider = "floatBinaryOpProvider")
 582     static void subFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
 583         float[] a = fa.apply(SPECIES.length());
 584         float[] b = fb.apply(SPECIES.length());
 585         float[] r = fr.apply(SPECIES.length());
 586 
 587         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 588             for (int i = 0; i < a.length; i += SPECIES.length()) {
 589                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 590                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 591                 av.sub(bv).intoArray(r, i);
 592             }
 593         }
 594 
 595         assertArraysEquals(a, b, r, Float128VectorTests::sub);
 596     }
 597 
 598     @Test(dataProvider = "floatBinaryOpMaskProvider")
 599     static void subFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
 600                                           IntFunction<boolean[]> fm) {
 601         float[] a = fa.apply(SPECIES.length());
 602         float[] b = fb.apply(SPECIES.length());
 603         float[] r = fr.apply(SPECIES.length());
 604         boolean[] mask = fm.apply(SPECIES.length());
 605         Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
 606 
 607         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 608             for (int i = 0; i < a.length; i += SPECIES.length()) {
 609                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 610                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 611                 av.sub(bv, vmask).intoArray(r, i);
 612             }
 613         }
 614 
 615         assertArraysEquals(a, b, r, mask, Float128VectorTests::sub);
 616     }
 617 
 618     static float div(float a, float b) {
 619         return (float)(a / b);
 620     }
 621 
 622     @Test(dataProvider = "floatBinaryOpProvider")
 623     static void divFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
 624         float[] a = fa.apply(SPECIES.length());
 625         float[] b = fb.apply(SPECIES.length());


 628         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 629             for (int i = 0; i < a.length; i += SPECIES.length()) {
 630                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 631                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 632                 av.div(bv).intoArray(r, i);
 633             }
 634         }
 635 
 636         assertArraysEquals(a, b, r, Float128VectorTests::div);
 637     }
 638 
 639 
 640 
 641     @Test(dataProvider = "floatBinaryOpMaskProvider")
 642     static void divFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
 643                                           IntFunction<boolean[]> fm) {
 644         float[] a = fa.apply(SPECIES.length());
 645         float[] b = fb.apply(SPECIES.length());
 646         float[] r = fr.apply(SPECIES.length());
 647         boolean[] mask = fm.apply(SPECIES.length());
 648         Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
 649 
 650         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 651             for (int i = 0; i < a.length; i += SPECIES.length()) {
 652                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 653                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 654                 av.div(bv, vmask).intoArray(r, i);
 655             }
 656         }
 657 
 658         assertArraysEquals(a, b, r, mask, Float128VectorTests::div);
 659     }
 660 
 661     static float mul(float a, float b) {
 662         return (float)(a * b);
 663     }
 664 
 665     @Test(dataProvider = "floatBinaryOpProvider")
 666     static void mulFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
 667         float[] a = fa.apply(SPECIES.length());
 668         float[] b = fb.apply(SPECIES.length());
 669         float[] r = fr.apply(SPECIES.length());
 670 
 671         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 672             for (int i = 0; i < a.length; i += SPECIES.length()) {
 673                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 674                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 675                 av.mul(bv).intoArray(r, i);
 676             }
 677         }
 678 
 679         assertArraysEquals(a, b, r, Float128VectorTests::mul);
 680     }
 681 
 682     @Test(dataProvider = "floatBinaryOpMaskProvider")
 683     static void mulFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
 684                                           IntFunction<boolean[]> fm) {
 685         float[] a = fa.apply(SPECIES.length());
 686         float[] b = fb.apply(SPECIES.length());
 687         float[] r = fr.apply(SPECIES.length());
 688         boolean[] mask = fm.apply(SPECIES.length());
 689         Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
 690 
 691         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 692             for (int i = 0; i < a.length; i += SPECIES.length()) {
 693                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 694                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 695                 av.mul(bv, vmask).intoArray(r, i);
 696             }
 697         }
 698 
 699         assertArraysEquals(a, b, r, mask, Float128VectorTests::mul);
 700     }
 701 
 702 
 703 
 704 
 705 
 706 
 707 
 708 
 709 


 954 
 955         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 956             for (int i = 0; i < a.length; i += SPECIES.length()) {
 957                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 958                 av.with(0, (float)4).intoArray(r, i);
 959             }
 960         }
 961 
 962         assertInsertArraysEquals(a, r, (float)4, 0);
 963     }
 964 
 965     @Test(dataProvider = "floatCompareOpProvider")
 966     static void lessThanFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
 967         float[] a = fa.apply(SPECIES.length());
 968         float[] b = fb.apply(SPECIES.length());
 969 
 970         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 971             for (int i = 0; i < a.length; i += SPECIES.length()) {
 972                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 973                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 974                 Vector.Mask<Float> mv = av.lessThan(bv);
 975 
 976                 // Check results as part of computation.
 977                 for (int j = 0; j < SPECIES.length(); j++) {
 978                     Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]);
 979                 }
 980             }
 981         }
 982     }
 983 
 984 
 985     @Test(dataProvider = "floatCompareOpProvider")
 986     static void greaterThanFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
 987         float[] a = fa.apply(SPECIES.length());
 988         float[] b = fb.apply(SPECIES.length());
 989 
 990         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 991             for (int i = 0; i < a.length; i += SPECIES.length()) {
 992                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 993                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 994                 Vector.Mask<Float> mv = av.greaterThan(bv);
 995 
 996                 // Check results as part of computation.
 997                 for (int j = 0; j < SPECIES.length(); j++) {
 998                     Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]);
 999                 }
1000             }
1001         }
1002     }
1003 
1004 
1005     @Test(dataProvider = "floatCompareOpProvider")
1006     static void equalFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1007         float[] a = fa.apply(SPECIES.length());
1008         float[] b = fb.apply(SPECIES.length());
1009 
1010         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1011             for (int i = 0; i < a.length; i += SPECIES.length()) {
1012                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1013                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1014                 Vector.Mask<Float> mv = av.equal(bv);
1015 
1016                 // Check results as part of computation.
1017                 for (int j = 0; j < SPECIES.length(); j++) {
1018                     Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]);
1019                 }
1020             }
1021         }
1022     }
1023 
1024 
1025     @Test(dataProvider = "floatCompareOpProvider")
1026     static void notEqualFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1027         float[] a = fa.apply(SPECIES.length());
1028         float[] b = fb.apply(SPECIES.length());
1029 
1030         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1031             for (int i = 0; i < a.length; i += SPECIES.length()) {
1032                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1033                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1034                 Vector.Mask<Float> mv = av.notEqual(bv);
1035 
1036                 // Check results as part of computation.
1037                 for (int j = 0; j < SPECIES.length(); j++) {
1038                     Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]);
1039                 }
1040             }
1041         }
1042     }
1043 
1044 
1045     @Test(dataProvider = "floatCompareOpProvider")
1046     static void lessThanEqFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1047         float[] a = fa.apply(SPECIES.length());
1048         float[] b = fb.apply(SPECIES.length());
1049 
1050         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1051             for (int i = 0; i < a.length; i += SPECIES.length()) {
1052                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1053                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1054                 Vector.Mask<Float> mv = av.lessThanEq(bv);
1055 
1056                 // Check results as part of computation.
1057                 for (int j = 0; j < SPECIES.length(); j++) {
1058                     Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]);
1059                 }
1060             }
1061         }
1062     }
1063 
1064 
1065     @Test(dataProvider = "floatCompareOpProvider")
1066     static void greaterThanEqFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1067         float[] a = fa.apply(SPECIES.length());
1068         float[] b = fb.apply(SPECIES.length());
1069 
1070         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1071             for (int i = 0; i < a.length; i += SPECIES.length()) {
1072                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1073                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1074                 Vector.Mask<Float> mv = av.greaterThanEq(bv);
1075 
1076                 // Check results as part of computation.
1077                 for (int j = 0; j < SPECIES.length(); j++) {
1078                     Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]);
1079                 }
1080             }
1081         }
1082     }
1083 
1084 
1085     static float blend(float a, float b, boolean mask) {
1086         return mask ? b : a;
1087     }
1088 
1089     @Test(dataProvider = "floatBinaryOpMaskProvider")
1090     static void blendFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
1091                                           IntFunction<boolean[]> fm) {
1092         float[] a = fa.apply(SPECIES.length());
1093         float[] b = fb.apply(SPECIES.length());
1094         float[] r = fr.apply(SPECIES.length());
1095         boolean[] mask = fm.apply(SPECIES.length());
1096         Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
1097 
1098         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1099             for (int i = 0; i < a.length; i += SPECIES.length()) {
1100                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1101                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1102                 av.blend(bv, vmask).intoArray(r, i);
1103             }
1104         }
1105 
1106         assertArraysEquals(a, b, r, mask, Float128VectorTests::blend);
1107     }
1108 
1109     @Test(dataProvider = "floatUnaryOpShuffleProvider")
1110     static void RearrangeFloat128VectorTests(IntFunction<float[]> fa,
1111                                            BiFunction<Integer,Integer,int[]> fs) {
1112         float[] a = fa.apply(SPECIES.length());
1113         int[] order = fs.apply(a.length, SPECIES.length());
1114         float[] r = fr.apply(SPECIES.length());
1115 
1116         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1117             for (int i = 0; i < a.length; i += SPECIES.length()) {
1118                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1119                 av.rearrange(FloatVector.shuffleFromArray(SPECIES, order, i)).intoArray(r, i);
1120             }
1121         }
1122 
1123         assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1124     }
1125 
1126 
1127 
1128 
1129     @Test(dataProvider = "floatUnaryOpProvider")
1130     static void getFloat128VectorTests(IntFunction<float[]> fa) {
1131         float[] a = fa.apply(SPECIES.length());
1132         float[] r = fr.apply(SPECIES.length());
1133 
1134         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1135             for (int i = 0; i < a.length; i += SPECIES.length()) {
1136                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1137                 int num_lanes = SPECIES.length();
1138                 // Manually unroll because full unroll happens after intrinsification.
1139                 // Unroll is needed because get intrinsic requires for index to be a known constant.


1739             for (int i = 0; i < a.length; i += SPECIES.length()) {
1740                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1741                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1742                 FloatVector cv = FloatVector.fromArray(SPECIES, c, i);
1743                 av.fma(bv, cv).intoArray(r, i);
1744             }
1745         }
1746 
1747         assertArraysEquals(a, b, c, r, Float128VectorTests::fma);
1748     }
1749 
1750 
1751     @Test(dataProvider = "floatTernaryOpMaskProvider")
1752     static void fmaFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
1753                                           IntFunction<float[]> fc, IntFunction<boolean[]> fm) {
1754         float[] a = fa.apply(SPECIES.length());
1755         float[] b = fb.apply(SPECIES.length());
1756         float[] c = fc.apply(SPECIES.length());
1757         float[] r = fr.apply(SPECIES.length());
1758         boolean[] mask = fm.apply(SPECIES.length());
1759         Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
1760 
1761         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1762             for (int i = 0; i < a.length; i += SPECIES.length()) {
1763                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1764                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1765                 FloatVector cv = FloatVector.fromArray(SPECIES, c, i);
1766                 av.fma(bv, cv, vmask).intoArray(r, i);
1767             }
1768         }
1769 
1770         assertArraysEquals(a, b, c, r, mask, Float128VectorTests::fma);
1771     }
1772 
1773 
1774     static float neg(float a) {
1775         return (float)(-((float)a));
1776     }
1777 
1778     @Test(dataProvider = "floatUnaryOpProvider")
1779     static void negFloat128VectorTests(IntFunction<float[]> fa) {
1780         float[] a = fa.apply(SPECIES.length());
1781         float[] r = fr.apply(SPECIES.length());
1782 
1783         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1784             for (int i = 0; i < a.length; i += SPECIES.length()) {
1785                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1786                 av.neg().intoArray(r, i);
1787             }
1788         }
1789 
1790         assertArraysEquals(a, r, Float128VectorTests::neg);
1791     }
1792 
1793     @Test(dataProvider = "floatUnaryOpMaskProvider")
1794     static void negMaskedFloat128VectorTests(IntFunction<float[]> fa,
1795                                                 IntFunction<boolean[]> fm) {
1796         float[] a = fa.apply(SPECIES.length());
1797         float[] r = fr.apply(SPECIES.length());
1798         boolean[] mask = fm.apply(SPECIES.length());
1799         Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
1800 
1801         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1802             for (int i = 0; i < a.length; i += SPECIES.length()) {
1803                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1804                 av.neg(vmask).intoArray(r, i);
1805             }
1806         }
1807 
1808         assertArraysEquals(a, r, mask, Float128VectorTests::neg);
1809     }
1810 
1811     static float abs(float a) {
1812         return (float)(Math.abs((float)a));
1813     }
1814 
1815     @Test(dataProvider = "floatUnaryOpProvider")
1816     static void absFloat128VectorTests(IntFunction<float[]> fa) {
1817         float[] a = fa.apply(SPECIES.length());
1818         float[] r = fr.apply(SPECIES.length());
1819 
1820         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1821             for (int i = 0; i < a.length; i += SPECIES.length()) {
1822                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1823                 av.abs().intoArray(r, i);
1824             }
1825         }
1826 
1827         assertArraysEquals(a, r, Float128VectorTests::abs);
1828     }
1829 
1830     @Test(dataProvider = "floatUnaryOpMaskProvider")
1831     static void absMaskedFloat128VectorTests(IntFunction<float[]> fa,
1832                                                 IntFunction<boolean[]> fm) {
1833         float[] a = fa.apply(SPECIES.length());
1834         float[] r = fr.apply(SPECIES.length());
1835         boolean[] mask = fm.apply(SPECIES.length());
1836         Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
1837 
1838         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1839             for (int i = 0; i < a.length; i += SPECIES.length()) {
1840                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1841                 av.abs(vmask).intoArray(r, i);
1842             }
1843         }
1844 
1845         assertArraysEquals(a, r, mask, Float128VectorTests::abs);
1846     }
1847 
1848 
1849 
1850 
1851 
1852     static float sqrt(float a) {
1853         return (float)(Math.sqrt((double)a));
1854     }
1855 
1856 


1861         float[] r = fr.apply(SPECIES.length());
1862 
1863         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1864             for (int i = 0; i < a.length; i += SPECIES.length()) {
1865                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1866                 av.sqrt().intoArray(r, i);
1867             }
1868         }
1869 
1870         assertArraysEquals(a, r, Float128VectorTests::sqrt);
1871     }
1872 
1873 
1874 
1875     @Test(dataProvider = "floatUnaryOpMaskProvider")
1876     static void sqrtMaskedFloat128VectorTests(IntFunction<float[]> fa,
1877                                                 IntFunction<boolean[]> fm) {
1878         float[] a = fa.apply(SPECIES.length());
1879         float[] r = fr.apply(SPECIES.length());
1880         boolean[] mask = fm.apply(SPECIES.length());
1881         Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
1882 
1883         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1884             for (int i = 0; i < a.length; i += SPECIES.length()) {
1885                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1886                 av.sqrt(vmask).intoArray(r, i);
1887             }
1888         }
1889 
1890         assertArraysEquals(a, r, mask, Float128VectorTests::sqrt);
1891     }
1892 
1893 
1894     static float[] gather(float a[], int ix, int[] b, int iy) {
1895         float[] res = new float[SPECIES.length()];
1896         for (int i = 0; i < SPECIES.length(); i++) {
1897             int bi = iy + i;
1898             res[i] = a[b[bi] + ix];
1899         }
1900         return res;
1901     }




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


 547         float[] r = fr.apply(SPECIES.length());
 548 
 549         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 550             for (int i = 0; i < a.length; i += SPECIES.length()) {
 551                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 552                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 553                 av.add(bv).intoArray(r, i);
 554             }
 555         }
 556 
 557         assertArraysEquals(a, b, r, Float128VectorTests::add);
 558     }
 559 
 560     @Test(dataProvider = "floatBinaryOpMaskProvider")
 561     static void addFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
 562                                           IntFunction<boolean[]> fm) {
 563         float[] a = fa.apply(SPECIES.length());
 564         float[] b = fb.apply(SPECIES.length());
 565         float[] r = fr.apply(SPECIES.length());
 566         boolean[] mask = fm.apply(SPECIES.length());
 567         VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
 568 
 569         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 570             for (int i = 0; i < a.length; i += SPECIES.length()) {
 571                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 572                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 573                 av.add(bv, vmask).intoArray(r, i);
 574             }
 575         }
 576 
 577         assertArraysEquals(a, b, r, mask, Float128VectorTests::add);
 578     }
 579     static float sub(float a, float b) {
 580         return (float)(a - b);
 581     }
 582 
 583     @Test(dataProvider = "floatBinaryOpProvider")
 584     static void subFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
 585         float[] a = fa.apply(SPECIES.length());
 586         float[] b = fb.apply(SPECIES.length());
 587         float[] r = fr.apply(SPECIES.length());
 588 
 589         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 590             for (int i = 0; i < a.length; i += SPECIES.length()) {
 591                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 592                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 593                 av.sub(bv).intoArray(r, i);
 594             }
 595         }
 596 
 597         assertArraysEquals(a, b, r, Float128VectorTests::sub);
 598     }
 599 
 600     @Test(dataProvider = "floatBinaryOpMaskProvider")
 601     static void subFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
 602                                           IntFunction<boolean[]> fm) {
 603         float[] a = fa.apply(SPECIES.length());
 604         float[] b = fb.apply(SPECIES.length());
 605         float[] r = fr.apply(SPECIES.length());
 606         boolean[] mask = fm.apply(SPECIES.length());
 607         VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
 608 
 609         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 610             for (int i = 0; i < a.length; i += SPECIES.length()) {
 611                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 612                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 613                 av.sub(bv, vmask).intoArray(r, i);
 614             }
 615         }
 616 
 617         assertArraysEquals(a, b, r, mask, Float128VectorTests::sub);
 618     }
 619 
 620     static float div(float a, float b) {
 621         return (float)(a / b);
 622     }
 623 
 624     @Test(dataProvider = "floatBinaryOpProvider")
 625     static void divFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
 626         float[] a = fa.apply(SPECIES.length());
 627         float[] b = fb.apply(SPECIES.length());


 630         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 631             for (int i = 0; i < a.length; i += SPECIES.length()) {
 632                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 633                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 634                 av.div(bv).intoArray(r, i);
 635             }
 636         }
 637 
 638         assertArraysEquals(a, b, r, Float128VectorTests::div);
 639     }
 640 
 641 
 642 
 643     @Test(dataProvider = "floatBinaryOpMaskProvider")
 644     static void divFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
 645                                           IntFunction<boolean[]> fm) {
 646         float[] a = fa.apply(SPECIES.length());
 647         float[] b = fb.apply(SPECIES.length());
 648         float[] r = fr.apply(SPECIES.length());
 649         boolean[] mask = fm.apply(SPECIES.length());
 650         VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
 651 
 652         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 653             for (int i = 0; i < a.length; i += SPECIES.length()) {
 654                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 655                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 656                 av.div(bv, vmask).intoArray(r, i);
 657             }
 658         }
 659 
 660         assertArraysEquals(a, b, r, mask, Float128VectorTests::div);
 661     }
 662 
 663     static float mul(float a, float b) {
 664         return (float)(a * b);
 665     }
 666 
 667     @Test(dataProvider = "floatBinaryOpProvider")
 668     static void mulFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
 669         float[] a = fa.apply(SPECIES.length());
 670         float[] b = fb.apply(SPECIES.length());
 671         float[] r = fr.apply(SPECIES.length());
 672 
 673         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 674             for (int i = 0; i < a.length; i += SPECIES.length()) {
 675                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 676                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 677                 av.mul(bv).intoArray(r, i);
 678             }
 679         }
 680 
 681         assertArraysEquals(a, b, r, Float128VectorTests::mul);
 682     }
 683 
 684     @Test(dataProvider = "floatBinaryOpMaskProvider")
 685     static void mulFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
 686                                           IntFunction<boolean[]> fm) {
 687         float[] a = fa.apply(SPECIES.length());
 688         float[] b = fb.apply(SPECIES.length());
 689         float[] r = fr.apply(SPECIES.length());
 690         boolean[] mask = fm.apply(SPECIES.length());
 691         VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
 692 
 693         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 694             for (int i = 0; i < a.length; i += SPECIES.length()) {
 695                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 696                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 697                 av.mul(bv, vmask).intoArray(r, i);
 698             }
 699         }
 700 
 701         assertArraysEquals(a, b, r, mask, Float128VectorTests::mul);
 702     }
 703 
 704 
 705 
 706 
 707 
 708 
 709 
 710 
 711 


 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     }
 966 
 967     @Test(dataProvider = "floatCompareOpProvider")
 968     static void lessThanFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
 969         float[] a = fa.apply(SPECIES.length());
 970         float[] b = fb.apply(SPECIES.length());
 971 
 972         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 973             for (int i = 0; i < a.length; i += SPECIES.length()) {
 974                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 975                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 976                 VectorMask<Float> mv = av.lessThan(bv);
 977 
 978                 // Check results as part of computation.
 979                 for (int j = 0; j < SPECIES.length(); j++) {
 980                     Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]);
 981                 }
 982             }
 983         }
 984     }
 985 
 986 
 987     @Test(dataProvider = "floatCompareOpProvider")
 988     static void greaterThanFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
 989         float[] a = fa.apply(SPECIES.length());
 990         float[] b = fb.apply(SPECIES.length());
 991 
 992         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 993             for (int i = 0; i < a.length; i += SPECIES.length()) {
 994                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 995                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 996                 VectorMask<Float> mv = av.greaterThan(bv);
 997 
 998                 // Check results as part of computation.
 999                 for (int j = 0; j < SPECIES.length(); j++) {
1000                     Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]);
1001                 }
1002             }
1003         }
1004     }
1005 
1006 
1007     @Test(dataProvider = "floatCompareOpProvider")
1008     static void equalFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1009         float[] a = fa.apply(SPECIES.length());
1010         float[] b = fb.apply(SPECIES.length());
1011 
1012         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1013             for (int i = 0; i < a.length; i += SPECIES.length()) {
1014                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1015                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1016                 VectorMask<Float> mv = av.equal(bv);
1017 
1018                 // Check results as part of computation.
1019                 for (int j = 0; j < SPECIES.length(); j++) {
1020                     Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]);
1021                 }
1022             }
1023         }
1024     }
1025 
1026 
1027     @Test(dataProvider = "floatCompareOpProvider")
1028     static void notEqualFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1029         float[] a = fa.apply(SPECIES.length());
1030         float[] b = fb.apply(SPECIES.length());
1031 
1032         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1033             for (int i = 0; i < a.length; i += SPECIES.length()) {
1034                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1035                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1036                 VectorMask<Float> mv = av.notEqual(bv);
1037 
1038                 // Check results as part of computation.
1039                 for (int j = 0; j < SPECIES.length(); j++) {
1040                     Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]);
1041                 }
1042             }
1043         }
1044     }
1045 
1046 
1047     @Test(dataProvider = "floatCompareOpProvider")
1048     static void lessThanEqFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1049         float[] a = fa.apply(SPECIES.length());
1050         float[] b = fb.apply(SPECIES.length());
1051 
1052         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1053             for (int i = 0; i < a.length; i += SPECIES.length()) {
1054                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1055                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1056                 VectorMask<Float> mv = av.lessThanEq(bv);
1057 
1058                 // Check results as part of computation.
1059                 for (int j = 0; j < SPECIES.length(); j++) {
1060                     Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]);
1061                 }
1062             }
1063         }
1064     }
1065 
1066 
1067     @Test(dataProvider = "floatCompareOpProvider")
1068     static void greaterThanEqFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
1069         float[] a = fa.apply(SPECIES.length());
1070         float[] b = fb.apply(SPECIES.length());
1071 
1072         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1073             for (int i = 0; i < a.length; i += SPECIES.length()) {
1074                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1075                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1076                 VectorMask<Float> mv = av.greaterThanEq(bv);
1077 
1078                 // Check results as part of computation.
1079                 for (int j = 0; j < SPECIES.length(); j++) {
1080                     Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]);
1081                 }
1082             }
1083         }
1084     }
1085 
1086 
1087     static float blend(float a, float b, boolean mask) {
1088         return mask ? b : a;
1089     }
1090 
1091     @Test(dataProvider = "floatBinaryOpMaskProvider")
1092     static void blendFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
1093                                           IntFunction<boolean[]> fm) {
1094         float[] a = fa.apply(SPECIES.length());
1095         float[] b = fb.apply(SPECIES.length());
1096         float[] r = fr.apply(SPECIES.length());
1097         boolean[] mask = fm.apply(SPECIES.length());
1098         VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
1099 
1100         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1101             for (int i = 0; i < a.length; i += SPECIES.length()) {
1102                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1103                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1104                 av.blend(bv, vmask).intoArray(r, i);
1105             }
1106         }
1107 
1108         assertArraysEquals(a, b, r, mask, Float128VectorTests::blend);
1109     }
1110 
1111     @Test(dataProvider = "floatUnaryOpShuffleProvider")
1112     static void RearrangeFloat128VectorTests(IntFunction<float[]> fa,
1113                                            BiFunction<Integer,Integer,int[]> fs) {
1114         float[] a = fa.apply(SPECIES.length());
1115         int[] order = fs.apply(a.length, SPECIES.length());
1116         float[] r = fr.apply(SPECIES.length());
1117 
1118         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1119             for (int i = 0; i < a.length; i += SPECIES.length()) {
1120                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1121                 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
1122             }
1123         }
1124 
1125         assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1126     }
1127 
1128 
1129 
1130 
1131     @Test(dataProvider = "floatUnaryOpProvider")
1132     static void getFloat128VectorTests(IntFunction<float[]> fa) {
1133         float[] a = fa.apply(SPECIES.length());
1134         float[] r = fr.apply(SPECIES.length());
1135 
1136         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1137             for (int i = 0; i < a.length; i += SPECIES.length()) {
1138                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1139                 int num_lanes = SPECIES.length();
1140                 // Manually unroll because full unroll happens after intrinsification.
1141                 // Unroll is needed because get intrinsic requires for index to be a known constant.


1741             for (int i = 0; i < a.length; i += SPECIES.length()) {
1742                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1743                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1744                 FloatVector cv = FloatVector.fromArray(SPECIES, c, i);
1745                 av.fma(bv, cv).intoArray(r, i);
1746             }
1747         }
1748 
1749         assertArraysEquals(a, b, c, r, Float128VectorTests::fma);
1750     }
1751 
1752 
1753     @Test(dataProvider = "floatTernaryOpMaskProvider")
1754     static void fmaFloat128VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb,
1755                                           IntFunction<float[]> fc, IntFunction<boolean[]> fm) {
1756         float[] a = fa.apply(SPECIES.length());
1757         float[] b = fb.apply(SPECIES.length());
1758         float[] c = fc.apply(SPECIES.length());
1759         float[] r = fr.apply(SPECIES.length());
1760         boolean[] mask = fm.apply(SPECIES.length());
1761         VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
1762 
1763         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1764             for (int i = 0; i < a.length; i += SPECIES.length()) {
1765                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1766                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
1767                 FloatVector cv = FloatVector.fromArray(SPECIES, c, i);
1768                 av.fma(bv, cv, vmask).intoArray(r, i);
1769             }
1770         }
1771 
1772         assertArraysEquals(a, b, c, r, mask, Float128VectorTests::fma);
1773     }
1774 
1775 
1776     static float neg(float a) {
1777         return (float)(-((float)a));
1778     }
1779 
1780     @Test(dataProvider = "floatUnaryOpProvider")
1781     static void negFloat128VectorTests(IntFunction<float[]> fa) {
1782         float[] a = fa.apply(SPECIES.length());
1783         float[] r = fr.apply(SPECIES.length());
1784 
1785         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1786             for (int i = 0; i < a.length; i += SPECIES.length()) {
1787                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1788                 av.neg().intoArray(r, i);
1789             }
1790         }
1791 
1792         assertArraysEquals(a, r, Float128VectorTests::neg);
1793     }
1794 
1795     @Test(dataProvider = "floatUnaryOpMaskProvider")
1796     static void negMaskedFloat128VectorTests(IntFunction<float[]> fa,
1797                                                 IntFunction<boolean[]> fm) {
1798         float[] a = fa.apply(SPECIES.length());
1799         float[] r = fr.apply(SPECIES.length());
1800         boolean[] mask = fm.apply(SPECIES.length());
1801         VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
1802 
1803         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1804             for (int i = 0; i < a.length; i += SPECIES.length()) {
1805                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1806                 av.neg(vmask).intoArray(r, i);
1807             }
1808         }
1809 
1810         assertArraysEquals(a, r, mask, Float128VectorTests::neg);
1811     }
1812 
1813     static float abs(float a) {
1814         return (float)(Math.abs((float)a));
1815     }
1816 
1817     @Test(dataProvider = "floatUnaryOpProvider")
1818     static void absFloat128VectorTests(IntFunction<float[]> fa) {
1819         float[] a = fa.apply(SPECIES.length());
1820         float[] r = fr.apply(SPECIES.length());
1821 
1822         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1823             for (int i = 0; i < a.length; i += SPECIES.length()) {
1824                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1825                 av.abs().intoArray(r, i);
1826             }
1827         }
1828 
1829         assertArraysEquals(a, r, Float128VectorTests::abs);
1830     }
1831 
1832     @Test(dataProvider = "floatUnaryOpMaskProvider")
1833     static void absMaskedFloat128VectorTests(IntFunction<float[]> fa,
1834                                                 IntFunction<boolean[]> fm) {
1835         float[] a = fa.apply(SPECIES.length());
1836         float[] r = fr.apply(SPECIES.length());
1837         boolean[] mask = fm.apply(SPECIES.length());
1838         VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
1839 
1840         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1841             for (int i = 0; i < a.length; i += SPECIES.length()) {
1842                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1843                 av.abs(vmask).intoArray(r, i);
1844             }
1845         }
1846 
1847         assertArraysEquals(a, r, mask, Float128VectorTests::abs);
1848     }
1849 
1850 
1851 
1852 
1853 
1854     static float sqrt(float a) {
1855         return (float)(Math.sqrt((double)a));
1856     }
1857 
1858 


1863         float[] r = fr.apply(SPECIES.length());
1864 
1865         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1866             for (int i = 0; i < a.length; i += SPECIES.length()) {
1867                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1868                 av.sqrt().intoArray(r, i);
1869             }
1870         }
1871 
1872         assertArraysEquals(a, r, Float128VectorTests::sqrt);
1873     }
1874 
1875 
1876 
1877     @Test(dataProvider = "floatUnaryOpMaskProvider")
1878     static void sqrtMaskedFloat128VectorTests(IntFunction<float[]> fa,
1879                                                 IntFunction<boolean[]> fm) {
1880         float[] a = fa.apply(SPECIES.length());
1881         float[] r = fr.apply(SPECIES.length());
1882         boolean[] mask = fm.apply(SPECIES.length());
1883         VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask);
1884 
1885         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1886             for (int i = 0; i < a.length; i += SPECIES.length()) {
1887                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
1888                 av.sqrt(vmask).intoArray(r, i);
1889             }
1890         }
1891 
1892         assertArraysEquals(a, r, mask, Float128VectorTests::sqrt);
1893     }
1894 
1895 
1896     static float[] gather(float a[], int ix, int[] b, int iy) {
1897         float[] res = new float[SPECIES.length()];
1898         for (int i = 0; i < SPECIES.length(); i++) {
1899             int bi = iy + i;
1900             res[i] = a[b[bi] + ix];
1901         }
1902         return res;
1903     }


< prev index next >