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