< prev index next >

test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.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 DoubleMaxVectorTests
  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.DoubleVector;
  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 DoubleMaxVectorTests extends AbstractVectorTest {
  50 
  51     static final Species<Double> SPECIES =
  52                 DoubleVector.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         double apply(double a);
  62     }
  63 
  64     static void assertArraysEquals(double[] a, double[] 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(double[] a, double[] r, boolean[] mask, FUnOp f) {
  76         int i = 0;
  77         try {


 549         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 554                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 555                 av.add(bv).intoArray(r, i);
 556             }
 557         }
 558 
 559         assertArraysEquals(a, b, r, DoubleMaxVectorTests::add);
 560     }
 561 
 562     @Test(dataProvider = "doubleBinaryOpMaskProvider")
 563     static void addDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
 564                                           IntFunction<boolean[]> fm) {
 565         double[] a = fa.apply(SPECIES.length());
 566         double[] b = fb.apply(SPECIES.length());
 567         double[] r = fr.apply(SPECIES.length());
 568         boolean[] mask = fm.apply(SPECIES.length());
 569         Vector.Mask<Double> vmask = DoubleVector.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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 574                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 575                 av.add(bv, vmask).intoArray(r, i);
 576             }
 577         }
 578 
 579         assertArraysEquals(a, b, r, mask, DoubleMaxVectorTests::add);
 580     }
 581     static double sub(double a, double b) {
 582         return (double)(a - b);
 583     }
 584 
 585     @Test(dataProvider = "doubleBinaryOpProvider")
 586     static void subDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
 587         double[] a = fa.apply(SPECIES.length());
 588         double[] b = fb.apply(SPECIES.length());
 589         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 594                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 595                 av.sub(bv).intoArray(r, i);
 596             }
 597         }
 598 
 599         assertArraysEquals(a, b, r, DoubleMaxVectorTests::sub);
 600     }
 601 
 602     @Test(dataProvider = "doubleBinaryOpMaskProvider")
 603     static void subDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
 604                                           IntFunction<boolean[]> fm) {
 605         double[] a = fa.apply(SPECIES.length());
 606         double[] b = fb.apply(SPECIES.length());
 607         double[] r = fr.apply(SPECIES.length());
 608         boolean[] mask = fm.apply(SPECIES.length());
 609         Vector.Mask<Double> vmask = DoubleVector.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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 614                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 615                 av.sub(bv, vmask).intoArray(r, i);
 616             }
 617         }
 618 
 619         assertArraysEquals(a, b, r, mask, DoubleMaxVectorTests::sub);
 620     }
 621 
 622     static double div(double a, double b) {
 623         return (double)(a / b);
 624     }
 625 
 626     @Test(dataProvider = "doubleBinaryOpProvider")
 627     static void divDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
 628         double[] a = fa.apply(SPECIES.length());
 629         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 635                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 636                 av.div(bv).intoArray(r, i);
 637             }
 638         }
 639 
 640         assertArraysEquals(a, b, r, DoubleMaxVectorTests::div);
 641     }
 642 
 643 
 644 
 645     @Test(dataProvider = "doubleBinaryOpMaskProvider")
 646     static void divDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
 647                                           IntFunction<boolean[]> fm) {
 648         double[] a = fa.apply(SPECIES.length());
 649         double[] b = fb.apply(SPECIES.length());
 650         double[] r = fr.apply(SPECIES.length());
 651         boolean[] mask = fm.apply(SPECIES.length());
 652         Vector.Mask<Double> vmask = DoubleVector.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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 657                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 658                 av.div(bv, vmask).intoArray(r, i);
 659             }
 660         }
 661 
 662         assertArraysEquals(a, b, r, mask, DoubleMaxVectorTests::div);
 663     }
 664 
 665     static double mul(double a, double b) {
 666         return (double)(a * b);
 667     }
 668 
 669     @Test(dataProvider = "doubleBinaryOpProvider")
 670     static void mulDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
 671         double[] a = fa.apply(SPECIES.length());
 672         double[] b = fb.apply(SPECIES.length());
 673         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 678                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 679                 av.mul(bv).intoArray(r, i);
 680             }
 681         }
 682 
 683         assertArraysEquals(a, b, r, DoubleMaxVectorTests::mul);
 684     }
 685 
 686     @Test(dataProvider = "doubleBinaryOpMaskProvider")
 687     static void mulDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
 688                                           IntFunction<boolean[]> fm) {
 689         double[] a = fa.apply(SPECIES.length());
 690         double[] b = fb.apply(SPECIES.length());
 691         double[] r = fr.apply(SPECIES.length());
 692         boolean[] mask = fm.apply(SPECIES.length());
 693         Vector.Mask<Double> vmask = DoubleVector.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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 698                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 699                 av.mul(bv, vmask).intoArray(r, i);
 700             }
 701         }
 702 
 703         assertArraysEquals(a, b, r, mask, DoubleMaxVectorTests::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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 962                 av.with(0, (double)4).intoArray(r, i);
 963             }
 964         }
 965 
 966         assertInsertArraysEquals(a, r, (double)4, 0);
 967     }
 968 
 969     @Test(dataProvider = "doubleCompareOpProvider")
 970     static void lessThanDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
 971         double[] a = fa.apply(SPECIES.length());
 972         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 977                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 978                 Vector.Mask<Double> 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 = "doubleCompareOpProvider")
 990     static void greaterThanDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
 991         double[] a = fa.apply(SPECIES.length());
 992         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 997                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 998                 Vector.Mask<Double> 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 = "doubleCompareOpProvider")
1010     static void equalDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1011         double[] a = fa.apply(SPECIES.length());
1012         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1017                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1018                 Vector.Mask<Double> 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 = "doubleCompareOpProvider")
1030     static void notEqualDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1031         double[] a = fa.apply(SPECIES.length());
1032         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1037                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1038                 Vector.Mask<Double> 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 = "doubleCompareOpProvider")
1050     static void lessThanEqDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1051         double[] a = fa.apply(SPECIES.length());
1052         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1057                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1058                 Vector.Mask<Double> 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 = "doubleCompareOpProvider")
1070     static void greaterThanEqDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1071         double[] a = fa.apply(SPECIES.length());
1072         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1077                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1078                 Vector.Mask<Double> 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 double blend(double a, double b, boolean mask) {
1090         return mask ? b : a;
1091     }
1092 
1093     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1094     static void blendDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
1095                                           IntFunction<boolean[]> fm) {
1096         double[] a = fa.apply(SPECIES.length());
1097         double[] b = fb.apply(SPECIES.length());
1098         double[] r = fr.apply(SPECIES.length());
1099         boolean[] mask = fm.apply(SPECIES.length());
1100         Vector.Mask<Double> vmask = DoubleVector.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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1105                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1106                 av.blend(bv, vmask).intoArray(r, i);
1107             }
1108         }
1109 
1110         assertArraysEquals(a, b, r, mask, DoubleMaxVectorTests::blend);
1111     }
1112 
1113     @Test(dataProvider = "doubleUnaryOpShuffleProvider")
1114     static void RearrangeDoubleMaxVectorTests(IntFunction<double[]> fa,
1115                                            BiFunction<Integer,Integer,int[]> fs) {
1116         double[] a = fa.apply(SPECIES.length());
1117         int[] order = fs.apply(a.length, SPECIES.length());
1118         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1123                 av.rearrange(DoubleVector.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 = "doubleUnaryOpProvider")
1134     static void getDoubleMaxVectorTests(IntFunction<double[]> fa) {
1135         double[] a = fa.apply(SPECIES.length());
1136         double[] 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                 DoubleVector av = DoubleVector.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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1745                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1746                 DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i);
1747                 av.fma(bv, cv).intoArray(r, i);
1748             }
1749         }
1750 
1751         assertArraysEquals(a, b, c, r, DoubleMaxVectorTests::fma);
1752     }
1753 
1754 
1755     @Test(dataProvider = "doubleTernaryOpMaskProvider")
1756     static void fmaDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
1757                                           IntFunction<double[]> fc, IntFunction<boolean[]> fm) {
1758         double[] a = fa.apply(SPECIES.length());
1759         double[] b = fb.apply(SPECIES.length());
1760         double[] c = fc.apply(SPECIES.length());
1761         double[] r = fr.apply(SPECIES.length());
1762         boolean[] mask = fm.apply(SPECIES.length());
1763         Vector.Mask<Double> vmask = DoubleVector.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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1768                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1769                 DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i);
1770                 av.fma(bv, cv, vmask).intoArray(r, i);
1771             }
1772         }
1773 
1774         assertArraysEquals(a, b, c, r, mask, DoubleMaxVectorTests::fma);
1775     }
1776 
1777 
1778     static double neg(double a) {
1779         return (double)(-((double)a));
1780     }
1781 
1782     @Test(dataProvider = "doubleUnaryOpProvider")
1783     static void negDoubleMaxVectorTests(IntFunction<double[]> fa) {
1784         double[] a = fa.apply(SPECIES.length());
1785         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1790                 av.neg().intoArray(r, i);
1791             }
1792         }
1793 
1794         assertArraysEquals(a, r, DoubleMaxVectorTests::neg);
1795     }
1796 
1797     @Test(dataProvider = "doubleUnaryOpMaskProvider")
1798     static void negMaskedDoubleMaxVectorTests(IntFunction<double[]> fa,
1799                                                 IntFunction<boolean[]> fm) {
1800         double[] a = fa.apply(SPECIES.length());
1801         double[] r = fr.apply(SPECIES.length());
1802         boolean[] mask = fm.apply(SPECIES.length());
1803         Vector.Mask<Double> vmask = DoubleVector.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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1808                 av.neg(vmask).intoArray(r, i);
1809             }
1810         }
1811 
1812         assertArraysEquals(a, r, mask, DoubleMaxVectorTests::neg);
1813     }
1814 
1815     static double abs(double a) {
1816         return (double)(Math.abs((double)a));
1817     }
1818 
1819     @Test(dataProvider = "doubleUnaryOpProvider")
1820     static void absDoubleMaxVectorTests(IntFunction<double[]> fa) {
1821         double[] a = fa.apply(SPECIES.length());
1822         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1827                 av.abs().intoArray(r, i);
1828             }
1829         }
1830 
1831         assertArraysEquals(a, r, DoubleMaxVectorTests::abs);
1832     }
1833 
1834     @Test(dataProvider = "doubleUnaryOpMaskProvider")
1835     static void absMaskedDoubleMaxVectorTests(IntFunction<double[]> fa,
1836                                                 IntFunction<boolean[]> fm) {
1837         double[] a = fa.apply(SPECIES.length());
1838         double[] r = fr.apply(SPECIES.length());
1839         boolean[] mask = fm.apply(SPECIES.length());
1840         Vector.Mask<Double> vmask = DoubleVector.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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1845                 av.abs(vmask).intoArray(r, i);
1846             }
1847         }
1848 
1849         assertArraysEquals(a, r, mask, DoubleMaxVectorTests::abs);
1850     }
1851 
1852 
1853 
1854 
1855 
1856     static double sqrt(double a) {
1857         return (double)(Math.sqrt((double)a));
1858     }
1859 
1860 


1865         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1870                 av.sqrt().intoArray(r, i);
1871             }
1872         }
1873 
1874         assertArraysEquals(a, r, DoubleMaxVectorTests::sqrt);
1875     }
1876 
1877 
1878 
1879     @Test(dataProvider = "doubleUnaryOpMaskProvider")
1880     static void sqrtMaskedDoubleMaxVectorTests(IntFunction<double[]> fa,
1881                                                 IntFunction<boolean[]> fm) {
1882         double[] a = fa.apply(SPECIES.length());
1883         double[] r = fr.apply(SPECIES.length());
1884         boolean[] mask = fm.apply(SPECIES.length());
1885         Vector.Mask<Double> vmask = DoubleVector.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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1890                 av.sqrt(vmask).intoArray(r, i);
1891             }
1892         }
1893 
1894         assertArraysEquals(a, r, mask, DoubleMaxVectorTests::sqrt);
1895     }
1896 
1897 
1898     static double[] gather(double a[], int ix, int[] b, int iy) {
1899         double[] res = new double[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 DoubleMaxVectorTests
  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.DoubleVector;
  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 DoubleMaxVectorTests extends AbstractVectorTest {
  52 
  53     static final VectorSpecies<Double> SPECIES =
  54                 DoubleVector.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         double apply(double a);
  64     }
  65 
  66     static void assertArraysEquals(double[] a, double[] 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(double[] a, double[] r, boolean[] mask, FUnOp f) {
  78         int i = 0;
  79         try {


 551         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 556                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 557                 av.add(bv).intoArray(r, i);
 558             }
 559         }
 560 
 561         assertArraysEquals(a, b, r, DoubleMaxVectorTests::add);
 562     }
 563 
 564     @Test(dataProvider = "doubleBinaryOpMaskProvider")
 565     static void addDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
 566                                           IntFunction<boolean[]> fm) {
 567         double[] a = fa.apply(SPECIES.length());
 568         double[] b = fb.apply(SPECIES.length());
 569         double[] r = fr.apply(SPECIES.length());
 570         boolean[] mask = fm.apply(SPECIES.length());
 571         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 576                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 577                 av.add(bv, vmask).intoArray(r, i);
 578             }
 579         }
 580 
 581         assertArraysEquals(a, b, r, mask, DoubleMaxVectorTests::add);
 582     }
 583     static double sub(double a, double b) {
 584         return (double)(a - b);
 585     }
 586 
 587     @Test(dataProvider = "doubleBinaryOpProvider")
 588     static void subDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
 589         double[] a = fa.apply(SPECIES.length());
 590         double[] b = fb.apply(SPECIES.length());
 591         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 596                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 597                 av.sub(bv).intoArray(r, i);
 598             }
 599         }
 600 
 601         assertArraysEquals(a, b, r, DoubleMaxVectorTests::sub);
 602     }
 603 
 604     @Test(dataProvider = "doubleBinaryOpMaskProvider")
 605     static void subDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
 606                                           IntFunction<boolean[]> fm) {
 607         double[] a = fa.apply(SPECIES.length());
 608         double[] b = fb.apply(SPECIES.length());
 609         double[] r = fr.apply(SPECIES.length());
 610         boolean[] mask = fm.apply(SPECIES.length());
 611         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 616                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 617                 av.sub(bv, vmask).intoArray(r, i);
 618             }
 619         }
 620 
 621         assertArraysEquals(a, b, r, mask, DoubleMaxVectorTests::sub);
 622     }
 623 
 624     static double div(double a, double b) {
 625         return (double)(a / b);
 626     }
 627 
 628     @Test(dataProvider = "doubleBinaryOpProvider")
 629     static void divDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
 630         double[] a = fa.apply(SPECIES.length());
 631         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 637                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 638                 av.div(bv).intoArray(r, i);
 639             }
 640         }
 641 
 642         assertArraysEquals(a, b, r, DoubleMaxVectorTests::div);
 643     }
 644 
 645 
 646 
 647     @Test(dataProvider = "doubleBinaryOpMaskProvider")
 648     static void divDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
 649                                           IntFunction<boolean[]> fm) {
 650         double[] a = fa.apply(SPECIES.length());
 651         double[] b = fb.apply(SPECIES.length());
 652         double[] r = fr.apply(SPECIES.length());
 653         boolean[] mask = fm.apply(SPECIES.length());
 654         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 659                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 660                 av.div(bv, vmask).intoArray(r, i);
 661             }
 662         }
 663 
 664         assertArraysEquals(a, b, r, mask, DoubleMaxVectorTests::div);
 665     }
 666 
 667     static double mul(double a, double b) {
 668         return (double)(a * b);
 669     }
 670 
 671     @Test(dataProvider = "doubleBinaryOpProvider")
 672     static void mulDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
 673         double[] a = fa.apply(SPECIES.length());
 674         double[] b = fb.apply(SPECIES.length());
 675         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 680                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 681                 av.mul(bv).intoArray(r, i);
 682             }
 683         }
 684 
 685         assertArraysEquals(a, b, r, DoubleMaxVectorTests::mul);
 686     }
 687 
 688     @Test(dataProvider = "doubleBinaryOpMaskProvider")
 689     static void mulDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
 690                                           IntFunction<boolean[]> fm) {
 691         double[] a = fa.apply(SPECIES.length());
 692         double[] b = fb.apply(SPECIES.length());
 693         double[] r = fr.apply(SPECIES.length());
 694         boolean[] mask = fm.apply(SPECIES.length());
 695         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 700                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 701                 av.mul(bv, vmask).intoArray(r, i);
 702             }
 703         }
 704 
 705         assertArraysEquals(a, b, r, mask, DoubleMaxVectorTests::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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 964                 av.with(0, (double)4).intoArray(r, i);
 965             }
 966         }
 967 
 968         assertInsertArraysEquals(a, r, (double)4, 0);
 969     }
 970 
 971     @Test(dataProvider = "doubleCompareOpProvider")
 972     static void lessThanDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
 973         double[] a = fa.apply(SPECIES.length());
 974         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 979                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 980                 VectorMask<Double> 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 = "doubleCompareOpProvider")
 992     static void greaterThanDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
 993         double[] a = fa.apply(SPECIES.length());
 994         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 999                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1000                 VectorMask<Double> 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 = "doubleCompareOpProvider")
1012     static void equalDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1013         double[] a = fa.apply(SPECIES.length());
1014         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1019                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1020                 VectorMask<Double> 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 = "doubleCompareOpProvider")
1032     static void notEqualDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1033         double[] a = fa.apply(SPECIES.length());
1034         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1039                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1040                 VectorMask<Double> 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 = "doubleCompareOpProvider")
1052     static void lessThanEqDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1053         double[] a = fa.apply(SPECIES.length());
1054         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1059                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1060                 VectorMask<Double> 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 = "doubleCompareOpProvider")
1072     static void greaterThanEqDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1073         double[] a = fa.apply(SPECIES.length());
1074         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1079                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1080                 VectorMask<Double> 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 double blend(double a, double b, boolean mask) {
1092         return mask ? b : a;
1093     }
1094 
1095     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1096     static void blendDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
1097                                           IntFunction<boolean[]> fm) {
1098         double[] a = fa.apply(SPECIES.length());
1099         double[] b = fb.apply(SPECIES.length());
1100         double[] r = fr.apply(SPECIES.length());
1101         boolean[] mask = fm.apply(SPECIES.length());
1102         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1107                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1108                 av.blend(bv, vmask).intoArray(r, i);
1109             }
1110         }
1111 
1112         assertArraysEquals(a, b, r, mask, DoubleMaxVectorTests::blend);
1113     }
1114 
1115     @Test(dataProvider = "doubleUnaryOpShuffleProvider")
1116     static void RearrangeDoubleMaxVectorTests(IntFunction<double[]> fa,
1117                                            BiFunction<Integer,Integer,int[]> fs) {
1118         double[] a = fa.apply(SPECIES.length());
1119         int[] order = fs.apply(a.length, SPECIES.length());
1120         double[] 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                 DoubleVector av = DoubleVector.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 = "doubleUnaryOpProvider")
1136     static void getDoubleMaxVectorTests(IntFunction<double[]> fa) {
1137         double[] a = fa.apply(SPECIES.length());
1138         double[] 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                 DoubleVector av = DoubleVector.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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1747                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1748                 DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i);
1749                 av.fma(bv, cv).intoArray(r, i);
1750             }
1751         }
1752 
1753         assertArraysEquals(a, b, c, r, DoubleMaxVectorTests::fma);
1754     }
1755 
1756 
1757     @Test(dataProvider = "doubleTernaryOpMaskProvider")
1758     static void fmaDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
1759                                           IntFunction<double[]> fc, IntFunction<boolean[]> fm) {
1760         double[] a = fa.apply(SPECIES.length());
1761         double[] b = fb.apply(SPECIES.length());
1762         double[] c = fc.apply(SPECIES.length());
1763         double[] r = fr.apply(SPECIES.length());
1764         boolean[] mask = fm.apply(SPECIES.length());
1765         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1770                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1771                 DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i);
1772                 av.fma(bv, cv, vmask).intoArray(r, i);
1773             }
1774         }
1775 
1776         assertArraysEquals(a, b, c, r, mask, DoubleMaxVectorTests::fma);
1777     }
1778 
1779 
1780     static double neg(double a) {
1781         return (double)(-((double)a));
1782     }
1783 
1784     @Test(dataProvider = "doubleUnaryOpProvider")
1785     static void negDoubleMaxVectorTests(IntFunction<double[]> fa) {
1786         double[] a = fa.apply(SPECIES.length());
1787         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1792                 av.neg().intoArray(r, i);
1793             }
1794         }
1795 
1796         assertArraysEquals(a, r, DoubleMaxVectorTests::neg);
1797     }
1798 
1799     @Test(dataProvider = "doubleUnaryOpMaskProvider")
1800     static void negMaskedDoubleMaxVectorTests(IntFunction<double[]> fa,
1801                                                 IntFunction<boolean[]> fm) {
1802         double[] a = fa.apply(SPECIES.length());
1803         double[] r = fr.apply(SPECIES.length());
1804         boolean[] mask = fm.apply(SPECIES.length());
1805         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1810                 av.neg(vmask).intoArray(r, i);
1811             }
1812         }
1813 
1814         assertArraysEquals(a, r, mask, DoubleMaxVectorTests::neg);
1815     }
1816 
1817     static double abs(double a) {
1818         return (double)(Math.abs((double)a));
1819     }
1820 
1821     @Test(dataProvider = "doubleUnaryOpProvider")
1822     static void absDoubleMaxVectorTests(IntFunction<double[]> fa) {
1823         double[] a = fa.apply(SPECIES.length());
1824         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1829                 av.abs().intoArray(r, i);
1830             }
1831         }
1832 
1833         assertArraysEquals(a, r, DoubleMaxVectorTests::abs);
1834     }
1835 
1836     @Test(dataProvider = "doubleUnaryOpMaskProvider")
1837     static void absMaskedDoubleMaxVectorTests(IntFunction<double[]> fa,
1838                                                 IntFunction<boolean[]> fm) {
1839         double[] a = fa.apply(SPECIES.length());
1840         double[] r = fr.apply(SPECIES.length());
1841         boolean[] mask = fm.apply(SPECIES.length());
1842         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1847                 av.abs(vmask).intoArray(r, i);
1848             }
1849         }
1850 
1851         assertArraysEquals(a, r, mask, DoubleMaxVectorTests::abs);
1852     }
1853 
1854 
1855 
1856 
1857 
1858     static double sqrt(double a) {
1859         return (double)(Math.sqrt((double)a));
1860     }
1861 
1862 


1867         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1872                 av.sqrt().intoArray(r, i);
1873             }
1874         }
1875 
1876         assertArraysEquals(a, r, DoubleMaxVectorTests::sqrt);
1877     }
1878 
1879 
1880 
1881     @Test(dataProvider = "doubleUnaryOpMaskProvider")
1882     static void sqrtMaskedDoubleMaxVectorTests(IntFunction<double[]> fa,
1883                                                 IntFunction<boolean[]> fm) {
1884         double[] a = fa.apply(SPECIES.length());
1885         double[] r = fr.apply(SPECIES.length());
1886         boolean[] mask = fm.apply(SPECIES.length());
1887         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1892                 av.sqrt(vmask).intoArray(r, i);
1893             }
1894         }
1895 
1896         assertArraysEquals(a, r, mask, DoubleMaxVectorTests::sqrt);
1897     }
1898 
1899 
1900     static double[] gather(double a[], int ix, int[] b, int iy) {
1901         double[] res = new double[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     }


< prev index next >