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