1 /*
   2  * Copyright (c) 2018, 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
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @modules jdk.incubator.vector
  27  * @run testng/othervm -ea -esa ShortMaxVectorTests
  28  */
  29 
  30 import jdk.incubator.vector.VectorShape;
  31 import jdk.incubator.vector.VectorSpecies;
  32 import jdk.incubator.vector.VectorShuffle;
  33 import jdk.incubator.vector.VectorMask;
  34 import jdk.incubator.vector.Vector;
  35 
  36 import jdk.incubator.vector.ShortVector;
  37 
  38 import org.testng.Assert;
  39 import org.testng.annotations.DataProvider;
  40 import org.testng.annotations.Test;
  41 
  42 import java.lang.Integer;
  43 import java.util.List;
  44 import java.util.function.BiFunction;
  45 import java.util.function.IntFunction;
  46 import java.util.stream.Collectors;
  47 import java.util.stream.Stream;
  48 
  49 @Test
  50 public class ShortMaxVectorTests extends AbstractVectorTest {
  51 
  52     static final VectorSpecies<Short> SPECIES =
  53                 ShortVector.SPECIES_MAX;
  54 
  55     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  56 
  57     static VectorShape getMaxBit() {
  58         return VectorShape.S_Max_BIT;
  59     }
  60 
  61     interface FUnOp {
  62         short apply(short a);
  63     }
  64 
  65     static void assertArraysEquals(short[] a, short[] r, FUnOp f) {
  66         int i = 0;
  67         try {
  68             for (; i < a.length; i++) {
  69                 Assert.assertEquals(r[i], f.apply(a[i]));
  70             }
  71         } catch (AssertionError e) {
  72             Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
  73         }
  74     }
  75 
  76     static void assertArraysEquals(short[] a, short[] r, boolean[] mask, FUnOp f) {
  77         int i = 0;
  78         try {
  79             for (; i < a.length; i++) {
  80                 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]);
  81             }
  82         } catch (AssertionError e) {
  83             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()]);
  84         }
  85     }
  86 
  87     interface FReductionOp {
  88         short apply(short[] a, int idx);
  89     }
  90 
  91     interface FReductionAllOp {
  92         short apply(short[] a);
  93     }
  94 
  95     static void assertReductionArraysEquals(short[] a, short[] b, short c,
  96                                             FReductionOp f, FReductionAllOp fa) {
  97         int i = 0;
  98         try {
  99             Assert.assertEquals(c, fa.apply(a));
 100             for (; i < a.length; i += SPECIES.length()) {
 101                 Assert.assertEquals(b[i], f.apply(a, i));
 102             }
 103         } catch (AssertionError e) {
 104             Assert.assertEquals(c, fa.apply(a), "Final result is incorrect!");
 105             Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i);
 106         }
 107     }
 108 
 109     interface FBoolReductionOp {
 110         boolean apply(boolean[] a, int idx);
 111     }
 112 
 113     static void assertReductionBoolArraysEquals(boolean[] a, boolean[] b, FBoolReductionOp f) {
 114         int i = 0;
 115         try {
 116             for (; i < a.length; i += SPECIES.length()) {
 117                 Assert.assertEquals(f.apply(a, i), b[i]);
 118             }
 119         } catch (AssertionError e) {
 120             Assert.assertEquals(f.apply(a, i), b[i], "at index #" + i);
 121         }
 122     }
 123 
 124     static void assertInsertArraysEquals(short[] a, short[] b, short element, int index) {
 125         int i = 0;
 126         try {
 127             for (; i < a.length; i += 1) {
 128                 if(i%SPECIES.length() == index) {
 129                     Assert.assertEquals(b[i], element);
 130                 } else {
 131                     Assert.assertEquals(b[i], a[i]);
 132                 }
 133             }
 134         } catch (AssertionError e) {
 135             if (i%SPECIES.length() == index) {
 136                 Assert.assertEquals(b[i], element, "at index #" + i);
 137             } else {
 138                 Assert.assertEquals(b[i], a[i], "at index #" + i);
 139             }
 140         }
 141     }
 142 
 143     static void assertRearrangeArraysEquals(short[] a, short[] r, int[] order, int vector_len) {
 144         int i = 0, j = 0;
 145         try {
 146             for (; i < a.length; i += vector_len) {
 147                 for (j = 0; j < vector_len; j++) {
 148                     Assert.assertEquals(r[i+j], a[i+order[i+j]]);
 149                 }
 150             }
 151         } catch (AssertionError e) {
 152             int idx = i + j;
 153             Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
 154         }
 155     }
 156 
 157     interface FBinOp {
 158         short apply(short a, short b);
 159     }
 160 
 161     interface FBinMaskOp {
 162         short apply(short a, short b, boolean m);
 163 
 164         static FBinMaskOp lift(FBinOp f) {
 165             return (a, b, m) -> m ? f.apply(a, b) : a;
 166         }
 167     }
 168 
 169     static void assertArraysEquals(short[] a, short[] b, short[] r, FBinOp f) {
 170         int i = 0;
 171         try {
 172             for (; i < a.length; i++) {
 173                 Assert.assertEquals(r[i], f.apply(a[i], b[i]));
 174             }
 175         } catch (AssertionError e) {
 176             Assert.assertEquals(f.apply(a[i], b[i]), r[i], "(" + a[i] + ", " + b[i] + ") at index #" + i);
 177         }
 178     }
 179 
 180     static void assertArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) {
 181         assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 182     }
 183 
 184     static void assertArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinMaskOp f) {
 185         int i = 0;
 186         try {
 187             for (; i < a.length; i++) {
 188                 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]));
 189             }
 190         } catch (AssertionError err) {
 191             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()]);
 192         }
 193     }
 194 
 195     static void assertShiftArraysEquals(short[] a, short[] b, short[] r, FBinOp f) {
 196         int i = 0;
 197         int j = 0;
 198         try {
 199             for (; j < a.length; j += SPECIES.length()) {
 200                 for (i = 0; i < SPECIES.length(); i++) {
 201                     Assert.assertEquals(f.apply(a[i+j], b[j]), r[i+j]);
 202                 }
 203             }
 204         } catch (AssertionError e) {
 205             Assert.assertEquals(f.apply(a[i+j], b[j]), r[i+j], "at index #" + i + ", " + j);
 206         }
 207     }
 208 
 209     static void assertShiftArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinOp f) {
 210         assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 211     }
 212 
 213     static void assertShiftArraysEquals(short[] a, short[] b, short[] r, boolean[] mask, FBinMaskOp f) {
 214         int i = 0;
 215         int j = 0;
 216         try {
 217             for (; j < a.length; j += SPECIES.length()) {
 218                 for (i = 0; i < SPECIES.length(); i++) {
 219                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i]));
 220                 }
 221             }
 222         } catch (AssertionError err) {
 223             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]);
 224         }
 225     }
 226 
 227 
 228     interface FBinArrayOp {
 229         short apply(short[] a, int b);
 230     }
 231 
 232     static void assertArraysEquals(short[] a, short[] r, FBinArrayOp f) {
 233         int i = 0;
 234         try {
 235             for (; i < a.length; i++) {
 236                 Assert.assertEquals(f.apply(a, i), r[i]);
 237             }
 238         } catch (AssertionError e) {
 239             Assert.assertEquals(f.apply(a,i), r[i], "at index #" + i);
 240         }
 241     }
 242 
 243     static final List<IntFunction<short[]>> SHORT_GENERATORS = List.of(
 244             withToString("short[-i * 5]", (int s) -> {
 245                 return fill(s * 1000,
 246                             i -> (short)(-i * 5));
 247             }),
 248             withToString("short[i * 5]", (int s) -> {
 249                 return fill(s * 1000,
 250                             i -> (short)(i * 5));
 251             }),
 252             withToString("short[i + 1]", (int s) -> {
 253                 return fill(s * 1000,
 254                             i -> (((short)(i + 1) == 0) ? 1 : (short)(i + 1)));
 255             }),
 256             withToString("short[cornerCaseValue(i)]", (int s) -> {
 257                 return fill(s * 1000,
 258                             i -> cornerCaseValue(i));
 259             })
 260     );
 261 
 262     // Create combinations of pairs
 263     // @@@ Might be sensitive to order e.g. div by 0
 264     static final List<List<IntFunction<short[]>>> SHORT_GENERATOR_PAIRS =
 265         Stream.of(SHORT_GENERATORS.get(0)).
 266                 flatMap(fa -> SHORT_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
 267                 collect(Collectors.toList());
 268 
 269     @DataProvider
 270     public Object[][] boolUnaryOpProvider() {
 271         return BOOL_ARRAY_GENERATORS.stream().
 272                 map(f -> new Object[]{f}).
 273                 toArray(Object[][]::new);
 274     }
 275 
 276 
 277     @DataProvider
 278     public Object[][] shortBinaryOpProvider() {
 279         return SHORT_GENERATOR_PAIRS.stream().map(List::toArray).
 280                 toArray(Object[][]::new);
 281     }
 282 
 283     @DataProvider
 284     public Object[][] shortIndexedOpProvider() {
 285         return SHORT_GENERATOR_PAIRS.stream().map(List::toArray).
 286                 toArray(Object[][]::new);
 287     }
 288 
 289     @DataProvider
 290     public Object[][] shortBinaryOpMaskProvider() {
 291         return BOOLEAN_MASK_GENERATORS.stream().
 292                 flatMap(fm -> SHORT_GENERATOR_PAIRS.stream().map(lfa -> {
 293                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
 294                 })).
 295                 toArray(Object[][]::new);
 296     }
 297 
 298 
 299     @DataProvider
 300     public Object[][] shortUnaryOpProvider() {
 301         return SHORT_GENERATORS.stream().
 302                 map(f -> new Object[]{f}).
 303                 toArray(Object[][]::new);
 304     }
 305 
 306     @DataProvider
 307     public Object[][] shortUnaryOpMaskProvider() {
 308         return BOOLEAN_MASK_GENERATORS.stream().
 309                 flatMap(fm -> SHORT_GENERATORS.stream().map(fa -> {
 310                     return new Object[] {fa, fm};
 311                 })).
 312                 toArray(Object[][]::new);
 313     }
 314 
 315     @DataProvider
 316     public Object[][] shortUnaryOpShuffleProvider() {
 317         return INT_SHUFFLE_GENERATORS.stream().
 318                 flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> {
 319                     return new Object[] {fa, fs};
 320                 })).
 321                 toArray(Object[][]::new);
 322     }
 323 
 324     @DataProvider
 325     public Object[][] shortUnaryOpIndexProvider() {
 326         return INT_INDEX_GENERATORS.stream().
 327                 flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> {
 328                     return new Object[] {fa, fs};
 329                 })).
 330                 toArray(Object[][]::new);
 331     }
 332 
 333 
 334     static final List<IntFunction<short[]>> SHORT_COMPARE_GENERATORS = List.of(
 335             withToString("short[i]", (int s) -> {
 336                 return fill(s * 1000,
 337                             i -> (short)i);
 338             }),
 339             withToString("short[i + 1]", (int s) -> {
 340                 return fill(s * 1000,
 341                             i -> (short)(i + 1));
 342             }),
 343             withToString("short[i - 2]", (int s) -> {
 344                 return fill(s * 1000,
 345                             i -> (short)(i - 2));
 346             }),
 347             withToString("short[zigZag(i)]", (int s) -> {
 348                 return fill(s * 1000,
 349                             i -> i%3 == 0 ? (short)i : (i%3 == 1 ? (short)(i + 1) : (short)(i - 2)));
 350             }),
 351             withToString("short[cornerCaseValue(i)]", (int s) -> {
 352                 return fill(s * 1000,
 353                             i -> cornerCaseValue(i));
 354             })
 355     );
 356 
 357     static final List<List<IntFunction<short[]>>> SHORT_COMPARE_GENERATOR_PAIRS =
 358         SHORT_COMPARE_GENERATORS.stream().
 359                 flatMap(fa -> SHORT_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))).
 360                 collect(Collectors.toList());
 361 
 362     @DataProvider
 363     public Object[][] shortCompareOpProvider() {
 364         return SHORT_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
 365                 toArray(Object[][]::new);
 366     }
 367 
 368     interface ToShortF {
 369         short apply(int i);
 370     }
 371 
 372     static short[] fill(int s , ToShortF f) {
 373         return fill(new short[s], f);
 374     }
 375 
 376     static short[] fill(short[] a, ToShortF f) {
 377         for (int i = 0; i < a.length; i++) {
 378             a[i] = f.apply(i);
 379         }
 380         return a;
 381     }
 382 
 383     static short cornerCaseValue(int i) {
 384         switch(i % 5) {
 385             case 0:
 386                 return Short.MAX_VALUE;
 387             case 1:
 388                 return Short.MIN_VALUE;
 389             case 2:
 390                 return Short.MIN_VALUE;
 391             case 3:
 392                 return Short.MAX_VALUE;
 393             default:
 394                 return (short)0;
 395         }
 396     }
 397    static short get(short[] a, int i) {
 398        return (short) a[i];
 399    }
 400 
 401    static final IntFunction<short[]> fr = (vl) -> {
 402         int length = 1000 * vl;
 403         return new short[length];
 404     };
 405 
 406     static final IntFunction<boolean[]> fmr = (vl) -> {
 407         int length = 1000 * vl;
 408         return new boolean[length];
 409     };
 410     static short add(short a, short b) {
 411         return (short)(a + b);
 412     }
 413 
 414     @Test(dataProvider = "shortBinaryOpProvider")
 415     static void addShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 416         short[] a = fa.apply(SPECIES.length());
 417         short[] b = fb.apply(SPECIES.length());
 418         short[] r = fr.apply(SPECIES.length());
 419 
 420         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 421             for (int i = 0; i < a.length; i += SPECIES.length()) {
 422                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 423                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 424                 av.add(bv).intoArray(r, i);
 425             }
 426         }
 427 
 428         assertArraysEquals(a, b, r, ShortMaxVectorTests::add);
 429     }
 430 
 431     @Test(dataProvider = "shortBinaryOpMaskProvider")
 432     static void addShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 433                                           IntFunction<boolean[]> fm) {
 434         short[] a = fa.apply(SPECIES.length());
 435         short[] b = fb.apply(SPECIES.length());
 436         short[] r = fr.apply(SPECIES.length());
 437         boolean[] mask = fm.apply(SPECIES.length());
 438         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 439 
 440         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 441             for (int i = 0; i < a.length; i += SPECIES.length()) {
 442                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 443                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 444                 av.add(bv, vmask).intoArray(r, i);
 445             }
 446         }
 447 
 448         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::add);
 449     }
 450     static short sub(short a, short b) {
 451         return (short)(a - b);
 452     }
 453 
 454     @Test(dataProvider = "shortBinaryOpProvider")
 455     static void subShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 456         short[] a = fa.apply(SPECIES.length());
 457         short[] b = fb.apply(SPECIES.length());
 458         short[] r = fr.apply(SPECIES.length());
 459 
 460         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 461             for (int i = 0; i < a.length; i += SPECIES.length()) {
 462                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 463                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 464                 av.sub(bv).intoArray(r, i);
 465             }
 466         }
 467 
 468         assertArraysEquals(a, b, r, ShortMaxVectorTests::sub);
 469     }
 470 
 471     @Test(dataProvider = "shortBinaryOpMaskProvider")
 472     static void subShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 473                                           IntFunction<boolean[]> fm) {
 474         short[] a = fa.apply(SPECIES.length());
 475         short[] b = fb.apply(SPECIES.length());
 476         short[] r = fr.apply(SPECIES.length());
 477         boolean[] mask = fm.apply(SPECIES.length());
 478         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 479 
 480         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 481             for (int i = 0; i < a.length; i += SPECIES.length()) {
 482                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 483                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 484                 av.sub(bv, vmask).intoArray(r, i);
 485             }
 486         }
 487 
 488         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::sub);
 489     }
 490 
 491 
 492     static short mul(short a, short b) {
 493         return (short)(a * b);
 494     }
 495 
 496     @Test(dataProvider = "shortBinaryOpProvider")
 497     static void mulShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 498         short[] a = fa.apply(SPECIES.length());
 499         short[] b = fb.apply(SPECIES.length());
 500         short[] r = fr.apply(SPECIES.length());
 501 
 502         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 503             for (int i = 0; i < a.length; i += SPECIES.length()) {
 504                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 505                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 506                 av.mul(bv).intoArray(r, i);
 507             }
 508         }
 509 
 510         assertArraysEquals(a, b, r, ShortMaxVectorTests::mul);
 511     }
 512 
 513     @Test(dataProvider = "shortBinaryOpMaskProvider")
 514     static void mulShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 515                                           IntFunction<boolean[]> fm) {
 516         short[] a = fa.apply(SPECIES.length());
 517         short[] b = fb.apply(SPECIES.length());
 518         short[] r = fr.apply(SPECIES.length());
 519         boolean[] mask = fm.apply(SPECIES.length());
 520         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 521 
 522         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 523             for (int i = 0; i < a.length; i += SPECIES.length()) {
 524                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 525                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 526                 av.mul(bv, vmask).intoArray(r, i);
 527             }
 528         }
 529 
 530         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::mul);
 531     }
 532 
 533     static short and(short a, short b) {
 534         return (short)(a & b);
 535     }
 536 
 537     @Test(dataProvider = "shortBinaryOpProvider")
 538     static void andShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 539         short[] a = fa.apply(SPECIES.length());
 540         short[] b = fb.apply(SPECIES.length());
 541         short[] r = fr.apply(SPECIES.length());
 542 
 543         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 544             for (int i = 0; i < a.length; i += SPECIES.length()) {
 545                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 546                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 547                 av.and(bv).intoArray(r, i);
 548             }
 549         }
 550 
 551         assertArraysEquals(a, b, r, ShortMaxVectorTests::and);
 552     }
 553 
 554 
 555 
 556     @Test(dataProvider = "shortBinaryOpMaskProvider")
 557     static void andShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 558                                           IntFunction<boolean[]> fm) {
 559         short[] a = fa.apply(SPECIES.length());
 560         short[] b = fb.apply(SPECIES.length());
 561         short[] r = fr.apply(SPECIES.length());
 562         boolean[] mask = fm.apply(SPECIES.length());
 563         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 564 
 565         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 566             for (int i = 0; i < a.length; i += SPECIES.length()) {
 567                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 568                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 569                 av.and(bv, vmask).intoArray(r, i);
 570             }
 571         }
 572 
 573         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::and);
 574     }
 575 
 576 
 577     static short or(short a, short b) {
 578         return (short)(a | b);
 579     }
 580 
 581     @Test(dataProvider = "shortBinaryOpProvider")
 582     static void orShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 583         short[] a = fa.apply(SPECIES.length());
 584         short[] b = fb.apply(SPECIES.length());
 585         short[] r = fr.apply(SPECIES.length());
 586 
 587         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 588             for (int i = 0; i < a.length; i += SPECIES.length()) {
 589                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 590                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 591                 av.or(bv).intoArray(r, i);
 592             }
 593         }
 594 
 595         assertArraysEquals(a, b, r, ShortMaxVectorTests::or);
 596     }
 597 
 598 
 599 
 600     @Test(dataProvider = "shortBinaryOpMaskProvider")
 601     static void orShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 602                                           IntFunction<boolean[]> fm) {
 603         short[] a = fa.apply(SPECIES.length());
 604         short[] b = fb.apply(SPECIES.length());
 605         short[] r = fr.apply(SPECIES.length());
 606         boolean[] mask = fm.apply(SPECIES.length());
 607         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 608 
 609         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 610             for (int i = 0; i < a.length; i += SPECIES.length()) {
 611                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 612                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 613                 av.or(bv, vmask).intoArray(r, i);
 614             }
 615         }
 616 
 617         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::or);
 618     }
 619 
 620 
 621     static short xor(short a, short b) {
 622         return (short)(a ^ b);
 623     }
 624 
 625     @Test(dataProvider = "shortBinaryOpProvider")
 626     static void xorShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 627         short[] a = fa.apply(SPECIES.length());
 628         short[] b = fb.apply(SPECIES.length());
 629         short[] r = fr.apply(SPECIES.length());
 630 
 631         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 632             for (int i = 0; i < a.length; i += SPECIES.length()) {
 633                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 634                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 635                 av.xor(bv).intoArray(r, i);
 636             }
 637         }
 638 
 639         assertArraysEquals(a, b, r, ShortMaxVectorTests::xor);
 640     }
 641 
 642 
 643 
 644     @Test(dataProvider = "shortBinaryOpMaskProvider")
 645     static void xorShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 646                                           IntFunction<boolean[]> fm) {
 647         short[] a = fa.apply(SPECIES.length());
 648         short[] b = fb.apply(SPECIES.length());
 649         short[] r = fr.apply(SPECIES.length());
 650         boolean[] mask = fm.apply(SPECIES.length());
 651         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 652 
 653         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 654             for (int i = 0; i < a.length; i += SPECIES.length()) {
 655                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 656                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 657                 av.xor(bv, vmask).intoArray(r, i);
 658             }
 659         }
 660 
 661         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::xor);
 662     }
 663 
 664 
 665 
 666 
 667 
 668 
 669     static short shiftLeft(short a, short b) {
 670         return (short)((a << (b & 0xF)));
 671     }
 672 
 673     @Test(dataProvider = "shortBinaryOpProvider")
 674     static void shiftLeftShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 675         short[] a = fa.apply(SPECIES.length());
 676         short[] b = fb.apply(SPECIES.length());
 677         short[] r = fr.apply(SPECIES.length());
 678 
 679         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 680             for (int i = 0; i < a.length; i += SPECIES.length()) {
 681                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 682                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 683                 av.shiftLeft(bv).intoArray(r, i);
 684             }
 685         }
 686 
 687         assertArraysEquals(a, b, r, ShortMaxVectorTests::shiftLeft);
 688     }
 689 
 690 
 691 
 692     @Test(dataProvider = "shortBinaryOpMaskProvider")
 693     static void shiftLeftShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 694                                           IntFunction<boolean[]> fm) {
 695         short[] a = fa.apply(SPECIES.length());
 696         short[] b = fb.apply(SPECIES.length());
 697         short[] r = fr.apply(SPECIES.length());
 698         boolean[] mask = fm.apply(SPECIES.length());
 699         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 700 
 701         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 702             for (int i = 0; i < a.length; i += SPECIES.length()) {
 703                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 704                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 705                 av.shiftLeft(bv, vmask).intoArray(r, i);
 706             }
 707         }
 708 
 709         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftLeft);
 710     }
 711 
 712 
 713 
 714 
 715 
 716 
 717     static short shiftRight(short a, short b) {
 718         return (short)((a >>> (b & 0xF)));
 719     }
 720 
 721     @Test(dataProvider = "shortBinaryOpProvider")
 722     static void shiftRightShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 723         short[] a = fa.apply(SPECIES.length());
 724         short[] b = fb.apply(SPECIES.length());
 725         short[] r = fr.apply(SPECIES.length());
 726 
 727         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 728             for (int i = 0; i < a.length; i += SPECIES.length()) {
 729                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 730                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 731                 av.shiftRight(bv).intoArray(r, i);
 732             }
 733         }
 734 
 735         assertArraysEquals(a, b, r, ShortMaxVectorTests::shiftRight);
 736     }
 737 
 738 
 739 
 740     @Test(dataProvider = "shortBinaryOpMaskProvider")
 741     static void shiftRightShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 742                                           IntFunction<boolean[]> fm) {
 743         short[] a = fa.apply(SPECIES.length());
 744         short[] b = fb.apply(SPECIES.length());
 745         short[] r = fr.apply(SPECIES.length());
 746         boolean[] mask = fm.apply(SPECIES.length());
 747         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 748 
 749         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 750             for (int i = 0; i < a.length; i += SPECIES.length()) {
 751                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 752                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 753                 av.shiftRight(bv, vmask).intoArray(r, i);
 754             }
 755         }
 756 
 757         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftRight);
 758     }
 759 
 760 
 761 
 762 
 763 
 764 
 765     static short shiftArithmeticRight(short a, short b) {
 766         return (short)((a >> (b & 0xF)));
 767     }
 768 
 769     @Test(dataProvider = "shortBinaryOpProvider")
 770     static void shiftArithmeticRightShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 771         short[] a = fa.apply(SPECIES.length());
 772         short[] b = fb.apply(SPECIES.length());
 773         short[] r = fr.apply(SPECIES.length());
 774 
 775         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 776             for (int i = 0; i < a.length; i += SPECIES.length()) {
 777                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 778                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 779                 av.shiftArithmeticRight(bv).intoArray(r, i);
 780             }
 781         }
 782 
 783         assertArraysEquals(a, b, r, ShortMaxVectorTests::shiftArithmeticRight);
 784     }
 785 
 786 
 787 
 788     @Test(dataProvider = "shortBinaryOpMaskProvider")
 789     static void shiftArithmeticRightShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 790                                           IntFunction<boolean[]> fm) {
 791         short[] a = fa.apply(SPECIES.length());
 792         short[] b = fb.apply(SPECIES.length());
 793         short[] r = fr.apply(SPECIES.length());
 794         boolean[] mask = fm.apply(SPECIES.length());
 795         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 796 
 797         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 798             for (int i = 0; i < a.length; i += SPECIES.length()) {
 799                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 800                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 801                 av.shiftArithmeticRight(bv, vmask).intoArray(r, i);
 802             }
 803         }
 804 
 805         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftArithmeticRight);
 806     }
 807 
 808 
 809 
 810 
 811 
 812 
 813     static short shiftLeft_unary(short a, short b) {
 814         return (short)((a << (b & 15)));
 815     }
 816 
 817     @Test(dataProvider = "shortBinaryOpProvider")
 818     static void shiftLeftShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 819         short[] a = fa.apply(SPECIES.length());
 820         short[] b = fb.apply(SPECIES.length());
 821         short[] r = fr.apply(SPECIES.length());
 822 
 823         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 824             for (int i = 0; i < a.length; i += SPECIES.length()) {
 825                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 826                 av.shiftLeft((int)b[i]).intoArray(r, i);
 827             }
 828         }
 829 
 830         assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::shiftLeft_unary);
 831     }
 832 
 833 
 834 
 835     @Test(dataProvider = "shortBinaryOpMaskProvider")
 836     static void shiftLeftShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
 837                                           IntFunction<boolean[]> fm) {
 838         short[] a = fa.apply(SPECIES.length());
 839         short[] b = fb.apply(SPECIES.length());
 840         short[] r = fr.apply(SPECIES.length());
 841         boolean[] mask = fm.apply(SPECIES.length());
 842         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 843 
 844         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 845             for (int i = 0; i < a.length; i += SPECIES.length()) {
 846                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 847                 av.shiftLeft((int)b[i], vmask).intoArray(r, i);
 848             }
 849         }
 850 
 851         assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftLeft_unary);
 852     }
 853 
 854 
 855 
 856 
 857 
 858 
 859     static short shiftRight_unary(short a, short b) {
 860         return (short)(((a & 0xFFFF) >>> (b & 15)));
 861     }
 862 
 863     @Test(dataProvider = "shortBinaryOpProvider")
 864     static void shiftRightShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 865         short[] a = fa.apply(SPECIES.length());
 866         short[] b = fb.apply(SPECIES.length());
 867         short[] r = fr.apply(SPECIES.length());
 868 
 869         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 870             for (int i = 0; i < a.length; i += SPECIES.length()) {
 871                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 872                 av.shiftRight((int)b[i]).intoArray(r, i);
 873             }
 874         }
 875 
 876         assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::shiftRight_unary);
 877     }
 878 
 879 
 880 
 881     @Test(dataProvider = "shortBinaryOpMaskProvider")
 882     static void shiftRightShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
 883                                           IntFunction<boolean[]> fm) {
 884         short[] a = fa.apply(SPECIES.length());
 885         short[] b = fb.apply(SPECIES.length());
 886         short[] r = fr.apply(SPECIES.length());
 887         boolean[] mask = fm.apply(SPECIES.length());
 888         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 889 
 890         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 891             for (int i = 0; i < a.length; i += SPECIES.length()) {
 892                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 893                 av.shiftRight((int)b[i], vmask).intoArray(r, i);
 894             }
 895         }
 896 
 897         assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftRight_unary);
 898     }
 899 
 900 
 901 
 902 
 903 
 904 
 905     static short shiftArithmeticRight_unary(short a, short b) {
 906         return (short)((a >> (b & 15)));
 907     }
 908 
 909     @Test(dataProvider = "shortBinaryOpProvider")
 910     static void shiftArithmeticRightShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 911         short[] a = fa.apply(SPECIES.length());
 912         short[] b = fb.apply(SPECIES.length());
 913         short[] r = fr.apply(SPECIES.length());
 914 
 915         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 916             for (int i = 0; i < a.length; i += SPECIES.length()) {
 917                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 918                 av.shiftArithmeticRight((int)b[i]).intoArray(r, i);
 919             }
 920         }
 921 
 922         assertShiftArraysEquals(a, b, r, ShortMaxVectorTests::shiftArithmeticRight_unary);
 923     }
 924 
 925 
 926 
 927     @Test(dataProvider = "shortBinaryOpMaskProvider")
 928     static void shiftArithmeticRightShortMaxVectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
 929                                           IntFunction<boolean[]> fm) {
 930         short[] a = fa.apply(SPECIES.length());
 931         short[] b = fb.apply(SPECIES.length());
 932         short[] r = fr.apply(SPECIES.length());
 933         boolean[] mask = fm.apply(SPECIES.length());
 934         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 935 
 936         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 937             for (int i = 0; i < a.length; i += SPECIES.length()) {
 938                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 939                 av.shiftArithmeticRight((int)b[i], vmask).intoArray(r, i);
 940             }
 941         }
 942 
 943         assertShiftArraysEquals(a, b, r, mask, ShortMaxVectorTests::shiftArithmeticRight_unary);
 944     }
 945 
 946     static short max(short a, short b) {
 947         return (short)(Math.max(a, b));
 948     }
 949 
 950     @Test(dataProvider = "shortBinaryOpProvider")
 951     static void maxShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 952         short[] a = fa.apply(SPECIES.length());
 953         short[] b = fb.apply(SPECIES.length());
 954         short[] r = fr.apply(SPECIES.length());
 955 
 956         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 957             for (int i = 0; i < a.length; i += SPECIES.length()) {
 958                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 959                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 960                 av.max(bv).intoArray(r, i);
 961             }
 962         }
 963 
 964         assertArraysEquals(a, b, r, ShortMaxVectorTests::max);
 965     }
 966     static short min(short a, short b) {
 967         return (short)(Math.min(a, b));
 968     }
 969 
 970     @Test(dataProvider = "shortBinaryOpProvider")
 971     static void minShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 972         short[] a = fa.apply(SPECIES.length());
 973         short[] b = fb.apply(SPECIES.length());
 974         short[] r = fr.apply(SPECIES.length());
 975 
 976         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 977             for (int i = 0; i < a.length; i += SPECIES.length()) {
 978                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 979                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 980                 av.min(bv).intoArray(r, i);
 981             }
 982         }
 983 
 984         assertArraysEquals(a, b, r, ShortMaxVectorTests::min);
 985     }
 986 
 987     static short andLanes(short[] a, int idx) {
 988         short res = -1;
 989         for (int i = idx; i < (idx + SPECIES.length()); i++) {
 990             res &= a[i];
 991         }
 992 
 993         return res;
 994     }
 995 
 996     static short andLanes(short[] a) {
 997         short res = -1;
 998         for (int i = 0; i < a.length; i += SPECIES.length()) {
 999             short tmp = -1;
1000             for (int j = 0; j < SPECIES.length(); j++) {
1001                 tmp &= a[i + j];
1002             }
1003             res &= tmp;
1004         }
1005 
1006         return res;
1007     }
1008 
1009 
1010     @Test(dataProvider = "shortUnaryOpProvider")
1011     static void andLanesShortMaxVectorTests(IntFunction<short[]> fa) {
1012         short[] a = fa.apply(SPECIES.length());
1013         short[] r = fr.apply(SPECIES.length());
1014         short ra = -1;
1015 
1016         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1017             for (int i = 0; i < a.length; i += SPECIES.length()) {
1018                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1019                 r[i] = av.andLanes();
1020             }
1021         }
1022 
1023         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1024             ra = -1;
1025             for (int i = 0; i < a.length; i += SPECIES.length()) {
1026                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1027                 ra &= av.andLanes();
1028             }
1029         }
1030 
1031         assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::andLanes, ShortMaxVectorTests::andLanes);
1032     }
1033 
1034 
1035     static short orLanes(short[] a, int idx) {
1036         short res = 0;
1037         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1038             res |= a[i];
1039         }
1040 
1041         return res;
1042     }
1043 
1044     static short orLanes(short[] a) {
1045         short res = 0;
1046         for (int i = 0; i < a.length; i += SPECIES.length()) {
1047             short tmp = 0;
1048             for (int j = 0; j < SPECIES.length(); j++) {
1049                 tmp |= a[i + j];
1050             }
1051             res |= tmp;
1052         }
1053 
1054         return res;
1055     }
1056 
1057 
1058     @Test(dataProvider = "shortUnaryOpProvider")
1059     static void orLanesShortMaxVectorTests(IntFunction<short[]> fa) {
1060         short[] a = fa.apply(SPECIES.length());
1061         short[] r = fr.apply(SPECIES.length());
1062         short ra = 0;
1063 
1064         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1065             for (int i = 0; i < a.length; i += SPECIES.length()) {
1066                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1067                 r[i] = av.orLanes();
1068             }
1069         }
1070 
1071         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1072             ra = 0;
1073             for (int i = 0; i < a.length; i += SPECIES.length()) {
1074                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1075                 ra |= av.orLanes();
1076             }
1077         }
1078 
1079         assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::orLanes, ShortMaxVectorTests::orLanes);
1080     }
1081 
1082 
1083     static short xorLanes(short[] a, int idx) {
1084         short res = 0;
1085         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1086             res ^= a[i];
1087         }
1088 
1089         return res;
1090     }
1091 
1092     static short xorLanes(short[] a) {
1093         short res = 0;
1094         for (int i = 0; i < a.length; i += SPECIES.length()) {
1095             short tmp = 0;
1096             for (int j = 0; j < SPECIES.length(); j++) {
1097                 tmp ^= a[i + j];
1098             }
1099             res ^= tmp;
1100         }
1101 
1102         return res;
1103     }
1104 
1105 
1106     @Test(dataProvider = "shortUnaryOpProvider")
1107     static void xorLanesShortMaxVectorTests(IntFunction<short[]> fa) {
1108         short[] a = fa.apply(SPECIES.length());
1109         short[] r = fr.apply(SPECIES.length());
1110         short ra = 0;
1111 
1112         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1113             for (int i = 0; i < a.length; i += SPECIES.length()) {
1114                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1115                 r[i] = av.xorLanes();
1116             }
1117         }
1118 
1119         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1120             ra = 0;
1121             for (int i = 0; i < a.length; i += SPECIES.length()) {
1122                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1123                 ra ^= av.xorLanes();
1124             }
1125         }
1126 
1127         assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::xorLanes, ShortMaxVectorTests::xorLanes);
1128     }
1129 
1130     static short addLanes(short[] a, int idx) {
1131         short res = 0;
1132         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1133             res += a[i];
1134         }
1135 
1136         return res;
1137     }
1138 
1139     static short addLanes(short[] a) {
1140         short res = 0;
1141         for (int i = 0; i < a.length; i += SPECIES.length()) {
1142             short tmp = 0;
1143             for (int j = 0; j < SPECIES.length(); j++) {
1144                 tmp += a[i + j];
1145             }
1146             res += tmp;
1147         }
1148 
1149         return res;
1150     }
1151     @Test(dataProvider = "shortUnaryOpProvider")
1152     static void addLanesShortMaxVectorTests(IntFunction<short[]> fa) {
1153         short[] a = fa.apply(SPECIES.length());
1154         short[] r = fr.apply(SPECIES.length());
1155         short ra = 0;
1156 
1157         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1158             for (int i = 0; i < a.length; i += SPECIES.length()) {
1159                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1160                 r[i] = av.addLanes();
1161             }
1162         }
1163 
1164         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1165             ra = 0;
1166             for (int i = 0; i < a.length; i += SPECIES.length()) {
1167                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1168                 ra += av.addLanes();
1169             }
1170         }
1171 
1172         assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::addLanes, ShortMaxVectorTests::addLanes);
1173     }
1174     static short mulLanes(short[] a, int idx) {
1175         short res = 1;
1176         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1177             res *= a[i];
1178         }
1179 
1180         return res;
1181     }
1182 
1183     static short mulLanes(short[] a) {
1184         short res = 1;
1185         for (int i = 0; i < a.length; i += SPECIES.length()) {
1186             short tmp = 1;
1187             for (int j = 0; j < SPECIES.length(); j++) {
1188                 tmp *= a[i + j];
1189             }
1190             res *= tmp;
1191         }
1192 
1193         return res;
1194     }
1195     @Test(dataProvider = "shortUnaryOpProvider")
1196     static void mulLanesShortMaxVectorTests(IntFunction<short[]> fa) {
1197         short[] a = fa.apply(SPECIES.length());
1198         short[] r = fr.apply(SPECIES.length());
1199         short ra = 1;
1200 
1201         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1202             for (int i = 0; i < a.length; i += SPECIES.length()) {
1203                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1204                 r[i] = av.mulLanes();
1205             }
1206         }
1207 
1208         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1209             ra = 1;
1210             for (int i = 0; i < a.length; i += SPECIES.length()) {
1211                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1212                 ra *= av.mulLanes();
1213             }
1214         }
1215 
1216         assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::mulLanes, ShortMaxVectorTests::mulLanes);
1217     }
1218     static short minLanes(short[] a, int idx) {
1219         short res = Short.MAX_VALUE;
1220         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1221             res = (short)Math.min(res, a[i]);
1222         }
1223 
1224         return res;
1225     }
1226 
1227     static short minLanes(short[] a) {
1228         short res = Short.MAX_VALUE;
1229         for (int i = 0; i < a.length; i++) {
1230             res = (short)Math.min(res, a[i]);
1231         }
1232 
1233         return res;
1234     }
1235     @Test(dataProvider = "shortUnaryOpProvider")
1236     static void minLanesShortMaxVectorTests(IntFunction<short[]> fa) {
1237         short[] a = fa.apply(SPECIES.length());
1238         short[] r = fr.apply(SPECIES.length());
1239         short ra = Short.MAX_VALUE;
1240 
1241         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1242             for (int i = 0; i < a.length; i += SPECIES.length()) {
1243                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1244                 r[i] = av.minLanes();
1245             }
1246         }
1247 
1248         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1249             ra = Short.MAX_VALUE;
1250             for (int i = 0; i < a.length; i += SPECIES.length()) {
1251                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1252                 ra = (short)Math.min(ra, av.minLanes());
1253             }
1254         }
1255 
1256         assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::minLanes, ShortMaxVectorTests::minLanes);
1257     }
1258     static short maxLanes(short[] a, int idx) {
1259         short res = Short.MIN_VALUE;
1260         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1261             res = (short)Math.max(res, a[i]);
1262         }
1263 
1264         return res;
1265     }
1266 
1267     static short maxLanes(short[] a) {
1268         short res = Short.MIN_VALUE;
1269         for (int i = 0; i < a.length; i++) {
1270             res = (short)Math.max(res, a[i]);
1271         }
1272 
1273         return res;
1274     }
1275     @Test(dataProvider = "shortUnaryOpProvider")
1276     static void maxLanesShortMaxVectorTests(IntFunction<short[]> fa) {
1277         short[] a = fa.apply(SPECIES.length());
1278         short[] r = fr.apply(SPECIES.length());
1279         short ra = Short.MIN_VALUE;
1280 
1281         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1282             for (int i = 0; i < a.length; i += SPECIES.length()) {
1283                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1284                 r[i] = av.maxLanes();
1285             }
1286         }
1287 
1288         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1289             ra = Short.MIN_VALUE;
1290             for (int i = 0; i < a.length; i += SPECIES.length()) {
1291                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1292                 ra = (short)Math.max(ra, av.maxLanes());
1293             }
1294         }
1295 
1296         assertReductionArraysEquals(a, r, ra, ShortMaxVectorTests::maxLanes, ShortMaxVectorTests::maxLanes);
1297     }
1298 
1299     static boolean anyTrue(boolean[] a, int idx) {
1300         boolean res = false;
1301         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1302             res |= a[i];
1303         }
1304 
1305         return res;
1306     }
1307 
1308 
1309     @Test(dataProvider = "boolUnaryOpProvider")
1310     static void anyTrueShortMaxVectorTests(IntFunction<boolean[]> fm) {
1311         boolean[] mask = fm.apply(SPECIES.length());
1312         boolean[] r = fmr.apply(SPECIES.length());
1313 
1314         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1315             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1316                 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, i);
1317                 r[i] = vmask.anyTrue();
1318             }
1319         }
1320 
1321         assertReductionBoolArraysEquals(mask, r, ShortMaxVectorTests::anyTrue);
1322     }
1323 
1324 
1325     static boolean allTrue(boolean[] a, int idx) {
1326         boolean res = true;
1327         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1328             res &= a[i];
1329         }
1330 
1331         return res;
1332     }
1333 
1334 
1335     @Test(dataProvider = "boolUnaryOpProvider")
1336     static void allTrueShortMaxVectorTests(IntFunction<boolean[]> fm) {
1337         boolean[] mask = fm.apply(SPECIES.length());
1338         boolean[] r = fmr.apply(SPECIES.length());
1339 
1340         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1341             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1342                 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, i);
1343                 r[i] = vmask.allTrue();
1344             }
1345         }
1346 
1347         assertReductionBoolArraysEquals(mask, r, ShortMaxVectorTests::allTrue);
1348     }
1349 
1350 
1351     @Test(dataProvider = "shortUnaryOpProvider")
1352     static void withShortMaxVectorTests(IntFunction<short []> fa) {
1353         short[] a = fa.apply(SPECIES.length());
1354         short[] r = fr.apply(SPECIES.length());
1355 
1356         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1357             for (int i = 0; i < a.length; i += SPECIES.length()) {
1358                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1359                 av.with(0, (short)4).intoArray(r, i);
1360             }
1361         }
1362 
1363         assertInsertArraysEquals(a, r, (short)4, 0);
1364     }
1365 
1366     @Test(dataProvider = "shortCompareOpProvider")
1367     static void lessThanShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1368         short[] a = fa.apply(SPECIES.length());
1369         short[] b = fb.apply(SPECIES.length());
1370 
1371         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1372             for (int i = 0; i < a.length; i += SPECIES.length()) {
1373                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1374                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1375                 VectorMask<Short> mv = av.lessThan(bv);
1376 
1377                 // Check results as part of computation.
1378                 for (int j = 0; j < SPECIES.length(); j++) {
1379                     Assert.assertEquals(mv.lane(j), a[i + j] < b[i + j]);
1380                 }
1381             }
1382         }
1383     }
1384 
1385 
1386     @Test(dataProvider = "shortCompareOpProvider")
1387     static void greaterThanShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1388         short[] a = fa.apply(SPECIES.length());
1389         short[] b = fb.apply(SPECIES.length());
1390 
1391         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1392             for (int i = 0; i < a.length; i += SPECIES.length()) {
1393                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1394                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1395                 VectorMask<Short> mv = av.greaterThan(bv);
1396 
1397                 // Check results as part of computation.
1398                 for (int j = 0; j < SPECIES.length(); j++) {
1399                     Assert.assertEquals(mv.lane(j), a[i + j] > b[i + j]);
1400                 }
1401             }
1402         }
1403     }
1404 
1405 
1406     @Test(dataProvider = "shortCompareOpProvider")
1407     static void equalShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1408         short[] a = fa.apply(SPECIES.length());
1409         short[] b = fb.apply(SPECIES.length());
1410 
1411         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1412             for (int i = 0; i < a.length; i += SPECIES.length()) {
1413                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1414                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1415                 VectorMask<Short> mv = av.equal(bv);
1416 
1417                 // Check results as part of computation.
1418                 for (int j = 0; j < SPECIES.length(); j++) {
1419                     Assert.assertEquals(mv.lane(j), a[i + j] == b[i + j]);
1420                 }
1421             }
1422         }
1423     }
1424 
1425 
1426     @Test(dataProvider = "shortCompareOpProvider")
1427     static void notEqualShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1428         short[] a = fa.apply(SPECIES.length());
1429         short[] b = fb.apply(SPECIES.length());
1430 
1431         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1432             for (int i = 0; i < a.length; i += SPECIES.length()) {
1433                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1434                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1435                 VectorMask<Short> mv = av.notEqual(bv);
1436 
1437                 // Check results as part of computation.
1438                 for (int j = 0; j < SPECIES.length(); j++) {
1439                     Assert.assertEquals(mv.lane(j), a[i + j] != b[i + j]);
1440                 }
1441             }
1442         }
1443     }
1444 
1445 
1446     @Test(dataProvider = "shortCompareOpProvider")
1447     static void lessThanEqShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1448         short[] a = fa.apply(SPECIES.length());
1449         short[] b = fb.apply(SPECIES.length());
1450 
1451         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1452             for (int i = 0; i < a.length; i += SPECIES.length()) {
1453                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1454                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1455                 VectorMask<Short> mv = av.lessThanEq(bv);
1456 
1457                 // Check results as part of computation.
1458                 for (int j = 0; j < SPECIES.length(); j++) {
1459                     Assert.assertEquals(mv.lane(j), a[i + j] <= b[i + j]);
1460                 }
1461             }
1462         }
1463     }
1464 
1465 
1466     @Test(dataProvider = "shortCompareOpProvider")
1467     static void greaterThanEqShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1468         short[] a = fa.apply(SPECIES.length());
1469         short[] b = fb.apply(SPECIES.length());
1470 
1471         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1472             for (int i = 0; i < a.length; i += SPECIES.length()) {
1473                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1474                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1475                 VectorMask<Short> mv = av.greaterThanEq(bv);
1476 
1477                 // Check results as part of computation.
1478                 for (int j = 0; j < SPECIES.length(); j++) {
1479                     Assert.assertEquals(mv.lane(j), a[i + j] >= b[i + j]);
1480                 }
1481             }
1482         }
1483     }
1484 
1485 
1486     static short blend(short a, short b, boolean mask) {
1487         return mask ? b : a;
1488     }
1489 
1490     @Test(dataProvider = "shortBinaryOpMaskProvider")
1491     static void blendShortMaxVectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
1492                                           IntFunction<boolean[]> fm) {
1493         short[] a = fa.apply(SPECIES.length());
1494         short[] b = fb.apply(SPECIES.length());
1495         short[] r = fr.apply(SPECIES.length());
1496         boolean[] mask = fm.apply(SPECIES.length());
1497         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
1498 
1499         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1500             for (int i = 0; i < a.length; i += SPECIES.length()) {
1501                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1502                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1503                 av.blend(bv, vmask).intoArray(r, i);
1504             }
1505         }
1506 
1507         assertArraysEquals(a, b, r, mask, ShortMaxVectorTests::blend);
1508     }
1509 
1510     @Test(dataProvider = "shortUnaryOpShuffleProvider")
1511     static void RearrangeShortMaxVectorTests(IntFunction<short[]> fa,
1512                                            BiFunction<Integer,Integer,int[]> fs) {
1513         short[] a = fa.apply(SPECIES.length());
1514         int[] order = fs.apply(a.length, SPECIES.length());
1515         short[] r = fr.apply(SPECIES.length());
1516 
1517         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1518             for (int i = 0; i < a.length; i += SPECIES.length()) {
1519                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1520                 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
1521             }
1522         }
1523 
1524         assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1525     }
1526 
1527 
1528 
1529 
1530     @Test(dataProvider = "shortUnaryOpProvider")
1531     static void getShortMaxVectorTests(IntFunction<short[]> fa) {
1532         short[] a = fa.apply(SPECIES.length());
1533         short[] r = fr.apply(SPECIES.length());
1534 
1535         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1536             for (int i = 0; i < a.length; i += SPECIES.length()) {
1537                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1538                 int num_lanes = SPECIES.length();
1539                 // Manually unroll because full unroll happens after intrinsification.
1540                 // Unroll is needed because get intrinsic requires for index to be a known constant.
1541                 if (num_lanes == 1) {
1542                     r[i]=av.lane(0);
1543                 } else if (num_lanes == 2) {
1544                     r[i]=av.lane(0);
1545                     r[i+1]=av.lane(1);
1546                 } else if (num_lanes == 4) {
1547                     r[i]=av.lane(0);
1548                     r[i+1]=av.lane(1);
1549                     r[i+2]=av.lane(2);
1550                     r[i+3]=av.lane(3);
1551                 } else if (num_lanes == 8) {
1552                     r[i]=av.lane(0);
1553                     r[i+1]=av.lane(1);
1554                     r[i+2]=av.lane(2);
1555                     r[i+3]=av.lane(3);
1556                     r[i+4]=av.lane(4);
1557                     r[i+5]=av.lane(5);
1558                     r[i+6]=av.lane(6);
1559                     r[i+7]=av.lane(7);
1560                 } else if (num_lanes == 16) {
1561                     r[i]=av.lane(0);
1562                     r[i+1]=av.lane(1);
1563                     r[i+2]=av.lane(2);
1564                     r[i+3]=av.lane(3);
1565                     r[i+4]=av.lane(4);
1566                     r[i+5]=av.lane(5);
1567                     r[i+6]=av.lane(6);
1568                     r[i+7]=av.lane(7);
1569                     r[i+8]=av.lane(8);
1570                     r[i+9]=av.lane(9);
1571                     r[i+10]=av.lane(10);
1572                     r[i+11]=av.lane(11);
1573                     r[i+12]=av.lane(12);
1574                     r[i+13]=av.lane(13);
1575                     r[i+14]=av.lane(14);
1576                     r[i+15]=av.lane(15);
1577                 } else if (num_lanes == 32) {
1578                     r[i]=av.lane(0);
1579                     r[i+1]=av.lane(1);
1580                     r[i+2]=av.lane(2);
1581                     r[i+3]=av.lane(3);
1582                     r[i+4]=av.lane(4);
1583                     r[i+5]=av.lane(5);
1584                     r[i+6]=av.lane(6);
1585                     r[i+7]=av.lane(7);
1586                     r[i+8]=av.lane(8);
1587                     r[i+9]=av.lane(9);
1588                     r[i+10]=av.lane(10);
1589                     r[i+11]=av.lane(11);
1590                     r[i+12]=av.lane(12);
1591                     r[i+13]=av.lane(13);
1592                     r[i+14]=av.lane(14);
1593                     r[i+15]=av.lane(15);
1594                     r[i+16]=av.lane(16);
1595                     r[i+17]=av.lane(17);
1596                     r[i+18]=av.lane(18);
1597                     r[i+19]=av.lane(19);
1598                     r[i+20]=av.lane(20);
1599                     r[i+21]=av.lane(21);
1600                     r[i+22]=av.lane(22);
1601                     r[i+23]=av.lane(23);
1602                     r[i+24]=av.lane(24);
1603                     r[i+25]=av.lane(25);
1604                     r[i+26]=av.lane(26);
1605                     r[i+27]=av.lane(27);
1606                     r[i+28]=av.lane(28);
1607                     r[i+29]=av.lane(29);
1608                     r[i+30]=av.lane(30);
1609                     r[i+31]=av.lane(31);
1610                 } else if (num_lanes == 64) {
1611                     r[i]=av.lane(0);
1612                     r[i+1]=av.lane(1);
1613                     r[i+2]=av.lane(2);
1614                     r[i+3]=av.lane(3);
1615                     r[i+4]=av.lane(4);
1616                     r[i+5]=av.lane(5);
1617                     r[i+6]=av.lane(6);
1618                     r[i+7]=av.lane(7);
1619                     r[i+8]=av.lane(8);
1620                     r[i+9]=av.lane(9);
1621                     r[i+10]=av.lane(10);
1622                     r[i+11]=av.lane(11);
1623                     r[i+12]=av.lane(12);
1624                     r[i+13]=av.lane(13);
1625                     r[i+14]=av.lane(14);
1626                     r[i+15]=av.lane(15);
1627                     r[i+16]=av.lane(16);
1628                     r[i+17]=av.lane(17);
1629                     r[i+18]=av.lane(18);
1630                     r[i+19]=av.lane(19);
1631                     r[i+20]=av.lane(20);
1632                     r[i+21]=av.lane(21);
1633                     r[i+22]=av.lane(22);
1634                     r[i+23]=av.lane(23);
1635                     r[i+24]=av.lane(24);
1636                     r[i+25]=av.lane(25);
1637                     r[i+26]=av.lane(26);
1638                     r[i+27]=av.lane(27);
1639                     r[i+28]=av.lane(28);
1640                     r[i+29]=av.lane(29);
1641                     r[i+30]=av.lane(30);
1642                     r[i+31]=av.lane(31);
1643                     r[i+32]=av.lane(32);
1644                     r[i+33]=av.lane(33);
1645                     r[i+34]=av.lane(34);
1646                     r[i+35]=av.lane(35);
1647                     r[i+36]=av.lane(36);
1648                     r[i+37]=av.lane(37);
1649                     r[i+38]=av.lane(38);
1650                     r[i+39]=av.lane(39);
1651                     r[i+40]=av.lane(40);
1652                     r[i+41]=av.lane(41);
1653                     r[i+42]=av.lane(42);
1654                     r[i+43]=av.lane(43);
1655                     r[i+44]=av.lane(44);
1656                     r[i+45]=av.lane(45);
1657                     r[i+46]=av.lane(46);
1658                     r[i+47]=av.lane(47);
1659                     r[i+48]=av.lane(48);
1660                     r[i+49]=av.lane(49);
1661                     r[i+50]=av.lane(50);
1662                     r[i+51]=av.lane(51);
1663                     r[i+52]=av.lane(52);
1664                     r[i+53]=av.lane(53);
1665                     r[i+54]=av.lane(54);
1666                     r[i+55]=av.lane(55);
1667                     r[i+56]=av.lane(56);
1668                     r[i+57]=av.lane(57);
1669                     r[i+58]=av.lane(58);
1670                     r[i+59]=av.lane(59);
1671                     r[i+60]=av.lane(60);
1672                     r[i+61]=av.lane(61);
1673                     r[i+62]=av.lane(62);
1674                     r[i+63]=av.lane(63);
1675                 } else {
1676                     for (int j = 0; j < SPECIES.length(); j++) {
1677                         r[i+j]=av.lane(j);
1678                     }
1679                 }
1680             }
1681         }
1682 
1683         assertArraysEquals(a, r, ShortMaxVectorTests::get);
1684     }
1685 
1686 
1687 
1688 
1689 
1690 
1691 
1692 
1693 
1694 
1695 
1696 
1697 
1698 
1699 
1700 
1701 
1702 
1703 
1704 
1705 
1706 
1707     static short neg(short a) {
1708         return (short)(-((short)a));
1709     }
1710 
1711     @Test(dataProvider = "shortUnaryOpProvider")
1712     static void negShortMaxVectorTests(IntFunction<short[]> fa) {
1713         short[] a = fa.apply(SPECIES.length());
1714         short[] r = fr.apply(SPECIES.length());
1715 
1716         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1717             for (int i = 0; i < a.length; i += SPECIES.length()) {
1718                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1719                 av.neg().intoArray(r, i);
1720             }
1721         }
1722 
1723         assertArraysEquals(a, r, ShortMaxVectorTests::neg);
1724     }
1725 
1726     @Test(dataProvider = "shortUnaryOpMaskProvider")
1727     static void negMaskedShortMaxVectorTests(IntFunction<short[]> fa,
1728                                                 IntFunction<boolean[]> fm) {
1729         short[] a = fa.apply(SPECIES.length());
1730         short[] r = fr.apply(SPECIES.length());
1731         boolean[] mask = fm.apply(SPECIES.length());
1732         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
1733 
1734         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1735             for (int i = 0; i < a.length; i += SPECIES.length()) {
1736                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1737                 av.neg(vmask).intoArray(r, i);
1738             }
1739         }
1740 
1741         assertArraysEquals(a, r, mask, ShortMaxVectorTests::neg);
1742     }
1743 
1744     static short abs(short a) {
1745         return (short)(Math.abs((short)a));
1746     }
1747 
1748     @Test(dataProvider = "shortUnaryOpProvider")
1749     static void absShortMaxVectorTests(IntFunction<short[]> fa) {
1750         short[] a = fa.apply(SPECIES.length());
1751         short[] r = fr.apply(SPECIES.length());
1752 
1753         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1754             for (int i = 0; i < a.length; i += SPECIES.length()) {
1755                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1756                 av.abs().intoArray(r, i);
1757             }
1758         }
1759 
1760         assertArraysEquals(a, r, ShortMaxVectorTests::abs);
1761     }
1762 
1763     @Test(dataProvider = "shortUnaryOpMaskProvider")
1764     static void absMaskedShortMaxVectorTests(IntFunction<short[]> fa,
1765                                                 IntFunction<boolean[]> fm) {
1766         short[] a = fa.apply(SPECIES.length());
1767         short[] r = fr.apply(SPECIES.length());
1768         boolean[] mask = fm.apply(SPECIES.length());
1769         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
1770 
1771         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1772             for (int i = 0; i < a.length; i += SPECIES.length()) {
1773                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1774                 av.abs(vmask).intoArray(r, i);
1775             }
1776         }
1777 
1778         assertArraysEquals(a, r, mask, ShortMaxVectorTests::abs);
1779     }
1780 
1781 
1782     static short not(short a) {
1783         return (short)(~((short)a));
1784     }
1785 
1786 
1787 
1788     @Test(dataProvider = "shortUnaryOpProvider")
1789     static void notShortMaxVectorTests(IntFunction<short[]> fa) {
1790         short[] a = fa.apply(SPECIES.length());
1791         short[] r = fr.apply(SPECIES.length());
1792 
1793         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1794             for (int i = 0; i < a.length; i += SPECIES.length()) {
1795                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1796                 av.not().intoArray(r, i);
1797             }
1798         }
1799 
1800         assertArraysEquals(a, r, ShortMaxVectorTests::not);
1801     }
1802 
1803 
1804 
1805     @Test(dataProvider = "shortUnaryOpMaskProvider")
1806     static void notMaskedShortMaxVectorTests(IntFunction<short[]> fa,
1807                                                 IntFunction<boolean[]> fm) {
1808         short[] a = fa.apply(SPECIES.length());
1809         short[] r = fr.apply(SPECIES.length());
1810         boolean[] mask = fm.apply(SPECIES.length());
1811         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
1812 
1813         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1814             for (int i = 0; i < a.length; i += SPECIES.length()) {
1815                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1816                 av.not(vmask).intoArray(r, i);
1817             }
1818         }
1819 
1820         assertArraysEquals(a, r, mask, ShortMaxVectorTests::not);
1821     }
1822 
1823 
1824 
1825 
1826 
1827 
1828 }
1829