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