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     static byte shiftLeft(byte a, byte b) {
 668         return (byte)((a << (b & 0x7)));
 669     }
 670 
 671     @Test(dataProvider = "byteBinaryOpProvider")
 672     static void shiftLeftByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 673         byte[] a = fa.apply(SPECIES.length());
 674         byte[] b = fb.apply(SPECIES.length());
 675         byte[] r = fr.apply(SPECIES.length());
 676 
 677         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 678             for (int i = 0; i < a.length; i += SPECIES.length()) {
 679                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 680                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 681                 av.shiftLeft(bv).intoArray(r, i);
 682             }
 683         }
 684 
 685         assertArraysEquals(a, b, r, ByteMaxVectorTests::shiftLeft);
 686     }
 687 
 688 
 689 
 690     @Test(dataProvider = "byteBinaryOpMaskProvider")
 691     static void shiftLeftByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 692                                           IntFunction<boolean[]> fm) {
 693         byte[] a = fa.apply(SPECIES.length());
 694         byte[] b = fb.apply(SPECIES.length());
 695         byte[] r = fr.apply(SPECIES.length());
 696         boolean[] mask = fm.apply(SPECIES.length());
 697         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 698 
 699         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 700             for (int i = 0; i < a.length; i += SPECIES.length()) {
 701                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 702                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 703                 av.shiftLeft(bv, vmask).intoArray(r, i);
 704             }
 705         }
 706 
 707         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::shiftLeft);
 708     }
 709 
 710 
 711 
 712 
 713 
 714 
 715     static byte shiftRight(byte a, byte b) {
 716         return (byte)((a >>> (b & 0x7)));
 717     }
 718 
 719     @Test(dataProvider = "byteBinaryOpProvider")
 720     static void shiftRightByteMaxVectorTests(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                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 729                 av.shiftRight(bv).intoArray(r, i);
 730             }
 731         }
 732 
 733         assertArraysEquals(a, b, r, ByteMaxVectorTests::shiftRight);
 734     }
 735 
 736 
 737 
 738     @Test(dataProvider = "byteBinaryOpMaskProvider")
 739     static void shiftRightByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 740                                           IntFunction<boolean[]> fm) {
 741         byte[] a = fa.apply(SPECIES.length());
 742         byte[] b = fb.apply(SPECIES.length());
 743         byte[] r = fr.apply(SPECIES.length());
 744         boolean[] mask = fm.apply(SPECIES.length());
 745         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 746 
 747         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 748             for (int i = 0; i < a.length; i += SPECIES.length()) {
 749                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 750                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 751                 av.shiftRight(bv, vmask).intoArray(r, i);
 752             }
 753         }
 754 
 755         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::shiftRight);
 756     }
 757 
 758 
 759 
 760 
 761 
 762 
 763     static byte shiftArithmeticRight(byte a, byte b) {
 764         return (byte)((a >> (b & 0x7)));
 765     }
 766 
 767     @Test(dataProvider = "byteBinaryOpProvider")
 768     static void shiftArithmeticRightByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 769         byte[] a = fa.apply(SPECIES.length());
 770         byte[] b = fb.apply(SPECIES.length());
 771         byte[] r = fr.apply(SPECIES.length());
 772 
 773         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 774             for (int i = 0; i < a.length; i += SPECIES.length()) {
 775                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 776                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 777                 av.shiftArithmeticRight(bv).intoArray(r, i);
 778             }
 779         }
 780 
 781         assertArraysEquals(a, b, r, ByteMaxVectorTests::shiftArithmeticRight);
 782     }
 783 
 784 
 785 
 786     @Test(dataProvider = "byteBinaryOpMaskProvider")
 787     static void shiftArithmeticRightByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 788                                           IntFunction<boolean[]> fm) {
 789         byte[] a = fa.apply(SPECIES.length());
 790         byte[] b = fb.apply(SPECIES.length());
 791         byte[] r = fr.apply(SPECIES.length());
 792         boolean[] mask = fm.apply(SPECIES.length());
 793         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 794 
 795         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 796             for (int i = 0; i < a.length; i += SPECIES.length()) {
 797                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 798                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 799                 av.shiftArithmeticRight(bv, vmask).intoArray(r, i);
 800             }
 801         }
 802 
 803         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::shiftArithmeticRight);
 804     }
 805 
 806 
 807 
 808 
 809 
 810 
 811     static byte shiftLeft_unary(byte a, byte b) {
 812         return (byte)((a << (b & 7)));
 813     }
 814 
 815     @Test(dataProvider = "byteBinaryOpProvider")
 816     static void shiftLeftByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 817         byte[] a = fa.apply(SPECIES.length());
 818         byte[] b = fb.apply(SPECIES.length());
 819         byte[] r = fr.apply(SPECIES.length());
 820 
 821         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 822             for (int i = 0; i < a.length; i += SPECIES.length()) {
 823                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 824                 av.shiftLeft((int)b[i]).intoArray(r, i);
 825             }
 826         }
 827 
 828         assertShiftArraysEquals(a, b, r, ByteMaxVectorTests::shiftLeft_unary);
 829     }
 830 
 831 
 832 
 833     @Test(dataProvider = "byteBinaryOpMaskProvider")
 834     static void shiftLeftByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 835                                           IntFunction<boolean[]> fm) {
 836         byte[] a = fa.apply(SPECIES.length());
 837         byte[] b = fb.apply(SPECIES.length());
 838         byte[] r = fr.apply(SPECIES.length());
 839         boolean[] mask = fm.apply(SPECIES.length());
 840         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 841 
 842         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 843             for (int i = 0; i < a.length; i += SPECIES.length()) {
 844                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 845                 av.shiftLeft((int)b[i], vmask).intoArray(r, i);
 846             }
 847         }
 848 
 849         assertShiftArraysEquals(a, b, r, mask, ByteMaxVectorTests::shiftLeft_unary);
 850     }
 851 
 852 
 853 
 854 
 855 
 856 
 857     static byte shiftRight_unary(byte a, byte b) {
 858         return (byte)(((a & 0xFF) >>> (b & 7)));
 859     }
 860 
 861     @Test(dataProvider = "byteBinaryOpProvider")
 862     static void shiftRightByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 863         byte[] a = fa.apply(SPECIES.length());
 864         byte[] b = fb.apply(SPECIES.length());
 865         byte[] r = fr.apply(SPECIES.length());
 866 
 867         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 868             for (int i = 0; i < a.length; i += SPECIES.length()) {
 869                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 870                 av.shiftRight((int)b[i]).intoArray(r, i);
 871             }
 872         }
 873 
 874         assertShiftArraysEquals(a, b, r, ByteMaxVectorTests::shiftRight_unary);
 875     }
 876 
 877 
 878 
 879     @Test(dataProvider = "byteBinaryOpMaskProvider")
 880     static void shiftRightByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 881                                           IntFunction<boolean[]> fm) {
 882         byte[] a = fa.apply(SPECIES.length());
 883         byte[] b = fb.apply(SPECIES.length());
 884         byte[] r = fr.apply(SPECIES.length());
 885         boolean[] mask = fm.apply(SPECIES.length());
 886         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 887 
 888         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 889             for (int i = 0; i < a.length; i += SPECIES.length()) {
 890                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 891                 av.shiftRight((int)b[i], vmask).intoArray(r, i);
 892             }
 893         }
 894 
 895         assertShiftArraysEquals(a, b, r, mask, ByteMaxVectorTests::shiftRight_unary);
 896     }
 897 
 898 
 899 
 900 
 901 
 902 
 903     static byte shiftArithmeticRight_unary(byte a, byte b) {
 904         return (byte)((a >> (b & 7)));
 905     }
 906 
 907     @Test(dataProvider = "byteBinaryOpProvider")
 908     static void shiftArithmeticRightByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 909         byte[] a = fa.apply(SPECIES.length());
 910         byte[] b = fb.apply(SPECIES.length());
 911         byte[] r = fr.apply(SPECIES.length());
 912 
 913         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 914             for (int i = 0; i < a.length; i += SPECIES.length()) {
 915                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 916                 av.shiftArithmeticRight((int)b[i]).intoArray(r, i);
 917             }
 918         }
 919 
 920         assertShiftArraysEquals(a, b, r, ByteMaxVectorTests::shiftArithmeticRight_unary);
 921     }
 922 
 923 
 924 
 925     @Test(dataProvider = "byteBinaryOpMaskProvider")
 926     static void shiftArithmeticRightByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 927                                           IntFunction<boolean[]> fm) {
 928         byte[] a = fa.apply(SPECIES.length());
 929         byte[] b = fb.apply(SPECIES.length());
 930         byte[] r = fr.apply(SPECIES.length());
 931         boolean[] mask = fm.apply(SPECIES.length());
 932         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 933 
 934         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 935             for (int i = 0; i < a.length; i += SPECIES.length()) {
 936                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 937                 av.shiftArithmeticRight((int)b[i], vmask).intoArray(r, i);
 938             }
 939         }
 940 
 941         assertShiftArraysEquals(a, b, r, mask, ByteMaxVectorTests::shiftArithmeticRight_unary);
 942     }
 943 
 944 
 945 
 946     static byte max(byte a, byte b) {
 947         return (byte)(Math.max(a, b));
 948     }
 949 
 950     @Test(dataProvider = "byteBinaryOpProvider")
 951     static void maxByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 952         byte[] a = fa.apply(SPECIES.length());
 953         byte[] b = fb.apply(SPECIES.length());
 954         byte[] r = fr.apply(SPECIES.length());
 955 
 956         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 957             for (int i = 0; i < a.length; i += SPECIES.length()) {
 958                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 959                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 960                 av.max(bv).intoArray(r, i);
 961             }
 962         }
 963 
 964         assertArraysEquals(a, b, r, ByteMaxVectorTests::max);
 965     }
 966     static byte min(byte a, byte b) {
 967         return (byte)(Math.min(a, b));
 968     }
 969 
 970     @Test(dataProvider = "byteBinaryOpProvider")
 971     static void minByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 972         byte[] a = fa.apply(SPECIES.length());
 973         byte[] b = fb.apply(SPECIES.length());
 974         byte[] r = fr.apply(SPECIES.length());
 975 
 976         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 977             for (int i = 0; i < a.length; i += SPECIES.length()) {
 978                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 979                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 980                 av.min(bv).intoArray(r, i);
 981             }
 982         }
 983 
 984         assertArraysEquals(a, b, r, ByteMaxVectorTests::min);
 985     }
 986 
 987     static byte andLanes(byte[] a, int idx) {
 988         byte res = -1;
 989         for (int i = idx; i < (idx + SPECIES.length()); i++) {
 990             res &= a[i];
 991         }
 992 
 993         return res;
 994     }
 995 
 996     static byte andLanes(byte[] a) {
 997         byte res = -1;
 998         for (int i = 0; i < a.length; i += SPECIES.length()) {
 999             byte tmp = -1;
1000             for (int j = 0; j < SPECIES.length(); j++) {
1001                 tmp &= a[i + j];
1002             }
1003             res &= tmp;
1004         }
1005 
1006         return res;
1007     }
1008 
1009 
1010     @Test(dataProvider = "byteUnaryOpProvider")
1011     static void andLanesByteMaxVectorTests(IntFunction<byte[]> fa) {
1012         byte[] a = fa.apply(SPECIES.length());
1013         byte[] r = fr.apply(SPECIES.length());
1014         byte ra = -1;
1015 
1016         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1017             for (int i = 0; i < a.length; i += SPECIES.length()) {
1018                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1019                 r[i] = av.andLanes();
1020             }
1021         }
1022 
1023         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1024             ra = -1;
1025             for (int i = 0; i < a.length; i += SPECIES.length()) {
1026                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1027                 ra &= av.andLanes();
1028             }
1029         }
1030 
1031         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::andLanes, ByteMaxVectorTests::andLanes);
1032     }
1033 
1034 
1035     static byte orLanes(byte[] a, int idx) {
1036         byte res = 0;
1037         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1038             res |= a[i];
1039         }
1040 
1041         return res;
1042     }
1043 
1044     static byte orLanes(byte[] a) {
1045         byte res = 0;
1046         for (int i = 0; i < a.length; i += SPECIES.length()) {
1047             byte tmp = 0;
1048             for (int j = 0; j < SPECIES.length(); j++) {
1049                 tmp |= a[i + j];
1050             }
1051             res |= tmp;
1052         }
1053 
1054         return res;
1055     }
1056 
1057 
1058     @Test(dataProvider = "byteUnaryOpProvider")
1059     static void orLanesByteMaxVectorTests(IntFunction<byte[]> fa) {
1060         byte[] a = fa.apply(SPECIES.length());
1061         byte[] r = fr.apply(SPECIES.length());
1062         byte ra = 0;
1063 
1064         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1065             for (int i = 0; i < a.length; i += SPECIES.length()) {
1066                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1067                 r[i] = av.orLanes();
1068             }
1069         }
1070 
1071         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1072             ra = 0;
1073             for (int i = 0; i < a.length; i += SPECIES.length()) {
1074                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1075                 ra |= av.orLanes();
1076             }
1077         }
1078 
1079         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::orLanes, ByteMaxVectorTests::orLanes);
1080     }
1081 
1082 
1083     static byte xorLanes(byte[] a, int idx) {
1084         byte res = 0;
1085         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1086             res ^= a[i];
1087         }
1088 
1089         return res;
1090     }
1091 
1092     static byte xorLanes(byte[] a) {
1093         byte res = 0;
1094         for (int i = 0; i < a.length; i += SPECIES.length()) {
1095             byte tmp = 0;
1096             for (int j = 0; j < SPECIES.length(); j++) {
1097                 tmp ^= a[i + j];
1098             }
1099             res ^= tmp;
1100         }
1101 
1102         return res;
1103     }
1104 
1105 
1106     @Test(dataProvider = "byteUnaryOpProvider")
1107     static void xorLanesByteMaxVectorTests(IntFunction<byte[]> fa) {
1108         byte[] a = fa.apply(SPECIES.length());
1109         byte[] r = fr.apply(SPECIES.length());
1110         byte ra = 0;
1111 
1112         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1113             for (int i = 0; i < a.length; i += SPECIES.length()) {
1114                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1115                 r[i] = av.xorLanes();
1116             }
1117         }
1118 
1119         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1120             ra = 0;
1121             for (int i = 0; i < a.length; i += SPECIES.length()) {
1122                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1123                 ra ^= av.xorLanes();
1124             }
1125         }
1126 
1127         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::xorLanes, ByteMaxVectorTests::xorLanes);
1128     }
1129 
1130     static byte addLanes(byte[] a, int idx) {
1131         byte res = 0;
1132         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1133             res += a[i];
1134         }
1135 
1136         return res;
1137     }
1138 
1139     static byte addLanes(byte[] a) {
1140         byte res = 0;
1141         for (int i = 0; i < a.length; i += SPECIES.length()) {
1142             byte tmp = 0;
1143             for (int j = 0; j < SPECIES.length(); j++) {
1144                 tmp += a[i + j];
1145             }
1146             res += tmp;
1147         }
1148 
1149         return res;
1150     }
1151     @Test(dataProvider = "byteUnaryOpProvider")
1152     static void addLanesByteMaxVectorTests(IntFunction<byte[]> fa) {
1153         byte[] a = fa.apply(SPECIES.length());
1154         byte[] r = fr.apply(SPECIES.length());
1155         byte ra = 0;
1156 
1157         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1158             for (int i = 0; i < a.length; i += SPECIES.length()) {
1159                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1160                 r[i] = av.addLanes();
1161             }
1162         }
1163 
1164         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1165             ra = 0;
1166             for (int i = 0; i < a.length; i += SPECIES.length()) {
1167                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1168                 ra += av.addLanes();
1169             }
1170         }
1171 
1172         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::addLanes, ByteMaxVectorTests::addLanes);
1173     }
1174     static byte mulLanes(byte[] a, int idx) {
1175         byte res = 1;
1176         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1177             res *= a[i];
1178         }
1179 
1180         return res;
1181     }
1182 
1183     static byte mulLanes(byte[] a) {
1184         byte res = 1;
1185         for (int i = 0; i < a.length; i += SPECIES.length()) {
1186             byte tmp = 1;
1187             for (int j = 0; j < SPECIES.length(); j++) {
1188                 tmp *= a[i + j];
1189             }
1190             res *= tmp;
1191         }
1192 
1193         return res;
1194     }
1195     @Test(dataProvider = "byteUnaryOpProvider")
1196     static void mulLanesByteMaxVectorTests(IntFunction<byte[]> fa) {
1197         byte[] a = fa.apply(SPECIES.length());
1198         byte[] r = fr.apply(SPECIES.length());
1199         byte ra = 1;
1200 
1201         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1202             for (int i = 0; i < a.length; i += SPECIES.length()) {
1203                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1204                 r[i] = av.mulLanes();
1205             }
1206         }
1207 
1208         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1209             ra = 1;
1210             for (int i = 0; i < a.length; i += SPECIES.length()) {
1211                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1212                 ra *= av.mulLanes();
1213             }
1214         }
1215 
1216         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::mulLanes, ByteMaxVectorTests::mulLanes);
1217     }
1218     static byte minLanes(byte[] a, int idx) {
1219         byte res = Byte.MAX_VALUE;
1220         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1221             res = (byte)Math.min(res, a[i]);
1222         }
1223 
1224         return res;
1225     }
1226 
1227     static byte minLanes(byte[] a) {
1228         byte res = Byte.MAX_VALUE;
1229         for (int i = 0; i < a.length; i++) {
1230             res = (byte)Math.min(res, a[i]);
1231         }
1232 
1233         return res;
1234     }
1235     @Test(dataProvider = "byteUnaryOpProvider")
1236     static void minLanesByteMaxVectorTests(IntFunction<byte[]> fa) {
1237         byte[] a = fa.apply(SPECIES.length());
1238         byte[] r = fr.apply(SPECIES.length());
1239         byte ra = Byte.MAX_VALUE;
1240 
1241         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1242             for (int i = 0; i < a.length; i += SPECIES.length()) {
1243                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1244                 r[i] = av.minLanes();
1245             }
1246         }
1247 
1248         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1249             ra = Byte.MAX_VALUE;
1250             for (int i = 0; i < a.length; i += SPECIES.length()) {
1251                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1252                 ra = (byte)Math.min(ra, av.minLanes());
1253             }
1254         }
1255 
1256         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::minLanes, ByteMaxVectorTests::minLanes);
1257     }
1258     static byte maxLanes(byte[] a, int idx) {
1259         byte res = Byte.MIN_VALUE;
1260         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1261             res = (byte)Math.max(res, a[i]);
1262         }
1263 
1264         return res;
1265     }
1266 
1267     static byte maxLanes(byte[] a) {
1268         byte res = Byte.MIN_VALUE;
1269         for (int i = 0; i < a.length; i++) {
1270             res = (byte)Math.max(res, a[i]);
1271         }
1272 
1273         return res;
1274     }
1275     @Test(dataProvider = "byteUnaryOpProvider")
1276     static void maxLanesByteMaxVectorTests(IntFunction<byte[]> fa) {
1277         byte[] a = fa.apply(SPECIES.length());
1278         byte[] r = fr.apply(SPECIES.length());
1279         byte ra = Byte.MIN_VALUE;
1280 
1281         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1282             for (int i = 0; i < a.length; i += SPECIES.length()) {
1283                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1284                 r[i] = av.maxLanes();
1285             }
1286         }
1287 
1288         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1289             ra = Byte.MIN_VALUE;
1290             for (int i = 0; i < a.length; i += SPECIES.length()) {
1291                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1292                 ra = (byte)Math.max(ra, av.maxLanes());
1293             }
1294         }
1295 
1296         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::maxLanes, ByteMaxVectorTests::maxLanes);
1297     }
1298 
1299     static boolean anyTrue(boolean[] a, int idx) {
1300         boolean res = false;
1301         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1302             res |= a[i];
1303         }
1304 
1305         return res;
1306     }
1307 
1308 
1309     @Test(dataProvider = "boolUnaryOpProvider")
1310     static void anyTrueByteMaxVectorTests(IntFunction<boolean[]> fm) {
1311         boolean[] mask = fm.apply(SPECIES.length());
1312         boolean[] r = fmr.apply(SPECIES.length());
1313 
1314         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1315             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1316                 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i);
1317                 r[i] = vmask.anyTrue();
1318             }
1319         }
1320 
1321         assertReductionBoolArraysEquals(mask, r, ByteMaxVectorTests::anyTrue);
1322     }
1323 
1324 
1325     static boolean allTrue(boolean[] a, int idx) {
1326         boolean res = true;
1327         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1328             res &= a[i];
1329         }
1330 
1331         return res;
1332     }
1333 
1334 
1335     @Test(dataProvider = "boolUnaryOpProvider")
1336     static void allTrueByteMaxVectorTests(IntFunction<boolean[]> fm) {
1337         boolean[] mask = fm.apply(SPECIES.length());
1338         boolean[] r = fmr.apply(SPECIES.length());
1339 
1340         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1341             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1342                 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i);
1343                 r[i] = vmask.allTrue();
1344             }
1345         }
1346 
1347         assertReductionBoolArraysEquals(mask, r, ByteMaxVectorTests::allTrue);
1348     }
1349 
1350 
1351     @Test(dataProvider = "byteUnaryOpProvider")
1352     static void withByteMaxVectorTests(IntFunction<byte []> fa) {
1353         byte[] a = fa.apply(SPECIES.length());
1354         byte[] r = fr.apply(SPECIES.length());
1355 
1356         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1357             for (int i = 0; i < a.length; i += SPECIES.length()) {
1358                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1359                 av.with(0, (byte)4).intoArray(r, i);
1360             }
1361         }
1362 
1363         assertInsertArraysEquals(a, r, (byte)4, 0);
1364     }
1365 
1366     @Test(dataProvider = "byteCompareOpProvider")
1367     static void lessThanByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1368         byte[] a = fa.apply(SPECIES.length());
1369         byte[] b = fb.apply(SPECIES.length());
1370 
1371         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1372             for (int i = 0; i < a.length; i += SPECIES.length()) {
1373                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1374                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1375                 VectorMask<Byte> mv = av.lessThan(bv);
1376 
1377                 // Check results as part of computation.
1378                 for (int j = 0; j < SPECIES.length(); j++) {
1379                     Assert.assertEquals(mv.lane(j), a[i + j] < b[i + j]);
1380                 }
1381             }
1382         }
1383     }
1384 
1385 
1386     @Test(dataProvider = "byteCompareOpProvider")
1387     static void greaterThanByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1388         byte[] a = fa.apply(SPECIES.length());
1389         byte[] b = fb.apply(SPECIES.length());
1390 
1391         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1392             for (int i = 0; i < a.length; i += SPECIES.length()) {
1393                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1394                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1395                 VectorMask<Byte> mv = av.greaterThan(bv);
1396 
1397                 // Check results as part of computation.
1398                 for (int j = 0; j < SPECIES.length(); j++) {
1399                     Assert.assertEquals(mv.lane(j), a[i + j] > b[i + j]);
1400                 }
1401             }
1402         }
1403     }
1404 
1405 
1406     @Test(dataProvider = "byteCompareOpProvider")
1407     static void equalByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1408         byte[] a = fa.apply(SPECIES.length());
1409         byte[] b = fb.apply(SPECIES.length());
1410 
1411         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1412             for (int i = 0; i < a.length; i += SPECIES.length()) {
1413                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1414                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1415                 VectorMask<Byte> mv = av.equal(bv);
1416 
1417                 // Check results as part of computation.
1418                 for (int j = 0; j < SPECIES.length(); j++) {
1419                     Assert.assertEquals(mv.lane(j), a[i + j] == b[i + j]);
1420                 }
1421             }
1422         }
1423     }
1424 
1425 
1426     @Test(dataProvider = "byteCompareOpProvider")
1427     static void notEqualByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1428         byte[] a = fa.apply(SPECIES.length());
1429         byte[] b = fb.apply(SPECIES.length());
1430 
1431         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1432             for (int i = 0; i < a.length; i += SPECIES.length()) {
1433                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1434                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1435                 VectorMask<Byte> mv = av.notEqual(bv);
1436 
1437                 // Check results as part of computation.
1438                 for (int j = 0; j < SPECIES.length(); j++) {
1439                     Assert.assertEquals(mv.lane(j), a[i + j] != b[i + j]);
1440                 }
1441             }
1442         }
1443     }
1444 
1445 
1446     @Test(dataProvider = "byteCompareOpProvider")
1447     static void lessThanEqByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1448         byte[] a = fa.apply(SPECIES.length());
1449         byte[] b = fb.apply(SPECIES.length());
1450 
1451         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1452             for (int i = 0; i < a.length; i += SPECIES.length()) {
1453                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1454                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1455                 VectorMask<Byte> mv = av.lessThanEq(bv);
1456 
1457                 // Check results as part of computation.
1458                 for (int j = 0; j < SPECIES.length(); j++) {
1459                     Assert.assertEquals(mv.lane(j), a[i + j] <= b[i + j]);
1460                 }
1461             }
1462         }
1463     }
1464 
1465 
1466     @Test(dataProvider = "byteCompareOpProvider")
1467     static void greaterThanEqByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1468         byte[] a = fa.apply(SPECIES.length());
1469         byte[] b = fb.apply(SPECIES.length());
1470 
1471         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1472             for (int i = 0; i < a.length; i += SPECIES.length()) {
1473                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1474                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1475                 VectorMask<Byte> mv = av.greaterThanEq(bv);
1476 
1477                 // Check results as part of computation.
1478                 for (int j = 0; j < SPECIES.length(); j++) {
1479                     Assert.assertEquals(mv.lane(j), a[i + j] >= b[i + j]);
1480                 }
1481             }
1482         }
1483     }
1484 
1485 
1486     static byte blend(byte a, byte b, boolean mask) {
1487         return mask ? b : a;
1488     }
1489 
1490     @Test(dataProvider = "byteBinaryOpMaskProvider")
1491     static void blendByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1492                                           IntFunction<boolean[]> fm) {
1493         byte[] a = fa.apply(SPECIES.length());
1494         byte[] b = fb.apply(SPECIES.length());
1495         byte[] r = fr.apply(SPECIES.length());
1496         boolean[] mask = fm.apply(SPECIES.length());
1497         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1498 
1499         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1500             for (int i = 0; i < a.length; i += SPECIES.length()) {
1501                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1502                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1503                 av.blend(bv, vmask).intoArray(r, i);
1504             }
1505         }
1506 
1507         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::blend);
1508     }
1509 
1510     @Test(dataProvider = "byteUnaryOpShuffleProvider")
1511     static void RearrangeByteMaxVectorTests(IntFunction<byte[]> fa,
1512                                            BiFunction<Integer,Integer,int[]> fs) {
1513         byte[] a = fa.apply(SPECIES.length());
1514         int[] order = fs.apply(a.length, SPECIES.length());
1515         byte[] r = fr.apply(SPECIES.length());
1516 
1517         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1518             for (int i = 0; i < a.length; i += SPECIES.length()) {
1519                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1520                 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
1521             }
1522         }
1523 
1524         assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1525     }
1526 
1527 
1528 
1529 
1530     @Test(dataProvider = "byteUnaryOpProvider")
1531     static void getByteMaxVectorTests(IntFunction<byte[]> fa) {
1532         byte[] a = fa.apply(SPECIES.length());
1533         byte[] r = fr.apply(SPECIES.length());
1534 
1535         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1536             for (int i = 0; i < a.length; i += SPECIES.length()) {
1537                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1538                 int num_lanes = SPECIES.length();
1539                 // Manually unroll because full unroll happens after intrinsification.
1540                 // Unroll is needed because get intrinsic requires for index to be a known constant.
1541                 if (num_lanes == 1) {
1542                     r[i]=av.lane(0);
1543                 } else if (num_lanes == 2) {
1544                     r[i]=av.lane(0);
1545                     r[i+1]=av.lane(1);
1546                 } else if (num_lanes == 4) {
1547                     r[i]=av.lane(0);
1548                     r[i+1]=av.lane(1);
1549                     r[i+2]=av.lane(2);
1550                     r[i+3]=av.lane(3);
1551                 } else if (num_lanes == 8) {
1552                     r[i]=av.lane(0);
1553                     r[i+1]=av.lane(1);
1554                     r[i+2]=av.lane(2);
1555                     r[i+3]=av.lane(3);
1556                     r[i+4]=av.lane(4);
1557                     r[i+5]=av.lane(5);
1558                     r[i+6]=av.lane(6);
1559                     r[i+7]=av.lane(7);
1560                 } else if (num_lanes == 16) {
1561                     r[i]=av.lane(0);
1562                     r[i+1]=av.lane(1);
1563                     r[i+2]=av.lane(2);
1564                     r[i+3]=av.lane(3);
1565                     r[i+4]=av.lane(4);
1566                     r[i+5]=av.lane(5);
1567                     r[i+6]=av.lane(6);
1568                     r[i+7]=av.lane(7);
1569                     r[i+8]=av.lane(8);
1570                     r[i+9]=av.lane(9);
1571                     r[i+10]=av.lane(10);
1572                     r[i+11]=av.lane(11);
1573                     r[i+12]=av.lane(12);
1574                     r[i+13]=av.lane(13);
1575                     r[i+14]=av.lane(14);
1576                     r[i+15]=av.lane(15);
1577                 } else if (num_lanes == 32) {
1578                     r[i]=av.lane(0);
1579                     r[i+1]=av.lane(1);
1580                     r[i+2]=av.lane(2);
1581                     r[i+3]=av.lane(3);
1582                     r[i+4]=av.lane(4);
1583                     r[i+5]=av.lane(5);
1584                     r[i+6]=av.lane(6);
1585                     r[i+7]=av.lane(7);
1586                     r[i+8]=av.lane(8);
1587                     r[i+9]=av.lane(9);
1588                     r[i+10]=av.lane(10);
1589                     r[i+11]=av.lane(11);
1590                     r[i+12]=av.lane(12);
1591                     r[i+13]=av.lane(13);
1592                     r[i+14]=av.lane(14);
1593                     r[i+15]=av.lane(15);
1594                     r[i+16]=av.lane(16);
1595                     r[i+17]=av.lane(17);
1596                     r[i+18]=av.lane(18);
1597                     r[i+19]=av.lane(19);
1598                     r[i+20]=av.lane(20);
1599                     r[i+21]=av.lane(21);
1600                     r[i+22]=av.lane(22);
1601                     r[i+23]=av.lane(23);
1602                     r[i+24]=av.lane(24);
1603                     r[i+25]=av.lane(25);
1604                     r[i+26]=av.lane(26);
1605                     r[i+27]=av.lane(27);
1606                     r[i+28]=av.lane(28);
1607                     r[i+29]=av.lane(29);
1608                     r[i+30]=av.lane(30);
1609                     r[i+31]=av.lane(31);
1610                 } else if (num_lanes == 64) {
1611                     r[i]=av.lane(0);
1612                     r[i+1]=av.lane(1);
1613                     r[i+2]=av.lane(2);
1614                     r[i+3]=av.lane(3);
1615                     r[i+4]=av.lane(4);
1616                     r[i+5]=av.lane(5);
1617                     r[i+6]=av.lane(6);
1618                     r[i+7]=av.lane(7);
1619                     r[i+8]=av.lane(8);
1620                     r[i+9]=av.lane(9);
1621                     r[i+10]=av.lane(10);
1622                     r[i+11]=av.lane(11);
1623                     r[i+12]=av.lane(12);
1624                     r[i+13]=av.lane(13);
1625                     r[i+14]=av.lane(14);
1626                     r[i+15]=av.lane(15);
1627                     r[i+16]=av.lane(16);
1628                     r[i+17]=av.lane(17);
1629                     r[i+18]=av.lane(18);
1630                     r[i+19]=av.lane(19);
1631                     r[i+20]=av.lane(20);
1632                     r[i+21]=av.lane(21);
1633                     r[i+22]=av.lane(22);
1634                     r[i+23]=av.lane(23);
1635                     r[i+24]=av.lane(24);
1636                     r[i+25]=av.lane(25);
1637                     r[i+26]=av.lane(26);
1638                     r[i+27]=av.lane(27);
1639                     r[i+28]=av.lane(28);
1640                     r[i+29]=av.lane(29);
1641                     r[i+30]=av.lane(30);
1642                     r[i+31]=av.lane(31);
1643                     r[i+32]=av.lane(32);
1644                     r[i+33]=av.lane(33);
1645                     r[i+34]=av.lane(34);
1646                     r[i+35]=av.lane(35);
1647                     r[i+36]=av.lane(36);
1648                     r[i+37]=av.lane(37);
1649                     r[i+38]=av.lane(38);
1650                     r[i+39]=av.lane(39);
1651                     r[i+40]=av.lane(40);
1652                     r[i+41]=av.lane(41);
1653                     r[i+42]=av.lane(42);
1654                     r[i+43]=av.lane(43);
1655                     r[i+44]=av.lane(44);
1656                     r[i+45]=av.lane(45);
1657                     r[i+46]=av.lane(46);
1658                     r[i+47]=av.lane(47);
1659                     r[i+48]=av.lane(48);
1660                     r[i+49]=av.lane(49);
1661                     r[i+50]=av.lane(50);
1662                     r[i+51]=av.lane(51);
1663                     r[i+52]=av.lane(52);
1664                     r[i+53]=av.lane(53);
1665                     r[i+54]=av.lane(54);
1666                     r[i+55]=av.lane(55);
1667                     r[i+56]=av.lane(56);
1668                     r[i+57]=av.lane(57);
1669                     r[i+58]=av.lane(58);
1670                     r[i+59]=av.lane(59);
1671                     r[i+60]=av.lane(60);
1672                     r[i+61]=av.lane(61);
1673                     r[i+62]=av.lane(62);
1674                     r[i+63]=av.lane(63);
1675                 } else {
1676                     for (int j = 0; j < SPECIES.length(); j++) {
1677                         r[i+j]=av.lane(j);
1678                     }
1679                 }
1680             }
1681         }
1682 
1683         assertArraysEquals(a, r, ByteMaxVectorTests::get);
1684     }
1685 
1686 
1687 
1688 
1689 
1690 
1691 
1692 
1693 
1694 
1695 
1696 
1697 
1698 
1699 
1700 
1701 
1702 
1703 
1704 
1705 
1706 
1707     static byte neg(byte a) {
1708         return (byte)(-((byte)a));
1709     }
1710 
1711     @Test(dataProvider = "byteUnaryOpProvider")
1712     static void negByteMaxVectorTests(IntFunction<byte[]> fa) {
1713         byte[] a = fa.apply(SPECIES.length());
1714         byte[] r = fr.apply(SPECIES.length());
1715 
1716         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1717             for (int i = 0; i < a.length; i += SPECIES.length()) {
1718                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1719                 av.neg().intoArray(r, i);
1720             }
1721         }
1722 
1723         assertArraysEquals(a, r, ByteMaxVectorTests::neg);
1724     }
1725 
1726     @Test(dataProvider = "byteUnaryOpMaskProvider")
1727     static void negMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
1728                                                 IntFunction<boolean[]> fm) {
1729         byte[] a = fa.apply(SPECIES.length());
1730         byte[] r = fr.apply(SPECIES.length());
1731         boolean[] mask = fm.apply(SPECIES.length());
1732         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1733 
1734         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1735             for (int i = 0; i < a.length; i += SPECIES.length()) {
1736                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1737                 av.neg(vmask).intoArray(r, i);
1738             }
1739         }
1740 
1741         assertArraysEquals(a, r, mask, ByteMaxVectorTests::neg);
1742     }
1743 
1744     static byte abs(byte a) {
1745         return (byte)(Math.abs((byte)a));
1746     }
1747 
1748     @Test(dataProvider = "byteUnaryOpProvider")
1749     static void absByteMaxVectorTests(IntFunction<byte[]> fa) {
1750         byte[] a = fa.apply(SPECIES.length());
1751         byte[] r = fr.apply(SPECIES.length());
1752 
1753         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1754             for (int i = 0; i < a.length; i += SPECIES.length()) {
1755                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1756                 av.abs().intoArray(r, i);
1757             }
1758         }
1759 
1760         assertArraysEquals(a, r, ByteMaxVectorTests::abs);
1761     }
1762 
1763     @Test(dataProvider = "byteUnaryOpMaskProvider")
1764     static void absMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
1765                                                 IntFunction<boolean[]> fm) {
1766         byte[] a = fa.apply(SPECIES.length());
1767         byte[] r = fr.apply(SPECIES.length());
1768         boolean[] mask = fm.apply(SPECIES.length());
1769         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1770 
1771         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1772             for (int i = 0; i < a.length; i += SPECIES.length()) {
1773                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1774                 av.abs(vmask).intoArray(r, i);
1775             }
1776         }
1777 
1778         assertArraysEquals(a, r, mask, ByteMaxVectorTests::abs);
1779     }
1780 
1781 
1782     static byte not(byte a) {
1783         return (byte)(~((byte)a));
1784     }
1785 
1786 
1787 
1788     @Test(dataProvider = "byteUnaryOpProvider")
1789     static void notByteMaxVectorTests(IntFunction<byte[]> fa) {
1790         byte[] a = fa.apply(SPECIES.length());
1791         byte[] r = fr.apply(SPECIES.length());
1792 
1793         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1794             for (int i = 0; i < a.length; i += SPECIES.length()) {
1795                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1796                 av.not().intoArray(r, i);
1797             }
1798         }
1799 
1800         assertArraysEquals(a, r, ByteMaxVectorTests::not);
1801     }
1802 
1803 
1804 
1805     @Test(dataProvider = "byteUnaryOpMaskProvider")
1806     static void notMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
1807                                                 IntFunction<boolean[]> fm) {
1808         byte[] a = fa.apply(SPECIES.length());
1809         byte[] r = fr.apply(SPECIES.length());
1810         boolean[] mask = fm.apply(SPECIES.length());
1811         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1812 
1813         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1814             for (int i = 0; i < a.length; i += SPECIES.length()) {
1815                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1816                 av.not(vmask).intoArray(r, i);
1817             }
1818         }
1819 
1820         assertArraysEquals(a, r, mask, ByteMaxVectorTests::not);
1821     }
1822 
1823 
1824 
1825 
1826 
1827 
1828 }
1829