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