1 /*
   2  * Copyright (c) 2018, 2022, 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 -XX:-TieredCompilation DoubleMaxVectorTests
  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.Objects;
  51 import java.util.stream.Collectors;
  52 import java.util.stream.Stream;
  53 
  54 @Test
  55 public class DoubleMaxVectorTests extends AbstractVectorTest {
  56 
  57     static final VectorSpecies<Double> SPECIES =
  58                 DoubleVector.SPECIES_MAX;
  59 
  60     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  61 
  62     static VectorShape getMaxBit() {
  63         return VectorShape.S_Max_BIT;
  64     }
  65 
  66     private static final int Max = 256;  // juts so we can do N/Max
  67 
  68 
  69     static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max);
  70 
  71     interface FUnOp {
  72         double apply(double a);
  73     }
  74 
  75     static void assertArraysEquals(double[] r, double[] a, FUnOp f) {
  76         int i = 0;
  77         try {
  78             for (; i < a.length; i++) {
  79                 Assert.assertEquals(r[i], f.apply(a[i]));
  80             }
  81         } catch (AssertionError e) {
  82             Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
  83         }
  84     }
  85 
  86     interface FUnArrayOp {
  87         double[] apply(double a);
  88     }
  89 
  90     static void assertArraysEquals(double[] r, double[] a, FUnArrayOp f) {
  91         int i = 0;
  92         try {
  93             for (; i < a.length; i += SPECIES.length()) {
  94                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
  95                   f.apply(a[i]));
  96             }
  97         } catch (AssertionError e) {
  98             double[] ref = f.apply(a[i]);
  99             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 100             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 101               + ", res: " + Arrays.toString(res)
 102               + "), at index #" + i);
 103         }
 104     }
 105 
 106     static void assertArraysEquals(double[] r, double[] a, boolean[] mask, FUnOp f) {
 107         int i = 0;
 108         try {
 109             for (; i < a.length; i++) {
 110                 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]);
 111             }
 112         } catch (AssertionError e) {
 113             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()]);
 114         }
 115     }
 116 
 117     interface FReductionOp {
 118         double apply(double[] a, int idx);
 119     }
 120 
 121     interface FReductionAllOp {
 122         double apply(double[] a);
 123     }
 124 
 125     static void assertReductionArraysEquals(double[] r, double rc, double[] a,
 126                                             FReductionOp f, FReductionAllOp fa) {
 127         int i = 0;
 128         try {
 129             Assert.assertEquals(rc, fa.apply(a));
 130             for (; i < a.length; i += SPECIES.length()) {
 131                 Assert.assertEquals(r[i], f.apply(a, i));
 132             }
 133         } catch (AssertionError e) {
 134             Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!");
 135             Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
 136         }
 137     }
 138 
 139     interface FReductionMaskedOp {
 140         double apply(double[] a, int idx, boolean[] mask);
 141     }
 142 
 143     interface FReductionAllMaskedOp {
 144         double apply(double[] a, boolean[] mask);
 145     }
 146 
 147     static void assertReductionArraysEqualsMasked(double[] r, double rc, double[] a, boolean[] mask,
 148                                             FReductionMaskedOp f, FReductionAllMaskedOp fa) {
 149         int i = 0;
 150         try {
 151             Assert.assertEquals(rc, fa.apply(a, mask));
 152             for (; i < a.length; i += SPECIES.length()) {
 153                 Assert.assertEquals(r[i], f.apply(a, i, mask));
 154             }
 155         } catch (AssertionError e) {
 156             Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
 157             Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
 158         }
 159     }
 160 
 161     interface FReductionOpLong {
 162         long apply(double[] a, int idx);
 163     }
 164 
 165     interface FReductionAllOpLong {
 166         long apply(double[] a);
 167     }
 168 
 169     static void assertReductionLongArraysEquals(long[] r, long rc, double[] a,
 170                                             FReductionOpLong f, FReductionAllOpLong fa) {
 171         int i = 0;
 172         try {
 173             Assert.assertEquals(rc, fa.apply(a));
 174             for (; i < a.length; i += SPECIES.length()) {
 175                 Assert.assertEquals(r[i], f.apply(a, i));
 176             }
 177         } catch (AssertionError e) {
 178             Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!");
 179             Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
 180         }
 181     }
 182 
 183     interface FReductionMaskedOpLong {
 184         long apply(double[] a, int idx, boolean[] mask);
 185     }
 186 
 187     interface FReductionAllMaskedOpLong {
 188         long apply(double[] a, boolean[] mask);
 189     }
 190 
 191     static void assertReductionLongArraysEqualsMasked(long[] r, long rc, double[] a, boolean[] mask,
 192                                             FReductionMaskedOpLong f, FReductionAllMaskedOpLong fa) {
 193         int i = 0;
 194         try {
 195             Assert.assertEquals(rc, fa.apply(a, mask));
 196             for (; i < a.length; i += SPECIES.length()) {
 197                 Assert.assertEquals(r[i], f.apply(a, i, mask));
 198             }
 199         } catch (AssertionError e) {
 200             Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
 201             Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
 202         }
 203     }
 204 
 205     interface FBoolReductionOp {
 206         boolean apply(boolean[] a, int idx);
 207     }
 208 
 209     static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReductionOp f) {
 210         int i = 0;
 211         try {
 212             for (; i < a.length; i += SPECIES.length()) {
 213                 Assert.assertEquals(r[i], f.apply(a, i));
 214             }
 215         } catch (AssertionError e) {
 216             Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
 217         }
 218     }
 219 
 220     interface FMaskReductionOp {
 221         int apply(boolean[] a, int idx);
 222     }
 223 
 224     static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) {
 225         int i = 0;
 226         try {
 227             for (; i < a.length; i += SPECIES.length()) {
 228                 Assert.assertEquals(r[i], f.apply(a, i));
 229             }
 230         } catch (AssertionError e) {
 231             Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
 232         }
 233     }
 234 
 235     static void assertInsertArraysEquals(double[] r, double[] a, double element, int index, int start, int end) {
 236         int i = start;
 237         try {
 238             for (; i < end; i += 1) {
 239                 if(i%SPECIES.length() == index) {
 240                     Assert.assertEquals(r[i], element);
 241                 } else {
 242                     Assert.assertEquals(r[i], a[i]);
 243                 }
 244             }
 245         } catch (AssertionError e) {
 246             if (i%SPECIES.length() == index) {
 247                 Assert.assertEquals(r[i], element, "at index #" + i);
 248             } else {
 249                 Assert.assertEquals(r[i], a[i], "at index #" + i);
 250             }
 251         }
 252     }
 253 
 254     static void assertRearrangeArraysEquals(double[] r, double[] a, int[] order, int vector_len) {
 255         int i = 0, j = 0;
 256         try {
 257             for (; i < a.length; i += vector_len) {
 258                 for (j = 0; j < vector_len; j++) {
 259                     Assert.assertEquals(r[i+j], a[i+order[i+j]]);
 260                 }
 261             }
 262         } catch (AssertionError e) {
 263             int idx = i + j;
 264             Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
 265         }
 266     }
 267 
 268     static void assertcompressArraysEquals(double[] r, double[] a, boolean[] m, int vector_len) {
 269         int i = 0, j = 0, k = 0;
 270         try {
 271             for (; i < a.length; i += vector_len) {
 272                 k = 0;
 273                 for (j = 0; j < vector_len; j++) {
 274                     if (m[(i + j) % SPECIES.length()]) {
 275                         Assert.assertEquals(r[i + k], a[i + j]);
 276                         k++;
 277                     }
 278                 }
 279                 for (; k < vector_len; k++) {
 280                     Assert.assertEquals(r[i + k], (double)0);
 281                 }
 282             }
 283         } catch (AssertionError e) {
 284             int idx = i + k;
 285             if (m[(i + j) % SPECIES.length()]) {
 286                 Assert.assertEquals(r[idx], a[i + j], "at index #" + idx);
 287             } else {
 288                 Assert.assertEquals(r[idx], (double)0, "at index #" + idx);
 289             }
 290         }
 291     }
 292 
 293     static void assertexpandArraysEquals(double[] r, double[] a, boolean[] m, int vector_len) {
 294         int i = 0, j = 0, k = 0;
 295         try {
 296             for (; i < a.length; i += vector_len) {
 297                 k = 0;
 298                 for (j = 0; j < vector_len; j++) {
 299                     if (m[(i + j) % SPECIES.length()]) {
 300                         Assert.assertEquals(r[i + j], a[i + k]);
 301                         k++;
 302                     } else {
 303                         Assert.assertEquals(r[i + j], (double)0);
 304                     }
 305                 }
 306             }
 307         } catch (AssertionError e) {
 308             int idx = i + j;
 309             if (m[idx % SPECIES.length()]) {
 310                 Assert.assertEquals(r[idx], a[i + k], "at index #" + idx);
 311             } else {
 312                 Assert.assertEquals(r[idx], (double)0, "at index #" + idx);
 313             }
 314         }
 315     }
 316 
 317     static void assertSelectFromArraysEquals(double[] r, double[] a, double[] order, int vector_len) {
 318         int i = 0, j = 0;
 319         try {
 320             for (; i < a.length; i += vector_len) {
 321                 for (j = 0; j < vector_len; j++) {
 322                     Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]);
 323                 }
 324             }
 325         } catch (AssertionError e) {
 326             int idx = i + j;
 327             Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]);
 328         }
 329     }
 330 
 331     static void assertRearrangeArraysEquals(double[] r, double[] a, int[] order, boolean[] mask, int vector_len) {
 332         int i = 0, j = 0;
 333         try {
 334             for (; i < a.length; i += vector_len) {
 335                 for (j = 0; j < vector_len; j++) {
 336                     if (mask[j % SPECIES.length()])
 337                          Assert.assertEquals(r[i+j], a[i+order[i+j]]);
 338                     else
 339                          Assert.assertEquals(r[i+j], (double)0);
 340                 }
 341             }
 342         } catch (AssertionError e) {
 343             int idx = i + j;
 344             if (mask[j % SPECIES.length()])
 345                 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
 346             else
 347                 Assert.assertEquals(r[i+j], (double)0, "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
 348         }
 349     }
 350 
 351     static void assertSelectFromArraysEquals(double[] r, double[] a, double[] order, boolean[] mask, int vector_len) {
 352         int i = 0, j = 0;
 353         try {
 354             for (; i < a.length; i += vector_len) {
 355                 for (j = 0; j < vector_len; j++) {
 356                     if (mask[j % SPECIES.length()])
 357                          Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]);
 358                     else
 359                          Assert.assertEquals(r[i+j], (double)0);
 360                 }
 361             }
 362         } catch (AssertionError e) {
 363             int idx = i + j;
 364             if (mask[j % SPECIES.length()])
 365                 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
 366             else
 367                 Assert.assertEquals(r[i+j], (double)0, "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
 368         }
 369     }
 370 
 371     static void assertBroadcastArraysEquals(double[] r, double[] a) {
 372         int i = 0;
 373         for (; i < a.length; i += SPECIES.length()) {
 374             int idx = i;
 375             for (int j = idx; j < (idx + SPECIES.length()); j++)
 376                 a[j]=a[idx];
 377         }
 378 
 379         try {
 380             for (i = 0; i < a.length; i++) {
 381                 Assert.assertEquals(r[i], a[i]);
 382             }
 383         } catch (AssertionError e) {
 384             Assert.assertEquals(r[i], a[i], "at index #" + i + ", input = " + a[i]);
 385         }
 386     }
 387 
 388     interface FBinOp {
 389         double apply(double a, double b);
 390     }
 391 
 392     interface FBinMaskOp {
 393         double apply(double a, double b, boolean m);
 394 
 395         static FBinMaskOp lift(FBinOp f) {
 396             return (a, b, m) -> m ? f.apply(a, b) : a;
 397         }
 398     }
 399 
 400     static void assertArraysEquals(double[] r, double[] a, double[] b, FBinOp f) {
 401         int i = 0;
 402         try {
 403             for (; i < a.length; i++) {
 404                 Assert.assertEquals(r[i], f.apply(a[i], b[i]));
 405             }
 406         } catch (AssertionError e) {
 407             Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i);
 408         }
 409     }
 410 
 411     static void assertBroadcastArraysEquals(double[] r, double[] a, double[] b, FBinOp f) {
 412         int i = 0;
 413         try {
 414             for (; i < a.length; i++) {
 415                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]));
 416             }
 417         } catch (AssertionError e) {
 418             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]),
 419                                 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i);
 420         }
 421     }
 422 
 423     static void assertBroadcastLongArraysEquals(double[] r, double[] a, double[] b, FBinOp f) {
 424         int i = 0;
 425         try {
 426             for (; i < a.length; i++) {
 427                 Assert.assertEquals(r[i], f.apply(a[i], (double)((long)b[(i / SPECIES.length()) * SPECIES.length()])));
 428             }
 429         } catch (AssertionError e) {
 430             Assert.assertEquals(r[i], f.apply(a[i], (double)((long)b[(i / SPECIES.length()) * SPECIES.length()])),
 431                                 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i);
 432         }
 433     }
 434 
 435     static void assertArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinOp f) {
 436         assertArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
 437     }
 438 
 439     static void assertArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinMaskOp f) {
 440         int i = 0;
 441         try {
 442             for (; i < a.length; i++) {
 443                 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]));
 444             }
 445         } catch (AssertionError err) {
 446             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()]);
 447         }
 448     }
 449 
 450     static void assertBroadcastArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinOp f) {
 451         assertBroadcastArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
 452     }
 453 
 454     static void assertBroadcastArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinMaskOp f) {
 455         int i = 0;
 456         try {
 457             for (; i < a.length; i++) {
 458                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]));
 459             }
 460         } catch (AssertionError err) {
 461             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
 462                                 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] +
 463                                 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
 464                                 mask[i % SPECIES.length()]);
 465         }
 466     }
 467 
 468     static void assertBroadcastLongArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinOp f) {
 469         assertBroadcastLongArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
 470     }
 471 
 472     static void assertBroadcastLongArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinMaskOp f) {
 473         int i = 0;
 474         try {
 475             for (; i < a.length; i++) {
 476                 Assert.assertEquals(r[i], f.apply(a[i], (double)((long)b[(i / SPECIES.length()) * SPECIES.length()]), mask[i % SPECIES.length()]));
 477             }
 478         } catch (AssertionError err) {
 479             Assert.assertEquals(r[i], f.apply(a[i], (double)((long)b[(i / SPECIES.length()) * SPECIES.length()]),
 480                                 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] +
 481                                 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
 482                                 mask[i % SPECIES.length()]);
 483         }
 484     }
 485 
 486     static void assertShiftArraysEquals(double[] r, double[] a, double[] b, FBinOp f) {
 487         int i = 0;
 488         int j = 0;
 489         try {
 490             for (; j < a.length; j += SPECIES.length()) {
 491                 for (i = 0; i < SPECIES.length(); i++) {
 492                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]));
 493                 }
 494             }
 495         } catch (AssertionError e) {
 496             Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j);
 497         }
 498     }
 499 
 500     static void assertShiftArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinOp f) {
 501         assertShiftArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
 502     }
 503 
 504     static void assertShiftArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinMaskOp f) {
 505         int i = 0;
 506         int j = 0;
 507         try {
 508             for (; j < a.length; j += SPECIES.length()) {
 509                 for (i = 0; i < SPECIES.length(); i++) {
 510                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i]));
 511                 }
 512             }
 513         } catch (AssertionError err) {
 514             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]);
 515         }
 516     }
 517 
 518     interface FBinConstOp {
 519         double apply(double a);
 520     }
 521 
 522     interface FBinConstMaskOp {
 523         double apply(double a, boolean m);
 524 
 525         static FBinConstMaskOp lift(FBinConstOp f) {
 526             return (a, m) -> m ? f.apply(a) : a;
 527         }
 528     }
 529 
 530     static void assertShiftConstEquals(double[] r, double[] a, FBinConstOp f) {
 531         int i = 0;
 532         int j = 0;
 533         try {
 534             for (; j < a.length; j += SPECIES.length()) {
 535                 for (i = 0; i < SPECIES.length(); i++) {
 536                     Assert.assertEquals(r[i+j], f.apply(a[i+j]));
 537                 }
 538             }
 539         } catch (AssertionError e) {
 540             Assert.assertEquals(r[i+j], f.apply(a[i+j]), "at index #" + i + ", " + j);
 541         }
 542     }
 543 
 544     static void assertShiftConstEquals(double[] r, double[] a, boolean[] mask, FBinConstOp f) {
 545         assertShiftConstEquals(r, a, mask, FBinConstMaskOp.lift(f));
 546     }
 547 
 548     static void assertShiftConstEquals(double[] r, double[] a, boolean[] mask, FBinConstMaskOp f) {
 549         int i = 0;
 550         int j = 0;
 551         try {
 552             for (; j < a.length; j += SPECIES.length()) {
 553                 for (i = 0; i < SPECIES.length(); i++) {
 554                     Assert.assertEquals(r[i+j], f.apply(a[i+j], mask[i]));
 555                 }
 556             }
 557         } catch (AssertionError err) {
 558             Assert.assertEquals(r[i+j], f.apply(a[i+j], mask[i]), "at index #" + i + ", input1 = " + a[i+j] + ", mask = " + mask[i]);
 559         }
 560     }
 561 
 562     interface FTernOp {
 563         double apply(double a, double b, double c);
 564     }
 565 
 566     interface FTernMaskOp {
 567         double apply(double a, double b, double c, boolean m);
 568 
 569         static FTernMaskOp lift(FTernOp f) {
 570             return (a, b, c, m) -> m ? f.apply(a, b, c) : a;
 571         }
 572     }
 573 
 574     static void assertArraysEquals(double[] r, double[] a, double[] b, double[] c, FTernOp f) {
 575         int i = 0;
 576         try {
 577             for (; i < a.length; i++) {
 578                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]));
 579             }
 580         } catch (AssertionError e) {
 581             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
 582         }
 583     }
 584 
 585     static void assertArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask, FTernOp f) {
 586         assertArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
 587     }
 588 
 589     static void assertArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask, FTernMaskOp f) {
 590         int i = 0;
 591         try {
 592             for (; i < a.length; i++) {
 593                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]));
 594             }
 595         } catch (AssertionError err) {
 596             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = "
 597               + b[i] + ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]);
 598         }
 599     }
 600 
 601     static void assertBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, FTernOp f) {
 602         int i = 0;
 603         try {
 604             for (; i < a.length; i++) {
 605                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()]));
 606             }
 607         } catch (AssertionError e) {
 608             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" +
 609                                 i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " +
 610                                 c[(i / SPECIES.length()) * SPECIES.length()]);
 611         }
 612     }
 613 
 614     static void assertAltBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, FTernOp f) {
 615         int i = 0;
 616         try {
 617             for (; i < a.length; i++) {
 618                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i]));
 619             }
 620         } catch (AssertionError e) {
 621             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i]), "at index #" +
 622                                 i + ", input1 = " + a[i] + ", input2 = " +
 623                                 b[(i / SPECIES.length()) * SPECIES.length()] + ",  input3 = " + c[i]);
 624         }
 625     }
 626 
 627     static void assertBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask,
 628                                             FTernOp f) {
 629         assertBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
 630     }
 631 
 632     static void assertBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask,
 633                                             FTernMaskOp f) {
 634         int i = 0;
 635         try {
 636             for (; i < a.length; i++) {
 637                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()],
 638                                     mask[i % SPECIES.length()]));
 639             }
 640         } catch (AssertionError err) {
 641             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()],
 642                                 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " +
 643                                 b[i] + ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
 644                                 mask[i % SPECIES.length()]);
 645         }
 646     }
 647 
 648     static void assertAltBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask,
 649                                             FTernOp f) {
 650         assertAltBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
 651     }
 652 
 653     static void assertAltBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask,
 654                                             FTernMaskOp f) {
 655         int i = 0;
 656         try {
 657             for (; i < a.length; i++) {
 658                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i],
 659                                     mask[i % SPECIES.length()]));
 660             }
 661         } catch (AssertionError err) {
 662             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i],
 663                                 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] +
 664                                 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] +
 665                                 ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]);
 666         }
 667     }
 668 
 669     static void assertDoubleBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, FTernOp f) {
 670         int i = 0;
 671         try {
 672             for (; i < a.length; i++) {
 673                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
 674                                     c[(i / SPECIES.length()) * SPECIES.length()]));
 675             }
 676         } catch (AssertionError e) {
 677             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
 678                                 c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" + i + ", input1 = " + a[i]
 679                                 + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", input3 = " +
 680                                 c[(i / SPECIES.length()) * SPECIES.length()]);
 681         }
 682     }
 683 
 684     static void assertDoubleBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask,
 685                                                   FTernOp f) {
 686         assertDoubleBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
 687     }
 688 
 689     static void assertDoubleBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask,
 690                                                   FTernMaskOp f) {
 691         int i = 0;
 692         try {
 693             for (; i < a.length; i++) {
 694                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
 695                                     c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]));
 696             }
 697         } catch (AssertionError err) {
 698             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
 699                                 c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]), "at index #"
 700                                 + i + ", input1 = " + a[i] + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] +
 701                                 ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
 702                                 mask[i % SPECIES.length()]);
 703         }
 704     }
 705 
 706 
 707     static boolean isWithin1Ulp(double actual, double expected) {
 708         if (Double.isNaN(expected) && !Double.isNaN(actual)) {
 709             return false;
 710         } else if (!Double.isNaN(expected) && Double.isNaN(actual)) {
 711             return false;
 712         }
 713 
 714         double low = Math.nextDown(expected);
 715         double high = Math.nextUp(expected);
 716 
 717         if (Double.compare(low, expected) > 0) {
 718             return false;
 719         }
 720 
 721         if (Double.compare(high, expected) < 0) {
 722             return false;
 723         }
 724 
 725         return true;
 726     }
 727 
 728     static void assertArraysEqualsWithinOneUlp(double[] r, double[] a, FUnOp mathf, FUnOp strictmathf) {
 729         int i = 0;
 730         try {
 731             // Check that result is within 1 ulp of strict math or equivalent to math implementation.
 732             for (; i < a.length; i++) {
 733                 Assert.assertTrue(Double.compare(r[i], mathf.apply(a[i])) == 0 ||
 734                                     isWithin1Ulp(r[i], strictmathf.apply(a[i])));
 735             }
 736         } catch (AssertionError e) {
 737             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]));
 738             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]));
 739         }
 740     }
 741 
 742     static void assertArraysEqualsWithinOneUlp(double[] r, double[] a, double[] b, FBinOp mathf, FBinOp strictmathf) {
 743         int i = 0;
 744         try {
 745             // Check that result is within 1 ulp of strict math or equivalent to math implementation.
 746             for (; i < a.length; i++) {
 747                 Assert.assertTrue(Double.compare(r[i], mathf.apply(a[i], b[i])) == 0 ||
 748                                     isWithin1Ulp(r[i], strictmathf.apply(a[i], b[i])));
 749             }
 750         } catch (AssertionError e) {
 751             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]));
 752             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]));
 753         }
 754     }
 755 
 756     static void assertBroadcastArraysEqualsWithinOneUlp(double[] r, double[] a, double[] b,
 757                                                         FBinOp mathf, FBinOp strictmathf) {
 758         int i = 0;
 759         try {
 760             // Check that result is within 1 ulp of strict math or equivalent to math implementation.
 761             for (; i < a.length; i++) {
 762                 Assert.assertTrue(Double.compare(r[i],
 763                                   mathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])) == 0 ||
 764                                   isWithin1Ulp(r[i],
 765                                   strictmathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])));
 766             }
 767         } catch (AssertionError e) {
 768             Assert.assertTrue(Double.compare(r[i],
 769                               mathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])) == 0,
 770                               "at index #" + i + ", input1 = " + a[i] + ", input2 = " +
 771                               b[(i / SPECIES.length()) * SPECIES.length()] + ", actual = " + r[i] +
 772                               ", expected = " + mathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]));
 773             Assert.assertTrue(isWithin1Ulp(r[i],
 774                               strictmathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])),
 775                              "at index #" + i + ", input1 = " + a[i] + ", input2 = " +
 776                              b[(i / SPECIES.length()) * SPECIES.length()] + ", actual = " + r[i] +
 777                              ", expected (within 1 ulp) = " + strictmathf.apply(a[i],
 778                              b[(i / SPECIES.length()) * SPECIES.length()]));
 779         }
 780     }
 781 
 782     interface FBinArrayOp {
 783         double apply(double[] a, int b);
 784     }
 785 
 786     static void assertArraysEquals(double[] r, double[] a, FBinArrayOp f) {
 787         int i = 0;
 788         try {
 789             for (; i < a.length; i++) {
 790                 Assert.assertEquals(r[i], f.apply(a, i));
 791             }
 792         } catch (AssertionError e) {
 793             Assert.assertEquals(r[i], f.apply(a,i), "at index #" + i);
 794         }
 795     }
 796 
 797     interface FGatherScatterOp {
 798         double[] apply(double[] a, int ix, int[] b, int iy);
 799     }
 800 
 801     static void assertArraysEquals(double[] r, double[] a, int[] b, FGatherScatterOp f) {
 802         int i = 0;
 803         try {
 804             for (; i < a.length; i += SPECIES.length()) {
 805                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 806                   f.apply(a, i, b, i));
 807             }
 808         } catch (AssertionError e) {
 809             double[] ref = f.apply(a, i, b, i);
 810             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 811             Assert.assertEquals(res, ref,
 812               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 813               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 814               + ", b: "
 815               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 816               + " at index #" + i);
 817         }
 818     }
 819 
 820     interface FGatherMaskedOp {
 821         double[] apply(double[] a, int ix, boolean[] mask, int[] b, int iy);
 822     }
 823 
 824     interface FScatterMaskedOp {
 825         double[] apply(double[] r, double[] a, int ix, boolean[] mask, int[] b, int iy);
 826     }
 827 
 828     static void assertArraysEquals(double[] r, double[] a, int[] b, boolean[] mask, FGatherMaskedOp f) {
 829         int i = 0;
 830         try {
 831             for (; i < a.length; i += SPECIES.length()) {
 832                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 833                   f.apply(a, i, mask, b, i));
 834             }
 835         } catch (AssertionError e) {
 836             double[] ref = f.apply(a, i, mask, b, i);
 837             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 838             Assert.assertEquals(res, ref,
 839               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 840               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 841               + ", b: "
 842               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 843               + ", mask: "
 844               + Arrays.toString(mask)
 845               + " at index #" + i);
 846         }
 847     }
 848 
 849     static void assertArraysEquals(double[] r, double[] a, int[] b, boolean[] mask, FScatterMaskedOp f) {
 850         int i = 0;
 851         try {
 852             for (; i < a.length; i += SPECIES.length()) {
 853                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 854                   f.apply(r, a, i, mask, b, i));
 855             }
 856         } catch (AssertionError e) {
 857             double[] ref = f.apply(r, a, i, mask, b, i);
 858             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 859             Assert.assertEquals(res, ref,
 860               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 861               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 862               + ", b: "
 863               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 864               + ", r: "
 865               + Arrays.toString(Arrays.copyOfRange(r, i, i+SPECIES.length()))
 866               + ", mask: "
 867               + Arrays.toString(mask)
 868               + " at index #" + i);
 869         }
 870     }
 871 
 872     interface FLaneOp {
 873         double[] apply(double[] a, int origin, int idx);
 874     }
 875 
 876     static void assertArraysEquals(double[] r, double[] a, int origin, FLaneOp f) {
 877         int i = 0;
 878         try {
 879             for (; i < a.length; i += SPECIES.length()) {
 880                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 881                   f.apply(a, origin, i));
 882             }
 883         } catch (AssertionError e) {
 884             double[] ref = f.apply(a, origin, i);
 885             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 886             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 887               + ", res: " + Arrays.toString(res)
 888               + "), at index #" + i);
 889         }
 890     }
 891 
 892     interface FLaneBop {
 893         double[] apply(double[] a, double[] b, int origin, int idx);
 894     }
 895 
 896     static void assertArraysEquals(double[] r, double[] a, double[] b, int origin, FLaneBop f) {
 897         int i = 0;
 898         try {
 899             for (; i < a.length; i += SPECIES.length()) {
 900                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 901                   f.apply(a, b, origin, i));
 902             }
 903         } catch (AssertionError e) {
 904             double[] ref = f.apply(a, b, origin, i);
 905             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 906             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 907               + ", res: " + Arrays.toString(res)
 908               + "), at index #" + i
 909               + ", at origin #" + origin);
 910         }
 911     }
 912 
 913     interface FLaneMaskedBop {
 914         double[] apply(double[] a, double[] b, int origin, boolean[] mask, int idx);
 915     }
 916 
 917     static void assertArraysEquals(double[] r, double[] a, double[] b, int origin, boolean[] mask, FLaneMaskedBop f) {
 918         int i = 0;
 919         try {
 920             for (; i < a.length; i += SPECIES.length()) {
 921                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 922                   f.apply(a, b, origin, mask, i));
 923             }
 924         } catch (AssertionError e) {
 925             double[] ref = f.apply(a, b, origin, mask, i);
 926             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 927             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 928               + ", res: " + Arrays.toString(res)
 929               + "), at index #" + i
 930               + ", at origin #" + origin);
 931         }
 932     }
 933 
 934     interface FLanePartBop {
 935         double[] apply(double[] a, double[] b, int origin, int part, int idx);
 936     }
 937 
 938     static void assertArraysEquals(double[] r, double[] a, double[] b, int origin, int part, FLanePartBop f) {
 939         int i = 0;
 940         try {
 941             for (; i < a.length; i += SPECIES.length()) {
 942                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 943                   f.apply(a, b, origin, part, i));
 944             }
 945         } catch (AssertionError e) {
 946             double[] ref = f.apply(a, b, origin, part, i);
 947             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 948             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 949               + ", res: " + Arrays.toString(res)
 950               + "), at index #" + i
 951               + ", at origin #" + origin
 952               + ", with part #" + part);
 953         }
 954     }
 955 
 956     interface FLanePartMaskedBop {
 957         double[] apply(double[] a, double[] b, int origin, int part, boolean[] mask, int idx);
 958     }
 959 
 960     static void assertArraysEquals(double[] r, double[] a, double[] b, int origin, int part, boolean[] mask, FLanePartMaskedBop f) {
 961         int i = 0;
 962         try {
 963             for (; i < a.length; i += SPECIES.length()) {
 964                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 965                   f.apply(a, b, origin, part, mask, i));
 966             }
 967         } catch (AssertionError e) {
 968             double[] ref = f.apply(a, b, origin, part, mask, i);
 969             double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 970             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 971               + ", res: " + Arrays.toString(res)
 972               + "), at index #" + i
 973               + ", at origin #" + origin
 974               + ", with part #" + part);
 975         }
 976     }
 977 
 978     static int intCornerCaseValue(int i) {
 979         switch(i % 5) {
 980             case 0:
 981                 return Integer.MAX_VALUE;
 982             case 1:
 983                 return Integer.MIN_VALUE;
 984             case 2:
 985                 return Integer.MIN_VALUE;
 986             case 3:
 987                 return Integer.MAX_VALUE;
 988             default:
 989                 return (int)0;
 990         }
 991     }
 992 
 993     static final List<IntFunction<double[]>> INT_DOUBLE_GENERATORS = List.of(
 994             withToString("double[-i * 5]", (int s) -> {
 995                 return fill(s * BUFFER_REPS,
 996                             i -> (double)(-i * 5));
 997             }),
 998             withToString("double[i * 5]", (int s) -> {
 999                 return fill(s * BUFFER_REPS,
1000                             i -> (double)(i * 5));
1001             }),
1002             withToString("double[i + 1]", (int s) -> {
1003                 return fill(s * BUFFER_REPS,
1004                             i -> (((double)(i + 1) == 0) ? 1 : (double)(i + 1)));
1005             }),
1006             withToString("double[intCornerCaseValue(i)]", (int s) -> {
1007                 return fill(s * BUFFER_REPS,
1008                             i -> (double)intCornerCaseValue(i));
1009             })
1010     );
1011 
1012     static void assertArraysEquals(int[] r, double[] a, int offs) {
1013         int i = 0;
1014         try {
1015             for (; i < r.length; i++) {
1016                 Assert.assertEquals(r[i], (int)(a[i+offs]));
1017             }
1018         } catch (AssertionError e) {
1019             Assert.assertEquals(r[i], (int)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
1020         }
1021     }
1022 
1023     static long longCornerCaseValue(int i) {
1024         switch(i % 5) {
1025             case 0:
1026                 return Long.MAX_VALUE;
1027             case 1:
1028                 return Long.MIN_VALUE;
1029             case 2:
1030                 return Long.MIN_VALUE;
1031             case 3:
1032                 return Long.MAX_VALUE;
1033             default:
1034                 return (long)0;
1035         }
1036     }
1037 
1038     static final List<IntFunction<double[]>> LONG_DOUBLE_GENERATORS = List.of(
1039             withToString("double[-i * 5]", (int s) -> {
1040                 return fill(s * BUFFER_REPS,
1041                             i -> (double)(-i * 5));
1042             }),
1043             withToString("double[i * 5]", (int s) -> {
1044                 return fill(s * BUFFER_REPS,
1045                             i -> (double)(i * 5));
1046             }),
1047             withToString("double[i + 1]", (int s) -> {
1048                 return fill(s * BUFFER_REPS,
1049                             i -> (((double)(i + 1) == 0) ? 1 : (double)(i + 1)));
1050             }),
1051             withToString("double[cornerCaseValue(i)]", (int s) -> {
1052                 return fill(s * BUFFER_REPS,
1053                             i -> (double)longCornerCaseValue(i));
1054             })
1055     );
1056 
1057 
1058     static void assertArraysEquals(long[] r, double[] a, int offs) {
1059         int i = 0;
1060         try {
1061             for (; i < r.length; i++) {
1062                 Assert.assertEquals(r[i], (long)(a[i+offs]));
1063             }
1064         } catch (AssertionError e) {
1065             Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
1066         }
1067     }
1068 
1069     static long bits(double e) {
1070         return  Double.doubleToLongBits(e);
1071     }
1072 
1073     static final List<IntFunction<double[]>> DOUBLE_GENERATORS = List.of(
1074             withToString("double[-i * 5]", (int s) -> {
1075                 return fill(s * BUFFER_REPS,
1076                             i -> (double)(-i * 5));
1077             }),
1078             withToString("double[i * 5]", (int s) -> {
1079                 return fill(s * BUFFER_REPS,
1080                             i -> (double)(i * 5));
1081             }),
1082             withToString("double[i + 1]", (int s) -> {
1083                 return fill(s * BUFFER_REPS,
1084                             i -> (((double)(i + 1) == 0) ? 1 : (double)(i + 1)));
1085             }),
1086             withToString("double[cornerCaseValue(i)]", (int s) -> {
1087                 return fill(s * BUFFER_REPS,
1088                             i -> cornerCaseValue(i));
1089             })
1090     );
1091 
1092     // Create combinations of pairs
1093     // @@@ Might be sensitive to order e.g. div by 0
1094     static final List<List<IntFunction<double[]>>> DOUBLE_GENERATOR_PAIRS =
1095         Stream.of(DOUBLE_GENERATORS.get(0)).
1096                 flatMap(fa -> DOUBLE_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
1097                 collect(Collectors.toList());
1098 
1099     @DataProvider
1100     public Object[][] boolUnaryOpProvider() {
1101         return BOOL_ARRAY_GENERATORS.stream().
1102                 map(f -> new Object[]{f}).
1103                 toArray(Object[][]::new);
1104     }
1105 
1106     static final List<List<IntFunction<double[]>>> DOUBLE_GENERATOR_TRIPLES =
1107         DOUBLE_GENERATOR_PAIRS.stream().
1108                 flatMap(pair -> DOUBLE_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))).
1109                 collect(Collectors.toList());
1110 
1111     @DataProvider
1112     public Object[][] doubleBinaryOpProvider() {
1113         return DOUBLE_GENERATOR_PAIRS.stream().map(List::toArray).
1114                 toArray(Object[][]::new);
1115     }
1116 
1117     @DataProvider
1118     public Object[][] doubleIndexedOpProvider() {
1119         return DOUBLE_GENERATOR_PAIRS.stream().map(List::toArray).
1120                 toArray(Object[][]::new);
1121     }
1122 
1123     @DataProvider
1124     public Object[][] doubleBinaryOpMaskProvider() {
1125         return BOOLEAN_MASK_GENERATORS.stream().
1126                 flatMap(fm -> DOUBLE_GENERATOR_PAIRS.stream().map(lfa -> {
1127                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1128                 })).
1129                 toArray(Object[][]::new);
1130     }
1131 
1132     @DataProvider
1133     public Object[][] doubleTernaryOpProvider() {
1134         return DOUBLE_GENERATOR_TRIPLES.stream().map(List::toArray).
1135                 toArray(Object[][]::new);
1136     }
1137 
1138     @DataProvider
1139     public Object[][] doubleTernaryOpMaskProvider() {
1140         return BOOLEAN_MASK_GENERATORS.stream().
1141                 flatMap(fm -> DOUBLE_GENERATOR_TRIPLES.stream().map(lfa -> {
1142                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1143                 })).
1144                 toArray(Object[][]::new);
1145     }
1146 
1147     @DataProvider
1148     public Object[][] doubleUnaryOpProvider() {
1149         return DOUBLE_GENERATORS.stream().
1150                 map(f -> new Object[]{f}).
1151                 toArray(Object[][]::new);
1152     }
1153 
1154     @DataProvider
1155     public Object[][] doubleUnaryOpMaskProvider() {
1156         return BOOLEAN_MASK_GENERATORS.stream().
1157                 flatMap(fm -> DOUBLE_GENERATORS.stream().map(fa -> {
1158                     return new Object[] {fa, fm};
1159                 })).
1160                 toArray(Object[][]::new);
1161     }
1162 
1163     @DataProvider
1164     public Object[][] doubletoIntUnaryOpProvider() {
1165         return INT_DOUBLE_GENERATORS.stream().
1166                 map(f -> new Object[]{f}).
1167                 toArray(Object[][]::new);
1168     }
1169 
1170     @DataProvider
1171     public Object[][] doubletoLongUnaryOpProvider() {
1172         return LONG_DOUBLE_GENERATORS.stream().
1173                 map(f -> new Object[]{f}).
1174                 toArray(Object[][]::new);
1175     }
1176 
1177     @DataProvider
1178     public Object[][] maskProvider() {
1179         return BOOLEAN_MASK_GENERATORS.stream().
1180                 map(f -> new Object[]{f}).
1181                 toArray(Object[][]::new);
1182     }
1183 
1184     @DataProvider
1185     public Object[][] maskCompareOpProvider() {
1186         return BOOLEAN_MASK_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
1187                 toArray(Object[][]::new);
1188     }
1189 
1190     @DataProvider
1191     public Object[][] shuffleProvider() {
1192         return INT_SHUFFLE_GENERATORS.stream().
1193                 map(f -> new Object[]{f}).
1194                 toArray(Object[][]::new);
1195     }
1196 
1197     @DataProvider
1198     public Object[][] shuffleCompareOpProvider() {
1199         return INT_SHUFFLE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
1200                 toArray(Object[][]::new);
1201     }
1202 
1203     @DataProvider
1204     public Object[][] doubleUnaryOpShuffleProvider() {
1205         return INT_SHUFFLE_GENERATORS.stream().
1206                 flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> {
1207                     return new Object[] {fa, fs};
1208                 })).
1209                 toArray(Object[][]::new);
1210     }
1211 
1212     @DataProvider
1213     public Object[][] doubleUnaryOpShuffleMaskProvider() {
1214         return BOOLEAN_MASK_GENERATORS.stream().
1215                 flatMap(fm -> INT_SHUFFLE_GENERATORS.stream().
1216                     flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> {
1217                         return new Object[] {fa, fs, fm};
1218                 }))).
1219                 toArray(Object[][]::new);
1220     }
1221 
1222     static final List<BiFunction<Integer,Integer,double[]>> DOUBLE_SHUFFLE_GENERATORS = List.of(
1223             withToStringBi("shuffle[random]", (Integer l, Integer m) -> {
1224                 double[] a = new double[l];
1225                 int upper = m;
1226                 for (int i = 0; i < 1; i++) {
1227                     a[i] = (double)RAND.nextInt(upper);
1228                 }
1229                 return a;
1230             })
1231     );
1232 
1233     @DataProvider
1234     public Object[][] doubleUnaryOpSelectFromProvider() {
1235         return DOUBLE_SHUFFLE_GENERATORS.stream().
1236                 flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> {
1237                     return new Object[] {fa, fs};
1238                 })).
1239                 toArray(Object[][]::new);
1240     }
1241 
1242     @DataProvider
1243     public Object[][] doubleUnaryOpSelectFromMaskProvider() {
1244         return BOOLEAN_MASK_GENERATORS.stream().
1245                 flatMap(fm -> DOUBLE_SHUFFLE_GENERATORS.stream().
1246                     flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> {
1247                         return new Object[] {fa, fs, fm};
1248                 }))).
1249                 toArray(Object[][]::new);
1250     }
1251 
1252     static final List<IntFunction<double[]>> DOUBLE_COMPARE_GENERATORS = List.of(
1253             withToString("double[i]", (int s) -> {
1254                 return fill(s * BUFFER_REPS,
1255                             i -> (double)i);
1256             }),
1257             withToString("double[i - length / 2]", (int s) -> {
1258                 return fill(s * BUFFER_REPS,
1259                             i -> (double)(i - (s * BUFFER_REPS / 2)));
1260             }),
1261             withToString("double[i + 1]", (int s) -> {
1262                 return fill(s * BUFFER_REPS,
1263                             i -> (double)(i + 1));
1264             }),
1265             withToString("double[i - 2]", (int s) -> {
1266                 return fill(s * BUFFER_REPS,
1267                             i -> (double)(i - 2));
1268             }),
1269             withToString("double[zigZag(i)]", (int s) -> {
1270                 return fill(s * BUFFER_REPS,
1271                             i -> i%3 == 0 ? (double)i : (i%3 == 1 ? (double)(i + 1) : (double)(i - 2)));
1272             }),
1273             withToString("double[cornerCaseValue(i)]", (int s) -> {
1274                 return fill(s * BUFFER_REPS,
1275                             i -> cornerCaseValue(i));
1276             })
1277     );
1278 
1279     static final List<List<IntFunction<double[]>>> DOUBLE_TEST_GENERATOR_ARGS =
1280         DOUBLE_COMPARE_GENERATORS.stream().
1281                 map(fa -> List.of(fa)).
1282                 collect(Collectors.toList());
1283 
1284     @DataProvider
1285     public Object[][] doubleTestOpProvider() {
1286         return DOUBLE_TEST_GENERATOR_ARGS.stream().map(List::toArray).
1287                 toArray(Object[][]::new);
1288     }
1289 
1290     @DataProvider
1291     public Object[][] doubleTestOpMaskProvider() {
1292         return BOOLEAN_MASK_GENERATORS.stream().
1293                 flatMap(fm -> DOUBLE_TEST_GENERATOR_ARGS.stream().map(lfa -> {
1294                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1295                 })).
1296                 toArray(Object[][]::new);
1297     }
1298 
1299     static final List<List<IntFunction<double[]>>> DOUBLE_COMPARE_GENERATOR_PAIRS =
1300         DOUBLE_COMPARE_GENERATORS.stream().
1301                 flatMap(fa -> DOUBLE_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))).
1302                 collect(Collectors.toList());
1303 
1304     @DataProvider
1305     public Object[][] doubleCompareOpProvider() {
1306         return DOUBLE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
1307                 toArray(Object[][]::new);
1308     }
1309 
1310     @DataProvider
1311     public Object[][] doubleCompareOpMaskProvider() {
1312         return BOOLEAN_MASK_GENERATORS.stream().
1313                 flatMap(fm -> DOUBLE_COMPARE_GENERATOR_PAIRS.stream().map(lfa -> {
1314                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1315                 })).
1316                 toArray(Object[][]::new);
1317     }
1318 
1319     interface ToDoubleF {
1320         double apply(int i);
1321     }
1322 
1323     static double[] fill(int s , ToDoubleF f) {
1324         return fill(new double[s], f);
1325     }
1326 
1327     static double[] fill(double[] a, ToDoubleF f) {
1328         for (int i = 0; i < a.length; i++) {
1329             a[i] = f.apply(i);
1330         }
1331         return a;
1332     }
1333 
1334     static double cornerCaseValue(int i) {
1335         switch(i % 7) {
1336             case 0:
1337                 return Double.MAX_VALUE;
1338             case 1:
1339                 return Double.MIN_VALUE;
1340             case 2:
1341                 return Double.NEGATIVE_INFINITY;
1342             case 3:
1343                 return Double.POSITIVE_INFINITY;
1344             case 4:
1345                 return Double.NaN;
1346             case 5:
1347                 return (double)0.0;
1348             default:
1349                 return (double)-0.0;
1350         }
1351     }
1352 
1353     static double get(double[] a, int i) {
1354         return (double) a[i];
1355     }
1356 
1357     static final IntFunction<double[]> fr = (vl) -> {
1358         int length = BUFFER_REPS * vl;
1359         return new double[length];
1360     };
1361 
1362     static final IntFunction<boolean[]> fmr = (vl) -> {
1363         int length = BUFFER_REPS * vl;
1364         return new boolean[length];
1365     };
1366 
1367     static final IntFunction<long[]> lfr = (vl) -> {
1368         int length = BUFFER_REPS * vl;
1369         return new long[length];
1370     };
1371 
1372     static boolean eq(double a, double b) {
1373         return a == b;
1374     }
1375 
1376     static boolean neq(double a, double b) {
1377         return a != b;
1378     }
1379 
1380     static boolean lt(double a, double b) {
1381         return a < b;
1382     }
1383 
1384     static boolean le(double a, double b) {
1385         return a <= b;
1386     }
1387 
1388     static boolean gt(double a, double b) {
1389         return a > b;
1390     }
1391 
1392     static boolean ge(double a, double b) {
1393         return a >= b;
1394     }
1395 
1396     static double firstNonZero(double a, double b) {
1397         return Double.compare(a, (double) 0) != 0 ? a : b;
1398     }
1399 
1400     @Test
1401     static void smokeTest1() {
1402         DoubleVector three = DoubleVector.broadcast(SPECIES, (byte)-3);
1403         DoubleVector three2 = (DoubleVector) SPECIES.broadcast(-3);
1404         assert(three.eq(three2).allTrue());
1405         DoubleVector three3 = three2.broadcast(1).broadcast(-3);
1406         assert(three.eq(three3).allTrue());
1407         int scale = 2;
1408         Class<?> ETYPE = double.class;
1409         if (ETYPE == double.class || ETYPE == long.class)
1410             scale = 1000000;
1411         else if (ETYPE == byte.class && SPECIES.length() >= 64)
1412             scale = 1;
1413         DoubleVector higher = three.addIndex(scale);
1414         VectorMask<Double> m = three.compare(VectorOperators.LE, higher);
1415         assert(m.allTrue());
1416         m = higher.min((double)-1).test(VectorOperators.IS_NEGATIVE);
1417         assert(m.allTrue());
1418         m = higher.test(VectorOperators.IS_FINITE);
1419         assert(m.allTrue());
1420         double max = higher.reduceLanes(VectorOperators.MAX);
1421         assert(max == -3 + scale * (SPECIES.length()-1));
1422     }
1423 
1424     private static double[]
1425     bothToArray(DoubleVector a, DoubleVector b) {
1426         double[] r = new double[a.length() + b.length()];
1427         a.intoArray(r, 0);
1428         b.intoArray(r, a.length());
1429         return r;
1430     }
1431 
1432     @Test
1433     static void smokeTest2() {
1434         // Do some zipping and shuffling.
1435         DoubleVector io = (DoubleVector) SPECIES.broadcast(0).addIndex(1);
1436         DoubleVector io2 = (DoubleVector) VectorShuffle.iota(SPECIES,0,1,false).toVector();
1437         Assert.assertEquals(io, io2);
1438         DoubleVector a = io.add((double)1); //[1,2]
1439         DoubleVector b = a.neg();  //[-1,-2]
1440         double[] abValues = bothToArray(a,b); //[1,2,-1,-2]
1441         VectorShuffle<Double> zip0 = VectorShuffle.makeZip(SPECIES, 0);
1442         VectorShuffle<Double> zip1 = VectorShuffle.makeZip(SPECIES, 1);
1443         DoubleVector zab0 = a.rearrange(zip0,b); //[1,-1]
1444         DoubleVector zab1 = a.rearrange(zip1,b); //[2,-2]
1445         double[] zabValues = bothToArray(zab0, zab1); //[1,-1,2,-2]
1446         // manually zip
1447         double[] manual = new double[zabValues.length];
1448         for (int i = 0; i < manual.length; i += 2) {
1449             manual[i+0] = abValues[i/2];
1450             manual[i+1] = abValues[a.length() + i/2];
1451         }
1452         Assert.assertEquals(Arrays.toString(zabValues), Arrays.toString(manual));
1453         VectorShuffle<Double> unz0 = VectorShuffle.makeUnzip(SPECIES, 0);
1454         VectorShuffle<Double> unz1 = VectorShuffle.makeUnzip(SPECIES, 1);
1455         DoubleVector uab0 = zab0.rearrange(unz0,zab1);
1456         DoubleVector uab1 = zab0.rearrange(unz1,zab1);
1457         double[] abValues1 = bothToArray(uab0, uab1);
1458         Assert.assertEquals(Arrays.toString(abValues), Arrays.toString(abValues1));
1459     }
1460 
1461     static void iotaShuffle() {
1462         DoubleVector io = (DoubleVector) SPECIES.broadcast(0).addIndex(1);
1463         DoubleVector io2 = (DoubleVector) VectorShuffle.iota(SPECIES, 0 , 1, false).toVector();
1464         Assert.assertEquals(io, io2);
1465     }
1466 
1467     @Test
1468     // Test all shuffle related operations.
1469     static void shuffleTest() {
1470         // To test backend instructions, make sure that C2 is used.
1471         for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) {
1472             iotaShuffle();
1473         }
1474     }
1475 
1476     @Test
1477     void viewAsIntegeralLanesTest() {
1478         Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes();
1479         VectorSpecies<?> asIntegralSpecies = asIntegral.species();
1480         Assert.assertNotEquals(asIntegralSpecies.elementType(), SPECIES.elementType());
1481         Assert.assertEquals(asIntegralSpecies.vectorShape(), SPECIES.vectorShape());
1482         Assert.assertEquals(asIntegralSpecies.length(), SPECIES.length());
1483         Assert.assertEquals(asIntegral.viewAsFloatingLanes().species(), SPECIES);
1484     }
1485 
1486     @Test
1487     void viewAsFloatingLanesTest() {
1488         Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes();
1489         Assert.assertEquals(asFloating.species(), SPECIES);
1490     }
1491 
1492     static double ADD(double a, double b) {
1493         return (double)(a + b);
1494     }
1495 
1496     @Test(dataProvider = "doubleBinaryOpProvider")
1497     static void ADDDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1498         double[] a = fa.apply(SPECIES.length());
1499         double[] b = fb.apply(SPECIES.length());
1500         double[] r = fr.apply(SPECIES.length());
1501 
1502         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1503             for (int i = 0; i < a.length; i += SPECIES.length()) {
1504                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1505                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1506                 av.lanewise(VectorOperators.ADD, bv).intoArray(r, i);
1507             }
1508         }
1509 
1510         assertArraysEquals(r, a, b, DoubleMaxVectorTests::ADD);
1511     }
1512 
1513     static double add(double a, double b) {
1514         return (double)(a + b);
1515     }
1516 
1517     @Test(dataProvider = "doubleBinaryOpProvider")
1518     static void addDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1519         double[] a = fa.apply(SPECIES.length());
1520         double[] b = fb.apply(SPECIES.length());
1521         double[] r = fr.apply(SPECIES.length());
1522 
1523         for (int i = 0; i < a.length; i += SPECIES.length()) {
1524             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1525             DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1526             av.add(bv).intoArray(r, i);
1527         }
1528 
1529         assertArraysEquals(r, a, b, DoubleMaxVectorTests::add);
1530     }
1531 
1532     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1533     static void ADDDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1534                                           IntFunction<boolean[]> fm) {
1535         double[] a = fa.apply(SPECIES.length());
1536         double[] b = fb.apply(SPECIES.length());
1537         double[] r = fr.apply(SPECIES.length());
1538         boolean[] mask = fm.apply(SPECIES.length());
1539         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1540 
1541         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1542             for (int i = 0; i < a.length; i += SPECIES.length()) {
1543                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1544                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1545                 av.lanewise(VectorOperators.ADD, bv, vmask).intoArray(r, i);
1546             }
1547         }
1548 
1549         assertArraysEquals(r, a, b, mask, DoubleMaxVectorTests::ADD);
1550     }
1551 
1552     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1553     static void addDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1554                                           IntFunction<boolean[]> fm) {
1555         double[] a = fa.apply(SPECIES.length());
1556         double[] b = fb.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 
1561         for (int i = 0; i < a.length; i += SPECIES.length()) {
1562             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1563             DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1564             av.add(bv, vmask).intoArray(r, i);
1565         }
1566 
1567         assertArraysEquals(r, a, b, mask, DoubleMaxVectorTests::add);
1568     }
1569 
1570     static double SUB(double a, double b) {
1571         return (double)(a - b);
1572     }
1573 
1574     @Test(dataProvider = "doubleBinaryOpProvider")
1575     static void SUBDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1576         double[] a = fa.apply(SPECIES.length());
1577         double[] b = fb.apply(SPECIES.length());
1578         double[] r = fr.apply(SPECIES.length());
1579 
1580         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1581             for (int i = 0; i < a.length; i += SPECIES.length()) {
1582                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1583                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1584                 av.lanewise(VectorOperators.SUB, bv).intoArray(r, i);
1585             }
1586         }
1587 
1588         assertArraysEquals(r, a, b, DoubleMaxVectorTests::SUB);
1589     }
1590 
1591     static double sub(double a, double b) {
1592         return (double)(a - b);
1593     }
1594 
1595     @Test(dataProvider = "doubleBinaryOpProvider")
1596     static void subDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1597         double[] a = fa.apply(SPECIES.length());
1598         double[] b = fb.apply(SPECIES.length());
1599         double[] r = fr.apply(SPECIES.length());
1600 
1601         for (int i = 0; i < a.length; i += SPECIES.length()) {
1602             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1603             DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1604             av.sub(bv).intoArray(r, i);
1605         }
1606 
1607         assertArraysEquals(r, a, b, DoubleMaxVectorTests::sub);
1608     }
1609 
1610     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1611     static void SUBDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1612                                           IntFunction<boolean[]> fm) {
1613         double[] a = fa.apply(SPECIES.length());
1614         double[] b = fb.apply(SPECIES.length());
1615         double[] r = fr.apply(SPECIES.length());
1616         boolean[] mask = fm.apply(SPECIES.length());
1617         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1618 
1619         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1620             for (int i = 0; i < a.length; i += SPECIES.length()) {
1621                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1622                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1623                 av.lanewise(VectorOperators.SUB, bv, vmask).intoArray(r, i);
1624             }
1625         }
1626 
1627         assertArraysEquals(r, a, b, mask, DoubleMaxVectorTests::SUB);
1628     }
1629 
1630     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1631     static void subDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1632                                           IntFunction<boolean[]> fm) {
1633         double[] a = fa.apply(SPECIES.length());
1634         double[] b = fb.apply(SPECIES.length());
1635         double[] r = fr.apply(SPECIES.length());
1636         boolean[] mask = fm.apply(SPECIES.length());
1637         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1638 
1639         for (int i = 0; i < a.length; i += SPECIES.length()) {
1640             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1641             DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1642             av.sub(bv, vmask).intoArray(r, i);
1643         }
1644 
1645         assertArraysEquals(r, a, b, mask, DoubleMaxVectorTests::sub);
1646     }
1647 
1648     static double MUL(double a, double b) {
1649         return (double)(a * b);
1650     }
1651 
1652     @Test(dataProvider = "doubleBinaryOpProvider")
1653     static void MULDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1654         double[] a = fa.apply(SPECIES.length());
1655         double[] b = fb.apply(SPECIES.length());
1656         double[] r = fr.apply(SPECIES.length());
1657 
1658         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1659             for (int i = 0; i < a.length; i += SPECIES.length()) {
1660                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1661                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1662                 av.lanewise(VectorOperators.MUL, bv).intoArray(r, i);
1663             }
1664         }
1665 
1666         assertArraysEquals(r, a, b, DoubleMaxVectorTests::MUL);
1667     }
1668 
1669     static double mul(double a, double b) {
1670         return (double)(a * b);
1671     }
1672 
1673     @Test(dataProvider = "doubleBinaryOpProvider")
1674     static void mulDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1675         double[] a = fa.apply(SPECIES.length());
1676         double[] b = fb.apply(SPECIES.length());
1677         double[] r = fr.apply(SPECIES.length());
1678 
1679         for (int i = 0; i < a.length; i += SPECIES.length()) {
1680             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1681             DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1682             av.mul(bv).intoArray(r, i);
1683         }
1684 
1685         assertArraysEquals(r, a, b, DoubleMaxVectorTests::mul);
1686     }
1687 
1688     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1689     static void MULDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1690                                           IntFunction<boolean[]> fm) {
1691         double[] a = fa.apply(SPECIES.length());
1692         double[] b = fb.apply(SPECIES.length());
1693         double[] r = fr.apply(SPECIES.length());
1694         boolean[] mask = fm.apply(SPECIES.length());
1695         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1696 
1697         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1698             for (int i = 0; i < a.length; i += SPECIES.length()) {
1699                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1700                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1701                 av.lanewise(VectorOperators.MUL, bv, vmask).intoArray(r, i);
1702             }
1703         }
1704 
1705         assertArraysEquals(r, a, b, mask, DoubleMaxVectorTests::MUL);
1706     }
1707 
1708     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1709     static void mulDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1710                                           IntFunction<boolean[]> fm) {
1711         double[] a = fa.apply(SPECIES.length());
1712         double[] b = fb.apply(SPECIES.length());
1713         double[] r = fr.apply(SPECIES.length());
1714         boolean[] mask = fm.apply(SPECIES.length());
1715         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1716 
1717         for (int i = 0; i < a.length; i += SPECIES.length()) {
1718             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1719             DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1720             av.mul(bv, vmask).intoArray(r, i);
1721         }
1722 
1723         assertArraysEquals(r, a, b, mask, DoubleMaxVectorTests::mul);
1724     }
1725 
1726     static double DIV(double a, double b) {
1727         return (double)(a / b);
1728     }
1729 
1730     @Test(dataProvider = "doubleBinaryOpProvider")
1731     static void DIVDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1732         double[] a = fa.apply(SPECIES.length());
1733         double[] b = fb.apply(SPECIES.length());
1734         double[] r = fr.apply(SPECIES.length());
1735 
1736         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1737             for (int i = 0; i < a.length; i += SPECIES.length()) {
1738                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1739                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1740                 av.lanewise(VectorOperators.DIV, bv).intoArray(r, i);
1741             }
1742         }
1743 
1744         assertArraysEquals(r, a, b, DoubleMaxVectorTests::DIV);
1745     }
1746 
1747     static double div(double a, double b) {
1748         return (double)(a / b);
1749     }
1750 
1751     @Test(dataProvider = "doubleBinaryOpProvider")
1752     static void divDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1753         double[] a = fa.apply(SPECIES.length());
1754         double[] b = fb.apply(SPECIES.length());
1755         double[] r = fr.apply(SPECIES.length());
1756 
1757         for (int i = 0; i < a.length; i += SPECIES.length()) {
1758             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1759             DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1760             av.div(bv).intoArray(r, i);
1761         }
1762 
1763         assertArraysEquals(r, a, b, DoubleMaxVectorTests::div);
1764     }
1765 
1766     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1767     static void DIVDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1768                                           IntFunction<boolean[]> fm) {
1769         double[] a = fa.apply(SPECIES.length());
1770         double[] b = fb.apply(SPECIES.length());
1771         double[] r = fr.apply(SPECIES.length());
1772         boolean[] mask = fm.apply(SPECIES.length());
1773         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1774 
1775         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1776             for (int i = 0; i < a.length; i += SPECIES.length()) {
1777                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1778                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1779                 av.lanewise(VectorOperators.DIV, bv, vmask).intoArray(r, i);
1780             }
1781         }
1782 
1783         assertArraysEquals(r, a, b, mask, DoubleMaxVectorTests::DIV);
1784     }
1785 
1786     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1787     static void divDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1788                                           IntFunction<boolean[]> fm) {
1789         double[] a = fa.apply(SPECIES.length());
1790         double[] b = fb.apply(SPECIES.length());
1791         double[] r = fr.apply(SPECIES.length());
1792         boolean[] mask = fm.apply(SPECIES.length());
1793         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1794 
1795         for (int i = 0; i < a.length; i += SPECIES.length()) {
1796             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1797             DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1798             av.div(bv, vmask).intoArray(r, i);
1799         }
1800 
1801         assertArraysEquals(r, a, b, mask, DoubleMaxVectorTests::div);
1802     }
1803 
1804     static double FIRST_NONZERO(double a, double b) {
1805         return (double)(Double.doubleToLongBits(a)!=0?a:b);
1806     }
1807 
1808     @Test(dataProvider = "doubleBinaryOpProvider")
1809     static void FIRST_NONZERODoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1810         double[] a = fa.apply(SPECIES.length());
1811         double[] b = fb.apply(SPECIES.length());
1812         double[] r = fr.apply(SPECIES.length());
1813 
1814         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1815             for (int i = 0; i < a.length; i += SPECIES.length()) {
1816                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1817                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1818                 av.lanewise(VectorOperators.FIRST_NONZERO, bv).intoArray(r, i);
1819             }
1820         }
1821 
1822         assertArraysEquals(r, a, b, DoubleMaxVectorTests::FIRST_NONZERO);
1823     }
1824 
1825     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1826     static void FIRST_NONZERODoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
1827                                           IntFunction<boolean[]> fm) {
1828         double[] a = fa.apply(SPECIES.length());
1829         double[] b = fb.apply(SPECIES.length());
1830         double[] r = fr.apply(SPECIES.length());
1831         boolean[] mask = fm.apply(SPECIES.length());
1832         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1833 
1834         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1835             for (int i = 0; i < a.length; i += SPECIES.length()) {
1836                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1837                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
1838                 av.lanewise(VectorOperators.FIRST_NONZERO, bv, vmask).intoArray(r, i);
1839             }
1840         }
1841 
1842         assertArraysEquals(r, a, b, mask, DoubleMaxVectorTests::FIRST_NONZERO);
1843     }
1844 
1845     @Test(dataProvider = "doubleBinaryOpProvider")
1846     static void addDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1847         double[] a = fa.apply(SPECIES.length());
1848         double[] b = fb.apply(SPECIES.length());
1849         double[] r = fr.apply(SPECIES.length());
1850 
1851         for (int i = 0; i < a.length; i += SPECIES.length()) {
1852             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1853             av.add(b[i]).intoArray(r, i);
1854         }
1855 
1856         assertBroadcastArraysEquals(r, a, b, DoubleMaxVectorTests::add);
1857     }
1858 
1859     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1860     static void addDoubleMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb,
1861                                           IntFunction<boolean[]> fm) {
1862         double[] a = fa.apply(SPECIES.length());
1863         double[] b = fb.apply(SPECIES.length());
1864         double[] r = fr.apply(SPECIES.length());
1865         boolean[] mask = fm.apply(SPECIES.length());
1866         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1867 
1868         for (int i = 0; i < a.length; i += SPECIES.length()) {
1869             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1870             av.add(b[i], vmask).intoArray(r, i);
1871         }
1872 
1873         assertBroadcastArraysEquals(r, a, b, mask, DoubleMaxVectorTests::add);
1874     }
1875 
1876     @Test(dataProvider = "doubleBinaryOpProvider")
1877     static void subDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1878         double[] a = fa.apply(SPECIES.length());
1879         double[] b = fb.apply(SPECIES.length());
1880         double[] r = fr.apply(SPECIES.length());
1881 
1882         for (int i = 0; i < a.length; i += SPECIES.length()) {
1883             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1884             av.sub(b[i]).intoArray(r, i);
1885         }
1886 
1887         assertBroadcastArraysEquals(r, a, b, DoubleMaxVectorTests::sub);
1888     }
1889 
1890     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1891     static void subDoubleMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb,
1892                                           IntFunction<boolean[]> fm) {
1893         double[] a = fa.apply(SPECIES.length());
1894         double[] b = fb.apply(SPECIES.length());
1895         double[] r = fr.apply(SPECIES.length());
1896         boolean[] mask = fm.apply(SPECIES.length());
1897         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1898 
1899         for (int i = 0; i < a.length; i += SPECIES.length()) {
1900             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1901             av.sub(b[i], vmask).intoArray(r, i);
1902         }
1903 
1904         assertBroadcastArraysEquals(r, a, b, mask, DoubleMaxVectorTests::sub);
1905     }
1906 
1907     @Test(dataProvider = "doubleBinaryOpProvider")
1908     static void mulDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1909         double[] a = fa.apply(SPECIES.length());
1910         double[] b = fb.apply(SPECIES.length());
1911         double[] r = fr.apply(SPECIES.length());
1912 
1913         for (int i = 0; i < a.length; i += SPECIES.length()) {
1914             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1915             av.mul(b[i]).intoArray(r, i);
1916         }
1917 
1918         assertBroadcastArraysEquals(r, a, b, DoubleMaxVectorTests::mul);
1919     }
1920 
1921     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1922     static void mulDoubleMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb,
1923                                           IntFunction<boolean[]> fm) {
1924         double[] a = fa.apply(SPECIES.length());
1925         double[] b = fb.apply(SPECIES.length());
1926         double[] r = fr.apply(SPECIES.length());
1927         boolean[] mask = fm.apply(SPECIES.length());
1928         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1929 
1930         for (int i = 0; i < a.length; i += SPECIES.length()) {
1931             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1932             av.mul(b[i], vmask).intoArray(r, i);
1933         }
1934 
1935         assertBroadcastArraysEquals(r, a, b, mask, DoubleMaxVectorTests::mul);
1936     }
1937 
1938     @Test(dataProvider = "doubleBinaryOpProvider")
1939     static void divDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1940         double[] a = fa.apply(SPECIES.length());
1941         double[] b = fb.apply(SPECIES.length());
1942         double[] r = fr.apply(SPECIES.length());
1943 
1944         for (int i = 0; i < a.length; i += SPECIES.length()) {
1945             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1946             av.div(b[i]).intoArray(r, i);
1947         }
1948 
1949         assertBroadcastArraysEquals(r, a, b, DoubleMaxVectorTests::div);
1950     }
1951 
1952     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1953     static void divDoubleMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb,
1954                                           IntFunction<boolean[]> fm) {
1955         double[] a = fa.apply(SPECIES.length());
1956         double[] b = fb.apply(SPECIES.length());
1957         double[] r = fr.apply(SPECIES.length());
1958         boolean[] mask = fm.apply(SPECIES.length());
1959         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1960 
1961         for (int i = 0; i < a.length; i += SPECIES.length()) {
1962             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1963             av.div(b[i], vmask).intoArray(r, i);
1964         }
1965 
1966         assertBroadcastArraysEquals(r, a, b, mask, DoubleMaxVectorTests::div);
1967     }
1968 
1969     @Test(dataProvider = "doubleBinaryOpProvider")
1970     static void ADDDoubleMaxVectorTestsBroadcastLongSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
1971         double[] a = fa.apply(SPECIES.length());
1972         double[] b = fb.apply(SPECIES.length());
1973         double[] r = fr.apply(SPECIES.length());
1974 
1975         for (int i = 0; i < a.length; i += SPECIES.length()) {
1976             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1977             av.lanewise(VectorOperators.ADD, (long)b[i]).intoArray(r, i);
1978         }
1979 
1980         assertBroadcastLongArraysEquals(r, a, b, DoubleMaxVectorTests::ADD);
1981     }
1982 
1983     @Test(dataProvider = "doubleBinaryOpMaskProvider")
1984     static void ADDDoubleMaxVectorTestsBroadcastMaskedLongSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb,
1985                                           IntFunction<boolean[]> fm) {
1986         double[] a = fa.apply(SPECIES.length());
1987         double[] b = fb.apply(SPECIES.length());
1988         double[] r = fr.apply(SPECIES.length());
1989         boolean[] mask = fm.apply(SPECIES.length());
1990         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1991 
1992         for (int i = 0; i < a.length; i += SPECIES.length()) {
1993             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
1994             av.lanewise(VectorOperators.ADD, (long)b[i], vmask).intoArray(r, i);
1995         }
1996 
1997         assertBroadcastLongArraysEquals(r, a, b, mask, DoubleMaxVectorTests::ADD);
1998     }
1999 
2000     static double MIN(double a, double b) {
2001         return (double)(Math.min(a, b));
2002     }
2003 
2004     @Test(dataProvider = "doubleBinaryOpProvider")
2005     static void MINDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2006         double[] a = fa.apply(SPECIES.length());
2007         double[] b = fb.apply(SPECIES.length());
2008         double[] r = fr.apply(SPECIES.length());
2009 
2010         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2011             for (int i = 0; i < a.length; i += SPECIES.length()) {
2012                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2013                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2014                 av.lanewise(VectorOperators.MIN, bv).intoArray(r, i);
2015             }
2016         }
2017 
2018         assertArraysEquals(r, a, b, DoubleMaxVectorTests::MIN);
2019     }
2020 
2021     static double min(double a, double b) {
2022         return (double)(Math.min(a, b));
2023     }
2024 
2025     @Test(dataProvider = "doubleBinaryOpProvider")
2026     static void minDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2027         double[] a = fa.apply(SPECIES.length());
2028         double[] b = fb.apply(SPECIES.length());
2029         double[] r = fr.apply(SPECIES.length());
2030 
2031         for (int i = 0; i < a.length; i += SPECIES.length()) {
2032             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2033             DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2034             av.min(bv).intoArray(r, i);
2035         }
2036 
2037         assertArraysEquals(r, a, b, DoubleMaxVectorTests::min);
2038     }
2039 
2040     static double MAX(double a, double b) {
2041         return (double)(Math.max(a, b));
2042     }
2043 
2044     @Test(dataProvider = "doubleBinaryOpProvider")
2045     static void MAXDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2046         double[] a = fa.apply(SPECIES.length());
2047         double[] b = fb.apply(SPECIES.length());
2048         double[] r = fr.apply(SPECIES.length());
2049 
2050         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2051             for (int i = 0; i < a.length; i += SPECIES.length()) {
2052                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2053                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2054                 av.lanewise(VectorOperators.MAX, bv).intoArray(r, i);
2055             }
2056         }
2057 
2058         assertArraysEquals(r, a, b, DoubleMaxVectorTests::MAX);
2059     }
2060 
2061     static double max(double a, double b) {
2062         return (double)(Math.max(a, b));
2063     }
2064 
2065     @Test(dataProvider = "doubleBinaryOpProvider")
2066     static void maxDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2067         double[] a = fa.apply(SPECIES.length());
2068         double[] b = fb.apply(SPECIES.length());
2069         double[] r = fr.apply(SPECIES.length());
2070 
2071         for (int i = 0; i < a.length; i += SPECIES.length()) {
2072             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2073             DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2074             av.max(bv).intoArray(r, i);
2075         }
2076 
2077         assertArraysEquals(r, a, b, DoubleMaxVectorTests::max);
2078     }
2079 
2080     @Test(dataProvider = "doubleBinaryOpProvider")
2081     static void MINDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2082         double[] a = fa.apply(SPECIES.length());
2083         double[] b = fb.apply(SPECIES.length());
2084         double[] r = fr.apply(SPECIES.length());
2085 
2086         for (int i = 0; i < a.length; i += SPECIES.length()) {
2087             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2088             av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i);
2089         }
2090 
2091         assertBroadcastArraysEquals(r, a, b, DoubleMaxVectorTests::MIN);
2092     }
2093 
2094     @Test(dataProvider = "doubleBinaryOpProvider")
2095     static void minDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2096         double[] a = fa.apply(SPECIES.length());
2097         double[] b = fb.apply(SPECIES.length());
2098         double[] r = fr.apply(SPECIES.length());
2099 
2100         for (int i = 0; i < a.length; i += SPECIES.length()) {
2101             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2102             av.min(b[i]).intoArray(r, i);
2103         }
2104 
2105         assertBroadcastArraysEquals(r, a, b, DoubleMaxVectorTests::min);
2106     }
2107 
2108     @Test(dataProvider = "doubleBinaryOpProvider")
2109     static void MAXDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2110         double[] a = fa.apply(SPECIES.length());
2111         double[] b = fb.apply(SPECIES.length());
2112         double[] r = fr.apply(SPECIES.length());
2113 
2114         for (int i = 0; i < a.length; i += SPECIES.length()) {
2115             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2116             av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i);
2117         }
2118 
2119         assertBroadcastArraysEquals(r, a, b, DoubleMaxVectorTests::MAX);
2120     }
2121 
2122     @Test(dataProvider = "doubleBinaryOpProvider")
2123     static void maxDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2124         double[] a = fa.apply(SPECIES.length());
2125         double[] b = fb.apply(SPECIES.length());
2126         double[] r = fr.apply(SPECIES.length());
2127 
2128         for (int i = 0; i < a.length; i += SPECIES.length()) {
2129             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2130             av.max(b[i]).intoArray(r, i);
2131         }
2132 
2133         assertBroadcastArraysEquals(r, a, b, DoubleMaxVectorTests::max);
2134     }
2135 
2136     static double ADDReduce(double[] a, int idx) {
2137         double res = 0;
2138         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2139             res += a[i];
2140         }
2141 
2142         return res;
2143     }
2144 
2145     static double ADDReduceAll(double[] a) {
2146         double res = 0;
2147         for (int i = 0; i < a.length; i += SPECIES.length()) {
2148             res += ADDReduce(a, i);
2149         }
2150 
2151         return res;
2152     }
2153 
2154     @Test(dataProvider = "doubleUnaryOpProvider")
2155     static void ADDReduceDoubleMaxVectorTests(IntFunction<double[]> fa) {
2156         double[] a = fa.apply(SPECIES.length());
2157         double[] r = fr.apply(SPECIES.length());
2158         double ra = 0;
2159 
2160         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2161             for (int i = 0; i < a.length; i += SPECIES.length()) {
2162                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2163                 r[i] = av.reduceLanes(VectorOperators.ADD);
2164             }
2165         }
2166 
2167         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2168             ra = 0;
2169             for (int i = 0; i < a.length; i += SPECIES.length()) {
2170                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2171                 ra += av.reduceLanes(VectorOperators.ADD);
2172             }
2173         }
2174 
2175         assertReductionArraysEquals(r, ra, a,
2176                 DoubleMaxVectorTests::ADDReduce, DoubleMaxVectorTests::ADDReduceAll);
2177     }
2178 
2179     static double ADDReduceMasked(double[] a, int idx, boolean[] mask) {
2180         double res = 0;
2181         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2182             if (mask[i % SPECIES.length()])
2183                 res += a[i];
2184         }
2185 
2186         return res;
2187     }
2188 
2189     static double ADDReduceAllMasked(double[] a, boolean[] mask) {
2190         double res = 0;
2191         for (int i = 0; i < a.length; i += SPECIES.length()) {
2192             res += ADDReduceMasked(a, i, mask);
2193         }
2194 
2195         return res;
2196     }
2197 
2198     @Test(dataProvider = "doubleUnaryOpMaskProvider")
2199     static void ADDReduceDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) {
2200         double[] a = fa.apply(SPECIES.length());
2201         double[] r = fr.apply(SPECIES.length());
2202         boolean[] mask = fm.apply(SPECIES.length());
2203         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2204         double ra = 0;
2205 
2206         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2207             for (int i = 0; i < a.length; i += SPECIES.length()) {
2208                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2209                 r[i] = av.reduceLanes(VectorOperators.ADD, vmask);
2210             }
2211         }
2212 
2213         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2214             ra = 0;
2215             for (int i = 0; i < a.length; i += SPECIES.length()) {
2216                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2217                 ra += av.reduceLanes(VectorOperators.ADD, vmask);
2218             }
2219         }
2220 
2221         assertReductionArraysEqualsMasked(r, ra, a, mask,
2222                 DoubleMaxVectorTests::ADDReduceMasked, DoubleMaxVectorTests::ADDReduceAllMasked);
2223     }
2224 
2225     static double MULReduce(double[] a, int idx) {
2226         double res = 1;
2227         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2228             res *= a[i];
2229         }
2230 
2231         return res;
2232     }
2233 
2234     static double MULReduceAll(double[] a) {
2235         double res = 1;
2236         for (int i = 0; i < a.length; i += SPECIES.length()) {
2237             res *= MULReduce(a, i);
2238         }
2239 
2240         return res;
2241     }
2242 
2243     @Test(dataProvider = "doubleUnaryOpProvider")
2244     static void MULReduceDoubleMaxVectorTests(IntFunction<double[]> fa) {
2245         double[] a = fa.apply(SPECIES.length());
2246         double[] r = fr.apply(SPECIES.length());
2247         double ra = 1;
2248 
2249         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2250             for (int i = 0; i < a.length; i += SPECIES.length()) {
2251                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2252                 r[i] = av.reduceLanes(VectorOperators.MUL);
2253             }
2254         }
2255 
2256         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2257             ra = 1;
2258             for (int i = 0; i < a.length; i += SPECIES.length()) {
2259                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2260                 ra *= av.reduceLanes(VectorOperators.MUL);
2261             }
2262         }
2263 
2264         assertReductionArraysEquals(r, ra, a,
2265                 DoubleMaxVectorTests::MULReduce, DoubleMaxVectorTests::MULReduceAll);
2266     }
2267 
2268     static double MULReduceMasked(double[] a, int idx, boolean[] mask) {
2269         double res = 1;
2270         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2271             if (mask[i % SPECIES.length()])
2272                 res *= a[i];
2273         }
2274 
2275         return res;
2276     }
2277 
2278     static double MULReduceAllMasked(double[] a, boolean[] mask) {
2279         double res = 1;
2280         for (int i = 0; i < a.length; i += SPECIES.length()) {
2281             res *= MULReduceMasked(a, i, mask);
2282         }
2283 
2284         return res;
2285     }
2286 
2287     @Test(dataProvider = "doubleUnaryOpMaskProvider")
2288     static void MULReduceDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) {
2289         double[] a = fa.apply(SPECIES.length());
2290         double[] r = fr.apply(SPECIES.length());
2291         boolean[] mask = fm.apply(SPECIES.length());
2292         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2293         double ra = 1;
2294 
2295         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2296             for (int i = 0; i < a.length; i += SPECIES.length()) {
2297                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2298                 r[i] = av.reduceLanes(VectorOperators.MUL, vmask);
2299             }
2300         }
2301 
2302         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2303             ra = 1;
2304             for (int i = 0; i < a.length; i += SPECIES.length()) {
2305                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2306                 ra *= av.reduceLanes(VectorOperators.MUL, vmask);
2307             }
2308         }
2309 
2310         assertReductionArraysEqualsMasked(r, ra, a, mask,
2311                 DoubleMaxVectorTests::MULReduceMasked, DoubleMaxVectorTests::MULReduceAllMasked);
2312     }
2313 
2314     static double MINReduce(double[] a, int idx) {
2315         double res = Double.POSITIVE_INFINITY;
2316         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2317             res = (double) Math.min(res, a[i]);
2318         }
2319 
2320         return res;
2321     }
2322 
2323     static double MINReduceAll(double[] a) {
2324         double res = Double.POSITIVE_INFINITY;
2325         for (int i = 0; i < a.length; i += SPECIES.length()) {
2326             res = (double) Math.min(res, MINReduce(a, i));
2327         }
2328 
2329         return res;
2330     }
2331 
2332     @Test(dataProvider = "doubleUnaryOpProvider")
2333     static void MINReduceDoubleMaxVectorTests(IntFunction<double[]> fa) {
2334         double[] a = fa.apply(SPECIES.length());
2335         double[] r = fr.apply(SPECIES.length());
2336         double ra = Double.POSITIVE_INFINITY;
2337 
2338         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2339             for (int i = 0; i < a.length; i += SPECIES.length()) {
2340                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2341                 r[i] = av.reduceLanes(VectorOperators.MIN);
2342             }
2343         }
2344 
2345         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2346             ra = Double.POSITIVE_INFINITY;
2347             for (int i = 0; i < a.length; i += SPECIES.length()) {
2348                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2349                 ra = (double) Math.min(ra, av.reduceLanes(VectorOperators.MIN));
2350             }
2351         }
2352 
2353         assertReductionArraysEquals(r, ra, a,
2354                 DoubleMaxVectorTests::MINReduce, DoubleMaxVectorTests::MINReduceAll);
2355     }
2356 
2357     static double MINReduceMasked(double[] a, int idx, boolean[] mask) {
2358         double res = Double.POSITIVE_INFINITY;
2359         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2360             if (mask[i % SPECIES.length()])
2361                 res = (double) Math.min(res, a[i]);
2362         }
2363 
2364         return res;
2365     }
2366 
2367     static double MINReduceAllMasked(double[] a, boolean[] mask) {
2368         double res = Double.POSITIVE_INFINITY;
2369         for (int i = 0; i < a.length; i += SPECIES.length()) {
2370             res = (double) Math.min(res, MINReduceMasked(a, i, mask));
2371         }
2372 
2373         return res;
2374     }
2375 
2376     @Test(dataProvider = "doubleUnaryOpMaskProvider")
2377     static void MINReduceDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) {
2378         double[] a = fa.apply(SPECIES.length());
2379         double[] r = fr.apply(SPECIES.length());
2380         boolean[] mask = fm.apply(SPECIES.length());
2381         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2382         double ra = Double.POSITIVE_INFINITY;
2383 
2384         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2385             for (int i = 0; i < a.length; i += SPECIES.length()) {
2386                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2387                 r[i] = av.reduceLanes(VectorOperators.MIN, vmask);
2388             }
2389         }
2390 
2391         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2392             ra = Double.POSITIVE_INFINITY;
2393             for (int i = 0; i < a.length; i += SPECIES.length()) {
2394                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2395                 ra = (double) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask));
2396             }
2397         }
2398 
2399         assertReductionArraysEqualsMasked(r, ra, a, mask,
2400                 DoubleMaxVectorTests::MINReduceMasked, DoubleMaxVectorTests::MINReduceAllMasked);
2401     }
2402 
2403     static double MAXReduce(double[] a, int idx) {
2404         double res = Double.NEGATIVE_INFINITY;
2405         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2406             res = (double) Math.max(res, a[i]);
2407         }
2408 
2409         return res;
2410     }
2411 
2412     static double MAXReduceAll(double[] a) {
2413         double res = Double.NEGATIVE_INFINITY;
2414         for (int i = 0; i < a.length; i += SPECIES.length()) {
2415             res = (double) Math.max(res, MAXReduce(a, i));
2416         }
2417 
2418         return res;
2419     }
2420 
2421     @Test(dataProvider = "doubleUnaryOpProvider")
2422     static void MAXReduceDoubleMaxVectorTests(IntFunction<double[]> fa) {
2423         double[] a = fa.apply(SPECIES.length());
2424         double[] r = fr.apply(SPECIES.length());
2425         double ra = Double.NEGATIVE_INFINITY;
2426 
2427         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2428             for (int i = 0; i < a.length; i += SPECIES.length()) {
2429                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2430                 r[i] = av.reduceLanes(VectorOperators.MAX);
2431             }
2432         }
2433 
2434         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2435             ra = Double.NEGATIVE_INFINITY;
2436             for (int i = 0; i < a.length; i += SPECIES.length()) {
2437                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2438                 ra = (double) Math.max(ra, av.reduceLanes(VectorOperators.MAX));
2439             }
2440         }
2441 
2442         assertReductionArraysEquals(r, ra, a,
2443                 DoubleMaxVectorTests::MAXReduce, DoubleMaxVectorTests::MAXReduceAll);
2444     }
2445 
2446     static double MAXReduceMasked(double[] a, int idx, boolean[] mask) {
2447         double res = Double.NEGATIVE_INFINITY;
2448         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2449             if (mask[i % SPECIES.length()])
2450                 res = (double) Math.max(res, a[i]);
2451         }
2452 
2453         return res;
2454     }
2455 
2456     static double MAXReduceAllMasked(double[] a, boolean[] mask) {
2457         double res = Double.NEGATIVE_INFINITY;
2458         for (int i = 0; i < a.length; i += SPECIES.length()) {
2459             res = (double) Math.max(res, MAXReduceMasked(a, i, mask));
2460         }
2461 
2462         return res;
2463     }
2464 
2465     @Test(dataProvider = "doubleUnaryOpMaskProvider")
2466     static void MAXReduceDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) {
2467         double[] a = fa.apply(SPECIES.length());
2468         double[] r = fr.apply(SPECIES.length());
2469         boolean[] mask = fm.apply(SPECIES.length());
2470         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2471         double ra = Double.NEGATIVE_INFINITY;
2472 
2473         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2474             for (int i = 0; i < a.length; i += SPECIES.length()) {
2475                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2476                 r[i] = av.reduceLanes(VectorOperators.MAX, vmask);
2477             }
2478         }
2479 
2480         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2481             ra = Double.NEGATIVE_INFINITY;
2482             for (int i = 0; i < a.length; i += SPECIES.length()) {
2483                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2484                 ra = (double) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask));
2485             }
2486         }
2487 
2488         assertReductionArraysEqualsMasked(r, ra, a, mask,
2489                 DoubleMaxVectorTests::MAXReduceMasked, DoubleMaxVectorTests::MAXReduceAllMasked);
2490     }
2491 
2492     static double FIRST_NONZEROReduce(double[] a, int idx) {
2493         double res = (double) 0;
2494         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2495             res = firstNonZero(res, a[i]);
2496         }
2497 
2498         return res;
2499     }
2500 
2501     static double FIRST_NONZEROReduceAll(double[] a) {
2502         double res = (double) 0;
2503         for (int i = 0; i < a.length; i += SPECIES.length()) {
2504             res = firstNonZero(res, FIRST_NONZEROReduce(a, i));
2505         }
2506 
2507         return res;
2508     }
2509 
2510     @Test(dataProvider = "doubleUnaryOpProvider")
2511     static void FIRST_NONZEROReduceDoubleMaxVectorTests(IntFunction<double[]> fa) {
2512         double[] a = fa.apply(SPECIES.length());
2513         double[] r = fr.apply(SPECIES.length());
2514         double ra = (double) 0;
2515 
2516         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2517             for (int i = 0; i < a.length; i += SPECIES.length()) {
2518                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2519                 r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO);
2520             }
2521         }
2522 
2523         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2524             ra = (double) 0;
2525             for (int i = 0; i < a.length; i += SPECIES.length()) {
2526                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2527                 ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO));
2528             }
2529         }
2530 
2531         assertReductionArraysEquals(r, ra, a,
2532                 DoubleMaxVectorTests::FIRST_NONZEROReduce, DoubleMaxVectorTests::FIRST_NONZEROReduceAll);
2533     }
2534 
2535     static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) {
2536         double res = (double) 0;
2537         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2538             if (mask[i % SPECIES.length()])
2539                 res = firstNonZero(res, a[i]);
2540         }
2541 
2542         return res;
2543     }
2544 
2545     static double FIRST_NONZEROReduceAllMasked(double[] a, boolean[] mask) {
2546         double res = (double) 0;
2547         for (int i = 0; i < a.length; i += SPECIES.length()) {
2548             res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask));
2549         }
2550 
2551         return res;
2552     }
2553 
2554     @Test(dataProvider = "doubleUnaryOpMaskProvider")
2555     static void FIRST_NONZEROReduceDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) {
2556         double[] a = fa.apply(SPECIES.length());
2557         double[] r = fr.apply(SPECIES.length());
2558         boolean[] mask = fm.apply(SPECIES.length());
2559         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2560         double ra = (double) 0;
2561 
2562         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2563             for (int i = 0; i < a.length; i += SPECIES.length()) {
2564                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2565                 r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask);
2566             }
2567         }
2568 
2569         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2570             ra = (double) 0;
2571             for (int i = 0; i < a.length; i += SPECIES.length()) {
2572                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2573                 ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask));
2574             }
2575         }
2576 
2577         assertReductionArraysEqualsMasked(r, ra, a, mask,
2578                 DoubleMaxVectorTests::FIRST_NONZEROReduceMasked, DoubleMaxVectorTests::FIRST_NONZEROReduceAllMasked);
2579     }
2580 
2581     @Test(dataProvider = "doubleUnaryOpProvider")
2582     static void withDoubleMaxVectorTests(IntFunction<double []> fa) {
2583         double[] a = fa.apply(SPECIES.length());
2584         double[] r = fr.apply(SPECIES.length());
2585 
2586         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2587             for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
2588                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2589                 av.withLane((j++ & (SPECIES.length()-1)), (double)(65535+i)).intoArray(r, i);
2590             }
2591         }
2592 
2593 
2594         for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
2595             assertInsertArraysEquals(r, a, (double)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length());
2596         }
2597     }
2598 
2599     static boolean testIS_DEFAULT(double a) {
2600         return bits(a)==0;
2601     }
2602 
2603     @Test(dataProvider = "doubleTestOpProvider")
2604     static void IS_DEFAULTDoubleMaxVectorTests(IntFunction<double[]> fa) {
2605         double[] a = fa.apply(SPECIES.length());
2606 
2607         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2608             for (int i = 0; i < a.length; i += SPECIES.length()) {
2609                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2610                 VectorMask<Double> mv = av.test(VectorOperators.IS_DEFAULT);
2611 
2612                 // Check results as part of computation.
2613                 for (int j = 0; j < SPECIES.length(); j++) {
2614                     Assert.assertEquals(mv.laneIsSet(j), testIS_DEFAULT(a[i + j]));
2615                 }
2616             }
2617         }
2618     }
2619 
2620     @Test(dataProvider = "doubleTestOpMaskProvider")
2621     static void IS_DEFAULTMaskedDoubleMaxVectorTests(IntFunction<double[]> fa,
2622                                           IntFunction<boolean[]> fm) {
2623         double[] a = fa.apply(SPECIES.length());
2624         boolean[] mask = fm.apply(SPECIES.length());
2625         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2626 
2627         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2628             for (int i = 0; i < a.length; i += SPECIES.length()) {
2629                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2630                 VectorMask<Double> mv = av.test(VectorOperators.IS_DEFAULT, vmask);
2631 
2632                 // Check results as part of computation.
2633                 for (int j = 0; j < SPECIES.length(); j++) {
2634                     Assert.assertEquals(mv.laneIsSet(j),  vmask.laneIsSet(j) && testIS_DEFAULT(a[i + j]));
2635                 }
2636             }
2637         }
2638     }
2639 
2640     static boolean testIS_NEGATIVE(double a) {
2641         return bits(a)<0;
2642     }
2643 
2644     @Test(dataProvider = "doubleTestOpProvider")
2645     static void IS_NEGATIVEDoubleMaxVectorTests(IntFunction<double[]> fa) {
2646         double[] a = fa.apply(SPECIES.length());
2647 
2648         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2649             for (int i = 0; i < a.length; i += SPECIES.length()) {
2650                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2651                 VectorMask<Double> mv = av.test(VectorOperators.IS_NEGATIVE);
2652 
2653                 // Check results as part of computation.
2654                 for (int j = 0; j < SPECIES.length(); j++) {
2655                     Assert.assertEquals(mv.laneIsSet(j), testIS_NEGATIVE(a[i + j]));
2656                 }
2657             }
2658         }
2659     }
2660 
2661     @Test(dataProvider = "doubleTestOpMaskProvider")
2662     static void IS_NEGATIVEMaskedDoubleMaxVectorTests(IntFunction<double[]> fa,
2663                                           IntFunction<boolean[]> fm) {
2664         double[] a = fa.apply(SPECIES.length());
2665         boolean[] mask = fm.apply(SPECIES.length());
2666         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2667 
2668         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2669             for (int i = 0; i < a.length; i += SPECIES.length()) {
2670                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2671                 VectorMask<Double> mv = av.test(VectorOperators.IS_NEGATIVE, vmask);
2672 
2673                 // Check results as part of computation.
2674                 for (int j = 0; j < SPECIES.length(); j++) {
2675                     Assert.assertEquals(mv.laneIsSet(j),  vmask.laneIsSet(j) && testIS_NEGATIVE(a[i + j]));
2676                 }
2677             }
2678         }
2679     }
2680 
2681     static boolean testIS_FINITE(double a) {
2682         return Double.isFinite(a);
2683     }
2684 
2685     @Test(dataProvider = "doubleTestOpProvider")
2686     static void IS_FINITEDoubleMaxVectorTests(IntFunction<double[]> fa) {
2687         double[] a = fa.apply(SPECIES.length());
2688 
2689         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2690             for (int i = 0; i < a.length; i += SPECIES.length()) {
2691                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2692                 VectorMask<Double> mv = av.test(VectorOperators.IS_FINITE);
2693 
2694                 // Check results as part of computation.
2695                 for (int j = 0; j < SPECIES.length(); j++) {
2696                     Assert.assertEquals(mv.laneIsSet(j), testIS_FINITE(a[i + j]));
2697                 }
2698             }
2699         }
2700     }
2701 
2702     @Test(dataProvider = "doubleTestOpMaskProvider")
2703     static void IS_FINITEMaskedDoubleMaxVectorTests(IntFunction<double[]> fa,
2704                                           IntFunction<boolean[]> fm) {
2705         double[] a = fa.apply(SPECIES.length());
2706         boolean[] mask = fm.apply(SPECIES.length());
2707         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2708 
2709         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2710             for (int i = 0; i < a.length; i += SPECIES.length()) {
2711                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2712                 VectorMask<Double> mv = av.test(VectorOperators.IS_FINITE, vmask);
2713 
2714                 // Check results as part of computation.
2715                 for (int j = 0; j < SPECIES.length(); j++) {
2716                     Assert.assertEquals(mv.laneIsSet(j),  vmask.laneIsSet(j) && testIS_FINITE(a[i + j]));
2717                 }
2718             }
2719         }
2720     }
2721 
2722     static boolean testIS_NAN(double a) {
2723         return Double.isNaN(a);
2724     }
2725 
2726     @Test(dataProvider = "doubleTestOpProvider")
2727     static void IS_NANDoubleMaxVectorTests(IntFunction<double[]> fa) {
2728         double[] a = fa.apply(SPECIES.length());
2729 
2730         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2731             for (int i = 0; i < a.length; i += SPECIES.length()) {
2732                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2733                 VectorMask<Double> mv = av.test(VectorOperators.IS_NAN);
2734 
2735                 // Check results as part of computation.
2736                 for (int j = 0; j < SPECIES.length(); j++) {
2737                     Assert.assertEquals(mv.laneIsSet(j), testIS_NAN(a[i + j]));
2738                 }
2739             }
2740         }
2741     }
2742 
2743     @Test(dataProvider = "doubleTestOpMaskProvider")
2744     static void IS_NANMaskedDoubleMaxVectorTests(IntFunction<double[]> fa,
2745                                           IntFunction<boolean[]> fm) {
2746         double[] a = fa.apply(SPECIES.length());
2747         boolean[] mask = fm.apply(SPECIES.length());
2748         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2749 
2750         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2751             for (int i = 0; i < a.length; i += SPECIES.length()) {
2752                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2753                 VectorMask<Double> mv = av.test(VectorOperators.IS_NAN, vmask);
2754 
2755                 // Check results as part of computation.
2756                 for (int j = 0; j < SPECIES.length(); j++) {
2757                     Assert.assertEquals(mv.laneIsSet(j),  vmask.laneIsSet(j) && testIS_NAN(a[i + j]));
2758                 }
2759             }
2760         }
2761     }
2762 
2763     static boolean testIS_INFINITE(double a) {
2764         return Double.isInfinite(a);
2765     }
2766 
2767     @Test(dataProvider = "doubleTestOpProvider")
2768     static void IS_INFINITEDoubleMaxVectorTests(IntFunction<double[]> fa) {
2769         double[] a = fa.apply(SPECIES.length());
2770 
2771         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2772             for (int i = 0; i < a.length; i += SPECIES.length()) {
2773                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2774                 VectorMask<Double> mv = av.test(VectorOperators.IS_INFINITE);
2775 
2776                 // Check results as part of computation.
2777                 for (int j = 0; j < SPECIES.length(); j++) {
2778                     Assert.assertEquals(mv.laneIsSet(j), testIS_INFINITE(a[i + j]));
2779                 }
2780             }
2781         }
2782     }
2783 
2784     @Test(dataProvider = "doubleTestOpMaskProvider")
2785     static void IS_INFINITEMaskedDoubleMaxVectorTests(IntFunction<double[]> fa,
2786                                           IntFunction<boolean[]> fm) {
2787         double[] a = fa.apply(SPECIES.length());
2788         boolean[] mask = fm.apply(SPECIES.length());
2789         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2790 
2791         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2792             for (int i = 0; i < a.length; i += SPECIES.length()) {
2793                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2794                 VectorMask<Double> mv = av.test(VectorOperators.IS_INFINITE, vmask);
2795 
2796                 // Check results as part of computation.
2797                 for (int j = 0; j < SPECIES.length(); j++) {
2798                     Assert.assertEquals(mv.laneIsSet(j),  vmask.laneIsSet(j) && testIS_INFINITE(a[i + j]));
2799                 }
2800             }
2801         }
2802     }
2803 
2804     @Test(dataProvider = "doubleCompareOpProvider")
2805     static void LTDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2806         double[] a = fa.apply(SPECIES.length());
2807         double[] b = fb.apply(SPECIES.length());
2808 
2809         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2810             for (int i = 0; i < a.length; i += SPECIES.length()) {
2811                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2812                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2813                 VectorMask<Double> mv = av.compare(VectorOperators.LT, bv);
2814 
2815                 // Check results as part of computation.
2816                 for (int j = 0; j < SPECIES.length(); j++) {
2817                     Assert.assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i + j]));
2818                 }
2819             }
2820         }
2821     }
2822 
2823     @Test(dataProvider = "doubleCompareOpProvider")
2824     static void ltDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2825         double[] a = fa.apply(SPECIES.length());
2826         double[] b = fb.apply(SPECIES.length());
2827 
2828         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2829             for (int i = 0; i < a.length; i += SPECIES.length()) {
2830                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2831                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2832                 VectorMask<Double> mv = av.lt(bv);
2833 
2834                 // Check results as part of computation.
2835                 for (int j = 0; j < SPECIES.length(); j++) {
2836                     Assert.assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i + j]));
2837                 }
2838             }
2839         }
2840     }
2841 
2842     @Test(dataProvider = "doubleCompareOpMaskProvider")
2843     static void LTDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
2844                                                 IntFunction<boolean[]> fm) {
2845         double[] a = fa.apply(SPECIES.length());
2846         double[] b = fb.apply(SPECIES.length());
2847         boolean[] mask = fm.apply(SPECIES.length());
2848 
2849         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2850 
2851         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2852             for (int i = 0; i < a.length; i += SPECIES.length()) {
2853                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2854                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2855                 VectorMask<Double> mv = av.compare(VectorOperators.LT, bv, vmask);
2856 
2857                 // Check results as part of computation.
2858                 for (int j = 0; j < SPECIES.length(); j++) {
2859                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && lt(a[i + j], b[i + j]));
2860                 }
2861             }
2862         }
2863     }
2864 
2865     @Test(dataProvider = "doubleCompareOpProvider")
2866     static void GTDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2867         double[] a = fa.apply(SPECIES.length());
2868         double[] b = fb.apply(SPECIES.length());
2869 
2870         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2871             for (int i = 0; i < a.length; i += SPECIES.length()) {
2872                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2873                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2874                 VectorMask<Double> mv = av.compare(VectorOperators.GT, bv);
2875 
2876                 // Check results as part of computation.
2877                 for (int j = 0; j < SPECIES.length(); j++) {
2878                     Assert.assertEquals(mv.laneIsSet(j), gt(a[i + j], b[i + j]));
2879                 }
2880             }
2881         }
2882     }
2883 
2884     @Test(dataProvider = "doubleCompareOpMaskProvider")
2885     static void GTDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
2886                                                 IntFunction<boolean[]> fm) {
2887         double[] a = fa.apply(SPECIES.length());
2888         double[] b = fb.apply(SPECIES.length());
2889         boolean[] mask = fm.apply(SPECIES.length());
2890 
2891         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2892 
2893         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2894             for (int i = 0; i < a.length; i += SPECIES.length()) {
2895                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2896                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2897                 VectorMask<Double> mv = av.compare(VectorOperators.GT, bv, vmask);
2898 
2899                 // Check results as part of computation.
2900                 for (int j = 0; j < SPECIES.length(); j++) {
2901                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && gt(a[i + j], b[i + j]));
2902                 }
2903             }
2904         }
2905     }
2906 
2907     @Test(dataProvider = "doubleCompareOpProvider")
2908     static void EQDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2909         double[] a = fa.apply(SPECIES.length());
2910         double[] b = fb.apply(SPECIES.length());
2911 
2912         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2913             for (int i = 0; i < a.length; i += SPECIES.length()) {
2914                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2915                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2916                 VectorMask<Double> mv = av.compare(VectorOperators.EQ, bv);
2917 
2918                 // Check results as part of computation.
2919                 for (int j = 0; j < SPECIES.length(); j++) {
2920                     Assert.assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i + j]));
2921                 }
2922             }
2923         }
2924     }
2925 
2926     @Test(dataProvider = "doubleCompareOpProvider")
2927     static void eqDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2928         double[] a = fa.apply(SPECIES.length());
2929         double[] b = fb.apply(SPECIES.length());
2930 
2931         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2932             for (int i = 0; i < a.length; i += SPECIES.length()) {
2933                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2934                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2935                 VectorMask<Double> mv = av.eq(bv);
2936 
2937                 // Check results as part of computation.
2938                 for (int j = 0; j < SPECIES.length(); j++) {
2939                     Assert.assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i + j]));
2940                 }
2941             }
2942         }
2943     }
2944 
2945     @Test(dataProvider = "doubleCompareOpMaskProvider")
2946     static void EQDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
2947                                                 IntFunction<boolean[]> fm) {
2948         double[] a = fa.apply(SPECIES.length());
2949         double[] b = fb.apply(SPECIES.length());
2950         boolean[] mask = fm.apply(SPECIES.length());
2951 
2952         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2953 
2954         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2955             for (int i = 0; i < a.length; i += SPECIES.length()) {
2956                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2957                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2958                 VectorMask<Double> mv = av.compare(VectorOperators.EQ, bv, vmask);
2959 
2960                 // Check results as part of computation.
2961                 for (int j = 0; j < SPECIES.length(); j++) {
2962                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && eq(a[i + j], b[i + j]));
2963                 }
2964             }
2965         }
2966     }
2967 
2968     @Test(dataProvider = "doubleCompareOpProvider")
2969     static void NEDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
2970         double[] a = fa.apply(SPECIES.length());
2971         double[] b = fb.apply(SPECIES.length());
2972 
2973         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2974             for (int i = 0; i < a.length; i += SPECIES.length()) {
2975                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2976                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
2977                 VectorMask<Double> mv = av.compare(VectorOperators.NE, bv);
2978 
2979                 // Check results as part of computation.
2980                 for (int j = 0; j < SPECIES.length(); j++) {
2981                     Assert.assertEquals(mv.laneIsSet(j), neq(a[i + j], b[i + j]));
2982                 }
2983             }
2984         }
2985     }
2986 
2987     @Test(dataProvider = "doubleCompareOpMaskProvider")
2988     static void NEDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
2989                                                 IntFunction<boolean[]> fm) {
2990         double[] a = fa.apply(SPECIES.length());
2991         double[] b = fb.apply(SPECIES.length());
2992         boolean[] mask = fm.apply(SPECIES.length());
2993 
2994         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2995 
2996         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2997             for (int i = 0; i < a.length; i += SPECIES.length()) {
2998                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
2999                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
3000                 VectorMask<Double> mv = av.compare(VectorOperators.NE, bv, vmask);
3001 
3002                 // Check results as part of computation.
3003                 for (int j = 0; j < SPECIES.length(); j++) {
3004                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && neq(a[i + j], b[i + j]));
3005                 }
3006             }
3007         }
3008     }
3009 
3010     @Test(dataProvider = "doubleCompareOpProvider")
3011     static void LEDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
3012         double[] a = fa.apply(SPECIES.length());
3013         double[] b = fb.apply(SPECIES.length());
3014 
3015         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3016             for (int i = 0; i < a.length; i += SPECIES.length()) {
3017                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3018                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
3019                 VectorMask<Double> mv = av.compare(VectorOperators.LE, bv);
3020 
3021                 // Check results as part of computation.
3022                 for (int j = 0; j < SPECIES.length(); j++) {
3023                     Assert.assertEquals(mv.laneIsSet(j), le(a[i + j], b[i + j]));
3024                 }
3025             }
3026         }
3027     }
3028 
3029     @Test(dataProvider = "doubleCompareOpMaskProvider")
3030     static void LEDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
3031                                                 IntFunction<boolean[]> fm) {
3032         double[] a = fa.apply(SPECIES.length());
3033         double[] b = fb.apply(SPECIES.length());
3034         boolean[] mask = fm.apply(SPECIES.length());
3035 
3036         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3037 
3038         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3039             for (int i = 0; i < a.length; i += SPECIES.length()) {
3040                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3041                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
3042                 VectorMask<Double> mv = av.compare(VectorOperators.LE, bv, vmask);
3043 
3044                 // Check results as part of computation.
3045                 for (int j = 0; j < SPECIES.length(); j++) {
3046                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && le(a[i + j], b[i + j]));
3047                 }
3048             }
3049         }
3050     }
3051 
3052     @Test(dataProvider = "doubleCompareOpProvider")
3053     static void GEDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
3054         double[] a = fa.apply(SPECIES.length());
3055         double[] b = fb.apply(SPECIES.length());
3056 
3057         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3058             for (int i = 0; i < a.length; i += SPECIES.length()) {
3059                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3060                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
3061                 VectorMask<Double> mv = av.compare(VectorOperators.GE, bv);
3062 
3063                 // Check results as part of computation.
3064                 for (int j = 0; j < SPECIES.length(); j++) {
3065                     Assert.assertEquals(mv.laneIsSet(j), ge(a[i + j], b[i + j]));
3066                 }
3067             }
3068         }
3069     }
3070 
3071     @Test(dataProvider = "doubleCompareOpMaskProvider")
3072     static void GEDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
3073                                                 IntFunction<boolean[]> fm) {
3074         double[] a = fa.apply(SPECIES.length());
3075         double[] b = fb.apply(SPECIES.length());
3076         boolean[] mask = fm.apply(SPECIES.length());
3077 
3078         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3079 
3080         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3081             for (int i = 0; i < a.length; i += SPECIES.length()) {
3082                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3083                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
3084                 VectorMask<Double> mv = av.compare(VectorOperators.GE, bv, vmask);
3085 
3086                 // Check results as part of computation.
3087                 for (int j = 0; j < SPECIES.length(); j++) {
3088                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && ge(a[i + j], b[i + j]));
3089                 }
3090             }
3091         }
3092     }
3093 
3094     @Test(dataProvider = "doubleCompareOpProvider")
3095     static void LTDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
3096         double[] a = fa.apply(SPECIES.length());
3097         double[] b = fb.apply(SPECIES.length());
3098 
3099         for (int i = 0; i < a.length; i += SPECIES.length()) {
3100             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3101             VectorMask<Double> mv = av.compare(VectorOperators.LT, b[i]);
3102 
3103             // Check results as part of computation.
3104             for (int j = 0; j < SPECIES.length(); j++) {
3105                 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i]);
3106             }
3107         }
3108     }
3109 
3110     @Test(dataProvider = "doubleCompareOpMaskProvider")
3111     static void LTDoubleMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa,
3112                                 IntFunction<double[]> fb, IntFunction<boolean[]> fm) {
3113         double[] a = fa.apply(SPECIES.length());
3114         double[] b = fb.apply(SPECIES.length());
3115         boolean[] mask = fm.apply(SPECIES.length());
3116 
3117         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3118 
3119         for (int i = 0; i < a.length; i += SPECIES.length()) {
3120             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3121             VectorMask<Double> mv = av.compare(VectorOperators.LT, b[i], vmask);
3122 
3123             // Check results as part of computation.
3124             for (int j = 0; j < SPECIES.length(); j++) {
3125                 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i]));
3126             }
3127         }
3128     }
3129 
3130     @Test(dataProvider = "doubleCompareOpProvider")
3131     static void LTDoubleMaxVectorTestsBroadcastLongSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
3132         double[] a = fa.apply(SPECIES.length());
3133         double[] b = fb.apply(SPECIES.length());
3134 
3135         for (int i = 0; i < a.length; i += SPECIES.length()) {
3136             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3137             VectorMask<Double> mv = av.compare(VectorOperators.LT, (long)b[i]);
3138 
3139             // Check results as part of computation.
3140             for (int j = 0; j < SPECIES.length(); j++) {
3141                 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < (double)((long)b[i]));
3142             }
3143         }
3144     }
3145 
3146     @Test(dataProvider = "doubleCompareOpMaskProvider")
3147     static void LTDoubleMaxVectorTestsBroadcastLongMaskedSmokeTest(IntFunction<double[]> fa,
3148                                 IntFunction<double[]> fb, IntFunction<boolean[]> fm) {
3149         double[] a = fa.apply(SPECIES.length());
3150         double[] b = fb.apply(SPECIES.length());
3151         boolean[] mask = fm.apply(SPECIES.length());
3152 
3153         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3154 
3155         for (int i = 0; i < a.length; i += SPECIES.length()) {
3156             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3157             VectorMask<Double> mv = av.compare(VectorOperators.LT, (long)b[i], vmask);
3158 
3159             // Check results as part of computation.
3160             for (int j = 0; j < SPECIES.length(); j++) {
3161                 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (double)((long)b[i])));
3162             }
3163         }
3164     }
3165 
3166     @Test(dataProvider = "doubleCompareOpProvider")
3167     static void EQDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
3168         double[] a = fa.apply(SPECIES.length());
3169         double[] b = fb.apply(SPECIES.length());
3170 
3171         for (int i = 0; i < a.length; i += SPECIES.length()) {
3172             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3173             VectorMask<Double> mv = av.compare(VectorOperators.EQ, b[i]);
3174 
3175             // Check results as part of computation.
3176             for (int j = 0; j < SPECIES.length(); j++) {
3177                 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i]);
3178             }
3179         }
3180     }
3181 
3182     @Test(dataProvider = "doubleCompareOpMaskProvider")
3183     static void EQDoubleMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa,
3184                                 IntFunction<double[]> fb, IntFunction<boolean[]> fm) {
3185         double[] a = fa.apply(SPECIES.length());
3186         double[] b = fb.apply(SPECIES.length());
3187         boolean[] mask = fm.apply(SPECIES.length());
3188 
3189         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3190 
3191         for (int i = 0; i < a.length; i += SPECIES.length()) {
3192             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3193             VectorMask<Double> mv = av.compare(VectorOperators.EQ, b[i], vmask);
3194 
3195             // Check results as part of computation.
3196             for (int j = 0; j < SPECIES.length(); j++) {
3197                 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i]));
3198             }
3199         }
3200     }
3201 
3202     @Test(dataProvider = "doubleCompareOpProvider")
3203     static void EQDoubleMaxVectorTestsBroadcastLongSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
3204         double[] a = fa.apply(SPECIES.length());
3205         double[] b = fb.apply(SPECIES.length());
3206 
3207         for (int i = 0; i < a.length; i += SPECIES.length()) {
3208             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3209             VectorMask<Double> mv = av.compare(VectorOperators.EQ, (long)b[i]);
3210 
3211             // Check results as part of computation.
3212             for (int j = 0; j < SPECIES.length(); j++) {
3213                 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == (double)((long)b[i]));
3214             }
3215         }
3216     }
3217 
3218     @Test(dataProvider = "doubleCompareOpMaskProvider")
3219     static void EQDoubleMaxVectorTestsBroadcastLongMaskedSmokeTest(IntFunction<double[]> fa,
3220                                 IntFunction<double[]> fb, IntFunction<boolean[]> fm) {
3221         double[] a = fa.apply(SPECIES.length());
3222         double[] b = fb.apply(SPECIES.length());
3223         boolean[] mask = fm.apply(SPECIES.length());
3224 
3225         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3226 
3227         for (int i = 0; i < a.length; i += SPECIES.length()) {
3228             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3229             VectorMask<Double> mv = av.compare(VectorOperators.EQ, (long)b[i], vmask);
3230 
3231             // Check results as part of computation.
3232             for (int j = 0; j < SPECIES.length(); j++) {
3233                 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (double)((long)b[i])));
3234             }
3235         }
3236     }
3237 
3238     static double blend(double a, double b, boolean mask) {
3239         return mask ? b : a;
3240     }
3241 
3242     @Test(dataProvider = "doubleBinaryOpMaskProvider")
3243     static void blendDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb,
3244                                           IntFunction<boolean[]> fm) {
3245         double[] a = fa.apply(SPECIES.length());
3246         double[] b = fb.apply(SPECIES.length());
3247         double[] r = fr.apply(SPECIES.length());
3248         boolean[] mask = fm.apply(SPECIES.length());
3249         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3250 
3251         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3252             for (int i = 0; i < a.length; i += SPECIES.length()) {
3253                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3254                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
3255                 av.blend(bv, vmask).intoArray(r, i);
3256             }
3257         }
3258 
3259         assertArraysEquals(r, a, b, mask, DoubleMaxVectorTests::blend);
3260     }
3261 
3262     @Test(dataProvider = "doubleUnaryOpShuffleProvider")
3263     static void RearrangeDoubleMaxVectorTests(IntFunction<double[]> fa,
3264                                            BiFunction<Integer,Integer,int[]> fs) {
3265         double[] a = fa.apply(SPECIES.length());
3266         int[] order = fs.apply(a.length, SPECIES.length());
3267         double[] r = fr.apply(SPECIES.length());
3268 
3269         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3270             for (int i = 0; i < a.length; i += SPECIES.length()) {
3271                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3272                 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
3273             }
3274         }
3275 
3276         assertRearrangeArraysEquals(r, a, order, SPECIES.length());
3277     }
3278 
3279     @Test(dataProvider = "doubleUnaryOpShuffleMaskProvider")
3280     static void RearrangeDoubleMaxVectorTestsMaskedSmokeTest(IntFunction<double[]> fa,
3281                                                           BiFunction<Integer,Integer,int[]> fs,
3282                                                           IntFunction<boolean[]> fm) {
3283         double[] a = fa.apply(SPECIES.length());
3284         int[] order = fs.apply(a.length, SPECIES.length());
3285         double[] r = fr.apply(SPECIES.length());
3286         boolean[] mask = fm.apply(SPECIES.length());
3287         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3288 
3289         for (int i = 0; i < a.length; i += SPECIES.length()) {
3290             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3291             av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i);
3292         }
3293 
3294         assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length());
3295     }
3296 
3297     @Test(dataProvider = "doubleUnaryOpMaskProvider")
3298     static void compressDoubleMaxVectorTests(IntFunction<double[]> fa,
3299                                                 IntFunction<boolean[]> fm) {
3300         double[] a = fa.apply(SPECIES.length());
3301         double[] r = fr.apply(SPECIES.length());
3302         boolean[] mask = fm.apply(SPECIES.length());
3303         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3304 
3305         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3306             for (int i = 0; i < a.length; i += SPECIES.length()) {
3307                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3308                 av.compress(vmask).intoArray(r, i);
3309             }
3310         }
3311 
3312         assertcompressArraysEquals(r, a, mask, SPECIES.length());
3313     }
3314 
3315     @Test(dataProvider = "doubleUnaryOpMaskProvider")
3316     static void expandDoubleMaxVectorTests(IntFunction<double[]> fa,
3317                                                 IntFunction<boolean[]> fm) {
3318         double[] a = fa.apply(SPECIES.length());
3319         double[] r = fr.apply(SPECIES.length());
3320         boolean[] mask = fm.apply(SPECIES.length());
3321         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3322 
3323         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3324             for (int i = 0; i < a.length; i += SPECIES.length()) {
3325                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3326                 av.expand(vmask).intoArray(r, i);
3327             }
3328         }
3329 
3330         assertexpandArraysEquals(r, a, mask, SPECIES.length());
3331     }
3332 
3333     @Test(dataProvider = "doubleUnaryOpProvider")
3334     static void getDoubleMaxVectorTests(IntFunction<double[]> fa) {
3335         double[] a = fa.apply(SPECIES.length());
3336         double[] r = fr.apply(SPECIES.length());
3337 
3338         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3339             for (int i = 0; i < a.length; i += SPECIES.length()) {
3340                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3341                 int num_lanes = SPECIES.length();
3342                 // Manually unroll because full unroll happens after intrinsification.
3343                 // Unroll is needed because get intrinsic requires for index to be a known constant.
3344                 if (num_lanes == 1) {
3345                     r[i]=av.lane(0);
3346                 } else if (num_lanes == 2) {
3347                     r[i]=av.lane(0);
3348                     r[i+1]=av.lane(1);
3349                 } else if (num_lanes == 4) {
3350                     r[i]=av.lane(0);
3351                     r[i+1]=av.lane(1);
3352                     r[i+2]=av.lane(2);
3353                     r[i+3]=av.lane(3);
3354                 } else if (num_lanes == 8) {
3355                     r[i]=av.lane(0);
3356                     r[i+1]=av.lane(1);
3357                     r[i+2]=av.lane(2);
3358                     r[i+3]=av.lane(3);
3359                     r[i+4]=av.lane(4);
3360                     r[i+5]=av.lane(5);
3361                     r[i+6]=av.lane(6);
3362                     r[i+7]=av.lane(7);
3363                 } else if (num_lanes == 16) {
3364                     r[i]=av.lane(0);
3365                     r[i+1]=av.lane(1);
3366                     r[i+2]=av.lane(2);
3367                     r[i+3]=av.lane(3);
3368                     r[i+4]=av.lane(4);
3369                     r[i+5]=av.lane(5);
3370                     r[i+6]=av.lane(6);
3371                     r[i+7]=av.lane(7);
3372                     r[i+8]=av.lane(8);
3373                     r[i+9]=av.lane(9);
3374                     r[i+10]=av.lane(10);
3375                     r[i+11]=av.lane(11);
3376                     r[i+12]=av.lane(12);
3377                     r[i+13]=av.lane(13);
3378                     r[i+14]=av.lane(14);
3379                     r[i+15]=av.lane(15);
3380                 } else if (num_lanes == 32) {
3381                     r[i]=av.lane(0);
3382                     r[i+1]=av.lane(1);
3383                     r[i+2]=av.lane(2);
3384                     r[i+3]=av.lane(3);
3385                     r[i+4]=av.lane(4);
3386                     r[i+5]=av.lane(5);
3387                     r[i+6]=av.lane(6);
3388                     r[i+7]=av.lane(7);
3389                     r[i+8]=av.lane(8);
3390                     r[i+9]=av.lane(9);
3391                     r[i+10]=av.lane(10);
3392                     r[i+11]=av.lane(11);
3393                     r[i+12]=av.lane(12);
3394                     r[i+13]=av.lane(13);
3395                     r[i+14]=av.lane(14);
3396                     r[i+15]=av.lane(15);
3397                     r[i+16]=av.lane(16);
3398                     r[i+17]=av.lane(17);
3399                     r[i+18]=av.lane(18);
3400                     r[i+19]=av.lane(19);
3401                     r[i+20]=av.lane(20);
3402                     r[i+21]=av.lane(21);
3403                     r[i+22]=av.lane(22);
3404                     r[i+23]=av.lane(23);
3405                     r[i+24]=av.lane(24);
3406                     r[i+25]=av.lane(25);
3407                     r[i+26]=av.lane(26);
3408                     r[i+27]=av.lane(27);
3409                     r[i+28]=av.lane(28);
3410                     r[i+29]=av.lane(29);
3411                     r[i+30]=av.lane(30);
3412                     r[i+31]=av.lane(31);
3413                 } else if (num_lanes == 64) {
3414                     r[i]=av.lane(0);
3415                     r[i+1]=av.lane(1);
3416                     r[i+2]=av.lane(2);
3417                     r[i+3]=av.lane(3);
3418                     r[i+4]=av.lane(4);
3419                     r[i+5]=av.lane(5);
3420                     r[i+6]=av.lane(6);
3421                     r[i+7]=av.lane(7);
3422                     r[i+8]=av.lane(8);
3423                     r[i+9]=av.lane(9);
3424                     r[i+10]=av.lane(10);
3425                     r[i+11]=av.lane(11);
3426                     r[i+12]=av.lane(12);
3427                     r[i+13]=av.lane(13);
3428                     r[i+14]=av.lane(14);
3429                     r[i+15]=av.lane(15);
3430                     r[i+16]=av.lane(16);
3431                     r[i+17]=av.lane(17);
3432                     r[i+18]=av.lane(18);
3433                     r[i+19]=av.lane(19);
3434                     r[i+20]=av.lane(20);
3435                     r[i+21]=av.lane(21);
3436                     r[i+22]=av.lane(22);
3437                     r[i+23]=av.lane(23);
3438                     r[i+24]=av.lane(24);
3439                     r[i+25]=av.lane(25);
3440                     r[i+26]=av.lane(26);
3441                     r[i+27]=av.lane(27);
3442                     r[i+28]=av.lane(28);
3443                     r[i+29]=av.lane(29);
3444                     r[i+30]=av.lane(30);
3445                     r[i+31]=av.lane(31);
3446                     r[i+32]=av.lane(32);
3447                     r[i+33]=av.lane(33);
3448                     r[i+34]=av.lane(34);
3449                     r[i+35]=av.lane(35);
3450                     r[i+36]=av.lane(36);
3451                     r[i+37]=av.lane(37);
3452                     r[i+38]=av.lane(38);
3453                     r[i+39]=av.lane(39);
3454                     r[i+40]=av.lane(40);
3455                     r[i+41]=av.lane(41);
3456                     r[i+42]=av.lane(42);
3457                     r[i+43]=av.lane(43);
3458                     r[i+44]=av.lane(44);
3459                     r[i+45]=av.lane(45);
3460                     r[i+46]=av.lane(46);
3461                     r[i+47]=av.lane(47);
3462                     r[i+48]=av.lane(48);
3463                     r[i+49]=av.lane(49);
3464                     r[i+50]=av.lane(50);
3465                     r[i+51]=av.lane(51);
3466                     r[i+52]=av.lane(52);
3467                     r[i+53]=av.lane(53);
3468                     r[i+54]=av.lane(54);
3469                     r[i+55]=av.lane(55);
3470                     r[i+56]=av.lane(56);
3471                     r[i+57]=av.lane(57);
3472                     r[i+58]=av.lane(58);
3473                     r[i+59]=av.lane(59);
3474                     r[i+60]=av.lane(60);
3475                     r[i+61]=av.lane(61);
3476                     r[i+62]=av.lane(62);
3477                     r[i+63]=av.lane(63);
3478                 } else {
3479                     for (int j = 0; j < SPECIES.length(); j++) {
3480                         r[i+j]=av.lane(j);
3481                     }
3482                 }
3483             }
3484         }
3485 
3486         assertArraysEquals(r, a, DoubleMaxVectorTests::get);
3487     }
3488 
3489     @Test(dataProvider = "doubleUnaryOpProvider")
3490     static void BroadcastDoubleMaxVectorTests(IntFunction<double[]> fa) {
3491         double[] a = fa.apply(SPECIES.length());
3492         double[] r = new double[a.length];
3493 
3494         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3495             for (int i = 0; i < a.length; i += SPECIES.length()) {
3496                 DoubleVector.broadcast(SPECIES, a[i]).intoArray(r, i);
3497             }
3498         }
3499 
3500         assertBroadcastArraysEquals(r, a);
3501     }
3502 
3503     @Test(dataProvider = "doubleUnaryOpProvider")
3504     static void ZeroDoubleMaxVectorTests(IntFunction<double[]> fa) {
3505         double[] a = fa.apply(SPECIES.length());
3506         double[] r = new double[a.length];
3507 
3508         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3509             for (int i = 0; i < a.length; i += SPECIES.length()) {
3510                 DoubleVector.zero(SPECIES).intoArray(a, i);
3511             }
3512         }
3513 
3514         Assert.assertEquals(a, r);
3515     }
3516 
3517     static double[] sliceUnary(double[] a, int origin, int idx) {
3518         double[] res = new double[SPECIES.length()];
3519         for (int i = 0; i < SPECIES.length(); i++){
3520             if(i+origin < SPECIES.length())
3521                 res[i] = a[idx+i+origin];
3522             else
3523                 res[i] = (double)0;
3524         }
3525         return res;
3526     }
3527 
3528     @Test(dataProvider = "doubleUnaryOpProvider")
3529     static void sliceUnaryDoubleMaxVectorTests(IntFunction<double[]> fa) {
3530         double[] a = fa.apply(SPECIES.length());
3531         double[] r = new double[a.length];
3532         int origin = (new java.util.Random()).nextInt(SPECIES.length());
3533         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3534             for (int i = 0; i < a.length; i += SPECIES.length()) {
3535                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3536                 av.slice(origin).intoArray(r, i);
3537             }
3538         }
3539 
3540         assertArraysEquals(r, a, origin, DoubleMaxVectorTests::sliceUnary);
3541     }
3542 
3543     static double[] sliceBinary(double[] a, double[] b, int origin, int idx) {
3544         double[] res = new double[SPECIES.length()];
3545         for (int i = 0, j = 0; i < SPECIES.length(); i++){
3546             if(i+origin < SPECIES.length())
3547                 res[i] = a[idx+i+origin];
3548             else {
3549                 res[i] = b[idx+j];
3550                 j++;
3551             }
3552         }
3553         return res;
3554     }
3555 
3556     @Test(dataProvider = "doubleBinaryOpProvider")
3557     static void sliceBinaryDoubleMaxVectorTestsBinary(IntFunction<double[]> fa, IntFunction<double[]> fb) {
3558         double[] a = fa.apply(SPECIES.length());
3559         double[] b = fb.apply(SPECIES.length());
3560         double[] r = new double[a.length];
3561         int origin = (new java.util.Random()).nextInt(SPECIES.length());
3562         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3563             for (int i = 0; i < a.length; i += SPECIES.length()) {
3564                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3565                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
3566                 av.slice(origin, bv).intoArray(r, i);
3567             }
3568         }
3569 
3570         assertArraysEquals(r, a, b, origin, DoubleMaxVectorTests::sliceBinary);
3571     }
3572 
3573     static double[] slice(double[] a, double[] b, int origin, boolean[] mask, int idx) {
3574         double[] res = new double[SPECIES.length()];
3575         for (int i = 0, j = 0; i < SPECIES.length(); i++){
3576             if(i+origin < SPECIES.length())
3577                 res[i] = mask[i] ? a[idx+i+origin] : (double)0;
3578             else {
3579                 res[i] = mask[i] ? b[idx+j] : (double)0;
3580                 j++;
3581             }
3582         }
3583         return res;
3584     }
3585 
3586     @Test(dataProvider = "doubleBinaryOpMaskProvider")
3587     static void sliceDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
3588     IntFunction<boolean[]> fm) {
3589         double[] a = fa.apply(SPECIES.length());
3590         double[] b = fb.apply(SPECIES.length());
3591         boolean[] mask = fm.apply(SPECIES.length());
3592         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3593 
3594         double[] r = new double[a.length];
3595         int origin = (new java.util.Random()).nextInt(SPECIES.length());
3596         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3597             for (int i = 0; i < a.length; i += SPECIES.length()) {
3598                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3599                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
3600                 av.slice(origin, bv, vmask).intoArray(r, i);
3601             }
3602         }
3603 
3604         assertArraysEquals(r, a, b, origin, mask, DoubleMaxVectorTests::slice);
3605     }
3606 
3607     static double[] unsliceUnary(double[] a, int origin, int idx) {
3608         double[] res = new double[SPECIES.length()];
3609         for (int i = 0, j = 0; i < SPECIES.length(); i++){
3610             if(i < origin)
3611                 res[i] = (double)0;
3612             else {
3613                 res[i] = a[idx+j];
3614                 j++;
3615             }
3616         }
3617         return res;
3618     }
3619 
3620     @Test(dataProvider = "doubleUnaryOpProvider")
3621     static void unsliceUnaryDoubleMaxVectorTests(IntFunction<double[]> fa) {
3622         double[] a = fa.apply(SPECIES.length());
3623         double[] r = new double[a.length];
3624         int origin = (new java.util.Random()).nextInt(SPECIES.length());
3625         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3626             for (int i = 0; i < a.length; i += SPECIES.length()) {
3627                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3628                 av.unslice(origin).intoArray(r, i);
3629             }
3630         }
3631 
3632         assertArraysEquals(r, a, origin, DoubleMaxVectorTests::unsliceUnary);
3633     }
3634 
3635     static double[] unsliceBinary(double[] a, double[] b, int origin, int part, int idx) {
3636         double[] res = new double[SPECIES.length()];
3637         for (int i = 0, j = 0; i < SPECIES.length(); i++){
3638             if (part == 0) {
3639                 if (i < origin)
3640                     res[i] = b[idx+i];
3641                 else {
3642                     res[i] = a[idx+j];
3643                     j++;
3644                 }
3645             } else if (part == 1) {
3646                 if (i < origin)
3647                     res[i] = a[idx+SPECIES.length()-origin+i];
3648                 else {
3649                     res[i] = b[idx+origin+j];
3650                     j++;
3651                 }
3652             }
3653         }
3654         return res;
3655     }
3656 
3657     @Test(dataProvider = "doubleBinaryOpProvider")
3658     static void unsliceBinaryDoubleMaxVectorTestsBinary(IntFunction<double[]> fa, IntFunction<double[]> fb) {
3659         double[] a = fa.apply(SPECIES.length());
3660         double[] b = fb.apply(SPECIES.length());
3661         double[] r = new double[a.length];
3662         int origin = (new java.util.Random()).nextInt(SPECIES.length());
3663         int part = (new java.util.Random()).nextInt(2);
3664         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3665             for (int i = 0; i < a.length; i += SPECIES.length()) {
3666                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3667                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
3668                 av.unslice(origin, bv, part).intoArray(r, i);
3669             }
3670         }
3671 
3672         assertArraysEquals(r, a, b, origin, part, DoubleMaxVectorTests::unsliceBinary);
3673     }
3674 
3675     static double[] unslice(double[] a, double[] b, int origin, int part, boolean[] mask, int idx) {
3676         double[] res = new double[SPECIES.length()];
3677         for (int i = 0, j = 0; i < SPECIES.length(); i++){
3678             if(i+origin < SPECIES.length())
3679                 res[i] = b[idx+i+origin];
3680             else {
3681                 res[i] = b[idx+j];
3682                 j++;
3683             }
3684         }
3685         for (int i = 0; i < SPECIES.length(); i++){
3686             res[i] = mask[i] ? a[idx+i] : res[i];
3687         }
3688         double[] res1 = new double[SPECIES.length()];
3689         if (part == 0) {
3690             for (int i = 0, j = 0; i < SPECIES.length(); i++){
3691                 if (i < origin)
3692                     res1[i] = b[idx+i];
3693                 else {
3694                    res1[i] = res[j];
3695                    j++;
3696                 }
3697             }
3698         } else if (part == 1) {
3699             for (int i = 0, j = 0; i < SPECIES.length(); i++){
3700                 if (i < origin)
3701                     res1[i] = res[SPECIES.length()-origin+i];
3702                 else {
3703                     res1[i] = b[idx+origin+j];
3704                     j++;
3705                 }
3706             }
3707         }
3708         return res1;
3709     }
3710 
3711     @Test(dataProvider = "doubleBinaryOpMaskProvider")
3712     static void unsliceDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
3713     IntFunction<boolean[]> fm) {
3714         double[] a = fa.apply(SPECIES.length());
3715         double[] b = fb.apply(SPECIES.length());
3716         boolean[] mask = fm.apply(SPECIES.length());
3717         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3718         double[] r = new double[a.length];
3719         int origin = (new java.util.Random()).nextInt(SPECIES.length());
3720         int part = (new java.util.Random()).nextInt(2);
3721         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3722             for (int i = 0; i < a.length; i += SPECIES.length()) {
3723                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3724                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
3725                 av.unslice(origin, bv, part, vmask).intoArray(r, i);
3726             }
3727         }
3728 
3729         assertArraysEquals(r, a, b, origin, part, mask, DoubleMaxVectorTests::unslice);
3730     }
3731 
3732     static double SIN(double a) {
3733         return (double)(Math.sin((double)a));
3734     }
3735 
3736     static double strictSIN(double a) {
3737         return (double)(StrictMath.sin((double)a));
3738     }
3739 
3740     @Test(dataProvider = "doubleUnaryOpProvider")
3741     static void SINDoubleMaxVectorTests(IntFunction<double[]> fa) {
3742         double[] a = fa.apply(SPECIES.length());
3743         double[] r = fr.apply(SPECIES.length());
3744 
3745         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3746             for (int i = 0; i < a.length; i += SPECIES.length()) {
3747                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3748                 av.lanewise(VectorOperators.SIN).intoArray(r, i);
3749             }
3750         }
3751 
3752         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::SIN, DoubleMaxVectorTests::strictSIN);
3753     }
3754 
3755     static double EXP(double a) {
3756         return (double)(Math.exp((double)a));
3757     }
3758 
3759     static double strictEXP(double a) {
3760         return (double)(StrictMath.exp((double)a));
3761     }
3762 
3763     @Test(dataProvider = "doubleUnaryOpProvider")
3764     static void EXPDoubleMaxVectorTests(IntFunction<double[]> fa) {
3765         double[] a = fa.apply(SPECIES.length());
3766         double[] r = fr.apply(SPECIES.length());
3767 
3768         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3769             for (int i = 0; i < a.length; i += SPECIES.length()) {
3770                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3771                 av.lanewise(VectorOperators.EXP).intoArray(r, i);
3772             }
3773         }
3774 
3775         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::EXP, DoubleMaxVectorTests::strictEXP);
3776     }
3777 
3778     static double LOG1P(double a) {
3779         return (double)(Math.log1p((double)a));
3780     }
3781 
3782     static double strictLOG1P(double a) {
3783         return (double)(StrictMath.log1p((double)a));
3784     }
3785 
3786     @Test(dataProvider = "doubleUnaryOpProvider")
3787     static void LOG1PDoubleMaxVectorTests(IntFunction<double[]> fa) {
3788         double[] a = fa.apply(SPECIES.length());
3789         double[] r = fr.apply(SPECIES.length());
3790 
3791         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3792             for (int i = 0; i < a.length; i += SPECIES.length()) {
3793                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3794                 av.lanewise(VectorOperators.LOG1P).intoArray(r, i);
3795             }
3796         }
3797 
3798         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::LOG1P, DoubleMaxVectorTests::strictLOG1P);
3799     }
3800 
3801     static double LOG(double a) {
3802         return (double)(Math.log((double)a));
3803     }
3804 
3805     static double strictLOG(double a) {
3806         return (double)(StrictMath.log((double)a));
3807     }
3808 
3809     @Test(dataProvider = "doubleUnaryOpProvider")
3810     static void LOGDoubleMaxVectorTests(IntFunction<double[]> fa) {
3811         double[] a = fa.apply(SPECIES.length());
3812         double[] r = fr.apply(SPECIES.length());
3813 
3814         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3815             for (int i = 0; i < a.length; i += SPECIES.length()) {
3816                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3817                 av.lanewise(VectorOperators.LOG).intoArray(r, i);
3818             }
3819         }
3820 
3821         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::LOG, DoubleMaxVectorTests::strictLOG);
3822     }
3823 
3824     static double LOG10(double a) {
3825         return (double)(Math.log10((double)a));
3826     }
3827 
3828     static double strictLOG10(double a) {
3829         return (double)(StrictMath.log10((double)a));
3830     }
3831 
3832     @Test(dataProvider = "doubleUnaryOpProvider")
3833     static void LOG10DoubleMaxVectorTests(IntFunction<double[]> fa) {
3834         double[] a = fa.apply(SPECIES.length());
3835         double[] r = fr.apply(SPECIES.length());
3836 
3837         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3838             for (int i = 0; i < a.length; i += SPECIES.length()) {
3839                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3840                 av.lanewise(VectorOperators.LOG10).intoArray(r, i);
3841             }
3842         }
3843 
3844         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::LOG10, DoubleMaxVectorTests::strictLOG10);
3845     }
3846 
3847     static double EXPM1(double a) {
3848         return (double)(Math.expm1((double)a));
3849     }
3850 
3851     static double strictEXPM1(double a) {
3852         return (double)(StrictMath.expm1((double)a));
3853     }
3854 
3855     @Test(dataProvider = "doubleUnaryOpProvider")
3856     static void EXPM1DoubleMaxVectorTests(IntFunction<double[]> fa) {
3857         double[] a = fa.apply(SPECIES.length());
3858         double[] r = fr.apply(SPECIES.length());
3859 
3860         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3861             for (int i = 0; i < a.length; i += SPECIES.length()) {
3862                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3863                 av.lanewise(VectorOperators.EXPM1).intoArray(r, i);
3864             }
3865         }
3866 
3867         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::EXPM1, DoubleMaxVectorTests::strictEXPM1);
3868     }
3869 
3870     static double COS(double a) {
3871         return (double)(Math.cos((double)a));
3872     }
3873 
3874     static double strictCOS(double a) {
3875         return (double)(StrictMath.cos((double)a));
3876     }
3877 
3878     @Test(dataProvider = "doubleUnaryOpProvider")
3879     static void COSDoubleMaxVectorTests(IntFunction<double[]> fa) {
3880         double[] a = fa.apply(SPECIES.length());
3881         double[] r = fr.apply(SPECIES.length());
3882 
3883         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3884             for (int i = 0; i < a.length; i += SPECIES.length()) {
3885                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3886                 av.lanewise(VectorOperators.COS).intoArray(r, i);
3887             }
3888         }
3889 
3890         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::COS, DoubleMaxVectorTests::strictCOS);
3891     }
3892 
3893     static double TAN(double a) {
3894         return (double)(Math.tan((double)a));
3895     }
3896 
3897     static double strictTAN(double a) {
3898         return (double)(StrictMath.tan((double)a));
3899     }
3900 
3901     @Test(dataProvider = "doubleUnaryOpProvider")
3902     static void TANDoubleMaxVectorTests(IntFunction<double[]> fa) {
3903         double[] a = fa.apply(SPECIES.length());
3904         double[] r = fr.apply(SPECIES.length());
3905 
3906         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3907             for (int i = 0; i < a.length; i += SPECIES.length()) {
3908                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3909                 av.lanewise(VectorOperators.TAN).intoArray(r, i);
3910             }
3911         }
3912 
3913         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::TAN, DoubleMaxVectorTests::strictTAN);
3914     }
3915 
3916     static double SINH(double a) {
3917         return (double)(Math.sinh((double)a));
3918     }
3919 
3920     static double strictSINH(double a) {
3921         return (double)(StrictMath.sinh((double)a));
3922     }
3923 
3924     @Test(dataProvider = "doubleUnaryOpProvider")
3925     static void SINHDoubleMaxVectorTests(IntFunction<double[]> fa) {
3926         double[] a = fa.apply(SPECIES.length());
3927         double[] r = fr.apply(SPECIES.length());
3928 
3929         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3930             for (int i = 0; i < a.length; i += SPECIES.length()) {
3931                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3932                 av.lanewise(VectorOperators.SINH).intoArray(r, i);
3933             }
3934         }
3935 
3936         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::SINH, DoubleMaxVectorTests::strictSINH);
3937     }
3938 
3939     static double COSH(double a) {
3940         return (double)(Math.cosh((double)a));
3941     }
3942 
3943     static double strictCOSH(double a) {
3944         return (double)(StrictMath.cosh((double)a));
3945     }
3946 
3947     @Test(dataProvider = "doubleUnaryOpProvider")
3948     static void COSHDoubleMaxVectorTests(IntFunction<double[]> fa) {
3949         double[] a = fa.apply(SPECIES.length());
3950         double[] r = fr.apply(SPECIES.length());
3951 
3952         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3953             for (int i = 0; i < a.length; i += SPECIES.length()) {
3954                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3955                 av.lanewise(VectorOperators.COSH).intoArray(r, i);
3956             }
3957         }
3958 
3959         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::COSH, DoubleMaxVectorTests::strictCOSH);
3960     }
3961 
3962     static double TANH(double a) {
3963         return (double)(Math.tanh((double)a));
3964     }
3965 
3966     static double strictTANH(double a) {
3967         return (double)(StrictMath.tanh((double)a));
3968     }
3969 
3970     @Test(dataProvider = "doubleUnaryOpProvider")
3971     static void TANHDoubleMaxVectorTests(IntFunction<double[]> fa) {
3972         double[] a = fa.apply(SPECIES.length());
3973         double[] r = fr.apply(SPECIES.length());
3974 
3975         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3976             for (int i = 0; i < a.length; i += SPECIES.length()) {
3977                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
3978                 av.lanewise(VectorOperators.TANH).intoArray(r, i);
3979             }
3980         }
3981 
3982         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::TANH, DoubleMaxVectorTests::strictTANH);
3983     }
3984 
3985     static double ASIN(double a) {
3986         return (double)(Math.asin((double)a));
3987     }
3988 
3989     static double strictASIN(double a) {
3990         return (double)(StrictMath.asin((double)a));
3991     }
3992 
3993     @Test(dataProvider = "doubleUnaryOpProvider")
3994     static void ASINDoubleMaxVectorTests(IntFunction<double[]> fa) {
3995         double[] a = fa.apply(SPECIES.length());
3996         double[] r = fr.apply(SPECIES.length());
3997 
3998         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3999             for (int i = 0; i < a.length; i += SPECIES.length()) {
4000                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4001                 av.lanewise(VectorOperators.ASIN).intoArray(r, i);
4002             }
4003         }
4004 
4005         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::ASIN, DoubleMaxVectorTests::strictASIN);
4006     }
4007 
4008     static double ACOS(double a) {
4009         return (double)(Math.acos((double)a));
4010     }
4011 
4012     static double strictACOS(double a) {
4013         return (double)(StrictMath.acos((double)a));
4014     }
4015 
4016     @Test(dataProvider = "doubleUnaryOpProvider")
4017     static void ACOSDoubleMaxVectorTests(IntFunction<double[]> fa) {
4018         double[] a = fa.apply(SPECIES.length());
4019         double[] r = fr.apply(SPECIES.length());
4020 
4021         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4022             for (int i = 0; i < a.length; i += SPECIES.length()) {
4023                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4024                 av.lanewise(VectorOperators.ACOS).intoArray(r, i);
4025             }
4026         }
4027 
4028         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::ACOS, DoubleMaxVectorTests::strictACOS);
4029     }
4030 
4031     static double ATAN(double a) {
4032         return (double)(Math.atan((double)a));
4033     }
4034 
4035     static double strictATAN(double a) {
4036         return (double)(StrictMath.atan((double)a));
4037     }
4038 
4039     @Test(dataProvider = "doubleUnaryOpProvider")
4040     static void ATANDoubleMaxVectorTests(IntFunction<double[]> fa) {
4041         double[] a = fa.apply(SPECIES.length());
4042         double[] r = fr.apply(SPECIES.length());
4043 
4044         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4045             for (int i = 0; i < a.length; i += SPECIES.length()) {
4046                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4047                 av.lanewise(VectorOperators.ATAN).intoArray(r, i);
4048             }
4049         }
4050 
4051         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::ATAN, DoubleMaxVectorTests::strictATAN);
4052     }
4053 
4054     static double CBRT(double a) {
4055         return (double)(Math.cbrt((double)a));
4056     }
4057 
4058     static double strictCBRT(double a) {
4059         return (double)(StrictMath.cbrt((double)a));
4060     }
4061 
4062     @Test(dataProvider = "doubleUnaryOpProvider")
4063     static void CBRTDoubleMaxVectorTests(IntFunction<double[]> fa) {
4064         double[] a = fa.apply(SPECIES.length());
4065         double[] r = fr.apply(SPECIES.length());
4066 
4067         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4068             for (int i = 0; i < a.length; i += SPECIES.length()) {
4069                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4070                 av.lanewise(VectorOperators.CBRT).intoArray(r, i);
4071             }
4072         }
4073 
4074         assertArraysEqualsWithinOneUlp(r, a, DoubleMaxVectorTests::CBRT, DoubleMaxVectorTests::strictCBRT);
4075     }
4076 
4077     static double HYPOT(double a, double b) {
4078         return (double)(Math.hypot((double)a, (double)b));
4079     }
4080 
4081     static double strictHYPOT(double a, double b) {
4082         return (double)(StrictMath.hypot((double)a, (double)b));
4083     }
4084 
4085     @Test(dataProvider = "doubleBinaryOpProvider")
4086     static void HYPOTDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
4087         double[] a = fa.apply(SPECIES.length());
4088         double[] b = fb.apply(SPECIES.length());
4089         double[] r = fr.apply(SPECIES.length());
4090 
4091         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4092             for (int i = 0; i < a.length; i += SPECIES.length()) {
4093                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4094                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
4095                 av.lanewise(VectorOperators.HYPOT, bv).intoArray(r, i);
4096             }
4097         }
4098 
4099         assertArraysEqualsWithinOneUlp(r, a, b, DoubleMaxVectorTests::HYPOT, DoubleMaxVectorTests::strictHYPOT);
4100     }
4101 
4102 
4103     static double POW(double a, double b) {
4104         return (double)(Math.pow((double)a, (double)b));
4105     }
4106 
4107     static double strictPOW(double a, double b) {
4108         return (double)(StrictMath.pow((double)a, (double)b));
4109     }
4110 
4111     @Test(dataProvider = "doubleBinaryOpProvider")
4112     static void POWDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
4113         double[] a = fa.apply(SPECIES.length());
4114         double[] b = fb.apply(SPECIES.length());
4115         double[] r = fr.apply(SPECIES.length());
4116 
4117         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4118             for (int i = 0; i < a.length; i += SPECIES.length()) {
4119                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4120                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
4121                 av.lanewise(VectorOperators.POW, bv).intoArray(r, i);
4122             }
4123         }
4124 
4125         assertArraysEqualsWithinOneUlp(r, a, b, DoubleMaxVectorTests::POW, DoubleMaxVectorTests::strictPOW);
4126     }
4127 
4128 
4129     static double pow(double a, double b) {
4130         return (double)(Math.pow((double)a, (double)b));
4131     }
4132 
4133     static double strictpow(double a, double b) {
4134         return (double)(StrictMath.pow((double)a, (double)b));
4135     }
4136 
4137     @Test(dataProvider = "doubleBinaryOpProvider")
4138     static void powDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
4139         double[] a = fa.apply(SPECIES.length());
4140         double[] b = fb.apply(SPECIES.length());
4141         double[] r = fr.apply(SPECIES.length());
4142 
4143         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4144             for (int i = 0; i < a.length; i += SPECIES.length()) {
4145                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4146                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
4147                 av.pow(bv).intoArray(r, i);
4148             }
4149         }
4150 
4151         assertArraysEqualsWithinOneUlp(r, a, b, DoubleMaxVectorTests::pow, DoubleMaxVectorTests::strictpow);
4152     }
4153 
4154 
4155     static double ATAN2(double a, double b) {
4156         return (double)(Math.atan2((double)a, (double)b));
4157     }
4158 
4159     static double strictATAN2(double a, double b) {
4160         return (double)(StrictMath.atan2((double)a, (double)b));
4161     }
4162 
4163     @Test(dataProvider = "doubleBinaryOpProvider")
4164     static void ATAN2DoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) {
4165         double[] a = fa.apply(SPECIES.length());
4166         double[] b = fb.apply(SPECIES.length());
4167         double[] r = fr.apply(SPECIES.length());
4168 
4169         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4170             for (int i = 0; i < a.length; i += SPECIES.length()) {
4171                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4172                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
4173                 av.lanewise(VectorOperators.ATAN2, bv).intoArray(r, i);
4174             }
4175         }
4176 
4177         assertArraysEqualsWithinOneUlp(r, a, b, DoubleMaxVectorTests::ATAN2, DoubleMaxVectorTests::strictATAN2);
4178     }
4179 
4180 
4181     @Test(dataProvider = "doubleBinaryOpProvider")
4182     static void POWDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
4183         double[] a = fa.apply(SPECIES.length());
4184         double[] b = fb.apply(SPECIES.length());
4185         double[] r = fr.apply(SPECIES.length());
4186 
4187         for (int i = 0; i < a.length; i += SPECIES.length()) {
4188             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4189             av.lanewise(VectorOperators.POW, b[i]).intoArray(r, i);
4190         }
4191 
4192         assertBroadcastArraysEqualsWithinOneUlp(r, a, b, DoubleMaxVectorTests::POW, DoubleMaxVectorTests::strictPOW);
4193     }
4194 
4195 
4196     @Test(dataProvider = "doubleBinaryOpProvider")
4197     static void powDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
4198         double[] a = fa.apply(SPECIES.length());
4199         double[] b = fb.apply(SPECIES.length());
4200         double[] r = fr.apply(SPECIES.length());
4201 
4202         for (int i = 0; i < a.length; i += SPECIES.length()) {
4203             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4204             av.pow(b[i]).intoArray(r, i);
4205         }
4206 
4207         assertBroadcastArraysEqualsWithinOneUlp(r, a, b, DoubleMaxVectorTests::pow, DoubleMaxVectorTests::strictpow);
4208     }
4209 
4210 
4211     static double FMA(double a, double b, double c) {
4212         return (double)(Math.fma(a, b, c));
4213     }
4214 
4215     static double fma(double a, double b, double c) {
4216         return (double)(Math.fma(a, b, c));
4217     }
4218 
4219     @Test(dataProvider = "doubleTernaryOpProvider")
4220     static void FMADoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb, IntFunction<double[]> fc) {
4221         int count = INVOC_COUNT;
4222         switch ("FMA") {
4223         case "fma": case "lanewise_FMA":
4224            // Math.fma uses BigDecimal
4225            count = Math.max(5, count/20); break;
4226         }
4227         final int INVOC_COUNT = count;
4228         double[] a = fa.apply(SPECIES.length());
4229         double[] b = fb.apply(SPECIES.length());
4230         double[] c = fc.apply(SPECIES.length());
4231         double[] r = fr.apply(SPECIES.length());
4232 
4233         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4234             for (int i = 0; i < a.length; i += SPECIES.length()) {
4235                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4236                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
4237                 DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i);
4238                 av.lanewise(VectorOperators.FMA, bv, cv).intoArray(r, i);
4239             }
4240         }
4241 
4242         assertArraysEquals(r, a, b, c, DoubleMaxVectorTests::FMA);
4243     }
4244 
4245     @Test(dataProvider = "doubleTernaryOpProvider")
4246     static void fmaDoubleMaxVectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb, IntFunction<double[]> fc) {
4247         int count = INVOC_COUNT;
4248         switch ("fma") {
4249         case "fma": case "lanewise_FMA":
4250            // Math.fma uses BigDecimal
4251            count = Math.max(5, count/20); break;
4252         }
4253         final int INVOC_COUNT = count;
4254         double[] a = fa.apply(SPECIES.length());
4255         double[] b = fb.apply(SPECIES.length());
4256         double[] c = fc.apply(SPECIES.length());
4257         double[] r = fr.apply(SPECIES.length());
4258 
4259         for (int i = 0; i < a.length; i += SPECIES.length()) {
4260             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4261             DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
4262             DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i);
4263             av.fma(bv, cv).intoArray(r, i);
4264         }
4265 
4266         assertArraysEquals(r, a, b, c, DoubleMaxVectorTests::fma);
4267     }
4268 
4269     @Test(dataProvider = "doubleTernaryOpMaskProvider")
4270     static void FMADoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb,
4271                                           IntFunction<double[]> fc, IntFunction<boolean[]> fm) {
4272         int count = INVOC_COUNT;
4273         switch ("FMA") {
4274         case "fma": case "lanewise_FMA":
4275            // Math.fma uses BigDecimal
4276            count = Math.max(5, count/20); break;
4277         }
4278         final int INVOC_COUNT = count;
4279         double[] a = fa.apply(SPECIES.length());
4280         double[] b = fb.apply(SPECIES.length());
4281         double[] c = fc.apply(SPECIES.length());
4282         double[] r = fr.apply(SPECIES.length());
4283         boolean[] mask = fm.apply(SPECIES.length());
4284         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4285 
4286         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4287             for (int i = 0; i < a.length; i += SPECIES.length()) {
4288                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4289                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
4290                 DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i);
4291                 av.lanewise(VectorOperators.FMA, bv, cv, vmask).intoArray(r, i);
4292             }
4293         }
4294 
4295         assertArraysEquals(r, a, b, c, mask, DoubleMaxVectorTests::FMA);
4296     }
4297 
4298     @Test(dataProvider = "doubleTernaryOpProvider")
4299     static void FMADoubleMaxVectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, IntFunction<double[]> fc) {
4300         double[] a = fa.apply(SPECIES.length());
4301         double[] b = fb.apply(SPECIES.length());
4302         double[] c = fc.apply(SPECIES.length());
4303         double[] r = fr.apply(SPECIES.length());
4304 
4305         for (int i = 0; i < a.length; i += SPECIES.length()) {
4306             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4307             DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
4308             av.lanewise(VectorOperators.FMA, bv, c[i]).intoArray(r, i);
4309         }
4310         assertBroadcastArraysEquals(r, a, b, c, DoubleMaxVectorTests::FMA);
4311     }
4312 
4313     @Test(dataProvider = "doubleTernaryOpProvider")
4314     static void FMADoubleMaxVectorTestsAltBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, IntFunction<double[]> fc) {
4315         double[] a = fa.apply(SPECIES.length());
4316         double[] b = fb.apply(SPECIES.length());
4317         double[] c = fc.apply(SPECIES.length());
4318         double[] r = fr.apply(SPECIES.length());
4319 
4320         for (int i = 0; i < a.length; i += SPECIES.length()) {
4321             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4322             DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i);
4323             av.lanewise(VectorOperators.FMA, b[i], cv).intoArray(r, i);
4324         }
4325         assertAltBroadcastArraysEquals(r, a, b, c, DoubleMaxVectorTests::FMA);
4326     }
4327 
4328     @Test(dataProvider = "doubleTernaryOpMaskProvider")
4329     static void FMADoubleMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb,
4330                                           IntFunction<double[]> fc, IntFunction<boolean[]> fm) {
4331         double[] a = fa.apply(SPECIES.length());
4332         double[] b = fb.apply(SPECIES.length());
4333         double[] c = fc.apply(SPECIES.length());
4334         double[] r = fr.apply(SPECIES.length());
4335         boolean[] mask = fm.apply(SPECIES.length());
4336         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4337 
4338         for (int i = 0; i < a.length; i += SPECIES.length()) {
4339             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4340             DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
4341             av.lanewise(VectorOperators.FMA, bv, c[i], vmask).intoArray(r, i);
4342         }
4343 
4344         assertBroadcastArraysEquals(r, a, b, c, mask, DoubleMaxVectorTests::FMA);
4345     }
4346 
4347     @Test(dataProvider = "doubleTernaryOpMaskProvider")
4348     static void FMADoubleMaxVectorTestsAltBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb,
4349                                           IntFunction<double[]> fc, IntFunction<boolean[]> fm) {
4350         double[] a = fa.apply(SPECIES.length());
4351         double[] b = fb.apply(SPECIES.length());
4352         double[] c = fc.apply(SPECIES.length());
4353         double[] r = fr.apply(SPECIES.length());
4354         boolean[] mask = fm.apply(SPECIES.length());
4355         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4356 
4357         for (int i = 0; i < a.length; i += SPECIES.length()) {
4358             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4359             DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i);
4360             av.lanewise(VectorOperators.FMA, b[i], cv, vmask).intoArray(r, i);
4361         }
4362 
4363         assertAltBroadcastArraysEquals(r, a, b, c, mask, DoubleMaxVectorTests::FMA);
4364     }
4365 
4366     @Test(dataProvider = "doubleTernaryOpProvider")
4367     static void FMADoubleMaxVectorTestsDoubleBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, IntFunction<double[]> fc) {
4368         int count = INVOC_COUNT;
4369         switch ("FMA") {
4370         case "fma": case "lanewise_FMA":
4371            // Math.fma uses BigDecimal
4372            count = Math.max(5, count/20); break;
4373         }
4374         final int INVOC_COUNT = count;
4375         double[] a = fa.apply(SPECIES.length());
4376         double[] b = fb.apply(SPECIES.length());
4377         double[] c = fc.apply(SPECIES.length());
4378         double[] r = fr.apply(SPECIES.length());
4379 
4380         for (int i = 0; i < a.length; i += SPECIES.length()) {
4381             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4382             av.lanewise(VectorOperators.FMA, b[i], c[i]).intoArray(r, i);
4383         }
4384 
4385         assertDoubleBroadcastArraysEquals(r, a, b, c, DoubleMaxVectorTests::FMA);
4386     }
4387 
4388     @Test(dataProvider = "doubleTernaryOpProvider")
4389     static void fmaDoubleMaxVectorTestsDoubleBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, IntFunction<double[]> fc) {
4390         int count = INVOC_COUNT;
4391         switch ("fma") {
4392         case "fma": case "lanewise_FMA":
4393            // Math.fma uses BigDecimal
4394            count = Math.max(5, count/20); break;
4395         }
4396         final int INVOC_COUNT = count;
4397         double[] a = fa.apply(SPECIES.length());
4398         double[] b = fb.apply(SPECIES.length());
4399         double[] c = fc.apply(SPECIES.length());
4400         double[] r = fr.apply(SPECIES.length());
4401 
4402         for (int i = 0; i < a.length; i += SPECIES.length()) {
4403             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4404             av.fma(b[i], c[i]).intoArray(r, i);
4405         }
4406 
4407         assertDoubleBroadcastArraysEquals(r, a, b, c, DoubleMaxVectorTests::fma);
4408     }
4409 
4410     @Test(dataProvider = "doubleTernaryOpMaskProvider")
4411     static void FMADoubleMaxVectorTestsDoubleBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb,
4412                                           IntFunction<double[]> fc, IntFunction<boolean[]> fm) {
4413         int count = INVOC_COUNT;
4414         switch ("FMA") {
4415         case "fma": case "lanewise_FMA":
4416            // Math.fma uses BigDecimal
4417            count = Math.max(5, count/20); break;
4418         }
4419         final int INVOC_COUNT = count;
4420         double[] a = fa.apply(SPECIES.length());
4421         double[] b = fb.apply(SPECIES.length());
4422         double[] c = fc.apply(SPECIES.length());
4423         double[] r = fr.apply(SPECIES.length());
4424         boolean[] mask = fm.apply(SPECIES.length());
4425         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4426 
4427         for (int i = 0; i < a.length; i += SPECIES.length()) {
4428             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4429             av.lanewise(VectorOperators.FMA, b[i], c[i], vmask).intoArray(r, i);
4430         }
4431 
4432         assertDoubleBroadcastArraysEquals(r, a, b, c, mask, DoubleMaxVectorTests::FMA);
4433     }
4434 
4435     static double NEG(double a) {
4436         return (double)(-((double)a));
4437     }
4438 
4439     static double neg(double a) {
4440         return (double)(-((double)a));
4441     }
4442 
4443     @Test(dataProvider = "doubleUnaryOpProvider")
4444     static void NEGDoubleMaxVectorTests(IntFunction<double[]> fa) {
4445         double[] a = fa.apply(SPECIES.length());
4446         double[] r = fr.apply(SPECIES.length());
4447 
4448         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4449             for (int i = 0; i < a.length; i += SPECIES.length()) {
4450                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4451                 av.lanewise(VectorOperators.NEG).intoArray(r, i);
4452             }
4453         }
4454 
4455         assertArraysEquals(r, a, DoubleMaxVectorTests::NEG);
4456     }
4457 
4458     @Test(dataProvider = "doubleUnaryOpProvider")
4459     static void negDoubleMaxVectorTests(IntFunction<double[]> fa) {
4460         double[] a = fa.apply(SPECIES.length());
4461         double[] r = fr.apply(SPECIES.length());
4462 
4463         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4464             for (int i = 0; i < a.length; i += SPECIES.length()) {
4465                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4466                 av.neg().intoArray(r, i);
4467             }
4468         }
4469 
4470         assertArraysEquals(r, a, DoubleMaxVectorTests::neg);
4471     }
4472 
4473     @Test(dataProvider = "doubleUnaryOpMaskProvider")
4474     static void NEGMaskedDoubleMaxVectorTests(IntFunction<double[]> fa,
4475                                                 IntFunction<boolean[]> fm) {
4476         double[] a = fa.apply(SPECIES.length());
4477         double[] r = fr.apply(SPECIES.length());
4478         boolean[] mask = fm.apply(SPECIES.length());
4479         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4480 
4481         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4482             for (int i = 0; i < a.length; i += SPECIES.length()) {
4483                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4484                 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i);
4485             }
4486         }
4487 
4488         assertArraysEquals(r, a, mask, DoubleMaxVectorTests::NEG);
4489     }
4490 
4491     static double ABS(double a) {
4492         return (double)(Math.abs((double)a));
4493     }
4494 
4495     static double abs(double a) {
4496         return (double)(Math.abs((double)a));
4497     }
4498 
4499     @Test(dataProvider = "doubleUnaryOpProvider")
4500     static void ABSDoubleMaxVectorTests(IntFunction<double[]> fa) {
4501         double[] a = fa.apply(SPECIES.length());
4502         double[] r = fr.apply(SPECIES.length());
4503 
4504         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4505             for (int i = 0; i < a.length; i += SPECIES.length()) {
4506                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4507                 av.lanewise(VectorOperators.ABS).intoArray(r, i);
4508             }
4509         }
4510 
4511         assertArraysEquals(r, a, DoubleMaxVectorTests::ABS);
4512     }
4513 
4514     @Test(dataProvider = "doubleUnaryOpProvider")
4515     static void absDoubleMaxVectorTests(IntFunction<double[]> fa) {
4516         double[] a = fa.apply(SPECIES.length());
4517         double[] r = fr.apply(SPECIES.length());
4518 
4519         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4520             for (int i = 0; i < a.length; i += SPECIES.length()) {
4521                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4522                 av.abs().intoArray(r, i);
4523             }
4524         }
4525 
4526         assertArraysEquals(r, a, DoubleMaxVectorTests::abs);
4527     }
4528 
4529     @Test(dataProvider = "doubleUnaryOpMaskProvider")
4530     static void ABSMaskedDoubleMaxVectorTests(IntFunction<double[]> fa,
4531                                                 IntFunction<boolean[]> fm) {
4532         double[] a = fa.apply(SPECIES.length());
4533         double[] r = fr.apply(SPECIES.length());
4534         boolean[] mask = fm.apply(SPECIES.length());
4535         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4536 
4537         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4538             for (int i = 0; i < a.length; i += SPECIES.length()) {
4539                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4540                 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i);
4541             }
4542         }
4543 
4544         assertArraysEquals(r, a, mask, DoubleMaxVectorTests::ABS);
4545     }
4546 
4547     static double SQRT(double a) {
4548         return (double)(Math.sqrt((double)a));
4549     }
4550 
4551     static double sqrt(double a) {
4552         return (double)(Math.sqrt((double)a));
4553     }
4554 
4555     @Test(dataProvider = "doubleUnaryOpProvider")
4556     static void SQRTDoubleMaxVectorTests(IntFunction<double[]> fa) {
4557         double[] a = fa.apply(SPECIES.length());
4558         double[] r = fr.apply(SPECIES.length());
4559 
4560         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4561             for (int i = 0; i < a.length; i += SPECIES.length()) {
4562                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4563                 av.lanewise(VectorOperators.SQRT).intoArray(r, i);
4564             }
4565         }
4566 
4567         assertArraysEquals(r, a, DoubleMaxVectorTests::SQRT);
4568     }
4569 
4570     @Test(dataProvider = "doubleUnaryOpProvider")
4571     static void sqrtDoubleMaxVectorTests(IntFunction<double[]> fa) {
4572         double[] a = fa.apply(SPECIES.length());
4573         double[] r = fr.apply(SPECIES.length());
4574 
4575         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4576             for (int i = 0; i < a.length; i += SPECIES.length()) {
4577                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4578                 av.sqrt().intoArray(r, i);
4579             }
4580         }
4581 
4582         assertArraysEquals(r, a, DoubleMaxVectorTests::sqrt);
4583     }
4584 
4585     @Test(dataProvider = "doubleUnaryOpMaskProvider")
4586     static void SQRTMaskedDoubleMaxVectorTests(IntFunction<double[]> fa,
4587                                                 IntFunction<boolean[]> fm) {
4588         double[] a = fa.apply(SPECIES.length());
4589         double[] r = fr.apply(SPECIES.length());
4590         boolean[] mask = fm.apply(SPECIES.length());
4591         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4592 
4593         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4594             for (int i = 0; i < a.length; i += SPECIES.length()) {
4595                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4596                 av.lanewise(VectorOperators.SQRT, vmask).intoArray(r, i);
4597             }
4598         }
4599 
4600         assertArraysEquals(r, a, mask, DoubleMaxVectorTests::SQRT);
4601     }
4602 
4603     @Test(dataProvider = "doubleCompareOpProvider")
4604     static void ltDoubleMaxVectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
4605         double[] a = fa.apply(SPECIES.length());
4606         double[] b = fb.apply(SPECIES.length());
4607 
4608         for (int i = 0; i < a.length; i += SPECIES.length()) {
4609             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4610             VectorMask<Double> mv = av.lt(b[i]);
4611 
4612             // Check results as part of computation.
4613             for (int j = 0; j < SPECIES.length(); j++) {
4614                 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i]);
4615             }
4616         }
4617     }
4618 
4619     @Test(dataProvider = "doubleCompareOpProvider")
4620     static void eqDoubleMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) {
4621         double[] a = fa.apply(SPECIES.length());
4622         double[] b = fb.apply(SPECIES.length());
4623 
4624         for (int i = 0; i < a.length; i += SPECIES.length()) {
4625             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4626             VectorMask<Double> mv = av.eq(b[i]);
4627 
4628             // Check results as part of computation.
4629             for (int j = 0; j < SPECIES.length(); j++) {
4630                 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i]);
4631             }
4632         }
4633     }
4634 
4635     @Test(dataProvider = "doubletoIntUnaryOpProvider")
4636     static void toIntArrayDoubleMaxVectorTestsSmokeTest(IntFunction<double[]> fa) {
4637         double[] a = fa.apply(SPECIES.length());
4638 
4639         for (int i = 0; i < a.length; i += SPECIES.length()) {
4640             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4641             int[] r = av.toIntArray();
4642             assertArraysEquals(r, a, i);
4643         }
4644     }
4645 
4646     @Test(dataProvider = "doubletoLongUnaryOpProvider")
4647     static void toLongArrayDoubleMaxVectorTestsSmokeTest(IntFunction<double[]> fa) {
4648         double[] a = fa.apply(SPECIES.length());
4649 
4650         for (int i = 0; i < a.length; i += SPECIES.length()) {
4651             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4652             long[] r = av.toLongArray();
4653             assertArraysEquals(r, a, i);
4654         }
4655     }
4656 
4657 
4658     @Test(dataProvider = "doubleUnaryOpProvider")
4659     static void toStringDoubleMaxVectorTestsSmokeTest(IntFunction<double[]> fa) {
4660         double[] a = fa.apply(SPECIES.length());
4661 
4662         for (int i = 0; i < a.length; i += SPECIES.length()) {
4663             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4664             String str = av.toString();
4665 
4666             double subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
4667             Assert.assertTrue(str.equals(Arrays.toString(subarr)), "at index " + i + ", string should be = " + Arrays.toString(subarr) + ", but is = " + str);
4668         }
4669     }
4670 
4671     @Test(dataProvider = "doubleUnaryOpProvider")
4672     static void hashCodeDoubleMaxVectorTestsSmokeTest(IntFunction<double[]> fa) {
4673         double[] a = fa.apply(SPECIES.length());
4674 
4675         for (int i = 0; i < a.length; i += SPECIES.length()) {
4676             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4677             int hash = av.hashCode();
4678 
4679             double subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
4680             int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr));
4681             Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash);
4682         }
4683     }
4684 
4685 
4686     static long ADDReduceLong(double[] a, int idx) {
4687         double res = 0;
4688         for (int i = idx; i < (idx + SPECIES.length()); i++) {
4689             res += a[i];
4690         }
4691 
4692         return (long)res;
4693     }
4694 
4695     static long ADDReduceAllLong(double[] a) {
4696         long res = 0;
4697         for (int i = 0; i < a.length; i += SPECIES.length()) {
4698             res += ADDReduceLong(a, i);
4699         }
4700 
4701         return res;
4702     }
4703 
4704     @Test(dataProvider = "doubleUnaryOpProvider")
4705     static void ADDReduceLongDoubleMaxVectorTests(IntFunction<double[]> fa) {
4706         double[] a = fa.apply(SPECIES.length());
4707         long[] r = lfr.apply(SPECIES.length());
4708         long ra = 0;
4709 
4710         for (int i = 0; i < a.length; i += SPECIES.length()) {
4711             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4712             r[i] = av.reduceLanesToLong(VectorOperators.ADD);
4713         }
4714 
4715         ra = 0;
4716         for (int i = 0; i < a.length; i ++) {
4717             ra += r[i];
4718         }
4719 
4720         assertReductionLongArraysEquals(r, ra, a,
4721                 DoubleMaxVectorTests::ADDReduceLong, DoubleMaxVectorTests::ADDReduceAllLong);
4722     }
4723 
4724     static long ADDReduceLongMasked(double[] a, int idx, boolean[] mask) {
4725         double res = 0;
4726         for (int i = idx; i < (idx + SPECIES.length()); i++) {
4727             if(mask[i % SPECIES.length()])
4728                 res += a[i];
4729         }
4730 
4731         return (long)res;
4732     }
4733 
4734     static long ADDReduceAllLongMasked(double[] a, boolean[] mask) {
4735         long res = 0;
4736         for (int i = 0; i < a.length; i += SPECIES.length()) {
4737             res += ADDReduceLongMasked(a, i, mask);
4738         }
4739 
4740         return res;
4741     }
4742 
4743     @Test(dataProvider = "doubleUnaryOpMaskProvider")
4744     static void ADDReduceLongDoubleMaxVectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) {
4745         double[] a = fa.apply(SPECIES.length());
4746         long[] r = lfr.apply(SPECIES.length());
4747         boolean[] mask = fm.apply(SPECIES.length());
4748         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4749         long ra = 0;
4750 
4751         for (int i = 0; i < a.length; i += SPECIES.length()) {
4752             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4753             r[i] = av.reduceLanesToLong(VectorOperators.ADD, vmask);
4754         }
4755 
4756         ra = 0;
4757         for (int i = 0; i < a.length; i ++) {
4758             ra += r[i];
4759         }
4760 
4761         assertReductionLongArraysEqualsMasked(r, ra, a, mask,
4762                 DoubleMaxVectorTests::ADDReduceLongMasked, DoubleMaxVectorTests::ADDReduceAllLongMasked);
4763     }
4764 
4765     @Test(dataProvider = "doubletoLongUnaryOpProvider")
4766     static void BroadcastLongDoubleMaxVectorTestsSmokeTest(IntFunction<double[]> fa) {
4767         double[] a = fa.apply(SPECIES.length());
4768         double[] r = new double[a.length];
4769 
4770         for (int i = 0; i < a.length; i += SPECIES.length()) {
4771             DoubleVector.broadcast(SPECIES, (long)a[i]).intoArray(r, i);
4772         }
4773         assertBroadcastArraysEquals(r, a);
4774     }
4775 
4776     @Test(dataProvider = "doubleBinaryOpMaskProvider")
4777     static void blendDoubleMaxVectorTestsBroadcastLongSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb,
4778                                           IntFunction<boolean[]> fm) {
4779         double[] a = fa.apply(SPECIES.length());
4780         double[] b = fb.apply(SPECIES.length());
4781         double[] r = fr.apply(SPECIES.length());
4782         boolean[] mask = fm.apply(SPECIES.length());
4783         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4784 
4785         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4786             for (int i = 0; i < a.length; i += SPECIES.length()) {
4787                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4788                 av.blend((long)b[i], vmask).intoArray(r, i);
4789             }
4790         }
4791         assertBroadcastLongArraysEquals(r, a, b, mask, DoubleMaxVectorTests::blend);
4792     }
4793 
4794 
4795     @Test(dataProvider = "doubleUnaryOpSelectFromProvider")
4796     static void SelectFromDoubleMaxVectorTests(IntFunction<double[]> fa,
4797                                            BiFunction<Integer,Integer,double[]> fs) {
4798         double[] a = fa.apply(SPECIES.length());
4799         double[] order = fs.apply(a.length, SPECIES.length());
4800         double[] r = fr.apply(SPECIES.length());
4801 
4802         for (int i = 0; i < a.length; i += SPECIES.length()) {
4803             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4804             DoubleVector bv = DoubleVector.fromArray(SPECIES, order, i);
4805             bv.selectFrom(av).intoArray(r, i);
4806         }
4807 
4808         assertSelectFromArraysEquals(r, a, order, SPECIES.length());
4809     }
4810 
4811     @Test(dataProvider = "doubleUnaryOpSelectFromMaskProvider")
4812     static void SelectFromDoubleMaxVectorTestsMaskedSmokeTest(IntFunction<double[]> fa,
4813                                                            BiFunction<Integer,Integer,double[]> fs,
4814                                                            IntFunction<boolean[]> fm) {
4815         double[] a = fa.apply(SPECIES.length());
4816         double[] order = fs.apply(a.length, SPECIES.length());
4817         double[] r = fr.apply(SPECIES.length());
4818         boolean[] mask = fm.apply(SPECIES.length());
4819         VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4820 
4821         for (int i = 0; i < a.length; i += SPECIES.length()) {
4822             DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
4823             DoubleVector bv = DoubleVector.fromArray(SPECIES, order, i);
4824             bv.selectFrom(av, vmask).intoArray(r, i);
4825         }
4826 
4827         assertSelectFromArraysEquals(r, a, order, mask, SPECIES.length());
4828     }
4829 
4830     @Test(dataProvider = "shuffleProvider")
4831     static void shuffleMiscellaneousDoubleMaxVectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fs) {
4832         int[] a = fs.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length());
4833 
4834         for (int i = 0; i < a.length; i += SPECIES.length()) {
4835             var shuffle = VectorShuffle.fromArray(SPECIES, a, i);
4836             int hash = shuffle.hashCode();
4837             int length = shuffle.length();
4838 
4839             int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
4840             int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr));
4841             Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash);
4842             Assert.assertEquals(length, SPECIES.length());
4843         }
4844     }
4845 
4846     @Test(dataProvider = "shuffleProvider")
4847     static void shuffleToStringDoubleMaxVectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fs) {
4848         int[] a = fs.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length());
4849 
4850         for (int i = 0; i < a.length; i += SPECIES.length()) {
4851             var shuffle = VectorShuffle.fromArray(SPECIES, a, i);
4852             String str = shuffle.toString();
4853 
4854             int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
4855             Assert.assertTrue(str.equals("Shuffle" + Arrays.toString(subarr)), "at index " +
4856                 i + ", string should be = " + Arrays.toString(subarr) + ", but is = " + str);
4857         }
4858     }
4859 
4860     @Test(dataProvider = "shuffleCompareOpProvider")
4861     static void shuffleEqualsDoubleMaxVectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fa, BiFunction<Integer,Integer,int[]> fb) {
4862         int[] a = fa.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length());
4863         int[] b = fb.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length());
4864 
4865         for (int i = 0; i < a.length; i += SPECIES.length()) {
4866             var av = VectorShuffle.fromArray(SPECIES, a, i);
4867             var bv = VectorShuffle.fromArray(SPECIES, b, i);
4868             boolean eq = av.equals(bv);
4869             int to = i + SPECIES.length();
4870             Assert.assertEquals(eq, Arrays.equals(a, i, to, b, i, to));
4871         }
4872     }
4873 
4874     @Test(dataProvider = "maskCompareOpProvider")
4875     static void maskEqualsDoubleMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) {
4876         boolean[] a = fa.apply(SPECIES.length());
4877         boolean[] b = fb.apply(SPECIES.length());
4878 
4879         for (int i = 0; i < a.length; i += SPECIES.length()) {
4880             var av = SPECIES.loadMask(a, i);
4881             var bv = SPECIES.loadMask(b, i);
4882             boolean equals = av.equals(bv);
4883             int to = i + SPECIES.length();
4884             Assert.assertEquals(equals, Arrays.equals(a, i, to, b, i, to));
4885         }
4886     }
4887 
4888     static boolean beq(boolean a, boolean b) {
4889         return (a == b);
4890     }
4891 
4892     @Test(dataProvider = "maskCompareOpProvider")
4893     static void maskEqDoubleMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) {
4894         boolean[] a = fa.apply(SPECIES.length());
4895         boolean[] b = fb.apply(SPECIES.length());
4896         boolean[] r = new boolean[a.length];
4897 
4898         for (int i = 0; i < a.length; i += SPECIES.length()) {
4899             var av = SPECIES.loadMask(a, i);
4900             var bv = SPECIES.loadMask(b, i);
4901             var cv = av.eq(bv);
4902             cv.intoArray(r, i);
4903         }
4904         assertArraysEquals(r, a, b, DoubleMaxVectorTests::beq);
4905     }
4906 
4907     @Test(dataProvider = "maskProvider")
4908     static void maskHashCodeDoubleMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4909         boolean[] a = fa.apply(SPECIES.length());
4910 
4911         for (int i = 0; i < a.length; i += SPECIES.length()) {
4912             var vmask = SPECIES.loadMask(a, i);
4913             int hash = vmask.hashCode();
4914 
4915             boolean subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
4916             int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr));
4917             Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash);
4918         }
4919     }
4920 
4921     static int maskTrueCount(boolean[] a, int idx) {
4922         int trueCount = 0;
4923         for (int i = idx; i < idx + SPECIES.length(); i++) {
4924             trueCount += a[i] ? 1 : 0;
4925         }
4926         return trueCount;
4927     }
4928 
4929     @Test(dataProvider = "maskProvider")
4930     static void maskTrueCountDoubleMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4931         boolean[] a = fa.apply(SPECIES.length());
4932         int[] r = new int[a.length];
4933 
4934         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
4935             for (int i = 0; i < a.length; i += SPECIES.length()) {
4936                 var vmask = SPECIES.loadMask(a, i);
4937                 r[i] = vmask.trueCount();
4938             }
4939         }
4940 
4941         assertMaskReductionArraysEquals(r, a, DoubleMaxVectorTests::maskTrueCount);
4942     }
4943 
4944     static int maskLastTrue(boolean[] a, int idx) {
4945         int i = idx + SPECIES.length() - 1;
4946         for (; i >= idx; i--) {
4947             if (a[i]) {
4948                 break;
4949             }
4950         }
4951         return i - idx;
4952     }
4953 
4954     @Test(dataProvider = "maskProvider")
4955     static void maskLastTrueDoubleMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4956         boolean[] a = fa.apply(SPECIES.length());
4957         int[] r = new int[a.length];
4958 
4959         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
4960             for (int i = 0; i < a.length; i += SPECIES.length()) {
4961                 var vmask = SPECIES.loadMask(a, i);
4962                 r[i] = vmask.lastTrue();
4963             }
4964         }
4965 
4966         assertMaskReductionArraysEquals(r, a, DoubleMaxVectorTests::maskLastTrue);
4967     }
4968 
4969     static int maskFirstTrue(boolean[] a, int idx) {
4970         int i = idx;
4971         for (; i < idx + SPECIES.length(); i++) {
4972             if (a[i]) {
4973                 break;
4974             }
4975         }
4976         return i - idx;
4977     }
4978 
4979     @Test(dataProvider = "maskProvider")
4980     static void maskFirstTrueDoubleMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4981         boolean[] a = fa.apply(SPECIES.length());
4982         int[] r = new int[a.length];
4983 
4984         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
4985             for (int i = 0; i < a.length; i += SPECIES.length()) {
4986                 var vmask = SPECIES.loadMask(a, i);
4987                 r[i] = vmask.firstTrue();
4988             }
4989         }
4990 
4991         assertMaskReductionArraysEquals(r, a, DoubleMaxVectorTests::maskFirstTrue);
4992     }
4993 
4994     @Test(dataProvider = "maskProvider")
4995     static void maskCompressDoubleMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
4996         int trueCount = 0;
4997         boolean[] a = fa.apply(SPECIES.length());
4998 
4999         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5000             for (int i = 0; i < a.length; i += SPECIES.length()) {
5001                 var vmask = SPECIES.loadMask(a, i);
5002                 trueCount = vmask.trueCount();
5003                 var rmask = vmask.compress();
5004                 for (int j = 0; j < SPECIES.length(); j++)  {
5005                     Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
5006                 }
5007             }
5008         }
5009     }
5010 
5011 
5012     @DataProvider
5013     public static Object[][] offsetProvider() {
5014         return new Object[][]{
5015                 {0},
5016                 {-1},
5017                 {+1},
5018                 {+2},
5019                 {-2},
5020         };
5021     }
5022 
5023     @Test(dataProvider = "offsetProvider")
5024     static void indexInRangeDoubleMaxVectorTestsSmokeTest(int offset) {
5025         int limit = SPECIES.length() * BUFFER_REPS;
5026         for (int i = 0; i < limit; i += SPECIES.length()) {
5027             var actualMask = SPECIES.indexInRange(i + offset, limit);
5028             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
5029             assert(actualMask.equals(expectedMask));
5030             for (int j = 0; j < SPECIES.length(); j++)  {
5031                 int index = i + j + offset;
5032                 Assert.assertEquals(actualMask.laneIsSet(j), index >= 0 && index < limit);
5033             }
5034         }
5035     }
5036 
5037     @Test(dataProvider = "offsetProvider")
5038     static void indexInRangeLongDoubleMaxVectorTestsSmokeTest(int offset) {
5039         long limit = SPECIES.length() * BUFFER_REPS;
5040         for (long i = 0; i < limit; i += SPECIES.length()) {
5041             var actualMask = SPECIES.indexInRange(i + offset, limit);
5042             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
5043             assert(actualMask.equals(expectedMask));
5044             for (int j = 0; j < SPECIES.length(); j++)  {
5045                 long index = i + j + offset;
5046                 Assert.assertEquals(actualMask.laneIsSet(j), index >= 0 && index < limit);
5047             }
5048         }
5049     }
5050 
5051     @DataProvider
5052     public static Object[][] lengthProvider() {
5053         return new Object[][]{
5054                 {0},
5055                 {1},
5056                 {32},
5057                 {37},
5058                 {1024},
5059                 {1024+1},
5060                 {1024+5},
5061         };
5062     }
5063 
5064     @Test(dataProvider = "lengthProvider")
5065     static void loopBoundDoubleMaxVectorTestsSmokeTest(int length) {
5066         int actualLoopBound = SPECIES.loopBound(length);
5067         int expectedLoopBound = length - Math.floorMod(length, SPECIES.length());
5068         Assert.assertEquals(actualLoopBound, expectedLoopBound);
5069     }
5070 
5071     @Test(dataProvider = "lengthProvider")
5072     static void loopBoundLongDoubleMaxVectorTestsSmokeTest(int _length) {
5073         long length = _length;
5074         long actualLoopBound = SPECIES.loopBound(length);
5075         long expectedLoopBound = length - Math.floorMod(length, SPECIES.length());
5076         Assert.assertEquals(actualLoopBound, expectedLoopBound);
5077     }
5078 
5079     @Test
5080     static void ElementSizeDoubleMaxVectorTestsSmokeTest() {
5081         DoubleVector av = DoubleVector.zero(SPECIES);
5082         int elsize = av.elementSize();
5083         Assert.assertEquals(elsize, Double.SIZE);
5084     }
5085 
5086     @Test
5087     static void VectorShapeDoubleMaxVectorTestsSmokeTest() {
5088         DoubleVector av = DoubleVector.zero(SPECIES);
5089         VectorShape vsh = av.shape();
5090         assert(vsh.equals(VectorShape.S_Max_BIT));
5091     }
5092 
5093     @Test
5094     static void ShapeWithLanesDoubleMaxVectorTestsSmokeTest() {
5095         DoubleVector av = DoubleVector.zero(SPECIES);
5096         VectorShape vsh = av.shape();
5097         VectorSpecies species = vsh.withLanes(double.class);
5098         assert(species.equals(SPECIES));
5099     }
5100 
5101     @Test
5102     static void ElementTypeDoubleMaxVectorTestsSmokeTest() {
5103         DoubleVector av = DoubleVector.zero(SPECIES);
5104         assert(av.species().elementType() == double.class);
5105     }
5106 
5107     @Test
5108     static void SpeciesElementSizeDoubleMaxVectorTestsSmokeTest() {
5109         DoubleVector av = DoubleVector.zero(SPECIES);
5110         assert(av.species().elementSize() == Double.SIZE);
5111     }
5112 
5113     @Test
5114     static void VectorTypeDoubleMaxVectorTestsSmokeTest() {
5115         DoubleVector av = DoubleVector.zero(SPECIES);
5116         assert(av.species().vectorType() == av.getClass());
5117     }
5118 
5119     @Test
5120     static void WithLanesDoubleMaxVectorTestsSmokeTest() {
5121         DoubleVector av = DoubleVector.zero(SPECIES);
5122         VectorSpecies species = av.species().withLanes(double.class);
5123         assert(species.equals(SPECIES));
5124     }
5125 
5126     @Test
5127     static void WithShapeDoubleMaxVectorTestsSmokeTest() {
5128         DoubleVector av = DoubleVector.zero(SPECIES);
5129         VectorShape vsh = av.shape();
5130         VectorSpecies species = av.species().withShape(vsh);
5131         assert(species.equals(SPECIES));
5132     }
5133 
5134     @Test
5135     static void MaskAllTrueDoubleMaxVectorTestsSmokeTest() {
5136         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5137           Assert.assertEquals(SPECIES.maskAll(true).toLong(), -1L >>> (64 - SPECIES.length()));
5138         }
5139     }
5140 }