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