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