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