1 /*
   2  * Copyright (c) 2018, 2020, 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  */
  23 
  24 /*
  25  * @test
  26  * @modules jdk.incubator.vector
  27  * @run testng/othervm -ea -esa -Xbatch Double512VectorTests
  28  */
  29 
  30 // -- This file was mechanically generated: Do not edit! -- //
  31 
  32 import jdk.incubator.vector.VectorShape;
  33 import jdk.incubator.vector.VectorSpecies;
  34 import jdk.incubator.vector.VectorShuffle;
  35 import jdk.incubator.vector.VectorMask;
  36 import jdk.incubator.vector.VectorOperators;
  37 import jdk.incubator.vector.Vector;
  38 
  39 import jdk.incubator.vector.DoubleVector;
  40 
  41 import org.testng.Assert;
  42 import org.testng.annotations.DataProvider;
  43 import org.testng.annotations.Test;
  44 
  45 import java.lang.Integer;
  46 import java.util.List;
  47 import java.util.Arrays;
  48 import java.util.function.BiFunction;
  49 import java.util.function.IntFunction;
  50 import java.util.stream.Collectors;
  51 import java.util.stream.Stream;
  52 
  53 @Test
  54 public class Double512VectorTests extends AbstractVectorTest {
  55 
  56     static final VectorSpecies<Double> SPECIES =
  57                 DoubleVector.SPECIES_512;
  58 
  59     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  60 
  61 
  62     static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
  63 
  64     static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (512 / 8));
  65 
  66     interface FUnOp {
  67         double apply(double a);
  68     }
  69 
  70     static void assertArraysEquals(double[] a, double[] r, FUnOp f) {
  71         int i = 0;
  72         try {
  73             for (; i < a.length; i++) {
  74                 Assert.assertEquals(r[i], f.apply(a[i]));
  75             }
  76         } catch (AssertionError e) {
  77             Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
  78         }
  79     }
  80 
  81     interface FUnArrayOp {
  82         double[] apply(double a);
  83     }
  84 
  85     static void assertArraysEquals(double[] a, double[] r, FUnArrayOp f) {
  86         int i = 0;
  87         try {
  88             for (; i < a.length; i += SPECIES.length()) {
  89                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
  90                   f.apply(a[i]));
  91             }
  92         } catch (AssertionError e) {
  93             double[] ref = f.apply(a[i]);
  94             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
  95             Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref)
  96               + ", res: " + Arrays.toString(res)
  97               + "), at index #" + i);
  98         }
  99     }
 100 
 101     static void assertArraysEquals(double[] a, double[] r, boolean[] mask, FUnOp f) {
 102         int i = 0;
 103         try {
 104             for (; i < a.length; i++) {
 105                 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]);
 106             }
 107         } catch (AssertionError e) {
 108             Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i], "at index #" + i + ", input = " + a[i] + ", mask = " + mask[i % SPECIES.length()]);
 109         }
 110     }
 111 
 112     interface FReductionOp {
 113         double apply(double[] a, int idx);
 114     }
 115 
 116     interface FReductionAllOp {
 117         double apply(double[] a);
 118     }
 119 
 120     static void assertReductionArraysEquals(double[] a, double[] b, double c,
 121                                             FReductionOp f, FReductionAllOp fa) {
 122         int i = 0;
 123         try {
 124             Assert.assertEquals(c, fa.apply(a));
 125             for (; i < a.length; i += SPECIES.length()) {
 126                 Assert.assertEquals(b[i], f.apply(a, i));
 127             }
 128         } catch (AssertionError e) {
 129             Assert.assertEquals(c, fa.apply(a), "Final result is incorrect!");
 130             Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i);
 131         }
 132     }
 133 
 134     interface FReductionMaskedOp {
 135         double apply(double[] a, int idx, boolean[] mask);
 136     }
 137 
 138     interface FReductionAllMaskedOp {
 139         double apply(double[] a, boolean[] mask);
 140     }
 141 
 142     static void assertReductionArraysEqualsMasked(double[] a, double[] b, double c, boolean[] mask,
 143                                             FReductionMaskedOp f, FReductionAllMaskedOp fa) {
 144         int i = 0;
 145         try {
 146             Assert.assertEquals(c, fa.apply(a, mask));
 147             for (; i < a.length; i += SPECIES.length()) {
 148                 Assert.assertEquals(b[i], f.apply(a, i, mask));
 149             }
 150         } catch (AssertionError e) {
 151             Assert.assertEquals(c, fa.apply(a, mask), "Final result is incorrect!");
 152             Assert.assertEquals(b[i], f.apply(a, i, mask), "at index #" + i);
 153         }
 154     }
 155 
 156     interface FBoolReductionOp {
 157         boolean apply(boolean[] a, int idx);
 158     }
 159 
 160     static void assertReductionBoolArraysEquals(boolean[] a, boolean[] b, FBoolReductionOp f) {
 161         int i = 0;
 162         try {
 163             for (; i < a.length; i += SPECIES.length()) {
 164                 Assert.assertEquals(b[i], f.apply(a, i));
 165             }
 166         } catch (AssertionError e) {
 167             Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i);
 168         }
 169     }
 170 
 171     static void assertInsertArraysEquals(double[] a, double[] b, double element, int index) {
 172         int i = 0;
 173         try {
 174             for (; i < a.length; i += 1) {
 175                 if(i%SPECIES.length() == index) {
 176                     Assert.assertEquals(b[i], element);
 177                 } else {
 178                     Assert.assertEquals(b[i], a[i]);
 179                 }
 180             }
 181         } catch (AssertionError e) {
 182             if (i%SPECIES.length() == index) {
 183                 Assert.assertEquals(b[i], element, "at index #" + i);
 184             } else {
 185                 Assert.assertEquals(b[i], a[i], "at index #" + i);
 186             }
 187         }
 188     }
 189 
 190     static void assertRearrangeArraysEquals(double[] a, double[] r, int[] order, int vector_len) {
 191         int i = 0, j = 0;
 192         try {
 193             for (; i < a.length; i += vector_len) {
 194                 for (j = 0; j < vector_len; j++) {
 195                     Assert.assertEquals(r[i+j], a[i+order[i+j]]);
 196                 }
 197             }
 198         } catch (AssertionError e) {
 199             int idx = i + j;
 200             Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
 201         }
 202     }
 203 
 204     static void assertBroadcastArraysEquals(double[]a, double[]r) {
 205         int i = 0;
 206         for (; i < a.length; i += SPECIES.length()) {
 207             int idx = i;
 208             for (int j = idx; j < (idx + SPECIES.length()); j++)
 209                 a[j]=a[idx];
 210         }
 211 
 212         try {
 213             for (i = 0; i < a.length; i++) {
 214                 Assert.assertEquals(r[i], a[i]);
 215             }
 216         } catch (AssertionError e) {
 217             Assert.assertEquals(r[i], a[i], "at index #" + i + ", input = " + a[i]);
 218         }
 219     }
 220 
 221     interface FBinOp {
 222         double apply(double a, double b);
 223     }
 224 
 225     interface FBinMaskOp {
 226         double apply(double a, double b, boolean m);
 227 
 228         static FBinMaskOp lift(FBinOp f) {
 229             return (a, b, m) -> m ? f.apply(a, b) : a;
 230         }
 231     }
 232 
 233     static void assertArraysEquals(double[] a, double[] b, double[] r, FBinOp f) {
 234         int i = 0;
 235         try {
 236             for (; i < a.length; i++) {
 237                 Assert.assertEquals(r[i], f.apply(a[i], b[i]));
 238             }
 239         } catch (AssertionError e) {
 240             Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i);
 241         }
 242     }
 243 
 244     static void assertArraysEquals(double[] a, double[] b, double[] r, boolean[] mask, FBinOp f) {
 245         assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 246     }
 247 
 248     static void assertArraysEquals(double[] a, double[] b, double[] r, boolean[] mask, FBinMaskOp f) {
 249         int i = 0;
 250         try {
 251             for (; i < a.length; i++) {
 252                 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]));
 253             }
 254         } catch (AssertionError err) {
 255             Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", mask = " + mask[i % SPECIES.length()]);
 256         }
 257     }
 258 
 259     static void assertShiftArraysEquals(double[] a, double[] b, double[] r, FBinOp f) {
 260         int i = 0;
 261         int j = 0;
 262         try {
 263             for (; j < a.length; j += SPECIES.length()) {
 264                 for (i = 0; i < SPECIES.length(); i++) {
 265                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]));
 266                 }
 267             }
 268         } catch (AssertionError e) {
 269             Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j);
 270         }
 271     }
 272 
 273     static void assertShiftArraysEquals(double[] a, double[] b, double[] r, boolean[] mask, FBinOp f) {
 274         assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 275     }
 276 
 277     static void assertShiftArraysEquals(double[] a, double[] b, double[] r, boolean[] mask, FBinMaskOp f) {
 278         int i = 0;
 279         int j = 0;
 280         try {
 281             for (; j < a.length; j += SPECIES.length()) {
 282                 for (i = 0; i < SPECIES.length(); i++) {
 283                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i]));
 284                 }
 285             }
 286         } catch (AssertionError err) {
 287             Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i]), "at index #" + i + ", input1 = " + a[i+j] + ", input2 = " + b[j] + ", mask = " + mask[i]);
 288         }
 289     }
 290 
 291     interface FTernOp {
 292         double apply(double a, double b, double c);
 293     }
 294 
 295     interface FTernMaskOp {
 296         double apply(double a, double b, double c, boolean m);
 297 
 298         static FTernMaskOp lift(FTernOp f) {
 299             return (a, b, c, m) -> m ? f.apply(a, b, c) : a;
 300         }
 301     }
 302 
 303     static void assertArraysEquals(double[] a, double[] b, double[] c, double[] r, FTernOp f) {
 304         int i = 0;
 305         try {
 306             for (; i < a.length; i++) {
 307                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]));
 308             }
 309         } catch (AssertionError e) {
 310             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
 311         }
 312     }
 313 
 314     static void assertArraysEquals(double[] a, double[] b, double[] c, double[] r, boolean[] mask, FTernOp f) {
 315         assertArraysEquals(a, b, c, r, mask, FTernMaskOp.lift(f));
 316     }
 317 
 318     static void assertArraysEquals(double[] a, double[] b, double[] c, double[] r, boolean[] mask, FTernMaskOp f) {
 319         int i = 0;
 320         try {
 321             for (; i < a.length; i++) {
 322                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]));
 323             }
 324         } catch (AssertionError err) {
 325             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = "
 326               + b[i] + ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]);
 327         }
 328     }
 329 
 330     static boolean isWithin1Ulp(double actual, double expected) {
 331         if (Double.isNaN(expected) && !Double.isNaN(actual)) {
 332             return false;
 333         } else if (!Double.isNaN(expected) && Double.isNaN(actual)) {
 334             return false;
 335         }
 336 
 337         double low = Math.nextDown(expected);
 338         double high = Math.nextUp(expected);
 339 
 340         if (Double.compare(low, expected) > 0) {
 341             return false;
 342         }
 343 
 344         if (Double.compare(high, expected) < 0) {
 345             return false;
 346         }
 347 
 348         return true;
 349     }
 350 
 351     static void assertArraysEqualsWithinOneUlp(double[] a, double[] r, FUnOp mathf, FUnOp strictmathf) {
 352         int i = 0;
 353         try {
 354             // Check that result is within 1 ulp of strict math or equivalent to math implementation.
 355             for (; i < a.length; i++) {
 356                 Assert.assertTrue(Double.compare(r[i], mathf.apply(a[i])) == 0 ||
 357                                     isWithin1Ulp(r[i], strictmathf.apply(a[i])));
 358             }
 359         } catch (AssertionError e) {
 360             Assert.assertTrue(Double.compare(r[i], mathf.apply(a[i])) == 0, "at index #" + i + ", input = " + a[i] + ", actual = " + r[i] + ", expected = " + mathf.apply(a[i]));
 361             Assert.assertTrue(isWithin1Ulp(r[i], strictmathf.apply(a[i])), "at index #" + i + ", input = " + a[i] + ", actual = " + r[i] + ", expected (within 1 ulp) = " + strictmathf.apply(a[i]));
 362         }
 363     }
 364 
 365     static void assertArraysEqualsWithinOneUlp(double[] a, double[] b, double[] r, FBinOp mathf, FBinOp strictmathf) {
 366         int i = 0;
 367         try {
 368             // Check that result is within 1 ulp of strict math or equivalent to math implementation.
 369             for (; i < a.length; i++) {
 370                 Assert.assertTrue(Double.compare(r[i], mathf.apply(a[i], b[i])) == 0 ||
 371                                     isWithin1Ulp(r[i], strictmathf.apply(a[i], b[i])));
 372             }
 373         } catch (AssertionError e) {
 374             Assert.assertTrue(Double.compare(r[i], mathf.apply(a[i], b[i])) == 0, "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", actual = " + r[i] + ", expected = " + mathf.apply(a[i], b[i]));
 375             Assert.assertTrue(isWithin1Ulp(r[i], strictmathf.apply(a[i], b[i])), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", actual = " + r[i] + ", expected (within 1 ulp) = " + strictmathf.apply(a[i], b[i]));
 376         }
 377     }
 378 
 379     interface FBinArrayOp {
 380         double apply(double[] a, int b);
 381     }
 382 
 383     static void assertArraysEquals(double[] a, double[] r, FBinArrayOp f) {
 384         int i = 0;
 385         try {
 386             for (; i < a.length; i++) {
 387                 Assert.assertEquals(r[i], f.apply(a, i));
 388             }
 389         } catch (AssertionError e) {
 390             Assert.assertEquals(r[i], f.apply(a,i), "at index #" + i);
 391         }
 392     }
 393 
 394     interface FGatherScatterOp {
 395         double[] apply(double[] a, int ix, int[] b, int iy);
 396     }
 397 
 398     static void assertArraysEquals(double[] a, int[] b, double[] r, FGatherScatterOp f) {
 399         int i = 0;
 400         try {
 401             for (; i < a.length; i += SPECIES.length()) {
 402                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 403                   f.apply(a, i, b, i));
 404             }
 405         } catch (AssertionError e) {
 406             double[] ref = f.apply(a, i, b, i);
 407             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 408             Assert.assertEquals(res, ref,
 409               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 410               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 411               + ", b: "
 412               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 413               + " at index #" + i);
 414         }
 415     }
 416 
 417     interface FGatherMaskedOp {
 418         double[] apply(double[] a, int ix, boolean[] mask, int[] b, int iy);
 419     }
 420 
 421     interface FScatterMaskedOp {
 422         double[] apply(double[] r, double[] a, int ix, boolean[] mask, int[] b, int iy);
 423     }
 424 
 425     static void assertArraysEquals(double[] a, int[] b, double[] r, boolean[] mask, FGatherMaskedOp f) {
 426         int i = 0;
 427         try {
 428             for (; i < a.length; i += SPECIES.length()) {
 429                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 430                   f.apply(a, i, mask, b, i));
 431             }
 432         } catch (AssertionError e) {
 433             double[] ref = f.apply(a, i, mask, b, i);
 434             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 435             Assert.assertEquals(ref, res,
 436               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 437               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 438               + ", b: "
 439               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 440               + ", mask: "
 441               + Arrays.toString(mask)
 442               + " at index #" + i);
 443         }
 444     }
 445 
 446     static void assertArraysEquals(double[] a, int[] b, double[] r, boolean[] mask, FScatterMaskedOp f) {
 447         int i = 0;
 448         try {
 449             for (; i < a.length; i += SPECIES.length()) {
 450                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 451                   f.apply(r, a, i, mask, b, i));
 452             }
 453         } catch (AssertionError e) {
 454             double[] ref = f.apply(r, a, i, mask, b, i);
 455             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 456             Assert.assertEquals(ref, res,
 457               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 458               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 459               + ", b: "
 460               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 461               + ", r: "
 462               + Arrays.toString(Arrays.copyOfRange(r, i, i+SPECIES.length()))
 463               + ", mask: "
 464               + Arrays.toString(mask)
 465               + " at index #" + i);
 466         }
 467     }
 468 
 469     interface FLaneOp {
 470         double[] apply(double[] a, int origin, int idx);
 471     }
 472 
 473     static void assertArraysEquals(double[] a, double[] r, int origin, FLaneOp f) {
 474         int i = 0;
 475         try {
 476             for (; i < a.length; i += SPECIES.length()) {
 477                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 478                   f.apply(a, origin, i));
 479             }
 480         } catch (AssertionError e) {
 481             double[] ref = f.apply(a, origin, i);
 482             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 483             Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref)
 484               + ", res: " + Arrays.toString(res)
 485               + "), at index #" + i);
 486         }
 487     }
 488 
 489     interface FLaneBop {
 490         double[] apply(double[] a, double[] b, int origin, int idx);
 491     }
 492 
 493     static void assertArraysEquals(double[] a, double[] b, double[] r, int origin, FLaneBop f) {
 494         int i = 0;
 495         try {
 496             for (; i < a.length; i += SPECIES.length()) {
 497                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 498                   f.apply(a, b, origin, i));
 499             }
 500         } catch (AssertionError e) {
 501             double[] ref = f.apply(a, b, origin, i);
 502             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 503             Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref)
 504               + ", res: " + Arrays.toString(res)
 505               + "), at index #" + i
 506               + ", at origin #" + origin);
 507         }
 508     }
 509 
 510     interface FLaneMaskedBop {
 511         double[] apply(double[] a, double[] b, int origin, boolean[] mask, int idx);
 512     }
 513 
 514     static void assertArraysEquals(double[] a, double[] b, double[] r, int origin, boolean[] mask, FLaneMaskedBop f) {
 515         int i = 0;
 516         try {
 517             for (; i < a.length; i += SPECIES.length()) {
 518                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 519                   f.apply(a, b, origin, mask, i));
 520             }
 521         } catch (AssertionError e) {
 522             double[] ref = f.apply(a, b, origin, mask, i);
 523             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 524             Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref)
 525               + ", res: " + Arrays.toString(res)
 526               + "), at index #" + i
 527               + ", at origin #" + origin);
 528         }
 529     }
 530 
 531     interface FLanePartBop {
 532         double[] apply(double[] a, double[] b, int origin, int part, int idx);
 533     }
 534 
 535     static void assertArraysEquals(double[] a, double[] b, double[] r, int origin, int part, FLanePartBop f) {
 536         int i = 0;
 537         try {
 538             for (; i < a.length; i += SPECIES.length()) {
 539                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 540                   f.apply(a, b, origin, part, i));
 541             }
 542         } catch (AssertionError e) {
 543             double[] ref = f.apply(a, b, origin, part, i);
 544             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 545             Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref)
 546               + ", res: " + Arrays.toString(res)
 547               + "), at index #" + i
 548               + ", at origin #" + origin
 549               + ", with part #" + part);
 550         }
 551     }
 552 
 553     interface FLanePartMaskedBop {
 554         double[] apply(double[] a, double[] b, int origin, int part, boolean[] mask, int idx);
 555     }
 556 
 557     static void assertArraysEquals(double[] a, double[] b, double[] r, int origin, int part, boolean[] mask, FLanePartMaskedBop f) {
 558         int i = 0;
 559         try {
 560             for (; i < a.length; i += SPECIES.length()) {
 561                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 562                   f.apply(a, b, origin, part, mask, i));
 563             }
 564         } catch (AssertionError e) {
 565             double[] ref = f.apply(a, b, origin, part, mask, i);
 566             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 567             Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref)
 568               + ", res: " + Arrays.toString(res)
 569               + "), at index #" + i
 570               + ", at origin #" + origin
 571               + ", with part #" + part);
 572         }
 573     }
 574 
 575     static long bits(double e) {
 576         return  Double.doubleToLongBits(e);
 577     }
 578 
 579     static final List<IntFunction<double[]>> DOUBLE_GENERATORS = List.of(
 580             withToString("double[-i * 5]", (int s) -> {
 581                 return fill(s * BUFFER_REPS,
 582                             i -> (double)(-i * 5));
 583             }),
 584             withToString("double[i * 5]", (int s) -> {
 585                 return fill(s * BUFFER_REPS,
 586                             i -> (double)(i * 5));
 587             }),
 588             withToString("double[i + 1]", (int s) -> {
 589                 return fill(s * BUFFER_REPS,
 590                             i -> (((double)(i + 1) == 0) ? 1 : (double)(i + 1)));
 591             }),
 592             withToString("double[cornerCaseValue(i)]", (int s) -> {
 593                 return fill(s * BUFFER_REPS,
 594                             i -> cornerCaseValue(i));
 595             })
 596     );
 597 
 598     // Create combinations of pairs
 599     // @@@ Might be sensitive to order e.g. div by 0
 600     static final List<List<IntFunction<double[]>>> DOUBLE_GENERATOR_PAIRS =
 601         Stream.of(DOUBLE_GENERATORS.get(0)).
 602                 flatMap(fa -> DOUBLE_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
 603                 collect(Collectors.toList());
 604 
 605     @DataProvider
 606     public Object[][] boolUnaryOpProvider() {
 607         return BOOL_ARRAY_GENERATORS.stream().
 608                 map(f -> new Object[]{f}).
 609                 toArray(Object[][]::new);
 610     }
 611 
 612     static final List<List<IntFunction<double[]>>> DOUBLE_GENERATOR_TRIPLES =
 613         DOUBLE_GENERATOR_PAIRS.stream().
 614                 flatMap(pair -> DOUBLE_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))).
 615                 collect(Collectors.toList());
 616 
 617     @DataProvider
 618     public Object[][] doubleBinaryOpProvider() {
 619         return DOUBLE_GENERATOR_PAIRS.stream().map(List::toArray).
 620                 toArray(Object[][]::new);
 621     }
 622 
 623     @DataProvider
 624     public Object[][] doubleIndexedOpProvider() {
 625         return DOUBLE_GENERATOR_PAIRS.stream().map(List::toArray).
 626                 toArray(Object[][]::new);
 627     }
 628 
 629     @DataProvider
 630     public Object[][] doubleBinaryOpMaskProvider() {
 631         return BOOLEAN_MASK_GENERATORS.stream().
 632                 flatMap(fm -> DOUBLE_GENERATOR_PAIRS.stream().map(lfa -> {
 633                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
 634                 })).
 635                 toArray(Object[][]::new);
 636     }
 637 
 638     @DataProvider
 639     public Object[][] doubleTernaryOpProvider() {
 640         return DOUBLE_GENERATOR_TRIPLES.stream().map(List::toArray).
 641                 toArray(Object[][]::new);
 642     }
 643 
 644     @DataProvider
 645     public Object[][] doubleTernaryOpMaskProvider() {
 646         return BOOLEAN_MASK_GENERATORS.stream().
 647                 flatMap(fm -> DOUBLE_GENERATOR_TRIPLES.stream().map(lfa -> {
 648                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
 649                 })).
 650                 toArray(Object[][]::new);
 651     }
 652 
 653     @DataProvider
 654     public Object[][] doubleUnaryOpProvider() {
 655         return DOUBLE_GENERATORS.stream().
 656                 map(f -> new Object[]{f}).
 657                 toArray(Object[][]::new);
 658     }
 659 
 660     @DataProvider
 661     public Object[][] doubleUnaryOpMaskProvider() {
 662         return BOOLEAN_MASK_GENERATORS.stream().
 663                 flatMap(fm -> DOUBLE_GENERATORS.stream().map(fa -> {
 664                     return new Object[] {fa, fm};
 665                 })).
 666                 toArray(Object[][]::new);
 667     }
 668 
 669     @DataProvider
 670     public Object[][] doubleUnaryOpShuffleProvider() {
 671         return INT_SHUFFLE_GENERATORS.stream().
 672                 flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> {
 673                     return new Object[] {fa, fs};
 674                 })).
 675                 toArray(Object[][]::new);
 676     }
 677 
 678     @DataProvider
 679     public Object[][] doubleUnaryOpIndexProvider() {
 680         return INT_INDEX_GENERATORS.stream().
 681                 flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> {
 682                     return new Object[] {fa, fs};
 683                 })).
 684                 toArray(Object[][]::new);
 685     }
 686 
 687     @DataProvider
 688     public Object[][] doubleUnaryMaskedOpIndexProvider() {
 689         return BOOLEAN_MASK_GENERATORS.stream().
 690           flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm ->
 691             DOUBLE_GENERATORS.stream().map(fa -> {
 692                     return new Object[] {fa, fm, fs};
 693             }))).
 694             toArray(Object[][]::new);
 695     }
 696 
 697     @DataProvider
 698     public Object[][] scatterMaskedOpIndexProvider() {
 699         return BOOLEAN_MASK_GENERATORS.stream().
 700           flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm ->
 701             DOUBLE_GENERATORS.stream().flatMap(fn ->
 702               DOUBLE_GENERATORS.stream().map(fa -> {
 703                     return new Object[] {fa, fn, fm, fs};
 704             })))).
 705             toArray(Object[][]::new);
 706     }
 707 
 708     static final List<IntFunction<double[]>> DOUBLE_COMPARE_GENERATORS = List.of(
 709             withToString("double[i]", (int s) -> {
 710                 return fill(s * BUFFER_REPS,
 711                             i -> (double)i);
 712             }),
 713             withToString("double[i + 1]", (int s) -> {
 714                 return fill(s * BUFFER_REPS,
 715                             i -> (double)(i + 1));
 716             }),
 717             withToString("double[i - 2]", (int s) -> {
 718                 return fill(s * BUFFER_REPS,
 719                             i -> (double)(i - 2));
 720             }),
 721             withToString("double[zigZag(i)]", (int s) -> {
 722                 return fill(s * BUFFER_REPS,
 723                             i -> i%3 == 0 ? (double)i : (i%3 == 1 ? (double)(i + 1) : (double)(i - 2)));
 724             }),
 725             withToString("double[cornerCaseValue(i)]", (int s) -> {
 726                 return fill(s * BUFFER_REPS,
 727                             i -> cornerCaseValue(i));
 728             })
 729     );
 730 
 731     static final List<List<IntFunction<double[]>>> DOUBLE_TEST_GENERATOR_ARGS =
 732         DOUBLE_COMPARE_GENERATORS.stream().
 733                 map(fa -> List.of(fa)).
 734                 collect(Collectors.toList());
 735 
 736     @DataProvider
 737     public Object[][] doubleTestOpProvider() {
 738         return DOUBLE_TEST_GENERATOR_ARGS.stream().map(List::toArray).
 739                 toArray(Object[][]::new);
 740     }
 741 
 742     static final List<List<IntFunction<double[]>>> DOUBLE_COMPARE_GENERATOR_PAIRS =
 743         DOUBLE_COMPARE_GENERATORS.stream().
 744                 flatMap(fa -> DOUBLE_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))).
 745                 collect(Collectors.toList());
 746 
 747     @DataProvider
 748     public Object[][] doubleCompareOpProvider() {
 749         return DOUBLE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
 750                 toArray(Object[][]::new);
 751     }
 752 
 753     interface ToDoubleF {
 754         double apply(int i);
 755     }
 756 
 757     static double[] fill(int s , ToDoubleF f) {
 758         return fill(new double[s], f);
 759     }
 760 
 761     static double[] fill(double[] a, ToDoubleF f) {
 762         for (int i = 0; i < a.length; i++) {
 763             a[i] = f.apply(i);
 764         }
 765         return a;
 766     }
 767 
 768     static double cornerCaseValue(int i) {
 769         switch(i % 7) {
 770             case 0:
 771                 return Double.MAX_VALUE;
 772             case 1:
 773                 return Double.MIN_VALUE;
 774             case 2:
 775                 return Double.NEGATIVE_INFINITY;
 776             case 3:
 777                 return Double.POSITIVE_INFINITY;
 778             case 4:
 779                 return Double.NaN;
 780             case 5:
 781                 return (double)0.0;
 782             default:
 783                 return (double)-0.0;
 784         }
 785     }
 786    static double get(double[] a, int i) {
 787        return (double) a[i];
 788    }
 789 
 790    static final IntFunction<double[]> fr = (vl) -> {
 791         int length = BUFFER_REPS * vl;
 792         return new double[length];
 793     };
 794 
 795     static final IntFunction<boolean[]> fmr = (vl) -> {
 796         int length = BUFFER_REPS * vl;
 797         return new boolean[length];
 798     };
 799 
 800 
 801     @Test
 802     static void smokeTest1() {
 803         DoubleVector three = DoubleVector.broadcast(SPECIES, (byte)-3);
 804         DoubleVector three2 = (DoubleVector) SPECIES.broadcast(-3);
 805         assert(three.eq(three2).allTrue());
 806         DoubleVector three3 = three2.broadcast(1).broadcast(-3);
 807         assert(three.eq(three3).allTrue());
 808         int scale = 2;
 809         Class<?> ETYPE = double.class;
 810         if (ETYPE == double.class || ETYPE == long.class)
 811             scale = 1000000;
 812         else if (ETYPE == byte.class && SPECIES.length() >= 64)
 813             scale = 1;
 814         DoubleVector higher = three.addIndex(scale);
 815         VectorMask<Double> m = three.compare(VectorOperators.LE, higher);
 816         assert(m.allTrue());
 817         m = higher.min((double)-1).test(VectorOperators.IS_NEGATIVE);
 818         assert(m.allTrue());
 819         m = higher.test(VectorOperators.IS_FINITE);
 820         assert(m.allTrue());
 821         double max = higher.reduceLanes(VectorOperators.MAX);
 822         assert(max == -3 + scale * (SPECIES.length()-1));
 823     }
 824 
 825     private static double[]
 826     bothToArray(DoubleVector a, DoubleVector b) {
 827         double[] r = new double[a.length() + b.length()];
 828         a.intoArray(r, 0);
 829         b.intoArray(r, a.length());
 830         return r;
 831     }
 832 
 833     @Test
 834     static void smokeTest2() {
 835         // Do some zipping and shuffling.
 836         DoubleVector io = (DoubleVector) SPECIES.broadcast(0).addIndex(1);
 837         DoubleVector io2 = (DoubleVector) VectorShuffle.iota(SPECIES,0,1,false).toVector();
 838         Assert.assertEquals(io, io2);
 839         DoubleVector a = io.add((double)1); //[1,2]
 840         DoubleVector b = a.neg();  //[-1,-2]
 841         double[] abValues = bothToArray(a,b); //[1,2,-1,-2]
 842         VectorShuffle<Double> zip0 = VectorShuffle.makeZip(SPECIES, 0);
 843         VectorShuffle<Double> zip1 = VectorShuffle.makeZip(SPECIES, 1);
 844         DoubleVector zab0 = a.rearrange(zip0,b); //[1,-1]
 845         DoubleVector zab1 = a.rearrange(zip1,b); //[2,-2]
 846         double[] zabValues = bothToArray(zab0, zab1); //[1,-1,2,-2]
 847         // manually zip
 848         double[] manual = new double[zabValues.length];
 849         for (int i = 0; i < manual.length; i += 2) {
 850             manual[i+0] = abValues[i/2];
 851             manual[i+1] = abValues[a.length() + i/2];
 852         }
 853         Assert.assertEquals(Arrays.toString(zabValues), Arrays.toString(manual));
 854         VectorShuffle<Double> unz0 = VectorShuffle.makeUnzip(SPECIES, 0);
 855         VectorShuffle<Double> unz1 = VectorShuffle.makeUnzip(SPECIES, 1);
 856         DoubleVector uab0 = zab0.rearrange(unz0,zab1);
 857         DoubleVector uab1 = zab0.rearrange(unz1,zab1);
 858         double[] abValues1 = bothToArray(uab0, uab1);
 859         Assert.assertEquals(Arrays.toString(abValues), Arrays.toString(abValues1));
 860     }
 861 
 862     static void iotaShuffle() {
 863         DoubleVector io = (DoubleVector) SPECIES.broadcast(0).addIndex(1);
 864         DoubleVector io2 = (DoubleVector) VectorShuffle.iota(SPECIES, 0 , 1, false).toVector();
 865         Assert.assertEquals(io, io2);
 866     }
 867 
 868     @Test
 869     // Test all shuffle related operations.
 870     static void shuffleTest() {
 871         // To test backend instructions, make sure that C2 is used.
 872         for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) {
 873             iotaShuffle();
 874         }
 875     }
 876 
 877     @Test
 878     void viewAsIntegeralLanesTest() {
 879         Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes();
 880         VectorSpecies<?> asIntegralSpecies = asIntegral.species();
 881         Assert.assertNotEquals(asIntegralSpecies.elementType(), SPECIES.elementType());
 882         Assert.assertEquals(asIntegralSpecies.vectorShape(), SPECIES.vectorShape());
 883         Assert.assertEquals(asIntegralSpecies.length(), SPECIES.length());
 884         Assert.assertEquals(asIntegral.viewAsFloatingLanes().species(), SPECIES);
 885     }
 886 
 887     @Test
 888     void viewAsFloatingLanesTest() {
 889         Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes();
 890         Assert.assertEquals(asFloating.species(), SPECIES);
 891     }
 892 
 893     static double ADD(double a, double b) {
 894         return (double)(a + b);
 895     }
 896 
 897     @Test(dataProvider = "doubleBinaryOpProvider")
 898     static void ADDDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
 899         double[] a = fa.apply(SPECIES.length());
 900         double[] b = fb.apply(SPECIES.length());
 901         double[] r = fr.apply(SPECIES.length());
 902 
 903         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 904             for (int i = 0; i < a.length; i += SPECIES.length()) {
 905                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 906                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 907                 av.lanewise(VectorOperators.ADD, bv).intoArray(r, i);
 908             }
 909         }
 910 
 911         assertArraysEquals(a, b, r, Double512VectorTests::ADD);
 912     }
 913     static double add(double a, double b) {
 914         return (double)(a + b);
 915     }
 916 
 917     @Test(dataProvider = "doubleBinaryOpProvider")
 918     static void addDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
 919         double[] a = fa.apply(SPECIES.length());
 920         double[] b = fb.apply(SPECIES.length());
 921         double[] r = fr.apply(SPECIES.length());
 922 
 923         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 924             for (int i = 0; i < a.length; i += SPECIES.length()) {
 925                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 926                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 927                 av.add(bv).intoArray(r, i);
 928             }
 929         }
 930 
 931         assertArraysEquals(a, b, r, Double512VectorTests::add);
 932     }
 933 
 934     @Test(dataProvider = "doubleBinaryOpMaskProvider")
 935     static void ADDDouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
 936                                           IntFunction<boolean[]> fm) {
 937         double[] a = fa.apply(SPECIES.length());
 938         double[] b = fb.apply(SPECIES.length());
 939         double[] r = fr.apply(SPECIES.length());
 940         boolean[] mask = fm.apply(SPECIES.length());
 941         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
 942 
 943         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 944             for (int i = 0; i < a.length; i += SPECIES.length()) {
 945                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 946                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 947                 av.lanewise(VectorOperators.ADD, bv, vmask).intoArray(r, i);
 948             }
 949         }
 950 
 951         assertArraysEquals(a, b, r, mask, Double512VectorTests::ADD);
 952     }
 953 
 954     @Test(dataProvider = "doubleBinaryOpMaskProvider")
 955     static void addDouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
 956                                           IntFunction<boolean[]> fm) {
 957         double[] a = fa.apply(SPECIES.length());
 958         double[] b = fb.apply(SPECIES.length());
 959         double[] r = fr.apply(SPECIES.length());
 960         boolean[] mask = fm.apply(SPECIES.length());
 961         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
 962 
 963         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 964             for (int i = 0; i < a.length; i += SPECIES.length()) {
 965                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 966                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 967                 av.add(bv, vmask).intoArray(r, i);
 968             }
 969         }
 970 
 971         assertArraysEquals(a, b, r, mask, Double512VectorTests::add);
 972     }
 973     static double SUB(double a, double b) {
 974         return (double)(a - b);
 975     }
 976 
 977     @Test(dataProvider = "doubleBinaryOpProvider")
 978     static void SUBDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
 979         double[] a = fa.apply(SPECIES.length());
 980         double[] b = fb.apply(SPECIES.length());
 981         double[] r = fr.apply(SPECIES.length());
 982 
 983         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 984             for (int i = 0; i < a.length; i += SPECIES.length()) {
 985                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 986                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 987                 av.lanewise(VectorOperators.SUB, bv).intoArray(r, i);
 988             }
 989         }
 990 
 991         assertArraysEquals(a, b, r, Double512VectorTests::SUB);
 992     }
 993     static double sub(double a, double b) {
 994         return (double)(a - b);
 995     }
 996 
 997     @Test(dataProvider = "doubleBinaryOpProvider")
 998     static void subDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
 999         double[] a = fa.apply(SPECIES.length());
1000         double[] b = fb.apply(SPECIES.length());
1001         double[] r = fr.apply(SPECIES.length());
1002 
1003         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1004             for (int i = 0; i < a.length; i += SPECIES.length()) {
1005                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1006                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1007                 av.sub(bv).intoArray(r, i);
1008             }
1009         }
1010 
1011         assertArraysEquals(a, b, r, Double512VectorTests::sub);
1012     }
1013 
1014     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1015     static void SUBDouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1016                                           IntFunction<boolean[]> fm) {
1017         double[] a = fa.apply(SPECIES.length());
1018         double[] b = fb.apply(SPECIES.length());
1019         double[] r = fr.apply(SPECIES.length());
1020         boolean[] mask = fm.apply(SPECIES.length());
1021         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1022 
1023         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1024             for (int i = 0; i < a.length; i += SPECIES.length()) {
1025                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1026                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1027                 av.lanewise(VectorOperators.SUB, bv, vmask).intoArray(r, i);
1028             }
1029         }
1030 
1031         assertArraysEquals(a, b, r, mask, Double512VectorTests::SUB);
1032     }
1033 
1034     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1035     static void subDouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1036                                           IntFunction<boolean[]> fm) {
1037         double[] a = fa.apply(SPECIES.length());
1038         double[] b = fb.apply(SPECIES.length());
1039         double[] r = fr.apply(SPECIES.length());
1040         boolean[] mask = fm.apply(SPECIES.length());
1041         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1042 
1043         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1044             for (int i = 0; i < a.length; i += SPECIES.length()) {
1045                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1046                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1047                 av.sub(bv, vmask).intoArray(r, i);
1048             }
1049         }
1050 
1051         assertArraysEquals(a, b, r, mask, Double512VectorTests::sub);
1052     }
1053     static double MUL(double a, double b) {
1054         return (double)(a * b);
1055     }
1056 
1057     @Test(dataProvider = "doubleBinaryOpProvider")
1058     static void MULDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1059         double[] a = fa.apply(SPECIES.length());
1060         double[] b = fb.apply(SPECIES.length());
1061         double[] r = fr.apply(SPECIES.length());
1062 
1063         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1064             for (int i = 0; i < a.length; i += SPECIES.length()) {
1065                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1066                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1067                 av.lanewise(VectorOperators.MUL, bv).intoArray(r, i);
1068             }
1069         }
1070 
1071         assertArraysEquals(a, b, r, Double512VectorTests::MUL);
1072     }
1073     static double mul(double a, double b) {
1074         return (double)(a * b);
1075     }
1076 
1077     @Test(dataProvider = "doubleBinaryOpProvider")
1078     static void mulDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1079         double[] a = fa.apply(SPECIES.length());
1080         double[] b = fb.apply(SPECIES.length());
1081         double[] r = fr.apply(SPECIES.length());
1082 
1083         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1084             for (int i = 0; i < a.length; i += SPECIES.length()) {
1085                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1086                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1087                 av.mul(bv).intoArray(r, i);
1088             }
1089         }
1090 
1091         assertArraysEquals(a, b, r, Double512VectorTests::mul);
1092     }
1093 
1094     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1095     static void MULDouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1096                                           IntFunction<boolean[]> fm) {
1097         double[] a = fa.apply(SPECIES.length());
1098         double[] b = fb.apply(SPECIES.length());
1099         double[] r = fr.apply(SPECIES.length());
1100         boolean[] mask = fm.apply(SPECIES.length());
1101         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1102 
1103         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1104             for (int i = 0; i < a.length; i += SPECIES.length()) {
1105                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1106                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1107                 av.lanewise(VectorOperators.MUL, bv, vmask).intoArray(r, i);
1108             }
1109         }
1110 
1111         assertArraysEquals(a, b, r, mask, Double512VectorTests::MUL);
1112     }
1113 
1114     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1115     static void mulDouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1116                                           IntFunction<boolean[]> fm) {
1117         double[] a = fa.apply(SPECIES.length());
1118         double[] b = fb.apply(SPECIES.length());
1119         double[] r = fr.apply(SPECIES.length());
1120         boolean[] mask = fm.apply(SPECIES.length());
1121         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1122 
1123         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1124             for (int i = 0; i < a.length; i += SPECIES.length()) {
1125                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1126                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1127                 av.mul(bv, vmask).intoArray(r, i);
1128             }
1129         }
1130 
1131         assertArraysEquals(a, b, r, mask, Double512VectorTests::mul);
1132     }
1133 
1134     static double DIV(double a, double b) {
1135         return (double)(a / b);
1136     }
1137 
1138     @Test(dataProvider = "doubleBinaryOpProvider")
1139     static void DIVDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1140         double[] a = fa.apply(SPECIES.length());
1141         double[] b = fb.apply(SPECIES.length());
1142         double[] r = fr.apply(SPECIES.length());
1143 
1144         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1145             for (int i = 0; i < a.length; i += SPECIES.length()) {
1146                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1147                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1148                 av.lanewise(VectorOperators.DIV, bv).intoArray(r, i);
1149             }
1150         }
1151 
1152         assertArraysEquals(a, b, r, Double512VectorTests::DIV);
1153     }
1154     static double div(double a, double b) {
1155         return (double)(a / b);
1156     }
1157 
1158     @Test(dataProvider = "doubleBinaryOpProvider")
1159     static void divDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1160         double[] a = fa.apply(SPECIES.length());
1161         double[] b = fb.apply(SPECIES.length());
1162         double[] r = fr.apply(SPECIES.length());
1163 
1164         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1165             for (int i = 0; i < a.length; i += SPECIES.length()) {
1166                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1167                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1168                 av.div(bv).intoArray(r, i);
1169             }
1170         }
1171 
1172         assertArraysEquals(a, b, r, Double512VectorTests::div);
1173     }
1174 
1175 
1176 
1177     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1178     static void DIVDouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1179                                           IntFunction<boolean[]> fm) {
1180         double[] a = fa.apply(SPECIES.length());
1181         double[] b = fb.apply(SPECIES.length());
1182         double[] r = fr.apply(SPECIES.length());
1183         boolean[] mask = fm.apply(SPECIES.length());
1184         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1185 
1186         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1187             for (int i = 0; i < a.length; i += SPECIES.length()) {
1188                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1189                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1190                 av.lanewise(VectorOperators.DIV, bv, vmask).intoArray(r, i);
1191             }
1192         }
1193 
1194         assertArraysEquals(a, b, r, mask, Double512VectorTests::DIV);
1195     }
1196 
1197     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1198     static void divDouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1199                                           IntFunction<boolean[]> fm) {
1200         double[] a = fa.apply(SPECIES.length());
1201         double[] b = fb.apply(SPECIES.length());
1202         double[] r = fr.apply(SPECIES.length());
1203         boolean[] mask = fm.apply(SPECIES.length());
1204         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1205 
1206         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1207             for (int i = 0; i < a.length; i += SPECIES.length()) {
1208                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1209                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1210                 av.div(bv, vmask).intoArray(r, i);
1211             }
1212         }
1213 
1214         assertArraysEquals(a, b, r, mask, Double512VectorTests::div);
1215     }
1216 
1217 
1218 
1219     static double FIRST_NONZERO(double a, double b) {
1220         return (double)(Double.doubleToLongBits(a)!=0?a:b);
1221     }
1222 
1223     @Test(dataProvider = "doubleBinaryOpProvider")
1224     static void FIRST_NONZERODouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1225         double[] a = fa.apply(SPECIES.length());
1226         double[] b = fb.apply(SPECIES.length());
1227         double[] r = fr.apply(SPECIES.length());
1228 
1229         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1230             for (int i = 0; i < a.length; i += SPECIES.length()) {
1231                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1232                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1233                 av.lanewise(VectorOperators.FIRST_NONZERO, bv).intoArray(r, i);
1234             }
1235         }
1236 
1237         assertArraysEquals(a, b, r, Double512VectorTests::FIRST_NONZERO);
1238     }
1239 
1240     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1241     static void FIRST_NONZERODouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1242                                           IntFunction<boolean[]> fm) {
1243         double[] a = fa.apply(SPECIES.length());
1244         double[] b = fb.apply(SPECIES.length());
1245         double[] r = fr.apply(SPECIES.length());
1246         boolean[] mask = fm.apply(SPECIES.length());
1247         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1248 
1249         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1250             for (int i = 0; i < a.length; i += SPECIES.length()) {
1251                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1252                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1253                 av.lanewise(VectorOperators.FIRST_NONZERO, bv, vmask).intoArray(r, i);
1254             }
1255         }
1256 
1257         assertArraysEquals(a, b, r, mask, Double512VectorTests::FIRST_NONZERO);
1258     }
1259 
1260 
1261 
1262 
1263 
1264 
1265 
1266 
1267 
1268 
1269 
1270 
1271 
1272 
1273 
1274 
1275 
1276 
1277 
1278 
1279 
1280 
1281 
1282 
1283 
1284 
1285 
1286 
1287 
1288 
1289 
1290 
1291 
1292 
1293 
1294 
1295 
1296 
1297 
1298 
1299 
1300 
1301 
1302 
1303     static double MIN(double a, double b) {
1304         return (double)(Math.min(a, b));
1305     }
1306 
1307     @Test(dataProvider = "doubleBinaryOpProvider")
1308     static void MINDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1309         double[] a = fa.apply(SPECIES.length());
1310         double[] b = fb.apply(SPECIES.length());
1311         double[] r = fr.apply(SPECIES.length());
1312 
1313         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1314             for (int i = 0; i < a.length; i += SPECIES.length()) {
1315                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1316                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1317                 av.lanewise(VectorOperators.MIN, bv).intoArray(r, i);
1318             }
1319         }
1320 
1321         assertArraysEquals(a, b, r, Double512VectorTests::MIN);
1322     }
1323     static double min(double a, double b) {
1324         return (double)(Math.min(a, b));
1325     }
1326 
1327     @Test(dataProvider = "doubleBinaryOpProvider")
1328     static void minDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1329         double[] a = fa.apply(SPECIES.length());
1330         double[] b = fb.apply(SPECIES.length());
1331         double[] r = fr.apply(SPECIES.length());
1332 
1333         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1334             for (int i = 0; i < a.length; i += SPECIES.length()) {
1335                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1336                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1337                 av.min(bv).intoArray(r, i);
1338             }
1339         }
1340 
1341         assertArraysEquals(a, b, r, Double512VectorTests::min);
1342     }
1343     static double MAX(double a, double b) {
1344         return (double)(Math.max(a, b));
1345     }
1346 
1347     @Test(dataProvider = "doubleBinaryOpProvider")
1348     static void MAXDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1349         double[] a = fa.apply(SPECIES.length());
1350         double[] b = fb.apply(SPECIES.length());
1351         double[] r = fr.apply(SPECIES.length());
1352 
1353         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1354             for (int i = 0; i < a.length; i += SPECIES.length()) {
1355                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1356                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1357                 av.lanewise(VectorOperators.MAX, bv).intoArray(r, i);
1358             }
1359         }
1360 
1361         assertArraysEquals(a, b, r, Double512VectorTests::MAX);
1362     }
1363     static double max(double a, double b) {
1364         return (double)(Math.max(a, b));
1365     }
1366 
1367     @Test(dataProvider = "doubleBinaryOpProvider")
1368     static void maxDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1369         double[] a = fa.apply(SPECIES.length());
1370         double[] b = fb.apply(SPECIES.length());
1371         double[] r = fr.apply(SPECIES.length());
1372 
1373         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1374             for (int i = 0; i < a.length; i += SPECIES.length()) {
1375                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1376                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1377                 av.max(bv).intoArray(r, i);
1378             }
1379         }
1380 
1381         assertArraysEquals(a, b, r, Double512VectorTests::max);
1382     }
1383 
1384 
1385 
1386 
1387 
1388 
1389 
1390 
1391 
1392 
1393 
1394 
1395     static double ADD(double[] a, int idx) {
1396         double res = 0;
1397         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1398             res += a[i];
1399         }
1400 
1401         return res;
1402     }
1403 
1404     static double ADD(double[] a) {
1405         double res = 0;
1406         for (int i = 0; i < a.length; i += SPECIES.length()) {
1407             double tmp = 0;
1408             for (int j = 0; j < SPECIES.length(); j++) {
1409                 tmp += a[i + j];
1410             }
1411             res += tmp;
1412         }
1413 
1414         return res;
1415     }
1416     @Test(dataProvider = "doubleUnaryOpProvider")
1417     static void ADDDouble512VectorTests(IntFunction<double[]> fa) {
1418         double[] a = fa.apply(SPECIES.length());
1419         double[] r = fr.apply(SPECIES.length());
1420         double ra = 0;
1421 
1422         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1423             for (int i = 0; i < a.length; i += SPECIES.length()) {
1424                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1425                 r[i] = av.reduceLanes(VectorOperators.ADD);
1426             }
1427         }
1428 
1429         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1430             ra = 0;
1431             for (int i = 0; i < a.length; i += SPECIES.length()) {
1432                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1433                 ra += av.reduceLanes(VectorOperators.ADD);
1434             }
1435         }
1436 
1437         assertReductionArraysEquals(a, r, ra, Double512VectorTests::ADD, Double512VectorTests::ADD);
1438     }
1439     static double ADDMasked(double[] a, int idx, boolean[] mask) {
1440         double res = 0;
1441         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1442             if(mask[i % SPECIES.length()])
1443                 res += a[i];
1444         }
1445 
1446         return res;
1447     }
1448 
1449     static double ADDMasked(double[] a, boolean[] mask) {
1450         double res = 0;
1451         for (int i = 0; i < a.length; i += SPECIES.length()) {
1452             double tmp = 0;
1453             for (int j = 0; j < SPECIES.length(); j++) {
1454                 if(mask[(i + j) % SPECIES.length()])
1455                     tmp += a[i + j];
1456             }
1457             res += tmp;
1458         }
1459 
1460         return res;
1461     }
1462     @Test(dataProvider = "doubleUnaryOpMaskProvider")
1463     static void ADDDouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) {
1464         double[] a = fa.apply(SPECIES.length());
1465         double[] r = fr.apply(SPECIES.length());
1466         boolean[] mask = fm.apply(SPECIES.length());
1467         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1468         double ra = 0;
1469 
1470         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1471             for (int i = 0; i < a.length; i += SPECIES.length()) {
1472                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1473                 r[i] = av.reduceLanes(VectorOperators.ADD, vmask);
1474             }
1475         }
1476 
1477         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1478             ra = 0;
1479             for (int i = 0; i < a.length; i += SPECIES.length()) {
1480                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1481                 ra += av.reduceLanes(VectorOperators.ADD, vmask);
1482             }
1483         }
1484 
1485         assertReductionArraysEqualsMasked(a, r, ra, mask, Double512VectorTests::ADDMasked, Double512VectorTests::ADDMasked);
1486     }
1487     static double MUL(double[] a, int idx) {
1488         double res = 1;
1489         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1490             res *= a[i];
1491         }
1492 
1493         return res;
1494     }
1495 
1496     static double MUL(double[] a) {
1497         double res = 1;
1498         for (int i = 0; i < a.length; i += SPECIES.length()) {
1499             double tmp = 1;
1500             for (int j = 0; j < SPECIES.length(); j++) {
1501                 tmp *= a[i + j];
1502             }
1503             res *= tmp;
1504         }
1505 
1506         return res;
1507     }
1508     @Test(dataProvider = "doubleUnaryOpProvider")
1509     static void MULDouble512VectorTests(IntFunction<double[]> fa) {
1510         double[] a = fa.apply(SPECIES.length());
1511         double[] r = fr.apply(SPECIES.length());
1512         double ra = 1;
1513 
1514         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1515             for (int i = 0; i < a.length; i += SPECIES.length()) {
1516                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1517                 r[i] = av.reduceLanes(VectorOperators.MUL);
1518             }
1519         }
1520 
1521         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1522             ra = 1;
1523             for (int i = 0; i < a.length; i += SPECIES.length()) {
1524                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1525                 ra *= av.reduceLanes(VectorOperators.MUL);
1526             }
1527         }
1528 
1529         assertReductionArraysEquals(a, r, ra, Double512VectorTests::MUL, Double512VectorTests::MUL);
1530     }
1531     static double MULMasked(double[] a, int idx, boolean[] mask) {
1532         double res = 1;
1533         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1534             if(mask[i % SPECIES.length()])
1535                 res *= a[i];
1536         }
1537 
1538         return res;
1539     }
1540 
1541     static double MULMasked(double[] a, boolean[] mask) {
1542         double res = 1;
1543         for (int i = 0; i < a.length; i += SPECIES.length()) {
1544             double tmp = 1;
1545             for (int j = 0; j < SPECIES.length(); j++) {
1546                 if(mask[(i + j) % SPECIES.length()])
1547                     tmp *= a[i + j];
1548             }
1549             res *= tmp;
1550         }
1551 
1552         return res;
1553     }
1554     @Test(dataProvider = "doubleUnaryOpMaskProvider")
1555     static void MULDouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) {
1556         double[] a = fa.apply(SPECIES.length());
1557         double[] r = fr.apply(SPECIES.length());
1558         boolean[] mask = fm.apply(SPECIES.length());
1559         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1560         double ra = 1;
1561 
1562         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1563             for (int i = 0; i < a.length; i += SPECIES.length()) {
1564                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1565                 r[i] = av.reduceLanes(VectorOperators.MUL, vmask);
1566             }
1567         }
1568 
1569         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1570             ra = 1;
1571             for (int i = 0; i < a.length; i += SPECIES.length()) {
1572                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1573                 ra *= av.reduceLanes(VectorOperators.MUL, vmask);
1574             }
1575         }
1576 
1577         assertReductionArraysEqualsMasked(a, r, ra, mask, Double512VectorTests::MULMasked, Double512VectorTests::MULMasked);
1578     }
1579     static double MIN(double[] a, int idx) {
1580         double res = Double.POSITIVE_INFINITY;
1581         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1582             res = (double)Math.min(res, a[i]);
1583         }
1584 
1585         return res;
1586     }
1587 
1588     static double MIN(double[] a) {
1589         double res = Double.POSITIVE_INFINITY;
1590         for (int i = 0; i < a.length; i++) {
1591             res = (double)Math.min(res, a[i]);
1592         }
1593 
1594         return res;
1595     }
1596     @Test(dataProvider = "doubleUnaryOpProvider")
1597     static void MINDouble512VectorTests(IntFunction<double[]> fa) {
1598         double[] a = fa.apply(SPECIES.length());
1599         double[] r = fr.apply(SPECIES.length());
1600         double ra = Double.POSITIVE_INFINITY;
1601 
1602         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1603             for (int i = 0; i < a.length; i += SPECIES.length()) {
1604                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1605                 r[i] = av.reduceLanes(VectorOperators.MIN);
1606             }
1607         }
1608 
1609         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1610             ra = Double.POSITIVE_INFINITY;
1611             for (int i = 0; i < a.length; i += SPECIES.length()) {
1612                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1613                 ra = (double)Math.min(ra, av.reduceLanes(VectorOperators.MIN));
1614             }
1615         }
1616 
1617         assertReductionArraysEquals(a, r, ra, Double512VectorTests::MIN, Double512VectorTests::MIN);
1618     }
1619     static double MINMasked(double[] a, int idx, boolean[] mask) {
1620         double res = Double.POSITIVE_INFINITY;
1621         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1622             if(mask[i % SPECIES.length()])
1623                 res = (double)Math.min(res, a[i]);
1624         }
1625 
1626         return res;
1627     }
1628 
1629     static double MINMasked(double[] a, boolean[] mask) {
1630         double res = Double.POSITIVE_INFINITY;
1631         for (int i = 0; i < a.length; i++) {
1632             if(mask[i % SPECIES.length()])
1633                 res = (double)Math.min(res, a[i]);
1634         }
1635 
1636         return res;
1637     }
1638     @Test(dataProvider = "doubleUnaryOpMaskProvider")
1639     static void MINDouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) {
1640         double[] a = fa.apply(SPECIES.length());
1641         double[] r = fr.apply(SPECIES.length());
1642         boolean[] mask = fm.apply(SPECIES.length());
1643         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1644         double ra = Double.POSITIVE_INFINITY;
1645 
1646         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1647             for (int i = 0; i < a.length; i += SPECIES.length()) {
1648                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1649                 r[i] = av.reduceLanes(VectorOperators.MIN, vmask);
1650             }
1651         }
1652 
1653         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1654             ra = Double.POSITIVE_INFINITY;
1655             for (int i = 0; i < a.length; i += SPECIES.length()) {
1656                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1657                 ra = (double)Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask));
1658             }
1659         }
1660 
1661         assertReductionArraysEqualsMasked(a, r, ra, mask, Double512VectorTests::MINMasked, Double512VectorTests::MINMasked);
1662     }
1663     static double MAX(double[] a, int idx) {
1664         double res = Double.NEGATIVE_INFINITY;
1665         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1666             res = (double)Math.max(res, a[i]);
1667         }
1668 
1669         return res;
1670     }
1671 
1672     static double MAX(double[] a) {
1673         double res = Double.NEGATIVE_INFINITY;
1674         for (int i = 0; i < a.length; i++) {
1675             res = (double)Math.max(res, a[i]);
1676         }
1677 
1678         return res;
1679     }
1680     @Test(dataProvider = "doubleUnaryOpProvider")
1681     static void MAXDouble512VectorTests(IntFunction<double[]> fa) {
1682         double[] a = fa.apply(SPECIES.length());
1683         double[] r = fr.apply(SPECIES.length());
1684         double ra = Double.NEGATIVE_INFINITY;
1685 
1686         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1687             for (int i = 0; i < a.length; i += SPECIES.length()) {
1688                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1689                 r[i] = av.reduceLanes(VectorOperators.MAX);
1690             }
1691         }
1692 
1693         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1694             ra = Double.NEGATIVE_INFINITY;
1695             for (int i = 0; i < a.length; i += SPECIES.length()) {
1696                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1697                 ra = (double)Math.max(ra, av.reduceLanes(VectorOperators.MAX));
1698             }
1699         }
1700 
1701         assertReductionArraysEquals(a, r, ra, Double512VectorTests::MAX, Double512VectorTests::MAX);
1702     }
1703     static double MAXMasked(double[] a, int idx, boolean[] mask) {
1704         double res = Double.NEGATIVE_INFINITY;
1705         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1706             if(mask[i % SPECIES.length()])
1707                 res = (double)Math.max(res, a[i]);
1708         }
1709 
1710         return res;
1711     }
1712 
1713     static double MAXMasked(double[] a, boolean[] mask) {
1714         double res = Double.NEGATIVE_INFINITY;
1715         for (int i = 0; i < a.length; i++) {
1716             if(mask[i % SPECIES.length()])
1717                 res = (double)Math.max(res, a[i]);
1718         }
1719 
1720         return res;
1721     }
1722     @Test(dataProvider = "doubleUnaryOpMaskProvider")
1723     static void MAXDouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) {
1724         double[] a = fa.apply(SPECIES.length());
1725         double[] r = fr.apply(SPECIES.length());
1726         boolean[] mask = fm.apply(SPECIES.length());
1727         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1728         double ra = Double.NEGATIVE_INFINITY;
1729 
1730         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1731             for (int i = 0; i < a.length; i += SPECIES.length()) {
1732                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1733                 r[i] = av.reduceLanes(VectorOperators.MAX, vmask);
1734             }
1735         }
1736 
1737         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1738             ra = Double.NEGATIVE_INFINITY;
1739             for (int i = 0; i < a.length; i += SPECIES.length()) {
1740                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1741                 ra = (double)Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask));
1742             }
1743         }
1744 
1745         assertReductionArraysEqualsMasked(a, r, ra, mask, Double512VectorTests::MAXMasked, Double512VectorTests::MAXMasked);
1746     }
1747 
1748 
1749 
1750 
1751 
1752     @Test(dataProvider = "doubleUnaryOpProvider")
1753     static void withDouble512VectorTests(IntFunction<double []> fa) {
1754         double[] a = fa.apply(SPECIES.length());
1755         double[] r = fr.apply(SPECIES.length());
1756 
1757         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1758             for (int i = 0; i < a.length; i += SPECIES.length()) {
1759                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1760                 av.withLane(0, (double)4).intoArray(r, i);
1761             }
1762         }
1763 
1764         assertInsertArraysEquals(a, r, (double)4, 0);
1765     }
1766     static boolean testIS_DEFAULT(double a) {
1767         return bits(a)==0;
1768     }
1769 
1770     @Test(dataProvider = "doubleTestOpProvider")
1771     static void IS_DEFAULTDouble512VectorTests(IntFunction<double[]> fa) {
1772         double[] a = fa.apply(SPECIES.length());
1773 
1774         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1775             for (int i = 0; i < a.length; i += SPECIES.length()) {
1776                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1777                 VectorMask<Double> mv = av.test(VectorOperators.IS_DEFAULT);
1778 
1779                 // Check results as part of computation.
1780                 for (int j = 0; j < SPECIES.length(); j++) {
1781    
1782                  Assert.assertEquals(mv.laneIsSet(j), testIS_DEFAULT(a[i + j]));
1783                 }
1784             }
1785         }
1786     }
1787 
1788     static boolean testIS_NEGATIVE(double a) {
1789         return bits(a)<0;
1790     }
1791 
1792     @Test(dataProvider = "doubleTestOpProvider")
1793     static void IS_NEGATIVEDouble512VectorTests(IntFunction<double[]> fa) {
1794         double[] a = fa.apply(SPECIES.length());
1795 
1796         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1797             for (int i = 0; i < a.length; i += SPECIES.length()) {
1798                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1799                 VectorMask<Double> mv = av.test(VectorOperators.IS_NEGATIVE);
1800 
1801                 // Check results as part of computation.
1802                 for (int j = 0; j < SPECIES.length(); j++) {
1803    
1804                  Assert.assertEquals(mv.laneIsSet(j), testIS_NEGATIVE(a[i + j]));
1805                 }
1806             }
1807         }
1808     }
1809 
1810 
1811     static boolean testIS_FINITE(double a) {
1812         return Double.isFinite(a);
1813     }
1814 
1815     @Test(dataProvider = "doubleTestOpProvider")
1816     static void IS_FINITEDouble512VectorTests(IntFunction<double[]> fa) {
1817         double[] a = fa.apply(SPECIES.length());
1818 
1819         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1820             for (int i = 0; i < a.length; i += SPECIES.length()) {
1821                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1822                 VectorMask<Double> mv = av.test(VectorOperators.IS_FINITE);
1823 
1824                 // Check results as part of computation.
1825                 for (int j = 0; j < SPECIES.length(); j++) {
1826    
1827                  Assert.assertEquals(mv.laneIsSet(j), testIS_FINITE(a[i + j]));
1828                 }
1829             }
1830         }
1831     }
1832 
1833 
1834 
1835     static boolean testIS_NAN(double a) {
1836         return Double.isNaN(a);
1837     }
1838 
1839     @Test(dataProvider = "doubleTestOpProvider")
1840     static void IS_NANDouble512VectorTests(IntFunction<double[]> fa) {
1841         double[] a = fa.apply(SPECIES.length());
1842 
1843         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1844             for (int i = 0; i < a.length; i += SPECIES.length()) {
1845                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1846                 VectorMask<Double> mv = av.test(VectorOperators.IS_NAN);
1847 
1848                 // Check results as part of computation.
1849                 for (int j = 0; j < SPECIES.length(); j++) {
1850    
1851                  Assert.assertEquals(mv.laneIsSet(j), testIS_NAN(a[i + j]));
1852                 }
1853             }
1854         }
1855     }
1856 
1857 
1858 
1859     static boolean testIS_INFINITE(double a) {
1860         return Double.isInfinite(a);
1861     }
1862 
1863     @Test(dataProvider = "doubleTestOpProvider")
1864     static void IS_INFINITEDouble512VectorTests(IntFunction<double[]> fa) {
1865         double[] a = fa.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                 VectorMask<Double> mv = av.test(VectorOperators.IS_INFINITE);
1871 
1872                 // Check results as part of computation.
1873                 for (int j = 0; j < SPECIES.length(); j++) {
1874    
1875                  Assert.assertEquals(mv.laneIsSet(j), testIS_INFINITE(a[i + j]));
1876                 }
1877             }
1878         }
1879     }
1880 
1881 
1882 
1883     @Test(dataProvider = "doubleCompareOpProvider")
1884     static void LTDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1885         double[] a = fa.apply(SPECIES.length());
1886         double[] b = fb.apply(SPECIES.length());
1887 
1888         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1889             for (int i = 0; i < a.length; i += SPECIES.length()) {
1890                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1891                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1892                 VectorMask<Double> mv = av.compare(VectorOperators.LT, bv);
1893 
1894                 // Check results as part of computation.
1895                 for (int j = 0; j < SPECIES.length(); j++) {
1896                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i + j]);
1897                 }
1898             }
1899         }
1900     }
1901 
1902 
1903     @Test(dataProvider = "doubleCompareOpProvider")
1904     static void ltDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1905         double[] a = fa.apply(SPECIES.length());
1906         double[] b = fb.apply(SPECIES.length());
1907 
1908         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1909             for (int i = 0; i < a.length; i += SPECIES.length()) {
1910                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1911                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1912                 VectorMask<Double> mv = av.lt(bv);
1913 
1914                 // Check results as part of computation.
1915                 for (int j = 0; j < SPECIES.length(); j++) {
1916                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i + j]);
1917                 }
1918             }
1919         }
1920     }
1921 
1922 
1923     @Test(dataProvider = "doubleCompareOpProvider")
1924     static void GTDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1925         double[] a = fa.apply(SPECIES.length());
1926         double[] b = fb.apply(SPECIES.length());
1927 
1928         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1929             for (int i = 0; i < a.length; i += SPECIES.length()) {
1930                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1931                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1932                 VectorMask<Double> mv = av.compare(VectorOperators.GT, bv);
1933 
1934                 // Check results as part of computation.
1935                 for (int j = 0; j < SPECIES.length(); j++) {
1936                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] > b[i + j]);
1937                 }
1938             }
1939         }
1940     }
1941 
1942 
1943     @Test(dataProvider = "doubleCompareOpProvider")
1944     static void EQDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1945         double[] a = fa.apply(SPECIES.length());
1946         double[] b = fb.apply(SPECIES.length());
1947 
1948         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1949             for (int i = 0; i < a.length; i += SPECIES.length()) {
1950                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1951                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1952                 VectorMask<Double> mv = av.compare(VectorOperators.EQ, bv);
1953 
1954                 // Check results as part of computation.
1955                 for (int j = 0; j < SPECIES.length(); j++) {
1956                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i + j]);
1957                 }
1958             }
1959         }
1960     }
1961 
1962 
1963     @Test(dataProvider = "doubleCompareOpProvider")
1964     static void eqDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1965         double[] a = fa.apply(SPECIES.length());
1966         double[] b = fb.apply(SPECIES.length());
1967 
1968         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1969             for (int i = 0; i < a.length; i += SPECIES.length()) {
1970                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1971                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1972                 VectorMask<Double> mv = av.eq(bv);
1973 
1974                 // Check results as part of computation.
1975                 for (int j = 0; j < SPECIES.length(); j++) {
1976                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i + j]);
1977                 }
1978             }
1979         }
1980     }
1981 
1982 
1983     @Test(dataProvider = "doubleCompareOpProvider")
1984     static void NEDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1985         double[] a = fa.apply(SPECIES.length());
1986         double[] b = fb.apply(SPECIES.length());
1987 
1988         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1989             for (int i = 0; i < a.length; i += SPECIES.length()) {
1990                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1991                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1992                 VectorMask<Double> mv = av.compare(VectorOperators.NE, bv);
1993 
1994                 // Check results as part of computation.
1995                 for (int j = 0; j < SPECIES.length(); j++) {
1996                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] != b[i + j]);
1997                 }
1998             }
1999         }
2000     }
2001 
2002 
2003     @Test(dataProvider = "doubleCompareOpProvider")
2004     static void LEDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2005         double[] a = fa.apply(SPECIES.length());
2006         double[] b = fb.apply(SPECIES.length());
2007 
2008         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2009             for (int i = 0; i < a.length; i += SPECIES.length()) {
2010                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2011                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2012                 VectorMask<Double> mv = av.compare(VectorOperators.LE, bv);
2013 
2014                 // Check results as part of computation.
2015                 for (int j = 0; j < SPECIES.length(); j++) {
2016                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] <= b[i + j]);
2017                 }
2018             }
2019         }
2020     }
2021 
2022 
2023     @Test(dataProvider = "doubleCompareOpProvider")
2024     static void GEDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2025         double[] a = fa.apply(SPECIES.length());
2026         double[] b = fb.apply(SPECIES.length());
2027 
2028         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2029             for (int i = 0; i < a.length; i += SPECIES.length()) {
2030                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2031                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2032                 VectorMask<Double> mv = av.compare(VectorOperators.GE, bv);
2033 
2034                 // Check results as part of computation.
2035                 for (int j = 0; j < SPECIES.length(); j++) {
2036                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] >= b[i + j]);
2037                 }
2038             }
2039         }
2040     }
2041 
2042 
2043     static double blend(double a, double b, boolean mask) {
2044         return mask ? b : a;
2045     }
2046 
2047     @Test(dataProvider = "doubleBinaryOpMaskProvider")
2048     static void blendDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
2049                                           IntFunction<boolean[]> fm) {
2050         double[] a = fa.apply(SPECIES.length());
2051         double[] b = fb.apply(SPECIES.length());
2052         double[] r = fr.apply(SPECIES.length());
2053         boolean[] mask = fm.apply(SPECIES.length());
2054         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2055 
2056         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2057             for (int i = 0; i < a.length; i += SPECIES.length()) {
2058                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2059                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2060                 av.blend(bv, vmask).intoArray(r, i);
2061             }
2062         }
2063 
2064         assertArraysEquals(a, b, r, mask, Double512VectorTests::blend);
2065     }
2066 
2067     @Test(dataProvider = "doubleUnaryOpShuffleProvider")
2068     static void RearrangeDouble512VectorTests(IntFunction<double[]> fa,
2069                                            BiFunction<Integer,Integer,int[]> fs) {
2070         double[] a = fa.apply(SPECIES.length());
2071         int[] order = fs.apply(a.length, SPECIES.length());
2072         double[] r = fr.apply(SPECIES.length());
2073 
2074         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2075             for (int i = 0; i < a.length; i += SPECIES.length()) {
2076                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2077                 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
2078             }
2079         }
2080 
2081         assertRearrangeArraysEquals(a, r, order, SPECIES.length());
2082     }
2083 
2084 
2085 
2086 
2087     @Test(dataProvider = "doubleUnaryOpProvider")
2088     static void getDouble512VectorTests(IntFunction<double[]> fa) {
2089         double[] a = fa.apply(SPECIES.length());
2090         double[] r = fr.apply(SPECIES.length());
2091 
2092         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2093             for (int i = 0; i < a.length; i += SPECIES.length()) {
2094                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2095                 int num_lanes = SPECIES.length();
2096                 // Manually unroll because full unroll happens after intrinsification.
2097                 // Unroll is needed because get intrinsic requires for index to be a known constant.
2098                 if (num_lanes == 1) {
2099                     r[i]=av.lane(0);
2100                 } else if (num_lanes == 2) {
2101                     r[i]=av.lane(0);
2102                     r[i+1]=av.lane(1);
2103                 } else if (num_lanes == 4) {
2104                     r[i]=av.lane(0);
2105                     r[i+1]=av.lane(1);
2106                     r[i+2]=av.lane(2);
2107                     r[i+3]=av.lane(3);
2108                 } else if (num_lanes == 8) {
2109                     r[i]=av.lane(0);
2110                     r[i+1]=av.lane(1);
2111                     r[i+2]=av.lane(2);
2112                     r[i+3]=av.lane(3);
2113                     r[i+4]=av.lane(4);
2114                     r[i+5]=av.lane(5);
2115                     r[i+6]=av.lane(6);
2116                     r[i+7]=av.lane(7);
2117                 } else if (num_lanes == 16) {
2118                     r[i]=av.lane(0);
2119                     r[i+1]=av.lane(1);
2120                     r[i+2]=av.lane(2);
2121                     r[i+3]=av.lane(3);
2122                     r[i+4]=av.lane(4);
2123                     r[i+5]=av.lane(5);
2124                     r[i+6]=av.lane(6);
2125                     r[i+7]=av.lane(7);
2126                     r[i+8]=av.lane(8);
2127                     r[i+9]=av.lane(9);
2128                     r[i+10]=av.lane(10);
2129                     r[i+11]=av.lane(11);
2130                     r[i+12]=av.lane(12);
2131                     r[i+13]=av.lane(13);
2132                     r[i+14]=av.lane(14);
2133                     r[i+15]=av.lane(15);
2134                 } else if (num_lanes == 32) {
2135                     r[i]=av.lane(0);
2136                     r[i+1]=av.lane(1);
2137                     r[i+2]=av.lane(2);
2138                     r[i+3]=av.lane(3);
2139                     r[i+4]=av.lane(4);
2140                     r[i+5]=av.lane(5);
2141                     r[i+6]=av.lane(6);
2142                     r[i+7]=av.lane(7);
2143                     r[i+8]=av.lane(8);
2144                     r[i+9]=av.lane(9);
2145                     r[i+10]=av.lane(10);
2146                     r[i+11]=av.lane(11);
2147                     r[i+12]=av.lane(12);
2148                     r[i+13]=av.lane(13);
2149                     r[i+14]=av.lane(14);
2150                     r[i+15]=av.lane(15);
2151                     r[i+16]=av.lane(16);
2152                     r[i+17]=av.lane(17);
2153                     r[i+18]=av.lane(18);
2154                     r[i+19]=av.lane(19);
2155                     r[i+20]=av.lane(20);
2156                     r[i+21]=av.lane(21);
2157                     r[i+22]=av.lane(22);
2158                     r[i+23]=av.lane(23);
2159                     r[i+24]=av.lane(24);
2160                     r[i+25]=av.lane(25);
2161                     r[i+26]=av.lane(26);
2162                     r[i+27]=av.lane(27);
2163                     r[i+28]=av.lane(28);
2164                     r[i+29]=av.lane(29);
2165                     r[i+30]=av.lane(30);
2166                     r[i+31]=av.lane(31);
2167                 } else if (num_lanes == 64) {
2168                     r[i]=av.lane(0);
2169                     r[i+1]=av.lane(1);
2170                     r[i+2]=av.lane(2);
2171                     r[i+3]=av.lane(3);
2172                     r[i+4]=av.lane(4);
2173                     r[i+5]=av.lane(5);
2174                     r[i+6]=av.lane(6);
2175                     r[i+7]=av.lane(7);
2176                     r[i+8]=av.lane(8);
2177                     r[i+9]=av.lane(9);
2178                     r[i+10]=av.lane(10);
2179                     r[i+11]=av.lane(11);
2180                     r[i+12]=av.lane(12);
2181                     r[i+13]=av.lane(13);
2182                     r[i+14]=av.lane(14);
2183                     r[i+15]=av.lane(15);
2184                     r[i+16]=av.lane(16);
2185                     r[i+17]=av.lane(17);
2186                     r[i+18]=av.lane(18);
2187                     r[i+19]=av.lane(19);
2188                     r[i+20]=av.lane(20);
2189                     r[i+21]=av.lane(21);
2190                     r[i+22]=av.lane(22);
2191                     r[i+23]=av.lane(23);
2192                     r[i+24]=av.lane(24);
2193                     r[i+25]=av.lane(25);
2194                     r[i+26]=av.lane(26);
2195                     r[i+27]=av.lane(27);
2196                     r[i+28]=av.lane(28);
2197                     r[i+29]=av.lane(29);
2198                     r[i+30]=av.lane(30);
2199                     r[i+31]=av.lane(31);
2200                     r[i+32]=av.lane(32);
2201                     r[i+33]=av.lane(33);
2202                     r[i+34]=av.lane(34);
2203                     r[i+35]=av.lane(35);
2204                     r[i+36]=av.lane(36);
2205                     r[i+37]=av.lane(37);
2206                     r[i+38]=av.lane(38);
2207                     r[i+39]=av.lane(39);
2208                     r[i+40]=av.lane(40);
2209                     r[i+41]=av.lane(41);
2210                     r[i+42]=av.lane(42);
2211                     r[i+43]=av.lane(43);
2212                     r[i+44]=av.lane(44);
2213                     r[i+45]=av.lane(45);
2214                     r[i+46]=av.lane(46);
2215                     r[i+47]=av.lane(47);
2216                     r[i+48]=av.lane(48);
2217                     r[i+49]=av.lane(49);
2218                     r[i+50]=av.lane(50);
2219                     r[i+51]=av.lane(51);
2220                     r[i+52]=av.lane(52);
2221                     r[i+53]=av.lane(53);
2222                     r[i+54]=av.lane(54);
2223                     r[i+55]=av.lane(55);
2224                     r[i+56]=av.lane(56);
2225                     r[i+57]=av.lane(57);
2226                     r[i+58]=av.lane(58);
2227                     r[i+59]=av.lane(59);
2228                     r[i+60]=av.lane(60);
2229                     r[i+61]=av.lane(61);
2230                     r[i+62]=av.lane(62);
2231                     r[i+63]=av.lane(63);
2232                 } else {
2233                     for (int j = 0; j < SPECIES.length(); j++) {
2234                         r[i+j]=av.lane(j);
2235                     }
2236                 }
2237             }
2238         }
2239 
2240         assertArraysEquals(a, r, Double512VectorTests::get);
2241     }
2242 
2243     @Test(dataProvider = "doubleUnaryOpProvider")
2244     static void BroadcastDouble512VectorTests(IntFunction<double[]> fa) {
2245         double[] a = fa.apply(SPECIES.length());
2246         double[] r = new double[a.length];
2247 
2248         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2249             for (int i = 0; i < a.length; i += SPECIES.length()) {
2250                 DoubleVector.broadcast(SPECIES, a[i]).intoArray(r, i);
2251             }
2252         }
2253 
2254         assertBroadcastArraysEquals(a, r);
2255     }
2256 
2257 
2258 
2259 
2260 
2261     @Test(dataProvider = "doubleUnaryOpProvider")
2262     static void ZeroDouble512VectorTests(IntFunction<double[]> fa) {
2263         double[] a = fa.apply(SPECIES.length());
2264         double[] r = new double[a.length];
2265 
2266         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2267             for (int i = 0; i < a.length; i += SPECIES.length()) {
2268                 DoubleVector.zero(SPECIES).intoArray(a, i);
2269             }
2270         }
2271 
2272         Assert.assertEquals(a, r);
2273     }
2274 
2275 
2276 
2277 
2278     static double[] sliceUnary(double[] a, int origin, int idx) {
2279         double[] res = new double[SPECIES.length()];
2280         for (int i = 0; i < SPECIES.length(); i++){
2281             if(i+origin < SPECIES.length())
2282                 res[i] = a[idx+i+origin];
2283             else
2284                 res[i] = (double)0;
2285         }
2286         return res;
2287     }
2288 
2289     @Test(dataProvider = "doubleUnaryOpProvider")
2290     static void sliceUnaryDouble512VectorTests(IntFunction<double[]> fa) {
2291         double[] a = fa.apply(SPECIES.length());
2292         double[] r = new double[a.length];
2293         int origin = (new java.util.Random()).nextInt(SPECIES.length());
2294         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2295             for (int i = 0; i < a.length; i += SPECIES.length()) {
2296                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2297                 av.slice(origin).intoArray(r, i);
2298             }
2299         }
2300 
2301         assertArraysEquals(a, r, origin, Double512VectorTests::sliceUnary);
2302     }
2303     static double[] sliceBinary(double[] a, double[] b, int origin, int idx) {
2304         double[] res = new double[SPECIES.length()];
2305         for (int i = 0, j = 0; i < SPECIES.length(); i++){
2306             if(i+origin < SPECIES.length())
2307                 res[i] = a[idx+i+origin];
2308             else {
2309                 res[i] = b[idx+j];
2310                 j++;
2311             }
2312         }
2313         return res;
2314     }
2315 
2316     @Test(dataProvider = "doubleBinaryOpProvider")
2317     static void sliceBinaryDouble512VectorTestsBinary(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2318         double[] a = fa.apply(SPECIES.length());
2319         double[] b = fb.apply(SPECIES.length());
2320         double[] r = new double[a.length];
2321         int origin = (new java.util.Random()).nextInt(SPECIES.length());
2322         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2323             for (int i = 0; i < a.length; i += SPECIES.length()) {
2324                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2325                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2326                 av.slice(origin, bv).intoArray(r, i);
2327             }
2328         }
2329 
2330         assertArraysEquals(a, b, r, origin, Double512VectorTests::sliceBinary);
2331     }
2332     static double[] slice(double[] a, double[] b, int origin, boolean[] mask, int idx) {
2333         double[] res = new double[SPECIES.length()];
2334         for (int i = 0, j = 0; i < SPECIES.length(); i++){
2335             if(i+origin < SPECIES.length())
2336                 res[i] = mask[i] ? a[idx+i+origin] : (double)0;
2337             else {
2338                 res[i] = mask[i] ? b[idx+j] : (double)0;
2339                 j++;
2340             }
2341         }
2342         return res;
2343     }
2344 
2345     @Test(dataProvider = "doubleBinaryOpMaskProvider")
2346     static void sliceDouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
2347     IntFunction<boolean[]> fm) {
2348         double[] a = fa.apply(SPECIES.length());
2349         double[] b = fb.apply(SPECIES.length());
2350         boolean[] mask = fm.apply(SPECIES.length());
2351         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2352 
2353         double[] r = new double[a.length];
2354         int origin = (new java.util.Random()).nextInt(SPECIES.length());
2355         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2356             for (int i = 0; i < a.length; i += SPECIES.length()) {
2357                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2358                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2359                 av.slice(origin, bv, vmask).intoArray(r, i);
2360             }
2361         }
2362 
2363         assertArraysEquals(a, b, r, origin, mask, Double512VectorTests::slice);
2364     }
2365     static double[] unsliceUnary(double[] a, int origin, int idx) {
2366         double[] res = new double[SPECIES.length()];
2367         for (int i = 0, j = 0; i < SPECIES.length(); i++){
2368             if(i < origin)
2369                 res[i] = (double)0;
2370             else {
2371                 res[i] = a[idx+j];
2372                 j++;
2373             }
2374         }
2375         return res;
2376     }
2377 
2378     @Test(dataProvider = "doubleUnaryOpProvider")
2379     static void unsliceUnaryDouble512VectorTests(IntFunction<double[]> fa) {
2380         double[] a = fa.apply(SPECIES.length());
2381         double[] r = new double[a.length];
2382         int origin = (new java.util.Random()).nextInt(SPECIES.length());
2383         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2384             for (int i = 0; i < a.length; i += SPECIES.length()) {
2385                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2386                 av.unslice(origin).intoArray(r, i);
2387             }
2388         }
2389 
2390         assertArraysEquals(a, r, origin, Double512VectorTests::unsliceUnary);
2391     }
2392     static double[] unsliceBinary(double[] a, double[] b, int origin, int part, int idx) {
2393         double[] res = new double[SPECIES.length()];
2394         for (int i = 0, j = 0; i < SPECIES.length(); i++){
2395             if (part == 0) {
2396                 if (i < origin)
2397                     res[i] = b[idx+i];
2398                 else {
2399                     res[i] = a[idx+j];
2400                     j++;
2401                 }
2402             } else if (part == 1) {
2403                 if (i < origin)
2404                     res[i] = a[idx+SPECIES.length()-origin+i];
2405                 else {
2406                     res[i] = b[idx+origin+j];
2407                     j++;
2408                 }
2409             }
2410         }
2411         return res;
2412     }
2413 
2414     @Test(dataProvider = "doubleBinaryOpProvider")
2415     static void unsliceBinaryDouble512VectorTestsBinary(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2416         double[] a = fa.apply(SPECIES.length());
2417         double[] b = fb.apply(SPECIES.length());
2418         double[] r = new double[a.length];
2419         int origin = (new java.util.Random()).nextInt(SPECIES.length());
2420         int part = (new java.util.Random()).nextInt(2);
2421         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2422             for (int i = 0; i < a.length; i += SPECIES.length()) {
2423                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2424                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2425                 av.unslice(origin, bv, part).intoArray(r, i);
2426             }
2427         }
2428 
2429         assertArraysEquals(a, b, r, origin, part, Double512VectorTests::unsliceBinary);
2430     }
2431     static double[] unslice(double[] a, double[] b, int origin, int part, boolean[] mask, int idx) {
2432         double[] res = new double[SPECIES.length()];
2433         for (int i = 0, j = 0; i < SPECIES.length(); i++){
2434             if(i+origin < SPECIES.length())
2435                 res[i] = b[idx+i+origin];
2436             else {
2437                 res[i] = b[idx+j];
2438                 j++;
2439             }
2440         }
2441         for (int i = 0; i < SPECIES.length(); i++){
2442             res[i] = mask[i] ? a[idx+i] : res[i];
2443         }
2444         double[] res1 = new double[SPECIES.length()];
2445         if (part == 0) {
2446             for (int i = 0, j = 0; i < SPECIES.length(); i++){
2447                 if (i < origin)
2448                     res1[i] = b[idx+i];
2449                 else {
2450                    res1[i] = res[j];
2451                    j++;
2452                 }
2453             }
2454         } else if (part == 1) {
2455             for (int i = 0, j = 0; i < SPECIES.length(); i++){
2456                 if (i < origin)
2457                     res1[i] = res[SPECIES.length()-origin+i];
2458                 else {
2459                     res1[i] = b[idx+origin+j];
2460                     j++;
2461                 }
2462             }
2463         }
2464         return res1;
2465     }
2466 
2467     @Test(dataProvider = "doubleBinaryOpMaskProvider")
2468     static void unsliceDouble512VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
2469     IntFunction<boolean[]> fm) {
2470         double[] a = fa.apply(SPECIES.length());
2471         double[] b = fb.apply(SPECIES.length());
2472         boolean[] mask = fm.apply(SPECIES.length());
2473         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2474         double[] r = new double[a.length];
2475         int origin = (new java.util.Random()).nextInt(SPECIES.length());
2476         int part = (new java.util.Random()).nextInt(2);
2477         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2478             for (int i = 0; i < a.length; i += SPECIES.length()) {
2479                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2480                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2481                 av.unslice(origin, bv, part, vmask).intoArray(r, i);
2482             }
2483         }
2484 
2485         assertArraysEquals(a, b, r, origin, part, mask, Double512VectorTests::unslice);
2486     }
2487 
2488     static double SIN(double a) {
2489         return (double)(Math.sin((double)a));
2490     }
2491 
2492     static double strictSIN(double a) {
2493         return (double)(StrictMath.sin((double)a));
2494     }
2495 
2496     @Test(dataProvider = "doubleUnaryOpProvider")
2497     static void SINDouble512VectorTests(IntFunction<double[]> fa) {
2498         double[] a = fa.apply(SPECIES.length());
2499         double[] r = fr.apply(SPECIES.length());
2500 
2501         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2502             for (int i = 0; i < a.length; i += SPECIES.length()) {
2503                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2504                 av.lanewise(VectorOperators.SIN).intoArray(r, i);
2505             }
2506         }
2507 
2508         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::SIN, Double512VectorTests::strictSIN);
2509     }
2510 
2511 
2512     static double EXP(double a) {
2513         return (double)(Math.exp((double)a));
2514     }
2515 
2516     static double strictEXP(double a) {
2517         return (double)(StrictMath.exp((double)a));
2518     }
2519 
2520     @Test(dataProvider = "doubleUnaryOpProvider")
2521     static void EXPDouble512VectorTests(IntFunction<double[]> fa) {
2522         double[] a = fa.apply(SPECIES.length());
2523         double[] r = fr.apply(SPECIES.length());
2524 
2525         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2526             for (int i = 0; i < a.length; i += SPECIES.length()) {
2527                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2528                 av.lanewise(VectorOperators.EXP).intoArray(r, i);
2529             }
2530         }
2531 
2532         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::EXP, Double512VectorTests::strictEXP);
2533     }
2534 
2535 
2536     static double LOG1P(double a) {
2537         return (double)(Math.log1p((double)a));
2538     }
2539 
2540     static double strictLOG1P(double a) {
2541         return (double)(StrictMath.log1p((double)a));
2542     }
2543 
2544     @Test(dataProvider = "doubleUnaryOpProvider")
2545     static void LOG1PDouble512VectorTests(IntFunction<double[]> fa) {
2546         double[] a = fa.apply(SPECIES.length());
2547         double[] r = fr.apply(SPECIES.length());
2548 
2549         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2550             for (int i = 0; i < a.length; i += SPECIES.length()) {
2551                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2552                 av.lanewise(VectorOperators.LOG1P).intoArray(r, i);
2553             }
2554         }
2555 
2556         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::LOG1P, Double512VectorTests::strictLOG1P);
2557     }
2558 
2559 
2560     static double LOG(double a) {
2561         return (double)(Math.log((double)a));
2562     }
2563 
2564     static double strictLOG(double a) {
2565         return (double)(StrictMath.log((double)a));
2566     }
2567 
2568     @Test(dataProvider = "doubleUnaryOpProvider")
2569     static void LOGDouble512VectorTests(IntFunction<double[]> fa) {
2570         double[] a = fa.apply(SPECIES.length());
2571         double[] r = fr.apply(SPECIES.length());
2572 
2573         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2574             for (int i = 0; i < a.length; i += SPECIES.length()) {
2575                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2576                 av.lanewise(VectorOperators.LOG).intoArray(r, i);
2577             }
2578         }
2579 
2580         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::LOG, Double512VectorTests::strictLOG);
2581     }
2582 
2583 
2584     static double LOG10(double a) {
2585         return (double)(Math.log10((double)a));
2586     }
2587 
2588     static double strictLOG10(double a) {
2589         return (double)(StrictMath.log10((double)a));
2590     }
2591 
2592     @Test(dataProvider = "doubleUnaryOpProvider")
2593     static void LOG10Double512VectorTests(IntFunction<double[]> fa) {
2594         double[] a = fa.apply(SPECIES.length());
2595         double[] r = fr.apply(SPECIES.length());
2596 
2597         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2598             for (int i = 0; i < a.length; i += SPECIES.length()) {
2599                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2600                 av.lanewise(VectorOperators.LOG10).intoArray(r, i);
2601             }
2602         }
2603 
2604         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::LOG10, Double512VectorTests::strictLOG10);
2605     }
2606 
2607 
2608     static double EXPM1(double a) {
2609         return (double)(Math.expm1((double)a));
2610     }
2611 
2612     static double strictEXPM1(double a) {
2613         return (double)(StrictMath.expm1((double)a));
2614     }
2615 
2616     @Test(dataProvider = "doubleUnaryOpProvider")
2617     static void EXPM1Double512VectorTests(IntFunction<double[]> fa) {
2618         double[] a = fa.apply(SPECIES.length());
2619         double[] r = fr.apply(SPECIES.length());
2620 
2621         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2622             for (int i = 0; i < a.length; i += SPECIES.length()) {
2623                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2624                 av.lanewise(VectorOperators.EXPM1).intoArray(r, i);
2625             }
2626         }
2627 
2628         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::EXPM1, Double512VectorTests::strictEXPM1);
2629     }
2630 
2631 
2632     static double COS(double a) {
2633         return (double)(Math.cos((double)a));
2634     }
2635 
2636     static double strictCOS(double a) {
2637         return (double)(StrictMath.cos((double)a));
2638     }
2639 
2640     @Test(dataProvider = "doubleUnaryOpProvider")
2641     static void COSDouble512VectorTests(IntFunction<double[]> fa) {
2642         double[] a = fa.apply(SPECIES.length());
2643         double[] r = fr.apply(SPECIES.length());
2644 
2645         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2646             for (int i = 0; i < a.length; i += SPECIES.length()) {
2647                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2648                 av.lanewise(VectorOperators.COS).intoArray(r, i);
2649             }
2650         }
2651 
2652         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::COS, Double512VectorTests::strictCOS);
2653     }
2654 
2655 
2656     static double TAN(double a) {
2657         return (double)(Math.tan((double)a));
2658     }
2659 
2660     static double strictTAN(double a) {
2661         return (double)(StrictMath.tan((double)a));
2662     }
2663 
2664     @Test(dataProvider = "doubleUnaryOpProvider")
2665     static void TANDouble512VectorTests(IntFunction<double[]> fa) {
2666         double[] a = fa.apply(SPECIES.length());
2667         double[] r = fr.apply(SPECIES.length());
2668 
2669         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2670             for (int i = 0; i < a.length; i += SPECIES.length()) {
2671                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2672                 av.lanewise(VectorOperators.TAN).intoArray(r, i);
2673             }
2674         }
2675 
2676         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::TAN, Double512VectorTests::strictTAN);
2677     }
2678 
2679 
2680     static double SINH(double a) {
2681         return (double)(Math.sinh((double)a));
2682     }
2683 
2684     static double strictSINH(double a) {
2685         return (double)(StrictMath.sinh((double)a));
2686     }
2687 
2688     @Test(dataProvider = "doubleUnaryOpProvider")
2689     static void SINHDouble512VectorTests(IntFunction<double[]> fa) {
2690         double[] a = fa.apply(SPECIES.length());
2691         double[] r = fr.apply(SPECIES.length());
2692 
2693         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2694             for (int i = 0; i < a.length; i += SPECIES.length()) {
2695                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2696                 av.lanewise(VectorOperators.SINH).intoArray(r, i);
2697             }
2698         }
2699 
2700         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::SINH, Double512VectorTests::strictSINH);
2701     }
2702 
2703 
2704     static double COSH(double a) {
2705         return (double)(Math.cosh((double)a));
2706     }
2707 
2708     static double strictCOSH(double a) {
2709         return (double)(StrictMath.cosh((double)a));
2710     }
2711 
2712     @Test(dataProvider = "doubleUnaryOpProvider")
2713     static void COSHDouble512VectorTests(IntFunction<double[]> fa) {
2714         double[] a = fa.apply(SPECIES.length());
2715         double[] r = fr.apply(SPECIES.length());
2716 
2717         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2718             for (int i = 0; i < a.length; i += SPECIES.length()) {
2719                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2720                 av.lanewise(VectorOperators.COSH).intoArray(r, i);
2721             }
2722         }
2723 
2724         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::COSH, Double512VectorTests::strictCOSH);
2725     }
2726 
2727 
2728     static double TANH(double a) {
2729         return (double)(Math.tanh((double)a));
2730     }
2731 
2732     static double strictTANH(double a) {
2733         return (double)(StrictMath.tanh((double)a));
2734     }
2735 
2736     @Test(dataProvider = "doubleUnaryOpProvider")
2737     static void TANHDouble512VectorTests(IntFunction<double[]> fa) {
2738         double[] a = fa.apply(SPECIES.length());
2739         double[] r = fr.apply(SPECIES.length());
2740 
2741         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2742             for (int i = 0; i < a.length; i += SPECIES.length()) {
2743                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2744                 av.lanewise(VectorOperators.TANH).intoArray(r, i);
2745             }
2746         }
2747 
2748         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::TANH, Double512VectorTests::strictTANH);
2749     }
2750 
2751 
2752     static double ASIN(double a) {
2753         return (double)(Math.asin((double)a));
2754     }
2755 
2756     static double strictASIN(double a) {
2757         return (double)(StrictMath.asin((double)a));
2758     }
2759 
2760     @Test(dataProvider = "doubleUnaryOpProvider")
2761     static void ASINDouble512VectorTests(IntFunction<double[]> fa) {
2762         double[] a = fa.apply(SPECIES.length());
2763         double[] r = fr.apply(SPECIES.length());
2764 
2765         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2766             for (int i = 0; i < a.length; i += SPECIES.length()) {
2767                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2768                 av.lanewise(VectorOperators.ASIN).intoArray(r, i);
2769             }
2770         }
2771 
2772         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::ASIN, Double512VectorTests::strictASIN);
2773     }
2774 
2775 
2776     static double ACOS(double a) {
2777         return (double)(Math.acos((double)a));
2778     }
2779 
2780     static double strictACOS(double a) {
2781         return (double)(StrictMath.acos((double)a));
2782     }
2783 
2784     @Test(dataProvider = "doubleUnaryOpProvider")
2785     static void ACOSDouble512VectorTests(IntFunction<double[]> fa) {
2786         double[] a = fa.apply(SPECIES.length());
2787         double[] r = fr.apply(SPECIES.length());
2788 
2789         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2790             for (int i = 0; i < a.length; i += SPECIES.length()) {
2791                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2792                 av.lanewise(VectorOperators.ACOS).intoArray(r, i);
2793             }
2794         }
2795 
2796         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::ACOS, Double512VectorTests::strictACOS);
2797     }
2798 
2799 
2800     static double ATAN(double a) {
2801         return (double)(Math.atan((double)a));
2802     }
2803 
2804     static double strictATAN(double a) {
2805         return (double)(StrictMath.atan((double)a));
2806     }
2807 
2808     @Test(dataProvider = "doubleUnaryOpProvider")
2809     static void ATANDouble512VectorTests(IntFunction<double[]> fa) {
2810         double[] a = fa.apply(SPECIES.length());
2811         double[] r = fr.apply(SPECIES.length());
2812 
2813         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2814             for (int i = 0; i < a.length; i += SPECIES.length()) {
2815                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2816                 av.lanewise(VectorOperators.ATAN).intoArray(r, i);
2817             }
2818         }
2819 
2820         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::ATAN, Double512VectorTests::strictATAN);
2821     }
2822 
2823 
2824     static double CBRT(double a) {
2825         return (double)(Math.cbrt((double)a));
2826     }
2827 
2828     static double strictCBRT(double a) {
2829         return (double)(StrictMath.cbrt((double)a));
2830     }
2831 
2832     @Test(dataProvider = "doubleUnaryOpProvider")
2833     static void CBRTDouble512VectorTests(IntFunction<double[]> fa) {
2834         double[] a = fa.apply(SPECIES.length());
2835         double[] r = fr.apply(SPECIES.length());
2836 
2837         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2838             for (int i = 0; i < a.length; i += SPECIES.length()) {
2839                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2840                 av.lanewise(VectorOperators.CBRT).intoArray(r, i);
2841             }
2842         }
2843 
2844         assertArraysEqualsWithinOneUlp(a, r, Double512VectorTests::CBRT, Double512VectorTests::strictCBRT);
2845     }
2846 
2847 
2848     static double HYPOT(double a, double b) {
2849         return (double)(Math.hypot((double)a, (double)b));
2850     }
2851 
2852     static double strictHYPOT(double a, double b) {
2853         return (double)(StrictMath.hypot((double)a, (double)b));
2854     }
2855 
2856     @Test(dataProvider = "doubleBinaryOpProvider")
2857     static void HYPOTDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2858         double[] a = fa.apply(SPECIES.length());
2859         double[] b = fb.apply(SPECIES.length());
2860         double[] r = fr.apply(SPECIES.length());
2861 
2862         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2863             for (int i = 0; i < a.length; i += SPECIES.length()) {
2864                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2865                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2866                 av.lanewise(VectorOperators.HYPOT, bv).intoArray(r, i);
2867             }
2868         }
2869 
2870         assertArraysEqualsWithinOneUlp(a, b, r, Double512VectorTests::HYPOT, Double512VectorTests::strictHYPOT);
2871     }
2872 
2873 
2874 
2875     static double POW(double a, double b) {
2876         return (double)(Math.pow((double)a, (double)b));
2877     }
2878 
2879     static double strictPOW(double a, double b) {
2880         return (double)(StrictMath.pow((double)a, (double)b));
2881     }
2882 
2883     @Test(dataProvider = "doubleBinaryOpProvider")
2884     static void POWDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2885         double[] a = fa.apply(SPECIES.length());
2886         double[] b = fb.apply(SPECIES.length());
2887         double[] r = fr.apply(SPECIES.length());
2888 
2889         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2890             for (int i = 0; i < a.length; i += SPECIES.length()) {
2891                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2892                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2893                 av.lanewise(VectorOperators.POW, bv).intoArray(r, i);
2894             }
2895         }
2896 
2897         assertArraysEqualsWithinOneUlp(a, b, r, Double512VectorTests::POW, Double512VectorTests::strictPOW);
2898     }
2899 
2900 
2901 
2902     static double ATAN2(double a, double b) {
2903         return (double)(Math.atan2((double)a, (double)b));
2904     }
2905 
2906     static double strictATAN2(double a, double b) {
2907         return (double)(StrictMath.atan2((double)a, (double)b));
2908     }
2909 
2910     @Test(dataProvider = "doubleBinaryOpProvider")
2911     static void ATAN2Double512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2912         double[] a = fa.apply(SPECIES.length());
2913         double[] b = fb.apply(SPECIES.length());
2914         double[] r = fr.apply(SPECIES.length());
2915 
2916         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2917             for (int i = 0; i < a.length; i += SPECIES.length()) {
2918                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2919                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2920                 av.lanewise(VectorOperators.ATAN2, bv).intoArray(r, i);
2921             }
2922         }
2923 
2924         assertArraysEqualsWithinOneUlp(a, b, r, Double512VectorTests::ATAN2, Double512VectorTests::strictATAN2);
2925     }
2926 
2927 
2928 
2929     static double FMA(double a, double b, double c) {
2930         return (double)(Math.fma(a, b, c));
2931     }
2932 
2933 
2934     @Test(dataProvider = "doubleTernaryOpProvider")
2935     static void FMADouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb, IntFunction<double[]> fc) {
2936         int count = INVOC_COUNT;
2937         switch ("FMA") {
2938         case "fma": case "lanewise_FMA":
2939            // Math.fma uses BigDecimal
2940            count = Math.max(5, count/20); break;
2941         }
2942         final int INVOC_COUNT = count;
2943         double[] a = fa.apply(SPECIES.length());
2944         double[] b = fb.apply(SPECIES.length());
2945         double[] c = fc.apply(SPECIES.length());
2946         double[] r = fr.apply(SPECIES.length());
2947 
2948         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2949             for (int i = 0; i < a.length; i += SPECIES.length()) {
2950                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2951                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2952                 DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i);
2953                 av.lanewise(VectorOperators.FMA, bv, cv).intoArray(r, i);
2954             }
2955         }
2956 
2957         assertArraysEquals(a, b, c, r, Double512VectorTests::FMA);
2958     }
2959 
2960 
2961     @Test(dataProvider = "doubleTernaryOpMaskProvider")
2962     static void FMADouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
2963                                           IntFunction<double[]> fc, IntFunction<boolean[]> fm) {
2964         int count = INVOC_COUNT;
2965         switch ("FMA") {
2966         case "fma": case "lanewise_FMA":
2967            // Math.fma uses BigDecimal
2968            count = Math.max(5, count/20); break;
2969         }
2970         final int INVOC_COUNT = count;
2971         double[] a = fa.apply(SPECIES.length());
2972         double[] b = fb.apply(SPECIES.length());
2973         double[] c = fc.apply(SPECIES.length());
2974         double[] r = fr.apply(SPECIES.length());
2975         boolean[] mask = fm.apply(SPECIES.length());
2976         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2977 
2978         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2979             for (int i = 0; i < a.length; i += SPECIES.length()) {
2980                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2981                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2982                 DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i);
2983                 av.lanewise(VectorOperators.FMA, bv, cv, vmask).intoArray(r, i);
2984             }
2985         }
2986 
2987         assertArraysEquals(a, b, c, r, mask, Double512VectorTests::FMA);
2988     }
2989 
2990 
2991 
2992 
2993 
2994     static double NEG(double a) {
2995         return (double)(-((double)a));
2996     }
2997 
2998     @Test(dataProvider = "doubleUnaryOpProvider")
2999     static void NEGDouble512VectorTests(IntFunction<double[]> fa) {
3000         double[] a = fa.apply(SPECIES.length());
3001         double[] r = fr.apply(SPECIES.length());
3002 
3003         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3004             for (int i = 0; i < a.length; i += SPECIES.length()) {
3005                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3006                 av.lanewise(VectorOperators.NEG).intoArray(r, i);
3007             }
3008         }
3009 
3010         assertArraysEquals(a, r, Double512VectorTests::NEG);
3011     }
3012 
3013     @Test(dataProvider = "doubleUnaryOpMaskProvider")
3014     static void NEGMaskedDouble512VectorTests(IntFunction<double[]> fa,
3015                                                 IntFunction<boolean[]> fm) {
3016         double[] a = fa.apply(SPECIES.length());
3017         double[] r = fr.apply(SPECIES.length());
3018         boolean[] mask = fm.apply(SPECIES.length());
3019         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3020 
3021         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3022             for (int i = 0; i < a.length; i += SPECIES.length()) {
3023                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3024                 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i);
3025             }
3026         }
3027 
3028         assertArraysEquals(a, r, mask, Double512VectorTests::NEG);
3029     }
3030 
3031     static double ABS(double a) {
3032         return (double)(Math.abs((double)a));
3033     }
3034 
3035     static double abs(double a) {
3036         return (double)(Math.abs((double)a));
3037     }
3038 
3039     @Test(dataProvider = "doubleUnaryOpProvider")
3040     static void ABSDouble512VectorTests(IntFunction<double[]> fa) {
3041         double[] a = fa.apply(SPECIES.length());
3042         double[] r = fr.apply(SPECIES.length());
3043 
3044         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3045             for (int i = 0; i < a.length; i += SPECIES.length()) {
3046                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3047                 av.lanewise(VectorOperators.ABS).intoArray(r, i);
3048             }
3049         }
3050 
3051         assertArraysEquals(a, r, Double512VectorTests::ABS);
3052     }
3053 
3054     @Test(dataProvider = "doubleUnaryOpProvider")
3055     static void absDouble512VectorTests(IntFunction<double[]> fa) {
3056         double[] a = fa.apply(SPECIES.length());
3057         double[] r = fr.apply(SPECIES.length());
3058 
3059         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3060             for (int i = 0; i < a.length; i += SPECIES.length()) {
3061                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3062                 av.abs().intoArray(r, i);
3063             }
3064         }
3065 
3066         assertArraysEquals(a, r, Double512VectorTests::abs);
3067     }
3068 
3069     @Test(dataProvider = "doubleUnaryOpMaskProvider")
3070     static void ABSMaskedDouble512VectorTests(IntFunction<double[]> fa,
3071                                                 IntFunction<boolean[]> fm) {
3072         double[] a = fa.apply(SPECIES.length());
3073         double[] r = fr.apply(SPECIES.length());
3074         boolean[] mask = fm.apply(SPECIES.length());
3075         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3076 
3077         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3078             for (int i = 0; i < a.length; i += SPECIES.length()) {
3079                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3080                 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i);
3081             }
3082         }
3083 
3084         assertArraysEquals(a, r, mask, Double512VectorTests::ABS);
3085     }
3086 
3087 
3088 
3089 
3090 
3091 
3092 
3093 
3094     static double SQRT(double a) {
3095         return (double)(Math.sqrt((double)a));
3096     }
3097 
3098 
3099 
3100     @Test(dataProvider = "doubleUnaryOpProvider")
3101     static void SQRTDouble512VectorTests(IntFunction<double[]> fa) {
3102         double[] a = fa.apply(SPECIES.length());
3103         double[] r = fr.apply(SPECIES.length());
3104 
3105         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3106             for (int i = 0; i < a.length; i += SPECIES.length()) {
3107                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3108                 av.lanewise(VectorOperators.SQRT).intoArray(r, i);
3109             }
3110         }
3111 
3112         assertArraysEquals(a, r, Double512VectorTests::SQRT);
3113     }
3114 
3115 
3116 
3117     @Test(dataProvider = "doubleUnaryOpMaskProvider")
3118     static void SQRTMaskedDouble512VectorTests(IntFunction<double[]> fa,
3119                                                 IntFunction<boolean[]> fm) {
3120         double[] a = fa.apply(SPECIES.length());
3121         double[] r = fr.apply(SPECIES.length());
3122         boolean[] mask = fm.apply(SPECIES.length());
3123         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3124 
3125         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3126             for (int i = 0; i < a.length; i += SPECIES.length()) {
3127                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3128                 av.lanewise(VectorOperators.SQRT, vmask).intoArray(r, i);
3129             }
3130         }
3131 
3132         assertArraysEquals(a, r, mask, Double512VectorTests::SQRT);
3133     }
3134 
3135     static double[] gather(double a[], int ix, int[] b, int iy) {
3136         double[] res = new double[SPECIES.length()];
3137         for (int i = 0; i < SPECIES.length(); i++) {
3138             int bi = iy + i;
3139             res[i] = a[b[bi] + ix];
3140         }
3141         return res;
3142     }
3143 
3144     @Test(dataProvider = "doubleUnaryOpIndexProvider")
3145     static void gatherDouble512VectorTests(IntFunction<double[]> fa, BiFunction<Integer,Integer,int[]> fs) {
3146         double[] a = fa.apply(SPECIES.length());
3147         int[] b    = fs.apply(a.length, SPECIES.length());
3148         double[] r = new double[a.length];
3149 
3150         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3151             for (int i = 0; i < a.length; i += SPECIES.length()) {
3152                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i);
3153                 av.intoArray(r, i);
3154             }
3155         }
3156 
3157         assertArraysEquals(a, b, r, Double512VectorTests::gather);
3158     }
3159     static double[] gatherMasked(double a[], int ix, boolean[] mask, int[] b, int iy) {
3160         double[] res = new double[SPECIES.length()];
3161         for (int i = 0; i < SPECIES.length(); i++) {
3162             int bi = iy + i;
3163             if (mask[i]) {
3164               res[i] = a[b[bi] + ix];
3165             }
3166         }
3167         return res;
3168     }
3169 
3170     @Test(dataProvider = "doubleUnaryMaskedOpIndexProvider")
3171     static void gatherMaskedDouble512VectorTests(IntFunction<double[]> fa, BiFunction<Integer,Integer,int[]> fs, IntFunction<boolean[]> fm) {
3172         double[] a = fa.apply(SPECIES.length());
3173         int[] b    = fs.apply(a.length, SPECIES.length());
3174         double[] r = new double[a.length];
3175         boolean[] mask = fm.apply(SPECIES.length());
3176         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3177 
3178         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3179             for (int i = 0; i < a.length; i += SPECIES.length()) {
3180                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i, b, i, vmask);
3181                 av.intoArray(r, i);
3182             }
3183         }
3184 
3185         assertArraysEquals(a, b, r, mask, Double512VectorTests::gatherMasked);
3186     }
3187 
3188     static double[] scatter(double a[], int ix, int[] b, int iy) {
3189       double[] res = new double[SPECIES.length()];
3190       for (int i = 0; i < SPECIES.length(); i++) {
3191         int bi = iy + i;
3192         res[b[bi]] = a[i + ix];
3193       }
3194       return res;
3195     }
3196 
3197     @Test(dataProvider = "doubleUnaryOpIndexProvider")
3198     static void scatterDouble512VectorTests(IntFunction<double[]> fa, BiFunction<Integer,Integer,int[]> fs) {
3199         double[] a = fa.apply(SPECIES.length());
3200         int[] b = fs.apply(a.length, SPECIES.length());
3201         double[] r = new double[a.length];
3202 
3203         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3204             for (int i = 0; i < a.length; i += SPECIES.length()) {
3205                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3206                 av.intoArray(r, i, b, i);
3207             }
3208         }
3209 
3210         assertArraysEquals(a, b, r, Double512VectorTests::scatter);
3211     }
3212 
3213     static double[] scatterMasked(double r[], double a[], int ix, boolean[] mask, int[] b, int iy) {
3214       // First, gather r.
3215       double[] oldVal = gather(r, ix, b, iy);
3216       double[] newVal = new double[SPECIES.length()];
3217 
3218       // Second, blending it with a.
3219       for (int i = 0; i < SPECIES.length(); i++) {
3220         newVal[i] = blend(oldVal[i], a[i+ix], mask[i]);
3221       }
3222 
3223       // Third, scatter: copy old value of r, and scatter it manually.
3224       double[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length());
3225       for (int i = 0; i < SPECIES.length(); i++) {
3226         int bi = iy + i;
3227         res[b[bi]] = newVal[i];
3228       }
3229 
3230       return res;
3231     }
3232 
3233     @Test(dataProvider = "scatterMaskedOpIndexProvider")
3234     static void scatterMaskedDouble512VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb, BiFunction<Integer,Integer,int[]> fs, IntFunction<boolean[]> fm) {
3235         double[] a = fa.apply(SPECIES.length());
3236         int[] b = fs.apply(a.length, SPECIES.length());
3237         double[] r = fb.apply(SPECIES.length());
3238         boolean[] mask = fm.apply(SPECIES.length());
3239         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3240 
3241         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3242             for (int i = 0; i < a.length; i += SPECIES.length()) {
3243                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3244                 av.intoArray(r, i, b, i, vmask);
3245             }
3246         }
3247 
3248         assertArraysEquals(a, b, r, mask, Double512VectorTests::scatterMasked);
3249     }
3250 
3251 }
3252