rev 54658 : refactored mask and shuffle creation methods, moved classes to top-level

   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 LongMaxVectorTests
  28  */
  29 
  30 import jdk.incubator.vector.Vector.Shape;
  31 import jdk.incubator.vector.Vector.Species;


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