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