1 /*
   2  * Copyright (c) 2018, 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
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @modules jdk.incubator.vector
  27  * @run testng/othervm -ea -esa ByteMaxVectorTests
  28  */
  29 
  30 import jdk.incubator.vector.VectorShape;
  31 import jdk.incubator.vector.VectorSpecies;
  32 import jdk.incubator.vector.VectorShuffle;
  33 import jdk.incubator.vector.VectorMask;
  34 import jdk.incubator.vector.Vector;
  35 
  36 import jdk.incubator.vector.ByteVector;
  37 
  38 import org.testng.Assert;
  39 import org.testng.annotations.DataProvider;
  40 import org.testng.annotations.Test;
  41 
  42 import java.lang.Integer;
  43 import java.util.List;
  44 import java.util.function.BiFunction;
  45 import java.util.function.IntFunction;
  46 import java.util.stream.Collectors;
  47 import java.util.stream.Stream;
  48 
  49 @Test
  50 public class ByteMaxVectorTests extends AbstractVectorTest {
  51 
  52     static final VectorSpecies<Byte> SPECIES =
  53                 ByteVector.SPECIES_MAX;
  54 
  55     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  56 
  57     static VectorShape getMaxBit() {
  58         return VectorShape.S_Max_BIT;
  59     }
  60 
  61     interface FUnOp {
  62         byte apply(byte a);
  63     }
  64 
  65     static void assertArraysEquals(byte[] a, byte[] r, FUnOp f) {
  66         int i = 0;
  67         try {
  68             for (; i < a.length; i++) {
  69                 Assert.assertEquals(r[i], f.apply(a[i]));
  70             }
  71         } catch (AssertionError e) {
  72             Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
  73         }
  74     }
  75 
  76     static void assertArraysEquals(byte[] a, byte[] r, boolean[] mask, FUnOp f) {
  77         int i = 0;
  78         try {
  79             for (; i < a.length; i++) {
  80                 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]);
  81             }
  82         } catch (AssertionError e) {
  83             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()]);
  84         }
  85     }
  86 
  87     interface FReductionOp {
  88         byte apply(byte[] a, int idx);
  89     }
  90 
  91     interface FReductionAllOp {
  92         byte apply(byte[] a);
  93     }
  94 
  95     static void assertReductionArraysEquals(byte[] a, byte[] b, byte c,
  96                                             FReductionOp f, FReductionAllOp fa) {
  97         int i = 0;
  98         try {
  99             Assert.assertEquals(c, fa.apply(a));
 100             for (; i < a.length; i += SPECIES.length()) {
 101                 Assert.assertEquals(b[i], f.apply(a, i));
 102             }
 103         } catch (AssertionError e) {
 104             Assert.assertEquals(c, fa.apply(a), "Final result is incorrect!");
 105             Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i);
 106         }
 107     }
 108 
 109     interface FBoolReductionOp {
 110         boolean apply(boolean[] a, int idx);
 111     }
 112 
 113     static void assertReductionBoolArraysEquals(boolean[] a, boolean[] b, FBoolReductionOp f) {
 114         int i = 0;
 115         try {
 116             for (; i < a.length; i += SPECIES.length()) {
 117                 Assert.assertEquals(f.apply(a, i), b[i]);
 118             }
 119         } catch (AssertionError e) {
 120             Assert.assertEquals(f.apply(a, i), b[i], "at index #" + i);
 121         }
 122     }
 123 
 124     static void assertInsertArraysEquals(byte[] a, byte[] b, byte element, int index) {
 125         int i = 0;
 126         try {
 127             for (; i < a.length; i += 1) {
 128                 if(i%SPECIES.length() == index) {
 129                     Assert.assertEquals(b[i], element);
 130                 } else {
 131                     Assert.assertEquals(b[i], a[i]);
 132                 }
 133             }
 134         } catch (AssertionError e) {
 135             if (i%SPECIES.length() == index) {
 136                 Assert.assertEquals(b[i], element, "at index #" + i);
 137             } else {
 138                 Assert.assertEquals(b[i], a[i], "at index #" + i);
 139             }
 140         }
 141     }
 142 
 143     static void assertRearrangeArraysEquals(byte[] a, byte[] r, int[] order, int vector_len) {
 144         int i = 0, j = 0;
 145         try {
 146             for (; i < a.length; i += vector_len) {
 147                 for (j = 0; j < vector_len; j++) {
 148                     Assert.assertEquals(r[i+j], a[i+order[i+j]]);
 149                 }
 150             }
 151         } catch (AssertionError e) {
 152             int idx = i + j;
 153             Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
 154         }
 155     }
 156 
 157     interface FBinOp {
 158         byte apply(byte a, byte b);
 159     }
 160 
 161     interface FBinMaskOp {
 162         byte apply(byte a, byte b, boolean m);
 163 
 164         static FBinMaskOp lift(FBinOp f) {
 165             return (a, b, m) -> m ? f.apply(a, b) : a;
 166         }
 167     }
 168 
 169     static void assertArraysEquals(byte[] a, byte[] b, byte[] r, FBinOp f) {
 170         int i = 0;
 171         try {
 172             for (; i < a.length; i++) {
 173                 Assert.assertEquals(r[i], f.apply(a[i], b[i]));
 174             }
 175         } catch (AssertionError e) {
 176             Assert.assertEquals(f.apply(a[i], b[i]), r[i], "(" + a[i] + ", " + b[i] + ") at index #" + i);
 177         }
 178     }
 179 
 180     static void assertArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) {
 181         assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 182     }
 183 
 184     static void assertArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) {
 185         int i = 0;
 186         try {
 187             for (; i < a.length; i++) {
 188                 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]));
 189             }
 190         } catch (AssertionError err) {
 191             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()]);
 192         }
 193     }
 194 
 195     static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, FBinOp f) {
 196         int i = 0;
 197         int j = 0;
 198         try {
 199             for (; j < a.length; j += SPECIES.length()) {
 200                 for (i = 0; i < SPECIES.length(); i++) {
 201                     Assert.assertEquals(f.apply(a[i+j], b[j]), r[i+j]);
 202                 }
 203             }
 204         } catch (AssertionError e) {
 205             Assert.assertEquals(f.apply(a[i+j], b[j]), r[i+j], "at index #" + i + ", " + j);
 206         }
 207     }
 208 
 209     static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) {
 210         assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f));
 211     }
 212 
 213     static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) {
 214         int i = 0;
 215         int j = 0;
 216         try {
 217             for (; j < a.length; j += SPECIES.length()) {
 218                 for (i = 0; i < SPECIES.length(); i++) {
 219                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i]));
 220                 }
 221             }
 222         } catch (AssertionError err) {
 223             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]);
 224         }
 225     }
 226 
 227 
 228     interface FBinArrayOp {
 229         byte apply(byte[] a, int b);
 230     }
 231 
 232     static void assertArraysEquals(byte[] a, byte[] r, FBinArrayOp f) {
 233         int i = 0;
 234         try {
 235             for (; i < a.length; i++) {
 236                 Assert.assertEquals(f.apply(a, i), r[i]);
 237             }
 238         } catch (AssertionError e) {
 239             Assert.assertEquals(f.apply(a,i), r[i], "at index #" + i);
 240         }
 241     }
 242 
 243     static final List<IntFunction<byte[]>> BYTE_GENERATORS = List.of(
 244             withToString("byte[-i * 5]", (int s) -> {
 245                 return fill(s * 1000,
 246                             i -> (byte)(-i * 5));
 247             }),
 248             withToString("byte[i * 5]", (int s) -> {
 249                 return fill(s * 1000,
 250                             i -> (byte)(i * 5));
 251             }),
 252             withToString("byte[i + 1]", (int s) -> {
 253                 return fill(s * 1000,
 254                             i -> (((byte)(i + 1) == 0) ? 1 : (byte)(i + 1)));
 255             }),
 256             withToString("byte[cornerCaseValue(i)]", (int s) -> {
 257                 return fill(s * 1000,
 258                             i -> cornerCaseValue(i));
 259             })
 260     );
 261 
 262     // Create combinations of pairs
 263     // @@@ Might be sensitive to order e.g. div by 0
 264     static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_PAIRS =
 265         Stream.of(BYTE_GENERATORS.get(0)).
 266                 flatMap(fa -> BYTE_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
 267                 collect(Collectors.toList());
 268 
 269     @DataProvider
 270     public Object[][] boolUnaryOpProvider() {
 271         return BOOL_ARRAY_GENERATORS.stream().
 272                 map(f -> new Object[]{f}).
 273                 toArray(Object[][]::new);
 274     }
 275 
 276 
 277     @DataProvider
 278     public Object[][] byteBinaryOpProvider() {
 279         return BYTE_GENERATOR_PAIRS.stream().map(List::toArray).
 280                 toArray(Object[][]::new);
 281     }
 282 
 283     @DataProvider
 284     public Object[][] byteIndexedOpProvider() {
 285         return BYTE_GENERATOR_PAIRS.stream().map(List::toArray).
 286                 toArray(Object[][]::new);
 287     }
 288 
 289     @DataProvider
 290     public Object[][] byteBinaryOpMaskProvider() {
 291         return BOOLEAN_MASK_GENERATORS.stream().
 292                 flatMap(fm -> BYTE_GENERATOR_PAIRS.stream().map(lfa -> {
 293                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
 294                 })).
 295                 toArray(Object[][]::new);
 296     }
 297 
 298 
 299     @DataProvider
 300     public Object[][] byteUnaryOpProvider() {
 301         return BYTE_GENERATORS.stream().
 302                 map(f -> new Object[]{f}).
 303                 toArray(Object[][]::new);
 304     }
 305 
 306     @DataProvider
 307     public Object[][] byteUnaryOpMaskProvider() {
 308         return BOOLEAN_MASK_GENERATORS.stream().
 309                 flatMap(fm -> BYTE_GENERATORS.stream().map(fa -> {
 310                     return new Object[] {fa, fm};
 311                 })).
 312                 toArray(Object[][]::new);
 313     }
 314 
 315     @DataProvider
 316     public Object[][] byteUnaryOpShuffleProvider() {
 317         return INT_SHUFFLE_GENERATORS.stream().
 318                 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> {
 319                     return new Object[] {fa, fs};
 320                 })).
 321                 toArray(Object[][]::new);
 322     }
 323 
 324     @DataProvider
 325     public Object[][] byteUnaryOpIndexProvider() {
 326         return INT_INDEX_GENERATORS.stream().
 327                 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> {
 328                     return new Object[] {fa, fs};
 329                 })).
 330                 toArray(Object[][]::new);
 331     }
 332 
 333 
 334     static final List<IntFunction<byte[]>> BYTE_COMPARE_GENERATORS = List.of(
 335             withToString("byte[i]", (int s) -> {
 336                 return fill(s * 1000,
 337                             i -> (byte)i);
 338             }),
 339             withToString("byte[i + 1]", (int s) -> {
 340                 return fill(s * 1000,
 341                             i -> (byte)(i + 1));
 342             }),
 343             withToString("byte[i - 2]", (int s) -> {
 344                 return fill(s * 1000,
 345                             i -> (byte)(i - 2));
 346             }),
 347             withToString("byte[zigZag(i)]", (int s) -> {
 348                 return fill(s * 1000,
 349                             i -> i%3 == 0 ? (byte)i : (i%3 == 1 ? (byte)(i + 1) : (byte)(i - 2)));
 350             }),
 351             withToString("byte[cornerCaseValue(i)]", (int s) -> {
 352                 return fill(s * 1000,
 353                             i -> cornerCaseValue(i));
 354             })
 355     );
 356 
 357     static final List<List<IntFunction<byte[]>>> BYTE_COMPARE_GENERATOR_PAIRS =
 358         BYTE_COMPARE_GENERATORS.stream().
 359                 flatMap(fa -> BYTE_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))).
 360                 collect(Collectors.toList());
 361 
 362     @DataProvider
 363     public Object[][] byteCompareOpProvider() {
 364         return BYTE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
 365                 toArray(Object[][]::new);
 366     }
 367 
 368     interface ToByteF {
 369         byte apply(int i);
 370     }
 371 
 372     static byte[] fill(int s , ToByteF f) {
 373         return fill(new byte[s], f);
 374     }
 375 
 376     static byte[] fill(byte[] a, ToByteF f) {
 377         for (int i = 0; i < a.length; i++) {
 378             a[i] = f.apply(i);
 379         }
 380         return a;
 381     }
 382 
 383     static byte cornerCaseValue(int i) {
 384         switch(i % 5) {
 385             case 0:
 386                 return Byte.MAX_VALUE;
 387             case 1:
 388                 return Byte.MIN_VALUE;
 389             case 2:
 390                 return Byte.MIN_VALUE;
 391             case 3:
 392                 return Byte.MAX_VALUE;
 393             default:
 394                 return (byte)0;
 395         }
 396     }
 397    static byte get(byte[] a, int i) {
 398        return (byte) a[i];
 399    }
 400 
 401    static final IntFunction<byte[]> fr = (vl) -> {
 402         int length = 1000 * vl;
 403         return new byte[length];
 404     };
 405 
 406     static final IntFunction<boolean[]> fmr = (vl) -> {
 407         int length = 1000 * vl;
 408         return new boolean[length];
 409     };
 410     static byte add(byte a, byte b) {
 411         return (byte)(a + b);
 412     }
 413 
 414     @Test(dataProvider = "byteBinaryOpProvider")
 415     static void addByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 416         byte[] a = fa.apply(SPECIES.length());
 417         byte[] b = fb.apply(SPECIES.length());
 418         byte[] r = fr.apply(SPECIES.length());
 419 
 420         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 421             for (int i = 0; i < a.length; i += SPECIES.length()) {
 422                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 423                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 424                 av.add(bv).intoArray(r, i);
 425             }
 426         }
 427 
 428         assertArraysEquals(a, b, r, ByteMaxVectorTests::add);
 429     }
 430 
 431     @Test(dataProvider = "byteBinaryOpMaskProvider")
 432     static void addByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 433                                           IntFunction<boolean[]> fm) {
 434         byte[] a = fa.apply(SPECIES.length());
 435         byte[] b = fb.apply(SPECIES.length());
 436         byte[] r = fr.apply(SPECIES.length());
 437         boolean[] mask = fm.apply(SPECIES.length());
 438         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 439 
 440         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 441             for (int i = 0; i < a.length; i += SPECIES.length()) {
 442                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 443                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 444                 av.add(bv, vmask).intoArray(r, i);
 445             }
 446         }
 447 
 448         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::add);
 449     }
 450     static byte sub(byte a, byte b) {
 451         return (byte)(a - b);
 452     }
 453 
 454     @Test(dataProvider = "byteBinaryOpProvider")
 455     static void subByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 456         byte[] a = fa.apply(SPECIES.length());
 457         byte[] b = fb.apply(SPECIES.length());
 458         byte[] r = fr.apply(SPECIES.length());
 459 
 460         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 461             for (int i = 0; i < a.length; i += SPECIES.length()) {
 462                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 463                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 464                 av.sub(bv).intoArray(r, i);
 465             }
 466         }
 467 
 468         assertArraysEquals(a, b, r, ByteMaxVectorTests::sub);
 469     }
 470 
 471     @Test(dataProvider = "byteBinaryOpMaskProvider")
 472     static void subByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 473                                           IntFunction<boolean[]> fm) {
 474         byte[] a = fa.apply(SPECIES.length());
 475         byte[] b = fb.apply(SPECIES.length());
 476         byte[] r = fr.apply(SPECIES.length());
 477         boolean[] mask = fm.apply(SPECIES.length());
 478         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 479 
 480         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 481             for (int i = 0; i < a.length; i += SPECIES.length()) {
 482                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 483                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 484                 av.sub(bv, vmask).intoArray(r, i);
 485             }
 486         }
 487 
 488         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::sub);
 489     }
 490 
 491 
 492     static byte mul(byte a, byte b) {
 493         return (byte)(a * b);
 494     }
 495 
 496     @Test(dataProvider = "byteBinaryOpProvider")
 497     static void mulByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 498         byte[] a = fa.apply(SPECIES.length());
 499         byte[] b = fb.apply(SPECIES.length());
 500         byte[] r = fr.apply(SPECIES.length());
 501 
 502         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 503             for (int i = 0; i < a.length; i += SPECIES.length()) {
 504                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 505                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 506                 av.mul(bv).intoArray(r, i);
 507             }
 508         }
 509 
 510         assertArraysEquals(a, b, r, ByteMaxVectorTests::mul);
 511     }
 512 
 513     @Test(dataProvider = "byteBinaryOpMaskProvider")
 514     static void mulByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 515                                           IntFunction<boolean[]> fm) {
 516         byte[] a = fa.apply(SPECIES.length());
 517         byte[] b = fb.apply(SPECIES.length());
 518         byte[] r = fr.apply(SPECIES.length());
 519         boolean[] mask = fm.apply(SPECIES.length());
 520         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 521 
 522         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 523             for (int i = 0; i < a.length; i += SPECIES.length()) {
 524                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 525                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 526                 av.mul(bv, vmask).intoArray(r, i);
 527             }
 528         }
 529 
 530         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::mul);
 531     }
 532 
 533     static byte and(byte a, byte b) {
 534         return (byte)(a & b);
 535     }
 536 
 537     @Test(dataProvider = "byteBinaryOpProvider")
 538     static void andByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 539         byte[] a = fa.apply(SPECIES.length());
 540         byte[] b = fb.apply(SPECIES.length());
 541         byte[] r = fr.apply(SPECIES.length());
 542 
 543         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 544             for (int i = 0; i < a.length; i += SPECIES.length()) {
 545                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 546                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 547                 av.and(bv).intoArray(r, i);
 548             }
 549         }
 550 
 551         assertArraysEquals(a, b, r, ByteMaxVectorTests::and);
 552     }
 553 
 554 
 555 
 556     @Test(dataProvider = "byteBinaryOpMaskProvider")
 557     static void andByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 558                                           IntFunction<boolean[]> fm) {
 559         byte[] a = fa.apply(SPECIES.length());
 560         byte[] b = fb.apply(SPECIES.length());
 561         byte[] r = fr.apply(SPECIES.length());
 562         boolean[] mask = fm.apply(SPECIES.length());
 563         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 564 
 565         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 566             for (int i = 0; i < a.length; i += SPECIES.length()) {
 567                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 568                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 569                 av.and(bv, vmask).intoArray(r, i);
 570             }
 571         }
 572 
 573         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::and);
 574     }
 575 
 576 
 577     static byte or(byte a, byte b) {
 578         return (byte)(a | b);
 579     }
 580 
 581     @Test(dataProvider = "byteBinaryOpProvider")
 582     static void orByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 583         byte[] a = fa.apply(SPECIES.length());
 584         byte[] b = fb.apply(SPECIES.length());
 585         byte[] r = fr.apply(SPECIES.length());
 586 
 587         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 588             for (int i = 0; i < a.length; i += SPECIES.length()) {
 589                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 590                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 591                 av.or(bv).intoArray(r, i);
 592             }
 593         }
 594 
 595         assertArraysEquals(a, b, r, ByteMaxVectorTests::or);
 596     }
 597 
 598 
 599 
 600     @Test(dataProvider = "byteBinaryOpMaskProvider")
 601     static void orByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 602                                           IntFunction<boolean[]> fm) {
 603         byte[] a = fa.apply(SPECIES.length());
 604         byte[] b = fb.apply(SPECIES.length());
 605         byte[] r = fr.apply(SPECIES.length());
 606         boolean[] mask = fm.apply(SPECIES.length());
 607         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 608 
 609         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 610             for (int i = 0; i < a.length; i += SPECIES.length()) {
 611                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 612                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 613                 av.or(bv, vmask).intoArray(r, i);
 614             }
 615         }
 616 
 617         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::or);
 618     }
 619 
 620 
 621     static byte xor(byte a, byte b) {
 622         return (byte)(a ^ b);
 623     }
 624 
 625     @Test(dataProvider = "byteBinaryOpProvider")
 626     static void xorByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 627         byte[] a = fa.apply(SPECIES.length());
 628         byte[] b = fb.apply(SPECIES.length());
 629         byte[] r = fr.apply(SPECIES.length());
 630 
 631         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 632             for (int i = 0; i < a.length; i += SPECIES.length()) {
 633                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 634                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 635                 av.xor(bv).intoArray(r, i);
 636             }
 637         }
 638 
 639         assertArraysEquals(a, b, r, ByteMaxVectorTests::xor);
 640     }
 641 
 642 
 643 
 644     @Test(dataProvider = "byteBinaryOpMaskProvider")
 645     static void xorByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 646                                           IntFunction<boolean[]> fm) {
 647         byte[] a = fa.apply(SPECIES.length());
 648         byte[] b = fb.apply(SPECIES.length());
 649         byte[] r = fr.apply(SPECIES.length());
 650         boolean[] mask = fm.apply(SPECIES.length());
 651         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 652 
 653         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 654             for (int i = 0; i < a.length; i += SPECIES.length()) {
 655                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 656                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 657                 av.xor(bv, vmask).intoArray(r, i);
 658             }
 659         }
 660 
 661         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::xor);
 662     }
 663 
 664 
 665 
 666 
 667 
 668 
 669 
 670 
 671 
 672 
 673 
 674 
 675 
 676 
 677     static byte aShiftR_unary(byte a, byte b) {
 678         return (byte)((a >> (b & 7)));
 679     }
 680 
 681     @Test(dataProvider = "byteBinaryOpProvider")
 682     static void aShiftRByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 683         byte[] a = fa.apply(SPECIES.length());
 684         byte[] b = fb.apply(SPECIES.length());
 685         byte[] r = fr.apply(SPECIES.length());
 686 
 687         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 688             for (int i = 0; i < a.length; i += SPECIES.length()) {
 689                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 690                 av.aShiftR((int)b[i]).intoArray(r, i);
 691             }
 692         }
 693 
 694         assertShiftArraysEquals(a, b, r, ByteMaxVectorTests::aShiftR_unary);
 695     }
 696 
 697 
 698 
 699     @Test(dataProvider = "byteBinaryOpMaskProvider")
 700     static void aShiftRByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 701                                           IntFunction<boolean[]> fm) {
 702         byte[] a = fa.apply(SPECIES.length());
 703         byte[] b = fb.apply(SPECIES.length());
 704         byte[] r = fr.apply(SPECIES.length());
 705         boolean[] mask = fm.apply(SPECIES.length());
 706         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 707 
 708         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 709             for (int i = 0; i < a.length; i += SPECIES.length()) {
 710                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 711                 av.aShiftR((int)b[i], vmask).intoArray(r, i);
 712             }
 713         }
 714 
 715         assertShiftArraysEquals(a, b, r, mask, ByteMaxVectorTests::aShiftR_unary);
 716     }
 717 
 718 
 719     static byte shiftL_unary(byte a, byte b) {
 720         return (byte)((a << (b & 7)));
 721     }
 722 
 723     @Test(dataProvider = "byteBinaryOpProvider")
 724     static void shiftLByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 725         byte[] a = fa.apply(SPECIES.length());
 726         byte[] b = fb.apply(SPECIES.length());
 727         byte[] r = fr.apply(SPECIES.length());
 728 
 729         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 730             for (int i = 0; i < a.length; i += SPECIES.length()) {
 731                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 732                 av.shiftL((int)b[i]).intoArray(r, i);
 733             }
 734         }
 735 
 736         assertShiftArraysEquals(a, b, r, ByteMaxVectorTests::shiftL_unary);
 737     }
 738 
 739 
 740 
 741     @Test(dataProvider = "byteBinaryOpMaskProvider")
 742     static void shiftLByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 743                                           IntFunction<boolean[]> fm) {
 744         byte[] a = fa.apply(SPECIES.length());
 745         byte[] b = fb.apply(SPECIES.length());
 746         byte[] r = fr.apply(SPECIES.length());
 747         boolean[] mask = fm.apply(SPECIES.length());
 748         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 749 
 750         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 751             for (int i = 0; i < a.length; i += SPECIES.length()) {
 752                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 753                 av.shiftL((int)b[i], vmask).intoArray(r, i);
 754             }
 755         }
 756 
 757         assertShiftArraysEquals(a, b, r, mask, ByteMaxVectorTests::shiftL_unary);
 758     }
 759 
 760 
 761     static byte shiftR_unary(byte a, byte b) {
 762         return (byte)(((a & 0xFF) >>> (b & 7)));
 763     }
 764 
 765     @Test(dataProvider = "byteBinaryOpProvider")
 766     static void shiftRByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 767         byte[] a = fa.apply(SPECIES.length());
 768         byte[] b = fb.apply(SPECIES.length());
 769         byte[] r = fr.apply(SPECIES.length());
 770 
 771         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 772             for (int i = 0; i < a.length; i += SPECIES.length()) {
 773                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 774                 av.shiftR((int)b[i]).intoArray(r, i);
 775             }
 776         }
 777 
 778         assertShiftArraysEquals(a, b, r, ByteMaxVectorTests::shiftR_unary);
 779     }
 780 
 781 
 782 
 783     @Test(dataProvider = "byteBinaryOpMaskProvider")
 784     static void shiftRByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 785                                           IntFunction<boolean[]> fm) {
 786         byte[] a = fa.apply(SPECIES.length());
 787         byte[] b = fb.apply(SPECIES.length());
 788         byte[] r = fr.apply(SPECIES.length());
 789         boolean[] mask = fm.apply(SPECIES.length());
 790         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 791 
 792         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 793             for (int i = 0; i < a.length; i += SPECIES.length()) {
 794                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 795                 av.shiftR((int)b[i], vmask).intoArray(r, i);
 796             }
 797         }
 798 
 799         assertShiftArraysEquals(a, b, r, mask, ByteMaxVectorTests::shiftR_unary);
 800     }
 801 
 802 
 803 
 804 
 805 
 806 
 807 
 808     static byte max(byte a, byte b) {
 809         return (byte)(Math.max(a, b));
 810     }
 811 
 812     @Test(dataProvider = "byteBinaryOpProvider")
 813     static void maxByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 814         byte[] a = fa.apply(SPECIES.length());
 815         byte[] b = fb.apply(SPECIES.length());
 816         byte[] r = fr.apply(SPECIES.length());
 817 
 818         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 819             for (int i = 0; i < a.length; i += SPECIES.length()) {
 820                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 821                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 822                 av.max(bv).intoArray(r, i);
 823             }
 824         }
 825 
 826         assertArraysEquals(a, b, r, ByteMaxVectorTests::max);
 827     }
 828     static byte min(byte a, byte b) {
 829         return (byte)(Math.min(a, b));
 830     }
 831 
 832     @Test(dataProvider = "byteBinaryOpProvider")
 833     static void minByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 834         byte[] a = fa.apply(SPECIES.length());
 835         byte[] b = fb.apply(SPECIES.length());
 836         byte[] r = fr.apply(SPECIES.length());
 837 
 838         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 839             for (int i = 0; i < a.length; i += SPECIES.length()) {
 840                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 841                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 842                 av.min(bv).intoArray(r, i);
 843             }
 844         }
 845 
 846         assertArraysEquals(a, b, r, ByteMaxVectorTests::min);
 847     }
 848 
 849     static byte andAll(byte[] a, int idx) {
 850         byte res = -1;
 851         for (int i = idx; i < (idx + SPECIES.length()); i++) {
 852             res &= a[i];
 853         }
 854 
 855         return res;
 856     }
 857 
 858     static byte andAll(byte[] a) {
 859         byte res = -1;
 860         for (int i = 0; i < a.length; i += SPECIES.length()) {
 861             byte tmp = -1;
 862             for (int j = 0; j < SPECIES.length(); j++) {
 863                 tmp &= a[i + j];
 864             }
 865             res &= tmp;
 866         }
 867 
 868         return res;
 869     }
 870 
 871 
 872     @Test(dataProvider = "byteUnaryOpProvider")
 873     static void andAllByteMaxVectorTests(IntFunction<byte[]> fa) {
 874         byte[] a = fa.apply(SPECIES.length());
 875         byte[] r = fr.apply(SPECIES.length());
 876         byte ra = -1;
 877 
 878         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 879             for (int i = 0; i < a.length; i += SPECIES.length()) {
 880                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 881                 r[i] = av.andAll();
 882             }
 883         }
 884 
 885         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 886             ra = -1;
 887             for (int i = 0; i < a.length; i += SPECIES.length()) {
 888                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 889                 ra &= av.andAll();
 890             }
 891         }
 892 
 893         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::andAll, ByteMaxVectorTests::andAll);
 894     }
 895 
 896 
 897     static byte orAll(byte[] a, int idx) {
 898         byte res = 0;
 899         for (int i = idx; i < (idx + SPECIES.length()); i++) {
 900             res |= a[i];
 901         }
 902 
 903         return res;
 904     }
 905 
 906     static byte orAll(byte[] a) {
 907         byte res = 0;
 908         for (int i = 0; i < a.length; i += SPECIES.length()) {
 909             byte tmp = 0;
 910             for (int j = 0; j < SPECIES.length(); j++) {
 911                 tmp |= a[i + j];
 912             }
 913             res |= tmp;
 914         }
 915 
 916         return res;
 917     }
 918 
 919 
 920     @Test(dataProvider = "byteUnaryOpProvider")
 921     static void orAllByteMaxVectorTests(IntFunction<byte[]> fa) {
 922         byte[] a = fa.apply(SPECIES.length());
 923         byte[] r = fr.apply(SPECIES.length());
 924         byte ra = 0;
 925 
 926         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 927             for (int i = 0; i < a.length; i += SPECIES.length()) {
 928                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 929                 r[i] = av.orAll();
 930             }
 931         }
 932 
 933         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 934             ra = 0;
 935             for (int i = 0; i < a.length; i += SPECIES.length()) {
 936                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 937                 ra |= av.orAll();
 938             }
 939         }
 940 
 941         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::orAll, ByteMaxVectorTests::orAll);
 942     }
 943 
 944 
 945     static byte xorAll(byte[] a, int idx) {
 946         byte res = 0;
 947         for (int i = idx; i < (idx + SPECIES.length()); i++) {
 948             res ^= a[i];
 949         }
 950 
 951         return res;
 952     }
 953 
 954     static byte xorAll(byte[] a) {
 955         byte res = 0;
 956         for (int i = 0; i < a.length; i += SPECIES.length()) {
 957             byte tmp = 0;
 958             for (int j = 0; j < SPECIES.length(); j++) {
 959                 tmp ^= a[i + j];
 960             }
 961             res ^= tmp;
 962         }
 963 
 964         return res;
 965     }
 966 
 967 
 968     @Test(dataProvider = "byteUnaryOpProvider")
 969     static void xorAllByteMaxVectorTests(IntFunction<byte[]> fa) {
 970         byte[] a = fa.apply(SPECIES.length());
 971         byte[] r = fr.apply(SPECIES.length());
 972         byte ra = 0;
 973 
 974         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 975             for (int i = 0; i < a.length; i += SPECIES.length()) {
 976                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 977                 r[i] = av.xorAll();
 978             }
 979         }
 980 
 981         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 982             ra = 0;
 983             for (int i = 0; i < a.length; i += SPECIES.length()) {
 984                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 985                 ra ^= av.xorAll();
 986             }
 987         }
 988 
 989         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::xorAll, ByteMaxVectorTests::xorAll);
 990     }
 991 
 992     static byte addAll(byte[] a, int idx) {
 993         byte res = 0;
 994         for (int i = idx; i < (idx + SPECIES.length()); i++) {
 995             res += a[i];
 996         }
 997 
 998         return res;
 999     }
1000 
1001     static byte addAll(byte[] a) {
1002         byte res = 0;
1003         for (int i = 0; i < a.length; i += SPECIES.length()) {
1004             byte tmp = 0;
1005             for (int j = 0; j < SPECIES.length(); j++) {
1006                 tmp += a[i + j];
1007             }
1008             res += tmp;
1009         }
1010 
1011         return res;
1012     }
1013     @Test(dataProvider = "byteUnaryOpProvider")
1014     static void addAllByteMaxVectorTests(IntFunction<byte[]> fa) {
1015         byte[] a = fa.apply(SPECIES.length());
1016         byte[] r = fr.apply(SPECIES.length());
1017         byte ra = 0;
1018 
1019         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1020             for (int i = 0; i < a.length; i += SPECIES.length()) {
1021                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1022                 r[i] = av.addAll();
1023             }
1024         }
1025 
1026         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1027             ra = 0;
1028             for (int i = 0; i < a.length; i += SPECIES.length()) {
1029                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1030                 ra += av.addAll();
1031             }
1032         }
1033 
1034         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::addAll, ByteMaxVectorTests::addAll);
1035     }
1036     static byte mulAll(byte[] a, int idx) {
1037         byte res = 1;
1038         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1039             res *= a[i];
1040         }
1041 
1042         return res;
1043     }
1044 
1045     static byte mulAll(byte[] a) {
1046         byte res = 1;
1047         for (int i = 0; i < a.length; i += SPECIES.length()) {
1048             byte tmp = 1;
1049             for (int j = 0; j < SPECIES.length(); j++) {
1050                 tmp *= a[i + j];
1051             }
1052             res *= tmp;
1053         }
1054 
1055         return res;
1056     }
1057     @Test(dataProvider = "byteUnaryOpProvider")
1058     static void mulAllByteMaxVectorTests(IntFunction<byte[]> fa) {
1059         byte[] a = fa.apply(SPECIES.length());
1060         byte[] r = fr.apply(SPECIES.length());
1061         byte ra = 1;
1062 
1063         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1064             for (int i = 0; i < a.length; i += SPECIES.length()) {
1065                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1066                 r[i] = av.mulAll();
1067             }
1068         }
1069 
1070         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1071             ra = 1;
1072             for (int i = 0; i < a.length; i += SPECIES.length()) {
1073                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1074                 ra *= av.mulAll();
1075             }
1076         }
1077 
1078         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::mulAll, ByteMaxVectorTests::mulAll);
1079     }
1080     static byte minAll(byte[] a, int idx) {
1081         byte res = Byte.MAX_VALUE;
1082         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1083             res = (byte)Math.min(res, a[i]);
1084         }
1085 
1086         return res;
1087     }
1088 
1089     static byte minAll(byte[] a) {
1090         byte res = Byte.MAX_VALUE;
1091         for (int i = 0; i < a.length; i++) {
1092             res = (byte)Math.min(res, a[i]);
1093         }
1094 
1095         return res;
1096     }
1097     @Test(dataProvider = "byteUnaryOpProvider")
1098     static void minAllByteMaxVectorTests(IntFunction<byte[]> fa) {
1099         byte[] a = fa.apply(SPECIES.length());
1100         byte[] r = fr.apply(SPECIES.length());
1101         byte ra = Byte.MAX_VALUE;
1102 
1103         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1104             for (int i = 0; i < a.length; i += SPECIES.length()) {
1105                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1106                 r[i] = av.minAll();
1107             }
1108         }
1109 
1110         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1111             ra = Byte.MAX_VALUE;
1112             for (int i = 0; i < a.length; i += SPECIES.length()) {
1113                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1114                 ra = (byte)Math.min(ra, av.minAll());
1115             }
1116         }
1117 
1118         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::minAll, ByteMaxVectorTests::minAll);
1119     }
1120     static byte maxAll(byte[] a, int idx) {
1121         byte res = Byte.MIN_VALUE;
1122         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1123             res = (byte)Math.max(res, a[i]);
1124         }
1125 
1126         return res;
1127     }
1128 
1129     static byte maxAll(byte[] a) {
1130         byte res = Byte.MIN_VALUE;
1131         for (int i = 0; i < a.length; i++) {
1132             res = (byte)Math.max(res, a[i]);
1133         }
1134 
1135         return res;
1136     }
1137     @Test(dataProvider = "byteUnaryOpProvider")
1138     static void maxAllByteMaxVectorTests(IntFunction<byte[]> fa) {
1139         byte[] a = fa.apply(SPECIES.length());
1140         byte[] r = fr.apply(SPECIES.length());
1141         byte ra = Byte.MIN_VALUE;
1142 
1143         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1144             for (int i = 0; i < a.length; i += SPECIES.length()) {
1145                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1146                 r[i] = av.maxAll();
1147             }
1148         }
1149 
1150         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1151             ra = Byte.MIN_VALUE;
1152             for (int i = 0; i < a.length; i += SPECIES.length()) {
1153                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1154                 ra = (byte)Math.max(ra, av.maxAll());
1155             }
1156         }
1157 
1158         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::maxAll, ByteMaxVectorTests::maxAll);
1159     }
1160 
1161     static boolean anyTrue(boolean[] a, int idx) {
1162         boolean res = false;
1163         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1164             res |= a[i];
1165         }
1166 
1167         return res;
1168     }
1169 
1170 
1171     @Test(dataProvider = "boolUnaryOpProvider")
1172     static void anyTrueByteMaxVectorTests(IntFunction<boolean[]> fm) {
1173         boolean[] mask = fm.apply(SPECIES.length());
1174         boolean[] r = fmr.apply(SPECIES.length());
1175 
1176         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1177             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1178                 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i);
1179                 r[i] = vmask.anyTrue();
1180             }
1181         }
1182 
1183         assertReductionBoolArraysEquals(mask, r, ByteMaxVectorTests::anyTrue);
1184     }
1185 
1186 
1187     static boolean allTrue(boolean[] a, int idx) {
1188         boolean res = true;
1189         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1190             res &= a[i];
1191         }
1192 
1193         return res;
1194     }
1195 
1196 
1197     @Test(dataProvider = "boolUnaryOpProvider")
1198     static void allTrueByteMaxVectorTests(IntFunction<boolean[]> fm) {
1199         boolean[] mask = fm.apply(SPECIES.length());
1200         boolean[] r = fmr.apply(SPECIES.length());
1201 
1202         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1203             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1204                 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i);
1205                 r[i] = vmask.allTrue();
1206             }
1207         }
1208 
1209         assertReductionBoolArraysEquals(mask, r, ByteMaxVectorTests::allTrue);
1210     }
1211 
1212 
1213     @Test(dataProvider = "byteUnaryOpProvider")
1214     static void withByteMaxVectorTests(IntFunction<byte []> fa) {
1215         byte[] a = fa.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                 av.with(0, (byte)4).intoArray(r, i);
1222             }
1223         }
1224 
1225         assertInsertArraysEquals(a, r, (byte)4, 0);
1226     }
1227 
1228     @Test(dataProvider = "byteCompareOpProvider")
1229     static void lessThanByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1230         byte[] a = fa.apply(SPECIES.length());
1231         byte[] b = fb.apply(SPECIES.length());
1232 
1233         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1234             for (int i = 0; i < a.length; i += SPECIES.length()) {
1235                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1236                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1237                 VectorMask<Byte> mv = av.lessThan(bv);
1238 
1239                 // Check results as part of computation.
1240                 for (int j = 0; j < SPECIES.length(); j++) {
1241                     Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]);
1242                 }
1243             }
1244         }
1245     }
1246 
1247 
1248     @Test(dataProvider = "byteCompareOpProvider")
1249     static void greaterThanByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1250         byte[] a = fa.apply(SPECIES.length());
1251         byte[] b = fb.apply(SPECIES.length());
1252 
1253         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1254             for (int i = 0; i < a.length; i += SPECIES.length()) {
1255                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1256                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1257                 VectorMask<Byte> mv = av.greaterThan(bv);
1258 
1259                 // Check results as part of computation.
1260                 for (int j = 0; j < SPECIES.length(); j++) {
1261                     Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]);
1262                 }
1263             }
1264         }
1265     }
1266 
1267 
1268     @Test(dataProvider = "byteCompareOpProvider")
1269     static void equalByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1270         byte[] a = fa.apply(SPECIES.length());
1271         byte[] b = fb.apply(SPECIES.length());
1272 
1273         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1274             for (int i = 0; i < a.length; i += SPECIES.length()) {
1275                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1276                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1277                 VectorMask<Byte> mv = av.equal(bv);
1278 
1279                 // Check results as part of computation.
1280                 for (int j = 0; j < SPECIES.length(); j++) {
1281                     Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]);
1282                 }
1283             }
1284         }
1285     }
1286 
1287 
1288     @Test(dataProvider = "byteCompareOpProvider")
1289     static void notEqualByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1290         byte[] a = fa.apply(SPECIES.length());
1291         byte[] b = fb.apply(SPECIES.length());
1292 
1293         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1294             for (int i = 0; i < a.length; i += SPECIES.length()) {
1295                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1296                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1297                 VectorMask<Byte> mv = av.notEqual(bv);
1298 
1299                 // Check results as part of computation.
1300                 for (int j = 0; j < SPECIES.length(); j++) {
1301                     Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]);
1302                 }
1303             }
1304         }
1305     }
1306 
1307 
1308     @Test(dataProvider = "byteCompareOpProvider")
1309     static void lessThanEqByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1310         byte[] a = fa.apply(SPECIES.length());
1311         byte[] b = fb.apply(SPECIES.length());
1312 
1313         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1314             for (int i = 0; i < a.length; i += SPECIES.length()) {
1315                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1316                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1317                 VectorMask<Byte> mv = av.lessThanEq(bv);
1318 
1319                 // Check results as part of computation.
1320                 for (int j = 0; j < SPECIES.length(); j++) {
1321                     Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]);
1322                 }
1323             }
1324         }
1325     }
1326 
1327 
1328     @Test(dataProvider = "byteCompareOpProvider")
1329     static void greaterThanEqByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1330         byte[] a = fa.apply(SPECIES.length());
1331         byte[] b = fb.apply(SPECIES.length());
1332 
1333         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1334             for (int i = 0; i < a.length; i += SPECIES.length()) {
1335                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1336                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1337                 VectorMask<Byte> mv = av.greaterThanEq(bv);
1338 
1339                 // Check results as part of computation.
1340                 for (int j = 0; j < SPECIES.length(); j++) {
1341                     Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]);
1342                 }
1343             }
1344         }
1345     }
1346 
1347 
1348     static byte blend(byte a, byte b, boolean mask) {
1349         return mask ? b : a;
1350     }
1351 
1352     @Test(dataProvider = "byteBinaryOpMaskProvider")
1353     static void blendByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1354                                           IntFunction<boolean[]> fm) {
1355         byte[] a = fa.apply(SPECIES.length());
1356         byte[] b = fb.apply(SPECIES.length());
1357         byte[] r = fr.apply(SPECIES.length());
1358         boolean[] mask = fm.apply(SPECIES.length());
1359         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1360 
1361         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1362             for (int i = 0; i < a.length; i += SPECIES.length()) {
1363                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1364                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1365                 av.blend(bv, vmask).intoArray(r, i);
1366             }
1367         }
1368 
1369         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::blend);
1370     }
1371 
1372     @Test(dataProvider = "byteUnaryOpShuffleProvider")
1373     static void RearrangeByteMaxVectorTests(IntFunction<byte[]> fa,
1374                                            BiFunction<Integer,Integer,int[]> fs) {
1375         byte[] a = fa.apply(SPECIES.length());
1376         int[] order = fs.apply(a.length, SPECIES.length());
1377         byte[] r = fr.apply(SPECIES.length());
1378 
1379         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1380             for (int i = 0; i < a.length; i += SPECIES.length()) {
1381                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1382                 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
1383             }
1384         }
1385 
1386         assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1387     }
1388 
1389 
1390 
1391 
1392     @Test(dataProvider = "byteUnaryOpProvider")
1393     static void getByteMaxVectorTests(IntFunction<byte[]> fa) {
1394         byte[] a = fa.apply(SPECIES.length());
1395         byte[] r = fr.apply(SPECIES.length());
1396 
1397         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1398             for (int i = 0; i < a.length; i += SPECIES.length()) {
1399                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1400                 int num_lanes = SPECIES.length();
1401                 // Manually unroll because full unroll happens after intrinsification.
1402                 // Unroll is needed because get intrinsic requires for index to be a known constant.
1403                 if (num_lanes == 1) {
1404                     r[i]=av.get(0);
1405                 } else if (num_lanes == 2) {
1406                     r[i]=av.get(0);
1407                     r[i+1]=av.get(1);
1408                 } else if (num_lanes == 4) {
1409                     r[i]=av.get(0);
1410                     r[i+1]=av.get(1);
1411                     r[i+2]=av.get(2);
1412                     r[i+3]=av.get(3);
1413                 } else if (num_lanes == 8) {
1414                     r[i]=av.get(0);
1415                     r[i+1]=av.get(1);
1416                     r[i+2]=av.get(2);
1417                     r[i+3]=av.get(3);
1418                     r[i+4]=av.get(4);
1419                     r[i+5]=av.get(5);
1420                     r[i+6]=av.get(6);
1421                     r[i+7]=av.get(7);
1422                 } else if (num_lanes == 16) {
1423                     r[i]=av.get(0);
1424                     r[i+1]=av.get(1);
1425                     r[i+2]=av.get(2);
1426                     r[i+3]=av.get(3);
1427                     r[i+4]=av.get(4);
1428                     r[i+5]=av.get(5);
1429                     r[i+6]=av.get(6);
1430                     r[i+7]=av.get(7);
1431                     r[i+8]=av.get(8);
1432                     r[i+9]=av.get(9);
1433                     r[i+10]=av.get(10);
1434                     r[i+11]=av.get(11);
1435                     r[i+12]=av.get(12);
1436                     r[i+13]=av.get(13);
1437                     r[i+14]=av.get(14);
1438                     r[i+15]=av.get(15);
1439                 } else if (num_lanes == 32) {
1440                     r[i]=av.get(0);
1441                     r[i+1]=av.get(1);
1442                     r[i+2]=av.get(2);
1443                     r[i+3]=av.get(3);
1444                     r[i+4]=av.get(4);
1445                     r[i+5]=av.get(5);
1446                     r[i+6]=av.get(6);
1447                     r[i+7]=av.get(7);
1448                     r[i+8]=av.get(8);
1449                     r[i+9]=av.get(9);
1450                     r[i+10]=av.get(10);
1451                     r[i+11]=av.get(11);
1452                     r[i+12]=av.get(12);
1453                     r[i+13]=av.get(13);
1454                     r[i+14]=av.get(14);
1455                     r[i+15]=av.get(15);
1456                     r[i+16]=av.get(16);
1457                     r[i+17]=av.get(17);
1458                     r[i+18]=av.get(18);
1459                     r[i+19]=av.get(19);
1460                     r[i+20]=av.get(20);
1461                     r[i+21]=av.get(21);
1462                     r[i+22]=av.get(22);
1463                     r[i+23]=av.get(23);
1464                     r[i+24]=av.get(24);
1465                     r[i+25]=av.get(25);
1466                     r[i+26]=av.get(26);
1467                     r[i+27]=av.get(27);
1468                     r[i+28]=av.get(28);
1469                     r[i+29]=av.get(29);
1470                     r[i+30]=av.get(30);
1471                     r[i+31]=av.get(31);
1472                 } else if (num_lanes == 64) {
1473                     r[i]=av.get(0);
1474                     r[i+1]=av.get(1);
1475                     r[i+2]=av.get(2);
1476                     r[i+3]=av.get(3);
1477                     r[i+4]=av.get(4);
1478                     r[i+5]=av.get(5);
1479                     r[i+6]=av.get(6);
1480                     r[i+7]=av.get(7);
1481                     r[i+8]=av.get(8);
1482                     r[i+9]=av.get(9);
1483                     r[i+10]=av.get(10);
1484                     r[i+11]=av.get(11);
1485                     r[i+12]=av.get(12);
1486                     r[i+13]=av.get(13);
1487                     r[i+14]=av.get(14);
1488                     r[i+15]=av.get(15);
1489                     r[i+16]=av.get(16);
1490                     r[i+17]=av.get(17);
1491                     r[i+18]=av.get(18);
1492                     r[i+19]=av.get(19);
1493                     r[i+20]=av.get(20);
1494                     r[i+21]=av.get(21);
1495                     r[i+22]=av.get(22);
1496                     r[i+23]=av.get(23);
1497                     r[i+24]=av.get(24);
1498                     r[i+25]=av.get(25);
1499                     r[i+26]=av.get(26);
1500                     r[i+27]=av.get(27);
1501                     r[i+28]=av.get(28);
1502                     r[i+29]=av.get(29);
1503                     r[i+30]=av.get(30);
1504                     r[i+31]=av.get(31);
1505                     r[i+32]=av.get(32);
1506                     r[i+33]=av.get(33);
1507                     r[i+34]=av.get(34);
1508                     r[i+35]=av.get(35);
1509                     r[i+36]=av.get(36);
1510                     r[i+37]=av.get(37);
1511                     r[i+38]=av.get(38);
1512                     r[i+39]=av.get(39);
1513                     r[i+40]=av.get(40);
1514                     r[i+41]=av.get(41);
1515                     r[i+42]=av.get(42);
1516                     r[i+43]=av.get(43);
1517                     r[i+44]=av.get(44);
1518                     r[i+45]=av.get(45);
1519                     r[i+46]=av.get(46);
1520                     r[i+47]=av.get(47);
1521                     r[i+48]=av.get(48);
1522                     r[i+49]=av.get(49);
1523                     r[i+50]=av.get(50);
1524                     r[i+51]=av.get(51);
1525                     r[i+52]=av.get(52);
1526                     r[i+53]=av.get(53);
1527                     r[i+54]=av.get(54);
1528                     r[i+55]=av.get(55);
1529                     r[i+56]=av.get(56);
1530                     r[i+57]=av.get(57);
1531                     r[i+58]=av.get(58);
1532                     r[i+59]=av.get(59);
1533                     r[i+60]=av.get(60);
1534                     r[i+61]=av.get(61);
1535                     r[i+62]=av.get(62);
1536                     r[i+63]=av.get(63);
1537                 } else {
1538                     for (int j = 0; j < SPECIES.length(); j++) {
1539                         r[i+j]=av.get(j);
1540                     }
1541                 }
1542             }
1543         }
1544 
1545         assertArraysEquals(a, r, ByteMaxVectorTests::get);
1546     }
1547 
1548 
1549 
1550 
1551 
1552 
1553 
1554 
1555 
1556 
1557 
1558 
1559 
1560 
1561 
1562 
1563 
1564 
1565 
1566 
1567 
1568 
1569     static byte neg(byte a) {
1570         return (byte)(-((byte)a));
1571     }
1572 
1573     @Test(dataProvider = "byteUnaryOpProvider")
1574     static void negByteMaxVectorTests(IntFunction<byte[]> fa) {
1575         byte[] a = fa.apply(SPECIES.length());
1576         byte[] r = fr.apply(SPECIES.length());
1577 
1578         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1579             for (int i = 0; i < a.length; i += SPECIES.length()) {
1580                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1581                 av.neg().intoArray(r, i);
1582             }
1583         }
1584 
1585         assertArraysEquals(a, r, ByteMaxVectorTests::neg);
1586     }
1587 
1588     @Test(dataProvider = "byteUnaryOpMaskProvider")
1589     static void negMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
1590                                                 IntFunction<boolean[]> fm) {
1591         byte[] a = fa.apply(SPECIES.length());
1592         byte[] r = fr.apply(SPECIES.length());
1593         boolean[] mask = fm.apply(SPECIES.length());
1594         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1595 
1596         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1597             for (int i = 0; i < a.length; i += SPECIES.length()) {
1598                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1599                 av.neg(vmask).intoArray(r, i);
1600             }
1601         }
1602 
1603         assertArraysEquals(a, r, mask, ByteMaxVectorTests::neg);
1604     }
1605 
1606     static byte abs(byte a) {
1607         return (byte)(Math.abs((byte)a));
1608     }
1609 
1610     @Test(dataProvider = "byteUnaryOpProvider")
1611     static void absByteMaxVectorTests(IntFunction<byte[]> fa) {
1612         byte[] a = fa.apply(SPECIES.length());
1613         byte[] r = fr.apply(SPECIES.length());
1614 
1615         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1616             for (int i = 0; i < a.length; i += SPECIES.length()) {
1617                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1618                 av.abs().intoArray(r, i);
1619             }
1620         }
1621 
1622         assertArraysEquals(a, r, ByteMaxVectorTests::abs);
1623     }
1624 
1625     @Test(dataProvider = "byteUnaryOpMaskProvider")
1626     static void absMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
1627                                                 IntFunction<boolean[]> fm) {
1628         byte[] a = fa.apply(SPECIES.length());
1629         byte[] r = fr.apply(SPECIES.length());
1630         boolean[] mask = fm.apply(SPECIES.length());
1631         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1632 
1633         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1634             for (int i = 0; i < a.length; i += SPECIES.length()) {
1635                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1636                 av.abs(vmask).intoArray(r, i);
1637             }
1638         }
1639 
1640         assertArraysEquals(a, r, mask, ByteMaxVectorTests::abs);
1641     }
1642 
1643 
1644     static byte not(byte a) {
1645         return (byte)(~((byte)a));
1646     }
1647 
1648 
1649 
1650     @Test(dataProvider = "byteUnaryOpProvider")
1651     static void notByteMaxVectorTests(IntFunction<byte[]> fa) {
1652         byte[] a = fa.apply(SPECIES.length());
1653         byte[] r = fr.apply(SPECIES.length());
1654 
1655         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1656             for (int i = 0; i < a.length; i += SPECIES.length()) {
1657                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1658                 av.not().intoArray(r, i);
1659             }
1660         }
1661 
1662         assertArraysEquals(a, r, ByteMaxVectorTests::not);
1663     }
1664 
1665 
1666 
1667     @Test(dataProvider = "byteUnaryOpMaskProvider")
1668     static void notMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
1669                                                 IntFunction<boolean[]> fm) {
1670         byte[] a = fa.apply(SPECIES.length());
1671         byte[] r = fr.apply(SPECIES.length());
1672         boolean[] mask = fm.apply(SPECIES.length());
1673         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1674 
1675         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1676             for (int i = 0; i < a.length; i += SPECIES.length()) {
1677                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1678                 av.not(vmask).intoArray(r, i);
1679             }
1680         }
1681 
1682         assertArraysEquals(a, r, mask, ByteMaxVectorTests::not);
1683     }
1684 
1685 
1686 
1687 
1688 
1689 
1690 }
1691