1 /*
   2  * Copyright (c) 2018, 2022, 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 any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @modules jdk.incubator.vector
  27  * @run testng/othervm -ea -esa -Xbatch -XX:-TieredCompilation Int512VectorTests
  28  */
  29 
  30 // -- This file was mechanically generated: Do not edit! -- //
  31 
  32 import jdk.incubator.vector.VectorShape;
  33 import jdk.incubator.vector.VectorSpecies;
  34 import jdk.incubator.vector.VectorShuffle;
  35 import jdk.incubator.vector.VectorMask;
  36 import jdk.incubator.vector.VectorOperators;
  37 import jdk.incubator.vector.Vector;
  38 
  39 import jdk.incubator.vector.IntVector;
  40 
  41 import org.testng.Assert;
  42 import org.testng.annotations.DataProvider;
  43 import org.testng.annotations.Test;
  44 
  45 import java.lang.Integer;
  46 import java.util.List;
  47 import java.util.Arrays;
  48 import java.util.function.BiFunction;
  49 import java.util.function.IntFunction;
  50 import java.util.Objects;
  51 import java.util.stream.Collectors;
  52 import java.util.stream.Stream;
  53 
  54 @Test
  55 public class Int512VectorTests extends AbstractVectorTest {
  56 
  57     static final VectorSpecies<Integer> SPECIES =
  58                 IntVector.SPECIES_512;
  59 
  60     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  61 
  62 
  63     private static final int CONST_SHIFT = Integer.SIZE / 2;
  64 
  65     static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
  66 
  67     interface FUnOp {
  68         int apply(int a);
  69     }
  70 
  71     static void assertArraysEquals(int[] r, int[] a, FUnOp f) {
  72         int i = 0;
  73         try {
  74             for (; i < a.length; i++) {
  75                 Assert.assertEquals(r[i], f.apply(a[i]));
  76             }
  77         } catch (AssertionError e) {
  78             Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
  79         }
  80     }
  81 
  82     interface FUnArrayOp {
  83         int[] apply(int a);
  84     }
  85 
  86     static void assertArraysEquals(int[] r, int[] a, FUnArrayOp f) {
  87         int i = 0;
  88         try {
  89             for (; i < a.length; i += SPECIES.length()) {
  90                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
  91                   f.apply(a[i]));
  92             }
  93         } catch (AssertionError e) {
  94             int[] ref = f.apply(a[i]);
  95             int[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
  96             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
  97               + ", res: " + Arrays.toString(res)
  98               + "), at index #" + i);
  99         }
 100     }
 101 
 102     static void assertArraysEquals(int[] r, int[] a, boolean[] mask, FUnOp f) {
 103         int i = 0;
 104         try {
 105             for (; i < a.length; i++) {
 106                 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]);
 107             }
 108         } catch (AssertionError e) {
 109             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()]);
 110         }
 111     }
 112 
 113     interface FReductionOp {
 114         int apply(int[] a, int idx);
 115     }
 116 
 117     interface FReductionAllOp {
 118         int apply(int[] a);
 119     }
 120 
 121     static void assertReductionArraysEquals(int[] r, int rc, int[] a,
 122                                             FReductionOp f, FReductionAllOp fa) {
 123         int i = 0;
 124         try {
 125             Assert.assertEquals(rc, fa.apply(a));
 126             for (; i < a.length; i += SPECIES.length()) {
 127                 Assert.assertEquals(r[i], f.apply(a, i));
 128             }
 129         } catch (AssertionError e) {
 130             Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!");
 131             Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
 132         }
 133     }
 134 
 135     interface FReductionMaskedOp {
 136         int apply(int[] a, int idx, boolean[] mask);
 137     }
 138 
 139     interface FReductionAllMaskedOp {
 140         int apply(int[] a, boolean[] mask);
 141     }
 142 
 143     static void assertReductionArraysEqualsMasked(int[] r, int rc, int[] a, boolean[] mask,
 144                                             FReductionMaskedOp f, FReductionAllMaskedOp fa) {
 145         int i = 0;
 146         try {
 147             Assert.assertEquals(rc, fa.apply(a, mask));
 148             for (; i < a.length; i += SPECIES.length()) {
 149                 Assert.assertEquals(r[i], f.apply(a, i, mask));
 150             }
 151         } catch (AssertionError e) {
 152             Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
 153             Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
 154         }
 155     }
 156 
 157     interface FReductionOpLong {
 158         long apply(int[] a, int idx);
 159     }
 160 
 161     interface FReductionAllOpLong {
 162         long apply(int[] a);
 163     }
 164 
 165     static void assertReductionLongArraysEquals(long[] r, long rc, int[] a,
 166                                             FReductionOpLong f, FReductionAllOpLong fa) {
 167         int i = 0;
 168         try {
 169             Assert.assertEquals(rc, fa.apply(a));
 170             for (; i < a.length; i += SPECIES.length()) {
 171                 Assert.assertEquals(r[i], f.apply(a, i));
 172             }
 173         } catch (AssertionError e) {
 174             Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!");
 175             Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
 176         }
 177     }
 178 
 179     interface FReductionMaskedOpLong {
 180         long apply(int[] a, int idx, boolean[] mask);
 181     }
 182 
 183     interface FReductionAllMaskedOpLong {
 184         long apply(int[] a, boolean[] mask);
 185     }
 186 
 187     static void assertReductionLongArraysEqualsMasked(long[] r, long rc, int[] a, boolean[] mask,
 188                                             FReductionMaskedOpLong f, FReductionAllMaskedOpLong fa) {
 189         int i = 0;
 190         try {
 191             Assert.assertEquals(rc, fa.apply(a, mask));
 192             for (; i < a.length; i += SPECIES.length()) {
 193                 Assert.assertEquals(r[i], f.apply(a, i, mask));
 194             }
 195         } catch (AssertionError e) {
 196             Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
 197             Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
 198         }
 199     }
 200 
 201     interface FBoolReductionOp {
 202         boolean apply(boolean[] a, int idx);
 203     }
 204 
 205     static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReductionOp f) {
 206         int i = 0;
 207         try {
 208             for (; i < a.length; i += SPECIES.length()) {
 209                 Assert.assertEquals(r[i], f.apply(a, i));
 210             }
 211         } catch (AssertionError e) {
 212             Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
 213         }
 214     }
 215 
 216     interface FMaskReductionOp {
 217         int apply(boolean[] a, int idx);
 218     }
 219 
 220     static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) {
 221         int i = 0;
 222         try {
 223             for (; i < a.length; i += SPECIES.length()) {
 224                 Assert.assertEquals(r[i], f.apply(a, i));
 225             }
 226         } catch (AssertionError e) {
 227             Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
 228         }
 229     }
 230 
 231     static void assertInsertArraysEquals(int[] r, int[] a, int element, int index, int start, int end) {
 232         int i = start;
 233         try {
 234             for (; i < end; i += 1) {
 235                 if(i%SPECIES.length() == index) {
 236                     Assert.assertEquals(r[i], element);
 237                 } else {
 238                     Assert.assertEquals(r[i], a[i]);
 239                 }
 240             }
 241         } catch (AssertionError e) {
 242             if (i%SPECIES.length() == index) {
 243                 Assert.assertEquals(r[i], element, "at index #" + i);
 244             } else {
 245                 Assert.assertEquals(r[i], a[i], "at index #" + i);
 246             }
 247         }
 248     }
 249 
 250     static void assertRearrangeArraysEquals(int[] r, int[] a, int[] order, int vector_len) {
 251         int i = 0, j = 0;
 252         try {
 253             for (; i < a.length; i += vector_len) {
 254                 for (j = 0; j < vector_len; j++) {
 255                     Assert.assertEquals(r[i+j], a[i+order[i+j]]);
 256                 }
 257             }
 258         } catch (AssertionError e) {
 259             int idx = i + j;
 260             Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
 261         }
 262     }
 263 
 264     static void assertcompressArraysEquals(int[] r, int[] a, boolean[] m, int vector_len) {
 265         int i = 0, j = 0, k = 0;
 266         try {
 267             for (; i < a.length; i += vector_len) {
 268                 k = 0;
 269                 for (j = 0; j < vector_len; j++) {
 270                     if (m[(i + j) % SPECIES.length()]) {
 271                         Assert.assertEquals(r[i + k], a[i + j]);
 272                         k++;
 273                     }
 274                 }
 275                 for (; k < vector_len; k++) {
 276                     Assert.assertEquals(r[i + k], (int)0);
 277                 }
 278             }
 279         } catch (AssertionError e) {
 280             int idx = i + k;
 281             if (m[(i + j) % SPECIES.length()]) {
 282                 Assert.assertEquals(r[idx], a[i + j], "at index #" + idx);
 283             } else {
 284                 Assert.assertEquals(r[idx], (int)0, "at index #" + idx);
 285             }
 286         }
 287     }
 288 
 289     static void assertexpandArraysEquals(int[] r, int[] a, boolean[] m, int vector_len) {
 290         int i = 0, j = 0, k = 0;
 291         try {
 292             for (; i < a.length; i += vector_len) {
 293                 k = 0;
 294                 for (j = 0; j < vector_len; j++) {
 295                     if (m[(i + j) % SPECIES.length()]) {
 296                         Assert.assertEquals(r[i + j], a[i + k]);
 297                         k++;
 298                     } else {
 299                         Assert.assertEquals(r[i + j], (int)0);
 300                     }
 301                 }
 302             }
 303         } catch (AssertionError e) {
 304             int idx = i + j;
 305             if (m[idx % SPECIES.length()]) {
 306                 Assert.assertEquals(r[idx], a[i + k], "at index #" + idx);
 307             } else {
 308                 Assert.assertEquals(r[idx], (int)0, "at index #" + idx);
 309             }
 310         }
 311     }
 312 
 313     static void assertSelectFromArraysEquals(int[] r, int[] a, int[] order, int vector_len) {
 314         int i = 0, j = 0;
 315         try {
 316             for (; i < a.length; i += vector_len) {
 317                 for (j = 0; j < vector_len; j++) {
 318                     Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]);
 319                 }
 320             }
 321         } catch (AssertionError e) {
 322             int idx = i + j;
 323             Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]);
 324         }
 325     }
 326 
 327     static void assertRearrangeArraysEquals(int[] r, int[] a, int[] order, boolean[] mask, int vector_len) {
 328         int i = 0, j = 0;
 329         try {
 330             for (; i < a.length; i += vector_len) {
 331                 for (j = 0; j < vector_len; j++) {
 332                     if (mask[j % SPECIES.length()])
 333                          Assert.assertEquals(r[i+j], a[i+order[i+j]]);
 334                     else
 335                          Assert.assertEquals(r[i+j], (int)0);
 336                 }
 337             }
 338         } catch (AssertionError e) {
 339             int idx = i + j;
 340             if (mask[j % SPECIES.length()])
 341                 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
 342             else
 343                 Assert.assertEquals(r[i+j], (int)0, "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
 344         }
 345     }
 346 
 347     static void assertSelectFromArraysEquals(int[] r, int[] a, int[] order, boolean[] mask, int vector_len) {
 348         int i = 0, j = 0;
 349         try {
 350             for (; i < a.length; i += vector_len) {
 351                 for (j = 0; j < vector_len; j++) {
 352                     if (mask[j % SPECIES.length()])
 353                          Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]);
 354                     else
 355                          Assert.assertEquals(r[i+j], (int)0);
 356                 }
 357             }
 358         } catch (AssertionError e) {
 359             int idx = i + j;
 360             if (mask[j % SPECIES.length()])
 361                 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
 362             else
 363                 Assert.assertEquals(r[i+j], (int)0, "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
 364         }
 365     }
 366 
 367     static void assertBroadcastArraysEquals(int[] r, int[] a) {
 368         int i = 0;
 369         for (; i < a.length; i += SPECIES.length()) {
 370             int idx = i;
 371             for (int j = idx; j < (idx + SPECIES.length()); j++)
 372                 a[j]=a[idx];
 373         }
 374 
 375         try {
 376             for (i = 0; i < a.length; i++) {
 377                 Assert.assertEquals(r[i], a[i]);
 378             }
 379         } catch (AssertionError e) {
 380             Assert.assertEquals(r[i], a[i], "at index #" + i + ", input = " + a[i]);
 381         }
 382     }
 383 
 384     interface FBinOp {
 385         int apply(int a, int b);
 386     }
 387 
 388     interface FBinMaskOp {
 389         int apply(int a, int b, boolean m);
 390 
 391         static FBinMaskOp lift(FBinOp f) {
 392             return (a, b, m) -> m ? f.apply(a, b) : a;
 393         }
 394     }
 395 
 396     static void assertArraysEquals(int[] r, int[] a, int[] b, FBinOp f) {
 397         int i = 0;
 398         try {
 399             for (; i < a.length; i++) {
 400                 Assert.assertEquals(r[i], f.apply(a[i], b[i]));
 401             }
 402         } catch (AssertionError e) {
 403             Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i);
 404         }
 405     }
 406 
 407     static void assertBroadcastArraysEquals(int[] r, int[] a, int[] b, FBinOp f) {
 408         int i = 0;
 409         try {
 410             for (; i < a.length; i++) {
 411                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]));
 412             }
 413         } catch (AssertionError e) {
 414             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]),
 415                                 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i);
 416         }
 417     }
 418 
 419     static void assertBroadcastLongArraysEquals(int[] r, int[] a, int[] b, FBinOp f) {
 420         int i = 0;
 421         try {
 422             for (; i < a.length; i++) {
 423                 Assert.assertEquals(r[i], f.apply(a[i], (int)((long)b[(i / SPECIES.length()) * SPECIES.length()])));
 424             }
 425         } catch (AssertionError e) {
 426             Assert.assertEquals(r[i], f.apply(a[i], (int)((long)b[(i / SPECIES.length()) * SPECIES.length()])),
 427                                 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i);
 428         }
 429     }
 430 
 431     static void assertArraysEquals(int[] r, int[] a, int[] b, boolean[] mask, FBinOp f) {
 432         assertArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
 433     }
 434 
 435     static void assertArraysEquals(int[] r, int[] a, int[] b, boolean[] mask, FBinMaskOp f) {
 436         int i = 0;
 437         try {
 438             for (; i < a.length; i++) {
 439                 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]));
 440             }
 441         } catch (AssertionError err) {
 442             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()]);
 443         }
 444     }
 445 
 446     static void assertBroadcastArraysEquals(int[] r, int[] a, int[] b, boolean[] mask, FBinOp f) {
 447         assertBroadcastArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
 448     }
 449 
 450     static void assertBroadcastArraysEquals(int[] r, int[] a, int[] b, boolean[] mask, FBinMaskOp f) {
 451         int i = 0;
 452         try {
 453             for (; i < a.length; i++) {
 454                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]));
 455             }
 456         } catch (AssertionError err) {
 457             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
 458                                 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] +
 459                                 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
 460                                 mask[i % SPECIES.length()]);
 461         }
 462     }
 463 
 464     static void assertBroadcastLongArraysEquals(int[] r, int[] a, int[] b, boolean[] mask, FBinOp f) {
 465         assertBroadcastLongArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
 466     }
 467 
 468     static void assertBroadcastLongArraysEquals(int[] r, int[] a, int[] b, boolean[] mask, FBinMaskOp f) {
 469         int i = 0;
 470         try {
 471             for (; i < a.length; i++) {
 472                 Assert.assertEquals(r[i], f.apply(a[i], (int)((long)b[(i / SPECIES.length()) * SPECIES.length()]), mask[i % SPECIES.length()]));
 473             }
 474         } catch (AssertionError err) {
 475             Assert.assertEquals(r[i], f.apply(a[i], (int)((long)b[(i / SPECIES.length()) * SPECIES.length()]),
 476                                 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] +
 477                                 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
 478                                 mask[i % SPECIES.length()]);
 479         }
 480     }
 481 
 482     static void assertShiftArraysEquals(int[] r, int[] a, int[] b, FBinOp f) {
 483         int i = 0;
 484         int j = 0;
 485         try {
 486             for (; j < a.length; j += SPECIES.length()) {
 487                 for (i = 0; i < SPECIES.length(); i++) {
 488                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]));
 489                 }
 490             }
 491         } catch (AssertionError e) {
 492             Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j);
 493         }
 494     }
 495 
 496     static void assertShiftArraysEquals(int[] r, int[] a, int[] b, boolean[] mask, FBinOp f) {
 497         assertShiftArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
 498     }
 499 
 500     static void assertShiftArraysEquals(int[] r, int[] a, int[] b, boolean[] mask, FBinMaskOp f) {
 501         int i = 0;
 502         int j = 0;
 503         try {
 504             for (; j < a.length; j += SPECIES.length()) {
 505                 for (i = 0; i < SPECIES.length(); i++) {
 506                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i]));
 507                 }
 508             }
 509         } catch (AssertionError err) {
 510             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]);
 511         }
 512     }
 513 
 514     interface FBinConstOp {
 515         int apply(int a);
 516     }
 517 
 518     interface FBinConstMaskOp {
 519         int apply(int a, boolean m);
 520 
 521         static FBinConstMaskOp lift(FBinConstOp f) {
 522             return (a, m) -> m ? f.apply(a) : a;
 523         }
 524     }
 525 
 526     static void assertShiftConstEquals(int[] r, int[] a, FBinConstOp f) {
 527         int i = 0;
 528         int j = 0;
 529         try {
 530             for (; j < a.length; j += SPECIES.length()) {
 531                 for (i = 0; i < SPECIES.length(); i++) {
 532                     Assert.assertEquals(r[i+j], f.apply(a[i+j]));
 533                 }
 534             }
 535         } catch (AssertionError e) {
 536             Assert.assertEquals(r[i+j], f.apply(a[i+j]), "at index #" + i + ", " + j);
 537         }
 538     }
 539 
 540     static void assertShiftConstEquals(int[] r, int[] a, boolean[] mask, FBinConstOp f) {
 541         assertShiftConstEquals(r, a, mask, FBinConstMaskOp.lift(f));
 542     }
 543 
 544     static void assertShiftConstEquals(int[] r, int[] a, boolean[] mask, FBinConstMaskOp f) {
 545         int i = 0;
 546         int j = 0;
 547         try {
 548             for (; j < a.length; j += SPECIES.length()) {
 549                 for (i = 0; i < SPECIES.length(); i++) {
 550                     Assert.assertEquals(r[i+j], f.apply(a[i+j], mask[i]));
 551                 }
 552             }
 553         } catch (AssertionError err) {
 554             Assert.assertEquals(r[i+j], f.apply(a[i+j], mask[i]), "at index #" + i + ", input1 = " + a[i+j] + ", mask = " + mask[i]);
 555         }
 556     }
 557 
 558     interface FTernOp {
 559         int apply(int a, int b, int c);
 560     }
 561 
 562     interface FTernMaskOp {
 563         int apply(int a, int b, int c, boolean m);
 564 
 565         static FTernMaskOp lift(FTernOp f) {
 566             return (a, b, c, m) -> m ? f.apply(a, b, c) : a;
 567         }
 568     }
 569 
 570     static void assertArraysEquals(int[] r, int[] a, int[] b, int[] c, FTernOp f) {
 571         int i = 0;
 572         try {
 573             for (; i < a.length; i++) {
 574                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]));
 575             }
 576         } catch (AssertionError e) {
 577             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
 578         }
 579     }
 580 
 581     static void assertArraysEquals(int[] r, int[] a, int[] b, int[] c, boolean[] mask, FTernOp f) {
 582         assertArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
 583     }
 584 
 585     static void assertArraysEquals(int[] r, int[] a, int[] b, int[] c, boolean[] mask, FTernMaskOp f) {
 586         int i = 0;
 587         try {
 588             for (; i < a.length; i++) {
 589                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]));
 590             }
 591         } catch (AssertionError err) {
 592             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = "
 593               + b[i] + ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]);
 594         }
 595     }
 596 
 597     static void assertBroadcastArraysEquals(int[] r, int[] a, int[] b, int[] c, FTernOp f) {
 598         int i = 0;
 599         try {
 600             for (; i < a.length; i++) {
 601                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()]));
 602             }
 603         } catch (AssertionError e) {
 604             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" +
 605                                 i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " +
 606                                 c[(i / SPECIES.length()) * SPECIES.length()]);
 607         }
 608     }
 609 
 610     static void assertAltBroadcastArraysEquals(int[] r, int[] a, int[] b, int[] c, FTernOp f) {
 611         int i = 0;
 612         try {
 613             for (; i < a.length; i++) {
 614                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i]));
 615             }
 616         } catch (AssertionError e) {
 617             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i]), "at index #" +
 618                                 i + ", input1 = " + a[i] + ", input2 = " +
 619                                 b[(i / SPECIES.length()) * SPECIES.length()] + ",  input3 = " + c[i]);
 620         }
 621     }
 622 
 623     static void assertBroadcastArraysEquals(int[] r, int[] a, int[] b, int[] c, boolean[] mask,
 624                                             FTernOp f) {
 625         assertBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
 626     }
 627 
 628     static void assertBroadcastArraysEquals(int[] r, int[] a, int[] b, int[] c, boolean[] mask,
 629                                             FTernMaskOp f) {
 630         int i = 0;
 631         try {
 632             for (; i < a.length; i++) {
 633                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()],
 634                                     mask[i % SPECIES.length()]));
 635             }
 636         } catch (AssertionError err) {
 637             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()],
 638                                 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " +
 639                                 b[i] + ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
 640                                 mask[i % SPECIES.length()]);
 641         }
 642     }
 643 
 644     static void assertAltBroadcastArraysEquals(int[] r, int[] a, int[] b, int[] c, boolean[] mask,
 645                                             FTernOp f) {
 646         assertAltBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
 647     }
 648 
 649     static void assertAltBroadcastArraysEquals(int[] r, int[] a, int[] b, int[] c, boolean[] mask,
 650                                             FTernMaskOp f) {
 651         int i = 0;
 652         try {
 653             for (; i < a.length; i++) {
 654                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i],
 655                                     mask[i % SPECIES.length()]));
 656             }
 657         } catch (AssertionError err) {
 658             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i],
 659                                 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] +
 660                                 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] +
 661                                 ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]);
 662         }
 663     }
 664 
 665     static void assertDoubleBroadcastArraysEquals(int[] r, int[] a, int[] b, int[] c, FTernOp f) {
 666         int i = 0;
 667         try {
 668             for (; i < a.length; i++) {
 669                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
 670                                     c[(i / SPECIES.length()) * SPECIES.length()]));
 671             }
 672         } catch (AssertionError e) {
 673             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
 674                                 c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" + i + ", input1 = " + a[i]
 675                                 + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", input3 = " +
 676                                 c[(i / SPECIES.length()) * SPECIES.length()]);
 677         }
 678     }
 679 
 680     static void assertDoubleBroadcastArraysEquals(int[] r, int[] a, int[] b, int[] c, boolean[] mask,
 681                                                   FTernOp f) {
 682         assertDoubleBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
 683     }
 684 
 685     static void assertDoubleBroadcastArraysEquals(int[] r, int[] a, int[] b, int[] c, boolean[] mask,
 686                                                   FTernMaskOp f) {
 687         int i = 0;
 688         try {
 689             for (; i < a.length; i++) {
 690                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
 691                                     c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]));
 692             }
 693         } catch (AssertionError err) {
 694             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
 695                                 c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]), "at index #"
 696                                 + i + ", input1 = " + a[i] + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] +
 697                                 ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
 698                                 mask[i % SPECIES.length()]);
 699         }
 700     }
 701 
 702 
 703 
 704     interface FBinArrayOp {
 705         int apply(int[] a, int b);
 706     }
 707 
 708     static void assertArraysEquals(int[] r, int[] a, FBinArrayOp f) {
 709         int i = 0;
 710         try {
 711             for (; i < a.length; i++) {
 712                 Assert.assertEquals(r[i], f.apply(a, i));
 713             }
 714         } catch (AssertionError e) {
 715             Assert.assertEquals(r[i], f.apply(a,i), "at index #" + i);
 716         }
 717     }
 718 
 719     interface FGatherScatterOp {
 720         int[] apply(int[] a, int ix, int[] b, int iy);
 721     }
 722 
 723     static void assertArraysEquals(int[] r, int[] a, int[] b, FGatherScatterOp f) {
 724         int i = 0;
 725         try {
 726             for (; i < a.length; i += SPECIES.length()) {
 727                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 728                   f.apply(a, i, b, i));
 729             }
 730         } catch (AssertionError e) {
 731             int[] ref = f.apply(a, i, b, i);
 732             int[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 733             Assert.assertEquals(res, ref,
 734               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 735               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 736               + ", b: "
 737               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 738               + " at index #" + i);
 739         }
 740     }
 741 
 742     interface FGatherMaskedOp {
 743         int[] apply(int[] a, int ix, boolean[] mask, int[] b, int iy);
 744     }
 745 
 746     interface FScatterMaskedOp {
 747         int[] apply(int[] r, int[] a, int ix, boolean[] mask, int[] b, int iy);
 748     }
 749 
 750     static void assertArraysEquals(int[] r, int[] a, int[] b, boolean[] mask, FGatherMaskedOp f) {
 751         int i = 0;
 752         try {
 753             for (; i < a.length; i += SPECIES.length()) {
 754                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 755                   f.apply(a, i, mask, b, i));
 756             }
 757         } catch (AssertionError e) {
 758             int[] ref = f.apply(a, i, mask, b, i);
 759             int[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 760             Assert.assertEquals(res, ref,
 761               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 762               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 763               + ", b: "
 764               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 765               + ", mask: "
 766               + Arrays.toString(mask)
 767               + " at index #" + i);
 768         }
 769     }
 770 
 771     static void assertArraysEquals(int[] r, int[] a, int[] b, boolean[] mask, FScatterMaskedOp f) {
 772         int i = 0;
 773         try {
 774             for (; i < a.length; i += SPECIES.length()) {
 775                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 776                   f.apply(r, a, i, mask, b, i));
 777             }
 778         } catch (AssertionError e) {
 779             int[] ref = f.apply(r, a, i, mask, b, i);
 780             int[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 781             Assert.assertEquals(res, ref,
 782               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 783               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 784               + ", b: "
 785               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 786               + ", r: "
 787               + Arrays.toString(Arrays.copyOfRange(r, i, i+SPECIES.length()))
 788               + ", mask: "
 789               + Arrays.toString(mask)
 790               + " at index #" + i);
 791         }
 792     }
 793 
 794     interface FLaneOp {
 795         int[] apply(int[] a, int origin, int idx);
 796     }
 797 
 798     static void assertArraysEquals(int[] r, int[] a, int origin, FLaneOp f) {
 799         int i = 0;
 800         try {
 801             for (; i < a.length; i += SPECIES.length()) {
 802                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 803                   f.apply(a, origin, i));
 804             }
 805         } catch (AssertionError e) {
 806             int[] ref = f.apply(a, origin, i);
 807             int[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 808             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 809               + ", res: " + Arrays.toString(res)
 810               + "), at index #" + i);
 811         }
 812     }
 813 
 814     interface FLaneBop {
 815         int[] apply(int[] a, int[] b, int origin, int idx);
 816     }
 817 
 818     static void assertArraysEquals(int[] r, int[] a, int[] b, int origin, FLaneBop f) {
 819         int i = 0;
 820         try {
 821             for (; i < a.length; i += SPECIES.length()) {
 822                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 823                   f.apply(a, b, origin, i));
 824             }
 825         } catch (AssertionError e) {
 826             int[] ref = f.apply(a, b, origin, i);
 827             int[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 828             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 829               + ", res: " + Arrays.toString(res)
 830               + "), at index #" + i
 831               + ", at origin #" + origin);
 832         }
 833     }
 834 
 835     interface FLaneMaskedBop {
 836         int[] apply(int[] a, int[] b, int origin, boolean[] mask, int idx);
 837     }
 838 
 839     static void assertArraysEquals(int[] r, int[] a, int[] b, int origin, boolean[] mask, FLaneMaskedBop f) {
 840         int i = 0;
 841         try {
 842             for (; i < a.length; i += SPECIES.length()) {
 843                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 844                   f.apply(a, b, origin, mask, i));
 845             }
 846         } catch (AssertionError e) {
 847             int[] ref = f.apply(a, b, origin, mask, i);
 848             int[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 849             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 850               + ", res: " + Arrays.toString(res)
 851               + "), at index #" + i
 852               + ", at origin #" + origin);
 853         }
 854     }
 855 
 856     interface FLanePartBop {
 857         int[] apply(int[] a, int[] b, int origin, int part, int idx);
 858     }
 859 
 860     static void assertArraysEquals(int[] r, int[] a, int[] b, int origin, int part, FLanePartBop f) {
 861         int i = 0;
 862         try {
 863             for (; i < a.length; i += SPECIES.length()) {
 864                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 865                   f.apply(a, b, origin, part, i));
 866             }
 867         } catch (AssertionError e) {
 868             int[] ref = f.apply(a, b, origin, part, i);
 869             int[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 870             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 871               + ", res: " + Arrays.toString(res)
 872               + "), at index #" + i
 873               + ", at origin #" + origin
 874               + ", with part #" + part);
 875         }
 876     }
 877 
 878     interface FLanePartMaskedBop {
 879         int[] apply(int[] a, int[] b, int origin, int part, boolean[] mask, int idx);
 880     }
 881 
 882     static void assertArraysEquals(int[] r, int[] a, int[] b, int origin, int part, boolean[] mask, FLanePartMaskedBop f) {
 883         int i = 0;
 884         try {
 885             for (; i < a.length; i += SPECIES.length()) {
 886                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 887                   f.apply(a, b, origin, part, mask, i));
 888             }
 889         } catch (AssertionError e) {
 890             int[] ref = f.apply(a, b, origin, part, mask, i);
 891             int[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 892             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 893               + ", res: " + Arrays.toString(res)
 894               + "), at index #" + i
 895               + ", at origin #" + origin
 896               + ", with part #" + part);
 897         }
 898     }
 899 
 900 
 901     static void assertArraysEquals(int[] r, int[] a, int offs) {
 902         int i = 0;
 903         try {
 904             for (; i < r.length; i++) {
 905                 Assert.assertEquals(r[i], (int)(a[i+offs]));
 906             }
 907         } catch (AssertionError e) {
 908             Assert.assertEquals(r[i], (int)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
 909         }
 910     }
 911 
 912 
 913 
 914     static void assertArraysEquals(long[] r, int[] a, int offs) {
 915         int i = 0;
 916         try {
 917             for (; i < r.length; i++) {
 918                 Assert.assertEquals(r[i], (long)(a[i+offs]));
 919             }
 920         } catch (AssertionError e) {
 921             Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
 922         }
 923     }
 924 
 925     static void assertArraysEquals(double[] r, int[] a, int offs) {
 926         int i = 0;
 927         try {
 928             for (; i < r.length; i++) {
 929                 Assert.assertEquals(r[i], (double)(a[i+offs]));
 930             }
 931         } catch (AssertionError e) {
 932             Assert.assertEquals(r[i], (double)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
 933         }
 934     }
 935 
 936     static int bits(int e) {
 937         return  e;
 938     }
 939 
 940     static final List<IntFunction<int[]>> INT_GENERATORS = List.of(
 941             withToString("int[-i * 5]", (int s) -> {
 942                 return fill(s * BUFFER_REPS,
 943                             i -> (int)(-i * 5));
 944             }),
 945             withToString("int[i * 5]", (int s) -> {
 946                 return fill(s * BUFFER_REPS,
 947                             i -> (int)(i * 5));
 948             }),
 949             withToString("int[i + 1]", (int s) -> {
 950                 return fill(s * BUFFER_REPS,
 951                             i -> (((int)(i + 1) == 0) ? 1 : (int)(i + 1)));
 952             }),
 953             withToString("int[cornerCaseValue(i)]", (int s) -> {
 954                 return fill(s * BUFFER_REPS,
 955                             i -> cornerCaseValue(i));
 956             })
 957     );
 958 
 959     // Create combinations of pairs
 960     // @@@ Might be sensitive to order e.g. div by 0
 961     static final List<List<IntFunction<int[]>>> INT_GENERATOR_PAIRS =
 962         Stream.of(INT_GENERATORS.get(0)).
 963                 flatMap(fa -> INT_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
 964                 collect(Collectors.toList());
 965 
 966     @DataProvider
 967     public Object[][] boolUnaryOpProvider() {
 968         return BOOL_ARRAY_GENERATORS.stream().
 969                 map(f -> new Object[]{f}).
 970                 toArray(Object[][]::new);
 971     }
 972 
 973     static final List<List<IntFunction<int[]>>> INT_GENERATOR_TRIPLES =
 974         INT_GENERATOR_PAIRS.stream().
 975                 flatMap(pair -> INT_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))).
 976                 collect(Collectors.toList());
 977 
 978     @DataProvider
 979     public Object[][] intBinaryOpProvider() {
 980         return INT_GENERATOR_PAIRS.stream().map(List::toArray).
 981                 toArray(Object[][]::new);
 982     }
 983 
 984     @DataProvider
 985     public Object[][] intIndexedOpProvider() {
 986         return INT_GENERATOR_PAIRS.stream().map(List::toArray).
 987                 toArray(Object[][]::new);
 988     }
 989 
 990     @DataProvider
 991     public Object[][] intBinaryOpMaskProvider() {
 992         return BOOLEAN_MASK_GENERATORS.stream().
 993                 flatMap(fm -> INT_GENERATOR_PAIRS.stream().map(lfa -> {
 994                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
 995                 })).
 996                 toArray(Object[][]::new);
 997     }
 998 
 999     @DataProvider
1000     public Object[][] intTernaryOpProvider() {
1001         return INT_GENERATOR_TRIPLES.stream().map(List::toArray).
1002                 toArray(Object[][]::new);
1003     }
1004 
1005     @DataProvider
1006     public Object[][] intTernaryOpMaskProvider() {
1007         return BOOLEAN_MASK_GENERATORS.stream().
1008                 flatMap(fm -> INT_GENERATOR_TRIPLES.stream().map(lfa -> {
1009                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1010                 })).
1011                 toArray(Object[][]::new);
1012     }
1013 
1014     @DataProvider
1015     public Object[][] intUnaryOpProvider() {
1016         return INT_GENERATORS.stream().
1017                 map(f -> new Object[]{f}).
1018                 toArray(Object[][]::new);
1019     }
1020 
1021     @DataProvider
1022     public Object[][] intUnaryOpMaskProvider() {
1023         return BOOLEAN_MASK_GENERATORS.stream().
1024                 flatMap(fm -> INT_GENERATORS.stream().map(fa -> {
1025                     return new Object[] {fa, fm};
1026                 })).
1027                 toArray(Object[][]::new);
1028     }
1029 
1030     @DataProvider
1031     public Object[][] maskProvider() {
1032         return BOOLEAN_MASK_GENERATORS.stream().
1033                 map(f -> new Object[]{f}).
1034                 toArray(Object[][]::new);
1035     }
1036 
1037     @DataProvider
1038     public Object[][] maskCompareOpProvider() {
1039         return BOOLEAN_MASK_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
1040                 toArray(Object[][]::new);
1041     }
1042 
1043     @DataProvider
1044     public Object[][] shuffleProvider() {
1045         return INT_SHUFFLE_GENERATORS.stream().
1046                 map(f -> new Object[]{f}).
1047                 toArray(Object[][]::new);
1048     }
1049 
1050     @DataProvider
1051     public Object[][] shuffleCompareOpProvider() {
1052         return INT_SHUFFLE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
1053                 toArray(Object[][]::new);
1054     }
1055 
1056     @DataProvider
1057     public Object[][] intUnaryOpShuffleProvider() {
1058         return INT_SHUFFLE_GENERATORS.stream().
1059                 flatMap(fs -> INT_GENERATORS.stream().map(fa -> {
1060                     return new Object[] {fa, fs};
1061                 })).
1062                 toArray(Object[][]::new);
1063     }
1064 
1065     @DataProvider
1066     public Object[][] intUnaryOpShuffleMaskProvider() {
1067         return BOOLEAN_MASK_GENERATORS.stream().
1068                 flatMap(fm -> INT_SHUFFLE_GENERATORS.stream().
1069                     flatMap(fs -> INT_GENERATORS.stream().map(fa -> {
1070                         return new Object[] {fa, fs, fm};
1071                 }))).
1072                 toArray(Object[][]::new);
1073     }
1074 
1075     static final List<IntFunction<int[]>> INT_COMPARE_GENERATORS = List.of(
1076             withToString("int[i]", (int s) -> {
1077                 return fill(s * BUFFER_REPS,
1078                             i -> (int)i);
1079             }),
1080             withToString("int[i - length / 2]", (int s) -> {
1081                 return fill(s * BUFFER_REPS,
1082                             i -> (int)(i - (s * BUFFER_REPS / 2)));
1083             }),
1084             withToString("int[i + 1]", (int s) -> {
1085                 return fill(s * BUFFER_REPS,
1086                             i -> (int)(i + 1));
1087             }),
1088             withToString("int[i - 2]", (int s) -> {
1089                 return fill(s * BUFFER_REPS,
1090                             i -> (int)(i - 2));
1091             }),
1092             withToString("int[zigZag(i)]", (int s) -> {
1093                 return fill(s * BUFFER_REPS,
1094                             i -> i%3 == 0 ? (int)i : (i%3 == 1 ? (int)(i + 1) : (int)(i - 2)));
1095             }),
1096             withToString("int[cornerCaseValue(i)]", (int s) -> {
1097                 return fill(s * BUFFER_REPS,
1098                             i -> cornerCaseValue(i));
1099             })
1100     );
1101 
1102     static final List<List<IntFunction<int[]>>> INT_TEST_GENERATOR_ARGS =
1103         INT_COMPARE_GENERATORS.stream().
1104                 map(fa -> List.of(fa)).
1105                 collect(Collectors.toList());
1106 
1107     @DataProvider
1108     public Object[][] intTestOpProvider() {
1109         return INT_TEST_GENERATOR_ARGS.stream().map(List::toArray).
1110                 toArray(Object[][]::new);
1111     }
1112 
1113     @DataProvider
1114     public Object[][] intTestOpMaskProvider() {
1115         return BOOLEAN_MASK_GENERATORS.stream().
1116                 flatMap(fm -> INT_TEST_GENERATOR_ARGS.stream().map(lfa -> {
1117                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1118                 })).
1119                 toArray(Object[][]::new);
1120     }
1121 
1122     static final List<List<IntFunction<int[]>>> INT_COMPARE_GENERATOR_PAIRS =
1123         INT_COMPARE_GENERATORS.stream().
1124                 flatMap(fa -> INT_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))).
1125                 collect(Collectors.toList());
1126 
1127     @DataProvider
1128     public Object[][] intCompareOpProvider() {
1129         return INT_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
1130                 toArray(Object[][]::new);
1131     }
1132 
1133     @DataProvider
1134     public Object[][] intCompareOpMaskProvider() {
1135         return BOOLEAN_MASK_GENERATORS.stream().
1136                 flatMap(fm -> INT_COMPARE_GENERATOR_PAIRS.stream().map(lfa -> {
1137                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1138                 })).
1139                 toArray(Object[][]::new);
1140     }
1141 
1142     interface ToIntF {
1143         int apply(int i);
1144     }
1145 
1146     static int[] fill(int s , ToIntF f) {
1147         return fill(new int[s], f);
1148     }
1149 
1150     static int[] fill(int[] a, ToIntF f) {
1151         for (int i = 0; i < a.length; i++) {
1152             a[i] = f.apply(i);
1153         }
1154         return a;
1155     }
1156 
1157     static int cornerCaseValue(int i) {
1158         switch(i % 5) {
1159             case 0:
1160                 return Integer.MAX_VALUE;
1161             case 1:
1162                 return Integer.MIN_VALUE;
1163             case 2:
1164                 return Integer.MIN_VALUE;
1165             case 3:
1166                 return Integer.MAX_VALUE;
1167             default:
1168                 return (int)0;
1169         }
1170     }
1171 
1172     static int get(int[] a, int i) {
1173         return (int) a[i];
1174     }
1175 
1176     static final IntFunction<int[]> fr = (vl) -> {
1177         int length = BUFFER_REPS * vl;
1178         return new int[length];
1179     };
1180 
1181     static final IntFunction<boolean[]> fmr = (vl) -> {
1182         int length = BUFFER_REPS * vl;
1183         return new boolean[length];
1184     };
1185 
1186     static final IntFunction<long[]> lfr = (vl) -> {
1187         int length = BUFFER_REPS * vl;
1188         return new long[length];
1189     };
1190 
1191     static void replaceZero(int[] a, int v) {
1192         for (int i = 0; i < a.length; i++) {
1193             if (a[i] == 0) {
1194                 a[i] = v;
1195             }
1196         }
1197     }
1198 
1199     static void replaceZero(int[] a, boolean[] mask, int v) {
1200         for (int i = 0; i < a.length; i++) {
1201             if (mask[i % mask.length] && a[i] == 0) {
1202                 a[i] = v;
1203             }
1204         }
1205     }
1206 
1207     static int ROL_scalar(int a, int b) {
1208         return Integer.rotateLeft(a, ((int)b));
1209     }
1210 
1211     static int ROR_scalar(int a, int b) {
1212         return Integer.rotateRight(a, ((int)b));
1213     }
1214 
1215     static int TRAILING_ZEROS_COUNT_scalar(int a) {
1216         return Integer.numberOfTrailingZeros(a);
1217     }
1218 
1219     static int LEADING_ZEROS_COUNT_scalar(int a) {
1220         return Integer.numberOfLeadingZeros(a);
1221     }
1222 
1223     static int REVERSE_scalar(int a) {
1224         return Integer.reverse(a);
1225     }
1226 
1227     static boolean eq(int a, int b) {
1228         return a == b;
1229     }
1230 
1231     static boolean neq(int a, int b) {
1232         return a != b;
1233     }
1234 
1235     static boolean lt(int a, int b) {
1236         return a < b;
1237     }
1238 
1239     static boolean le(int a, int b) {
1240         return a <= b;
1241     }
1242 
1243     static boolean gt(int a, int b) {
1244         return a > b;
1245     }
1246 
1247     static boolean ge(int a, int b) {
1248         return a >= b;
1249     }
1250 
1251     static boolean ult(int a, int b) {
1252         return Integer.compareUnsigned(a, b) < 0;
1253     }
1254 
1255     static boolean ule(int a, int b) {
1256         return Integer.compareUnsigned(a, b) <= 0;
1257     }
1258 
1259     static boolean ugt(int a, int b) {
1260         return Integer.compareUnsigned(a, b) > 0;
1261     }
1262 
1263     static boolean uge(int a, int b) {
1264         return Integer.compareUnsigned(a, b) >= 0;
1265     }
1266 
1267     static int firstNonZero(int a, int b) {
1268         return Integer.compare(a, (int) 0) != 0 ? a : b;
1269     }
1270 
1271     @Test
1272     static void smokeTest1() {
1273         IntVector three = IntVector.broadcast(SPECIES, (byte)-3);
1274         IntVector three2 = (IntVector) SPECIES.broadcast(-3);
1275         assert(three.eq(three2).allTrue());
1276         IntVector three3 = three2.broadcast(1).broadcast(-3);
1277         assert(three.eq(three3).allTrue());
1278         int scale = 2;
1279         Class<?> ETYPE = int.class;
1280         if (ETYPE == double.class || ETYPE == long.class)
1281             scale = 1000000;
1282         else if (ETYPE == byte.class && SPECIES.length() >= 64)
1283             scale = 1;
1284         IntVector higher = three.addIndex(scale);
1285         VectorMask<Integer> m = three.compare(VectorOperators.LE, higher);
1286         assert(m.allTrue());
1287         m = higher.min((int)-1).test(VectorOperators.IS_NEGATIVE);
1288         assert(m.allTrue());
1289         int max = higher.reduceLanes(VectorOperators.MAX);
1290         assert(max == -3 + scale * (SPECIES.length()-1));
1291     }
1292 
1293     private static int[]
1294     bothToArray(IntVector a, IntVector b) {
1295         int[] r = new int[a.length() + b.length()];
1296         a.intoArray(r, 0);
1297         b.intoArray(r, a.length());
1298         return r;
1299     }
1300 
1301     @Test
1302     static void smokeTest2() {
1303         // Do some zipping and shuffling.
1304         IntVector io = (IntVector) SPECIES.broadcast(0).addIndex(1);
1305         IntVector io2 = (IntVector) VectorShuffle.iota(SPECIES,0,1,false).toVector();
1306         Assert.assertEquals(io, io2);
1307         IntVector a = io.add((int)1); //[1,2]
1308         IntVector b = a.neg();  //[-1,-2]
1309         int[] abValues = bothToArray(a,b); //[1,2,-1,-2]
1310         VectorShuffle<Integer> zip0 = VectorShuffle.makeZip(SPECIES, 0);
1311         VectorShuffle<Integer> zip1 = VectorShuffle.makeZip(SPECIES, 1);
1312         IntVector zab0 = a.rearrange(zip0,b); //[1,-1]
1313         IntVector zab1 = a.rearrange(zip1,b); //[2,-2]
1314         int[] zabValues = bothToArray(zab0, zab1); //[1,-1,2,-2]
1315         // manually zip
1316         int[] manual = new int[zabValues.length];
1317         for (int i = 0; i < manual.length; i += 2) {
1318             manual[i+0] = abValues[i/2];
1319             manual[i+1] = abValues[a.length() + i/2];
1320         }
1321         Assert.assertEquals(Arrays.toString(zabValues), Arrays.toString(manual));
1322         VectorShuffle<Integer> unz0 = VectorShuffle.makeUnzip(SPECIES, 0);
1323         VectorShuffle<Integer> unz1 = VectorShuffle.makeUnzip(SPECIES, 1);
1324         IntVector uab0 = zab0.rearrange(unz0,zab1);
1325         IntVector uab1 = zab0.rearrange(unz1,zab1);
1326         int[] abValues1 = bothToArray(uab0, uab1);
1327         Assert.assertEquals(Arrays.toString(abValues), Arrays.toString(abValues1));
1328     }
1329 
1330     static void iotaShuffle() {
1331         IntVector io = (IntVector) SPECIES.broadcast(0).addIndex(1);
1332         IntVector io2 = (IntVector) VectorShuffle.iota(SPECIES, 0 , 1, false).toVector();
1333         Assert.assertEquals(io, io2);
1334     }
1335 
1336     @Test
1337     // Test all shuffle related operations.
1338     static void shuffleTest() {
1339         // To test backend instructions, make sure that C2 is used.
1340         for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) {
1341             iotaShuffle();
1342         }
1343     }
1344 
1345     @Test
1346     void viewAsIntegeralLanesTest() {
1347         Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes();
1348         Assert.assertEquals(asIntegral.species(), SPECIES);
1349     }
1350 
1351     @Test
1352     void viewAsFloatingLanesTest() {
1353         Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes();
1354         VectorSpecies<?> asFloatingSpecies = asFloating.species();
1355         Assert.assertNotEquals(asFloatingSpecies.elementType(), SPECIES.elementType());
1356         Assert.assertEquals(asFloatingSpecies.vectorShape(), SPECIES.vectorShape());
1357         Assert.assertEquals(asFloatingSpecies.length(), SPECIES.length());
1358         Assert.assertEquals(asFloating.viewAsIntegralLanes().species(), SPECIES);
1359     }
1360 
1361     @Test
1362     // Test div by 0.
1363     static void bitwiseDivByZeroSmokeTest() {
1364         try {
1365             IntVector a = (IntVector) SPECIES.broadcast(0).addIndex(1);
1366             IntVector b = (IntVector) SPECIES.broadcast(0);
1367             a.div(b);
1368             Assert.fail();
1369         } catch (ArithmeticException e) {
1370         }
1371 
1372         try {
1373             IntVector a = (IntVector) SPECIES.broadcast(0).addIndex(1);
1374             IntVector b = (IntVector) SPECIES.broadcast(0);
1375             VectorMask<Integer> m = a.lt((int) 1);
1376             a.div(b, m);
1377             Assert.fail();
1378         } catch (ArithmeticException e) {
1379         }
1380     }
1381 
1382     static int ADD(int a, int b) {
1383         return (int)(a + b);
1384     }
1385 
1386     @Test(dataProvider = "intBinaryOpProvider")
1387     static void ADDInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1388         int[] a = fa.apply(SPECIES.length());
1389         int[] b = fb.apply(SPECIES.length());
1390         int[] r = fr.apply(SPECIES.length());
1391 
1392         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1393             for (int i = 0; i < a.length; i += SPECIES.length()) {
1394                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1395                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1396                 av.lanewise(VectorOperators.ADD, bv).intoArray(r, i);
1397             }
1398         }
1399 
1400         assertArraysEquals(r, a, b, Int512VectorTests::ADD);
1401     }
1402 
1403     static int add(int a, int b) {
1404         return (int)(a + b);
1405     }
1406 
1407     @Test(dataProvider = "intBinaryOpProvider")
1408     static void addInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1409         int[] a = fa.apply(SPECIES.length());
1410         int[] b = fb.apply(SPECIES.length());
1411         int[] r = fr.apply(SPECIES.length());
1412 
1413         for (int i = 0; i < a.length; i += SPECIES.length()) {
1414             IntVector av = IntVector.fromArray(SPECIES, a, i);
1415             IntVector bv = IntVector.fromArray(SPECIES, b, i);
1416             av.add(bv).intoArray(r, i);
1417         }
1418 
1419         assertArraysEquals(r, a, b, Int512VectorTests::add);
1420     }
1421 
1422     @Test(dataProvider = "intBinaryOpMaskProvider")
1423     static void ADDInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
1424                                           IntFunction<boolean[]> fm) {
1425         int[] a = fa.apply(SPECIES.length());
1426         int[] b = fb.apply(SPECIES.length());
1427         int[] r = fr.apply(SPECIES.length());
1428         boolean[] mask = fm.apply(SPECIES.length());
1429         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1430 
1431         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1432             for (int i = 0; i < a.length; i += SPECIES.length()) {
1433                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1434                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1435                 av.lanewise(VectorOperators.ADD, bv, vmask).intoArray(r, i);
1436             }
1437         }
1438 
1439         assertArraysEquals(r, a, b, mask, Int512VectorTests::ADD);
1440     }
1441 
1442     @Test(dataProvider = "intBinaryOpMaskProvider")
1443     static void addInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
1444                                           IntFunction<boolean[]> fm) {
1445         int[] a = fa.apply(SPECIES.length());
1446         int[] b = fb.apply(SPECIES.length());
1447         int[] r = fr.apply(SPECIES.length());
1448         boolean[] mask = fm.apply(SPECIES.length());
1449         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1450 
1451         for (int i = 0; i < a.length; i += SPECIES.length()) {
1452             IntVector av = IntVector.fromArray(SPECIES, a, i);
1453             IntVector bv = IntVector.fromArray(SPECIES, b, i);
1454             av.add(bv, vmask).intoArray(r, i);
1455         }
1456 
1457         assertArraysEquals(r, a, b, mask, Int512VectorTests::add);
1458     }
1459 
1460     static int SUB(int a, int b) {
1461         return (int)(a - b);
1462     }
1463 
1464     @Test(dataProvider = "intBinaryOpProvider")
1465     static void SUBInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1466         int[] a = fa.apply(SPECIES.length());
1467         int[] b = fb.apply(SPECIES.length());
1468         int[] r = fr.apply(SPECIES.length());
1469 
1470         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1471             for (int i = 0; i < a.length; i += SPECIES.length()) {
1472                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1473                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1474                 av.lanewise(VectorOperators.SUB, bv).intoArray(r, i);
1475             }
1476         }
1477 
1478         assertArraysEquals(r, a, b, Int512VectorTests::SUB);
1479     }
1480 
1481     static int sub(int a, int b) {
1482         return (int)(a - b);
1483     }
1484 
1485     @Test(dataProvider = "intBinaryOpProvider")
1486     static void subInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1487         int[] a = fa.apply(SPECIES.length());
1488         int[] b = fb.apply(SPECIES.length());
1489         int[] r = fr.apply(SPECIES.length());
1490 
1491         for (int i = 0; i < a.length; i += SPECIES.length()) {
1492             IntVector av = IntVector.fromArray(SPECIES, a, i);
1493             IntVector bv = IntVector.fromArray(SPECIES, b, i);
1494             av.sub(bv).intoArray(r, i);
1495         }
1496 
1497         assertArraysEquals(r, a, b, Int512VectorTests::sub);
1498     }
1499 
1500     @Test(dataProvider = "intBinaryOpMaskProvider")
1501     static void SUBInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
1502                                           IntFunction<boolean[]> fm) {
1503         int[] a = fa.apply(SPECIES.length());
1504         int[] b = fb.apply(SPECIES.length());
1505         int[] r = fr.apply(SPECIES.length());
1506         boolean[] mask = fm.apply(SPECIES.length());
1507         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1508 
1509         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1510             for (int i = 0; i < a.length; i += SPECIES.length()) {
1511                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1512                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1513                 av.lanewise(VectorOperators.SUB, bv, vmask).intoArray(r, i);
1514             }
1515         }
1516 
1517         assertArraysEquals(r, a, b, mask, Int512VectorTests::SUB);
1518     }
1519 
1520     @Test(dataProvider = "intBinaryOpMaskProvider")
1521     static void subInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
1522                                           IntFunction<boolean[]> fm) {
1523         int[] a = fa.apply(SPECIES.length());
1524         int[] b = fb.apply(SPECIES.length());
1525         int[] r = fr.apply(SPECIES.length());
1526         boolean[] mask = fm.apply(SPECIES.length());
1527         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1528 
1529         for (int i = 0; i < a.length; i += SPECIES.length()) {
1530             IntVector av = IntVector.fromArray(SPECIES, a, i);
1531             IntVector bv = IntVector.fromArray(SPECIES, b, i);
1532             av.sub(bv, vmask).intoArray(r, i);
1533         }
1534 
1535         assertArraysEquals(r, a, b, mask, Int512VectorTests::sub);
1536     }
1537 
1538     static int MUL(int a, int b) {
1539         return (int)(a * b);
1540     }
1541 
1542     @Test(dataProvider = "intBinaryOpProvider")
1543     static void MULInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1544         int[] a = fa.apply(SPECIES.length());
1545         int[] b = fb.apply(SPECIES.length());
1546         int[] r = fr.apply(SPECIES.length());
1547 
1548         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1549             for (int i = 0; i < a.length; i += SPECIES.length()) {
1550                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1551                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1552                 av.lanewise(VectorOperators.MUL, bv).intoArray(r, i);
1553             }
1554         }
1555 
1556         assertArraysEquals(r, a, b, Int512VectorTests::MUL);
1557     }
1558 
1559     static int mul(int a, int b) {
1560         return (int)(a * b);
1561     }
1562 
1563     @Test(dataProvider = "intBinaryOpProvider")
1564     static void mulInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1565         int[] a = fa.apply(SPECIES.length());
1566         int[] b = fb.apply(SPECIES.length());
1567         int[] r = fr.apply(SPECIES.length());
1568 
1569         for (int i = 0; i < a.length; i += SPECIES.length()) {
1570             IntVector av = IntVector.fromArray(SPECIES, a, i);
1571             IntVector bv = IntVector.fromArray(SPECIES, b, i);
1572             av.mul(bv).intoArray(r, i);
1573         }
1574 
1575         assertArraysEquals(r, a, b, Int512VectorTests::mul);
1576     }
1577 
1578     @Test(dataProvider = "intBinaryOpMaskProvider")
1579     static void MULInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
1580                                           IntFunction<boolean[]> fm) {
1581         int[] a = fa.apply(SPECIES.length());
1582         int[] b = fb.apply(SPECIES.length());
1583         int[] r = fr.apply(SPECIES.length());
1584         boolean[] mask = fm.apply(SPECIES.length());
1585         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1586 
1587         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1588             for (int i = 0; i < a.length; i += SPECIES.length()) {
1589                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1590                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1591                 av.lanewise(VectorOperators.MUL, bv, vmask).intoArray(r, i);
1592             }
1593         }
1594 
1595         assertArraysEquals(r, a, b, mask, Int512VectorTests::MUL);
1596     }
1597 
1598     @Test(dataProvider = "intBinaryOpMaskProvider")
1599     static void mulInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
1600                                           IntFunction<boolean[]> fm) {
1601         int[] a = fa.apply(SPECIES.length());
1602         int[] b = fb.apply(SPECIES.length());
1603         int[] r = fr.apply(SPECIES.length());
1604         boolean[] mask = fm.apply(SPECIES.length());
1605         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1606 
1607         for (int i = 0; i < a.length; i += SPECIES.length()) {
1608             IntVector av = IntVector.fromArray(SPECIES, a, i);
1609             IntVector bv = IntVector.fromArray(SPECIES, b, i);
1610             av.mul(bv, vmask).intoArray(r, i);
1611         }
1612 
1613         assertArraysEquals(r, a, b, mask, Int512VectorTests::mul);
1614     }
1615 
1616     static int DIV(int a, int b) {
1617         return (int)(a / b);
1618     }
1619 
1620     @Test(dataProvider = "intBinaryOpProvider")
1621     static void DIVInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1622         int[] a = fa.apply(SPECIES.length());
1623         int[] b = fb.apply(SPECIES.length());
1624         int[] r = fr.apply(SPECIES.length());
1625 
1626         replaceZero(b, (int) 1);
1627 
1628         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1629             for (int i = 0; i < a.length; i += SPECIES.length()) {
1630                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1631                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1632                 av.lanewise(VectorOperators.DIV, bv).intoArray(r, i);
1633             }
1634         }
1635 
1636         assertArraysEquals(r, a, b, Int512VectorTests::DIV);
1637     }
1638 
1639     static int div(int a, int b) {
1640         return (int)(a / b);
1641     }
1642 
1643     @Test(dataProvider = "intBinaryOpProvider")
1644     static void divInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1645         int[] a = fa.apply(SPECIES.length());
1646         int[] b = fb.apply(SPECIES.length());
1647         int[] r = fr.apply(SPECIES.length());
1648 
1649         replaceZero(b, (int) 1);
1650 
1651         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1652             for (int i = 0; i < a.length; i += SPECIES.length()) {
1653                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1654                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1655                 av.div(bv).intoArray(r, i);
1656             }
1657         }
1658 
1659         assertArraysEquals(r, a, b, Int512VectorTests::div);
1660     }
1661 
1662     @Test(dataProvider = "intBinaryOpMaskProvider")
1663     static void DIVInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
1664                                           IntFunction<boolean[]> fm) {
1665         int[] a = fa.apply(SPECIES.length());
1666         int[] b = fb.apply(SPECIES.length());
1667         int[] r = fr.apply(SPECIES.length());
1668         boolean[] mask = fm.apply(SPECIES.length());
1669         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1670 
1671         replaceZero(b, mask, (int) 1);
1672 
1673         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1674             for (int i = 0; i < a.length; i += SPECIES.length()) {
1675                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1676                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1677                 av.lanewise(VectorOperators.DIV, bv, vmask).intoArray(r, i);
1678             }
1679         }
1680 
1681         assertArraysEquals(r, a, b, mask, Int512VectorTests::DIV);
1682     }
1683 
1684     @Test(dataProvider = "intBinaryOpMaskProvider")
1685     static void divInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
1686                                           IntFunction<boolean[]> fm) {
1687         int[] a = fa.apply(SPECIES.length());
1688         int[] b = fb.apply(SPECIES.length());
1689         int[] r = fr.apply(SPECIES.length());
1690         boolean[] mask = fm.apply(SPECIES.length());
1691         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1692 
1693         replaceZero(b, mask, (int) 1);
1694 
1695         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1696             for (int i = 0; i < a.length; i += SPECIES.length()) {
1697                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1698                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1699                 av.div(bv, vmask).intoArray(r, i);
1700             }
1701         }
1702 
1703         assertArraysEquals(r, a, b, mask, Int512VectorTests::div);
1704     }
1705 
1706     static int FIRST_NONZERO(int a, int b) {
1707         return (int)((a)!=0?a:b);
1708     }
1709 
1710     @Test(dataProvider = "intBinaryOpProvider")
1711     static void FIRST_NONZEROInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1712         int[] a = fa.apply(SPECIES.length());
1713         int[] b = fb.apply(SPECIES.length());
1714         int[] r = fr.apply(SPECIES.length());
1715 
1716         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1717             for (int i = 0; i < a.length; i += SPECIES.length()) {
1718                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1719                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1720                 av.lanewise(VectorOperators.FIRST_NONZERO, bv).intoArray(r, i);
1721             }
1722         }
1723 
1724         assertArraysEquals(r, a, b, Int512VectorTests::FIRST_NONZERO);
1725     }
1726 
1727     @Test(dataProvider = "intBinaryOpMaskProvider")
1728     static void FIRST_NONZEROInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
1729                                           IntFunction<boolean[]> fm) {
1730         int[] a = fa.apply(SPECIES.length());
1731         int[] b = fb.apply(SPECIES.length());
1732         int[] r = fr.apply(SPECIES.length());
1733         boolean[] mask = fm.apply(SPECIES.length());
1734         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1735 
1736         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1737             for (int i = 0; i < a.length; i += SPECIES.length()) {
1738                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1739                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1740                 av.lanewise(VectorOperators.FIRST_NONZERO, bv, vmask).intoArray(r, i);
1741             }
1742         }
1743 
1744         assertArraysEquals(r, a, b, mask, Int512VectorTests::FIRST_NONZERO);
1745     }
1746 
1747     static int AND(int a, int b) {
1748         return (int)(a & b);
1749     }
1750 
1751     @Test(dataProvider = "intBinaryOpProvider")
1752     static void ANDInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1753         int[] a = fa.apply(SPECIES.length());
1754         int[] b = fb.apply(SPECIES.length());
1755         int[] r = fr.apply(SPECIES.length());
1756 
1757         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1758             for (int i = 0; i < a.length; i += SPECIES.length()) {
1759                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1760                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1761                 av.lanewise(VectorOperators.AND, bv).intoArray(r, i);
1762             }
1763         }
1764 
1765         assertArraysEquals(r, a, b, Int512VectorTests::AND);
1766     }
1767 
1768     static int and(int a, int b) {
1769         return (int)(a & b);
1770     }
1771 
1772     @Test(dataProvider = "intBinaryOpProvider")
1773     static void andInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1774         int[] a = fa.apply(SPECIES.length());
1775         int[] b = fb.apply(SPECIES.length());
1776         int[] r = fr.apply(SPECIES.length());
1777 
1778         for (int i = 0; i < a.length; i += SPECIES.length()) {
1779             IntVector av = IntVector.fromArray(SPECIES, a, i);
1780             IntVector bv = IntVector.fromArray(SPECIES, b, i);
1781             av.and(bv).intoArray(r, i);
1782         }
1783 
1784         assertArraysEquals(r, a, b, Int512VectorTests::and);
1785     }
1786 
1787     @Test(dataProvider = "intBinaryOpMaskProvider")
1788     static void ANDInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
1789                                           IntFunction<boolean[]> fm) {
1790         int[] a = fa.apply(SPECIES.length());
1791         int[] b = fb.apply(SPECIES.length());
1792         int[] r = fr.apply(SPECIES.length());
1793         boolean[] mask = fm.apply(SPECIES.length());
1794         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1795 
1796         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1797             for (int i = 0; i < a.length; i += SPECIES.length()) {
1798                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1799                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1800                 av.lanewise(VectorOperators.AND, bv, vmask).intoArray(r, i);
1801             }
1802         }
1803 
1804         assertArraysEquals(r, a, b, mask, Int512VectorTests::AND);
1805     }
1806 
1807     static int AND_NOT(int a, int b) {
1808         return (int)(a & ~b);
1809     }
1810 
1811     @Test(dataProvider = "intBinaryOpProvider")
1812     static void AND_NOTInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1813         int[] a = fa.apply(SPECIES.length());
1814         int[] b = fb.apply(SPECIES.length());
1815         int[] r = fr.apply(SPECIES.length());
1816 
1817         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1818             for (int i = 0; i < a.length; i += SPECIES.length()) {
1819                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1820                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1821                 av.lanewise(VectorOperators.AND_NOT, bv).intoArray(r, i);
1822             }
1823         }
1824 
1825         assertArraysEquals(r, a, b, Int512VectorTests::AND_NOT);
1826     }
1827 
1828     @Test(dataProvider = "intBinaryOpMaskProvider")
1829     static void AND_NOTInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
1830                                           IntFunction<boolean[]> fm) {
1831         int[] a = fa.apply(SPECIES.length());
1832         int[] b = fb.apply(SPECIES.length());
1833         int[] r = fr.apply(SPECIES.length());
1834         boolean[] mask = fm.apply(SPECIES.length());
1835         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1836 
1837         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1838             for (int i = 0; i < a.length; i += SPECIES.length()) {
1839                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1840                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1841                 av.lanewise(VectorOperators.AND_NOT, bv, vmask).intoArray(r, i);
1842             }
1843         }
1844 
1845         assertArraysEquals(r, a, b, mask, Int512VectorTests::AND_NOT);
1846     }
1847 
1848     static int OR(int a, int b) {
1849         return (int)(a | b);
1850     }
1851 
1852     @Test(dataProvider = "intBinaryOpProvider")
1853     static void ORInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1854         int[] a = fa.apply(SPECIES.length());
1855         int[] b = fb.apply(SPECIES.length());
1856         int[] r = fr.apply(SPECIES.length());
1857 
1858         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1859             for (int i = 0; i < a.length; i += SPECIES.length()) {
1860                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1861                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1862                 av.lanewise(VectorOperators.OR, bv).intoArray(r, i);
1863             }
1864         }
1865 
1866         assertArraysEquals(r, a, b, Int512VectorTests::OR);
1867     }
1868 
1869     static int or(int a, int b) {
1870         return (int)(a | b);
1871     }
1872 
1873     @Test(dataProvider = "intBinaryOpProvider")
1874     static void orInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1875         int[] a = fa.apply(SPECIES.length());
1876         int[] b = fb.apply(SPECIES.length());
1877         int[] r = fr.apply(SPECIES.length());
1878 
1879         for (int i = 0; i < a.length; i += SPECIES.length()) {
1880             IntVector av = IntVector.fromArray(SPECIES, a, i);
1881             IntVector bv = IntVector.fromArray(SPECIES, b, i);
1882             av.or(bv).intoArray(r, i);
1883         }
1884 
1885         assertArraysEquals(r, a, b, Int512VectorTests::or);
1886     }
1887 
1888     @Test(dataProvider = "intBinaryOpMaskProvider")
1889     static void ORInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
1890                                           IntFunction<boolean[]> fm) {
1891         int[] a = fa.apply(SPECIES.length());
1892         int[] b = fb.apply(SPECIES.length());
1893         int[] r = fr.apply(SPECIES.length());
1894         boolean[] mask = fm.apply(SPECIES.length());
1895         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1896 
1897         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1898             for (int i = 0; i < a.length; i += SPECIES.length()) {
1899                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1900                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1901                 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i);
1902             }
1903         }
1904 
1905         assertArraysEquals(r, a, b, mask, Int512VectorTests::OR);
1906     }
1907 
1908     static int XOR(int a, int b) {
1909         return (int)(a ^ b);
1910     }
1911 
1912     @Test(dataProvider = "intBinaryOpProvider")
1913     static void XORInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1914         int[] a = fa.apply(SPECIES.length());
1915         int[] b = fb.apply(SPECIES.length());
1916         int[] r = fr.apply(SPECIES.length());
1917 
1918         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1919             for (int i = 0; i < a.length; i += SPECIES.length()) {
1920                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1921                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1922                 av.lanewise(VectorOperators.XOR, bv).intoArray(r, i);
1923             }
1924         }
1925 
1926         assertArraysEquals(r, a, b, Int512VectorTests::XOR);
1927     }
1928 
1929     @Test(dataProvider = "intBinaryOpMaskProvider")
1930     static void XORInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
1931                                           IntFunction<boolean[]> fm) {
1932         int[] a = fa.apply(SPECIES.length());
1933         int[] b = fb.apply(SPECIES.length());
1934         int[] r = fr.apply(SPECIES.length());
1935         boolean[] mask = fm.apply(SPECIES.length());
1936         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1937 
1938         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1939             for (int i = 0; i < a.length; i += SPECIES.length()) {
1940                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1941                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1942                 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i);
1943             }
1944         }
1945 
1946         assertArraysEquals(r, a, b, mask, Int512VectorTests::XOR);
1947     }
1948 
1949     static int COMPRESS_BITS(int a, int b) {
1950         return (int)(Integer.compress(a, b));
1951     }
1952 
1953     @Test(dataProvider = "intBinaryOpProvider")
1954     static void COMPRESS_BITSInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1955         int[] a = fa.apply(SPECIES.length());
1956         int[] b = fb.apply(SPECIES.length());
1957         int[] r = fr.apply(SPECIES.length());
1958 
1959         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1960             for (int i = 0; i < a.length; i += SPECIES.length()) {
1961                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1962                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1963                 av.lanewise(VectorOperators.COMPRESS_BITS, bv).intoArray(r, i);
1964             }
1965         }
1966 
1967         assertArraysEquals(r, a, b, Int512VectorTests::COMPRESS_BITS);
1968     }
1969 
1970     @Test(dataProvider = "intBinaryOpMaskProvider")
1971     static void COMPRESS_BITSInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
1972                                           IntFunction<boolean[]> fm) {
1973         int[] a = fa.apply(SPECIES.length());
1974         int[] b = fb.apply(SPECIES.length());
1975         int[] r = fr.apply(SPECIES.length());
1976         boolean[] mask = fm.apply(SPECIES.length());
1977         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1978 
1979         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1980             for (int i = 0; i < a.length; i += SPECIES.length()) {
1981                 IntVector av = IntVector.fromArray(SPECIES, a, i);
1982                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
1983                 av.lanewise(VectorOperators.COMPRESS_BITS, bv, vmask).intoArray(r, i);
1984             }
1985         }
1986 
1987         assertArraysEquals(r, a, b, mask, Int512VectorTests::COMPRESS_BITS);
1988     }
1989 
1990     static int EXPAND_BITS(int a, int b) {
1991         return (int)(Integer.expand(a, b));
1992     }
1993 
1994     @Test(dataProvider = "intBinaryOpProvider")
1995     static void EXPAND_BITSInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
1996         int[] a = fa.apply(SPECIES.length());
1997         int[] b = fb.apply(SPECIES.length());
1998         int[] r = fr.apply(SPECIES.length());
1999 
2000         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2001             for (int i = 0; i < a.length; i += SPECIES.length()) {
2002                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2003                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
2004                 av.lanewise(VectorOperators.EXPAND_BITS, bv).intoArray(r, i);
2005             }
2006         }
2007 
2008         assertArraysEquals(r, a, b, Int512VectorTests::EXPAND_BITS);
2009     }
2010 
2011     @Test(dataProvider = "intBinaryOpMaskProvider")
2012     static void EXPAND_BITSInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
2013                                           IntFunction<boolean[]> fm) {
2014         int[] a = fa.apply(SPECIES.length());
2015         int[] b = fb.apply(SPECIES.length());
2016         int[] r = fr.apply(SPECIES.length());
2017         boolean[] mask = fm.apply(SPECIES.length());
2018         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2019 
2020         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2021             for (int i = 0; i < a.length; i += SPECIES.length()) {
2022                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2023                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
2024                 av.lanewise(VectorOperators.EXPAND_BITS, bv, vmask).intoArray(r, i);
2025             }
2026         }
2027 
2028         assertArraysEquals(r, a, b, mask, Int512VectorTests::EXPAND_BITS);
2029     }
2030 
2031     @Test(dataProvider = "intBinaryOpProvider")
2032     static void addInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2033         int[] a = fa.apply(SPECIES.length());
2034         int[] b = fb.apply(SPECIES.length());
2035         int[] r = fr.apply(SPECIES.length());
2036 
2037         for (int i = 0; i < a.length; i += SPECIES.length()) {
2038             IntVector av = IntVector.fromArray(SPECIES, a, i);
2039             av.add(b[i]).intoArray(r, i);
2040         }
2041 
2042         assertBroadcastArraysEquals(r, a, b, Int512VectorTests::add);
2043     }
2044 
2045     @Test(dataProvider = "intBinaryOpMaskProvider")
2046     static void addInt512VectorTestsBroadcastMaskedSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb,
2047                                           IntFunction<boolean[]> fm) {
2048         int[] a = fa.apply(SPECIES.length());
2049         int[] b = fb.apply(SPECIES.length());
2050         int[] r = fr.apply(SPECIES.length());
2051         boolean[] mask = fm.apply(SPECIES.length());
2052         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2053 
2054         for (int i = 0; i < a.length; i += SPECIES.length()) {
2055             IntVector av = IntVector.fromArray(SPECIES, a, i);
2056             av.add(b[i], vmask).intoArray(r, i);
2057         }
2058 
2059         assertBroadcastArraysEquals(r, a, b, mask, Int512VectorTests::add);
2060     }
2061 
2062     @Test(dataProvider = "intBinaryOpProvider")
2063     static void subInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2064         int[] a = fa.apply(SPECIES.length());
2065         int[] b = fb.apply(SPECIES.length());
2066         int[] r = fr.apply(SPECIES.length());
2067 
2068         for (int i = 0; i < a.length; i += SPECIES.length()) {
2069             IntVector av = IntVector.fromArray(SPECIES, a, i);
2070             av.sub(b[i]).intoArray(r, i);
2071         }
2072 
2073         assertBroadcastArraysEquals(r, a, b, Int512VectorTests::sub);
2074     }
2075 
2076     @Test(dataProvider = "intBinaryOpMaskProvider")
2077     static void subInt512VectorTestsBroadcastMaskedSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb,
2078                                           IntFunction<boolean[]> fm) {
2079         int[] a = fa.apply(SPECIES.length());
2080         int[] b = fb.apply(SPECIES.length());
2081         int[] r = fr.apply(SPECIES.length());
2082         boolean[] mask = fm.apply(SPECIES.length());
2083         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2084 
2085         for (int i = 0; i < a.length; i += SPECIES.length()) {
2086             IntVector av = IntVector.fromArray(SPECIES, a, i);
2087             av.sub(b[i], vmask).intoArray(r, i);
2088         }
2089 
2090         assertBroadcastArraysEquals(r, a, b, mask, Int512VectorTests::sub);
2091     }
2092 
2093     @Test(dataProvider = "intBinaryOpProvider")
2094     static void mulInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2095         int[] a = fa.apply(SPECIES.length());
2096         int[] b = fb.apply(SPECIES.length());
2097         int[] r = fr.apply(SPECIES.length());
2098 
2099         for (int i = 0; i < a.length; i += SPECIES.length()) {
2100             IntVector av = IntVector.fromArray(SPECIES, a, i);
2101             av.mul(b[i]).intoArray(r, i);
2102         }
2103 
2104         assertBroadcastArraysEquals(r, a, b, Int512VectorTests::mul);
2105     }
2106 
2107     @Test(dataProvider = "intBinaryOpMaskProvider")
2108     static void mulInt512VectorTestsBroadcastMaskedSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb,
2109                                           IntFunction<boolean[]> fm) {
2110         int[] a = fa.apply(SPECIES.length());
2111         int[] b = fb.apply(SPECIES.length());
2112         int[] r = fr.apply(SPECIES.length());
2113         boolean[] mask = fm.apply(SPECIES.length());
2114         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2115 
2116         for (int i = 0; i < a.length; i += SPECIES.length()) {
2117             IntVector av = IntVector.fromArray(SPECIES, a, i);
2118             av.mul(b[i], vmask).intoArray(r, i);
2119         }
2120 
2121         assertBroadcastArraysEquals(r, a, b, mask, Int512VectorTests::mul);
2122     }
2123 
2124     @Test(dataProvider = "intBinaryOpProvider")
2125     static void divInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2126         int[] a = fa.apply(SPECIES.length());
2127         int[] b = fb.apply(SPECIES.length());
2128         int[] r = fr.apply(SPECIES.length());
2129 
2130         replaceZero(b, (int) 1);
2131 
2132         for (int i = 0; i < a.length; i += SPECIES.length()) {
2133             IntVector av = IntVector.fromArray(SPECIES, a, i);
2134             av.div(b[i]).intoArray(r, i);
2135         }
2136 
2137         assertBroadcastArraysEquals(r, a, b, Int512VectorTests::div);
2138     }
2139 
2140     @Test(dataProvider = "intBinaryOpMaskProvider")
2141     static void divInt512VectorTestsBroadcastMaskedSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb,
2142                                           IntFunction<boolean[]> fm) {
2143         int[] a = fa.apply(SPECIES.length());
2144         int[] b = fb.apply(SPECIES.length());
2145         int[] r = fr.apply(SPECIES.length());
2146         boolean[] mask = fm.apply(SPECIES.length());
2147         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2148 
2149         replaceZero(b, (int) 1);
2150 
2151         for (int i = 0; i < a.length; i += SPECIES.length()) {
2152             IntVector av = IntVector.fromArray(SPECIES, a, i);
2153             av.div(b[i], vmask).intoArray(r, i);
2154         }
2155 
2156         assertBroadcastArraysEquals(r, a, b, mask, Int512VectorTests::div);
2157     }
2158 
2159     @Test(dataProvider = "intBinaryOpProvider")
2160     static void ORInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2161         int[] a = fa.apply(SPECIES.length());
2162         int[] b = fb.apply(SPECIES.length());
2163         int[] r = fr.apply(SPECIES.length());
2164 
2165         for (int i = 0; i < a.length; i += SPECIES.length()) {
2166             IntVector av = IntVector.fromArray(SPECIES, a, i);
2167             av.lanewise(VectorOperators.OR, b[i]).intoArray(r, i);
2168         }
2169 
2170         assertBroadcastArraysEquals(r, a, b, Int512VectorTests::OR);
2171     }
2172 
2173     @Test(dataProvider = "intBinaryOpProvider")
2174     static void orInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2175         int[] a = fa.apply(SPECIES.length());
2176         int[] b = fb.apply(SPECIES.length());
2177         int[] r = fr.apply(SPECIES.length());
2178 
2179         for (int i = 0; i < a.length; i += SPECIES.length()) {
2180             IntVector av = IntVector.fromArray(SPECIES, a, i);
2181             av.or(b[i]).intoArray(r, i);
2182         }
2183 
2184         assertBroadcastArraysEquals(r, a, b, Int512VectorTests::or);
2185     }
2186 
2187     @Test(dataProvider = "intBinaryOpMaskProvider")
2188     static void ORInt512VectorTestsBroadcastMaskedSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb,
2189                                           IntFunction<boolean[]> fm) {
2190         int[] a = fa.apply(SPECIES.length());
2191         int[] b = fb.apply(SPECIES.length());
2192         int[] r = fr.apply(SPECIES.length());
2193         boolean[] mask = fm.apply(SPECIES.length());
2194         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2195 
2196         for (int i = 0; i < a.length; i += SPECIES.length()) {
2197             IntVector av = IntVector.fromArray(SPECIES, a, i);
2198             av.lanewise(VectorOperators.OR, b[i], vmask).intoArray(r, i);
2199         }
2200 
2201         assertBroadcastArraysEquals(r, a, b, mask, Int512VectorTests::OR);
2202     }
2203 
2204     @Test(dataProvider = "intBinaryOpProvider")
2205     static void ANDInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2206         int[] a = fa.apply(SPECIES.length());
2207         int[] b = fb.apply(SPECIES.length());
2208         int[] r = fr.apply(SPECIES.length());
2209 
2210         for (int i = 0; i < a.length; i += SPECIES.length()) {
2211             IntVector av = IntVector.fromArray(SPECIES, a, i);
2212             av.lanewise(VectorOperators.AND, b[i]).intoArray(r, i);
2213         }
2214 
2215         assertBroadcastArraysEquals(r, a, b, Int512VectorTests::AND);
2216     }
2217 
2218     @Test(dataProvider = "intBinaryOpProvider")
2219     static void andInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2220         int[] a = fa.apply(SPECIES.length());
2221         int[] b = fb.apply(SPECIES.length());
2222         int[] r = fr.apply(SPECIES.length());
2223 
2224         for (int i = 0; i < a.length; i += SPECIES.length()) {
2225             IntVector av = IntVector.fromArray(SPECIES, a, i);
2226             av.and(b[i]).intoArray(r, i);
2227         }
2228 
2229         assertBroadcastArraysEquals(r, a, b, Int512VectorTests::and);
2230     }
2231 
2232     @Test(dataProvider = "intBinaryOpMaskProvider")
2233     static void ANDInt512VectorTestsBroadcastMaskedSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb,
2234                                           IntFunction<boolean[]> fm) {
2235         int[] a = fa.apply(SPECIES.length());
2236         int[] b = fb.apply(SPECIES.length());
2237         int[] r = fr.apply(SPECIES.length());
2238         boolean[] mask = fm.apply(SPECIES.length());
2239         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2240 
2241         for (int i = 0; i < a.length; i += SPECIES.length()) {
2242             IntVector av = IntVector.fromArray(SPECIES, a, i);
2243             av.lanewise(VectorOperators.AND, b[i], vmask).intoArray(r, i);
2244         }
2245 
2246         assertBroadcastArraysEquals(r, a, b, mask, Int512VectorTests::AND);
2247     }
2248 
2249     @Test(dataProvider = "intBinaryOpProvider")
2250     static void ORInt512VectorTestsBroadcastLongSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2251         int[] a = fa.apply(SPECIES.length());
2252         int[] b = fb.apply(SPECIES.length());
2253         int[] r = fr.apply(SPECIES.length());
2254 
2255         for (int i = 0; i < a.length; i += SPECIES.length()) {
2256             IntVector av = IntVector.fromArray(SPECIES, a, i);
2257             av.lanewise(VectorOperators.OR, (long)b[i]).intoArray(r, i);
2258         }
2259 
2260         assertBroadcastLongArraysEquals(r, a, b, Int512VectorTests::OR);
2261     }
2262 
2263     @Test(dataProvider = "intBinaryOpMaskProvider")
2264     static void ORInt512VectorTestsBroadcastMaskedLongSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb,
2265                                           IntFunction<boolean[]> fm) {
2266         int[] a = fa.apply(SPECIES.length());
2267         int[] b = fb.apply(SPECIES.length());
2268         int[] r = fr.apply(SPECIES.length());
2269         boolean[] mask = fm.apply(SPECIES.length());
2270         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2271 
2272         for (int i = 0; i < a.length; i += SPECIES.length()) {
2273             IntVector av = IntVector.fromArray(SPECIES, a, i);
2274             av.lanewise(VectorOperators.OR, (long)b[i], vmask).intoArray(r, i);
2275         }
2276 
2277         assertBroadcastLongArraysEquals(r, a, b, mask, Int512VectorTests::OR);
2278     }
2279 
2280     @Test(dataProvider = "intBinaryOpProvider")
2281     static void ADDInt512VectorTestsBroadcastLongSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2282         int[] a = fa.apply(SPECIES.length());
2283         int[] b = fb.apply(SPECIES.length());
2284         int[] r = fr.apply(SPECIES.length());
2285 
2286         for (int i = 0; i < a.length; i += SPECIES.length()) {
2287             IntVector av = IntVector.fromArray(SPECIES, a, i);
2288             av.lanewise(VectorOperators.ADD, (long)b[i]).intoArray(r, i);
2289         }
2290 
2291         assertBroadcastLongArraysEquals(r, a, b, Int512VectorTests::ADD);
2292     }
2293 
2294     @Test(dataProvider = "intBinaryOpMaskProvider")
2295     static void ADDInt512VectorTestsBroadcastMaskedLongSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb,
2296                                           IntFunction<boolean[]> fm) {
2297         int[] a = fa.apply(SPECIES.length());
2298         int[] b = fb.apply(SPECIES.length());
2299         int[] r = fr.apply(SPECIES.length());
2300         boolean[] mask = fm.apply(SPECIES.length());
2301         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2302 
2303         for (int i = 0; i < a.length; i += SPECIES.length()) {
2304             IntVector av = IntVector.fromArray(SPECIES, a, i);
2305             av.lanewise(VectorOperators.ADD, (long)b[i], vmask).intoArray(r, i);
2306         }
2307 
2308         assertBroadcastLongArraysEquals(r, a, b, mask, Int512VectorTests::ADD);
2309     }
2310 
2311     static int LSHL(int a, int b) {
2312         return (int)((a << b));
2313     }
2314 
2315     @Test(dataProvider = "intBinaryOpProvider")
2316     static void LSHLInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2317         int[] a = fa.apply(SPECIES.length());
2318         int[] b = fb.apply(SPECIES.length());
2319         int[] r = fr.apply(SPECIES.length());
2320 
2321         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2322             for (int i = 0; i < a.length; i += SPECIES.length()) {
2323                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2324                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
2325                 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i);
2326             }
2327         }
2328 
2329         assertArraysEquals(r, a, b, Int512VectorTests::LSHL);
2330     }
2331 
2332     @Test(dataProvider = "intBinaryOpMaskProvider")
2333     static void LSHLInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
2334                                           IntFunction<boolean[]> fm) {
2335         int[] a = fa.apply(SPECIES.length());
2336         int[] b = fb.apply(SPECIES.length());
2337         int[] r = fr.apply(SPECIES.length());
2338         boolean[] mask = fm.apply(SPECIES.length());
2339         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2340 
2341         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2342             for (int i = 0; i < a.length; i += SPECIES.length()) {
2343                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2344                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
2345                 av.lanewise(VectorOperators.LSHL, bv, vmask).intoArray(r, i);
2346             }
2347         }
2348 
2349         assertArraysEquals(r, a, b, mask, Int512VectorTests::LSHL);
2350     }
2351 
2352     static int ASHR(int a, int b) {
2353         return (int)((a >> b));
2354     }
2355 
2356     @Test(dataProvider = "intBinaryOpProvider")
2357     static void ASHRInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2358         int[] a = fa.apply(SPECIES.length());
2359         int[] b = fb.apply(SPECIES.length());
2360         int[] r = fr.apply(SPECIES.length());
2361 
2362         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2363             for (int i = 0; i < a.length; i += SPECIES.length()) {
2364                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2365                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
2366                 av.lanewise(VectorOperators.ASHR, bv).intoArray(r, i);
2367             }
2368         }
2369 
2370         assertArraysEquals(r, a, b, Int512VectorTests::ASHR);
2371     }
2372 
2373     @Test(dataProvider = "intBinaryOpMaskProvider")
2374     static void ASHRInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
2375                                           IntFunction<boolean[]> fm) {
2376         int[] a = fa.apply(SPECIES.length());
2377         int[] b = fb.apply(SPECIES.length());
2378         int[] r = fr.apply(SPECIES.length());
2379         boolean[] mask = fm.apply(SPECIES.length());
2380         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2381 
2382         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2383             for (int i = 0; i < a.length; i += SPECIES.length()) {
2384                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2385                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
2386                 av.lanewise(VectorOperators.ASHR, bv, vmask).intoArray(r, i);
2387             }
2388         }
2389 
2390         assertArraysEquals(r, a, b, mask, Int512VectorTests::ASHR);
2391     }
2392 
2393     static int LSHR(int a, int b) {
2394         return (int)((a >>> b));
2395     }
2396 
2397     @Test(dataProvider = "intBinaryOpProvider")
2398     static void LSHRInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2399         int[] a = fa.apply(SPECIES.length());
2400         int[] b = fb.apply(SPECIES.length());
2401         int[] r = fr.apply(SPECIES.length());
2402 
2403         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2404             for (int i = 0; i < a.length; i += SPECIES.length()) {
2405                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2406                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
2407                 av.lanewise(VectorOperators.LSHR, bv).intoArray(r, i);
2408             }
2409         }
2410 
2411         assertArraysEquals(r, a, b, Int512VectorTests::LSHR);
2412     }
2413 
2414     @Test(dataProvider = "intBinaryOpMaskProvider")
2415     static void LSHRInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
2416                                           IntFunction<boolean[]> fm) {
2417         int[] a = fa.apply(SPECIES.length());
2418         int[] b = fb.apply(SPECIES.length());
2419         int[] r = fr.apply(SPECIES.length());
2420         boolean[] mask = fm.apply(SPECIES.length());
2421         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2422 
2423         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2424             for (int i = 0; i < a.length; i += SPECIES.length()) {
2425                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2426                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
2427                 av.lanewise(VectorOperators.LSHR, bv, vmask).intoArray(r, i);
2428             }
2429         }
2430 
2431         assertArraysEquals(r, a, b, mask, Int512VectorTests::LSHR);
2432     }
2433 
2434     static int LSHL_unary(int a, int b) {
2435         return (int)((a << b));
2436     }
2437 
2438     @Test(dataProvider = "intBinaryOpProvider")
2439     static void LSHLInt512VectorTestsScalarShift(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2440         int[] a = fa.apply(SPECIES.length());
2441         int[] b = fb.apply(SPECIES.length());
2442         int[] r = fr.apply(SPECIES.length());
2443 
2444         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2445             for (int i = 0; i < a.length; i += SPECIES.length()) {
2446                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2447                 av.lanewise(VectorOperators.LSHL, (int)b[i]).intoArray(r, i);
2448             }
2449         }
2450 
2451         assertShiftArraysEquals(r, a, b, Int512VectorTests::LSHL_unary);
2452     }
2453 
2454     @Test(dataProvider = "intBinaryOpMaskProvider")
2455     static void LSHLInt512VectorTestsScalarShiftMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
2456                                           IntFunction<boolean[]> fm) {
2457         int[] a = fa.apply(SPECIES.length());
2458         int[] b = fb.apply(SPECIES.length());
2459         int[] r = fr.apply(SPECIES.length());
2460         boolean[] mask = fm.apply(SPECIES.length());
2461         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2462 
2463         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2464             for (int i = 0; i < a.length; i += SPECIES.length()) {
2465                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2466                 av.lanewise(VectorOperators.LSHL, (int)b[i], vmask).intoArray(r, i);
2467             }
2468         }
2469 
2470         assertShiftArraysEquals(r, a, b, mask, Int512VectorTests::LSHL_unary);
2471     }
2472 
2473     static int LSHR_unary(int a, int b) {
2474         return (int)((a >>> b));
2475     }
2476 
2477     @Test(dataProvider = "intBinaryOpProvider")
2478     static void LSHRInt512VectorTestsScalarShift(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2479         int[] a = fa.apply(SPECIES.length());
2480         int[] b = fb.apply(SPECIES.length());
2481         int[] r = fr.apply(SPECIES.length());
2482 
2483         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2484             for (int i = 0; i < a.length; i += SPECIES.length()) {
2485                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2486                 av.lanewise(VectorOperators.LSHR, (int)b[i]).intoArray(r, i);
2487             }
2488         }
2489 
2490         assertShiftArraysEquals(r, a, b, Int512VectorTests::LSHR_unary);
2491     }
2492 
2493     @Test(dataProvider = "intBinaryOpMaskProvider")
2494     static void LSHRInt512VectorTestsScalarShiftMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
2495                                           IntFunction<boolean[]> fm) {
2496         int[] a = fa.apply(SPECIES.length());
2497         int[] b = fb.apply(SPECIES.length());
2498         int[] r = fr.apply(SPECIES.length());
2499         boolean[] mask = fm.apply(SPECIES.length());
2500         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2501 
2502         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2503             for (int i = 0; i < a.length; i += SPECIES.length()) {
2504                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2505                 av.lanewise(VectorOperators.LSHR, (int)b[i], vmask).intoArray(r, i);
2506             }
2507         }
2508 
2509         assertShiftArraysEquals(r, a, b, mask, Int512VectorTests::LSHR_unary);
2510     }
2511 
2512     static int ASHR_unary(int a, int b) {
2513         return (int)((a >> b));
2514     }
2515 
2516     @Test(dataProvider = "intBinaryOpProvider")
2517     static void ASHRInt512VectorTestsScalarShift(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2518         int[] a = fa.apply(SPECIES.length());
2519         int[] b = fb.apply(SPECIES.length());
2520         int[] r = fr.apply(SPECIES.length());
2521 
2522         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2523             for (int i = 0; i < a.length; i += SPECIES.length()) {
2524                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2525                 av.lanewise(VectorOperators.ASHR, (int)b[i]).intoArray(r, i);
2526             }
2527         }
2528 
2529         assertShiftArraysEquals(r, a, b, Int512VectorTests::ASHR_unary);
2530     }
2531 
2532     @Test(dataProvider = "intBinaryOpMaskProvider")
2533     static void ASHRInt512VectorTestsScalarShiftMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
2534                                           IntFunction<boolean[]> fm) {
2535         int[] a = fa.apply(SPECIES.length());
2536         int[] b = fb.apply(SPECIES.length());
2537         int[] r = fr.apply(SPECIES.length());
2538         boolean[] mask = fm.apply(SPECIES.length());
2539         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2540 
2541         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2542             for (int i = 0; i < a.length; i += SPECIES.length()) {
2543                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2544                 av.lanewise(VectorOperators.ASHR, (int)b[i], vmask).intoArray(r, i);
2545             }
2546         }
2547 
2548         assertShiftArraysEquals(r, a, b, mask, Int512VectorTests::ASHR_unary);
2549     }
2550 
2551     static int ROR(int a, int b) {
2552         return (int)(ROR_scalar(a,b));
2553     }
2554 
2555     @Test(dataProvider = "intBinaryOpProvider")
2556     static void RORInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2557         int[] a = fa.apply(SPECIES.length());
2558         int[] b = fb.apply(SPECIES.length());
2559         int[] r = fr.apply(SPECIES.length());
2560 
2561         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2562             for (int i = 0; i < a.length; i += SPECIES.length()) {
2563                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2564                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
2565                 av.lanewise(VectorOperators.ROR, bv).intoArray(r, i);
2566             }
2567         }
2568 
2569         assertArraysEquals(r, a, b, Int512VectorTests::ROR);
2570     }
2571 
2572     @Test(dataProvider = "intBinaryOpMaskProvider")
2573     static void RORInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
2574                                           IntFunction<boolean[]> fm) {
2575         int[] a = fa.apply(SPECIES.length());
2576         int[] b = fb.apply(SPECIES.length());
2577         int[] r = fr.apply(SPECIES.length());
2578         boolean[] mask = fm.apply(SPECIES.length());
2579         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2580 
2581         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2582             for (int i = 0; i < a.length; i += SPECIES.length()) {
2583                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2584                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
2585                 av.lanewise(VectorOperators.ROR, bv, vmask).intoArray(r, i);
2586             }
2587         }
2588 
2589         assertArraysEquals(r, a, b, mask, Int512VectorTests::ROR);
2590     }
2591 
2592     static int ROL(int a, int b) {
2593         return (int)(ROL_scalar(a,b));
2594     }
2595 
2596     @Test(dataProvider = "intBinaryOpProvider")
2597     static void ROLInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2598         int[] a = fa.apply(SPECIES.length());
2599         int[] b = fb.apply(SPECIES.length());
2600         int[] r = fr.apply(SPECIES.length());
2601 
2602         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2603             for (int i = 0; i < a.length; i += SPECIES.length()) {
2604                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2605                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
2606                 av.lanewise(VectorOperators.ROL, bv).intoArray(r, i);
2607             }
2608         }
2609 
2610         assertArraysEquals(r, a, b, Int512VectorTests::ROL);
2611     }
2612 
2613     @Test(dataProvider = "intBinaryOpMaskProvider")
2614     static void ROLInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
2615                                           IntFunction<boolean[]> fm) {
2616         int[] a = fa.apply(SPECIES.length());
2617         int[] b = fb.apply(SPECIES.length());
2618         int[] r = fr.apply(SPECIES.length());
2619         boolean[] mask = fm.apply(SPECIES.length());
2620         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2621 
2622         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2623             for (int i = 0; i < a.length; i += SPECIES.length()) {
2624                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2625                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
2626                 av.lanewise(VectorOperators.ROL, bv, vmask).intoArray(r, i);
2627             }
2628         }
2629 
2630         assertArraysEquals(r, a, b, mask, Int512VectorTests::ROL);
2631     }
2632 
2633     static int ROR_unary(int a, int b) {
2634         return (int)(ROR_scalar(a, b));
2635     }
2636 
2637     @Test(dataProvider = "intBinaryOpProvider")
2638     static void RORInt512VectorTestsScalarShift(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2639         int[] a = fa.apply(SPECIES.length());
2640         int[] b = fb.apply(SPECIES.length());
2641         int[] r = fr.apply(SPECIES.length());
2642 
2643         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2644             for (int i = 0; i < a.length; i += SPECIES.length()) {
2645                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2646                 av.lanewise(VectorOperators.ROR, (int)b[i]).intoArray(r, i);
2647             }
2648         }
2649 
2650         assertShiftArraysEquals(r, a, b, Int512VectorTests::ROR_unary);
2651     }
2652 
2653     @Test(dataProvider = "intBinaryOpMaskProvider")
2654     static void RORInt512VectorTestsScalarShiftMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
2655                                           IntFunction<boolean[]> fm) {
2656         int[] a = fa.apply(SPECIES.length());
2657         int[] b = fb.apply(SPECIES.length());
2658         int[] r = fr.apply(SPECIES.length());
2659         boolean[] mask = fm.apply(SPECIES.length());
2660         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2661 
2662         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2663             for (int i = 0; i < a.length; i += SPECIES.length()) {
2664                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2665                 av.lanewise(VectorOperators.ROR, (int)b[i], vmask).intoArray(r, i);
2666             }
2667         }
2668 
2669         assertShiftArraysEquals(r, a, b, mask, Int512VectorTests::ROR_unary);
2670     }
2671 
2672     static int ROL_unary(int a, int b) {
2673         return (int)(ROL_scalar(a, b));
2674     }
2675 
2676     @Test(dataProvider = "intBinaryOpProvider")
2677     static void ROLInt512VectorTestsScalarShift(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2678         int[] a = fa.apply(SPECIES.length());
2679         int[] b = fb.apply(SPECIES.length());
2680         int[] r = fr.apply(SPECIES.length());
2681 
2682         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2683             for (int i = 0; i < a.length; i += SPECIES.length()) {
2684                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2685                 av.lanewise(VectorOperators.ROL, (int)b[i]).intoArray(r, i);
2686             }
2687         }
2688 
2689         assertShiftArraysEquals(r, a, b, Int512VectorTests::ROL_unary);
2690     }
2691 
2692     @Test(dataProvider = "intBinaryOpMaskProvider")
2693     static void ROLInt512VectorTestsScalarShiftMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
2694                                           IntFunction<boolean[]> fm) {
2695         int[] a = fa.apply(SPECIES.length());
2696         int[] b = fb.apply(SPECIES.length());
2697         int[] r = fr.apply(SPECIES.length());
2698         boolean[] mask = fm.apply(SPECIES.length());
2699         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2700 
2701         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2702             for (int i = 0; i < a.length; i += SPECIES.length()) {
2703                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2704                 av.lanewise(VectorOperators.ROL, (int)b[i], vmask).intoArray(r, i);
2705             }
2706         }
2707 
2708         assertShiftArraysEquals(r, a, b, mask, Int512VectorTests::ROL_unary);
2709     }
2710     static int LSHR_binary_const(int a) {
2711         return (int)((a >>> CONST_SHIFT));
2712     }
2713 
2714     @Test(dataProvider = "intUnaryOpProvider")
2715     static void LSHRInt512VectorTestsScalarShiftConst(IntFunction<int[]> fa) {
2716         int[] a = fa.apply(SPECIES.length());
2717         int[] r = fr.apply(SPECIES.length());
2718 
2719         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2720             for (int i = 0; i < a.length; i += SPECIES.length()) {
2721                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2722                 av.lanewise(VectorOperators.LSHR, CONST_SHIFT).intoArray(r, i);
2723             }
2724         }
2725 
2726         assertShiftConstEquals(r, a, Int512VectorTests::LSHR_binary_const);
2727     }
2728 
2729     @Test(dataProvider = "intUnaryOpMaskProvider")
2730     static void LSHRInt512VectorTestsScalarShiftMaskedConst(IntFunction<int[]> fa,
2731                                           IntFunction<boolean[]> fm) {
2732         int[] a = fa.apply(SPECIES.length());
2733         int[] r = fr.apply(SPECIES.length());
2734         boolean[] mask = fm.apply(SPECIES.length());
2735         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2736 
2737         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2738             for (int i = 0; i < a.length; i += SPECIES.length()) {
2739                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2740                 av.lanewise(VectorOperators.LSHR, CONST_SHIFT, vmask).intoArray(r, i);
2741             }
2742         }
2743 
2744         assertShiftConstEquals(r, a, mask, Int512VectorTests::LSHR_binary_const);
2745     }
2746 
2747     static int LSHL_binary_const(int a) {
2748         return (int)((a << CONST_SHIFT));
2749     }
2750 
2751     @Test(dataProvider = "intUnaryOpProvider")
2752     static void LSHLInt512VectorTestsScalarShiftConst(IntFunction<int[]> fa) {
2753         int[] a = fa.apply(SPECIES.length());
2754         int[] r = fr.apply(SPECIES.length());
2755 
2756         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2757             for (int i = 0; i < a.length; i += SPECIES.length()) {
2758                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2759                 av.lanewise(VectorOperators.LSHL, CONST_SHIFT).intoArray(r, i);
2760             }
2761         }
2762 
2763         assertShiftConstEquals(r, a, Int512VectorTests::LSHL_binary_const);
2764     }
2765 
2766     @Test(dataProvider = "intUnaryOpMaskProvider")
2767     static void LSHLInt512VectorTestsScalarShiftMaskedConst(IntFunction<int[]> fa,
2768                                           IntFunction<boolean[]> fm) {
2769         int[] a = fa.apply(SPECIES.length());
2770         int[] r = fr.apply(SPECIES.length());
2771         boolean[] mask = fm.apply(SPECIES.length());
2772         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2773 
2774         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2775             for (int i = 0; i < a.length; i += SPECIES.length()) {
2776                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2777                 av.lanewise(VectorOperators.LSHL, CONST_SHIFT, vmask).intoArray(r, i);
2778             }
2779         }
2780 
2781         assertShiftConstEquals(r, a, mask, Int512VectorTests::LSHL_binary_const);
2782     }
2783 
2784     static int ASHR_binary_const(int a) {
2785         return (int)((a >> CONST_SHIFT));
2786     }
2787 
2788     @Test(dataProvider = "intUnaryOpProvider")
2789     static void ASHRInt512VectorTestsScalarShiftConst(IntFunction<int[]> fa) {
2790         int[] a = fa.apply(SPECIES.length());
2791         int[] r = fr.apply(SPECIES.length());
2792 
2793         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2794             for (int i = 0; i < a.length; i += SPECIES.length()) {
2795                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2796                 av.lanewise(VectorOperators.ASHR, CONST_SHIFT).intoArray(r, i);
2797             }
2798         }
2799 
2800         assertShiftConstEquals(r, a, Int512VectorTests::ASHR_binary_const);
2801     }
2802 
2803     @Test(dataProvider = "intUnaryOpMaskProvider")
2804     static void ASHRInt512VectorTestsScalarShiftMaskedConst(IntFunction<int[]> fa,
2805                                           IntFunction<boolean[]> fm) {
2806         int[] a = fa.apply(SPECIES.length());
2807         int[] r = fr.apply(SPECIES.length());
2808         boolean[] mask = fm.apply(SPECIES.length());
2809         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2810 
2811         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2812             for (int i = 0; i < a.length; i += SPECIES.length()) {
2813                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2814                 av.lanewise(VectorOperators.ASHR, CONST_SHIFT, vmask).intoArray(r, i);
2815             }
2816         }
2817 
2818         assertShiftConstEquals(r, a, mask, Int512VectorTests::ASHR_binary_const);
2819     }
2820 
2821     static int ROR_binary_const(int a) {
2822         return (int)(ROR_scalar(a, CONST_SHIFT));
2823     }
2824 
2825     @Test(dataProvider = "intUnaryOpProvider")
2826     static void RORInt512VectorTestsScalarShiftConst(IntFunction<int[]> fa) {
2827         int[] a = fa.apply(SPECIES.length());
2828         int[] r = fr.apply(SPECIES.length());
2829 
2830         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2831             for (int i = 0; i < a.length; i += SPECIES.length()) {
2832                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2833                 av.lanewise(VectorOperators.ROR, CONST_SHIFT).intoArray(r, i);
2834             }
2835         }
2836 
2837         assertShiftConstEquals(r, a, Int512VectorTests::ROR_binary_const);
2838     }
2839 
2840     @Test(dataProvider = "intUnaryOpMaskProvider")
2841     static void RORInt512VectorTestsScalarShiftMaskedConst(IntFunction<int[]> fa,
2842                                           IntFunction<boolean[]> fm) {
2843         int[] a = fa.apply(SPECIES.length());
2844         int[] r = fr.apply(SPECIES.length());
2845         boolean[] mask = fm.apply(SPECIES.length());
2846         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2847 
2848         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2849             for (int i = 0; i < a.length; i += SPECIES.length()) {
2850                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2851                 av.lanewise(VectorOperators.ROR, CONST_SHIFT, vmask).intoArray(r, i);
2852             }
2853         }
2854 
2855         assertShiftConstEquals(r, a, mask, Int512VectorTests::ROR_binary_const);
2856     }
2857 
2858     static int ROL_binary_const(int a) {
2859         return (int)(ROL_scalar(a, CONST_SHIFT));
2860     }
2861 
2862     @Test(dataProvider = "intUnaryOpProvider")
2863     static void ROLInt512VectorTestsScalarShiftConst(IntFunction<int[]> fa) {
2864         int[] a = fa.apply(SPECIES.length());
2865         int[] r = fr.apply(SPECIES.length());
2866 
2867         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2868             for (int i = 0; i < a.length; i += SPECIES.length()) {
2869                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2870                 av.lanewise(VectorOperators.ROL, CONST_SHIFT).intoArray(r, i);
2871             }
2872         }
2873 
2874         assertShiftConstEquals(r, a, Int512VectorTests::ROL_binary_const);
2875     }
2876 
2877     @Test(dataProvider = "intUnaryOpMaskProvider")
2878     static void ROLInt512VectorTestsScalarShiftMaskedConst(IntFunction<int[]> fa,
2879                                           IntFunction<boolean[]> fm) {
2880         int[] a = fa.apply(SPECIES.length());
2881         int[] r = fr.apply(SPECIES.length());
2882         boolean[] mask = fm.apply(SPECIES.length());
2883         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2884 
2885         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2886             for (int i = 0; i < a.length; i += SPECIES.length()) {
2887                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2888                 av.lanewise(VectorOperators.ROL, CONST_SHIFT, vmask).intoArray(r, i);
2889             }
2890         }
2891 
2892         assertShiftConstEquals(r, a, mask, Int512VectorTests::ROL_binary_const);
2893     }
2894 
2895 
2896     static int MIN(int a, int b) {
2897         return (int)(Math.min(a, b));
2898     }
2899 
2900     @Test(dataProvider = "intBinaryOpProvider")
2901     static void MINInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2902         int[] a = fa.apply(SPECIES.length());
2903         int[] b = fb.apply(SPECIES.length());
2904         int[] r = fr.apply(SPECIES.length());
2905 
2906         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2907             for (int i = 0; i < a.length; i += SPECIES.length()) {
2908                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2909                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
2910                 av.lanewise(VectorOperators.MIN, bv).intoArray(r, i);
2911             }
2912         }
2913 
2914         assertArraysEquals(r, a, b, Int512VectorTests::MIN);
2915     }
2916 
2917     static int min(int a, int b) {
2918         return (int)(Math.min(a, b));
2919     }
2920 
2921     @Test(dataProvider = "intBinaryOpProvider")
2922     static void minInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2923         int[] a = fa.apply(SPECIES.length());
2924         int[] b = fb.apply(SPECIES.length());
2925         int[] r = fr.apply(SPECIES.length());
2926 
2927         for (int i = 0; i < a.length; i += SPECIES.length()) {
2928             IntVector av = IntVector.fromArray(SPECIES, a, i);
2929             IntVector bv = IntVector.fromArray(SPECIES, b, i);
2930             av.min(bv).intoArray(r, i);
2931         }
2932 
2933         assertArraysEquals(r, a, b, Int512VectorTests::min);
2934     }
2935 
2936     static int MAX(int a, int b) {
2937         return (int)(Math.max(a, b));
2938     }
2939 
2940     @Test(dataProvider = "intBinaryOpProvider")
2941     static void MAXInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2942         int[] a = fa.apply(SPECIES.length());
2943         int[] b = fb.apply(SPECIES.length());
2944         int[] r = fr.apply(SPECIES.length());
2945 
2946         for (int ic = 0; ic < INVOC_COUNT; ic++) {
2947             for (int i = 0; i < a.length; i += SPECIES.length()) {
2948                 IntVector av = IntVector.fromArray(SPECIES, a, i);
2949                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
2950                 av.lanewise(VectorOperators.MAX, bv).intoArray(r, i);
2951             }
2952         }
2953 
2954         assertArraysEquals(r, a, b, Int512VectorTests::MAX);
2955     }
2956 
2957     static int max(int a, int b) {
2958         return (int)(Math.max(a, b));
2959     }
2960 
2961     @Test(dataProvider = "intBinaryOpProvider")
2962     static void maxInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2963         int[] a = fa.apply(SPECIES.length());
2964         int[] b = fb.apply(SPECIES.length());
2965         int[] r = fr.apply(SPECIES.length());
2966 
2967         for (int i = 0; i < a.length; i += SPECIES.length()) {
2968             IntVector av = IntVector.fromArray(SPECIES, a, i);
2969             IntVector bv = IntVector.fromArray(SPECIES, b, i);
2970             av.max(bv).intoArray(r, i);
2971         }
2972 
2973         assertArraysEquals(r, a, b, Int512VectorTests::max);
2974     }
2975 
2976     @Test(dataProvider = "intBinaryOpProvider")
2977     static void MINInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2978         int[] a = fa.apply(SPECIES.length());
2979         int[] b = fb.apply(SPECIES.length());
2980         int[] r = fr.apply(SPECIES.length());
2981 
2982         for (int i = 0; i < a.length; i += SPECIES.length()) {
2983             IntVector av = IntVector.fromArray(SPECIES, a, i);
2984             av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i);
2985         }
2986 
2987         assertBroadcastArraysEquals(r, a, b, Int512VectorTests::MIN);
2988     }
2989 
2990     @Test(dataProvider = "intBinaryOpProvider")
2991     static void minInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
2992         int[] a = fa.apply(SPECIES.length());
2993         int[] b = fb.apply(SPECIES.length());
2994         int[] r = fr.apply(SPECIES.length());
2995 
2996         for (int i = 0; i < a.length; i += SPECIES.length()) {
2997             IntVector av = IntVector.fromArray(SPECIES, a, i);
2998             av.min(b[i]).intoArray(r, i);
2999         }
3000 
3001         assertBroadcastArraysEquals(r, a, b, Int512VectorTests::min);
3002     }
3003 
3004     @Test(dataProvider = "intBinaryOpProvider")
3005     static void MAXInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
3006         int[] a = fa.apply(SPECIES.length());
3007         int[] b = fb.apply(SPECIES.length());
3008         int[] r = fr.apply(SPECIES.length());
3009 
3010         for (int i = 0; i < a.length; i += SPECIES.length()) {
3011             IntVector av = IntVector.fromArray(SPECIES, a, i);
3012             av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i);
3013         }
3014 
3015         assertBroadcastArraysEquals(r, a, b, Int512VectorTests::MAX);
3016     }
3017 
3018     @Test(dataProvider = "intBinaryOpProvider")
3019     static void maxInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
3020         int[] a = fa.apply(SPECIES.length());
3021         int[] b = fb.apply(SPECIES.length());
3022         int[] r = fr.apply(SPECIES.length());
3023 
3024         for (int i = 0; i < a.length; i += SPECIES.length()) {
3025             IntVector av = IntVector.fromArray(SPECIES, a, i);
3026             av.max(b[i]).intoArray(r, i);
3027         }
3028 
3029         assertBroadcastArraysEquals(r, a, b, Int512VectorTests::max);
3030     }
3031 
3032     static int ANDReduce(int[] a, int idx) {
3033         int res = -1;
3034         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3035             res &= a[i];
3036         }
3037 
3038         return res;
3039     }
3040 
3041     static int ANDReduceAll(int[] a) {
3042         int res = -1;
3043         for (int i = 0; i < a.length; i += SPECIES.length()) {
3044             res &= ANDReduce(a, i);
3045         }
3046 
3047         return res;
3048     }
3049 
3050     @Test(dataProvider = "intUnaryOpProvider")
3051     static void ANDReduceInt512VectorTests(IntFunction<int[]> fa) {
3052         int[] a = fa.apply(SPECIES.length());
3053         int[] r = fr.apply(SPECIES.length());
3054         int ra = -1;
3055 
3056         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3057             for (int i = 0; i < a.length; i += SPECIES.length()) {
3058                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3059                 r[i] = av.reduceLanes(VectorOperators.AND);
3060             }
3061         }
3062 
3063         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3064             ra = -1;
3065             for (int i = 0; i < a.length; i += SPECIES.length()) {
3066                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3067                 ra &= av.reduceLanes(VectorOperators.AND);
3068             }
3069         }
3070 
3071         assertReductionArraysEquals(r, ra, a,
3072                 Int512VectorTests::ANDReduce, Int512VectorTests::ANDReduceAll);
3073     }
3074 
3075     static int ANDReduceMasked(int[] a, int idx, boolean[] mask) {
3076         int res = -1;
3077         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3078             if (mask[i % SPECIES.length()])
3079                 res &= a[i];
3080         }
3081 
3082         return res;
3083     }
3084 
3085     static int ANDReduceAllMasked(int[] a, boolean[] mask) {
3086         int res = -1;
3087         for (int i = 0; i < a.length; i += SPECIES.length()) {
3088             res &= ANDReduceMasked(a, i, mask);
3089         }
3090 
3091         return res;
3092     }
3093 
3094     @Test(dataProvider = "intUnaryOpMaskProvider")
3095     static void ANDReduceInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<boolean[]> fm) {
3096         int[] a = fa.apply(SPECIES.length());
3097         int[] r = fr.apply(SPECIES.length());
3098         boolean[] mask = fm.apply(SPECIES.length());
3099         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3100         int ra = -1;
3101 
3102         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3103             for (int i = 0; i < a.length; i += SPECIES.length()) {
3104                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3105                 r[i] = av.reduceLanes(VectorOperators.AND, vmask);
3106             }
3107         }
3108 
3109         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3110             ra = -1;
3111             for (int i = 0; i < a.length; i += SPECIES.length()) {
3112                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3113                 ra &= av.reduceLanes(VectorOperators.AND, vmask);
3114             }
3115         }
3116 
3117         assertReductionArraysEqualsMasked(r, ra, a, mask,
3118                 Int512VectorTests::ANDReduceMasked, Int512VectorTests::ANDReduceAllMasked);
3119     }
3120 
3121     static int ORReduce(int[] a, int idx) {
3122         int res = 0;
3123         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3124             res |= a[i];
3125         }
3126 
3127         return res;
3128     }
3129 
3130     static int ORReduceAll(int[] a) {
3131         int res = 0;
3132         for (int i = 0; i < a.length; i += SPECIES.length()) {
3133             res |= ORReduce(a, i);
3134         }
3135 
3136         return res;
3137     }
3138 
3139     @Test(dataProvider = "intUnaryOpProvider")
3140     static void ORReduceInt512VectorTests(IntFunction<int[]> fa) {
3141         int[] a = fa.apply(SPECIES.length());
3142         int[] r = fr.apply(SPECIES.length());
3143         int ra = 0;
3144 
3145         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3146             for (int i = 0; i < a.length; i += SPECIES.length()) {
3147                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3148                 r[i] = av.reduceLanes(VectorOperators.OR);
3149             }
3150         }
3151 
3152         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3153             ra = 0;
3154             for (int i = 0; i < a.length; i += SPECIES.length()) {
3155                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3156                 ra |= av.reduceLanes(VectorOperators.OR);
3157             }
3158         }
3159 
3160         assertReductionArraysEquals(r, ra, a,
3161                 Int512VectorTests::ORReduce, Int512VectorTests::ORReduceAll);
3162     }
3163 
3164     static int ORReduceMasked(int[] a, int idx, boolean[] mask) {
3165         int res = 0;
3166         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3167             if (mask[i % SPECIES.length()])
3168                 res |= a[i];
3169         }
3170 
3171         return res;
3172     }
3173 
3174     static int ORReduceAllMasked(int[] a, boolean[] mask) {
3175         int res = 0;
3176         for (int i = 0; i < a.length; i += SPECIES.length()) {
3177             res |= ORReduceMasked(a, i, mask);
3178         }
3179 
3180         return res;
3181     }
3182 
3183     @Test(dataProvider = "intUnaryOpMaskProvider")
3184     static void ORReduceInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<boolean[]> fm) {
3185         int[] a = fa.apply(SPECIES.length());
3186         int[] r = fr.apply(SPECIES.length());
3187         boolean[] mask = fm.apply(SPECIES.length());
3188         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3189         int ra = 0;
3190 
3191         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3192             for (int i = 0; i < a.length; i += SPECIES.length()) {
3193                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3194                 r[i] = av.reduceLanes(VectorOperators.OR, vmask);
3195             }
3196         }
3197 
3198         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3199             ra = 0;
3200             for (int i = 0; i < a.length; i += SPECIES.length()) {
3201                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3202                 ra |= av.reduceLanes(VectorOperators.OR, vmask);
3203             }
3204         }
3205 
3206         assertReductionArraysEqualsMasked(r, ra, a, mask,
3207                 Int512VectorTests::ORReduceMasked, Int512VectorTests::ORReduceAllMasked);
3208     }
3209 
3210     static int XORReduce(int[] a, int idx) {
3211         int res = 0;
3212         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3213             res ^= a[i];
3214         }
3215 
3216         return res;
3217     }
3218 
3219     static int XORReduceAll(int[] a) {
3220         int res = 0;
3221         for (int i = 0; i < a.length; i += SPECIES.length()) {
3222             res ^= XORReduce(a, i);
3223         }
3224 
3225         return res;
3226     }
3227 
3228     @Test(dataProvider = "intUnaryOpProvider")
3229     static void XORReduceInt512VectorTests(IntFunction<int[]> fa) {
3230         int[] a = fa.apply(SPECIES.length());
3231         int[] r = fr.apply(SPECIES.length());
3232         int ra = 0;
3233 
3234         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3235             for (int i = 0; i < a.length; i += SPECIES.length()) {
3236                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3237                 r[i] = av.reduceLanes(VectorOperators.XOR);
3238             }
3239         }
3240 
3241         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3242             ra = 0;
3243             for (int i = 0; i < a.length; i += SPECIES.length()) {
3244                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3245                 ra ^= av.reduceLanes(VectorOperators.XOR);
3246             }
3247         }
3248 
3249         assertReductionArraysEquals(r, ra, a,
3250                 Int512VectorTests::XORReduce, Int512VectorTests::XORReduceAll);
3251     }
3252 
3253     static int XORReduceMasked(int[] a, int idx, boolean[] mask) {
3254         int res = 0;
3255         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3256             if (mask[i % SPECIES.length()])
3257                 res ^= a[i];
3258         }
3259 
3260         return res;
3261     }
3262 
3263     static int XORReduceAllMasked(int[] a, boolean[] mask) {
3264         int res = 0;
3265         for (int i = 0; i < a.length; i += SPECIES.length()) {
3266             res ^= XORReduceMasked(a, i, mask);
3267         }
3268 
3269         return res;
3270     }
3271 
3272     @Test(dataProvider = "intUnaryOpMaskProvider")
3273     static void XORReduceInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<boolean[]> fm) {
3274         int[] a = fa.apply(SPECIES.length());
3275         int[] r = fr.apply(SPECIES.length());
3276         boolean[] mask = fm.apply(SPECIES.length());
3277         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3278         int ra = 0;
3279 
3280         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3281             for (int i = 0; i < a.length; i += SPECIES.length()) {
3282                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3283                 r[i] = av.reduceLanes(VectorOperators.XOR, vmask);
3284             }
3285         }
3286 
3287         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3288             ra = 0;
3289             for (int i = 0; i < a.length; i += SPECIES.length()) {
3290                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3291                 ra ^= av.reduceLanes(VectorOperators.XOR, vmask);
3292             }
3293         }
3294 
3295         assertReductionArraysEqualsMasked(r, ra, a, mask,
3296                 Int512VectorTests::XORReduceMasked, Int512VectorTests::XORReduceAllMasked);
3297     }
3298 
3299     static int ADDReduce(int[] a, int idx) {
3300         int res = 0;
3301         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3302             res += a[i];
3303         }
3304 
3305         return res;
3306     }
3307 
3308     static int ADDReduceAll(int[] a) {
3309         int res = 0;
3310         for (int i = 0; i < a.length; i += SPECIES.length()) {
3311             res += ADDReduce(a, i);
3312         }
3313 
3314         return res;
3315     }
3316 
3317     @Test(dataProvider = "intUnaryOpProvider")
3318     static void ADDReduceInt512VectorTests(IntFunction<int[]> fa) {
3319         int[] a = fa.apply(SPECIES.length());
3320         int[] r = fr.apply(SPECIES.length());
3321         int ra = 0;
3322 
3323         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3324             for (int i = 0; i < a.length; i += SPECIES.length()) {
3325                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3326                 r[i] = av.reduceLanes(VectorOperators.ADD);
3327             }
3328         }
3329 
3330         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3331             ra = 0;
3332             for (int i = 0; i < a.length; i += SPECIES.length()) {
3333                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3334                 ra += av.reduceLanes(VectorOperators.ADD);
3335             }
3336         }
3337 
3338         assertReductionArraysEquals(r, ra, a,
3339                 Int512VectorTests::ADDReduce, Int512VectorTests::ADDReduceAll);
3340     }
3341 
3342     static int ADDReduceMasked(int[] a, int idx, boolean[] mask) {
3343         int res = 0;
3344         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3345             if (mask[i % SPECIES.length()])
3346                 res += a[i];
3347         }
3348 
3349         return res;
3350     }
3351 
3352     static int ADDReduceAllMasked(int[] a, boolean[] mask) {
3353         int res = 0;
3354         for (int i = 0; i < a.length; i += SPECIES.length()) {
3355             res += ADDReduceMasked(a, i, mask);
3356         }
3357 
3358         return res;
3359     }
3360 
3361     @Test(dataProvider = "intUnaryOpMaskProvider")
3362     static void ADDReduceInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<boolean[]> fm) {
3363         int[] a = fa.apply(SPECIES.length());
3364         int[] r = fr.apply(SPECIES.length());
3365         boolean[] mask = fm.apply(SPECIES.length());
3366         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3367         int ra = 0;
3368 
3369         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3370             for (int i = 0; i < a.length; i += SPECIES.length()) {
3371                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3372                 r[i] = av.reduceLanes(VectorOperators.ADD, vmask);
3373             }
3374         }
3375 
3376         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3377             ra = 0;
3378             for (int i = 0; i < a.length; i += SPECIES.length()) {
3379                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3380                 ra += av.reduceLanes(VectorOperators.ADD, vmask);
3381             }
3382         }
3383 
3384         assertReductionArraysEqualsMasked(r, ra, a, mask,
3385                 Int512VectorTests::ADDReduceMasked, Int512VectorTests::ADDReduceAllMasked);
3386     }
3387 
3388     static int MULReduce(int[] a, int idx) {
3389         int res = 1;
3390         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3391             res *= a[i];
3392         }
3393 
3394         return res;
3395     }
3396 
3397     static int MULReduceAll(int[] a) {
3398         int res = 1;
3399         for (int i = 0; i < a.length; i += SPECIES.length()) {
3400             res *= MULReduce(a, i);
3401         }
3402 
3403         return res;
3404     }
3405 
3406     @Test(dataProvider = "intUnaryOpProvider")
3407     static void MULReduceInt512VectorTests(IntFunction<int[]> fa) {
3408         int[] a = fa.apply(SPECIES.length());
3409         int[] r = fr.apply(SPECIES.length());
3410         int ra = 1;
3411 
3412         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3413             for (int i = 0; i < a.length; i += SPECIES.length()) {
3414                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3415                 r[i] = av.reduceLanes(VectorOperators.MUL);
3416             }
3417         }
3418 
3419         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3420             ra = 1;
3421             for (int i = 0; i < a.length; i += SPECIES.length()) {
3422                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3423                 ra *= av.reduceLanes(VectorOperators.MUL);
3424             }
3425         }
3426 
3427         assertReductionArraysEquals(r, ra, a,
3428                 Int512VectorTests::MULReduce, Int512VectorTests::MULReduceAll);
3429     }
3430 
3431     static int MULReduceMasked(int[] a, int idx, boolean[] mask) {
3432         int res = 1;
3433         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3434             if (mask[i % SPECIES.length()])
3435                 res *= a[i];
3436         }
3437 
3438         return res;
3439     }
3440 
3441     static int MULReduceAllMasked(int[] a, boolean[] mask) {
3442         int res = 1;
3443         for (int i = 0; i < a.length; i += SPECIES.length()) {
3444             res *= MULReduceMasked(a, i, mask);
3445         }
3446 
3447         return res;
3448     }
3449 
3450     @Test(dataProvider = "intUnaryOpMaskProvider")
3451     static void MULReduceInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<boolean[]> fm) {
3452         int[] a = fa.apply(SPECIES.length());
3453         int[] r = fr.apply(SPECIES.length());
3454         boolean[] mask = fm.apply(SPECIES.length());
3455         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3456         int ra = 1;
3457 
3458         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3459             for (int i = 0; i < a.length; i += SPECIES.length()) {
3460                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3461                 r[i] = av.reduceLanes(VectorOperators.MUL, vmask);
3462             }
3463         }
3464 
3465         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3466             ra = 1;
3467             for (int i = 0; i < a.length; i += SPECIES.length()) {
3468                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3469                 ra *= av.reduceLanes(VectorOperators.MUL, vmask);
3470             }
3471         }
3472 
3473         assertReductionArraysEqualsMasked(r, ra, a, mask,
3474                 Int512VectorTests::MULReduceMasked, Int512VectorTests::MULReduceAllMasked);
3475     }
3476 
3477     static int MINReduce(int[] a, int idx) {
3478         int res = Integer.MAX_VALUE;
3479         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3480             res = (int) Math.min(res, a[i]);
3481         }
3482 
3483         return res;
3484     }
3485 
3486     static int MINReduceAll(int[] a) {
3487         int res = Integer.MAX_VALUE;
3488         for (int i = 0; i < a.length; i += SPECIES.length()) {
3489             res = (int) Math.min(res, MINReduce(a, i));
3490         }
3491 
3492         return res;
3493     }
3494 
3495     @Test(dataProvider = "intUnaryOpProvider")
3496     static void MINReduceInt512VectorTests(IntFunction<int[]> fa) {
3497         int[] a = fa.apply(SPECIES.length());
3498         int[] r = fr.apply(SPECIES.length());
3499         int ra = Integer.MAX_VALUE;
3500 
3501         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3502             for (int i = 0; i < a.length; i += SPECIES.length()) {
3503                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3504                 r[i] = av.reduceLanes(VectorOperators.MIN);
3505             }
3506         }
3507 
3508         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3509             ra = Integer.MAX_VALUE;
3510             for (int i = 0; i < a.length; i += SPECIES.length()) {
3511                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3512                 ra = (int) Math.min(ra, av.reduceLanes(VectorOperators.MIN));
3513             }
3514         }
3515 
3516         assertReductionArraysEquals(r, ra, a,
3517                 Int512VectorTests::MINReduce, Int512VectorTests::MINReduceAll);
3518     }
3519 
3520     static int MINReduceMasked(int[] a, int idx, boolean[] mask) {
3521         int res = Integer.MAX_VALUE;
3522         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3523             if (mask[i % SPECIES.length()])
3524                 res = (int) Math.min(res, a[i]);
3525         }
3526 
3527         return res;
3528     }
3529 
3530     static int MINReduceAllMasked(int[] a, boolean[] mask) {
3531         int res = Integer.MAX_VALUE;
3532         for (int i = 0; i < a.length; i += SPECIES.length()) {
3533             res = (int) Math.min(res, MINReduceMasked(a, i, mask));
3534         }
3535 
3536         return res;
3537     }
3538 
3539     @Test(dataProvider = "intUnaryOpMaskProvider")
3540     static void MINReduceInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<boolean[]> fm) {
3541         int[] a = fa.apply(SPECIES.length());
3542         int[] r = fr.apply(SPECIES.length());
3543         boolean[] mask = fm.apply(SPECIES.length());
3544         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3545         int ra = Integer.MAX_VALUE;
3546 
3547         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3548             for (int i = 0; i < a.length; i += SPECIES.length()) {
3549                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3550                 r[i] = av.reduceLanes(VectorOperators.MIN, vmask);
3551             }
3552         }
3553 
3554         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3555             ra = Integer.MAX_VALUE;
3556             for (int i = 0; i < a.length; i += SPECIES.length()) {
3557                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3558                 ra = (int) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask));
3559             }
3560         }
3561 
3562         assertReductionArraysEqualsMasked(r, ra, a, mask,
3563                 Int512VectorTests::MINReduceMasked, Int512VectorTests::MINReduceAllMasked);
3564     }
3565 
3566     static int MAXReduce(int[] a, int idx) {
3567         int res = Integer.MIN_VALUE;
3568         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3569             res = (int) Math.max(res, a[i]);
3570         }
3571 
3572         return res;
3573     }
3574 
3575     static int MAXReduceAll(int[] a) {
3576         int res = Integer.MIN_VALUE;
3577         for (int i = 0; i < a.length; i += SPECIES.length()) {
3578             res = (int) Math.max(res, MAXReduce(a, i));
3579         }
3580 
3581         return res;
3582     }
3583 
3584     @Test(dataProvider = "intUnaryOpProvider")
3585     static void MAXReduceInt512VectorTests(IntFunction<int[]> fa) {
3586         int[] a = fa.apply(SPECIES.length());
3587         int[] r = fr.apply(SPECIES.length());
3588         int ra = Integer.MIN_VALUE;
3589 
3590         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3591             for (int i = 0; i < a.length; i += SPECIES.length()) {
3592                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3593                 r[i] = av.reduceLanes(VectorOperators.MAX);
3594             }
3595         }
3596 
3597         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3598             ra = Integer.MIN_VALUE;
3599             for (int i = 0; i < a.length; i += SPECIES.length()) {
3600                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3601                 ra = (int) Math.max(ra, av.reduceLanes(VectorOperators.MAX));
3602             }
3603         }
3604 
3605         assertReductionArraysEquals(r, ra, a,
3606                 Int512VectorTests::MAXReduce, Int512VectorTests::MAXReduceAll);
3607     }
3608 
3609     static int MAXReduceMasked(int[] a, int idx, boolean[] mask) {
3610         int res = Integer.MIN_VALUE;
3611         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3612             if (mask[i % SPECIES.length()])
3613                 res = (int) Math.max(res, a[i]);
3614         }
3615 
3616         return res;
3617     }
3618 
3619     static int MAXReduceAllMasked(int[] a, boolean[] mask) {
3620         int res = Integer.MIN_VALUE;
3621         for (int i = 0; i < a.length; i += SPECIES.length()) {
3622             res = (int) Math.max(res, MAXReduceMasked(a, i, mask));
3623         }
3624 
3625         return res;
3626     }
3627 
3628     @Test(dataProvider = "intUnaryOpMaskProvider")
3629     static void MAXReduceInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<boolean[]> fm) {
3630         int[] a = fa.apply(SPECIES.length());
3631         int[] r = fr.apply(SPECIES.length());
3632         boolean[] mask = fm.apply(SPECIES.length());
3633         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3634         int ra = Integer.MIN_VALUE;
3635 
3636         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3637             for (int i = 0; i < a.length; i += SPECIES.length()) {
3638                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3639                 r[i] = av.reduceLanes(VectorOperators.MAX, vmask);
3640             }
3641         }
3642 
3643         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3644             ra = Integer.MIN_VALUE;
3645             for (int i = 0; i < a.length; i += SPECIES.length()) {
3646                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3647                 ra = (int) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask));
3648             }
3649         }
3650 
3651         assertReductionArraysEqualsMasked(r, ra, a, mask,
3652                 Int512VectorTests::MAXReduceMasked, Int512VectorTests::MAXReduceAllMasked);
3653     }
3654 
3655     static int FIRST_NONZEROReduce(int[] a, int idx) {
3656         int res = (int) 0;
3657         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3658             res = firstNonZero(res, a[i]);
3659         }
3660 
3661         return res;
3662     }
3663 
3664     static int FIRST_NONZEROReduceAll(int[] a) {
3665         int res = (int) 0;
3666         for (int i = 0; i < a.length; i += SPECIES.length()) {
3667             res = firstNonZero(res, FIRST_NONZEROReduce(a, i));
3668         }
3669 
3670         return res;
3671     }
3672 
3673     @Test(dataProvider = "intUnaryOpProvider")
3674     static void FIRST_NONZEROReduceInt512VectorTests(IntFunction<int[]> fa) {
3675         int[] a = fa.apply(SPECIES.length());
3676         int[] r = fr.apply(SPECIES.length());
3677         int ra = (int) 0;
3678 
3679         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3680             for (int i = 0; i < a.length; i += SPECIES.length()) {
3681                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3682                 r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO);
3683             }
3684         }
3685 
3686         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3687             ra = (int) 0;
3688             for (int i = 0; i < a.length; i += SPECIES.length()) {
3689                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3690                 ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO));
3691             }
3692         }
3693 
3694         assertReductionArraysEquals(r, ra, a,
3695                 Int512VectorTests::FIRST_NONZEROReduce, Int512VectorTests::FIRST_NONZEROReduceAll);
3696     }
3697 
3698     static int FIRST_NONZEROReduceMasked(int[] a, int idx, boolean[] mask) {
3699         int res = (int) 0;
3700         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3701             if (mask[i % SPECIES.length()])
3702                 res = firstNonZero(res, a[i]);
3703         }
3704 
3705         return res;
3706     }
3707 
3708     static int FIRST_NONZEROReduceAllMasked(int[] a, boolean[] mask) {
3709         int res = (int) 0;
3710         for (int i = 0; i < a.length; i += SPECIES.length()) {
3711             res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask));
3712         }
3713 
3714         return res;
3715     }
3716 
3717     @Test(dataProvider = "intUnaryOpMaskProvider")
3718     static void FIRST_NONZEROReduceInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<boolean[]> fm) {
3719         int[] a = fa.apply(SPECIES.length());
3720         int[] r = fr.apply(SPECIES.length());
3721         boolean[] mask = fm.apply(SPECIES.length());
3722         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3723         int ra = (int) 0;
3724 
3725         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3726             for (int i = 0; i < a.length; i += SPECIES.length()) {
3727                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3728                 r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask);
3729             }
3730         }
3731 
3732         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3733             ra = (int) 0;
3734             for (int i = 0; i < a.length; i += SPECIES.length()) {
3735                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3736                 ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask));
3737             }
3738         }
3739 
3740         assertReductionArraysEqualsMasked(r, ra, a, mask,
3741                 Int512VectorTests::FIRST_NONZEROReduceMasked, Int512VectorTests::FIRST_NONZEROReduceAllMasked);
3742     }
3743 
3744     static boolean anyTrue(boolean[] a, int idx) {
3745         boolean res = false;
3746         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3747             res |= a[i];
3748         }
3749 
3750         return res;
3751     }
3752 
3753     @Test(dataProvider = "boolUnaryOpProvider")
3754     static void anyTrueInt512VectorTests(IntFunction<boolean[]> fm) {
3755         boolean[] mask = fm.apply(SPECIES.length());
3756         boolean[] r = fmr.apply(SPECIES.length());
3757 
3758         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3759             for (int i = 0; i < mask.length; i += SPECIES.length()) {
3760                 VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, i);
3761                 r[i] = vmask.anyTrue();
3762             }
3763         }
3764 
3765         assertReductionBoolArraysEquals(r, mask, Int512VectorTests::anyTrue);
3766     }
3767 
3768     static boolean allTrue(boolean[] a, int idx) {
3769         boolean res = true;
3770         for (int i = idx; i < (idx + SPECIES.length()); i++) {
3771             res &= a[i];
3772         }
3773 
3774         return res;
3775     }
3776 
3777     @Test(dataProvider = "boolUnaryOpProvider")
3778     static void allTrueInt512VectorTests(IntFunction<boolean[]> fm) {
3779         boolean[] mask = fm.apply(SPECIES.length());
3780         boolean[] r = fmr.apply(SPECIES.length());
3781 
3782         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3783             for (int i = 0; i < mask.length; i += SPECIES.length()) {
3784                 VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, i);
3785                 r[i] = vmask.allTrue();
3786             }
3787         }
3788 
3789         assertReductionBoolArraysEquals(r, mask, Int512VectorTests::allTrue);
3790     }
3791 
3792     @Test(dataProvider = "intUnaryOpProvider")
3793     static void withInt512VectorTests(IntFunction<int []> fa) {
3794         int[] a = fa.apply(SPECIES.length());
3795         int[] r = fr.apply(SPECIES.length());
3796 
3797         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3798             for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
3799                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3800                 av.withLane((j++ & (SPECIES.length()-1)), (int)(65535+i)).intoArray(r, i);
3801             }
3802         }
3803 
3804 
3805         for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
3806             assertInsertArraysEquals(r, a, (int)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length());
3807         }
3808     }
3809 
3810     static boolean testIS_DEFAULT(int a) {
3811         return bits(a)==0;
3812     }
3813 
3814     @Test(dataProvider = "intTestOpProvider")
3815     static void IS_DEFAULTInt512VectorTests(IntFunction<int[]> fa) {
3816         int[] a = fa.apply(SPECIES.length());
3817 
3818         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3819             for (int i = 0; i < a.length; i += SPECIES.length()) {
3820                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3821                 VectorMask<Integer> mv = av.test(VectorOperators.IS_DEFAULT);
3822 
3823                 // Check results as part of computation.
3824                 for (int j = 0; j < SPECIES.length(); j++) {
3825                     Assert.assertEquals(mv.laneIsSet(j), testIS_DEFAULT(a[i + j]));
3826                 }
3827             }
3828         }
3829     }
3830 
3831     @Test(dataProvider = "intTestOpMaskProvider")
3832     static void IS_DEFAULTMaskedInt512VectorTests(IntFunction<int[]> fa,
3833                                           IntFunction<boolean[]> fm) {
3834         int[] a = fa.apply(SPECIES.length());
3835         boolean[] mask = fm.apply(SPECIES.length());
3836         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3837 
3838         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3839             for (int i = 0; i < a.length; i += SPECIES.length()) {
3840                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3841                 VectorMask<Integer> mv = av.test(VectorOperators.IS_DEFAULT, vmask);
3842 
3843                 // Check results as part of computation.
3844                 for (int j = 0; j < SPECIES.length(); j++) {
3845                     Assert.assertEquals(mv.laneIsSet(j),  vmask.laneIsSet(j) && testIS_DEFAULT(a[i + j]));
3846                 }
3847             }
3848         }
3849     }
3850 
3851     static boolean testIS_NEGATIVE(int a) {
3852         return bits(a)<0;
3853     }
3854 
3855     @Test(dataProvider = "intTestOpProvider")
3856     static void IS_NEGATIVEInt512VectorTests(IntFunction<int[]> fa) {
3857         int[] a = fa.apply(SPECIES.length());
3858 
3859         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3860             for (int i = 0; i < a.length; i += SPECIES.length()) {
3861                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3862                 VectorMask<Integer> mv = av.test(VectorOperators.IS_NEGATIVE);
3863 
3864                 // Check results as part of computation.
3865                 for (int j = 0; j < SPECIES.length(); j++) {
3866                     Assert.assertEquals(mv.laneIsSet(j), testIS_NEGATIVE(a[i + j]));
3867                 }
3868             }
3869         }
3870     }
3871 
3872     @Test(dataProvider = "intTestOpMaskProvider")
3873     static void IS_NEGATIVEMaskedInt512VectorTests(IntFunction<int[]> fa,
3874                                           IntFunction<boolean[]> fm) {
3875         int[] a = fa.apply(SPECIES.length());
3876         boolean[] mask = fm.apply(SPECIES.length());
3877         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3878 
3879         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3880             for (int i = 0; i < a.length; i += SPECIES.length()) {
3881                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3882                 VectorMask<Integer> mv = av.test(VectorOperators.IS_NEGATIVE, vmask);
3883 
3884                 // Check results as part of computation.
3885                 for (int j = 0; j < SPECIES.length(); j++) {
3886                     Assert.assertEquals(mv.laneIsSet(j),  vmask.laneIsSet(j) && testIS_NEGATIVE(a[i + j]));
3887                 }
3888             }
3889         }
3890     }
3891 
3892     @Test(dataProvider = "intCompareOpProvider")
3893     static void LTInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
3894         int[] a = fa.apply(SPECIES.length());
3895         int[] b = fb.apply(SPECIES.length());
3896 
3897         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3898             for (int i = 0; i < a.length; i += SPECIES.length()) {
3899                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3900                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
3901                 VectorMask<Integer> mv = av.compare(VectorOperators.LT, bv);
3902 
3903                 // Check results as part of computation.
3904                 for (int j = 0; j < SPECIES.length(); j++) {
3905                     Assert.assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i + j]));
3906                 }
3907             }
3908         }
3909     }
3910 
3911     @Test(dataProvider = "intCompareOpProvider")
3912     static void ltInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
3913         int[] a = fa.apply(SPECIES.length());
3914         int[] b = fb.apply(SPECIES.length());
3915 
3916         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3917             for (int i = 0; i < a.length; i += SPECIES.length()) {
3918                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3919                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
3920                 VectorMask<Integer> mv = av.lt(bv);
3921 
3922                 // Check results as part of computation.
3923                 for (int j = 0; j < SPECIES.length(); j++) {
3924                     Assert.assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i + j]));
3925                 }
3926             }
3927         }
3928     }
3929 
3930     @Test(dataProvider = "intCompareOpMaskProvider")
3931     static void LTInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
3932                                                 IntFunction<boolean[]> fm) {
3933         int[] a = fa.apply(SPECIES.length());
3934         int[] b = fb.apply(SPECIES.length());
3935         boolean[] mask = fm.apply(SPECIES.length());
3936 
3937         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3938 
3939         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3940             for (int i = 0; i < a.length; i += SPECIES.length()) {
3941                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3942                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
3943                 VectorMask<Integer> mv = av.compare(VectorOperators.LT, bv, vmask);
3944 
3945                 // Check results as part of computation.
3946                 for (int j = 0; j < SPECIES.length(); j++) {
3947                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && lt(a[i + j], b[i + j]));
3948                 }
3949             }
3950         }
3951     }
3952 
3953     @Test(dataProvider = "intCompareOpProvider")
3954     static void GTInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
3955         int[] a = fa.apply(SPECIES.length());
3956         int[] b = fb.apply(SPECIES.length());
3957 
3958         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3959             for (int i = 0; i < a.length; i += SPECIES.length()) {
3960                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3961                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
3962                 VectorMask<Integer> mv = av.compare(VectorOperators.GT, bv);
3963 
3964                 // Check results as part of computation.
3965                 for (int j = 0; j < SPECIES.length(); j++) {
3966                     Assert.assertEquals(mv.laneIsSet(j), gt(a[i + j], b[i + j]));
3967                 }
3968             }
3969         }
3970     }
3971 
3972     @Test(dataProvider = "intCompareOpMaskProvider")
3973     static void GTInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
3974                                                 IntFunction<boolean[]> fm) {
3975         int[] a = fa.apply(SPECIES.length());
3976         int[] b = fb.apply(SPECIES.length());
3977         boolean[] mask = fm.apply(SPECIES.length());
3978 
3979         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3980 
3981         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3982             for (int i = 0; i < a.length; i += SPECIES.length()) {
3983                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3984                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
3985                 VectorMask<Integer> mv = av.compare(VectorOperators.GT, bv, vmask);
3986 
3987                 // Check results as part of computation.
3988                 for (int j = 0; j < SPECIES.length(); j++) {
3989                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && gt(a[i + j], b[i + j]));
3990                 }
3991             }
3992         }
3993     }
3994 
3995     @Test(dataProvider = "intCompareOpProvider")
3996     static void EQInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
3997         int[] a = fa.apply(SPECIES.length());
3998         int[] b = fb.apply(SPECIES.length());
3999 
4000         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4001             for (int i = 0; i < a.length; i += SPECIES.length()) {
4002                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4003                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4004                 VectorMask<Integer> mv = av.compare(VectorOperators.EQ, bv);
4005 
4006                 // Check results as part of computation.
4007                 for (int j = 0; j < SPECIES.length(); j++) {
4008                     Assert.assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i + j]));
4009                 }
4010             }
4011         }
4012     }
4013 
4014     @Test(dataProvider = "intCompareOpProvider")
4015     static void eqInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
4016         int[] a = fa.apply(SPECIES.length());
4017         int[] b = fb.apply(SPECIES.length());
4018 
4019         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4020             for (int i = 0; i < a.length; i += SPECIES.length()) {
4021                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4022                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4023                 VectorMask<Integer> mv = av.eq(bv);
4024 
4025                 // Check results as part of computation.
4026                 for (int j = 0; j < SPECIES.length(); j++) {
4027                     Assert.assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i + j]));
4028                 }
4029             }
4030         }
4031     }
4032 
4033     @Test(dataProvider = "intCompareOpMaskProvider")
4034     static void EQInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
4035                                                 IntFunction<boolean[]> fm) {
4036         int[] a = fa.apply(SPECIES.length());
4037         int[] b = fb.apply(SPECIES.length());
4038         boolean[] mask = fm.apply(SPECIES.length());
4039 
4040         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4041 
4042         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4043             for (int i = 0; i < a.length; i += SPECIES.length()) {
4044                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4045                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4046                 VectorMask<Integer> mv = av.compare(VectorOperators.EQ, bv, vmask);
4047 
4048                 // Check results as part of computation.
4049                 for (int j = 0; j < SPECIES.length(); j++) {
4050                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && eq(a[i + j], b[i + j]));
4051                 }
4052             }
4053         }
4054     }
4055 
4056     @Test(dataProvider = "intCompareOpProvider")
4057     static void NEInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
4058         int[] a = fa.apply(SPECIES.length());
4059         int[] b = fb.apply(SPECIES.length());
4060 
4061         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4062             for (int i = 0; i < a.length; i += SPECIES.length()) {
4063                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4064                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4065                 VectorMask<Integer> mv = av.compare(VectorOperators.NE, bv);
4066 
4067                 // Check results as part of computation.
4068                 for (int j = 0; j < SPECIES.length(); j++) {
4069                     Assert.assertEquals(mv.laneIsSet(j), neq(a[i + j], b[i + j]));
4070                 }
4071             }
4072         }
4073     }
4074 
4075     @Test(dataProvider = "intCompareOpMaskProvider")
4076     static void NEInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
4077                                                 IntFunction<boolean[]> fm) {
4078         int[] a = fa.apply(SPECIES.length());
4079         int[] b = fb.apply(SPECIES.length());
4080         boolean[] mask = fm.apply(SPECIES.length());
4081 
4082         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4083 
4084         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4085             for (int i = 0; i < a.length; i += SPECIES.length()) {
4086                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4087                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4088                 VectorMask<Integer> mv = av.compare(VectorOperators.NE, bv, vmask);
4089 
4090                 // Check results as part of computation.
4091                 for (int j = 0; j < SPECIES.length(); j++) {
4092                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && neq(a[i + j], b[i + j]));
4093                 }
4094             }
4095         }
4096     }
4097 
4098     @Test(dataProvider = "intCompareOpProvider")
4099     static void LEInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
4100         int[] a = fa.apply(SPECIES.length());
4101         int[] b = fb.apply(SPECIES.length());
4102 
4103         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4104             for (int i = 0; i < a.length; i += SPECIES.length()) {
4105                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4106                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4107                 VectorMask<Integer> mv = av.compare(VectorOperators.LE, bv);
4108 
4109                 // Check results as part of computation.
4110                 for (int j = 0; j < SPECIES.length(); j++) {
4111                     Assert.assertEquals(mv.laneIsSet(j), le(a[i + j], b[i + j]));
4112                 }
4113             }
4114         }
4115     }
4116 
4117     @Test(dataProvider = "intCompareOpMaskProvider")
4118     static void LEInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
4119                                                 IntFunction<boolean[]> fm) {
4120         int[] a = fa.apply(SPECIES.length());
4121         int[] b = fb.apply(SPECIES.length());
4122         boolean[] mask = fm.apply(SPECIES.length());
4123 
4124         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4125 
4126         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4127             for (int i = 0; i < a.length; i += SPECIES.length()) {
4128                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4129                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4130                 VectorMask<Integer> mv = av.compare(VectorOperators.LE, bv, vmask);
4131 
4132                 // Check results as part of computation.
4133                 for (int j = 0; j < SPECIES.length(); j++) {
4134                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && le(a[i + j], b[i + j]));
4135                 }
4136             }
4137         }
4138     }
4139 
4140     @Test(dataProvider = "intCompareOpProvider")
4141     static void GEInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
4142         int[] a = fa.apply(SPECIES.length());
4143         int[] b = fb.apply(SPECIES.length());
4144 
4145         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4146             for (int i = 0; i < a.length; i += SPECIES.length()) {
4147                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4148                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4149                 VectorMask<Integer> mv = av.compare(VectorOperators.GE, bv);
4150 
4151                 // Check results as part of computation.
4152                 for (int j = 0; j < SPECIES.length(); j++) {
4153                     Assert.assertEquals(mv.laneIsSet(j), ge(a[i + j], b[i + j]));
4154                 }
4155             }
4156         }
4157     }
4158 
4159     @Test(dataProvider = "intCompareOpMaskProvider")
4160     static void GEInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
4161                                                 IntFunction<boolean[]> fm) {
4162         int[] a = fa.apply(SPECIES.length());
4163         int[] b = fb.apply(SPECIES.length());
4164         boolean[] mask = fm.apply(SPECIES.length());
4165 
4166         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4167 
4168         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4169             for (int i = 0; i < a.length; i += SPECIES.length()) {
4170                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4171                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4172                 VectorMask<Integer> mv = av.compare(VectorOperators.GE, bv, vmask);
4173 
4174                 // Check results as part of computation.
4175                 for (int j = 0; j < SPECIES.length(); j++) {
4176                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && ge(a[i + j], b[i + j]));
4177                 }
4178             }
4179         }
4180     }
4181 
4182     @Test(dataProvider = "intCompareOpProvider")
4183     static void UNSIGNED_LTInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
4184         int[] a = fa.apply(SPECIES.length());
4185         int[] b = fb.apply(SPECIES.length());
4186 
4187         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4188             for (int i = 0; i < a.length; i += SPECIES.length()) {
4189                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4190                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4191                 VectorMask<Integer> mv = av.compare(VectorOperators.UNSIGNED_LT, bv);
4192 
4193                 // Check results as part of computation.
4194                 for (int j = 0; j < SPECIES.length(); j++) {
4195                     Assert.assertEquals(mv.laneIsSet(j), ult(a[i + j], b[i + j]));
4196                 }
4197             }
4198         }
4199     }
4200 
4201     @Test(dataProvider = "intCompareOpMaskProvider")
4202     static void UNSIGNED_LTInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
4203                                                 IntFunction<boolean[]> fm) {
4204         int[] a = fa.apply(SPECIES.length());
4205         int[] b = fb.apply(SPECIES.length());
4206         boolean[] mask = fm.apply(SPECIES.length());
4207 
4208         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4209 
4210         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4211             for (int i = 0; i < a.length; i += SPECIES.length()) {
4212                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4213                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4214                 VectorMask<Integer> mv = av.compare(VectorOperators.UNSIGNED_LT, bv, vmask);
4215 
4216                 // Check results as part of computation.
4217                 for (int j = 0; j < SPECIES.length(); j++) {
4218                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && ult(a[i + j], b[i + j]));
4219                 }
4220             }
4221         }
4222     }
4223 
4224     @Test(dataProvider = "intCompareOpProvider")
4225     static void UNSIGNED_GTInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
4226         int[] a = fa.apply(SPECIES.length());
4227         int[] b = fb.apply(SPECIES.length());
4228 
4229         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4230             for (int i = 0; i < a.length; i += SPECIES.length()) {
4231                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4232                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4233                 VectorMask<Integer> mv = av.compare(VectorOperators.UNSIGNED_GT, bv);
4234 
4235                 // Check results as part of computation.
4236                 for (int j = 0; j < SPECIES.length(); j++) {
4237                     Assert.assertEquals(mv.laneIsSet(j), ugt(a[i + j], b[i + j]));
4238                 }
4239             }
4240         }
4241     }
4242 
4243     @Test(dataProvider = "intCompareOpMaskProvider")
4244     static void UNSIGNED_GTInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
4245                                                 IntFunction<boolean[]> fm) {
4246         int[] a = fa.apply(SPECIES.length());
4247         int[] b = fb.apply(SPECIES.length());
4248         boolean[] mask = fm.apply(SPECIES.length());
4249 
4250         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4251 
4252         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4253             for (int i = 0; i < a.length; i += SPECIES.length()) {
4254                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4255                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4256                 VectorMask<Integer> mv = av.compare(VectorOperators.UNSIGNED_GT, bv, vmask);
4257 
4258                 // Check results as part of computation.
4259                 for (int j = 0; j < SPECIES.length(); j++) {
4260                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && ugt(a[i + j], b[i + j]));
4261                 }
4262             }
4263         }
4264     }
4265 
4266     @Test(dataProvider = "intCompareOpProvider")
4267     static void UNSIGNED_LEInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
4268         int[] a = fa.apply(SPECIES.length());
4269         int[] b = fb.apply(SPECIES.length());
4270 
4271         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4272             for (int i = 0; i < a.length; i += SPECIES.length()) {
4273                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4274                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4275                 VectorMask<Integer> mv = av.compare(VectorOperators.UNSIGNED_LE, bv);
4276 
4277                 // Check results as part of computation.
4278                 for (int j = 0; j < SPECIES.length(); j++) {
4279                     Assert.assertEquals(mv.laneIsSet(j), ule(a[i + j], b[i + j]));
4280                 }
4281             }
4282         }
4283     }
4284 
4285     @Test(dataProvider = "intCompareOpMaskProvider")
4286     static void UNSIGNED_LEInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
4287                                                 IntFunction<boolean[]> fm) {
4288         int[] a = fa.apply(SPECIES.length());
4289         int[] b = fb.apply(SPECIES.length());
4290         boolean[] mask = fm.apply(SPECIES.length());
4291 
4292         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4293 
4294         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4295             for (int i = 0; i < a.length; i += SPECIES.length()) {
4296                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4297                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4298                 VectorMask<Integer> mv = av.compare(VectorOperators.UNSIGNED_LE, bv, vmask);
4299 
4300                 // Check results as part of computation.
4301                 for (int j = 0; j < SPECIES.length(); j++) {
4302                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && ule(a[i + j], b[i + j]));
4303                 }
4304             }
4305         }
4306     }
4307 
4308     @Test(dataProvider = "intCompareOpProvider")
4309     static void UNSIGNED_GEInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
4310         int[] a = fa.apply(SPECIES.length());
4311         int[] b = fb.apply(SPECIES.length());
4312 
4313         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4314             for (int i = 0; i < a.length; i += SPECIES.length()) {
4315                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4316                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4317                 VectorMask<Integer> mv = av.compare(VectorOperators.UNSIGNED_GE, bv);
4318 
4319                 // Check results as part of computation.
4320                 for (int j = 0; j < SPECIES.length(); j++) {
4321                     Assert.assertEquals(mv.laneIsSet(j), uge(a[i + j], b[i + j]));
4322                 }
4323             }
4324         }
4325     }
4326 
4327     @Test(dataProvider = "intCompareOpMaskProvider")
4328     static void UNSIGNED_GEInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
4329                                                 IntFunction<boolean[]> fm) {
4330         int[] a = fa.apply(SPECIES.length());
4331         int[] b = fb.apply(SPECIES.length());
4332         boolean[] mask = fm.apply(SPECIES.length());
4333 
4334         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4335 
4336         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4337             for (int i = 0; i < a.length; i += SPECIES.length()) {
4338                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4339                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4340                 VectorMask<Integer> mv = av.compare(VectorOperators.UNSIGNED_GE, bv, vmask);
4341 
4342                 // Check results as part of computation.
4343                 for (int j = 0; j < SPECIES.length(); j++) {
4344                     Assert.assertEquals(mv.laneIsSet(j), mask[j] && uge(a[i + j], b[i + j]));
4345                 }
4346             }
4347         }
4348     }
4349 
4350     @Test(dataProvider = "intCompareOpProvider")
4351     static void LTInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
4352         int[] a = fa.apply(SPECIES.length());
4353         int[] b = fb.apply(SPECIES.length());
4354 
4355         for (int i = 0; i < a.length; i += SPECIES.length()) {
4356             IntVector av = IntVector.fromArray(SPECIES, a, i);
4357             VectorMask<Integer> mv = av.compare(VectorOperators.LT, b[i]);
4358 
4359             // Check results as part of computation.
4360             for (int j = 0; j < SPECIES.length(); j++) {
4361                 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i]);
4362             }
4363         }
4364     }
4365 
4366     @Test(dataProvider = "intCompareOpMaskProvider")
4367     static void LTInt512VectorTestsBroadcastMaskedSmokeTest(IntFunction<int[]> fa,
4368                                 IntFunction<int[]> fb, IntFunction<boolean[]> fm) {
4369         int[] a = fa.apply(SPECIES.length());
4370         int[] b = fb.apply(SPECIES.length());
4371         boolean[] mask = fm.apply(SPECIES.length());
4372 
4373         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4374 
4375         for (int i = 0; i < a.length; i += SPECIES.length()) {
4376             IntVector av = IntVector.fromArray(SPECIES, a, i);
4377             VectorMask<Integer> mv = av.compare(VectorOperators.LT, b[i], vmask);
4378 
4379             // Check results as part of computation.
4380             for (int j = 0; j < SPECIES.length(); j++) {
4381                 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i]));
4382             }
4383         }
4384     }
4385 
4386     @Test(dataProvider = "intCompareOpProvider")
4387     static void LTInt512VectorTestsBroadcastLongSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
4388         int[] a = fa.apply(SPECIES.length());
4389         int[] b = fb.apply(SPECIES.length());
4390 
4391         for (int i = 0; i < a.length; i += SPECIES.length()) {
4392             IntVector av = IntVector.fromArray(SPECIES, a, i);
4393             VectorMask<Integer> mv = av.compare(VectorOperators.LT, (long)b[i]);
4394 
4395             // Check results as part of computation.
4396             for (int j = 0; j < SPECIES.length(); j++) {
4397                 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < (int)((long)b[i]));
4398             }
4399         }
4400     }
4401 
4402     @Test(dataProvider = "intCompareOpMaskProvider")
4403     static void LTInt512VectorTestsBroadcastLongMaskedSmokeTest(IntFunction<int[]> fa,
4404                                 IntFunction<int[]> fb, IntFunction<boolean[]> fm) {
4405         int[] a = fa.apply(SPECIES.length());
4406         int[] b = fb.apply(SPECIES.length());
4407         boolean[] mask = fm.apply(SPECIES.length());
4408 
4409         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4410 
4411         for (int i = 0; i < a.length; i += SPECIES.length()) {
4412             IntVector av = IntVector.fromArray(SPECIES, a, i);
4413             VectorMask<Integer> mv = av.compare(VectorOperators.LT, (long)b[i], vmask);
4414 
4415             // Check results as part of computation.
4416             for (int j = 0; j < SPECIES.length(); j++) {
4417                 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (int)((long)b[i])));
4418             }
4419         }
4420     }
4421 
4422     @Test(dataProvider = "intCompareOpProvider")
4423     static void EQInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
4424         int[] a = fa.apply(SPECIES.length());
4425         int[] b = fb.apply(SPECIES.length());
4426 
4427         for (int i = 0; i < a.length; i += SPECIES.length()) {
4428             IntVector av = IntVector.fromArray(SPECIES, a, i);
4429             VectorMask<Integer> mv = av.compare(VectorOperators.EQ, b[i]);
4430 
4431             // Check results as part of computation.
4432             for (int j = 0; j < SPECIES.length(); j++) {
4433                 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i]);
4434             }
4435         }
4436     }
4437 
4438     @Test(dataProvider = "intCompareOpMaskProvider")
4439     static void EQInt512VectorTestsBroadcastMaskedSmokeTest(IntFunction<int[]> fa,
4440                                 IntFunction<int[]> fb, IntFunction<boolean[]> fm) {
4441         int[] a = fa.apply(SPECIES.length());
4442         int[] b = fb.apply(SPECIES.length());
4443         boolean[] mask = fm.apply(SPECIES.length());
4444 
4445         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4446 
4447         for (int i = 0; i < a.length; i += SPECIES.length()) {
4448             IntVector av = IntVector.fromArray(SPECIES, a, i);
4449             VectorMask<Integer> mv = av.compare(VectorOperators.EQ, b[i], vmask);
4450 
4451             // Check results as part of computation.
4452             for (int j = 0; j < SPECIES.length(); j++) {
4453                 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i]));
4454             }
4455         }
4456     }
4457 
4458     @Test(dataProvider = "intCompareOpProvider")
4459     static void EQInt512VectorTestsBroadcastLongSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
4460         int[] a = fa.apply(SPECIES.length());
4461         int[] b = fb.apply(SPECIES.length());
4462 
4463         for (int i = 0; i < a.length; i += SPECIES.length()) {
4464             IntVector av = IntVector.fromArray(SPECIES, a, i);
4465             VectorMask<Integer> mv = av.compare(VectorOperators.EQ, (long)b[i]);
4466 
4467             // Check results as part of computation.
4468             for (int j = 0; j < SPECIES.length(); j++) {
4469                 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == (int)((long)b[i]));
4470             }
4471         }
4472     }
4473 
4474     @Test(dataProvider = "intCompareOpMaskProvider")
4475     static void EQInt512VectorTestsBroadcastLongMaskedSmokeTest(IntFunction<int[]> fa,
4476                                 IntFunction<int[]> fb, IntFunction<boolean[]> fm) {
4477         int[] a = fa.apply(SPECIES.length());
4478         int[] b = fb.apply(SPECIES.length());
4479         boolean[] mask = fm.apply(SPECIES.length());
4480 
4481         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4482 
4483         for (int i = 0; i < a.length; i += SPECIES.length()) {
4484             IntVector av = IntVector.fromArray(SPECIES, a, i);
4485             VectorMask<Integer> mv = av.compare(VectorOperators.EQ, (long)b[i], vmask);
4486 
4487             // Check results as part of computation.
4488             for (int j = 0; j < SPECIES.length(); j++) {
4489                 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (int)((long)b[i])));
4490             }
4491         }
4492     }
4493 
4494     static int blend(int a, int b, boolean mask) {
4495         return mask ? b : a;
4496     }
4497 
4498     @Test(dataProvider = "intBinaryOpMaskProvider")
4499     static void blendInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb,
4500                                           IntFunction<boolean[]> fm) {
4501         int[] a = fa.apply(SPECIES.length());
4502         int[] b = fb.apply(SPECIES.length());
4503         int[] r = fr.apply(SPECIES.length());
4504         boolean[] mask = fm.apply(SPECIES.length());
4505         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4506 
4507         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4508             for (int i = 0; i < a.length; i += SPECIES.length()) {
4509                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4510                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4511                 av.blend(bv, vmask).intoArray(r, i);
4512             }
4513         }
4514 
4515         assertArraysEquals(r, a, b, mask, Int512VectorTests::blend);
4516     }
4517 
4518     @Test(dataProvider = "intUnaryOpShuffleProvider")
4519     static void RearrangeInt512VectorTests(IntFunction<int[]> fa,
4520                                            BiFunction<Integer,Integer,int[]> fs) {
4521         int[] a = fa.apply(SPECIES.length());
4522         int[] order = fs.apply(a.length, SPECIES.length());
4523         int[] r = fr.apply(SPECIES.length());
4524 
4525         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4526             for (int i = 0; i < a.length; i += SPECIES.length()) {
4527                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4528                 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
4529             }
4530         }
4531 
4532         assertRearrangeArraysEquals(r, a, order, SPECIES.length());
4533     }
4534 
4535     @Test(dataProvider = "intUnaryOpShuffleMaskProvider")
4536     static void RearrangeInt512VectorTestsMaskedSmokeTest(IntFunction<int[]> fa,
4537                                                           BiFunction<Integer,Integer,int[]> fs,
4538                                                           IntFunction<boolean[]> fm) {
4539         int[] a = fa.apply(SPECIES.length());
4540         int[] order = fs.apply(a.length, SPECIES.length());
4541         int[] r = fr.apply(SPECIES.length());
4542         boolean[] mask = fm.apply(SPECIES.length());
4543         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4544 
4545         for (int i = 0; i < a.length; i += SPECIES.length()) {
4546             IntVector av = IntVector.fromArray(SPECIES, a, i);
4547             av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i);
4548         }
4549 
4550         assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length());
4551     }
4552 
4553     @Test(dataProvider = "intUnaryOpMaskProvider")
4554     static void compressInt512VectorTests(IntFunction<int[]> fa,
4555                                                 IntFunction<boolean[]> fm) {
4556         int[] a = fa.apply(SPECIES.length());
4557         int[] r = fr.apply(SPECIES.length());
4558         boolean[] mask = fm.apply(SPECIES.length());
4559         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4560 
4561         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4562             for (int i = 0; i < a.length; i += SPECIES.length()) {
4563                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4564                 av.compress(vmask).intoArray(r, i);
4565             }
4566         }
4567 
4568         assertcompressArraysEquals(r, a, mask, SPECIES.length());
4569     }
4570 
4571     @Test(dataProvider = "intUnaryOpMaskProvider")
4572     static void expandInt512VectorTests(IntFunction<int[]> fa,
4573                                                 IntFunction<boolean[]> fm) {
4574         int[] a = fa.apply(SPECIES.length());
4575         int[] r = fr.apply(SPECIES.length());
4576         boolean[] mask = fm.apply(SPECIES.length());
4577         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4578 
4579         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4580             for (int i = 0; i < a.length; i += SPECIES.length()) {
4581                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4582                 av.expand(vmask).intoArray(r, i);
4583             }
4584         }
4585 
4586         assertexpandArraysEquals(r, a, mask, SPECIES.length());
4587     }
4588 
4589     @Test(dataProvider = "intUnaryOpProvider")
4590     static void getInt512VectorTests(IntFunction<int[]> fa) {
4591         int[] a = fa.apply(SPECIES.length());
4592         int[] r = fr.apply(SPECIES.length());
4593 
4594         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4595             for (int i = 0; i < a.length; i += SPECIES.length()) {
4596                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4597                 int num_lanes = SPECIES.length();
4598                 // Manually unroll because full unroll happens after intrinsification.
4599                 // Unroll is needed because get intrinsic requires for index to be a known constant.
4600                 if (num_lanes == 1) {
4601                     r[i]=av.lane(0);
4602                 } else if (num_lanes == 2) {
4603                     r[i]=av.lane(0);
4604                     r[i+1]=av.lane(1);
4605                 } else if (num_lanes == 4) {
4606                     r[i]=av.lane(0);
4607                     r[i+1]=av.lane(1);
4608                     r[i+2]=av.lane(2);
4609                     r[i+3]=av.lane(3);
4610                 } else if (num_lanes == 8) {
4611                     r[i]=av.lane(0);
4612                     r[i+1]=av.lane(1);
4613                     r[i+2]=av.lane(2);
4614                     r[i+3]=av.lane(3);
4615                     r[i+4]=av.lane(4);
4616                     r[i+5]=av.lane(5);
4617                     r[i+6]=av.lane(6);
4618                     r[i+7]=av.lane(7);
4619                 } else if (num_lanes == 16) {
4620                     r[i]=av.lane(0);
4621                     r[i+1]=av.lane(1);
4622                     r[i+2]=av.lane(2);
4623                     r[i+3]=av.lane(3);
4624                     r[i+4]=av.lane(4);
4625                     r[i+5]=av.lane(5);
4626                     r[i+6]=av.lane(6);
4627                     r[i+7]=av.lane(7);
4628                     r[i+8]=av.lane(8);
4629                     r[i+9]=av.lane(9);
4630                     r[i+10]=av.lane(10);
4631                     r[i+11]=av.lane(11);
4632                     r[i+12]=av.lane(12);
4633                     r[i+13]=av.lane(13);
4634                     r[i+14]=av.lane(14);
4635                     r[i+15]=av.lane(15);
4636                 } else if (num_lanes == 32) {
4637                     r[i]=av.lane(0);
4638                     r[i+1]=av.lane(1);
4639                     r[i+2]=av.lane(2);
4640                     r[i+3]=av.lane(3);
4641                     r[i+4]=av.lane(4);
4642                     r[i+5]=av.lane(5);
4643                     r[i+6]=av.lane(6);
4644                     r[i+7]=av.lane(7);
4645                     r[i+8]=av.lane(8);
4646                     r[i+9]=av.lane(9);
4647                     r[i+10]=av.lane(10);
4648                     r[i+11]=av.lane(11);
4649                     r[i+12]=av.lane(12);
4650                     r[i+13]=av.lane(13);
4651                     r[i+14]=av.lane(14);
4652                     r[i+15]=av.lane(15);
4653                     r[i+16]=av.lane(16);
4654                     r[i+17]=av.lane(17);
4655                     r[i+18]=av.lane(18);
4656                     r[i+19]=av.lane(19);
4657                     r[i+20]=av.lane(20);
4658                     r[i+21]=av.lane(21);
4659                     r[i+22]=av.lane(22);
4660                     r[i+23]=av.lane(23);
4661                     r[i+24]=av.lane(24);
4662                     r[i+25]=av.lane(25);
4663                     r[i+26]=av.lane(26);
4664                     r[i+27]=av.lane(27);
4665                     r[i+28]=av.lane(28);
4666                     r[i+29]=av.lane(29);
4667                     r[i+30]=av.lane(30);
4668                     r[i+31]=av.lane(31);
4669                 } else if (num_lanes == 64) {
4670                     r[i]=av.lane(0);
4671                     r[i+1]=av.lane(1);
4672                     r[i+2]=av.lane(2);
4673                     r[i+3]=av.lane(3);
4674                     r[i+4]=av.lane(4);
4675                     r[i+5]=av.lane(5);
4676                     r[i+6]=av.lane(6);
4677                     r[i+7]=av.lane(7);
4678                     r[i+8]=av.lane(8);
4679                     r[i+9]=av.lane(9);
4680                     r[i+10]=av.lane(10);
4681                     r[i+11]=av.lane(11);
4682                     r[i+12]=av.lane(12);
4683                     r[i+13]=av.lane(13);
4684                     r[i+14]=av.lane(14);
4685                     r[i+15]=av.lane(15);
4686                     r[i+16]=av.lane(16);
4687                     r[i+17]=av.lane(17);
4688                     r[i+18]=av.lane(18);
4689                     r[i+19]=av.lane(19);
4690                     r[i+20]=av.lane(20);
4691                     r[i+21]=av.lane(21);
4692                     r[i+22]=av.lane(22);
4693                     r[i+23]=av.lane(23);
4694                     r[i+24]=av.lane(24);
4695                     r[i+25]=av.lane(25);
4696                     r[i+26]=av.lane(26);
4697                     r[i+27]=av.lane(27);
4698                     r[i+28]=av.lane(28);
4699                     r[i+29]=av.lane(29);
4700                     r[i+30]=av.lane(30);
4701                     r[i+31]=av.lane(31);
4702                     r[i+32]=av.lane(32);
4703                     r[i+33]=av.lane(33);
4704                     r[i+34]=av.lane(34);
4705                     r[i+35]=av.lane(35);
4706                     r[i+36]=av.lane(36);
4707                     r[i+37]=av.lane(37);
4708                     r[i+38]=av.lane(38);
4709                     r[i+39]=av.lane(39);
4710                     r[i+40]=av.lane(40);
4711                     r[i+41]=av.lane(41);
4712                     r[i+42]=av.lane(42);
4713                     r[i+43]=av.lane(43);
4714                     r[i+44]=av.lane(44);
4715                     r[i+45]=av.lane(45);
4716                     r[i+46]=av.lane(46);
4717                     r[i+47]=av.lane(47);
4718                     r[i+48]=av.lane(48);
4719                     r[i+49]=av.lane(49);
4720                     r[i+50]=av.lane(50);
4721                     r[i+51]=av.lane(51);
4722                     r[i+52]=av.lane(52);
4723                     r[i+53]=av.lane(53);
4724                     r[i+54]=av.lane(54);
4725                     r[i+55]=av.lane(55);
4726                     r[i+56]=av.lane(56);
4727                     r[i+57]=av.lane(57);
4728                     r[i+58]=av.lane(58);
4729                     r[i+59]=av.lane(59);
4730                     r[i+60]=av.lane(60);
4731                     r[i+61]=av.lane(61);
4732                     r[i+62]=av.lane(62);
4733                     r[i+63]=av.lane(63);
4734                 } else {
4735                     for (int j = 0; j < SPECIES.length(); j++) {
4736                         r[i+j]=av.lane(j);
4737                     }
4738                 }
4739             }
4740         }
4741 
4742         assertArraysEquals(r, a, Int512VectorTests::get);
4743     }
4744 
4745     @Test(dataProvider = "intUnaryOpProvider")
4746     static void BroadcastInt512VectorTests(IntFunction<int[]> fa) {
4747         int[] a = fa.apply(SPECIES.length());
4748         int[] r = new int[a.length];
4749 
4750         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4751             for (int i = 0; i < a.length; i += SPECIES.length()) {
4752                 IntVector.broadcast(SPECIES, a[i]).intoArray(r, i);
4753             }
4754         }
4755 
4756         assertBroadcastArraysEquals(r, a);
4757     }
4758 
4759     @Test(dataProvider = "intUnaryOpProvider")
4760     static void ZeroInt512VectorTests(IntFunction<int[]> fa) {
4761         int[] a = fa.apply(SPECIES.length());
4762         int[] r = new int[a.length];
4763 
4764         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4765             for (int i = 0; i < a.length; i += SPECIES.length()) {
4766                 IntVector.zero(SPECIES).intoArray(a, i);
4767             }
4768         }
4769 
4770         Assert.assertEquals(a, r);
4771     }
4772 
4773     static int[] sliceUnary(int[] a, int origin, int idx) {
4774         int[] res = new int[SPECIES.length()];
4775         for (int i = 0; i < SPECIES.length(); i++){
4776             if(i+origin < SPECIES.length())
4777                 res[i] = a[idx+i+origin];
4778             else
4779                 res[i] = (int)0;
4780         }
4781         return res;
4782     }
4783 
4784     @Test(dataProvider = "intUnaryOpProvider")
4785     static void sliceUnaryInt512VectorTests(IntFunction<int[]> fa) {
4786         int[] a = fa.apply(SPECIES.length());
4787         int[] r = new int[a.length];
4788         int origin = (new java.util.Random()).nextInt(SPECIES.length());
4789         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4790             for (int i = 0; i < a.length; i += SPECIES.length()) {
4791                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4792                 av.slice(origin).intoArray(r, i);
4793             }
4794         }
4795 
4796         assertArraysEquals(r, a, origin, Int512VectorTests::sliceUnary);
4797     }
4798 
4799     static int[] sliceBinary(int[] a, int[] b, int origin, int idx) {
4800         int[] res = new int[SPECIES.length()];
4801         for (int i = 0, j = 0; i < SPECIES.length(); i++){
4802             if(i+origin < SPECIES.length())
4803                 res[i] = a[idx+i+origin];
4804             else {
4805                 res[i] = b[idx+j];
4806                 j++;
4807             }
4808         }
4809         return res;
4810     }
4811 
4812     @Test(dataProvider = "intBinaryOpProvider")
4813     static void sliceBinaryInt512VectorTestsBinary(IntFunction<int[]> fa, IntFunction<int[]> fb) {
4814         int[] a = fa.apply(SPECIES.length());
4815         int[] b = fb.apply(SPECIES.length());
4816         int[] r = new int[a.length];
4817         int origin = (new java.util.Random()).nextInt(SPECIES.length());
4818         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4819             for (int i = 0; i < a.length; i += SPECIES.length()) {
4820                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4821                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4822                 av.slice(origin, bv).intoArray(r, i);
4823             }
4824         }
4825 
4826         assertArraysEquals(r, a, b, origin, Int512VectorTests::sliceBinary);
4827     }
4828 
4829     static int[] slice(int[] a, int[] b, int origin, boolean[] mask, int idx) {
4830         int[] res = new int[SPECIES.length()];
4831         for (int i = 0, j = 0; i < SPECIES.length(); i++){
4832             if(i+origin < SPECIES.length())
4833                 res[i] = mask[i] ? a[idx+i+origin] : (int)0;
4834             else {
4835                 res[i] = mask[i] ? b[idx+j] : (int)0;
4836                 j++;
4837             }
4838         }
4839         return res;
4840     }
4841 
4842     @Test(dataProvider = "intBinaryOpMaskProvider")
4843     static void sliceInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
4844     IntFunction<boolean[]> fm) {
4845         int[] a = fa.apply(SPECIES.length());
4846         int[] b = fb.apply(SPECIES.length());
4847         boolean[] mask = fm.apply(SPECIES.length());
4848         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4849 
4850         int[] r = new int[a.length];
4851         int origin = (new java.util.Random()).nextInt(SPECIES.length());
4852         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4853             for (int i = 0; i < a.length; i += SPECIES.length()) {
4854                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4855                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4856                 av.slice(origin, bv, vmask).intoArray(r, i);
4857             }
4858         }
4859 
4860         assertArraysEquals(r, a, b, origin, mask, Int512VectorTests::slice);
4861     }
4862 
4863     static int[] unsliceUnary(int[] a, int origin, int idx) {
4864         int[] res = new int[SPECIES.length()];
4865         for (int i = 0, j = 0; i < SPECIES.length(); i++){
4866             if(i < origin)
4867                 res[i] = (int)0;
4868             else {
4869                 res[i] = a[idx+j];
4870                 j++;
4871             }
4872         }
4873         return res;
4874     }
4875 
4876     @Test(dataProvider = "intUnaryOpProvider")
4877     static void unsliceUnaryInt512VectorTests(IntFunction<int[]> fa) {
4878         int[] a = fa.apply(SPECIES.length());
4879         int[] r = new int[a.length];
4880         int origin = (new java.util.Random()).nextInt(SPECIES.length());
4881         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4882             for (int i = 0; i < a.length; i += SPECIES.length()) {
4883                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4884                 av.unslice(origin).intoArray(r, i);
4885             }
4886         }
4887 
4888         assertArraysEquals(r, a, origin, Int512VectorTests::unsliceUnary);
4889     }
4890 
4891     static int[] unsliceBinary(int[] a, int[] b, int origin, int part, int idx) {
4892         int[] res = new int[SPECIES.length()];
4893         for (int i = 0, j = 0; i < SPECIES.length(); i++){
4894             if (part == 0) {
4895                 if (i < origin)
4896                     res[i] = b[idx+i];
4897                 else {
4898                     res[i] = a[idx+j];
4899                     j++;
4900                 }
4901             } else if (part == 1) {
4902                 if (i < origin)
4903                     res[i] = a[idx+SPECIES.length()-origin+i];
4904                 else {
4905                     res[i] = b[idx+origin+j];
4906                     j++;
4907                 }
4908             }
4909         }
4910         return res;
4911     }
4912 
4913     @Test(dataProvider = "intBinaryOpProvider")
4914     static void unsliceBinaryInt512VectorTestsBinary(IntFunction<int[]> fa, IntFunction<int[]> fb) {
4915         int[] a = fa.apply(SPECIES.length());
4916         int[] b = fb.apply(SPECIES.length());
4917         int[] r = new int[a.length];
4918         int origin = (new java.util.Random()).nextInt(SPECIES.length());
4919         int part = (new java.util.Random()).nextInt(2);
4920         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4921             for (int i = 0; i < a.length; i += SPECIES.length()) {
4922                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4923                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4924                 av.unslice(origin, bv, part).intoArray(r, i);
4925             }
4926         }
4927 
4928         assertArraysEquals(r, a, b, origin, part, Int512VectorTests::unsliceBinary);
4929     }
4930 
4931     static int[] unslice(int[] a, int[] b, int origin, int part, boolean[] mask, int idx) {
4932         int[] res = new int[SPECIES.length()];
4933         for (int i = 0, j = 0; i < SPECIES.length(); i++){
4934             if(i+origin < SPECIES.length())
4935                 res[i] = b[idx+i+origin];
4936             else {
4937                 res[i] = b[idx+j];
4938                 j++;
4939             }
4940         }
4941         for (int i = 0; i < SPECIES.length(); i++){
4942             res[i] = mask[i] ? a[idx+i] : res[i];
4943         }
4944         int[] res1 = new int[SPECIES.length()];
4945         if (part == 0) {
4946             for (int i = 0, j = 0; i < SPECIES.length(); i++){
4947                 if (i < origin)
4948                     res1[i] = b[idx+i];
4949                 else {
4950                    res1[i] = res[j];
4951                    j++;
4952                 }
4953             }
4954         } else if (part == 1) {
4955             for (int i = 0, j = 0; i < SPECIES.length(); i++){
4956                 if (i < origin)
4957                     res1[i] = res[SPECIES.length()-origin+i];
4958                 else {
4959                     res1[i] = b[idx+origin+j];
4960                     j++;
4961                 }
4962             }
4963         }
4964         return res1;
4965     }
4966 
4967     @Test(dataProvider = "intBinaryOpMaskProvider")
4968     static void unsliceInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
4969     IntFunction<boolean[]> fm) {
4970         int[] a = fa.apply(SPECIES.length());
4971         int[] b = fb.apply(SPECIES.length());
4972         boolean[] mask = fm.apply(SPECIES.length());
4973         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4974         int[] r = new int[a.length];
4975         int origin = (new java.util.Random()).nextInt(SPECIES.length());
4976         int part = (new java.util.Random()).nextInt(2);
4977         for (int ic = 0; ic < INVOC_COUNT; ic++) {
4978             for (int i = 0; i < a.length; i += SPECIES.length()) {
4979                 IntVector av = IntVector.fromArray(SPECIES, a, i);
4980                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
4981                 av.unslice(origin, bv, part, vmask).intoArray(r, i);
4982             }
4983         }
4984 
4985         assertArraysEquals(r, a, b, origin, part, mask, Int512VectorTests::unslice);
4986     }
4987 
4988     static int BITWISE_BLEND(int a, int b, int c) {
4989         return (int)((a&~(c))|(b&c));
4990     }
4991 
4992     static int bitwiseBlend(int a, int b, int c) {
4993         return (int)((a&~(c))|(b&c));
4994     }
4995 
4996     @Test(dataProvider = "intTernaryOpProvider")
4997     static void BITWISE_BLENDInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb, IntFunction<int[]> fc) {
4998         int[] a = fa.apply(SPECIES.length());
4999         int[] b = fb.apply(SPECIES.length());
5000         int[] c = fc.apply(SPECIES.length());
5001         int[] r = fr.apply(SPECIES.length());
5002 
5003         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5004             for (int i = 0; i < a.length; i += SPECIES.length()) {
5005                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5006                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
5007                 IntVector cv = IntVector.fromArray(SPECIES, c, i);
5008                 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv).intoArray(r, i);
5009             }
5010         }
5011 
5012         assertArraysEquals(r, a, b, c, Int512VectorTests::BITWISE_BLEND);
5013     }
5014 
5015     @Test(dataProvider = "intTernaryOpProvider")
5016     static void bitwiseBlendInt512VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb, IntFunction<int[]> fc) {
5017         int[] a = fa.apply(SPECIES.length());
5018         int[] b = fb.apply(SPECIES.length());
5019         int[] c = fc.apply(SPECIES.length());
5020         int[] r = fr.apply(SPECIES.length());
5021 
5022         for (int i = 0; i < a.length; i += SPECIES.length()) {
5023             IntVector av = IntVector.fromArray(SPECIES, a, i);
5024             IntVector bv = IntVector.fromArray(SPECIES, b, i);
5025             IntVector cv = IntVector.fromArray(SPECIES, c, i);
5026             av.bitwiseBlend(bv, cv).intoArray(r, i);
5027         }
5028 
5029         assertArraysEquals(r, a, b, c, Int512VectorTests::bitwiseBlend);
5030     }
5031 
5032     @Test(dataProvider = "intTernaryOpMaskProvider")
5033     static void BITWISE_BLENDInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<int[]> fb,
5034                                           IntFunction<int[]> fc, IntFunction<boolean[]> fm) {
5035         int[] a = fa.apply(SPECIES.length());
5036         int[] b = fb.apply(SPECIES.length());
5037         int[] c = fc.apply(SPECIES.length());
5038         int[] r = fr.apply(SPECIES.length());
5039         boolean[] mask = fm.apply(SPECIES.length());
5040         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5041 
5042         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5043             for (int i = 0; i < a.length; i += SPECIES.length()) {
5044                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5045                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
5046                 IntVector cv = IntVector.fromArray(SPECIES, c, i);
5047                 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i);
5048             }
5049         }
5050 
5051         assertArraysEquals(r, a, b, c, mask, Int512VectorTests::BITWISE_BLEND);
5052     }
5053 
5054     @Test(dataProvider = "intTernaryOpProvider")
5055     static void BITWISE_BLENDInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb, IntFunction<int[]> fc) {
5056         int[] a = fa.apply(SPECIES.length());
5057         int[] b = fb.apply(SPECIES.length());
5058         int[] c = fc.apply(SPECIES.length());
5059         int[] r = fr.apply(SPECIES.length());
5060 
5061         for (int i = 0; i < a.length; i += SPECIES.length()) {
5062             IntVector av = IntVector.fromArray(SPECIES, a, i);
5063             IntVector bv = IntVector.fromArray(SPECIES, b, i);
5064             av.lanewise(VectorOperators.BITWISE_BLEND, bv, c[i]).intoArray(r, i);
5065         }
5066         assertBroadcastArraysEquals(r, a, b, c, Int512VectorTests::BITWISE_BLEND);
5067     }
5068 
5069     @Test(dataProvider = "intTernaryOpProvider")
5070     static void BITWISE_BLENDInt512VectorTestsAltBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb, IntFunction<int[]> fc) {
5071         int[] a = fa.apply(SPECIES.length());
5072         int[] b = fb.apply(SPECIES.length());
5073         int[] c = fc.apply(SPECIES.length());
5074         int[] r = fr.apply(SPECIES.length());
5075 
5076         for (int i = 0; i < a.length; i += SPECIES.length()) {
5077             IntVector av = IntVector.fromArray(SPECIES, a, i);
5078             IntVector cv = IntVector.fromArray(SPECIES, c, i);
5079             av.lanewise(VectorOperators.BITWISE_BLEND, b[i], cv).intoArray(r, i);
5080         }
5081         assertAltBroadcastArraysEquals(r, a, b, c, Int512VectorTests::BITWISE_BLEND);
5082     }
5083 
5084     @Test(dataProvider = "intTernaryOpProvider")
5085     static void bitwiseBlendInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb, IntFunction<int[]> fc) {
5086         int[] a = fa.apply(SPECIES.length());
5087         int[] b = fb.apply(SPECIES.length());
5088         int[] c = fc.apply(SPECIES.length());
5089         int[] r = fr.apply(SPECIES.length());
5090 
5091         for (int i = 0; i < a.length; i += SPECIES.length()) {
5092             IntVector av = IntVector.fromArray(SPECIES, a, i);
5093             IntVector bv = IntVector.fromArray(SPECIES, b, i);
5094             av.bitwiseBlend(bv, c[i]).intoArray(r, i);
5095         }
5096         assertBroadcastArraysEquals(r, a, b, c, Int512VectorTests::bitwiseBlend);
5097     }
5098 
5099     @Test(dataProvider = "intTernaryOpProvider")
5100     static void bitwiseBlendInt512VectorTestsAltBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb, IntFunction<int[]> fc) {
5101         int[] a = fa.apply(SPECIES.length());
5102         int[] b = fb.apply(SPECIES.length());
5103         int[] c = fc.apply(SPECIES.length());
5104         int[] r = fr.apply(SPECIES.length());
5105 
5106         for (int i = 0; i < a.length; i += SPECIES.length()) {
5107             IntVector av = IntVector.fromArray(SPECIES, a, i);
5108             IntVector cv = IntVector.fromArray(SPECIES, c, i);
5109             av.bitwiseBlend(b[i], cv).intoArray(r, i);
5110         }
5111         assertAltBroadcastArraysEquals(r, a, b, c, Int512VectorTests::bitwiseBlend);
5112     }
5113 
5114     @Test(dataProvider = "intTernaryOpMaskProvider")
5115     static void BITWISE_BLENDInt512VectorTestsBroadcastMaskedSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb,
5116                                           IntFunction<int[]> fc, IntFunction<boolean[]> fm) {
5117         int[] a = fa.apply(SPECIES.length());
5118         int[] b = fb.apply(SPECIES.length());
5119         int[] c = fc.apply(SPECIES.length());
5120         int[] r = fr.apply(SPECIES.length());
5121         boolean[] mask = fm.apply(SPECIES.length());
5122         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5123 
5124         for (int i = 0; i < a.length; i += SPECIES.length()) {
5125             IntVector av = IntVector.fromArray(SPECIES, a, i);
5126             IntVector bv = IntVector.fromArray(SPECIES, b, i);
5127             av.lanewise(VectorOperators.BITWISE_BLEND, bv, c[i], vmask).intoArray(r, i);
5128         }
5129 
5130         assertBroadcastArraysEquals(r, a, b, c, mask, Int512VectorTests::BITWISE_BLEND);
5131     }
5132 
5133     @Test(dataProvider = "intTernaryOpMaskProvider")
5134     static void BITWISE_BLENDInt512VectorTestsAltBroadcastMaskedSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb,
5135                                           IntFunction<int[]> fc, IntFunction<boolean[]> fm) {
5136         int[] a = fa.apply(SPECIES.length());
5137         int[] b = fb.apply(SPECIES.length());
5138         int[] c = fc.apply(SPECIES.length());
5139         int[] r = fr.apply(SPECIES.length());
5140         boolean[] mask = fm.apply(SPECIES.length());
5141         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5142 
5143         for (int i = 0; i < a.length; i += SPECIES.length()) {
5144             IntVector av = IntVector.fromArray(SPECIES, a, i);
5145             IntVector cv = IntVector.fromArray(SPECIES, c, i);
5146             av.lanewise(VectorOperators.BITWISE_BLEND, b[i], cv, vmask).intoArray(r, i);
5147         }
5148 
5149         assertAltBroadcastArraysEquals(r, a, b, c, mask, Int512VectorTests::BITWISE_BLEND);
5150     }
5151 
5152     @Test(dataProvider = "intTernaryOpProvider")
5153     static void BITWISE_BLENDInt512VectorTestsDoubleBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb, IntFunction<int[]> fc) {
5154         int[] a = fa.apply(SPECIES.length());
5155         int[] b = fb.apply(SPECIES.length());
5156         int[] c = fc.apply(SPECIES.length());
5157         int[] r = fr.apply(SPECIES.length());
5158 
5159         for (int i = 0; i < a.length; i += SPECIES.length()) {
5160             IntVector av = IntVector.fromArray(SPECIES, a, i);
5161             av.lanewise(VectorOperators.BITWISE_BLEND, b[i], c[i]).intoArray(r, i);
5162         }
5163 
5164         assertDoubleBroadcastArraysEquals(r, a, b, c, Int512VectorTests::BITWISE_BLEND);
5165     }
5166 
5167     @Test(dataProvider = "intTernaryOpProvider")
5168     static void bitwiseBlendInt512VectorTestsDoubleBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb, IntFunction<int[]> fc) {
5169         int[] a = fa.apply(SPECIES.length());
5170         int[] b = fb.apply(SPECIES.length());
5171         int[] c = fc.apply(SPECIES.length());
5172         int[] r = fr.apply(SPECIES.length());
5173 
5174         for (int i = 0; i < a.length; i += SPECIES.length()) {
5175             IntVector av = IntVector.fromArray(SPECIES, a, i);
5176             av.bitwiseBlend(b[i], c[i]).intoArray(r, i);
5177         }
5178 
5179         assertDoubleBroadcastArraysEquals(r, a, b, c, Int512VectorTests::bitwiseBlend);
5180     }
5181 
5182     @Test(dataProvider = "intTernaryOpMaskProvider")
5183     static void BITWISE_BLENDInt512VectorTestsDoubleBroadcastMaskedSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb,
5184                                           IntFunction<int[]> fc, IntFunction<boolean[]> fm) {
5185         int[] a = fa.apply(SPECIES.length());
5186         int[] b = fb.apply(SPECIES.length());
5187         int[] c = fc.apply(SPECIES.length());
5188         int[] r = fr.apply(SPECIES.length());
5189         boolean[] mask = fm.apply(SPECIES.length());
5190         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5191 
5192         for (int i = 0; i < a.length; i += SPECIES.length()) {
5193             IntVector av = IntVector.fromArray(SPECIES, a, i);
5194             av.lanewise(VectorOperators.BITWISE_BLEND, b[i], c[i], vmask).intoArray(r, i);
5195         }
5196 
5197         assertDoubleBroadcastArraysEquals(r, a, b, c, mask, Int512VectorTests::BITWISE_BLEND);
5198     }
5199 
5200     static int NEG(int a) {
5201         return (int)(-((int)a));
5202     }
5203 
5204     static int neg(int a) {
5205         return (int)(-((int)a));
5206     }
5207 
5208     @Test(dataProvider = "intUnaryOpProvider")
5209     static void NEGInt512VectorTests(IntFunction<int[]> fa) {
5210         int[] a = fa.apply(SPECIES.length());
5211         int[] r = fr.apply(SPECIES.length());
5212 
5213         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5214             for (int i = 0; i < a.length; i += SPECIES.length()) {
5215                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5216                 av.lanewise(VectorOperators.NEG).intoArray(r, i);
5217             }
5218         }
5219 
5220         assertArraysEquals(r, a, Int512VectorTests::NEG);
5221     }
5222 
5223     @Test(dataProvider = "intUnaryOpProvider")
5224     static void negInt512VectorTests(IntFunction<int[]> fa) {
5225         int[] a = fa.apply(SPECIES.length());
5226         int[] r = fr.apply(SPECIES.length());
5227 
5228         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5229             for (int i = 0; i < a.length; i += SPECIES.length()) {
5230                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5231                 av.neg().intoArray(r, i);
5232             }
5233         }
5234 
5235         assertArraysEquals(r, a, Int512VectorTests::neg);
5236     }
5237 
5238     @Test(dataProvider = "intUnaryOpMaskProvider")
5239     static void NEGMaskedInt512VectorTests(IntFunction<int[]> fa,
5240                                                 IntFunction<boolean[]> fm) {
5241         int[] a = fa.apply(SPECIES.length());
5242         int[] r = fr.apply(SPECIES.length());
5243         boolean[] mask = fm.apply(SPECIES.length());
5244         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5245 
5246         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5247             for (int i = 0; i < a.length; i += SPECIES.length()) {
5248                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5249                 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i);
5250             }
5251         }
5252 
5253         assertArraysEquals(r, a, mask, Int512VectorTests::NEG);
5254     }
5255 
5256     static int ABS(int a) {
5257         return (int)(Math.abs((int)a));
5258     }
5259 
5260     static int abs(int a) {
5261         return (int)(Math.abs((int)a));
5262     }
5263 
5264     @Test(dataProvider = "intUnaryOpProvider")
5265     static void ABSInt512VectorTests(IntFunction<int[]> fa) {
5266         int[] a = fa.apply(SPECIES.length());
5267         int[] r = fr.apply(SPECIES.length());
5268 
5269         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5270             for (int i = 0; i < a.length; i += SPECIES.length()) {
5271                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5272                 av.lanewise(VectorOperators.ABS).intoArray(r, i);
5273             }
5274         }
5275 
5276         assertArraysEquals(r, a, Int512VectorTests::ABS);
5277     }
5278 
5279     @Test(dataProvider = "intUnaryOpProvider")
5280     static void absInt512VectorTests(IntFunction<int[]> fa) {
5281         int[] a = fa.apply(SPECIES.length());
5282         int[] r = fr.apply(SPECIES.length());
5283 
5284         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5285             for (int i = 0; i < a.length; i += SPECIES.length()) {
5286                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5287                 av.abs().intoArray(r, i);
5288             }
5289         }
5290 
5291         assertArraysEquals(r, a, Int512VectorTests::abs);
5292     }
5293 
5294     @Test(dataProvider = "intUnaryOpMaskProvider")
5295     static void ABSMaskedInt512VectorTests(IntFunction<int[]> fa,
5296                                                 IntFunction<boolean[]> fm) {
5297         int[] a = fa.apply(SPECIES.length());
5298         int[] r = fr.apply(SPECIES.length());
5299         boolean[] mask = fm.apply(SPECIES.length());
5300         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5301 
5302         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5303             for (int i = 0; i < a.length; i += SPECIES.length()) {
5304                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5305                 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i);
5306             }
5307         }
5308 
5309         assertArraysEquals(r, a, mask, Int512VectorTests::ABS);
5310     }
5311 
5312     static int NOT(int a) {
5313         return (int)(~((int)a));
5314     }
5315 
5316     static int not(int a) {
5317         return (int)(~((int)a));
5318     }
5319 
5320     @Test(dataProvider = "intUnaryOpProvider")
5321     static void NOTInt512VectorTests(IntFunction<int[]> fa) {
5322         int[] a = fa.apply(SPECIES.length());
5323         int[] r = fr.apply(SPECIES.length());
5324 
5325         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5326             for (int i = 0; i < a.length; i += SPECIES.length()) {
5327                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5328                 av.lanewise(VectorOperators.NOT).intoArray(r, i);
5329             }
5330         }
5331 
5332         assertArraysEquals(r, a, Int512VectorTests::NOT);
5333     }
5334 
5335     @Test(dataProvider = "intUnaryOpProvider")
5336     static void notInt512VectorTests(IntFunction<int[]> fa) {
5337         int[] a = fa.apply(SPECIES.length());
5338         int[] r = fr.apply(SPECIES.length());
5339 
5340         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5341             for (int i = 0; i < a.length; i += SPECIES.length()) {
5342                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5343                 av.not().intoArray(r, i);
5344             }
5345         }
5346 
5347         assertArraysEquals(r, a, Int512VectorTests::not);
5348     }
5349 
5350     @Test(dataProvider = "intUnaryOpMaskProvider")
5351     static void NOTMaskedInt512VectorTests(IntFunction<int[]> fa,
5352                                                 IntFunction<boolean[]> fm) {
5353         int[] a = fa.apply(SPECIES.length());
5354         int[] r = fr.apply(SPECIES.length());
5355         boolean[] mask = fm.apply(SPECIES.length());
5356         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5357 
5358         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5359             for (int i = 0; i < a.length; i += SPECIES.length()) {
5360                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5361                 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i);
5362             }
5363         }
5364 
5365         assertArraysEquals(r, a, mask, Int512VectorTests::NOT);
5366     }
5367 
5368     static int ZOMO(int a) {
5369         return (int)((a==0?0:-1));
5370     }
5371 
5372     @Test(dataProvider = "intUnaryOpProvider")
5373     static void ZOMOInt512VectorTests(IntFunction<int[]> fa) {
5374         int[] a = fa.apply(SPECIES.length());
5375         int[] r = fr.apply(SPECIES.length());
5376 
5377         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5378             for (int i = 0; i < a.length; i += SPECIES.length()) {
5379                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5380                 av.lanewise(VectorOperators.ZOMO).intoArray(r, i);
5381             }
5382         }
5383 
5384         assertArraysEquals(r, a, Int512VectorTests::ZOMO);
5385     }
5386 
5387     @Test(dataProvider = "intUnaryOpMaskProvider")
5388     static void ZOMOMaskedInt512VectorTests(IntFunction<int[]> fa,
5389                                                 IntFunction<boolean[]> fm) {
5390         int[] a = fa.apply(SPECIES.length());
5391         int[] r = fr.apply(SPECIES.length());
5392         boolean[] mask = fm.apply(SPECIES.length());
5393         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5394 
5395         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5396             for (int i = 0; i < a.length; i += SPECIES.length()) {
5397                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5398                 av.lanewise(VectorOperators.ZOMO, vmask).intoArray(r, i);
5399             }
5400         }
5401 
5402         assertArraysEquals(r, a, mask, Int512VectorTests::ZOMO);
5403     }
5404 
5405     static int BIT_COUNT(int a) {
5406         return (int)(Integer.bitCount(a));
5407     }
5408 
5409     @Test(dataProvider = "intUnaryOpProvider")
5410     static void BIT_COUNTInt512VectorTests(IntFunction<int[]> fa) {
5411         int[] a = fa.apply(SPECIES.length());
5412         int[] r = fr.apply(SPECIES.length());
5413 
5414         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5415             for (int i = 0; i < a.length; i += SPECIES.length()) {
5416                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5417                 av.lanewise(VectorOperators.BIT_COUNT).intoArray(r, i);
5418             }
5419         }
5420 
5421         assertArraysEquals(r, a, Int512VectorTests::BIT_COUNT);
5422     }
5423 
5424     @Test(dataProvider = "intUnaryOpMaskProvider")
5425     static void BIT_COUNTMaskedInt512VectorTests(IntFunction<int[]> fa,
5426                                                 IntFunction<boolean[]> fm) {
5427         int[] a = fa.apply(SPECIES.length());
5428         int[] r = fr.apply(SPECIES.length());
5429         boolean[] mask = fm.apply(SPECIES.length());
5430         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5431 
5432         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5433             for (int i = 0; i < a.length; i += SPECIES.length()) {
5434                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5435                 av.lanewise(VectorOperators.BIT_COUNT, vmask).intoArray(r, i);
5436             }
5437         }
5438 
5439         assertArraysEquals(r, a, mask, Int512VectorTests::BIT_COUNT);
5440     }
5441 
5442     static int TRAILING_ZEROS_COUNT(int a) {
5443         return (int)(TRAILING_ZEROS_COUNT_scalar(a));
5444     }
5445 
5446     @Test(dataProvider = "intUnaryOpProvider")
5447     static void TRAILING_ZEROS_COUNTInt512VectorTests(IntFunction<int[]> fa) {
5448         int[] a = fa.apply(SPECIES.length());
5449         int[] r = fr.apply(SPECIES.length());
5450 
5451         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5452             for (int i = 0; i < a.length; i += SPECIES.length()) {
5453                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5454                 av.lanewise(VectorOperators.TRAILING_ZEROS_COUNT).intoArray(r, i);
5455             }
5456         }
5457 
5458         assertArraysEquals(r, a, Int512VectorTests::TRAILING_ZEROS_COUNT);
5459     }
5460 
5461     @Test(dataProvider = "intUnaryOpMaskProvider")
5462     static void TRAILING_ZEROS_COUNTMaskedInt512VectorTests(IntFunction<int[]> fa,
5463                                                 IntFunction<boolean[]> fm) {
5464         int[] a = fa.apply(SPECIES.length());
5465         int[] r = fr.apply(SPECIES.length());
5466         boolean[] mask = fm.apply(SPECIES.length());
5467         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5468 
5469         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5470             for (int i = 0; i < a.length; i += SPECIES.length()) {
5471                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5472                 av.lanewise(VectorOperators.TRAILING_ZEROS_COUNT, vmask).intoArray(r, i);
5473             }
5474         }
5475 
5476         assertArraysEquals(r, a, mask, Int512VectorTests::TRAILING_ZEROS_COUNT);
5477     }
5478 
5479     static int LEADING_ZEROS_COUNT(int a) {
5480         return (int)(LEADING_ZEROS_COUNT_scalar(a));
5481     }
5482 
5483     @Test(dataProvider = "intUnaryOpProvider")
5484     static void LEADING_ZEROS_COUNTInt512VectorTests(IntFunction<int[]> fa) {
5485         int[] a = fa.apply(SPECIES.length());
5486         int[] r = fr.apply(SPECIES.length());
5487 
5488         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5489             for (int i = 0; i < a.length; i += SPECIES.length()) {
5490                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5491                 av.lanewise(VectorOperators.LEADING_ZEROS_COUNT).intoArray(r, i);
5492             }
5493         }
5494 
5495         assertArraysEquals(r, a, Int512VectorTests::LEADING_ZEROS_COUNT);
5496     }
5497 
5498     @Test(dataProvider = "intUnaryOpMaskProvider")
5499     static void LEADING_ZEROS_COUNTMaskedInt512VectorTests(IntFunction<int[]> fa,
5500                                                 IntFunction<boolean[]> fm) {
5501         int[] a = fa.apply(SPECIES.length());
5502         int[] r = fr.apply(SPECIES.length());
5503         boolean[] mask = fm.apply(SPECIES.length());
5504         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5505 
5506         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5507             for (int i = 0; i < a.length; i += SPECIES.length()) {
5508                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5509                 av.lanewise(VectorOperators.LEADING_ZEROS_COUNT, vmask).intoArray(r, i);
5510             }
5511         }
5512 
5513         assertArraysEquals(r, a, mask, Int512VectorTests::LEADING_ZEROS_COUNT);
5514     }
5515 
5516     static int REVERSE(int a) {
5517         return (int)(REVERSE_scalar(a));
5518     }
5519 
5520     @Test(dataProvider = "intUnaryOpProvider")
5521     static void REVERSEInt512VectorTests(IntFunction<int[]> fa) {
5522         int[] a = fa.apply(SPECIES.length());
5523         int[] r = fr.apply(SPECIES.length());
5524 
5525         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5526             for (int i = 0; i < a.length; i += SPECIES.length()) {
5527                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5528                 av.lanewise(VectorOperators.REVERSE).intoArray(r, i);
5529             }
5530         }
5531 
5532         assertArraysEquals(r, a, Int512VectorTests::REVERSE);
5533     }
5534 
5535     @Test(dataProvider = "intUnaryOpMaskProvider")
5536     static void REVERSEMaskedInt512VectorTests(IntFunction<int[]> fa,
5537                                                 IntFunction<boolean[]> fm) {
5538         int[] a = fa.apply(SPECIES.length());
5539         int[] r = fr.apply(SPECIES.length());
5540         boolean[] mask = fm.apply(SPECIES.length());
5541         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5542 
5543         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5544             for (int i = 0; i < a.length; i += SPECIES.length()) {
5545                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5546                 av.lanewise(VectorOperators.REVERSE, vmask).intoArray(r, i);
5547             }
5548         }
5549 
5550         assertArraysEquals(r, a, mask, Int512VectorTests::REVERSE);
5551     }
5552 
5553     static int REVERSE_BYTES(int a) {
5554         return (int)(Integer.reverseBytes(a));
5555     }
5556 
5557     @Test(dataProvider = "intUnaryOpProvider")
5558     static void REVERSE_BYTESInt512VectorTests(IntFunction<int[]> fa) {
5559         int[] a = fa.apply(SPECIES.length());
5560         int[] r = fr.apply(SPECIES.length());
5561 
5562         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5563             for (int i = 0; i < a.length; i += SPECIES.length()) {
5564                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5565                 av.lanewise(VectorOperators.REVERSE_BYTES).intoArray(r, i);
5566             }
5567         }
5568 
5569         assertArraysEquals(r, a, Int512VectorTests::REVERSE_BYTES);
5570     }
5571 
5572     @Test(dataProvider = "intUnaryOpMaskProvider")
5573     static void REVERSE_BYTESMaskedInt512VectorTests(IntFunction<int[]> fa,
5574                                                 IntFunction<boolean[]> fm) {
5575         int[] a = fa.apply(SPECIES.length());
5576         int[] r = fr.apply(SPECIES.length());
5577         boolean[] mask = fm.apply(SPECIES.length());
5578         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5579 
5580         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5581             for (int i = 0; i < a.length; i += SPECIES.length()) {
5582                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5583                 av.lanewise(VectorOperators.REVERSE_BYTES, vmask).intoArray(r, i);
5584             }
5585         }
5586 
5587         assertArraysEquals(r, a, mask, Int512VectorTests::REVERSE_BYTES);
5588     }
5589 
5590     @Test(dataProvider = "intCompareOpProvider")
5591     static void ltInt512VectorTestsBroadcastSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
5592         int[] a = fa.apply(SPECIES.length());
5593         int[] b = fb.apply(SPECIES.length());
5594 
5595         for (int i = 0; i < a.length; i += SPECIES.length()) {
5596             IntVector av = IntVector.fromArray(SPECIES, a, i);
5597             VectorMask<Integer> mv = av.lt(b[i]);
5598 
5599             // Check results as part of computation.
5600             for (int j = 0; j < SPECIES.length(); j++) {
5601                 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i]);
5602             }
5603         }
5604     }
5605 
5606     @Test(dataProvider = "intCompareOpProvider")
5607     static void eqInt512VectorTestsBroadcastMaskedSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb) {
5608         int[] a = fa.apply(SPECIES.length());
5609         int[] b = fb.apply(SPECIES.length());
5610 
5611         for (int i = 0; i < a.length; i += SPECIES.length()) {
5612             IntVector av = IntVector.fromArray(SPECIES, a, i);
5613             VectorMask<Integer> mv = av.eq(b[i]);
5614 
5615             // Check results as part of computation.
5616             for (int j = 0; j < SPECIES.length(); j++) {
5617                 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i]);
5618             }
5619         }
5620     }
5621 
5622     @Test(dataProvider = "intUnaryOpProvider")
5623     static void toIntArrayInt512VectorTestsSmokeTest(IntFunction<int[]> fa) {
5624         int[] a = fa.apply(SPECIES.length());
5625 
5626         for (int i = 0; i < a.length; i += SPECIES.length()) {
5627             IntVector av = IntVector.fromArray(SPECIES, a, i);
5628             int[] r = av.toIntArray();
5629             assertArraysEquals(r, a, i);
5630         }
5631     }
5632 
5633     @Test(dataProvider = "intUnaryOpProvider")
5634     static void toLongArrayInt512VectorTestsSmokeTest(IntFunction<int[]> fa) {
5635         int[] a = fa.apply(SPECIES.length());
5636 
5637         for (int i = 0; i < a.length; i += SPECIES.length()) {
5638             IntVector av = IntVector.fromArray(SPECIES, a, i);
5639             long[] r = av.toLongArray();
5640             assertArraysEquals(r, a, i);
5641         }
5642     }
5643 
5644     @Test(dataProvider = "intUnaryOpProvider")
5645     static void toDoubleArrayInt512VectorTestsSmokeTest(IntFunction<int[]> fa) {
5646         int[] a = fa.apply(SPECIES.length());
5647 
5648         for (int i = 0; i < a.length; i += SPECIES.length()) {
5649             IntVector av = IntVector.fromArray(SPECIES, a, i);
5650             double[] r = av.toDoubleArray();
5651             assertArraysEquals(r, a, i);
5652         }
5653     }
5654 
5655     @Test(dataProvider = "intUnaryOpProvider")
5656     static void toStringInt512VectorTestsSmokeTest(IntFunction<int[]> fa) {
5657         int[] a = fa.apply(SPECIES.length());
5658 
5659         for (int i = 0; i < a.length; i += SPECIES.length()) {
5660             IntVector av = IntVector.fromArray(SPECIES, a, i);
5661             String str = av.toString();
5662 
5663             int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
5664             Assert.assertTrue(str.equals(Arrays.toString(subarr)), "at index " + i + ", string should be = " + Arrays.toString(subarr) + ", but is = " + str);
5665         }
5666     }
5667 
5668     @Test(dataProvider = "intUnaryOpProvider")
5669     static void hashCodeInt512VectorTestsSmokeTest(IntFunction<int[]> fa) {
5670         int[] a = fa.apply(SPECIES.length());
5671 
5672         for (int i = 0; i < a.length; i += SPECIES.length()) {
5673             IntVector av = IntVector.fromArray(SPECIES, a, i);
5674             int hash = av.hashCode();
5675 
5676             int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
5677             int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr));
5678             Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash);
5679         }
5680     }
5681 
5682 
5683     static long ADDReduceLong(int[] a, int idx) {
5684         int res = 0;
5685         for (int i = idx; i < (idx + SPECIES.length()); i++) {
5686             res += a[i];
5687         }
5688 
5689         return (long)res;
5690     }
5691 
5692     static long ADDReduceAllLong(int[] a) {
5693         long res = 0;
5694         for (int i = 0; i < a.length; i += SPECIES.length()) {
5695             res += ADDReduceLong(a, i);
5696         }
5697 
5698         return res;
5699     }
5700 
5701     @Test(dataProvider = "intUnaryOpProvider")
5702     static void ADDReduceLongInt512VectorTests(IntFunction<int[]> fa) {
5703         int[] a = fa.apply(SPECIES.length());
5704         long[] r = lfr.apply(SPECIES.length());
5705         long ra = 0;
5706 
5707         for (int i = 0; i < a.length; i += SPECIES.length()) {
5708             IntVector av = IntVector.fromArray(SPECIES, a, i);
5709             r[i] = av.reduceLanesToLong(VectorOperators.ADD);
5710         }
5711 
5712         ra = 0;
5713         for (int i = 0; i < a.length; i ++) {
5714             ra += r[i];
5715         }
5716 
5717         assertReductionLongArraysEquals(r, ra, a,
5718                 Int512VectorTests::ADDReduceLong, Int512VectorTests::ADDReduceAllLong);
5719     }
5720 
5721     static long ADDReduceLongMasked(int[] a, int idx, boolean[] mask) {
5722         int res = 0;
5723         for (int i = idx; i < (idx + SPECIES.length()); i++) {
5724             if(mask[i % SPECIES.length()])
5725                 res += a[i];
5726         }
5727 
5728         return (long)res;
5729     }
5730 
5731     static long ADDReduceAllLongMasked(int[] a, boolean[] mask) {
5732         long res = 0;
5733         for (int i = 0; i < a.length; i += SPECIES.length()) {
5734             res += ADDReduceLongMasked(a, i, mask);
5735         }
5736 
5737         return res;
5738     }
5739 
5740     @Test(dataProvider = "intUnaryOpMaskProvider")
5741     static void ADDReduceLongInt512VectorTestsMasked(IntFunction<int[]> fa, IntFunction<boolean[]> fm) {
5742         int[] a = fa.apply(SPECIES.length());
5743         long[] r = lfr.apply(SPECIES.length());
5744         boolean[] mask = fm.apply(SPECIES.length());
5745         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5746         long ra = 0;
5747 
5748         for (int i = 0; i < a.length; i += SPECIES.length()) {
5749             IntVector av = IntVector.fromArray(SPECIES, a, i);
5750             r[i] = av.reduceLanesToLong(VectorOperators.ADD, vmask);
5751         }
5752 
5753         ra = 0;
5754         for (int i = 0; i < a.length; i ++) {
5755             ra += r[i];
5756         }
5757 
5758         assertReductionLongArraysEqualsMasked(r, ra, a, mask,
5759                 Int512VectorTests::ADDReduceLongMasked, Int512VectorTests::ADDReduceAllLongMasked);
5760     }
5761 
5762     @Test(dataProvider = "intUnaryOpProvider")
5763     static void BroadcastLongInt512VectorTestsSmokeTest(IntFunction<int[]> fa) {
5764         int[] a = fa.apply(SPECIES.length());
5765         int[] r = new int[a.length];
5766 
5767         for (int i = 0; i < a.length; i += SPECIES.length()) {
5768             IntVector.broadcast(SPECIES, (long)a[i]).intoArray(r, i);
5769         }
5770         assertBroadcastArraysEquals(r, a);
5771     }
5772 
5773     @Test(dataProvider = "intBinaryOpMaskProvider")
5774     static void blendInt512VectorTestsBroadcastLongSmokeTest(IntFunction<int[]> fa, IntFunction<int[]> fb,
5775                                           IntFunction<boolean[]> fm) {
5776         int[] a = fa.apply(SPECIES.length());
5777         int[] b = fb.apply(SPECIES.length());
5778         int[] r = fr.apply(SPECIES.length());
5779         boolean[] mask = fm.apply(SPECIES.length());
5780         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5781 
5782         for (int ic = 0; ic < INVOC_COUNT; ic++) {
5783             for (int i = 0; i < a.length; i += SPECIES.length()) {
5784                 IntVector av = IntVector.fromArray(SPECIES, a, i);
5785                 av.blend((long)b[i], vmask).intoArray(r, i);
5786             }
5787         }
5788         assertBroadcastLongArraysEquals(r, a, b, mask, Int512VectorTests::blend);
5789     }
5790 
5791 
5792     @Test(dataProvider = "intUnaryOpShuffleProvider")
5793     static void SelectFromInt512VectorTests(IntFunction<int[]> fa,
5794                                            BiFunction<Integer,Integer,int[]> fs) {
5795         int[] a = fa.apply(SPECIES.length());
5796         int[] order = fs.apply(a.length, SPECIES.length());
5797         int[] r = fr.apply(SPECIES.length());
5798 
5799         for (int i = 0; i < a.length; i += SPECIES.length()) {
5800             IntVector av = IntVector.fromArray(SPECIES, a, i);
5801             IntVector bv = IntVector.fromArray(SPECIES, order, i);
5802             bv.selectFrom(av).intoArray(r, i);
5803         }
5804 
5805         assertSelectFromArraysEquals(r, a, order, SPECIES.length());
5806     }
5807 
5808     @Test(dataProvider = "intUnaryOpShuffleMaskProvider")
5809     static void SelectFromInt512VectorTestsMaskedSmokeTest(IntFunction<int[]> fa,
5810                                                            BiFunction<Integer,Integer,int[]> fs,
5811                                                            IntFunction<boolean[]> fm) {
5812         int[] a = fa.apply(SPECIES.length());
5813         int[] order = fs.apply(a.length, SPECIES.length());
5814         int[] r = fr.apply(SPECIES.length());
5815         boolean[] mask = fm.apply(SPECIES.length());
5816         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5817 
5818         for (int i = 0; i < a.length; i += SPECIES.length()) {
5819             IntVector av = IntVector.fromArray(SPECIES, a, i);
5820             IntVector bv = IntVector.fromArray(SPECIES, order, i);
5821             bv.selectFrom(av, vmask).intoArray(r, i);
5822         }
5823 
5824         assertSelectFromArraysEquals(r, a, order, mask, SPECIES.length());
5825     }
5826 
5827     @Test(dataProvider = "shuffleProvider")
5828     static void shuffleMiscellaneousInt512VectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fs) {
5829         int[] a = fs.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length());
5830 
5831         for (int i = 0; i < a.length; i += SPECIES.length()) {
5832             var shuffle = VectorShuffle.fromArray(SPECIES, a, i);
5833             int hash = shuffle.hashCode();
5834             int length = shuffle.length();
5835 
5836             int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
5837             int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr));
5838             Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash);
5839             Assert.assertEquals(length, SPECIES.length());
5840         }
5841     }
5842 
5843     @Test(dataProvider = "shuffleProvider")
5844     static void shuffleToStringInt512VectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fs) {
5845         int[] a = fs.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length());
5846 
5847         for (int i = 0; i < a.length; i += SPECIES.length()) {
5848             var shuffle = VectorShuffle.fromArray(SPECIES, a, i);
5849             String str = shuffle.toString();
5850 
5851             int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
5852             Assert.assertTrue(str.equals("Shuffle" + Arrays.toString(subarr)), "at index " +
5853                 i + ", string should be = " + Arrays.toString(subarr) + ", but is = " + str);
5854         }
5855     }
5856 
5857     @Test(dataProvider = "shuffleCompareOpProvider")
5858     static void shuffleEqualsInt512VectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fa, BiFunction<Integer,Integer,int[]> fb) {
5859         int[] a = fa.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length());
5860         int[] b = fb.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length());
5861 
5862         for (int i = 0; i < a.length; i += SPECIES.length()) {
5863             var av = VectorShuffle.fromArray(SPECIES, a, i);
5864             var bv = VectorShuffle.fromArray(SPECIES, b, i);
5865             boolean eq = av.equals(bv);
5866             int to = i + SPECIES.length();
5867             Assert.assertEquals(eq, Arrays.equals(a, i, to, b, i, to));
5868         }
5869     }
5870 
5871     @Test(dataProvider = "maskCompareOpProvider")
5872     static void maskEqualsInt512VectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) {
5873         boolean[] a = fa.apply(SPECIES.length());
5874         boolean[] b = fb.apply(SPECIES.length());
5875 
5876         for (int i = 0; i < a.length; i += SPECIES.length()) {
5877             var av = SPECIES.loadMask(a, i);
5878             var bv = SPECIES.loadMask(b, i);
5879             boolean equals = av.equals(bv);
5880             int to = i + SPECIES.length();
5881             Assert.assertEquals(equals, Arrays.equals(a, i, to, b, i, to));
5882         }
5883     }
5884 
5885     static boolean beq(boolean a, boolean b) {
5886         return (a == b);
5887     }
5888 
5889     @Test(dataProvider = "maskCompareOpProvider")
5890     static void maskEqInt512VectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) {
5891         boolean[] a = fa.apply(SPECIES.length());
5892         boolean[] b = fb.apply(SPECIES.length());
5893         boolean[] r = new boolean[a.length];
5894 
5895         for (int i = 0; i < a.length; i += SPECIES.length()) {
5896             var av = SPECIES.loadMask(a, i);
5897             var bv = SPECIES.loadMask(b, i);
5898             var cv = av.eq(bv);
5899             cv.intoArray(r, i);
5900         }
5901         assertArraysEquals(r, a, b, Int512VectorTests::beq);
5902     }
5903 
5904     @Test(dataProvider = "maskProvider")
5905     static void maskHashCodeInt512VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5906         boolean[] a = fa.apply(SPECIES.length());
5907 
5908         for (int i = 0; i < a.length; i += SPECIES.length()) {
5909             var vmask = SPECIES.loadMask(a, i);
5910             int hash = vmask.hashCode();
5911 
5912             boolean subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
5913             int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr));
5914             Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash);
5915         }
5916     }
5917 
5918     static int maskTrueCount(boolean[] a, int idx) {
5919         int trueCount = 0;
5920         for (int i = idx; i < idx + SPECIES.length(); i++) {
5921             trueCount += a[i] ? 1 : 0;
5922         }
5923         return trueCount;
5924     }
5925 
5926     @Test(dataProvider = "maskProvider")
5927     static void maskTrueCountInt512VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5928         boolean[] a = fa.apply(SPECIES.length());
5929         int[] r = new int[a.length];
5930 
5931         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5932             for (int i = 0; i < a.length; i += SPECIES.length()) {
5933                 var vmask = SPECIES.loadMask(a, i);
5934                 r[i] = vmask.trueCount();
5935             }
5936         }
5937 
5938         assertMaskReductionArraysEquals(r, a, Int512VectorTests::maskTrueCount);
5939     }
5940 
5941     static int maskLastTrue(boolean[] a, int idx) {
5942         int i = idx + SPECIES.length() - 1;
5943         for (; i >= idx; i--) {
5944             if (a[i]) {
5945                 break;
5946             }
5947         }
5948         return i - idx;
5949     }
5950 
5951     @Test(dataProvider = "maskProvider")
5952     static void maskLastTrueInt512VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5953         boolean[] a = fa.apply(SPECIES.length());
5954         int[] r = new int[a.length];
5955 
5956         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5957             for (int i = 0; i < a.length; i += SPECIES.length()) {
5958                 var vmask = SPECIES.loadMask(a, i);
5959                 r[i] = vmask.lastTrue();
5960             }
5961         }
5962 
5963         assertMaskReductionArraysEquals(r, a, Int512VectorTests::maskLastTrue);
5964     }
5965 
5966     static int maskFirstTrue(boolean[] a, int idx) {
5967         int i = idx;
5968         for (; i < idx + SPECIES.length(); i++) {
5969             if (a[i]) {
5970                 break;
5971             }
5972         }
5973         return i - idx;
5974     }
5975 
5976     @Test(dataProvider = "maskProvider")
5977     static void maskFirstTrueInt512VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5978         boolean[] a = fa.apply(SPECIES.length());
5979         int[] r = new int[a.length];
5980 
5981         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5982             for (int i = 0; i < a.length; i += SPECIES.length()) {
5983                 var vmask = SPECIES.loadMask(a, i);
5984                 r[i] = vmask.firstTrue();
5985             }
5986         }
5987 
5988         assertMaskReductionArraysEquals(r, a, Int512VectorTests::maskFirstTrue);
5989     }
5990 
5991     @Test(dataProvider = "maskProvider")
5992     static void maskCompressInt512VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
5993         int trueCount = 0;
5994         boolean[] a = fa.apply(SPECIES.length());
5995 
5996         for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5997             for (int i = 0; i < a.length; i += SPECIES.length()) {
5998                 var vmask = SPECIES.loadMask(a, i);
5999                 trueCount = vmask.trueCount();
6000                 var rmask = vmask.compress();
6001                 for (int j = 0; j < SPECIES.length(); j++)  {
6002                     Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
6003                 }
6004             }
6005         }
6006     }
6007 
6008     @DataProvider
6009     public static Object[][] longMaskProvider() {
6010         return new Object[][]{
6011                 {0xFFFFFFFFFFFFFFFFL},
6012                 {0x0000000000000000L},
6013                 {0x5555555555555555L},
6014                 {0x0123456789abcdefL},
6015         };
6016     }
6017 
6018     @Test(dataProvider = "longMaskProvider")
6019     static void maskFromToLongInt512VectorTestsSmokeTest(long inputLong) {
6020         var vmask = VectorMask.fromLong(SPECIES, inputLong);
6021         long outputLong = vmask.toLong();
6022         Assert.assertEquals(outputLong, (inputLong & (((0xFFFFFFFFFFFFFFFFL >>> (64 - SPECIES.length()))))));
6023     }
6024 
6025     @DataProvider
6026     public static Object[][] offsetProvider() {
6027         return new Object[][]{
6028                 {0},
6029                 {-1},
6030                 {+1},
6031                 {+2},
6032                 {-2},
6033         };
6034     }
6035 
6036     @Test(dataProvider = "offsetProvider")
6037     static void indexInRangeInt512VectorTestsSmokeTest(int offset) {
6038         int limit = SPECIES.length() * BUFFER_REPS;
6039         for (int i = 0; i < limit; i += SPECIES.length()) {
6040             var actualMask = SPECIES.indexInRange(i + offset, limit);
6041             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
6042             assert(actualMask.equals(expectedMask));
6043             for (int j = 0; j < SPECIES.length(); j++)  {
6044                 int index = i + j + offset;
6045                 Assert.assertEquals(actualMask.laneIsSet(j), index >= 0 && index < limit);
6046             }
6047         }
6048     }
6049 
6050     @Test(dataProvider = "offsetProvider")
6051     static void indexInRangeLongInt512VectorTestsSmokeTest(int offset) {
6052         long limit = SPECIES.length() * BUFFER_REPS;
6053         for (long i = 0; i < limit; i += SPECIES.length()) {
6054             var actualMask = SPECIES.indexInRange(i + offset, limit);
6055             var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
6056             assert(actualMask.equals(expectedMask));
6057             for (int j = 0; j < SPECIES.length(); j++)  {
6058                 long index = i + j + offset;
6059                 Assert.assertEquals(actualMask.laneIsSet(j), index >= 0 && index < limit);
6060             }
6061         }
6062     }
6063 
6064     @DataProvider
6065     public static Object[][] lengthProvider() {
6066         return new Object[][]{
6067                 {0},
6068                 {1},
6069                 {32},
6070                 {37},
6071                 {1024},
6072                 {1024+1},
6073                 {1024+5},
6074         };
6075     }
6076 
6077     @Test(dataProvider = "lengthProvider")
6078     static void loopBoundInt512VectorTestsSmokeTest(int length) {
6079         int actualLoopBound = SPECIES.loopBound(length);
6080         int expectedLoopBound = length - Math.floorMod(length, SPECIES.length());
6081         Assert.assertEquals(actualLoopBound, expectedLoopBound);
6082     }
6083 
6084     @Test(dataProvider = "lengthProvider")
6085     static void loopBoundLongInt512VectorTestsSmokeTest(int _length) {
6086         long length = _length;
6087         long actualLoopBound = SPECIES.loopBound(length);
6088         long expectedLoopBound = length - Math.floorMod(length, SPECIES.length());
6089         Assert.assertEquals(actualLoopBound, expectedLoopBound);
6090     }
6091 
6092     @Test
6093     static void ElementSizeInt512VectorTestsSmokeTest() {
6094         IntVector av = IntVector.zero(SPECIES);
6095         int elsize = av.elementSize();
6096         Assert.assertEquals(elsize, Integer.SIZE);
6097     }
6098 
6099     @Test
6100     static void VectorShapeInt512VectorTestsSmokeTest() {
6101         IntVector av = IntVector.zero(SPECIES);
6102         VectorShape vsh = av.shape();
6103         assert(vsh.equals(VectorShape.S_512_BIT));
6104     }
6105 
6106     @Test
6107     static void ShapeWithLanesInt512VectorTestsSmokeTest() {
6108         IntVector av = IntVector.zero(SPECIES);
6109         VectorShape vsh = av.shape();
6110         VectorSpecies species = vsh.withLanes(int.class);
6111         assert(species.equals(SPECIES));
6112     }
6113 
6114     @Test
6115     static void ElementTypeInt512VectorTestsSmokeTest() {
6116         IntVector av = IntVector.zero(SPECIES);
6117         assert(av.species().elementType() == int.class);
6118     }
6119 
6120     @Test
6121     static void SpeciesElementSizeInt512VectorTestsSmokeTest() {
6122         IntVector av = IntVector.zero(SPECIES);
6123         assert(av.species().elementSize() == Integer.SIZE);
6124     }
6125 
6126     @Test
6127     static void VectorTypeInt512VectorTestsSmokeTest() {
6128         IntVector av = IntVector.zero(SPECIES);
6129         assert(av.species().vectorType() == av.getClass());
6130     }
6131 
6132     @Test
6133     static void WithLanesInt512VectorTestsSmokeTest() {
6134         IntVector av = IntVector.zero(SPECIES);
6135         VectorSpecies species = av.species().withLanes(int.class);
6136         assert(species.equals(SPECIES));
6137     }
6138 
6139     @Test
6140     static void WithShapeInt512VectorTestsSmokeTest() {
6141         IntVector av = IntVector.zero(SPECIES);
6142         VectorShape vsh = av.shape();
6143         VectorSpecies species = av.species().withShape(vsh);
6144         assert(species.equals(SPECIES));
6145     }
6146 
6147     @Test
6148     static void MaskAllTrueInt512VectorTestsSmokeTest() {
6149         for (int ic = 0; ic < INVOC_COUNT; ic++) {
6150           Assert.assertEquals(SPECIES.maskAll(true).toLong(), -1L >>> (64 - SPECIES.length()));
6151         }
6152     }
6153 }