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