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