1 /*
   2  * Copyright (c) 2018, 2020, 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 Byte128VectorTests
  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.stream.Collectors;
  51 import java.util.stream.Stream;
  52 
  53 @Test
  54 public class Byte128VectorTests extends AbstractVectorTest {
  55 
  56     static final VectorSpecies<Byte> SPECIES =
  57                 ByteVector.SPECIES_128;
  58 
  59     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  60 
  61 
  62     static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128);
  63 
  64     static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (128 / 8));
  65 
  66     interface FUnOp {
  67         byte apply(byte a);
  68     }
  69 
  70     static void assertArraysEquals(byte[] a, byte[] r, FUnOp f) {
  71         int i = 0;
  72         try {
  73             for (; i < a.length; i++) {
  74                 Assert.assertEquals(r[i], f.apply(a[i]));
  75             }
  76         } catch (AssertionError e) {
  77             Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
  78         }
  79     }
  80 
  81     interface FUnArrayOp {
  82         byte[] apply(byte a);
  83     }
  84 
  85     static void assertArraysEquals(byte[] a, byte[] r, FUnArrayOp f) {
  86         int i = 0;
  87         try {
  88             for (; i < a.length; i += SPECIES.length()) {
  89                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
  90                   f.apply(a[i]));
  91             }
  92         } catch (AssertionError e) {
  93             byte[] ref = f.apply(a[i]);
  94             byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
  95             Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref)
  96               + ", res: " + Arrays.toString(res)
  97               + "), at index #" + i);
  98         }
  99     }
 100 
 101     static void assertArraysEquals(byte[] a, byte[] r, boolean[] mask, FUnOp f) {
 102         int i = 0;
 103         try {
 104             for (; i < a.length; i++) {
 105                 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]);
 106             }
 107         } catch (AssertionError e) {
 108             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()]);
 109         }
 110     }
 111 
 112     interface FReductionOp {
 113         byte apply(byte[] a, int idx);
 114     }
 115 
 116     interface FReductionAllOp {
 117         byte apply(byte[] a);
 118     }
 119 
 120     static void assertReductionArraysEquals(byte[] a, byte[] b, byte c,
 121                                             FReductionOp f, FReductionAllOp fa) {
 122         int i = 0;
 123         try {
 124             Assert.assertEquals(c, fa.apply(a));
 125             for (; i < a.length; i += SPECIES.length()) {
 126                 Assert.assertEquals(b[i], f.apply(a, i));
 127             }
 128         } catch (AssertionError e) {
 129             Assert.assertEquals(c, fa.apply(a), "Final result is incorrect!");
 130             Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i);
 131         }
 132     }
 133 
 134     interface FReductionMaskedOp {
 135         byte apply(byte[] a, int idx, boolean[] mask);
 136     }
 137 
 138     interface FReductionAllMaskedOp {
 139         byte apply(byte[] a, boolean[] mask);
 140     }
 141 
 142     static void assertReductionArraysEqualsMasked(byte[] a, byte[] b, byte c, boolean[] mask,
 143                                             FReductionMaskedOp f, FReductionAllMaskedOp fa) {
 144         int i = 0;
 145         try {
 146             Assert.assertEquals(c, fa.apply(a, mask));
 147             for (; i < a.length; i += SPECIES.length()) {
 148                 Assert.assertEquals(b[i], f.apply(a, i, mask));
 149             }
 150         } catch (AssertionError e) {
 151             Assert.assertEquals(c, fa.apply(a, mask), "Final result is incorrect!");
 152             Assert.assertEquals(b[i], f.apply(a, i, mask), "at index #" + i);
 153         }
 154     }
 155 
 156     interface FBoolReductionOp {
 157         boolean apply(boolean[] a, int idx);
 158     }
 159 
 160     static void assertReductionBoolArraysEquals(boolean[] a, boolean[] b, FBoolReductionOp f) {
 161         int i = 0;
 162         try {
 163             for (; i < a.length; i += SPECIES.length()) {
 164                 Assert.assertEquals(b[i], f.apply(a, i));
 165             }
 166         } catch (AssertionError e) {
 167             Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i);
 168         }
 169     }
 170 
 171     static void assertInsertArraysEquals(byte[] a, byte[] b, byte element, int index) {
 172         int i = 0;
 173         try {
 174             for (; i < a.length; i += 1) {
 175                 if(i%SPECIES.length() == index) {
 176                     Assert.assertEquals(b[i], element);
 177                 } else {
 178                     Assert.assertEquals(b[i], a[i]);
 179                 }
 180             }
 181         } catch (AssertionError e) {
 182             if (i%SPECIES.length() == index) {
 183                 Assert.assertEquals(b[i], element, "at index #" + i);
 184             } else {
 185                 Assert.assertEquals(b[i], a[i], "at index #" + i);
 186             }
 187         }
 188     }
 189 
 190     static void assertRearrangeArraysEquals(byte[] a, byte[] r, int[] order, int vector_len) {
 191         int i = 0, j = 0;
 192         try {
 193             for (; i < a.length; i += vector_len) {
 194                 for (j = 0; j < vector_len; j++) {
 195                     Assert.assertEquals(r[i+j], a[i+order[i+j]]);
 196                 }
 197             }
 198         } catch (AssertionError e) {
 199             int idx = i + j;
 200             Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
 201         }
 202     }
 203 
 204     static void assertBroadcastArraysEquals(byte[]a, byte[]r) {
 205         int i = 0;
 206         for (; i < a.length; i += SPECIES.length()) {
 207             int idx = i;
 208             for (int j = idx; j < (idx + SPECIES.length()); j++)
 209                 a[j]=a[idx];
 210         }
 211 
 212         try {
 213             for (i = 0; i < a.length; i++) {
 214                 Assert.assertEquals(r[i], a[i]);
 215             }
 216         } catch (AssertionError e) {
 217             Assert.assertEquals(r[i], a[i], "at index #" + i + ", input = " + a[i]);
 218         }
 219     }
 220 
 221     interface FBinOp {
 222         byte apply(byte a, byte b);
 223     }
 224 
 225     interface FBinMaskOp {
 226         byte apply(byte a, byte b, boolean m);
 227 
 228         static FBinMaskOp lift(FBinOp f) {
 229             return (a, b, m) -> m ? f.apply(a, b) : a;
 230         }
 231     }
 232 
 233     static void assertArraysEquals(byte[] a, byte[] b, byte[] r, FBinOp f) {
 234         int i = 0;
 235         try {
 236             for (; i < a.length; i++) {
 237                 Assert.assertEquals(r[i], f.apply(a[i], b[i]));
 238             }
 239         } catch (AssertionError e) {
 240             Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i);
 241         }
 242     }
 243 
 244     static void assertBroadcastArraysEquals(byte[] a, byte[] b, byte[] r, FBinOp f) {
 245         int i = 0;
 246         try {
 247             for (; i < a.length; i++) {
 248                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]));
 249             }
 250         } catch (AssertionError e) {
 251             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]),
 252                                 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i);
 253         }
 254     }
 255 
 256     static void assertArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) {
 257         assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 258     }
 259 
 260     static void assertArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) {
 261         int i = 0;
 262         try {
 263             for (; i < a.length; i++) {
 264                 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]));
 265             }
 266         } catch (AssertionError err) {
 267             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()]);
 268         }
 269     }
 270 
 271     static void assertBroadcastArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) {
 272         assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 273     }
 274 
 275     static void assertBroadcastArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) {
 276         int i = 0;
 277         try {
 278             for (; i < a.length; i++) {
 279                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]));
 280             }
 281         } catch (AssertionError err) {
 282             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 
 283                                 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 
 284                                 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
 285                                 mask[i % SPECIES.length()]);
 286         }
 287     }
 288 
 289     static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, FBinOp f) {
 290         int i = 0;
 291         int j = 0;
 292         try {
 293             for (; j < a.length; j += SPECIES.length()) {
 294                 for (i = 0; i < SPECIES.length(); i++) {
 295                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]));
 296                 }
 297             }
 298         } catch (AssertionError e) {
 299             Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j);
 300         }
 301     }
 302 
 303     static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) {
 304         assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 305     }
 306 
 307     static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) {
 308         int i = 0;
 309         int j = 0;
 310         try {
 311             for (; j < a.length; j += SPECIES.length()) {
 312                 for (i = 0; i < SPECIES.length(); i++) {
 313                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i]));
 314                 }
 315             }
 316         } catch (AssertionError err) {
 317             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]);
 318         }
 319     }
 320 
 321     interface FTernOp {
 322         byte apply(byte a, byte b, byte c);
 323     }
 324 
 325     interface FTernMaskOp {
 326         byte apply(byte a, byte b, byte c, boolean m);
 327 
 328         static FTernMaskOp lift(FTernOp f) {
 329             return (a, b, c, m) -> m ? f.apply(a, b, c) : a;
 330         }
 331     }
 332 
 333     static void assertArraysEquals(byte[] a, byte[] b, byte[] c, byte[] r, FTernOp f) {
 334         int i = 0;
 335         try {
 336             for (; i < a.length; i++) {
 337                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]));
 338             }
 339         } catch (AssertionError e) {
 340             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
 341         }
 342     }
 343 
 344     static void assertArraysEquals(byte[] a, byte[] b, byte[] c, byte[] r, boolean[] mask, FTernOp f) {
 345         assertArraysEquals(a, b, c, r, mask, FTernMaskOp.lift(f));
 346     }
 347 
 348     static void assertArraysEquals(byte[] a, byte[] b, byte[] c, byte[] r, boolean[] mask, FTernMaskOp f) {
 349         int i = 0;
 350         try {
 351             for (; i < a.length; i++) {
 352                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]));
 353             }
 354         } catch (AssertionError err) {
 355             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = "
 356               + b[i] + ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]);
 357         }
 358     }
 359 
 360 
 361     interface FBinArrayOp {
 362         byte apply(byte[] a, int b);
 363     }
 364 
 365     static void assertArraysEquals(byte[] a, byte[] r, FBinArrayOp f) {
 366         int i = 0;
 367         try {
 368             for (; i < a.length; i++) {
 369                 Assert.assertEquals(r[i], f.apply(a, i));
 370             }
 371         } catch (AssertionError e) {
 372             Assert.assertEquals(r[i], f.apply(a,i), "at index #" + i);
 373         }
 374     }
 375 
 376     interface FGatherScatterOp {
 377         byte[] apply(byte[] a, int ix, int[] b, int iy);
 378     }
 379 
 380     static void assertArraysEquals(byte[] a, int[] b, byte[] r, FGatherScatterOp f) {
 381         int i = 0;
 382         try {
 383             for (; i < a.length; i += SPECIES.length()) {
 384                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 385                   f.apply(a, i, b, i));
 386             }
 387         } catch (AssertionError e) {
 388             byte[] ref = f.apply(a, i, b, i);
 389             byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 390             Assert.assertEquals(res, ref,
 391               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 392               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 393               + ", b: "
 394               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 395               + " at index #" + i);
 396         }
 397     }
 398 
 399     interface FGatherMaskedOp {
 400         byte[] apply(byte[] a, int ix, boolean[] mask, int[] b, int iy);
 401     }
 402 
 403     interface FScatterMaskedOp {
 404         byte[] apply(byte[] r, byte[] a, int ix, boolean[] mask, int[] b, int iy);
 405     }
 406 
 407     static void assertArraysEquals(byte[] a, int[] b, byte[] r, boolean[] mask, FGatherMaskedOp f) {
 408         int i = 0;
 409         try {
 410             for (; i < a.length; i += SPECIES.length()) {
 411                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 412                   f.apply(a, i, mask, b, i));
 413             }
 414         } catch (AssertionError e) {
 415             byte[] ref = f.apply(a, i, mask, b, i);
 416             byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 417             Assert.assertEquals(ref, res,
 418               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 419               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 420               + ", b: "
 421               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 422               + ", mask: "
 423               + Arrays.toString(mask)
 424               + " at index #" + i);
 425         }
 426     }
 427 
 428     static void assertArraysEquals(byte[] a, int[] b, byte[] r, boolean[] mask, FScatterMaskedOp f) {
 429         int i = 0;
 430         try {
 431             for (; i < a.length; i += SPECIES.length()) {
 432                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 433                   f.apply(r, a, i, mask, b, i));
 434             }
 435         } catch (AssertionError e) {
 436             byte[] ref = f.apply(r, a, i, mask, b, i);
 437             byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 438             Assert.assertEquals(ref, res,
 439               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 440               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 441               + ", b: "
 442               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 443               + ", r: "
 444               + Arrays.toString(Arrays.copyOfRange(r, i, i+SPECIES.length()))
 445               + ", mask: "
 446               + Arrays.toString(mask)
 447               + " at index #" + i);
 448         }
 449     }
 450 
 451     interface FLaneOp {
 452         byte[] apply(byte[] a, int origin, int idx);
 453     }
 454 
 455     static void assertArraysEquals(byte[] a, byte[] r, int origin, FLaneOp f) {
 456         int i = 0;
 457         try {
 458             for (; i < a.length; i += SPECIES.length()) {
 459                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 460                   f.apply(a, origin, i));
 461             }
 462         } catch (AssertionError e) {
 463             byte[] ref = f.apply(a, origin, i);
 464             byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 465             Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref)
 466               + ", res: " + Arrays.toString(res)
 467               + "), at index #" + i);
 468         }
 469     }
 470 
 471     interface FLaneBop {
 472         byte[] apply(byte[] a, byte[] b, int origin, int idx);
 473     }
 474 
 475     static void assertArraysEquals(byte[] a, byte[] b, byte[] r, int origin, FLaneBop f) {
 476         int i = 0;
 477         try {
 478             for (; i < a.length; i += SPECIES.length()) {
 479                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 480                   f.apply(a, b, origin, i));
 481             }
 482         } catch (AssertionError e) {
 483             byte[] ref = f.apply(a, b, origin, i);
 484             byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 485             Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref)
 486               + ", res: " + Arrays.toString(res)
 487               + "), at index #" + i
 488               + ", at origin #" + origin);
 489         }
 490     }
 491 
 492     interface FLaneMaskedBop {
 493         byte[] apply(byte[] a, byte[] b, int origin, boolean[] mask, int idx);
 494     }
 495 
 496     static void assertArraysEquals(byte[] a, byte[] b, byte[] r, int origin, boolean[] mask, FLaneMaskedBop f) {
 497         int i = 0;
 498         try {
 499             for (; i < a.length; i += SPECIES.length()) {
 500                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 501                   f.apply(a, b, origin, mask, i));
 502             }
 503         } catch (AssertionError e) {
 504             byte[] ref = f.apply(a, b, origin, mask, i);
 505             byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 506             Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref)
 507               + ", res: " + Arrays.toString(res)
 508               + "), at index #" + i
 509               + ", at origin #" + origin);
 510         }
 511     }
 512 
 513     interface FLanePartBop {
 514         byte[] apply(byte[] a, byte[] b, int origin, int part, int idx);
 515     }
 516 
 517     static void assertArraysEquals(byte[] a, byte[] b, byte[] r, int origin, int part, FLanePartBop f) {
 518         int i = 0;
 519         try {
 520             for (; i < a.length; i += SPECIES.length()) {
 521                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 522                   f.apply(a, b, origin, part, i));
 523             }
 524         } catch (AssertionError e) {
 525             byte[] ref = f.apply(a, b, origin, part, i);
 526             byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 527             Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref)
 528               + ", res: " + Arrays.toString(res)
 529               + "), at index #" + i
 530               + ", at origin #" + origin
 531               + ", with part #" + part);
 532         }
 533     }
 534 
 535     interface FLanePartMaskedBop {
 536         byte[] apply(byte[] a, byte[] b, int origin, int part, boolean[] mask, int idx);
 537     }
 538 
 539     static void assertArraysEquals(byte[] a, byte[] b, byte[] r, int origin, int part, boolean[] mask, FLanePartMaskedBop f) {
 540         int i = 0;
 541         try {
 542             for (; i < a.length; i += SPECIES.length()) {
 543                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 544                   f.apply(a, b, origin, part, mask, i));
 545             }
 546         } catch (AssertionError e) {
 547             byte[] ref = f.apply(a, b, origin, part, mask, i);
 548             byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 549             Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref)
 550               + ", res: " + Arrays.toString(res)
 551               + "), at index #" + i
 552               + ", at origin #" + origin
 553               + ", with part #" + part);
 554         }
 555     }
 556 
 557     static byte bits(byte e) {
 558         return  e;
 559     }
 560 
 561     static final List<IntFunction<byte[]>> BYTE_GENERATORS = List.of(
 562             withToString("byte[-i * 5]", (int s) -> {
 563                 return fill(s * BUFFER_REPS,
 564                             i -> (byte)(-i * 5));
 565             }),
 566             withToString("byte[i * 5]", (int s) -> {
 567                 return fill(s * BUFFER_REPS,
 568                             i -> (byte)(i * 5));
 569             }),
 570             withToString("byte[i + 1]", (int s) -> {
 571                 return fill(s * BUFFER_REPS,
 572                             i -> (((byte)(i + 1) == 0) ? 1 : (byte)(i + 1)));
 573             }),
 574             withToString("byte[cornerCaseValue(i)]", (int s) -> {
 575                 return fill(s * BUFFER_REPS,
 576                             i -> cornerCaseValue(i));
 577             })
 578     );
 579 
 580     // Create combinations of pairs
 581     // @@@ Might be sensitive to order e.g. div by 0
 582     static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_PAIRS =
 583         Stream.of(BYTE_GENERATORS.get(0)).
 584                 flatMap(fa -> BYTE_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
 585                 collect(Collectors.toList());
 586 
 587     @DataProvider
 588     public Object[][] boolUnaryOpProvider() {
 589         return BOOL_ARRAY_GENERATORS.stream().
 590                 map(f -> new Object[]{f}).
 591                 toArray(Object[][]::new);
 592     }
 593 
 594     static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_TRIPLES =
 595         BYTE_GENERATOR_PAIRS.stream().
 596                 flatMap(pair -> BYTE_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))).
 597                 collect(Collectors.toList());
 598 
 599     @DataProvider
 600     public Object[][] byteBinaryOpProvider() {
 601         return BYTE_GENERATOR_PAIRS.stream().map(List::toArray).
 602                 toArray(Object[][]::new);
 603     }
 604 
 605     @DataProvider
 606     public Object[][] byteIndexedOpProvider() {
 607         return BYTE_GENERATOR_PAIRS.stream().map(List::toArray).
 608                 toArray(Object[][]::new);
 609     }
 610 
 611     @DataProvider
 612     public Object[][] byteBinaryOpMaskProvider() {
 613         return BOOLEAN_MASK_GENERATORS.stream().
 614                 flatMap(fm -> BYTE_GENERATOR_PAIRS.stream().map(lfa -> {
 615                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
 616                 })).
 617                 toArray(Object[][]::new);
 618     }
 619 
 620     @DataProvider
 621     public Object[][] byteTernaryOpProvider() {
 622         return BYTE_GENERATOR_TRIPLES.stream().map(List::toArray).
 623                 toArray(Object[][]::new);
 624     }
 625 
 626     @DataProvider
 627     public Object[][] byteTernaryOpMaskProvider() {
 628         return BOOLEAN_MASK_GENERATORS.stream().
 629                 flatMap(fm -> BYTE_GENERATOR_TRIPLES.stream().map(lfa -> {
 630                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
 631                 })).
 632                 toArray(Object[][]::new);
 633     }
 634 
 635     @DataProvider
 636     public Object[][] byteUnaryOpProvider() {
 637         return BYTE_GENERATORS.stream().
 638                 map(f -> new Object[]{f}).
 639                 toArray(Object[][]::new);
 640     }
 641 
 642     @DataProvider
 643     public Object[][] byteUnaryOpMaskProvider() {
 644         return BOOLEAN_MASK_GENERATORS.stream().
 645                 flatMap(fm -> BYTE_GENERATORS.stream().map(fa -> {
 646                     return new Object[] {fa, fm};
 647                 })).
 648                 toArray(Object[][]::new);
 649     }
 650 
 651     @DataProvider
 652     public Object[][] byteUnaryOpShuffleProvider() {
 653         return INT_SHUFFLE_GENERATORS.stream().
 654                 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> {
 655                     return new Object[] {fa, fs};
 656                 })).
 657                 toArray(Object[][]::new);
 658     }
 659 
 660     @DataProvider
 661     public Object[][] byteUnaryOpIndexProvider() {
 662         return INT_INDEX_GENERATORS.stream().
 663                 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> {
 664                     return new Object[] {fa, fs};
 665                 })).
 666                 toArray(Object[][]::new);
 667     }
 668 
 669     @DataProvider
 670     public Object[][] byteUnaryMaskedOpIndexProvider() {
 671         return BOOLEAN_MASK_GENERATORS.stream().
 672           flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm ->
 673             BYTE_GENERATORS.stream().map(fa -> {
 674                     return new Object[] {fa, fm, fs};
 675             }))).
 676             toArray(Object[][]::new);
 677     }
 678 
 679     @DataProvider
 680     public Object[][] scatterMaskedOpIndexProvider() {
 681         return BOOLEAN_MASK_GENERATORS.stream().
 682           flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm ->
 683             BYTE_GENERATORS.stream().flatMap(fn ->
 684               BYTE_GENERATORS.stream().map(fa -> {
 685                     return new Object[] {fa, fn, fm, fs};
 686             })))).
 687             toArray(Object[][]::new);
 688     }
 689 
 690     static final List<IntFunction<byte[]>> BYTE_COMPARE_GENERATORS = List.of(
 691             withToString("byte[i]", (int s) -> {
 692                 return fill(s * BUFFER_REPS,
 693                             i -> (byte)i);
 694             }),
 695             withToString("byte[i + 1]", (int s) -> {
 696                 return fill(s * BUFFER_REPS,
 697                             i -> (byte)(i + 1));
 698             }),
 699             withToString("byte[i - 2]", (int s) -> {
 700                 return fill(s * BUFFER_REPS,
 701                             i -> (byte)(i - 2));
 702             }),
 703             withToString("byte[zigZag(i)]", (int s) -> {
 704                 return fill(s * BUFFER_REPS,
 705                             i -> i%3 == 0 ? (byte)i : (i%3 == 1 ? (byte)(i + 1) : (byte)(i - 2)));
 706             }),
 707             withToString("byte[cornerCaseValue(i)]", (int s) -> {
 708                 return fill(s * BUFFER_REPS,
 709                             i -> cornerCaseValue(i));
 710             })
 711     );
 712 
 713     static final List<List<IntFunction<byte[]>>> BYTE_TEST_GENERATOR_ARGS =
 714         BYTE_COMPARE_GENERATORS.stream().
 715                 map(fa -> List.of(fa)).
 716                 collect(Collectors.toList());
 717 
 718     @DataProvider
 719     public Object[][] byteTestOpProvider() {
 720         return BYTE_TEST_GENERATOR_ARGS.stream().map(List::toArray).
 721                 toArray(Object[][]::new);
 722     }
 723 
 724     static final List<List<IntFunction<byte[]>>> BYTE_COMPARE_GENERATOR_PAIRS =
 725         BYTE_COMPARE_GENERATORS.stream().
 726                 flatMap(fa -> BYTE_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))).
 727                 collect(Collectors.toList());
 728 
 729     @DataProvider
 730     public Object[][] byteCompareOpProvider() {
 731         return BYTE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
 732                 toArray(Object[][]::new);
 733     }
 734 
 735     interface ToByteF {
 736         byte apply(int i);
 737     }
 738 
 739     static byte[] fill(int s , ToByteF f) {
 740         return fill(new byte[s], f);
 741     }
 742 
 743     static byte[] fill(byte[] a, ToByteF f) {
 744         for (int i = 0; i < a.length; i++) {
 745             a[i] = f.apply(i);
 746         }
 747         return a;
 748     }
 749 
 750     static byte cornerCaseValue(int i) {
 751         switch(i % 5) {
 752             case 0:
 753                 return Byte.MAX_VALUE;
 754             case 1:
 755                 return Byte.MIN_VALUE;
 756             case 2:
 757                 return Byte.MIN_VALUE;
 758             case 3:
 759                 return Byte.MAX_VALUE;
 760             default:
 761                 return (byte)0;
 762         }
 763     }
 764    static byte get(byte[] a, int i) {
 765        return (byte) a[i];
 766    }
 767 
 768    static final IntFunction<byte[]> fr = (vl) -> {
 769         int length = BUFFER_REPS * vl;
 770         return new byte[length];
 771     };
 772 
 773     static final IntFunction<boolean[]> fmr = (vl) -> {
 774         int length = BUFFER_REPS * vl;
 775         return new boolean[length];
 776     };
 777 
 778     static void replaceZero(byte[] a, byte v) {
 779         for (int i = 0; i < a.length; i++) {
 780             if (a[i] == 0) {
 781                 a[i] = v;
 782             }
 783         }
 784     }
 785 
 786     static void replaceZero(byte[] a, boolean[] mask, byte v) {
 787         for (int i = 0; i < a.length; i++) {
 788             if (mask[i % mask.length] && a[i] == 0) {
 789                 a[i] = v;
 790             }
 791         }
 792     }
 793 
 794     @Test
 795     static void smokeTest1() {
 796         ByteVector three = ByteVector.broadcast(SPECIES, (byte)-3);
 797         ByteVector three2 = (ByteVector) SPECIES.broadcast(-3);
 798         assert(three.eq(three2).allTrue());
 799         ByteVector three3 = three2.broadcast(1).broadcast(-3);
 800         assert(three.eq(three3).allTrue());
 801         int scale = 2;
 802         Class<?> ETYPE = byte.class;
 803         if (ETYPE == double.class || ETYPE == long.class)
 804             scale = 1000000;
 805         else if (ETYPE == byte.class && SPECIES.length() >= 64)
 806             scale = 1;
 807         ByteVector higher = three.addIndex(scale);
 808         VectorMask<Byte> m = three.compare(VectorOperators.LE, higher);
 809         assert(m.allTrue());
 810         m = higher.min((byte)-1).test(VectorOperators.IS_NEGATIVE);
 811         assert(m.allTrue());
 812         byte max = higher.reduceLanes(VectorOperators.MAX);
 813         assert(max == -3 + scale * (SPECIES.length()-1));
 814     }
 815 
 816     private static byte[]
 817     bothToArray(ByteVector a, ByteVector b) {
 818         byte[] r = new byte[a.length() + b.length()];
 819         a.intoArray(r, 0);
 820         b.intoArray(r, a.length());
 821         return r;
 822     }
 823 
 824     @Test
 825     static void smokeTest2() {
 826         // Do some zipping and shuffling.
 827         ByteVector io = (ByteVector) SPECIES.broadcast(0).addIndex(1);
 828         ByteVector io2 = (ByteVector) VectorShuffle.iota(SPECIES,0,1,false).toVector();
 829         Assert.assertEquals(io, io2);
 830         ByteVector a = io.add((byte)1); //[1,2]
 831         ByteVector b = a.neg();  //[-1,-2]
 832         byte[] abValues = bothToArray(a,b); //[1,2,-1,-2]
 833         VectorShuffle<Byte> zip0 = VectorShuffle.makeZip(SPECIES, 0);
 834         VectorShuffle<Byte> zip1 = VectorShuffle.makeZip(SPECIES, 1);
 835         ByteVector zab0 = a.rearrange(zip0,b); //[1,-1]
 836         ByteVector zab1 = a.rearrange(zip1,b); //[2,-2]
 837         byte[] zabValues = bothToArray(zab0, zab1); //[1,-1,2,-2]
 838         // manually zip
 839         byte[] manual = new byte[zabValues.length];
 840         for (int i = 0; i < manual.length; i += 2) {
 841             manual[i+0] = abValues[i/2];
 842             manual[i+1] = abValues[a.length() + i/2];
 843         }
 844         Assert.assertEquals(Arrays.toString(zabValues), Arrays.toString(manual));
 845         VectorShuffle<Byte> unz0 = VectorShuffle.makeUnzip(SPECIES, 0);
 846         VectorShuffle<Byte> unz1 = VectorShuffle.makeUnzip(SPECIES, 1);
 847         ByteVector uab0 = zab0.rearrange(unz0,zab1);
 848         ByteVector uab1 = zab0.rearrange(unz1,zab1);
 849         byte[] abValues1 = bothToArray(uab0, uab1);
 850         Assert.assertEquals(Arrays.toString(abValues), Arrays.toString(abValues1));
 851     }
 852 
 853     static void iotaShuffle() {
 854         ByteVector io = (ByteVector) SPECIES.broadcast(0).addIndex(1);
 855         ByteVector io2 = (ByteVector) VectorShuffle.iota(SPECIES, 0 , 1, false).toVector();
 856         Assert.assertEquals(io, io2);
 857     }
 858 
 859     @Test
 860     // Test all shuffle related operations.
 861     static void shuffleTest() {
 862         // To test backend instructions, make sure that C2 is used.
 863         for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) {
 864             iotaShuffle();
 865         }
 866     }
 867 
 868     @Test
 869     void viewAsIntegeralLanesTest() {
 870         Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes();
 871         Assert.assertEquals(asIntegral.species(), SPECIES);
 872     }
 873 
 874     @Test(expectedExceptions = UnsupportedOperationException.class)
 875     void viewAsFloatingLanesTest() {
 876         SPECIES.zero().viewAsFloatingLanes();
 877     }
 878 
 879     @Test
 880     // Test div by 0.
 881     static void bitwiseDivByZeroSmokeTest() {
 882         try {
 883             ByteVector a = (ByteVector) SPECIES.broadcast(0).addIndex(1);
 884             ByteVector b = (ByteVector) SPECIES.broadcast(0);
 885             a.div(b);
 886             Assert.fail();
 887         } catch (ArithmeticException e) {
 888         }
 889 
 890         try {
 891             ByteVector a = (ByteVector) SPECIES.broadcast(0).addIndex(1);
 892             ByteVector b = (ByteVector) SPECIES.broadcast(0);
 893             VectorMask<Byte> m = a.lt((byte) 1);
 894             a.div(b, m);
 895             Assert.fail();
 896         } catch (ArithmeticException e) {
 897         }
 898     }
 899     static byte ADD(byte a, byte b) {
 900         return (byte)(a + b);
 901     }
 902 
 903     @Test(dataProvider = "byteBinaryOpProvider")
 904     static void ADDByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 905         byte[] a = fa.apply(SPECIES.length());
 906         byte[] b = fb.apply(SPECIES.length());
 907         byte[] r = fr.apply(SPECIES.length());
 908 
 909         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 910             for (int i = 0; i < a.length; i += SPECIES.length()) {
 911                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 912                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 913                 av.lanewise(VectorOperators.ADD, bv).intoArray(r, i);
 914             }
 915         }
 916 
 917         assertArraysEquals(a, b, r, Byte128VectorTests::ADD);
 918     }
 919     static byte add(byte a, byte b) {
 920         return (byte)(a + b);
 921     }
 922 
 923     @Test(dataProvider = "byteBinaryOpProvider")
 924     static void addByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 925         byte[] a = fa.apply(SPECIES.length());
 926         byte[] b = fb.apply(SPECIES.length());
 927         byte[] r = fr.apply(SPECIES.length());
 928 
 929         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 930             for (int i = 0; i < a.length; i += SPECIES.length()) {
 931                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 932                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 933                 av.add(bv).intoArray(r, i);
 934             }
 935         }
 936 
 937         assertArraysEquals(a, b, r, Byte128VectorTests::add);
 938     }
 939 
 940     @Test(dataProvider = "byteBinaryOpMaskProvider")
 941     static void ADDByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 942                                           IntFunction<boolean[]> fm) {
 943         byte[] a = fa.apply(SPECIES.length());
 944         byte[] b = fb.apply(SPECIES.length());
 945         byte[] r = fr.apply(SPECIES.length());
 946         boolean[] mask = fm.apply(SPECIES.length());
 947         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
 948 
 949         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 950             for (int i = 0; i < a.length; i += SPECIES.length()) {
 951                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 952                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 953                 av.lanewise(VectorOperators.ADD, bv, vmask).intoArray(r, i);
 954             }
 955         }
 956 
 957         assertArraysEquals(a, b, r, mask, Byte128VectorTests::ADD);
 958     }
 959 
 960     @Test(dataProvider = "byteBinaryOpMaskProvider")
 961     static void addByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 962                                           IntFunction<boolean[]> fm) {
 963         byte[] a = fa.apply(SPECIES.length());
 964         byte[] b = fb.apply(SPECIES.length());
 965         byte[] r = fr.apply(SPECIES.length());
 966         boolean[] mask = fm.apply(SPECIES.length());
 967         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
 968 
 969         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 970             for (int i = 0; i < a.length; i += SPECIES.length()) {
 971                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 972                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 973                 av.add(bv, vmask).intoArray(r, i);
 974             }
 975         }
 976 
 977         assertArraysEquals(a, b, r, mask, Byte128VectorTests::add);
 978     }
 979     static byte SUB(byte a, byte b) {
 980         return (byte)(a - b);
 981     }
 982 
 983     @Test(dataProvider = "byteBinaryOpProvider")
 984     static void SUBByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 985         byte[] a = fa.apply(SPECIES.length());
 986         byte[] b = fb.apply(SPECIES.length());
 987         byte[] r = fr.apply(SPECIES.length());
 988 
 989         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 990             for (int i = 0; i < a.length; i += SPECIES.length()) {
 991                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 992                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 993                 av.lanewise(VectorOperators.SUB, bv).intoArray(r, i);
 994             }
 995         }
 996 
 997         assertArraysEquals(a, b, r, Byte128VectorTests::SUB);
 998     }
 999     static byte sub(byte a, byte b) {
1000         return (byte)(a - b);
1001     }
1002 
1003     @Test(dataProvider = "byteBinaryOpProvider")
1004     static void subByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1005         byte[] a = fa.apply(SPECIES.length());
1006         byte[] b = fb.apply(SPECIES.length());
1007         byte[] r = fr.apply(SPECIES.length());
1008 
1009         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1010             for (int i = 0; i < a.length; i += SPECIES.length()) {
1011                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1012                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1013                 av.sub(bv).intoArray(r, i);
1014             }
1015         }
1016 
1017         assertArraysEquals(a, b, r, Byte128VectorTests::sub);
1018     }
1019 
1020     @Test(dataProvider = "byteBinaryOpMaskProvider")
1021     static void SUBByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1022                                           IntFunction<boolean[]> fm) {
1023         byte[] a = fa.apply(SPECIES.length());
1024         byte[] b = fb.apply(SPECIES.length());
1025         byte[] r = fr.apply(SPECIES.length());
1026         boolean[] mask = fm.apply(SPECIES.length());
1027         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1028 
1029         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1030             for (int i = 0; i < a.length; i += SPECIES.length()) {
1031                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1032                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1033                 av.lanewise(VectorOperators.SUB, bv, vmask).intoArray(r, i);
1034             }
1035         }
1036 
1037         assertArraysEquals(a, b, r, mask, Byte128VectorTests::SUB);
1038     }
1039 
1040     @Test(dataProvider = "byteBinaryOpMaskProvider")
1041     static void subByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1042                                           IntFunction<boolean[]> fm) {
1043         byte[] a = fa.apply(SPECIES.length());
1044         byte[] b = fb.apply(SPECIES.length());
1045         byte[] r = fr.apply(SPECIES.length());
1046         boolean[] mask = fm.apply(SPECIES.length());
1047         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1048 
1049         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1050             for (int i = 0; i < a.length; i += SPECIES.length()) {
1051                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1052                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1053                 av.sub(bv, vmask).intoArray(r, i);
1054             }
1055         }
1056 
1057         assertArraysEquals(a, b, r, mask, Byte128VectorTests::sub);
1058     }
1059     static byte MUL(byte a, byte b) {
1060         return (byte)(a * b);
1061     }
1062 
1063     @Test(dataProvider = "byteBinaryOpProvider")
1064     static void MULByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1065         byte[] a = fa.apply(SPECIES.length());
1066         byte[] b = fb.apply(SPECIES.length());
1067         byte[] r = fr.apply(SPECIES.length());
1068 
1069         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1070             for (int i = 0; i < a.length; i += SPECIES.length()) {
1071                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1072                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1073                 av.lanewise(VectorOperators.MUL, bv).intoArray(r, i);
1074             }
1075         }
1076 
1077         assertArraysEquals(a, b, r, Byte128VectorTests::MUL);
1078     }
1079     static byte mul(byte a, byte b) {
1080         return (byte)(a * b);
1081     }
1082 
1083     @Test(dataProvider = "byteBinaryOpProvider")
1084     static void mulByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1085         byte[] a = fa.apply(SPECIES.length());
1086         byte[] b = fb.apply(SPECIES.length());
1087         byte[] r = fr.apply(SPECIES.length());
1088 
1089         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1090             for (int i = 0; i < a.length; i += SPECIES.length()) {
1091                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1092                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1093                 av.mul(bv).intoArray(r, i);
1094             }
1095         }
1096 
1097         assertArraysEquals(a, b, r, Byte128VectorTests::mul);
1098     }
1099 
1100     @Test(dataProvider = "byteBinaryOpMaskProvider")
1101     static void MULByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1102                                           IntFunction<boolean[]> fm) {
1103         byte[] a = fa.apply(SPECIES.length());
1104         byte[] b = fb.apply(SPECIES.length());
1105         byte[] r = fr.apply(SPECIES.length());
1106         boolean[] mask = fm.apply(SPECIES.length());
1107         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1108 
1109         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1110             for (int i = 0; i < a.length; i += SPECIES.length()) {
1111                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1112                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1113                 av.lanewise(VectorOperators.MUL, bv, vmask).intoArray(r, i);
1114             }
1115         }
1116 
1117         assertArraysEquals(a, b, r, mask, Byte128VectorTests::MUL);
1118     }
1119 
1120     @Test(dataProvider = "byteBinaryOpMaskProvider")
1121     static void mulByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1122                                           IntFunction<boolean[]> fm) {
1123         byte[] a = fa.apply(SPECIES.length());
1124         byte[] b = fb.apply(SPECIES.length());
1125         byte[] r = fr.apply(SPECIES.length());
1126         boolean[] mask = fm.apply(SPECIES.length());
1127         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1128 
1129         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1130             for (int i = 0; i < a.length; i += SPECIES.length()) {
1131                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1132                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1133                 av.mul(bv, vmask).intoArray(r, i);
1134             }
1135         }
1136 
1137         assertArraysEquals(a, b, r, mask, Byte128VectorTests::mul);
1138     }
1139 
1140 
1141 
1142     static byte DIV(byte a, byte b) {
1143         return (byte)(a / b);
1144     }
1145 
1146     @Test(dataProvider = "byteBinaryOpProvider")
1147     static void DIVByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1148         byte[] a = fa.apply(SPECIES.length());
1149         byte[] b = fb.apply(SPECIES.length());
1150         byte[] r = fr.apply(SPECIES.length());
1151 
1152         replaceZero(b, (byte) 1);
1153 
1154         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1155             for (int i = 0; i < a.length; i += SPECIES.length()) {
1156                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1157                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1158                 av.lanewise(VectorOperators.DIV, bv).intoArray(r, i);
1159             }
1160         }
1161 
1162         assertArraysEquals(a, b, r, Byte128VectorTests::DIV);
1163     }
1164     static byte div(byte a, byte b) {
1165         return (byte)(a / b);
1166     }
1167 
1168     @Test(dataProvider = "byteBinaryOpProvider")
1169     static void divByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1170         byte[] a = fa.apply(SPECIES.length());
1171         byte[] b = fb.apply(SPECIES.length());
1172         byte[] r = fr.apply(SPECIES.length());
1173 
1174         replaceZero(b, (byte) 1);
1175 
1176         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1177             for (int i = 0; i < a.length; i += SPECIES.length()) {
1178                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1179                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1180                 av.div(bv).intoArray(r, i);
1181             }
1182         }
1183 
1184         assertArraysEquals(a, b, r, Byte128VectorTests::div);
1185     }
1186 
1187 
1188 
1189     @Test(dataProvider = "byteBinaryOpMaskProvider")
1190     static void DIVByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1191                                           IntFunction<boolean[]> fm) {
1192         byte[] a = fa.apply(SPECIES.length());
1193         byte[] b = fb.apply(SPECIES.length());
1194         byte[] r = fr.apply(SPECIES.length());
1195         boolean[] mask = fm.apply(SPECIES.length());
1196         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1197 
1198         replaceZero(b, mask, (byte) 1);
1199 
1200         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1201             for (int i = 0; i < a.length; i += SPECIES.length()) {
1202                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1203                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1204                 av.lanewise(VectorOperators.DIV, bv, vmask).intoArray(r, i);
1205             }
1206         }
1207 
1208         assertArraysEquals(a, b, r, mask, Byte128VectorTests::DIV);
1209     }
1210 
1211     @Test(dataProvider = "byteBinaryOpMaskProvider")
1212     static void divByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1213                                           IntFunction<boolean[]> fm) {
1214         byte[] a = fa.apply(SPECIES.length());
1215         byte[] b = fb.apply(SPECIES.length());
1216         byte[] r = fr.apply(SPECIES.length());
1217         boolean[] mask = fm.apply(SPECIES.length());
1218         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1219 
1220         replaceZero(b, mask, (byte) 1);
1221 
1222         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1223             for (int i = 0; i < a.length; i += SPECIES.length()) {
1224                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1225                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1226                 av.div(bv, vmask).intoArray(r, i);
1227             }
1228         }
1229 
1230         assertArraysEquals(a, b, r, mask, Byte128VectorTests::div);
1231     }
1232 
1233     static byte FIRST_NONZERO(byte a, byte b) {
1234         return (byte)((a)!=0?a:b);
1235     }
1236 
1237     @Test(dataProvider = "byteBinaryOpProvider")
1238     static void FIRST_NONZEROByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1239         byte[] a = fa.apply(SPECIES.length());
1240         byte[] b = fb.apply(SPECIES.length());
1241         byte[] r = fr.apply(SPECIES.length());
1242 
1243         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1244             for (int i = 0; i < a.length; i += SPECIES.length()) {
1245                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1246                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1247                 av.lanewise(VectorOperators.FIRST_NONZERO, bv).intoArray(r, i);
1248             }
1249         }
1250 
1251         assertArraysEquals(a, b, r, Byte128VectorTests::FIRST_NONZERO);
1252     }
1253 
1254     @Test(dataProvider = "byteBinaryOpMaskProvider")
1255     static void FIRST_NONZEROByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1256                                           IntFunction<boolean[]> fm) {
1257         byte[] a = fa.apply(SPECIES.length());
1258         byte[] b = fb.apply(SPECIES.length());
1259         byte[] r = fr.apply(SPECIES.length());
1260         boolean[] mask = fm.apply(SPECIES.length());
1261         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1262 
1263         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1264             for (int i = 0; i < a.length; i += SPECIES.length()) {
1265                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1266                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1267                 av.lanewise(VectorOperators.FIRST_NONZERO, bv, vmask).intoArray(r, i);
1268             }
1269         }
1270 
1271         assertArraysEquals(a, b, r, mask, Byte128VectorTests::FIRST_NONZERO);
1272     }
1273 
1274     static byte AND(byte a, byte b) {
1275         return (byte)(a & b);
1276     }
1277 
1278     @Test(dataProvider = "byteBinaryOpProvider")
1279     static void ANDByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1280         byte[] a = fa.apply(SPECIES.length());
1281         byte[] b = fb.apply(SPECIES.length());
1282         byte[] r = fr.apply(SPECIES.length());
1283 
1284         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1285             for (int i = 0; i < a.length; i += SPECIES.length()) {
1286                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1287                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1288                 av.lanewise(VectorOperators.AND, bv).intoArray(r, i);
1289             }
1290         }
1291 
1292         assertArraysEquals(a, b, r, Byte128VectorTests::AND);
1293     }
1294     static byte and(byte a, byte b) {
1295         return (byte)(a & b);
1296     }
1297 
1298     @Test(dataProvider = "byteBinaryOpProvider")
1299     static void andByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1300         byte[] a = fa.apply(SPECIES.length());
1301         byte[] b = fb.apply(SPECIES.length());
1302         byte[] r = fr.apply(SPECIES.length());
1303 
1304         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1305             for (int i = 0; i < a.length; i += SPECIES.length()) {
1306                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1307                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1308                 av.and(bv).intoArray(r, i);
1309             }
1310         }
1311 
1312         assertArraysEquals(a, b, r, Byte128VectorTests::and);
1313     }
1314 
1315 
1316 
1317     @Test(dataProvider = "byteBinaryOpMaskProvider")
1318     static void ANDByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1319                                           IntFunction<boolean[]> fm) {
1320         byte[] a = fa.apply(SPECIES.length());
1321         byte[] b = fb.apply(SPECIES.length());
1322         byte[] r = fr.apply(SPECIES.length());
1323         boolean[] mask = fm.apply(SPECIES.length());
1324         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1325 
1326         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1327             for (int i = 0; i < a.length; i += SPECIES.length()) {
1328                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1329                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1330                 av.lanewise(VectorOperators.AND, bv, vmask).intoArray(r, i);
1331             }
1332         }
1333 
1334         assertArraysEquals(a, b, r, mask, Byte128VectorTests::AND);
1335     }
1336 
1337 
1338     static byte AND_NOT(byte a, byte b) {
1339         return (byte)(a & ~b);
1340     }
1341 
1342     @Test(dataProvider = "byteBinaryOpProvider")
1343     static void AND_NOTByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1344         byte[] a = fa.apply(SPECIES.length());
1345         byte[] b = fb.apply(SPECIES.length());
1346         byte[] r = fr.apply(SPECIES.length());
1347 
1348         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1349             for (int i = 0; i < a.length; i += SPECIES.length()) {
1350                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1351                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1352                 av.lanewise(VectorOperators.AND_NOT, bv).intoArray(r, i);
1353             }
1354         }
1355 
1356         assertArraysEquals(a, b, r, Byte128VectorTests::AND_NOT);
1357     }
1358 
1359 
1360 
1361     @Test(dataProvider = "byteBinaryOpMaskProvider")
1362     static void AND_NOTByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1363                                           IntFunction<boolean[]> fm) {
1364         byte[] a = fa.apply(SPECIES.length());
1365         byte[] b = fb.apply(SPECIES.length());
1366         byte[] r = fr.apply(SPECIES.length());
1367         boolean[] mask = fm.apply(SPECIES.length());
1368         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1369 
1370         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1371             for (int i = 0; i < a.length; i += SPECIES.length()) {
1372                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1373                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1374                 av.lanewise(VectorOperators.AND_NOT, bv, vmask).intoArray(r, i);
1375             }
1376         }
1377 
1378         assertArraysEquals(a, b, r, mask, Byte128VectorTests::AND_NOT);
1379     }
1380 
1381 
1382     static byte OR(byte a, byte b) {
1383         return (byte)(a | b);
1384     }
1385 
1386     @Test(dataProvider = "byteBinaryOpProvider")
1387     static void ORByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1388         byte[] a = fa.apply(SPECIES.length());
1389         byte[] b = fb.apply(SPECIES.length());
1390         byte[] r = fr.apply(SPECIES.length());
1391 
1392         for (int ic = 0; ic < INVOC_COUNT; ic++) {
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.lanewise(VectorOperators.OR, bv).intoArray(r, i);
1397             }
1398         }
1399 
1400         assertArraysEquals(a, b, r, Byte128VectorTests::OR);
1401     }
1402     static byte or(byte a, byte b) {
1403         return (byte)(a | b);
1404     }
1405 
1406     @Test(dataProvider = "byteBinaryOpProvider")
1407     static void orByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1408         byte[] a = fa.apply(SPECIES.length());
1409         byte[] b = fb.apply(SPECIES.length());
1410         byte[] r = fr.apply(SPECIES.length());
1411 
1412         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1413             for (int i = 0; i < a.length; i += SPECIES.length()) {
1414                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1415                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1416                 av.or(bv).intoArray(r, i);
1417             }
1418         }
1419 
1420         assertArraysEquals(a, b, r, Byte128VectorTests::or);
1421     }
1422 
1423 
1424 
1425     @Test(dataProvider = "byteBinaryOpMaskProvider")
1426     static void ORByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1427                                           IntFunction<boolean[]> fm) {
1428         byte[] a = fa.apply(SPECIES.length());
1429         byte[] b = fb.apply(SPECIES.length());
1430         byte[] r = fr.apply(SPECIES.length());
1431         boolean[] mask = fm.apply(SPECIES.length());
1432         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1433 
1434         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1435             for (int i = 0; i < a.length; i += SPECIES.length()) {
1436                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1437                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1438                 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i);
1439             }
1440         }
1441 
1442         assertArraysEquals(a, b, r, mask, Byte128VectorTests::OR);
1443     }
1444 
1445 
1446     static byte XOR(byte a, byte b) {
1447         return (byte)(a ^ b);
1448     }
1449 
1450     @Test(dataProvider = "byteBinaryOpProvider")
1451     static void XORByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1452         byte[] a = fa.apply(SPECIES.length());
1453         byte[] b = fb.apply(SPECIES.length());
1454         byte[] r = fr.apply(SPECIES.length());
1455 
1456         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1457             for (int i = 0; i < a.length; i += SPECIES.length()) {
1458                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1459                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1460                 av.lanewise(VectorOperators.XOR, bv).intoArray(r, i);
1461             }
1462         }
1463 
1464         assertArraysEquals(a, b, r, Byte128VectorTests::XOR);
1465     }
1466 
1467 
1468 
1469     @Test(dataProvider = "byteBinaryOpMaskProvider")
1470     static void XORByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1471                                           IntFunction<boolean[]> fm) {
1472         byte[] a = fa.apply(SPECIES.length());
1473         byte[] b = fb.apply(SPECIES.length());
1474         byte[] r = fr.apply(SPECIES.length());
1475         boolean[] mask = fm.apply(SPECIES.length());
1476         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1477 
1478         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1479             for (int i = 0; i < a.length; i += SPECIES.length()) {
1480                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1481                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1482                 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i);
1483             }
1484         }
1485 
1486         assertArraysEquals(a, b, r, mask, Byte128VectorTests::XOR);
1487     }
1488 
1489 
1490     @Test(dataProvider = "byteBinaryOpProvider")
1491     static void addByte128VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1492         byte[] a = fa.apply(SPECIES.length());
1493         byte[] b = fb.apply(SPECIES.length());
1494         byte[] r = fr.apply(SPECIES.length());
1495 
1496         for (int i = 0; i < a.length; i += SPECIES.length()) {
1497             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1498             av.add(b[i]).intoArray(r, i);
1499         }
1500 
1501         assertBroadcastArraysEquals(a, b, r, Byte128VectorTests::add);
1502     }
1503 
1504     @Test(dataProvider = "byteBinaryOpMaskProvider")
1505     static void addByte128VectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1506                                           IntFunction<boolean[]> fm) {
1507         byte[] a = fa.apply(SPECIES.length());
1508         byte[] b = fb.apply(SPECIES.length());
1509         byte[] r = fr.apply(SPECIES.length());
1510         boolean[] mask = fm.apply(SPECIES.length());
1511         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1512 
1513         for (int i = 0; i < a.length; i += SPECIES.length()) {
1514             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1515             av.add(b[i], vmask).intoArray(r, i);
1516         }
1517 
1518         assertBroadcastArraysEquals(a, b, r, mask, Byte128VectorTests::add);
1519     }
1520 
1521     @Test(dataProvider = "byteBinaryOpProvider")
1522     static void subByte128VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1523         byte[] a = fa.apply(SPECIES.length());
1524         byte[] b = fb.apply(SPECIES.length());
1525         byte[] r = fr.apply(SPECIES.length());
1526 
1527         for (int i = 0; i < a.length; i += SPECIES.length()) {
1528             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1529             av.sub(b[i]).intoArray(r, i);
1530         }
1531 
1532         assertBroadcastArraysEquals(a, b, r, Byte128VectorTests::sub);
1533     }
1534 
1535     @Test(dataProvider = "byteBinaryOpMaskProvider")
1536     static void subByte128VectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1537                                           IntFunction<boolean[]> fm) {
1538         byte[] a = fa.apply(SPECIES.length());
1539         byte[] b = fb.apply(SPECIES.length());
1540         byte[] r = fr.apply(SPECIES.length());
1541         boolean[] mask = fm.apply(SPECIES.length());
1542         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1543 
1544         for (int i = 0; i < a.length; i += SPECIES.length()) {
1545             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1546             av.sub(b[i], vmask).intoArray(r, i);
1547         }
1548 
1549         assertBroadcastArraysEquals(a, b, r, mask, Byte128VectorTests::sub);
1550     }
1551 
1552     @Test(dataProvider = "byteBinaryOpProvider")
1553     static void mulByte128VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1554         byte[] a = fa.apply(SPECIES.length());
1555         byte[] b = fb.apply(SPECIES.length());
1556         byte[] r = fr.apply(SPECIES.length());
1557 
1558         for (int i = 0; i < a.length; i += SPECIES.length()) {
1559             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1560             av.mul(b[i]).intoArray(r, i);
1561         }
1562 
1563         assertBroadcastArraysEquals(a, b, r, Byte128VectorTests::mul);
1564     }
1565 
1566     @Test(dataProvider = "byteBinaryOpMaskProvider")
1567     static void mulByte128VectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1568                                           IntFunction<boolean[]> fm) {
1569         byte[] a = fa.apply(SPECIES.length());
1570         byte[] b = fb.apply(SPECIES.length());
1571         byte[] r = fr.apply(SPECIES.length());
1572         boolean[] mask = fm.apply(SPECIES.length());
1573         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1574 
1575         for (int i = 0; i < a.length; i += SPECIES.length()) {
1576             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1577             av.mul(b[i], vmask).intoArray(r, i);
1578         }
1579 
1580         assertBroadcastArraysEquals(a, b, r, mask, Byte128VectorTests::mul);
1581     }
1582 
1583 
1584 
1585 
1586     @Test(dataProvider = "byteBinaryOpProvider")
1587     static void divByte128VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1588         byte[] a = fa.apply(SPECIES.length());
1589         byte[] b = fb.apply(SPECIES.length());
1590         byte[] r = fr.apply(SPECIES.length());
1591 
1592         replaceZero(b, (byte) 1);
1593 
1594         for (int i = 0; i < a.length; i += SPECIES.length()) {
1595             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1596             av.div(b[i]).intoArray(r, i);
1597         }
1598 
1599         assertBroadcastArraysEquals(a, b, r, Byte128VectorTests::div);
1600     }
1601 
1602 
1603 
1604     @Test(dataProvider = "byteBinaryOpMaskProvider")
1605     static void divByte128VectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1606                                           IntFunction<boolean[]> fm) {
1607         byte[] a = fa.apply(SPECIES.length());
1608         byte[] b = fb.apply(SPECIES.length());
1609         byte[] r = fr.apply(SPECIES.length());
1610         boolean[] mask = fm.apply(SPECIES.length());
1611         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1612 
1613         replaceZero(b, (byte) 1);
1614 
1615        for (int i = 0; i < a.length; i += SPECIES.length()) {
1616            ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1617            av.div(b[i], vmask).intoArray(r, i);
1618        }
1619 
1620         assertBroadcastArraysEquals(a, b, r, mask, Byte128VectorTests::div);
1621     }
1622 
1623 
1624 
1625     @Test(dataProvider = "byteBinaryOpProvider")
1626     static void ORByte128VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1627         byte[] a = fa.apply(SPECIES.length());
1628         byte[] b = fb.apply(SPECIES.length());
1629         byte[] r = fr.apply(SPECIES.length());
1630 
1631         for (int i = 0; i < a.length; i += SPECIES.length()) {
1632             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1633             av.lanewise(VectorOperators.OR, b[i]).intoArray(r, i);
1634         }
1635 
1636         assertBroadcastArraysEquals(a, b, r, Byte128VectorTests::OR);
1637     }
1638 
1639     @Test(dataProvider = "byteBinaryOpProvider")
1640     static void orByte128VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1641         byte[] a = fa.apply(SPECIES.length());
1642         byte[] b = fb.apply(SPECIES.length());
1643         byte[] r = fr.apply(SPECIES.length());
1644 
1645         for (int i = 0; i < a.length; i += SPECIES.length()) {
1646             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1647             av.or(b[i]).intoArray(r, i);
1648         }
1649 
1650         assertBroadcastArraysEquals(a, b, r, Byte128VectorTests::or);
1651     }
1652 
1653 
1654 
1655     @Test(dataProvider = "byteBinaryOpMaskProvider")
1656     static void ORByte128VectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1657                                           IntFunction<boolean[]> fm) {
1658         byte[] a = fa.apply(SPECIES.length());
1659         byte[] b = fb.apply(SPECIES.length());
1660         byte[] r = fr.apply(SPECIES.length());
1661         boolean[] mask = fm.apply(SPECIES.length());
1662         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1663 
1664         for (int i = 0; i < a.length; i += SPECIES.length()) {
1665             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1666             av.lanewise(VectorOperators.OR, b[i], vmask).intoArray(r, i);
1667         }
1668 
1669         assertBroadcastArraysEquals(a, b, r, mask, Byte128VectorTests::OR);
1670     }
1671 
1672 
1673 
1674 
1675     static byte LSHL(byte a, byte b) {
1676         return (byte)((a << (b & 0x7)));
1677     }
1678 
1679     @Test(dataProvider = "byteBinaryOpProvider")
1680     static void LSHLByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1681         byte[] a = fa.apply(SPECIES.length());
1682         byte[] b = fb.apply(SPECIES.length());
1683         byte[] r = fr.apply(SPECIES.length());
1684 
1685         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1686             for (int i = 0; i < a.length; i += SPECIES.length()) {
1687                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1688                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1689                 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i);
1690             }
1691         }
1692 
1693         assertArraysEquals(a, b, r, Byte128VectorTests::LSHL);
1694     }
1695 
1696 
1697 
1698     @Test(dataProvider = "byteBinaryOpMaskProvider")
1699     static void LSHLByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1700                                           IntFunction<boolean[]> fm) {
1701         byte[] a = fa.apply(SPECIES.length());
1702         byte[] b = fb.apply(SPECIES.length());
1703         byte[] r = fr.apply(SPECIES.length());
1704         boolean[] mask = fm.apply(SPECIES.length());
1705         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1706 
1707         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1708             for (int i = 0; i < a.length; i += SPECIES.length()) {
1709                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1710                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1711                 av.lanewise(VectorOperators.LSHL, bv, vmask).intoArray(r, i);
1712             }
1713         }
1714 
1715         assertArraysEquals(a, b, r, mask, Byte128VectorTests::LSHL);
1716     }
1717 
1718 
1719 
1720 
1721 
1722 
1723     static byte ASHR(byte a, byte b) {
1724         return (byte)((a >> (b & 0x7)));
1725     }
1726 
1727     @Test(dataProvider = "byteBinaryOpProvider")
1728     static void ASHRByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1729         byte[] a = fa.apply(SPECIES.length());
1730         byte[] b = fb.apply(SPECIES.length());
1731         byte[] r = fr.apply(SPECIES.length());
1732 
1733         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1734             for (int i = 0; i < a.length; i += SPECIES.length()) {
1735                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1736                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1737                 av.lanewise(VectorOperators.ASHR, bv).intoArray(r, i);
1738             }
1739         }
1740 
1741         assertArraysEquals(a, b, r, Byte128VectorTests::ASHR);
1742     }
1743 
1744 
1745 
1746     @Test(dataProvider = "byteBinaryOpMaskProvider")
1747     static void ASHRByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1748                                           IntFunction<boolean[]> fm) {
1749         byte[] a = fa.apply(SPECIES.length());
1750         byte[] b = fb.apply(SPECIES.length());
1751         byte[] r = fr.apply(SPECIES.length());
1752         boolean[] mask = fm.apply(SPECIES.length());
1753         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1754 
1755         for (int ic = 0; ic < INVOC_COUNT; ic++) {
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.lanewise(VectorOperators.ASHR, bv, vmask).intoArray(r, i);
1760             }
1761         }
1762 
1763         assertArraysEquals(a, b, r, mask, Byte128VectorTests::ASHR);
1764     }
1765 
1766 
1767 
1768 
1769 
1770 
1771     static byte LSHR(byte a, byte b) {
1772         return (byte)(((a & 0xFF) >>> (b & 0x7)));
1773     }
1774 
1775     @Test(dataProvider = "byteBinaryOpProvider")
1776     static void LSHRByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1777         byte[] a = fa.apply(SPECIES.length());
1778         byte[] b = fb.apply(SPECIES.length());
1779         byte[] r = fr.apply(SPECIES.length());
1780 
1781         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1782             for (int i = 0; i < a.length; i += SPECIES.length()) {
1783                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1784                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1785                 av.lanewise(VectorOperators.LSHR, bv).intoArray(r, i);
1786             }
1787         }
1788 
1789         assertArraysEquals(a, b, r, Byte128VectorTests::LSHR);
1790     }
1791 
1792 
1793 
1794     @Test(dataProvider = "byteBinaryOpMaskProvider")
1795     static void LSHRByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1796                                           IntFunction<boolean[]> fm) {
1797         byte[] a = fa.apply(SPECIES.length());
1798         byte[] b = fb.apply(SPECIES.length());
1799         byte[] r = fr.apply(SPECIES.length());
1800         boolean[] mask = fm.apply(SPECIES.length());
1801         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1802 
1803         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1804             for (int i = 0; i < a.length; i += SPECIES.length()) {
1805                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1806                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1807                 av.lanewise(VectorOperators.LSHR, bv, vmask).intoArray(r, i);
1808             }
1809         }
1810 
1811         assertArraysEquals(a, b, r, mask, Byte128VectorTests::LSHR);
1812     }
1813 
1814 
1815 
1816 
1817 
1818 
1819     static byte LSHL_unary(byte a, byte b) {
1820         return (byte)((a << (b & 7)));
1821     }
1822 
1823     @Test(dataProvider = "byteBinaryOpProvider")
1824     static void LSHLByte128VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1825         byte[] a = fa.apply(SPECIES.length());
1826         byte[] b = fb.apply(SPECIES.length());
1827         byte[] r = fr.apply(SPECIES.length());
1828 
1829         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1830             for (int i = 0; i < a.length; i += SPECIES.length()) {
1831                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1832                 av.lanewise(VectorOperators.LSHL, (int)b[i]).intoArray(r, i);
1833             }
1834         }
1835 
1836         assertShiftArraysEquals(a, b, r, Byte128VectorTests::LSHL_unary);
1837     }
1838 
1839 
1840 
1841     @Test(dataProvider = "byteBinaryOpMaskProvider")
1842     static void LSHLByte128VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1843                                           IntFunction<boolean[]> fm) {
1844         byte[] a = fa.apply(SPECIES.length());
1845         byte[] b = fb.apply(SPECIES.length());
1846         byte[] r = fr.apply(SPECIES.length());
1847         boolean[] mask = fm.apply(SPECIES.length());
1848         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1849 
1850         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1851             for (int i = 0; i < a.length; i += SPECIES.length()) {
1852                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1853                 av.lanewise(VectorOperators.LSHL, (int)b[i], vmask).intoArray(r, i);
1854             }
1855         }
1856 
1857         assertShiftArraysEquals(a, b, r, mask, Byte128VectorTests::LSHL_unary);
1858     }
1859 
1860 
1861 
1862 
1863 
1864 
1865     static byte LSHR_unary(byte a, byte b) {
1866         return (byte)(((a & 0xFF) >>> (b & 7)));
1867     }
1868 
1869     @Test(dataProvider = "byteBinaryOpProvider")
1870     static void LSHRByte128VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1871         byte[] a = fa.apply(SPECIES.length());
1872         byte[] b = fb.apply(SPECIES.length());
1873         byte[] r = fr.apply(SPECIES.length());
1874 
1875         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1876             for (int i = 0; i < a.length; i += SPECIES.length()) {
1877                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1878                 av.lanewise(VectorOperators.LSHR, (int)b[i]).intoArray(r, i);
1879             }
1880         }
1881 
1882         assertShiftArraysEquals(a, b, r, Byte128VectorTests::LSHR_unary);
1883     }
1884 
1885 
1886 
1887     @Test(dataProvider = "byteBinaryOpMaskProvider")
1888     static void LSHRByte128VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1889                                           IntFunction<boolean[]> fm) {
1890         byte[] a = fa.apply(SPECIES.length());
1891         byte[] b = fb.apply(SPECIES.length());
1892         byte[] r = fr.apply(SPECIES.length());
1893         boolean[] mask = fm.apply(SPECIES.length());
1894         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1895 
1896         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1897             for (int i = 0; i < a.length; i += SPECIES.length()) {
1898                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1899                 av.lanewise(VectorOperators.LSHR, (int)b[i], vmask).intoArray(r, i);
1900             }
1901         }
1902 
1903         assertShiftArraysEquals(a, b, r, mask, Byte128VectorTests::LSHR_unary);
1904     }
1905 
1906 
1907 
1908 
1909 
1910 
1911     static byte ASHR_unary(byte a, byte b) {
1912         return (byte)((a >> (b & 7)));
1913     }
1914 
1915     @Test(dataProvider = "byteBinaryOpProvider")
1916     static void ASHRByte128VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1917         byte[] a = fa.apply(SPECIES.length());
1918         byte[] b = fb.apply(SPECIES.length());
1919         byte[] r = fr.apply(SPECIES.length());
1920 
1921         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1922             for (int i = 0; i < a.length; i += SPECIES.length()) {
1923                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1924                 av.lanewise(VectorOperators.ASHR, (int)b[i]).intoArray(r, i);
1925             }
1926         }
1927 
1928         assertShiftArraysEquals(a, b, r, Byte128VectorTests::ASHR_unary);
1929     }
1930 
1931 
1932 
1933     @Test(dataProvider = "byteBinaryOpMaskProvider")
1934     static void ASHRByte128VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1935                                           IntFunction<boolean[]> fm) {
1936         byte[] a = fa.apply(SPECIES.length());
1937         byte[] b = fb.apply(SPECIES.length());
1938         byte[] r = fr.apply(SPECIES.length());
1939         boolean[] mask = fm.apply(SPECIES.length());
1940         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1941 
1942         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1943             for (int i = 0; i < a.length; i += SPECIES.length()) {
1944                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1945                 av.lanewise(VectorOperators.ASHR, (int)b[i], vmask).intoArray(r, i);
1946             }
1947         }
1948 
1949         assertShiftArraysEquals(a, b, r, mask, Byte128VectorTests::ASHR_unary);
1950     }
1951 
1952 
1953 
1954     static byte MIN(byte a, byte b) {
1955         return (byte)(Math.min(a, b));
1956     }
1957 
1958     @Test(dataProvider = "byteBinaryOpProvider")
1959     static void MINByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1960         byte[] a = fa.apply(SPECIES.length());
1961         byte[] b = fb.apply(SPECIES.length());
1962         byte[] r = fr.apply(SPECIES.length());
1963 
1964         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1965             for (int i = 0; i < a.length; i += SPECIES.length()) {
1966                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1967                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1968                 av.lanewise(VectorOperators.MIN, bv).intoArray(r, i);
1969             }
1970         }
1971 
1972         assertArraysEquals(a, b, r, Byte128VectorTests::MIN);
1973     }
1974     static byte min(byte a, byte b) {
1975         return (byte)(Math.min(a, b));
1976     }
1977 
1978     @Test(dataProvider = "byteBinaryOpProvider")
1979     static void minByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1980         byte[] a = fa.apply(SPECIES.length());
1981         byte[] b = fb.apply(SPECIES.length());
1982         byte[] r = fr.apply(SPECIES.length());
1983 
1984         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1985             for (int i = 0; i < a.length; i += SPECIES.length()) {
1986                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1987                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1988                 av.min(bv).intoArray(r, i);
1989             }
1990         }
1991 
1992         assertArraysEquals(a, b, r, Byte128VectorTests::min);
1993     }
1994     static byte MAX(byte a, byte b) {
1995         return (byte)(Math.max(a, b));
1996     }
1997 
1998     @Test(dataProvider = "byteBinaryOpProvider")
1999     static void MAXByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2000         byte[] a = fa.apply(SPECIES.length());
2001         byte[] b = fb.apply(SPECIES.length());
2002         byte[] r = fr.apply(SPECIES.length());
2003 
2004         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2005             for (int i = 0; i < a.length; i += SPECIES.length()) {
2006                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2007                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2008                 av.lanewise(VectorOperators.MAX, bv).intoArray(r, i);
2009             }
2010         }
2011 
2012         assertArraysEquals(a, b, r, Byte128VectorTests::MAX);
2013     }
2014     static byte max(byte a, byte b) {
2015         return (byte)(Math.max(a, b));
2016     }
2017 
2018     @Test(dataProvider = "byteBinaryOpProvider")
2019     static void maxByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2020         byte[] a = fa.apply(SPECIES.length());
2021         byte[] b = fb.apply(SPECIES.length());
2022         byte[] r = fr.apply(SPECIES.length());
2023 
2024         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2025             for (int i = 0; i < a.length; i += SPECIES.length()) {
2026                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2027                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2028                 av.max(bv).intoArray(r, i);
2029             }
2030         }
2031 
2032         assertArraysEquals(a, b, r, Byte128VectorTests::max);
2033     }
2034 
2035     @Test(dataProvider = "byteBinaryOpProvider")
2036     static void MINByte128VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2037         byte[] a = fa.apply(SPECIES.length());
2038         byte[] b = fb.apply(SPECIES.length());
2039         byte[] r = fr.apply(SPECIES.length());
2040 
2041         for (int i = 0; i < a.length; i += SPECIES.length()) {
2042             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2043             av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i);
2044         }
2045 
2046         assertBroadcastArraysEquals(a, b, r, Byte128VectorTests::MIN);
2047     }
2048 
2049     @Test(dataProvider = "byteBinaryOpProvider")
2050     static void minByte128VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2051         byte[] a = fa.apply(SPECIES.length());
2052         byte[] b = fb.apply(SPECIES.length());
2053         byte[] r = fr.apply(SPECIES.length());
2054 
2055         for (int i = 0; i < a.length; i += SPECIES.length()) {
2056             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2057             av.min(b[i]).intoArray(r, i);
2058         }
2059 
2060         assertBroadcastArraysEquals(a, b, r, Byte128VectorTests::min);
2061     }
2062 
2063     @Test(dataProvider = "byteBinaryOpProvider")
2064     static void MAXByte128VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2065         byte[] a = fa.apply(SPECIES.length());
2066         byte[] b = fb.apply(SPECIES.length());
2067         byte[] r = fr.apply(SPECIES.length());
2068 
2069         for (int i = 0; i < a.length; i += SPECIES.length()) {
2070             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2071             av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i);
2072         }
2073 
2074         assertBroadcastArraysEquals(a, b, r, Byte128VectorTests::MAX);
2075     }
2076 
2077     @Test(dataProvider = "byteBinaryOpProvider")
2078     static void maxByte128VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2079         byte[] a = fa.apply(SPECIES.length());
2080         byte[] b = fb.apply(SPECIES.length());
2081         byte[] r = fr.apply(SPECIES.length());
2082 
2083         for (int i = 0; i < a.length; i += SPECIES.length()) {
2084             ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2085             av.max(b[i]).intoArray(r, i);
2086         }
2087 
2088         assertBroadcastArraysEquals(a, b, r, Byte128VectorTests::max);
2089     }
2090 
2091     static byte AND(byte[] a, int idx) {
2092         byte res = -1;
2093         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2094             res &= a[i];
2095         }
2096 
2097         return res;
2098     }
2099 
2100     static byte AND(byte[] a) {
2101         byte res = -1;
2102         for (int i = 0; i < a.length; i += SPECIES.length()) {
2103             byte tmp = -1;
2104             for (int j = 0; j < SPECIES.length(); j++) {
2105                 tmp &= a[i + j];
2106             }
2107             res &= tmp;
2108         }
2109 
2110         return res;
2111     }
2112 
2113 
2114     @Test(dataProvider = "byteUnaryOpProvider")
2115     static void ANDByte128VectorTests(IntFunction<byte[]> fa) {
2116         byte[] a = fa.apply(SPECIES.length());
2117         byte[] r = fr.apply(SPECIES.length());
2118         byte ra = -1;
2119 
2120         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2121             for (int i = 0; i < a.length; i += SPECIES.length()) {
2122                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2123                 r[i] = av.reduceLanes(VectorOperators.AND);
2124             }
2125         }
2126 
2127         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2128             ra = -1;
2129             for (int i = 0; i < a.length; i += SPECIES.length()) {
2130                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2131                 ra &= av.reduceLanes(VectorOperators.AND);
2132             }
2133         }
2134 
2135         assertReductionArraysEquals(a, r, ra, Byte128VectorTests::AND, Byte128VectorTests::AND);
2136     }
2137 
2138 
2139     static byte ANDMasked(byte[] a, int idx, boolean[] mask) {
2140         byte res = -1;
2141         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2142             if(mask[i % SPECIES.length()])
2143                 res &= a[i];
2144         }
2145 
2146         return res;
2147     }
2148 
2149     static byte ANDMasked(byte[] a, boolean[] mask) {
2150         byte res = -1;
2151         for (int i = 0; i < a.length; i += SPECIES.length()) {
2152             byte tmp = -1;
2153             for (int j = 0; j < SPECIES.length(); j++) {
2154                 if(mask[(i + j) % SPECIES.length()])
2155                     tmp &= a[i + j];
2156             }
2157             res &= tmp;
2158         }
2159 
2160         return res;
2161     }
2162 
2163 
2164     @Test(dataProvider = "byteUnaryOpMaskProvider")
2165     static void ANDByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
2166         byte[] a = fa.apply(SPECIES.length());
2167         byte[] r = fr.apply(SPECIES.length());
2168         boolean[] mask = fm.apply(SPECIES.length());
2169         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2170         byte ra = -1;
2171 
2172         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2173             for (int i = 0; i < a.length; i += SPECIES.length()) {
2174                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2175                 r[i] = av.reduceLanes(VectorOperators.AND, vmask);
2176             }
2177         }
2178 
2179         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2180             ra = -1;
2181             for (int i = 0; i < a.length; i += SPECIES.length()) {
2182                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2183                 ra &= av.reduceLanes(VectorOperators.AND, vmask);
2184             }
2185         }
2186 
2187         assertReductionArraysEqualsMasked(a, r, ra, mask, Byte128VectorTests::ANDMasked, Byte128VectorTests::ANDMasked);
2188     }
2189 
2190 
2191     static byte OR(byte[] a, int idx) {
2192         byte res = 0;
2193         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2194             res |= a[i];
2195         }
2196 
2197         return res;
2198     }
2199 
2200     static byte OR(byte[] a) {
2201         byte res = 0;
2202         for (int i = 0; i < a.length; i += SPECIES.length()) {
2203             byte tmp = 0;
2204             for (int j = 0; j < SPECIES.length(); j++) {
2205                 tmp |= a[i + j];
2206             }
2207             res |= tmp;
2208         }
2209 
2210         return res;
2211     }
2212 
2213 
2214     @Test(dataProvider = "byteUnaryOpProvider")
2215     static void ORByte128VectorTests(IntFunction<byte[]> fa) {
2216         byte[] a = fa.apply(SPECIES.length());
2217         byte[] r = fr.apply(SPECIES.length());
2218         byte ra = 0;
2219 
2220         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2221             for (int i = 0; i < a.length; i += SPECIES.length()) {
2222                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2223                 r[i] = av.reduceLanes(VectorOperators.OR);
2224             }
2225         }
2226 
2227         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2228             ra = 0;
2229             for (int i = 0; i < a.length; i += SPECIES.length()) {
2230                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2231                 ra |= av.reduceLanes(VectorOperators.OR);
2232             }
2233         }
2234 
2235         assertReductionArraysEquals(a, r, ra, Byte128VectorTests::OR, Byte128VectorTests::OR);
2236     }
2237 
2238 
2239     static byte ORMasked(byte[] a, int idx, boolean[] mask) {
2240         byte res = 0;
2241         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2242             if(mask[i % SPECIES.length()])
2243                 res |= a[i];
2244         }
2245 
2246         return res;
2247     }
2248 
2249     static byte ORMasked(byte[] a, boolean[] mask) {
2250         byte res = 0;
2251         for (int i = 0; i < a.length; i += SPECIES.length()) {
2252             byte tmp = 0;
2253             for (int j = 0; j < SPECIES.length(); j++) {
2254                 if(mask[(i + j) % SPECIES.length()])
2255                     tmp |= a[i + j];
2256             }
2257             res |= tmp;
2258         }
2259 
2260         return res;
2261     }
2262 
2263 
2264     @Test(dataProvider = "byteUnaryOpMaskProvider")
2265     static void ORByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
2266         byte[] a = fa.apply(SPECIES.length());
2267         byte[] r = fr.apply(SPECIES.length());
2268         boolean[] mask = fm.apply(SPECIES.length());
2269         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2270         byte ra = 0;
2271 
2272         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2273             for (int i = 0; i < a.length; i += SPECIES.length()) {
2274                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2275                 r[i] = av.reduceLanes(VectorOperators.OR, vmask);
2276             }
2277         }
2278 
2279         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2280             ra = 0;
2281             for (int i = 0; i < a.length; i += SPECIES.length()) {
2282                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2283                 ra |= av.reduceLanes(VectorOperators.OR, vmask);
2284             }
2285         }
2286 
2287         assertReductionArraysEqualsMasked(a, r, ra, mask, Byte128VectorTests::ORMasked, Byte128VectorTests::ORMasked);
2288     }
2289 
2290 
2291     static byte XOR(byte[] a, int idx) {
2292         byte res = 0;
2293         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2294             res ^= a[i];
2295         }
2296 
2297         return res;
2298     }
2299 
2300     static byte XOR(byte[] a) {
2301         byte res = 0;
2302         for (int i = 0; i < a.length; i += SPECIES.length()) {
2303             byte tmp = 0;
2304             for (int j = 0; j < SPECIES.length(); j++) {
2305                 tmp ^= a[i + j];
2306             }
2307             res ^= tmp;
2308         }
2309 
2310         return res;
2311     }
2312 
2313 
2314     @Test(dataProvider = "byteUnaryOpProvider")
2315     static void XORByte128VectorTests(IntFunction<byte[]> fa) {
2316         byte[] a = fa.apply(SPECIES.length());
2317         byte[] r = fr.apply(SPECIES.length());
2318         byte ra = 0;
2319 
2320         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2321             for (int i = 0; i < a.length; i += SPECIES.length()) {
2322                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2323                 r[i] = av.reduceLanes(VectorOperators.XOR);
2324             }
2325         }
2326 
2327         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2328             ra = 0;
2329             for (int i = 0; i < a.length; i += SPECIES.length()) {
2330                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2331                 ra ^= av.reduceLanes(VectorOperators.XOR);
2332             }
2333         }
2334 
2335         assertReductionArraysEquals(a, r, ra, Byte128VectorTests::XOR, Byte128VectorTests::XOR);
2336     }
2337 
2338 
2339     static byte XORMasked(byte[] a, int idx, boolean[] mask) {
2340         byte res = 0;
2341         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2342             if(mask[i % SPECIES.length()])
2343                 res ^= a[i];
2344         }
2345 
2346         return res;
2347     }
2348 
2349     static byte XORMasked(byte[] a, boolean[] mask) {
2350         byte res = 0;
2351         for (int i = 0; i < a.length; i += SPECIES.length()) {
2352             byte tmp = 0;
2353             for (int j = 0; j < SPECIES.length(); j++) {
2354                 if(mask[(i + j) % SPECIES.length()])
2355                     tmp ^= a[i + j];
2356             }
2357             res ^= tmp;
2358         }
2359 
2360         return res;
2361     }
2362 
2363 
2364     @Test(dataProvider = "byteUnaryOpMaskProvider")
2365     static void XORByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
2366         byte[] a = fa.apply(SPECIES.length());
2367         byte[] r = fr.apply(SPECIES.length());
2368         boolean[] mask = fm.apply(SPECIES.length());
2369         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2370         byte ra = 0;
2371 
2372         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2373             for (int i = 0; i < a.length; i += SPECIES.length()) {
2374                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2375                 r[i] = av.reduceLanes(VectorOperators.XOR, vmask);
2376             }
2377         }
2378 
2379         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2380             ra = 0;
2381             for (int i = 0; i < a.length; i += SPECIES.length()) {
2382                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2383                 ra ^= av.reduceLanes(VectorOperators.XOR, vmask);
2384             }
2385         }
2386 
2387         assertReductionArraysEqualsMasked(a, r, ra, mask, Byte128VectorTests::XORMasked, Byte128VectorTests::XORMasked);
2388     }
2389 
2390     static byte ADD(byte[] a, int idx) {
2391         byte res = 0;
2392         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2393             res += a[i];
2394         }
2395 
2396         return res;
2397     }
2398 
2399     static byte ADD(byte[] a) {
2400         byte res = 0;
2401         for (int i = 0; i < a.length; i += SPECIES.length()) {
2402             byte tmp = 0;
2403             for (int j = 0; j < SPECIES.length(); j++) {
2404                 tmp += a[i + j];
2405             }
2406             res += tmp;
2407         }
2408 
2409         return res;
2410     }
2411     @Test(dataProvider = "byteUnaryOpProvider")
2412     static void ADDByte128VectorTests(IntFunction<byte[]> fa) {
2413         byte[] a = fa.apply(SPECIES.length());
2414         byte[] r = fr.apply(SPECIES.length());
2415         byte ra = 0;
2416 
2417         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2418             for (int i = 0; i < a.length; i += SPECIES.length()) {
2419                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2420                 r[i] = av.reduceLanes(VectorOperators.ADD);
2421             }
2422         }
2423 
2424         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2425             ra = 0;
2426             for (int i = 0; i < a.length; i += SPECIES.length()) {
2427                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2428                 ra += av.reduceLanes(VectorOperators.ADD);
2429             }
2430         }
2431 
2432         assertReductionArraysEquals(a, r, ra, Byte128VectorTests::ADD, Byte128VectorTests::ADD);
2433     }
2434     static byte ADDMasked(byte[] a, int idx, boolean[] mask) {
2435         byte res = 0;
2436         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2437             if(mask[i % SPECIES.length()])
2438                 res += a[i];
2439         }
2440 
2441         return res;
2442     }
2443 
2444     static byte ADDMasked(byte[] a, boolean[] mask) {
2445         byte res = 0;
2446         for (int i = 0; i < a.length; i += SPECIES.length()) {
2447             byte tmp = 0;
2448             for (int j = 0; j < SPECIES.length(); j++) {
2449                 if(mask[(i + j) % SPECIES.length()])
2450                     tmp += a[i + j];
2451             }
2452             res += tmp;
2453         }
2454 
2455         return res;
2456     }
2457     @Test(dataProvider = "byteUnaryOpMaskProvider")
2458     static void ADDByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
2459         byte[] a = fa.apply(SPECIES.length());
2460         byte[] r = fr.apply(SPECIES.length());
2461         boolean[] mask = fm.apply(SPECIES.length());
2462         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2463         byte ra = 0;
2464 
2465         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2466             for (int i = 0; i < a.length; i += SPECIES.length()) {
2467                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2468                 r[i] = av.reduceLanes(VectorOperators.ADD, vmask);
2469             }
2470         }
2471 
2472         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2473             ra = 0;
2474             for (int i = 0; i < a.length; i += SPECIES.length()) {
2475                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2476                 ra += av.reduceLanes(VectorOperators.ADD, vmask);
2477             }
2478         }
2479 
2480         assertReductionArraysEqualsMasked(a, r, ra, mask, Byte128VectorTests::ADDMasked, Byte128VectorTests::ADDMasked);
2481     }
2482     static byte MUL(byte[] a, int idx) {
2483         byte res = 1;
2484         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2485             res *= a[i];
2486         }
2487 
2488         return res;
2489     }
2490 
2491     static byte MUL(byte[] a) {
2492         byte res = 1;
2493         for (int i = 0; i < a.length; i += SPECIES.length()) {
2494             byte tmp = 1;
2495             for (int j = 0; j < SPECIES.length(); j++) {
2496                 tmp *= a[i + j];
2497             }
2498             res *= tmp;
2499         }
2500 
2501         return res;
2502     }
2503     @Test(dataProvider = "byteUnaryOpProvider")
2504     static void MULByte128VectorTests(IntFunction<byte[]> fa) {
2505         byte[] a = fa.apply(SPECIES.length());
2506         byte[] r = fr.apply(SPECIES.length());
2507         byte ra = 1;
2508 
2509         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2510             for (int i = 0; i < a.length; i += SPECIES.length()) {
2511                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2512                 r[i] = av.reduceLanes(VectorOperators.MUL);
2513             }
2514         }
2515 
2516         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2517             ra = 1;
2518             for (int i = 0; i < a.length; i += SPECIES.length()) {
2519                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2520                 ra *= av.reduceLanes(VectorOperators.MUL);
2521             }
2522         }
2523 
2524         assertReductionArraysEquals(a, r, ra, Byte128VectorTests::MUL, Byte128VectorTests::MUL);
2525     }
2526     static byte MULMasked(byte[] a, int idx, boolean[] mask) {
2527         byte res = 1;
2528         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2529             if(mask[i % SPECIES.length()])
2530                 res *= a[i];
2531         }
2532 
2533         return res;
2534     }
2535 
2536     static byte MULMasked(byte[] a, boolean[] mask) {
2537         byte res = 1;
2538         for (int i = 0; i < a.length; i += SPECIES.length()) {
2539             byte tmp = 1;
2540             for (int j = 0; j < SPECIES.length(); j++) {
2541                 if(mask[(i + j) % SPECIES.length()])
2542                     tmp *= a[i + j];
2543             }
2544             res *= tmp;
2545         }
2546 
2547         return res;
2548     }
2549     @Test(dataProvider = "byteUnaryOpMaskProvider")
2550     static void MULByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
2551         byte[] a = fa.apply(SPECIES.length());
2552         byte[] r = fr.apply(SPECIES.length());
2553         boolean[] mask = fm.apply(SPECIES.length());
2554         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2555         byte ra = 1;
2556 
2557         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2558             for (int i = 0; i < a.length; i += SPECIES.length()) {
2559                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2560                 r[i] = av.reduceLanes(VectorOperators.MUL, vmask);
2561             }
2562         }
2563 
2564         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2565             ra = 1;
2566             for (int i = 0; i < a.length; i += SPECIES.length()) {
2567                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2568                 ra *= av.reduceLanes(VectorOperators.MUL, vmask);
2569             }
2570         }
2571 
2572         assertReductionArraysEqualsMasked(a, r, ra, mask, Byte128VectorTests::MULMasked, Byte128VectorTests::MULMasked);
2573     }
2574     static byte MIN(byte[] a, int idx) {
2575         byte res = Byte.MAX_VALUE;
2576         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2577             res = (byte)Math.min(res, a[i]);
2578         }
2579 
2580         return res;
2581     }
2582 
2583     static byte MIN(byte[] a) {
2584         byte res = Byte.MAX_VALUE;
2585         for (int i = 0; i < a.length; i++) {
2586             res = (byte)Math.min(res, a[i]);
2587         }
2588 
2589         return res;
2590     }
2591     @Test(dataProvider = "byteUnaryOpProvider")
2592     static void MINByte128VectorTests(IntFunction<byte[]> fa) {
2593         byte[] a = fa.apply(SPECIES.length());
2594         byte[] r = fr.apply(SPECIES.length());
2595         byte ra = Byte.MAX_VALUE;
2596 
2597         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2598             for (int i = 0; i < a.length; i += SPECIES.length()) {
2599                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2600                 r[i] = av.reduceLanes(VectorOperators.MIN);
2601             }
2602         }
2603 
2604         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2605             ra = Byte.MAX_VALUE;
2606             for (int i = 0; i < a.length; i += SPECIES.length()) {
2607                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2608                 ra = (byte)Math.min(ra, av.reduceLanes(VectorOperators.MIN));
2609             }
2610         }
2611 
2612         assertReductionArraysEquals(a, r, ra, Byte128VectorTests::MIN, Byte128VectorTests::MIN);
2613     }
2614     static byte MINMasked(byte[] a, int idx, boolean[] mask) {
2615         byte res = Byte.MAX_VALUE;
2616         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2617             if(mask[i % SPECIES.length()])
2618                 res = (byte)Math.min(res, a[i]);
2619         }
2620 
2621         return res;
2622     }
2623 
2624     static byte MINMasked(byte[] a, boolean[] mask) {
2625         byte res = Byte.MAX_VALUE;
2626         for (int i = 0; i < a.length; i++) {
2627             if(mask[i % SPECIES.length()])
2628                 res = (byte)Math.min(res, a[i]);
2629         }
2630 
2631         return res;
2632     }
2633     @Test(dataProvider = "byteUnaryOpMaskProvider")
2634     static void MINByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
2635         byte[] a = fa.apply(SPECIES.length());
2636         byte[] r = fr.apply(SPECIES.length());
2637         boolean[] mask = fm.apply(SPECIES.length());
2638         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2639         byte ra = Byte.MAX_VALUE;
2640 
2641         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2642             for (int i = 0; i < a.length; i += SPECIES.length()) {
2643                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2644                 r[i] = av.reduceLanes(VectorOperators.MIN, vmask);
2645             }
2646         }
2647 
2648         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2649             ra = Byte.MAX_VALUE;
2650             for (int i = 0; i < a.length; i += SPECIES.length()) {
2651                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2652                 ra = (byte)Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask));
2653             }
2654         }
2655 
2656         assertReductionArraysEqualsMasked(a, r, ra, mask, Byte128VectorTests::MINMasked, Byte128VectorTests::MINMasked);
2657     }
2658     static byte MAX(byte[] a, int idx) {
2659         byte res = Byte.MIN_VALUE;
2660         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2661             res = (byte)Math.max(res, a[i]);
2662         }
2663 
2664         return res;
2665     }
2666 
2667     static byte MAX(byte[] a) {
2668         byte res = Byte.MIN_VALUE;
2669         for (int i = 0; i < a.length; i++) {
2670             res = (byte)Math.max(res, a[i]);
2671         }
2672 
2673         return res;
2674     }
2675     @Test(dataProvider = "byteUnaryOpProvider")
2676     static void MAXByte128VectorTests(IntFunction<byte[]> fa) {
2677         byte[] a = fa.apply(SPECIES.length());
2678         byte[] r = fr.apply(SPECIES.length());
2679         byte ra = Byte.MIN_VALUE;
2680 
2681         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2682             for (int i = 0; i < a.length; i += SPECIES.length()) {
2683                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2684                 r[i] = av.reduceLanes(VectorOperators.MAX);
2685             }
2686         }
2687 
2688         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2689             ra = Byte.MIN_VALUE;
2690             for (int i = 0; i < a.length; i += SPECIES.length()) {
2691                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2692                 ra = (byte)Math.max(ra, av.reduceLanes(VectorOperators.MAX));
2693             }
2694         }
2695 
2696         assertReductionArraysEquals(a, r, ra, Byte128VectorTests::MAX, Byte128VectorTests::MAX);
2697     }
2698     static byte MAXMasked(byte[] a, int idx, boolean[] mask) {
2699         byte res = Byte.MIN_VALUE;
2700         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2701             if(mask[i % SPECIES.length()])
2702                 res = (byte)Math.max(res, a[i]);
2703         }
2704 
2705         return res;
2706     }
2707 
2708     static byte MAXMasked(byte[] a, boolean[] mask) {
2709         byte res = Byte.MIN_VALUE;
2710         for (int i = 0; i < a.length; i++) {
2711             if(mask[i % SPECIES.length()])
2712                 res = (byte)Math.max(res, a[i]);
2713         }
2714 
2715         return res;
2716     }
2717     @Test(dataProvider = "byteUnaryOpMaskProvider")
2718     static void MAXByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
2719         byte[] a = fa.apply(SPECIES.length());
2720         byte[] r = fr.apply(SPECIES.length());
2721         boolean[] mask = fm.apply(SPECIES.length());
2722         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2723         byte ra = Byte.MIN_VALUE;
2724 
2725         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2726             for (int i = 0; i < a.length; i += SPECIES.length()) {
2727                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2728                 r[i] = av.reduceLanes(VectorOperators.MAX, vmask);
2729             }
2730         }
2731 
2732         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2733             ra = Byte.MIN_VALUE;
2734             for (int i = 0; i < a.length; i += SPECIES.length()) {
2735                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2736                 ra = (byte)Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask));
2737             }
2738         }
2739 
2740         assertReductionArraysEqualsMasked(a, r, ra, mask, Byte128VectorTests::MAXMasked, Byte128VectorTests::MAXMasked);
2741     }
2742 
2743     static boolean anyTrue(boolean[] a, int idx) {
2744         boolean res = false;
2745         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2746             res |= a[i];
2747         }
2748 
2749         return res;
2750     }
2751 
2752 
2753     @Test(dataProvider = "boolUnaryOpProvider")
2754     static void anyTrueByte128VectorTests(IntFunction<boolean[]> fm) {
2755         boolean[] mask = fm.apply(SPECIES.length());
2756         boolean[] r = fmr.apply(SPECIES.length());
2757 
2758         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2759             for (int i = 0; i < mask.length; i += SPECIES.length()) {
2760                 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i);
2761                 r[i] = vmask.anyTrue();
2762             }
2763         }
2764 
2765         assertReductionBoolArraysEquals(mask, r, Byte128VectorTests::anyTrue);
2766     }
2767 
2768 
2769     static boolean allTrue(boolean[] a, int idx) {
2770         boolean res = true;
2771         for (int i = idx; i < (idx + SPECIES.length()); i++) {
2772             res &= a[i];
2773         }
2774 
2775         return res;
2776     }
2777 
2778 
2779     @Test(dataProvider = "boolUnaryOpProvider")
2780     static void allTrueByte128VectorTests(IntFunction<boolean[]> fm) {
2781         boolean[] mask = fm.apply(SPECIES.length());
2782         boolean[] r = fmr.apply(SPECIES.length());
2783 
2784         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2785             for (int i = 0; i < mask.length; i += SPECIES.length()) {
2786                 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i);
2787                 r[i] = vmask.allTrue();
2788             }
2789         }
2790 
2791         assertReductionBoolArraysEquals(mask, r, Byte128VectorTests::allTrue);
2792     }
2793 
2794 
2795     @Test(dataProvider = "byteUnaryOpProvider")
2796     static void withByte128VectorTests(IntFunction<byte []> fa) {
2797         byte[] a = fa.apply(SPECIES.length());
2798         byte[] r = fr.apply(SPECIES.length());
2799 
2800         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2801             for (int i = 0; i < a.length; i += SPECIES.length()) {
2802                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2803                 av.withLane(0, (byte)4).intoArray(r, i);
2804             }
2805         }
2806 
2807         assertInsertArraysEquals(a, r, (byte)4, 0);
2808     }
2809     static boolean testIS_DEFAULT(byte a) {
2810         return bits(a)==0;
2811     }
2812 
2813     @Test(dataProvider = "byteTestOpProvider")
2814     static void IS_DEFAULTByte128VectorTests(IntFunction<byte[]> fa) {
2815         byte[] a = fa.apply(SPECIES.length());
2816 
2817         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2818             for (int i = 0; i < a.length; i += SPECIES.length()) {
2819                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2820                 VectorMask<Byte> mv = av.test(VectorOperators.IS_DEFAULT);
2821 
2822                 // Check results as part of computation.
2823                 for (int j = 0; j < SPECIES.length(); j++) {
2824    
2825                  Assert.assertEquals(mv.laneIsSet(j), testIS_DEFAULT(a[i + j]));
2826                 }
2827             }
2828         }
2829     }
2830 
2831     static boolean testIS_NEGATIVE(byte a) {
2832         return bits(a)<0;
2833     }
2834 
2835     @Test(dataProvider = "byteTestOpProvider")
2836     static void IS_NEGATIVEByte128VectorTests(IntFunction<byte[]> fa) {
2837         byte[] a = fa.apply(SPECIES.length());
2838 
2839         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2840             for (int i = 0; i < a.length; i += SPECIES.length()) {
2841                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2842                 VectorMask<Byte> mv = av.test(VectorOperators.IS_NEGATIVE);
2843 
2844                 // Check results as part of computation.
2845                 for (int j = 0; j < SPECIES.length(); j++) {
2846    
2847                  Assert.assertEquals(mv.laneIsSet(j), testIS_NEGATIVE(a[i + j]));
2848                 }
2849             }
2850         }
2851     }
2852 
2853 
2854 
2855 
2856 
2857     @Test(dataProvider = "byteCompareOpProvider")
2858     static void LTByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2859         byte[] a = fa.apply(SPECIES.length());
2860         byte[] b = fb.apply(SPECIES.length());
2861 
2862         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2863             for (int i = 0; i < a.length; i += SPECIES.length()) {
2864                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2865                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2866                 VectorMask<Byte> mv = av.compare(VectorOperators.LT, bv);
2867 
2868                 // Check results as part of computation.
2869                 for (int j = 0; j < SPECIES.length(); j++) {
2870                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i + j]);
2871                 }
2872             }
2873         }
2874     }
2875 
2876 
2877     @Test(dataProvider = "byteCompareOpProvider")
2878     static void ltByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2879         byte[] a = fa.apply(SPECIES.length());
2880         byte[] b = fb.apply(SPECIES.length());
2881 
2882         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2883             for (int i = 0; i < a.length; i += SPECIES.length()) {
2884                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2885                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2886                 VectorMask<Byte> mv = av.lt(bv);
2887 
2888                 // Check results as part of computation.
2889                 for (int j = 0; j < SPECIES.length(); j++) {
2890                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i + j]);
2891                 }
2892             }
2893         }
2894     }
2895 
2896 
2897     @Test(dataProvider = "byteCompareOpProvider")
2898     static void GTByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2899         byte[] a = fa.apply(SPECIES.length());
2900         byte[] b = fb.apply(SPECIES.length());
2901 
2902         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2903             for (int i = 0; i < a.length; i += SPECIES.length()) {
2904                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2905                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2906                 VectorMask<Byte> mv = av.compare(VectorOperators.GT, bv);
2907 
2908                 // Check results as part of computation.
2909                 for (int j = 0; j < SPECIES.length(); j++) {
2910                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] > b[i + j]);
2911                 }
2912             }
2913         }
2914     }
2915 
2916 
2917     @Test(dataProvider = "byteCompareOpProvider")
2918     static void EQByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2919         byte[] a = fa.apply(SPECIES.length());
2920         byte[] b = fb.apply(SPECIES.length());
2921 
2922         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2923             for (int i = 0; i < a.length; i += SPECIES.length()) {
2924                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2925                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2926                 VectorMask<Byte> mv = av.compare(VectorOperators.EQ, bv);
2927 
2928                 // Check results as part of computation.
2929                 for (int j = 0; j < SPECIES.length(); j++) {
2930                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i + j]);
2931                 }
2932             }
2933         }
2934     }
2935 
2936 
2937     @Test(dataProvider = "byteCompareOpProvider")
2938     static void eqByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2939         byte[] a = fa.apply(SPECIES.length());
2940         byte[] b = fb.apply(SPECIES.length());
2941 
2942         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2943             for (int i = 0; i < a.length; i += SPECIES.length()) {
2944                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2945                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2946                 VectorMask<Byte> mv = av.eq(bv);
2947 
2948                 // Check results as part of computation.
2949                 for (int j = 0; j < SPECIES.length(); j++) {
2950                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i + j]);
2951                 }
2952             }
2953         }
2954     }
2955 
2956 
2957     @Test(dataProvider = "byteCompareOpProvider")
2958     static void NEByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2959         byte[] a = fa.apply(SPECIES.length());
2960         byte[] b = fb.apply(SPECIES.length());
2961 
2962         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2963             for (int i = 0; i < a.length; i += SPECIES.length()) {
2964                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2965                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2966                 VectorMask<Byte> mv = av.compare(VectorOperators.NE, bv);
2967 
2968                 // Check results as part of computation.
2969                 for (int j = 0; j < SPECIES.length(); j++) {
2970                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] != b[i + j]);
2971                 }
2972             }
2973         }
2974     }
2975 
2976 
2977     @Test(dataProvider = "byteCompareOpProvider")
2978     static void LEByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2979         byte[] a = fa.apply(SPECIES.length());
2980         byte[] b = fb.apply(SPECIES.length());
2981 
2982         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2983             for (int i = 0; i < a.length; i += SPECIES.length()) {
2984                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2985                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2986                 VectorMask<Byte> mv = av.compare(VectorOperators.LE, bv);
2987 
2988                 // Check results as part of computation.
2989                 for (int j = 0; j < SPECIES.length(); j++) {
2990                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] <= b[i + j]);
2991                 }
2992             }
2993         }
2994     }
2995 
2996 
2997     @Test(dataProvider = "byteCompareOpProvider")
2998     static void GEByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2999         byte[] a = fa.apply(SPECIES.length());
3000         byte[] b = fb.apply(SPECIES.length());
3001 
3002         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3003             for (int i = 0; i < a.length; i += SPECIES.length()) {
3004                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3005                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3006                 VectorMask<Byte> mv = av.compare(VectorOperators.GE, bv);
3007 
3008                 // Check results as part of computation.
3009                 for (int j = 0; j < SPECIES.length(); j++) {
3010                     Assert.assertEquals(mv.laneIsSet(j), a[i + j] >= b[i + j]);
3011                 }
3012             }
3013         }
3014     }
3015 
3016 
3017     static byte blend(byte a, byte b, boolean mask) {
3018         return mask ? b : a;
3019     }
3020 
3021     @Test(dataProvider = "byteBinaryOpMaskProvider")
3022     static void blendByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
3023                                           IntFunction<boolean[]> fm) {
3024         byte[] a = fa.apply(SPECIES.length());
3025         byte[] b = fb.apply(SPECIES.length());
3026         byte[] r = fr.apply(SPECIES.length());
3027         boolean[] mask = fm.apply(SPECIES.length());
3028         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3029 
3030         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3031             for (int i = 0; i < a.length; i += SPECIES.length()) {
3032                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3033                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3034                 av.blend(bv, vmask).intoArray(r, i);
3035             }
3036         }
3037 
3038         assertArraysEquals(a, b, r, mask, Byte128VectorTests::blend);
3039     }
3040 
3041     @Test(dataProvider = "byteUnaryOpShuffleProvider")
3042     static void RearrangeByte128VectorTests(IntFunction<byte[]> fa,
3043                                            BiFunction<Integer,Integer,int[]> fs) {
3044         byte[] a = fa.apply(SPECIES.length());
3045         int[] order = fs.apply(a.length, SPECIES.length());
3046         byte[] r = fr.apply(SPECIES.length());
3047 
3048         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3049             for (int i = 0; i < a.length; i += SPECIES.length()) {
3050                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3051                 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
3052             }
3053         }
3054 
3055         assertRearrangeArraysEquals(a, r, order, SPECIES.length());
3056     }
3057 
3058 
3059 
3060 
3061     @Test(dataProvider = "byteUnaryOpProvider")
3062     static void getByte128VectorTests(IntFunction<byte[]> fa) {
3063         byte[] a = fa.apply(SPECIES.length());
3064         byte[] r = fr.apply(SPECIES.length());
3065 
3066         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3067             for (int i = 0; i < a.length; i += SPECIES.length()) {
3068                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3069                 int num_lanes = SPECIES.length();
3070                 // Manually unroll because full unroll happens after intrinsification.
3071                 // Unroll is needed because get intrinsic requires for index to be a known constant.
3072                 if (num_lanes == 1) {
3073                     r[i]=av.lane(0);
3074                 } else if (num_lanes == 2) {
3075                     r[i]=av.lane(0);
3076                     r[i+1]=av.lane(1);
3077                 } else if (num_lanes == 4) {
3078                     r[i]=av.lane(0);
3079                     r[i+1]=av.lane(1);
3080                     r[i+2]=av.lane(2);
3081                     r[i+3]=av.lane(3);
3082                 } else if (num_lanes == 8) {
3083                     r[i]=av.lane(0);
3084                     r[i+1]=av.lane(1);
3085                     r[i+2]=av.lane(2);
3086                     r[i+3]=av.lane(3);
3087                     r[i+4]=av.lane(4);
3088                     r[i+5]=av.lane(5);
3089                     r[i+6]=av.lane(6);
3090                     r[i+7]=av.lane(7);
3091                 } else if (num_lanes == 16) {
3092                     r[i]=av.lane(0);
3093                     r[i+1]=av.lane(1);
3094                     r[i+2]=av.lane(2);
3095                     r[i+3]=av.lane(3);
3096                     r[i+4]=av.lane(4);
3097                     r[i+5]=av.lane(5);
3098                     r[i+6]=av.lane(6);
3099                     r[i+7]=av.lane(7);
3100                     r[i+8]=av.lane(8);
3101                     r[i+9]=av.lane(9);
3102                     r[i+10]=av.lane(10);
3103                     r[i+11]=av.lane(11);
3104                     r[i+12]=av.lane(12);
3105                     r[i+13]=av.lane(13);
3106                     r[i+14]=av.lane(14);
3107                     r[i+15]=av.lane(15);
3108                 } else if (num_lanes == 32) {
3109                     r[i]=av.lane(0);
3110                     r[i+1]=av.lane(1);
3111                     r[i+2]=av.lane(2);
3112                     r[i+3]=av.lane(3);
3113                     r[i+4]=av.lane(4);
3114                     r[i+5]=av.lane(5);
3115                     r[i+6]=av.lane(6);
3116                     r[i+7]=av.lane(7);
3117                     r[i+8]=av.lane(8);
3118                     r[i+9]=av.lane(9);
3119                     r[i+10]=av.lane(10);
3120                     r[i+11]=av.lane(11);
3121                     r[i+12]=av.lane(12);
3122                     r[i+13]=av.lane(13);
3123                     r[i+14]=av.lane(14);
3124                     r[i+15]=av.lane(15);
3125                     r[i+16]=av.lane(16);
3126                     r[i+17]=av.lane(17);
3127                     r[i+18]=av.lane(18);
3128                     r[i+19]=av.lane(19);
3129                     r[i+20]=av.lane(20);
3130                     r[i+21]=av.lane(21);
3131                     r[i+22]=av.lane(22);
3132                     r[i+23]=av.lane(23);
3133                     r[i+24]=av.lane(24);
3134                     r[i+25]=av.lane(25);
3135                     r[i+26]=av.lane(26);
3136                     r[i+27]=av.lane(27);
3137                     r[i+28]=av.lane(28);
3138                     r[i+29]=av.lane(29);
3139                     r[i+30]=av.lane(30);
3140                     r[i+31]=av.lane(31);
3141                 } else if (num_lanes == 64) {
3142                     r[i]=av.lane(0);
3143                     r[i+1]=av.lane(1);
3144                     r[i+2]=av.lane(2);
3145                     r[i+3]=av.lane(3);
3146                     r[i+4]=av.lane(4);
3147                     r[i+5]=av.lane(5);
3148                     r[i+6]=av.lane(6);
3149                     r[i+7]=av.lane(7);
3150                     r[i+8]=av.lane(8);
3151                     r[i+9]=av.lane(9);
3152                     r[i+10]=av.lane(10);
3153                     r[i+11]=av.lane(11);
3154                     r[i+12]=av.lane(12);
3155                     r[i+13]=av.lane(13);
3156                     r[i+14]=av.lane(14);
3157                     r[i+15]=av.lane(15);
3158                     r[i+16]=av.lane(16);
3159                     r[i+17]=av.lane(17);
3160                     r[i+18]=av.lane(18);
3161                     r[i+19]=av.lane(19);
3162                     r[i+20]=av.lane(20);
3163                     r[i+21]=av.lane(21);
3164                     r[i+22]=av.lane(22);
3165                     r[i+23]=av.lane(23);
3166                     r[i+24]=av.lane(24);
3167                     r[i+25]=av.lane(25);
3168                     r[i+26]=av.lane(26);
3169                     r[i+27]=av.lane(27);
3170                     r[i+28]=av.lane(28);
3171                     r[i+29]=av.lane(29);
3172                     r[i+30]=av.lane(30);
3173                     r[i+31]=av.lane(31);
3174                     r[i+32]=av.lane(32);
3175                     r[i+33]=av.lane(33);
3176                     r[i+34]=av.lane(34);
3177                     r[i+35]=av.lane(35);
3178                     r[i+36]=av.lane(36);
3179                     r[i+37]=av.lane(37);
3180                     r[i+38]=av.lane(38);
3181                     r[i+39]=av.lane(39);
3182                     r[i+40]=av.lane(40);
3183                     r[i+41]=av.lane(41);
3184                     r[i+42]=av.lane(42);
3185                     r[i+43]=av.lane(43);
3186                     r[i+44]=av.lane(44);
3187                     r[i+45]=av.lane(45);
3188                     r[i+46]=av.lane(46);
3189                     r[i+47]=av.lane(47);
3190                     r[i+48]=av.lane(48);
3191                     r[i+49]=av.lane(49);
3192                     r[i+50]=av.lane(50);
3193                     r[i+51]=av.lane(51);
3194                     r[i+52]=av.lane(52);
3195                     r[i+53]=av.lane(53);
3196                     r[i+54]=av.lane(54);
3197                     r[i+55]=av.lane(55);
3198                     r[i+56]=av.lane(56);
3199                     r[i+57]=av.lane(57);
3200                     r[i+58]=av.lane(58);
3201                     r[i+59]=av.lane(59);
3202                     r[i+60]=av.lane(60);
3203                     r[i+61]=av.lane(61);
3204                     r[i+62]=av.lane(62);
3205                     r[i+63]=av.lane(63);
3206                 } else {
3207                     for (int j = 0; j < SPECIES.length(); j++) {
3208                         r[i+j]=av.lane(j);
3209                     }
3210                 }
3211             }
3212         }
3213 
3214         assertArraysEquals(a, r, Byte128VectorTests::get);
3215     }
3216 
3217     @Test(dataProvider = "byteUnaryOpProvider")
3218     static void BroadcastByte128VectorTests(IntFunction<byte[]> fa) {
3219         byte[] a = fa.apply(SPECIES.length());
3220         byte[] r = new byte[a.length];
3221 
3222         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3223             for (int i = 0; i < a.length; i += SPECIES.length()) {
3224                 ByteVector.broadcast(SPECIES, a[i]).intoArray(r, i);
3225             }
3226         }
3227 
3228         assertBroadcastArraysEquals(a, r);
3229     }
3230 
3231 
3232 
3233 
3234 
3235     @Test(dataProvider = "byteUnaryOpProvider")
3236     static void ZeroByte128VectorTests(IntFunction<byte[]> fa) {
3237         byte[] a = fa.apply(SPECIES.length());
3238         byte[] r = new byte[a.length];
3239 
3240         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3241             for (int i = 0; i < a.length; i += SPECIES.length()) {
3242                 ByteVector.zero(SPECIES).intoArray(a, i);
3243             }
3244         }
3245 
3246         Assert.assertEquals(a, r);
3247     }
3248 
3249 
3250 
3251 
3252     static byte[] sliceUnary(byte[] a, int origin, int idx) {
3253         byte[] res = new byte[SPECIES.length()];
3254         for (int i = 0; i < SPECIES.length(); i++){
3255             if(i+origin < SPECIES.length())
3256                 res[i] = a[idx+i+origin];
3257             else
3258                 res[i] = (byte)0;
3259         }
3260         return res;
3261     }
3262 
3263     @Test(dataProvider = "byteUnaryOpProvider")
3264     static void sliceUnaryByte128VectorTests(IntFunction<byte[]> fa) {
3265         byte[] a = fa.apply(SPECIES.length());
3266         byte[] r = new byte[a.length];
3267         int origin = (new java.util.Random()).nextInt(SPECIES.length());
3268         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3269             for (int i = 0; i < a.length; i += SPECIES.length()) {
3270                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3271                 av.slice(origin).intoArray(r, i);
3272             }
3273         }
3274 
3275         assertArraysEquals(a, r, origin, Byte128VectorTests::sliceUnary);
3276     }
3277     static byte[] sliceBinary(byte[] a, byte[] b, int origin, int idx) {
3278         byte[] res = new byte[SPECIES.length()];
3279         for (int i = 0, j = 0; i < SPECIES.length(); i++){
3280             if(i+origin < SPECIES.length())
3281                 res[i] = a[idx+i+origin];
3282             else {
3283                 res[i] = b[idx+j];
3284                 j++;
3285             }
3286         }
3287         return res;
3288     }
3289 
3290     @Test(dataProvider = "byteBinaryOpProvider")
3291     static void sliceBinaryByte128VectorTestsBinary(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3292         byte[] a = fa.apply(SPECIES.length());
3293         byte[] b = fb.apply(SPECIES.length());
3294         byte[] r = new byte[a.length];
3295         int origin = (new java.util.Random()).nextInt(SPECIES.length());
3296         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3297             for (int i = 0; i < a.length; i += SPECIES.length()) {
3298                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3299                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3300                 av.slice(origin, bv).intoArray(r, i);
3301             }
3302         }
3303 
3304         assertArraysEquals(a, b, r, origin, Byte128VectorTests::sliceBinary);
3305     }
3306     static byte[] slice(byte[] a, byte[] b, int origin, boolean[] mask, int idx) {
3307         byte[] res = new byte[SPECIES.length()];
3308         for (int i = 0, j = 0; i < SPECIES.length(); i++){
3309             if(i+origin < SPECIES.length())
3310                 res[i] = mask[i] ? a[idx+i+origin] : (byte)0;
3311             else {
3312                 res[i] = mask[i] ? b[idx+j] : (byte)0;
3313                 j++;
3314             }
3315         }
3316         return res;
3317     }
3318 
3319     @Test(dataProvider = "byteBinaryOpMaskProvider")
3320     static void sliceByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
3321     IntFunction<boolean[]> fm) {
3322         byte[] a = fa.apply(SPECIES.length());
3323         byte[] b = fb.apply(SPECIES.length());
3324         boolean[] mask = fm.apply(SPECIES.length());
3325         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3326 
3327         byte[] r = new byte[a.length];
3328         int origin = (new java.util.Random()).nextInt(SPECIES.length());
3329         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3330             for (int i = 0; i < a.length; i += SPECIES.length()) {
3331                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3332                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3333                 av.slice(origin, bv, vmask).intoArray(r, i);
3334             }
3335         }
3336 
3337         assertArraysEquals(a, b, r, origin, mask, Byte128VectorTests::slice);
3338     }
3339     static byte[] unsliceUnary(byte[] a, int origin, int idx) {
3340         byte[] res = new byte[SPECIES.length()];
3341         for (int i = 0, j = 0; i < SPECIES.length(); i++){
3342             if(i < origin)
3343                 res[i] = (byte)0;
3344             else {
3345                 res[i] = a[idx+j];
3346                 j++;
3347             }
3348         }
3349         return res;
3350     }
3351 
3352     @Test(dataProvider = "byteUnaryOpProvider")
3353     static void unsliceUnaryByte128VectorTests(IntFunction<byte[]> fa) {
3354         byte[] a = fa.apply(SPECIES.length());
3355         byte[] r = new byte[a.length];
3356         int origin = (new java.util.Random()).nextInt(SPECIES.length());
3357         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3358             for (int i = 0; i < a.length; i += SPECIES.length()) {
3359                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3360                 av.unslice(origin).intoArray(r, i);
3361             }
3362         }
3363 
3364         assertArraysEquals(a, r, origin, Byte128VectorTests::unsliceUnary);
3365     }
3366     static byte[] unsliceBinary(byte[] a, byte[] b, int origin, int part, int idx) {
3367         byte[] res = new byte[SPECIES.length()];
3368         for (int i = 0, j = 0; i < SPECIES.length(); i++){
3369             if (part == 0) {
3370                 if (i < origin)
3371                     res[i] = b[idx+i];
3372                 else {
3373                     res[i] = a[idx+j];
3374                     j++;
3375                 }
3376             } else if (part == 1) {
3377                 if (i < origin)
3378                     res[i] = a[idx+SPECIES.length()-origin+i];
3379                 else {
3380                     res[i] = b[idx+origin+j];
3381                     j++;
3382                 }
3383             }
3384         }
3385         return res;
3386     }
3387 
3388     @Test(dataProvider = "byteBinaryOpProvider")
3389     static void unsliceBinaryByte128VectorTestsBinary(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3390         byte[] a = fa.apply(SPECIES.length());
3391         byte[] b = fb.apply(SPECIES.length());
3392         byte[] r = new byte[a.length];
3393         int origin = (new java.util.Random()).nextInt(SPECIES.length());
3394         int part = (new java.util.Random()).nextInt(2);
3395         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3396             for (int i = 0; i < a.length; i += SPECIES.length()) {
3397                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3398                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3399                 av.unslice(origin, bv, part).intoArray(r, i);
3400             }
3401         }
3402 
3403         assertArraysEquals(a, b, r, origin, part, Byte128VectorTests::unsliceBinary);
3404     }
3405     static byte[] unslice(byte[] a, byte[] b, int origin, int part, boolean[] mask, int idx) {
3406         byte[] res = new byte[SPECIES.length()];
3407         for (int i = 0, j = 0; i < SPECIES.length(); i++){
3408             if(i+origin < SPECIES.length())
3409                 res[i] = b[idx+i+origin];
3410             else {
3411                 res[i] = b[idx+j];
3412                 j++;
3413             }
3414         }
3415         for (int i = 0; i < SPECIES.length(); i++){
3416             res[i] = mask[i] ? a[idx+i] : res[i];
3417         }
3418         byte[] res1 = new byte[SPECIES.length()];
3419         if (part == 0) {
3420             for (int i = 0, j = 0; i < SPECIES.length(); i++){
3421                 if (i < origin)
3422                     res1[i] = b[idx+i];
3423                 else {
3424                    res1[i] = res[j];
3425                    j++;
3426                 }
3427             }
3428         } else if (part == 1) {
3429             for (int i = 0, j = 0; i < SPECIES.length(); i++){
3430                 if (i < origin)
3431                     res1[i] = res[SPECIES.length()-origin+i];
3432                 else {
3433                     res1[i] = b[idx+origin+j];
3434                     j++;
3435                 }
3436             }
3437         }
3438         return res1;
3439     }
3440 
3441     @Test(dataProvider = "byteBinaryOpMaskProvider")
3442     static void unsliceByte128VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
3443     IntFunction<boolean[]> fm) {
3444         byte[] a = fa.apply(SPECIES.length());
3445         byte[] b = fb.apply(SPECIES.length());
3446         boolean[] mask = fm.apply(SPECIES.length());
3447         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3448         byte[] r = new byte[a.length];
3449         int origin = (new java.util.Random()).nextInt(SPECIES.length());
3450         int part = (new java.util.Random()).nextInt(2);
3451         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3452             for (int i = 0; i < a.length; i += SPECIES.length()) {
3453                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3454                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3455                 av.unslice(origin, bv, part, vmask).intoArray(r, i);
3456             }
3457         }
3458 
3459         assertArraysEquals(a, b, r, origin, part, mask, Byte128VectorTests::unslice);
3460     }
3461 
3462 
3463 
3464 
3465 
3466 
3467 
3468 
3469 
3470 
3471 
3472 
3473 
3474 
3475 
3476 
3477 
3478 
3479 
3480 
3481 
3482 
3483     static byte BITWISE_BLEND(byte a, byte b, byte c) {
3484         return (byte)((a&~(c))|(b&c));
3485     }
3486 
3487 
3488     @Test(dataProvider = "byteTernaryOpProvider")
3489     static void BITWISE_BLENDByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
3490         byte[] a = fa.apply(SPECIES.length());
3491         byte[] b = fb.apply(SPECIES.length());
3492         byte[] c = fc.apply(SPECIES.length());
3493         byte[] r = fr.apply(SPECIES.length());
3494 
3495         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3496             for (int i = 0; i < a.length; i += SPECIES.length()) {
3497                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3498                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3499                 ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
3500                 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv).intoArray(r, i);
3501             }
3502         }
3503 
3504         assertArraysEquals(a, b, c, r, Byte128VectorTests::BITWISE_BLEND);
3505     }
3506 
3507 
3508     @Test(dataProvider = "byteTernaryOpMaskProvider")
3509     static void BITWISE_BLENDByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
3510                                           IntFunction<byte[]> fc, IntFunction<boolean[]> fm) {
3511         byte[] a = fa.apply(SPECIES.length());
3512         byte[] b = fb.apply(SPECIES.length());
3513         byte[] c = fc.apply(SPECIES.length());
3514         byte[] r = fr.apply(SPECIES.length());
3515         boolean[] mask = fm.apply(SPECIES.length());
3516         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3517 
3518         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3519             for (int i = 0; i < a.length; i += SPECIES.length()) {
3520                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3521                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3522                 ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
3523                 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i);
3524             }
3525         }
3526 
3527         assertArraysEquals(a, b, c, r, mask, Byte128VectorTests::BITWISE_BLEND);
3528     }
3529 
3530 
3531     static byte NEG(byte a) {
3532         return (byte)(-((byte)a));
3533     }
3534 
3535     static byte neg(byte a) {
3536         return (byte)(-((byte)a));
3537     }
3538 
3539     @Test(dataProvider = "byteUnaryOpProvider")
3540     static void NEGByte128VectorTests(IntFunction<byte[]> fa) {
3541         byte[] a = fa.apply(SPECIES.length());
3542         byte[] r = fr.apply(SPECIES.length());
3543 
3544         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3545             for (int i = 0; i < a.length; i += SPECIES.length()) {
3546                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3547                 av.lanewise(VectorOperators.NEG).intoArray(r, i);
3548             }
3549         }
3550 
3551         assertArraysEquals(a, r, Byte128VectorTests::NEG);
3552     }
3553 
3554     @Test(dataProvider = "byteUnaryOpProvider")
3555     static void negByte128VectorTests(IntFunction<byte[]> fa) {
3556         byte[] a = fa.apply(SPECIES.length());
3557         byte[] r = fr.apply(SPECIES.length());
3558 
3559         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3560             for (int i = 0; i < a.length; i += SPECIES.length()) {
3561                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3562                 av.neg().intoArray(r, i);
3563             }
3564         }
3565 
3566         assertArraysEquals(a, r, Byte128VectorTests::neg);
3567     }
3568 
3569     @Test(dataProvider = "byteUnaryOpMaskProvider")
3570     static void NEGMaskedByte128VectorTests(IntFunction<byte[]> fa,
3571                                                 IntFunction<boolean[]> fm) {
3572         byte[] a = fa.apply(SPECIES.length());
3573         byte[] r = fr.apply(SPECIES.length());
3574         boolean[] mask = fm.apply(SPECIES.length());
3575         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3576 
3577         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3578             for (int i = 0; i < a.length; i += SPECIES.length()) {
3579                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3580                 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i);
3581             }
3582         }
3583 
3584         assertArraysEquals(a, r, mask, Byte128VectorTests::NEG);
3585     }
3586 
3587     static byte ABS(byte a) {
3588         return (byte)(Math.abs((byte)a));
3589     }
3590 
3591     static byte abs(byte a) {
3592         return (byte)(Math.abs((byte)a));
3593     }
3594 
3595     @Test(dataProvider = "byteUnaryOpProvider")
3596     static void ABSByte128VectorTests(IntFunction<byte[]> fa) {
3597         byte[] a = fa.apply(SPECIES.length());
3598         byte[] r = fr.apply(SPECIES.length());
3599 
3600         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3601             for (int i = 0; i < a.length; i += SPECIES.length()) {
3602                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3603                 av.lanewise(VectorOperators.ABS).intoArray(r, i);
3604             }
3605         }
3606 
3607         assertArraysEquals(a, r, Byte128VectorTests::ABS);
3608     }
3609 
3610     @Test(dataProvider = "byteUnaryOpProvider")
3611     static void absByte128VectorTests(IntFunction<byte[]> fa) {
3612         byte[] a = fa.apply(SPECIES.length());
3613         byte[] r = fr.apply(SPECIES.length());
3614 
3615         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3616             for (int i = 0; i < a.length; i += SPECIES.length()) {
3617                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3618                 av.abs().intoArray(r, i);
3619             }
3620         }
3621 
3622         assertArraysEquals(a, r, Byte128VectorTests::abs);
3623     }
3624 
3625     @Test(dataProvider = "byteUnaryOpMaskProvider")
3626     static void ABSMaskedByte128VectorTests(IntFunction<byte[]> fa,
3627                                                 IntFunction<boolean[]> fm) {
3628         byte[] a = fa.apply(SPECIES.length());
3629         byte[] r = fr.apply(SPECIES.length());
3630         boolean[] mask = fm.apply(SPECIES.length());
3631         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3632 
3633         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3634             for (int i = 0; i < a.length; i += SPECIES.length()) {
3635                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3636                 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i);
3637             }
3638         }
3639 
3640         assertArraysEquals(a, r, mask, Byte128VectorTests::ABS);
3641     }
3642 
3643 
3644     static byte NOT(byte a) {
3645         return (byte)(~((byte)a));
3646     }
3647 
3648     static byte not(byte a) {
3649         return (byte)(~((byte)a));
3650     }
3651 
3652 
3653 
3654     @Test(dataProvider = "byteUnaryOpProvider")
3655     static void NOTByte128VectorTests(IntFunction<byte[]> fa) {
3656         byte[] a = fa.apply(SPECIES.length());
3657         byte[] r = fr.apply(SPECIES.length());
3658 
3659         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3660             for (int i = 0; i < a.length; i += SPECIES.length()) {
3661                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3662                 av.lanewise(VectorOperators.NOT).intoArray(r, i);
3663             }
3664         }
3665 
3666         assertArraysEquals(a, r, Byte128VectorTests::NOT);
3667     }
3668 
3669     @Test(dataProvider = "byteUnaryOpProvider")
3670     static void notByte128VectorTests(IntFunction<byte[]> fa) {
3671         byte[] a = fa.apply(SPECIES.length());
3672         byte[] r = fr.apply(SPECIES.length());
3673 
3674         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3675             for (int i = 0; i < a.length; i += SPECIES.length()) {
3676                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3677                 av.not().intoArray(r, i);
3678             }
3679         }
3680 
3681         assertArraysEquals(a, r, Byte128VectorTests::not);
3682     }
3683 
3684 
3685 
3686     @Test(dataProvider = "byteUnaryOpMaskProvider")
3687     static void NOTMaskedByte128VectorTests(IntFunction<byte[]> fa,
3688                                                 IntFunction<boolean[]> fm) {
3689         byte[] a = fa.apply(SPECIES.length());
3690         byte[] r = fr.apply(SPECIES.length());
3691         boolean[] mask = fm.apply(SPECIES.length());
3692         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3693 
3694         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3695             for (int i = 0; i < a.length; i += SPECIES.length()) {
3696                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3697                 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i);
3698             }
3699         }
3700 
3701         assertArraysEquals(a, r, mask, Byte128VectorTests::NOT);
3702     }
3703 
3704 
3705 
3706     static byte ZOMO(byte a) {
3707         return (byte)((a==0?0:-1));
3708     }
3709 
3710 
3711 
3712     @Test(dataProvider = "byteUnaryOpProvider")
3713     static void ZOMOByte128VectorTests(IntFunction<byte[]> fa) {
3714         byte[] a = fa.apply(SPECIES.length());
3715         byte[] r = fr.apply(SPECIES.length());
3716 
3717         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3718             for (int i = 0; i < a.length; i += SPECIES.length()) {
3719                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3720                 av.lanewise(VectorOperators.ZOMO).intoArray(r, i);
3721             }
3722         }
3723 
3724         assertArraysEquals(a, r, Byte128VectorTests::ZOMO);
3725     }
3726 
3727 
3728 
3729     @Test(dataProvider = "byteUnaryOpMaskProvider")
3730     static void ZOMOMaskedByte128VectorTests(IntFunction<byte[]> fa,
3731                                                 IntFunction<boolean[]> fm) {
3732         byte[] a = fa.apply(SPECIES.length());
3733         byte[] r = fr.apply(SPECIES.length());
3734         boolean[] mask = fm.apply(SPECIES.length());
3735         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3736 
3737         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3738             for (int i = 0; i < a.length; i += SPECIES.length()) {
3739                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3740                 av.lanewise(VectorOperators.ZOMO, vmask).intoArray(r, i);
3741             }
3742         }
3743 
3744         assertArraysEquals(a, r, mask, Byte128VectorTests::ZOMO);
3745     }
3746 
3747 
3748 
3749 
3750     static byte[] gather(byte a[], int ix, int[] b, int iy) {
3751         byte[] res = new byte[SPECIES.length()];
3752         for (int i = 0; i < SPECIES.length(); i++) {
3753             int bi = iy + i;
3754             res[i] = a[b[bi] + ix];
3755         }
3756         return res;
3757     }
3758 
3759     @Test(dataProvider = "byteUnaryOpIndexProvider")
3760     static void gatherByte128VectorTests(IntFunction<byte[]> fa, BiFunction<Integer,Integer,int[]> fs) {
3761         byte[] a = fa.apply(SPECIES.length());
3762         int[] b    = fs.apply(a.length, SPECIES.length());
3763         byte[] r = new byte[a.length];
3764 
3765         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3766             for (int i = 0; i < a.length; i += SPECIES.length()) {
3767                 ByteVector av = ByteVector.fromArray(SPECIES, a, i, b, i);
3768                 av.intoArray(r, i);
3769             }
3770         }
3771 
3772         assertArraysEquals(a, b, r, Byte128VectorTests::gather);
3773     }
3774     static byte[] gatherMasked(byte a[], int ix, boolean[] mask, int[] b, int iy) {
3775         byte[] res = new byte[SPECIES.length()];
3776         for (int i = 0; i < SPECIES.length(); i++) {
3777             int bi = iy + i;
3778             if (mask[i]) {
3779               res[i] = a[b[bi] + ix];
3780             }
3781         }
3782         return res;
3783     }
3784 
3785     @Test(dataProvider = "byteUnaryMaskedOpIndexProvider")
3786     static void gatherMaskedByte128VectorTests(IntFunction<byte[]> fa, BiFunction<Integer,Integer,int[]> fs, IntFunction<boolean[]> fm) {
3787         byte[] a = fa.apply(SPECIES.length());
3788         int[] b    = fs.apply(a.length, SPECIES.length());
3789         byte[] r = new byte[a.length];
3790         boolean[] mask = fm.apply(SPECIES.length());
3791         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3792 
3793         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3794             for (int i = 0; i < a.length; i += SPECIES.length()) {
3795                 ByteVector av = ByteVector.fromArray(SPECIES, a, i, b, i, vmask);
3796                 av.intoArray(r, i);
3797             }
3798         }
3799 
3800         assertArraysEquals(a, b, r, mask, Byte128VectorTests::gatherMasked);
3801     }
3802 
3803     static byte[] scatter(byte a[], int ix, int[] b, int iy) {
3804       byte[] res = new byte[SPECIES.length()];
3805       for (int i = 0; i < SPECIES.length(); i++) {
3806         int bi = iy + i;
3807         res[b[bi]] = a[i + ix];
3808       }
3809       return res;
3810     }
3811 
3812     @Test(dataProvider = "byteUnaryOpIndexProvider")
3813     static void scatterByte128VectorTests(IntFunction<byte[]> fa, BiFunction<Integer,Integer,int[]> fs) {
3814         byte[] a = fa.apply(SPECIES.length());
3815         int[] b = fs.apply(a.length, SPECIES.length());
3816         byte[] r = new byte[a.length];
3817 
3818         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3819             for (int i = 0; i < a.length; i += SPECIES.length()) {
3820                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3821                 av.intoArray(r, i, b, i);
3822             }
3823         }
3824 
3825         assertArraysEquals(a, b, r, Byte128VectorTests::scatter);
3826     }
3827 
3828     static byte[] scatterMasked(byte r[], byte a[], int ix, boolean[] mask, int[] b, int iy) {
3829       // First, gather r.
3830       byte[] oldVal = gather(r, ix, b, iy);
3831       byte[] newVal = new byte[SPECIES.length()];
3832 
3833       // Second, blending it with a.
3834       for (int i = 0; i < SPECIES.length(); i++) {
3835         newVal[i] = blend(oldVal[i], a[i+ix], mask[i]);
3836       }
3837 
3838       // Third, scatter: copy old value of r, and scatter it manually.
3839       byte[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length());
3840       for (int i = 0; i < SPECIES.length(); i++) {
3841         int bi = iy + i;
3842         res[b[bi]] = newVal[i];
3843       }
3844 
3845       return res;
3846     }
3847 
3848     @Test(dataProvider = "scatterMaskedOpIndexProvider")
3849     static void scatterMaskedByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, BiFunction<Integer,Integer,int[]> fs, IntFunction<boolean[]> fm) {
3850         byte[] a = fa.apply(SPECIES.length());
3851         int[] b = fs.apply(a.length, SPECIES.length());
3852         byte[] r = fb.apply(SPECIES.length());
3853         boolean[] mask = fm.apply(SPECIES.length());
3854         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3855 
3856         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3857             for (int i = 0; i < a.length; i += SPECIES.length()) {
3858                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3859                 av.intoArray(r, i, b, i, vmask);
3860             }
3861         }
3862 
3863         assertArraysEquals(a, b, r, mask, Byte128VectorTests::scatterMasked);
3864     }
3865 
3866 }
3867