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