< prev index next >

test/jdk/jdk/incubator/vector/Double512VectorTests.java

Print this page

   1 /*
   2  * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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 any
  21  * questions.
  22  */

  45 import org.testng.annotations.DataProvider;
  46 import org.testng.annotations.Test;
  47 
  48 import java.lang.Integer;
  49 import java.util.List;
  50 import java.util.Arrays;
  51 import java.util.function.BiFunction;
  52 import java.util.function.IntFunction;
  53 import java.util.Objects;
  54 import java.util.stream.Collectors;
  55 import java.util.stream.Stream;
  56 
  57 @Test
  58 public class Double512VectorTests extends AbstractVectorTest {
  59 
  60     static final VectorSpecies<Double> SPECIES =
  61                 DoubleVector.SPECIES_512;
  62 
  63     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  64 


  65 
  66     // for floating point addition reduction ops that may introduce rounding errors
  67     private static final double RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (double)10.0;
  68 
  69     // for floating point multiplication reduction ops that may introduce rounding errors
  70     private static final double RELATIVE_ROUNDING_ERROR_FACTOR_MUL = (double)50.0;
  71 
  72     static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
  73 
  74     static void assertArraysStrictlyEquals(double[] r, double[] a) {
  75         for (int i = 0; i < a.length; i++) {
  76             long ir = Double.doubleToRawLongBits(r[i]);
  77             long ia = Double.doubleToRawLongBits(a[i]);
  78             if (ir != ia) {
  79                 Assert.fail(String.format("at index #%d, expected = %016X, actual = %016X", i, ia, ir));
  80             }
  81         }
  82     }
  83 
  84     interface FUnOp {

2079         assertBroadcastLongArraysEquals(r, a, b, Double512VectorTests::ADD);
2080     }
2081 
2082     @Test(dataProvider = "doubleBinaryOpMaskProvider")
2083     static void ADDDouble512VectorTestsBroadcastMaskedLongSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb,
2084                                           IntFunction<boolean[]> fm) {
2085         double[] a = fa.apply(SPECIES.length());
2086         double[] b = fb.apply(SPECIES.length());
2087         double[] r = fr.apply(SPECIES.length());
2088         boolean[] mask = fm.apply(SPECIES.length());
2089         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2090 
2091         for (int i = 0; i < a.length; i += SPECIES.length()) {
2092             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2093             av.lanewise(VectorOperators.ADD, (long)b[i], vmask).intoArray(r, i);
2094         }
2095 
2096         assertBroadcastLongArraysEquals(r, a, b, mask, Double512VectorTests::ADD);
2097     }
2098 
2099     static DoubleVector bv_MIN = DoubleVector.broadcast(SPECIES, (double)10);
2100 
2101     @Test(dataProvider = "doubleUnaryOpProvider")
2102     static void MINDouble512VectorTestsWithMemOp(IntFunction<double[]> fa) {
2103         double[] a = fa.apply(SPECIES.length());
2104         double[] r = fr.apply(SPECIES.length());
2105 
2106         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2107             for (int i = 0; i < a.length; i += SPECIES.length()) {
2108                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2109                 av.lanewise(VectorOperators.MIN, bv_MIN).intoArray(r, i);
2110             }
2111         }
2112 
2113         assertArraysEquals(r, a, (double)10, Double512VectorTests::MIN);
2114     }
2115 
2116     static DoubleVector bv_min = DoubleVector.broadcast(SPECIES, (double)10);
2117 
2118     @Test(dataProvider = "doubleUnaryOpProvider")
2119     static void minDouble512VectorTestsWithMemOp(IntFunction<double[]> fa) {
2120         double[] a = fa.apply(SPECIES.length());
2121         double[] r = fr.apply(SPECIES.length());
2122 
2123         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2124             for (int i = 0; i < a.length; i += SPECIES.length()) {
2125                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2126                 av.min(bv_min).intoArray(r, i);
2127             }
2128         }
2129 
2130         assertArraysEquals(r, a, (double)10, Double512VectorTests::min);
2131     }
2132 
2133     static DoubleVector bv_MIN_M = DoubleVector.broadcast(SPECIES, (double)10);
2134 
2135     @Test(dataProvider = "doubleUnaryOpMaskProvider")
2136     static void MINDouble512VectorTestsMaskedWithMemOp(IntFunction<double[]> fa, IntFunction<boolean[]> fm) {
2137         double[] a = fa.apply(SPECIES.length());
2138         double[] r = fr.apply(SPECIES.length());
2139         boolean[] mask = fm.apply(SPECIES.length());
2140         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2141 
2142         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2143             for (int i = 0; i < a.length; i += SPECIES.length()) {
2144                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2145                 av.lanewise(VectorOperators.MIN, bv_MIN_M, vmask).intoArray(r, i);
2146             }
2147         }
2148 
2149         assertArraysEquals(r, a, (double)10, mask, Double512VectorTests::MIN);
2150     }
2151 
2152     static DoubleVector bv_MAX = DoubleVector.broadcast(SPECIES, (double)10);
2153 
2154     @Test(dataProvider = "doubleUnaryOpProvider")
2155     static void MAXDouble512VectorTestsWithMemOp(IntFunction<double[]> fa) {
2156         double[] a = fa.apply(SPECIES.length());
2157         double[] r = fr.apply(SPECIES.length());
2158 
2159         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2160             for (int i = 0; i < a.length; i += SPECIES.length()) {
2161                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2162                 av.lanewise(VectorOperators.MAX, bv_MAX).intoArray(r, i);
2163             }
2164         }
2165 
2166         assertArraysEquals(r, a, (double)10, Double512VectorTests::MAX);
2167     }
2168 
2169     static DoubleVector bv_max = DoubleVector.broadcast(SPECIES, (double)10);
2170 
2171     @Test(dataProvider = "doubleUnaryOpProvider")
2172     static void maxDouble512VectorTestsWithMemOp(IntFunction<double[]> fa) {
2173         double[] a = fa.apply(SPECIES.length());
2174         double[] r = fr.apply(SPECIES.length());
2175 
2176         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2177             for (int i = 0; i < a.length; i += SPECIES.length()) {
2178                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2179                 av.max(bv_max).intoArray(r, i);
2180             }
2181         }
2182 
2183         assertArraysEquals(r, a, (double)10, Double512VectorTests::max);
2184     }
2185 
2186     static DoubleVector bv_MAX_M = DoubleVector.broadcast(SPECIES, (double)10);
2187 
2188     @Test(dataProvider = "doubleUnaryOpMaskProvider")
2189     static void MAXDouble512VectorTestsMaskedWithMemOp(IntFunction<double[]> fa, IntFunction<boolean[]> fm) {
2190         double[] a = fa.apply(SPECIES.length());
2191         double[] r = fr.apply(SPECIES.length());
2192         boolean[] mask = fm.apply(SPECIES.length());
2193         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2194 
2195         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2196             for (int i = 0; i < a.length; i += SPECIES.length()) {
2197                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2198                 av.lanewise(VectorOperators.MAX, bv_MAX_M, vmask).intoArray(r, i);
2199             }
2200         }
2201 
2202         assertArraysEquals(r, a, (double)10, mask, Double512VectorTests::MAX);
2203     }
2204 
2205     static double MIN(double a, double b) {
2206         return (double)(Math.min(a, b));
2207     }
2208 
2209     @Test(dataProvider = "doubleBinaryOpProvider")
2210     static void MINDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2211         double[] a = fa.apply(SPECIES.length());
2212         double[] b = fb.apply(SPECIES.length());
2213         double[] r = fr.apply(SPECIES.length());
2214 
2215         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2216             for (int i = 0; i < a.length; i += SPECIES.length()) {
2217                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2218                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);

   1 /*
   2  * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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 any
  21  * questions.
  22  */

  45 import org.testng.annotations.DataProvider;
  46 import org.testng.annotations.Test;
  47 
  48 import java.lang.Integer;
  49 import java.util.List;
  50 import java.util.Arrays;
  51 import java.util.function.BiFunction;
  52 import java.util.function.IntFunction;
  53 import java.util.Objects;
  54 import java.util.stream.Collectors;
  55 import java.util.stream.Stream;
  56 
  57 @Test
  58 public class Double512VectorTests extends AbstractVectorTest {
  59 
  60     static final VectorSpecies<Double> SPECIES =
  61                 DoubleVector.SPECIES_512;
  62 
  63     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  64 
  65     static DoubleVector bcast_vec = DoubleVector.broadcast(SPECIES, (double)10);
  66 
  67 
  68     // for floating point addition reduction ops that may introduce rounding errors
  69     private static final double RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (double)10.0;
  70 
  71     // for floating point multiplication reduction ops that may introduce rounding errors
  72     private static final double RELATIVE_ROUNDING_ERROR_FACTOR_MUL = (double)50.0;
  73 
  74     static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
  75 
  76     static void assertArraysStrictlyEquals(double[] r, double[] a) {
  77         for (int i = 0; i < a.length; i++) {
  78             long ir = Double.doubleToRawLongBits(r[i]);
  79             long ia = Double.doubleToRawLongBits(a[i]);
  80             if (ir != ia) {
  81                 Assert.fail(String.format("at index #%d, expected = %016X, actual = %016X", i, ia, ir));
  82             }
  83         }
  84     }
  85 
  86     interface FUnOp {

2081         assertBroadcastLongArraysEquals(r, a, b, Double512VectorTests::ADD);
2082     }
2083 
2084     @Test(dataProvider = "doubleBinaryOpMaskProvider")
2085     static void ADDDouble512VectorTestsBroadcastMaskedLongSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb,
2086                                           IntFunction<boolean[]> fm) {
2087         double[] a = fa.apply(SPECIES.length());
2088         double[] b = fb.apply(SPECIES.length());
2089         double[] r = fr.apply(SPECIES.length());
2090         boolean[] mask = fm.apply(SPECIES.length());
2091         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2092 
2093         for (int i = 0; i < a.length; i += SPECIES.length()) {
2094             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2095             av.lanewise(VectorOperators.ADD, (long)b[i], vmask).intoArray(r, i);
2096         }
2097 
2098         assertBroadcastLongArraysEquals(r, a, b, mask, Double512VectorTests::ADD);
2099     }
2100 


2101     @Test(dataProvider = "doubleUnaryOpProvider")
2102     static void MINDouble512VectorTestsWithMemOp(IntFunction<double[]> fa) {
2103         double[] a = fa.apply(SPECIES.length());
2104         double[] r = fr.apply(SPECIES.length());
2105 
2106         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2107             for (int i = 0; i < a.length; i += SPECIES.length()) {
2108                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2109                 av.lanewise(VectorOperators.MIN, bcast_vec).intoArray(r, i);
2110             }
2111         }
2112 
2113         assertArraysEquals(r, a, (double)10, Double512VectorTests::MIN);
2114     }
2115 


2116     @Test(dataProvider = "doubleUnaryOpProvider")
2117     static void minDouble512VectorTestsWithMemOp(IntFunction<double[]> fa) {
2118         double[] a = fa.apply(SPECIES.length());
2119         double[] r = fr.apply(SPECIES.length());
2120 
2121         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2122             for (int i = 0; i < a.length; i += SPECIES.length()) {
2123                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2124                 av.min(bcast_vec).intoArray(r, i);
2125             }
2126         }
2127 
2128         assertArraysEquals(r, a, (double)10, Double512VectorTests::min);
2129     }
2130 


2131     @Test(dataProvider = "doubleUnaryOpMaskProvider")
2132     static void MINDouble512VectorTestsMaskedWithMemOp(IntFunction<double[]> fa, IntFunction<boolean[]> fm) {
2133         double[] a = fa.apply(SPECIES.length());
2134         double[] r = fr.apply(SPECIES.length());
2135         boolean[] mask = fm.apply(SPECIES.length());
2136         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2137 
2138         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2139             for (int i = 0; i < a.length; i += SPECIES.length()) {
2140                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2141                 av.lanewise(VectorOperators.MIN, bcast_vec, vmask).intoArray(r, i);
2142             }
2143         }
2144 
2145         assertArraysEquals(r, a, (double)10, mask, Double512VectorTests::MIN);
2146     }
2147 


2148     @Test(dataProvider = "doubleUnaryOpProvider")
2149     static void MAXDouble512VectorTestsWithMemOp(IntFunction<double[]> fa) {
2150         double[] a = fa.apply(SPECIES.length());
2151         double[] r = fr.apply(SPECIES.length());
2152 
2153         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2154             for (int i = 0; i < a.length; i += SPECIES.length()) {
2155                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2156                 av.lanewise(VectorOperators.MAX, bcast_vec).intoArray(r, i);
2157             }
2158         }
2159 
2160         assertArraysEquals(r, a, (double)10, Double512VectorTests::MAX);
2161     }
2162 


2163     @Test(dataProvider = "doubleUnaryOpProvider")
2164     static void maxDouble512VectorTestsWithMemOp(IntFunction<double[]> fa) {
2165         double[] a = fa.apply(SPECIES.length());
2166         double[] r = fr.apply(SPECIES.length());
2167 
2168         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2169             for (int i = 0; i < a.length; i += SPECIES.length()) {
2170                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2171                 av.max(bcast_vec).intoArray(r, i);
2172             }
2173         }
2174 
2175         assertArraysEquals(r, a, (double)10, Double512VectorTests::max);
2176     }
2177 


2178     @Test(dataProvider = "doubleUnaryOpMaskProvider")
2179     static void MAXDouble512VectorTestsMaskedWithMemOp(IntFunction<double[]> fa, IntFunction<boolean[]> fm) {
2180         double[] a = fa.apply(SPECIES.length());
2181         double[] r = fr.apply(SPECIES.length());
2182         boolean[] mask = fm.apply(SPECIES.length());
2183         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2184 
2185         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2186             for (int i = 0; i < a.length; i += SPECIES.length()) {
2187                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2188                 av.lanewise(VectorOperators.MAX, bcast_vec, vmask).intoArray(r, i);
2189             }
2190         }
2191 
2192         assertArraysEquals(r, a, (double)10, mask, Double512VectorTests::MAX);
2193     }
2194 
2195     static double MIN(double a, double b) {
2196         return (double)(Math.min(a, b));
2197     }
2198 
2199     @Test(dataProvider = "doubleBinaryOpProvider")
2200     static void MINDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2201         double[] a = fa.apply(SPECIES.length());
2202         double[] b = fb.apply(SPECIES.length());
2203         double[] r = fr.apply(SPECIES.length());
2204 
2205         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2206             for (int i = 0; i < a.length; i += SPECIES.length()) {
2207                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2208                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
< prev index next >