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