1 /*
   2  * Copyright (c) 2018, 2021, 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 $vectorteststype$
  28  */
  29 
  30 #warn This file is preprocessed before being compiled
  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 #if[Byte]
  40 import jdk.incubator.vector.ByteVector;
  41 #end[Byte]
  42 #if[Float]
  43 import jdk.incubator.vector.FloatVector;
  44 #end[Float]
  45 #if[Int]
  46 import jdk.incubator.vector.IntVector;
  47 #end[Int]
  48 #if[Double]
  49 import jdk.incubator.vector.DoubleVector;
  50 #end[Double]
  51 #if[Short]
  52 import jdk.incubator.vector.ShortVector;
  53 #end[Short]
  54 #if[Long]
  55 import jdk.incubator.vector.LongVector;
  56 #end[Long]
  57 
  58 import org.testng.Assert;
  59 import org.testng.annotations.DataProvider;
  60 import org.testng.annotations.Test;
  61 
  62 import java.lang.Integer;
  63 import java.util.List;
  64 import java.util.Arrays;
  65 import java.util.function.BiFunction;
  66 import java.util.function.IntFunction;
  67 import java.util.Objects;
  68 import java.util.stream.Collectors;
  69 import java.util.stream.Stream;
  70 
  71 @Test
  72 public class $vectorteststype$ extends AbstractVectorTest {
  73 
  74 #if[MaxBit]
  75     static final VectorSpecies<$Wideboxtype$> SPECIES =
  76                 $Type$Vector.SPECIES_MAX;
  77 #else[MaxBit]
  78     static final VectorSpecies<$Wideboxtype$> SPECIES =
  79                 $Type$Vector.SPECIES_$bits$;
  80 #end[MaxBit]
  81 
  82     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  83 
  84 #if[MaxBit]
  85     static VectorShape getMaxBit() {
  86         return VectorShape.S_Max_BIT;
  87     }
  88 
  89     private static final int Max = 256;  // juts so we can do N/$bits$
  90 #end[MaxBit]
  91 
  92     static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / $bits$);
  93 
  94     interface FUnOp {
  95         $type$ apply($type$ a);
  96     }
  97 
  98     static void assertArraysEquals($type$[] r, $type$[] a, FUnOp f) {
  99         int i = 0;
 100         try {
 101             for (; i < a.length; i++) {
 102                 Assert.assertEquals(r[i], f.apply(a[i]));
 103             }
 104         } catch (AssertionError e) {
 105             Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
 106         }
 107     }
 108 
 109     interface FUnArrayOp {
 110         $type$[] apply($type$ a);
 111     }
 112 
 113     static void assertArraysEquals($type$[] r, $type$[] a, FUnArrayOp f) {
 114         int i = 0;
 115         try {
 116             for (; i < a.length; i += SPECIES.length()) {
 117                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 118                   f.apply(a[i]));
 119             }
 120         } catch (AssertionError e) {
 121             $type$[] ref = f.apply(a[i]);
 122             $type$[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 123             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 124               + ", res: " + Arrays.toString(res)
 125               + "), at index #" + i);
 126         }
 127     }
 128 
 129     static void assertArraysEquals($type$[] r, $type$[] a, boolean[] mask, FUnOp f) {
 130         int i = 0;
 131         try {
 132             for (; i < a.length; i++) {
 133                 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]);
 134             }
 135         } catch (AssertionError e) {
 136             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()]);
 137         }
 138     }
 139 
 140     interface FReductionOp {
 141         $type$ apply($type$[] a, int idx);
 142     }
 143 
 144     interface FReductionAllOp {
 145         $type$ apply($type$[] a);
 146     }
 147 
 148     static void assertReductionArraysEquals($type$[] r, $type$ rc, $type$[] a,
 149                                             FReductionOp f, FReductionAllOp fa) {
 150         int i = 0;
 151         try {
 152             Assert.assertEquals(rc, fa.apply(a));
 153             for (; i < a.length; i += SPECIES.length()) {
 154                 Assert.assertEquals(r[i], f.apply(a, i));
 155             }
 156         } catch (AssertionError e) {
 157             Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!");
 158             Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
 159         }
 160     }
 161 
 162     interface FReductionMaskedOp {
 163         $type$ apply($type$[] a, int idx, boolean[] mask);
 164     }
 165 
 166     interface FReductionAllMaskedOp {
 167         $type$ apply($type$[] a, boolean[] mask);
 168     }
 169 
 170     static void assertReductionArraysEqualsMasked($type$[] r, $type$ rc, $type$[] a, boolean[] mask,
 171                                             FReductionMaskedOp f, FReductionAllMaskedOp fa) {
 172         int i = 0;
 173         try {
 174             Assert.assertEquals(rc, fa.apply(a, mask));
 175             for (; i < a.length; i += SPECIES.length()) {
 176                 Assert.assertEquals(r[i], f.apply(a, i, mask));
 177             }
 178         } catch (AssertionError e) {
 179             Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
 180             Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
 181         }
 182     }
 183 
 184 #if[!Long]
 185     interface FReductionOpLong {
 186         long apply($type$[] a, int idx);
 187     }
 188 
 189     interface FReductionAllOpLong {
 190         long apply($type$[] a);
 191     }
 192 
 193     static void assertReductionLongArraysEquals(long[] r, long rc, $type$[] a,
 194                                             FReductionOpLong f, FReductionAllOpLong fa) {
 195         int i = 0;
 196         try {
 197             Assert.assertEquals(rc, fa.apply(a));
 198             for (; i < a.length; i += SPECIES.length()) {
 199                 Assert.assertEquals(r[i], f.apply(a, i));
 200             }
 201         } catch (AssertionError e) {
 202             Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!");
 203             Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
 204         }
 205     }
 206 
 207     interface FReductionMaskedOpLong {
 208         long apply($type$[] a, int idx, boolean[] mask);
 209     }
 210 
 211     interface FReductionAllMaskedOpLong {
 212         long apply($type$[] a, boolean[] mask);
 213     }
 214 
 215     static void assertReductionLongArraysEqualsMasked(long[] r, long rc, $type$[] a, boolean[] mask,
 216                                             FReductionMaskedOpLong f, FReductionAllMaskedOpLong fa) {
 217         int i = 0;
 218         try {
 219             Assert.assertEquals(rc, fa.apply(a, mask));
 220             for (; i < a.length; i += SPECIES.length()) {
 221                 Assert.assertEquals(r[i], f.apply(a, i, mask));
 222             }
 223         } catch (AssertionError e) {
 224             Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
 225             Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
 226         }
 227     }
 228 #end[!Long]
 229 
 230     interface FBoolReductionOp {
 231         boolean apply(boolean[] a, int idx);
 232     }
 233 
 234     static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReductionOp f) {
 235         int i = 0;
 236         try {
 237             for (; i < a.length; i += SPECIES.length()) {
 238                 Assert.assertEquals(r[i], f.apply(a, i));
 239             }
 240         } catch (AssertionError e) {
 241             Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
 242         }
 243     }
 244 
 245     interface FMaskReductionOp {
 246         int apply(boolean[] a, int idx);
 247     }
 248 
 249     static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) {
 250         int i = 0;
 251         try {
 252             for (; i < a.length; i += SPECIES.length()) {
 253                 Assert.assertEquals(r[i], f.apply(a, i));
 254             }
 255         } catch (AssertionError e) {
 256             Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
 257         }
 258     }
 259 
 260     static void assertInsertArraysEquals($type$[] r, $type$[] a, $type$ element, int index) {
 261         int i = 0;
 262         try {
 263             for (; i < a.length; i += 1) {
 264                 if(i%SPECIES.length() == index) {
 265                     Assert.assertEquals(r[i], element);
 266                 } else {
 267                     Assert.assertEquals(r[i], a[i]);
 268                 }
 269             }
 270         } catch (AssertionError e) {
 271             if (i%SPECIES.length() == index) {
 272                 Assert.assertEquals(r[i], element, "at index #" + i);
 273             } else {
 274                 Assert.assertEquals(r[i], a[i], "at index #" + i);
 275             }
 276         }
 277     }
 278 
 279     static void assertRearrangeArraysEquals($type$[] r, $type$[] a, int[] order, int vector_len) {
 280         int i = 0, j = 0;
 281         try {
 282             for (; i < a.length; i += vector_len) {
 283                 for (j = 0; j < vector_len; j++) {
 284                     Assert.assertEquals(r[i+j], a[i+order[i+j]]);
 285                 }
 286             }
 287         } catch (AssertionError e) {
 288             int idx = i + j;
 289             Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
 290         }
 291     }
 292 
 293     static void assertcompressArraysEquals($type$[] r, $type$[] a, boolean[] m, int vector_len) {
 294         int i = 0, j = 0, k = 0;
 295         try {
 296             for (; i < a.length; i += vector_len) {
 297                 k = 0;
 298                 for (j = 0; j < vector_len; j++) {
 299                     if (m[(i + j) % SPECIES.length()]) {
 300                         Assert.assertEquals(r[i + k], a[i + j]);
 301                         k++;
 302                     }
 303                 }
 304                 for (; k < vector_len; k++) {
 305                     Assert.assertEquals(r[i + k], ($type$)0);
 306                 }
 307             }
 308         } catch (AssertionError e) {
 309             int idx = i + k;
 310             if (m[(i + j) % SPECIES.length()]) {
 311                 Assert.assertEquals(r[idx], a[i + j], "at index #" + idx);
 312             } else {
 313                 Assert.assertEquals(r[idx], ($type$)0, "at index #" + idx);
 314             }
 315         }
 316     }
 317 
 318     static void assertexpandArraysEquals($type$[] r, $type$[] a, boolean[] m, int vector_len) {
 319         int i = 0, j = 0, k = 0;
 320         try {
 321             for (; i < a.length; i += vector_len) {
 322                 k = 0;
 323                 for (j = 0; j < vector_len; j++) {
 324                     if (m[(i + j) % SPECIES.length()]) {
 325                         Assert.assertEquals(r[i + j], a[i + k]);
 326                         k++;
 327                     } else {
 328                         Assert.assertEquals(r[i + j], ($type$)0);
 329                     }
 330                 }
 331             }
 332         } catch (AssertionError e) {
 333             int idx = i + j;
 334             if (m[idx % SPECIES.length()]) {
 335                 Assert.assertEquals(r[idx], a[i + k], "at index #" + idx);
 336             } else {
 337                 Assert.assertEquals(r[idx], ($type$)0, "at index #" + idx);
 338             }
 339         }
 340     }
 341 
 342     static void assertSelectFromArraysEquals($type$[] r, $type$[] a, $type$[] order, int vector_len) {
 343         int i = 0, j = 0;
 344         try {
 345             for (; i < a.length; i += vector_len) {
 346                 for (j = 0; j < vector_len; j++) {
 347                     Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]);
 348                 }
 349             }
 350         } catch (AssertionError e) {
 351             int idx = i + j;
 352             Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]);
 353         }
 354     }
 355 
 356     static void assertRearrangeArraysEquals($type$[] r, $type$[] a, int[] order, boolean[] mask, int vector_len) {
 357         int i = 0, j = 0;
 358         try {
 359             for (; i < a.length; i += vector_len) {
 360                 for (j = 0; j < vector_len; j++) {
 361                     if (mask[j % SPECIES.length()])
 362                          Assert.assertEquals(r[i+j], a[i+order[i+j]]);
 363                     else
 364                          Assert.assertEquals(r[i+j], ($type$)0);
 365                 }
 366             }
 367         } catch (AssertionError e) {
 368             int idx = i + j;
 369             if (mask[j % SPECIES.length()])
 370                 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
 371             else
 372                 Assert.assertEquals(r[i+j], ($type$)0, "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
 373         }
 374     }
 375 
 376     static void assertSelectFromArraysEquals($type$[] r, $type$[] a, $type$[] order, boolean[] mask, int vector_len) {
 377         int i = 0, j = 0;
 378         try {
 379             for (; i < a.length; i += vector_len) {
 380                 for (j = 0; j < vector_len; j++) {
 381                     if (mask[j % SPECIES.length()])
 382                          Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]);
 383                     else
 384                          Assert.assertEquals(r[i+j], ($type$)0);
 385                 }
 386             }
 387         } catch (AssertionError e) {
 388             int idx = i + j;
 389             if (mask[j % SPECIES.length()])
 390                 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()]);
 391             else
 392                 Assert.assertEquals(r[i+j], ($type$)0, "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
 393         }
 394     }
 395 
 396     static void assertBroadcastArraysEquals($type$[] r, $type$[] a) {
 397         int i = 0;
 398         for (; i < a.length; i += SPECIES.length()) {
 399             int idx = i;
 400             for (int j = idx; j < (idx + SPECIES.length()); j++)
 401                 a[j]=a[idx];
 402         }
 403 
 404         try {
 405             for (i = 0; i < a.length; i++) {
 406                 Assert.assertEquals(r[i], a[i]);
 407             }
 408         } catch (AssertionError e) {
 409             Assert.assertEquals(r[i], a[i], "at index #" + i + ", input = " + a[i]);
 410         }
 411     }
 412 
 413     interface FBinOp {
 414         $type$ apply($type$ a, $type$ b);
 415     }
 416 
 417     interface FBinMaskOp {
 418         $type$ apply($type$ a, $type$ b, boolean m);
 419 
 420         static FBinMaskOp lift(FBinOp f) {
 421             return (a, b, m) -> m ? f.apply(a, b) : a;
 422         }
 423     }
 424 
 425     static void assertArraysEquals($type$[] r, $type$[] a, $type$[] b, FBinOp f) {
 426         int i = 0;
 427         try {
 428             for (; i < a.length; i++) {
 429                 Assert.assertEquals(r[i], f.apply(a[i], b[i]));
 430             }
 431         } catch (AssertionError e) {
 432             Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i);
 433         }
 434     }
 435 
 436     static void assertBroadcastArraysEquals($type$[] r, $type$[] a, $type$[] b, FBinOp f) {
 437         int i = 0;
 438         try {
 439             for (; i < a.length; i++) {
 440                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]));
 441             }
 442         } catch (AssertionError e) {
 443             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]),
 444                                 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i);
 445         }
 446     }
 447 
 448     static void assertBroadcastLongArraysEquals($type$[] r, $type$[] a, $type$[] b, FBinOp f) {
 449         int i = 0;
 450         try {
 451             for (; i < a.length; i++) {
 452                 Assert.assertEquals(r[i], f.apply(a[i], ($type$)((long)b[(i / SPECIES.length()) * SPECIES.length()])));
 453             }
 454         } catch (AssertionError e) {
 455             Assert.assertEquals(r[i], f.apply(a[i], ($type$)((long)b[(i / SPECIES.length()) * SPECIES.length()])),
 456                                 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i);
 457         }
 458     }
 459 
 460     static void assertArraysEquals($type$[] r, $type$[] a, $type$[] b, boolean[] mask, FBinOp f) {
 461         assertArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
 462     }
 463 
 464     static void assertArraysEquals($type$[] r, $type$[] a, $type$[] b, boolean[] mask, FBinMaskOp f) {
 465         int i = 0;
 466         try {
 467             for (; i < a.length; i++) {
 468                 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]));
 469             }
 470         } catch (AssertionError err) {
 471             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()]);
 472         }
 473     }
 474 
 475     static void assertBroadcastArraysEquals($type$[] r, $type$[] a, $type$[] b, boolean[] mask, FBinOp f) {
 476         assertBroadcastArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
 477     }
 478 
 479     static void assertBroadcastArraysEquals($type$[] r, $type$[] a, $type$[] b, boolean[] mask, FBinMaskOp f) {
 480         int i = 0;
 481         try {
 482             for (; i < a.length; i++) {
 483                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]));
 484             }
 485         } catch (AssertionError err) {
 486             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
 487                                 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] +
 488                                 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
 489                                 mask[i % SPECIES.length()]);
 490         }
 491     }
 492 
 493     static void assertBroadcastLongArraysEquals($type$[] r, $type$[] a, $type$[] b, boolean[] mask, FBinOp f) {
 494         assertBroadcastLongArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
 495     }
 496 
 497     static void assertBroadcastLongArraysEquals($type$[] r, $type$[] a, $type$[] b, boolean[] mask, FBinMaskOp f) {
 498         int i = 0;
 499         try {
 500             for (; i < a.length; i++) {
 501                 Assert.assertEquals(r[i], f.apply(a[i], ($type$)((long)b[(i / SPECIES.length()) * SPECIES.length()]), mask[i % SPECIES.length()]));
 502             }
 503         } catch (AssertionError err) {
 504             Assert.assertEquals(r[i], f.apply(a[i], ($type$)((long)b[(i / SPECIES.length()) * SPECIES.length()]),
 505                                 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] +
 506                                 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
 507                                 mask[i % SPECIES.length()]);
 508         }
 509     }
 510 
 511     static void assertShiftArraysEquals($type$[] r, $type$[] a, $type$[] b, FBinOp f) {
 512         int i = 0;
 513         int j = 0;
 514         try {
 515             for (; j < a.length; j += SPECIES.length()) {
 516                 for (i = 0; i < SPECIES.length(); i++) {
 517                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]));
 518                 }
 519             }
 520         } catch (AssertionError e) {
 521             Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j);
 522         }
 523     }
 524 
 525     static void assertShiftArraysEquals($type$[] r, $type$[] a, $type$[] b, boolean[] mask, FBinOp f) {
 526         assertShiftArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
 527     }
 528 
 529     static void assertShiftArraysEquals($type$[] r, $type$[] a, $type$[] b, boolean[] mask, FBinMaskOp f) {
 530         int i = 0;
 531         int j = 0;
 532         try {
 533             for (; j < a.length; j += SPECIES.length()) {
 534                 for (i = 0; i < SPECIES.length(); i++) {
 535                     Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i]));
 536                 }
 537             }
 538         } catch (AssertionError err) {
 539             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]);
 540         }
 541     }
 542 
 543     interface FTernOp {
 544         $type$ apply($type$ a, $type$ b, $type$ c);
 545     }
 546 
 547     interface FTernMaskOp {
 548         $type$ apply($type$ a, $type$ b, $type$ c, boolean m);
 549 
 550         static FTernMaskOp lift(FTernOp f) {
 551             return (a, b, c, m) -> m ? f.apply(a, b, c) : a;
 552         }
 553     }
 554 
 555     static void assertArraysEquals($type$[] r, $type$[] a, $type$[] b, $type$[] c, FTernOp f) {
 556         int i = 0;
 557         try {
 558             for (; i < a.length; i++) {
 559                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]));
 560             }
 561         } catch (AssertionError e) {
 562             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
 563         }
 564     }
 565 
 566     static void assertArraysEquals($type$[] r, $type$[] a, $type$[] b, $type$[] c, boolean[] mask, FTernOp f) {
 567         assertArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
 568     }
 569 
 570     static void assertArraysEquals($type$[] r, $type$[] a, $type$[] b, $type$[] c, boolean[] mask, FTernMaskOp 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], mask[i % SPECIES.length()]));
 575             }
 576         } catch (AssertionError err) {
 577             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = "
 578               + b[i] + ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]);
 579         }
 580     }
 581 
 582     static void assertBroadcastArraysEquals($type$[] r, $type$[] a, $type$[] b, $type$[] c, FTernOp f) {
 583         int i = 0;
 584         try {
 585             for (; i < a.length; i++) {
 586                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()]));
 587             }
 588         } catch (AssertionError e) {
 589             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" +
 590                                 i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " +
 591                                 c[(i / SPECIES.length()) * SPECIES.length()]);
 592         }
 593     }
 594 
 595     static void assertAltBroadcastArraysEquals($type$[] r, $type$[] a, $type$[] b, $type$[] c, FTernOp f) {
 596         int i = 0;
 597         try {
 598             for (; i < a.length; i++) {
 599                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i]));
 600             }
 601         } catch (AssertionError e) {
 602             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i]), "at index #" +
 603                                 i + ", input1 = " + a[i] + ", input2 = " +
 604                                 b[(i / SPECIES.length()) * SPECIES.length()] + ",  input3 = " + c[i]);
 605         }
 606     }
 607 
 608     static void assertBroadcastArraysEquals($type$[] r, $type$[] a, $type$[] b, $type$[] c, boolean[] mask,
 609                                             FTernOp f) {
 610         assertBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
 611     }
 612 
 613     static void assertBroadcastArraysEquals($type$[] r, $type$[] a, $type$[] b, $type$[] c, boolean[] mask,
 614                                             FTernMaskOp f) {
 615         int i = 0;
 616         try {
 617             for (; i < a.length; i++) {
 618                 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()],
 619                                     mask[i % SPECIES.length()]));
 620             }
 621         } catch (AssertionError err) {
 622             Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()],
 623                                 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " +
 624                                 b[i] + ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
 625                                 mask[i % SPECIES.length()]);
 626         }
 627     }
 628 
 629     static void assertAltBroadcastArraysEquals($type$[] r, $type$[] a, $type$[] b, $type$[] c, boolean[] mask,
 630                                             FTernOp f) {
 631         assertAltBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
 632     }
 633 
 634     static void assertAltBroadcastArraysEquals($type$[] r, $type$[] a, $type$[] b, $type$[] c, boolean[] mask,
 635                                             FTernMaskOp f) {
 636         int i = 0;
 637         try {
 638             for (; i < a.length; i++) {
 639                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i],
 640                                     mask[i % SPECIES.length()]));
 641             }
 642         } catch (AssertionError err) {
 643             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i],
 644                                 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] +
 645                                 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] +
 646                                 ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]);
 647         }
 648     }
 649 
 650     static void assertDoubleBroadcastArraysEquals($type$[] r, $type$[] a, $type$[] b, $type$[] c, FTernOp 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()],
 655                                     c[(i / SPECIES.length()) * SPECIES.length()]));
 656             }
 657         } catch (AssertionError e) {
 658             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
 659                                 c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" + i + ", input1 = " + a[i]
 660                                 + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", input3 = " +
 661                                 c[(i / SPECIES.length()) * SPECIES.length()]);
 662         }
 663     }
 664 
 665     static void assertDoubleBroadcastArraysEquals($type$[] r, $type$[] a, $type$[] b, $type$[] c, boolean[] mask,
 666                                                   FTernOp f) {
 667         assertDoubleBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
 668     }
 669 
 670     static void assertDoubleBroadcastArraysEquals($type$[] r, $type$[] a, $type$[] b, $type$[] c, boolean[] mask,
 671                                                   FTernMaskOp f) {
 672         int i = 0;
 673         try {
 674             for (; i < a.length; i++) {
 675                 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
 676                                     c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]));
 677             }
 678         } catch (AssertionError err) {
 679             Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
 680                                 c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]), "at index #"
 681                                 + i + ", input1 = " + a[i] + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] +
 682                                 ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
 683                                 mask[i % SPECIES.length()]);
 684         }
 685     }
 686 
 687 
 688 #if[FP]
 689     static boolean isWithin1Ulp($type$ actual, $type$ expected) {
 690         if ($Type$.isNaN(expected) && !$Type$.isNaN(actual)) {
 691             return false;
 692         } else if (!$Type$.isNaN(expected) && $Type$.isNaN(actual)) {
 693             return false;
 694         }
 695 
 696         $type$ low = Math.nextDown(expected);
 697         $type$ high = Math.nextUp(expected);
 698 
 699         if ($Type$.compare(low, expected) > 0) {
 700             return false;
 701         }
 702 
 703         if ($Type$.compare(high, expected) < 0) {
 704             return false;
 705         }
 706 
 707         return true;
 708     }
 709 
 710     static void assertArraysEqualsWithinOneUlp($type$[] r, $type$[] a, FUnOp mathf, FUnOp strictmathf) {
 711         int i = 0;
 712         try {
 713             // Check that result is within 1 ulp of strict math or equivalent to math implementation.
 714             for (; i < a.length; i++) {
 715                 Assert.assertTrue($Type$.compare(r[i], mathf.apply(a[i])) == 0 ||
 716                                     isWithin1Ulp(r[i], strictmathf.apply(a[i])));
 717             }
 718         } catch (AssertionError e) {
 719             Assert.assertTrue($Type$.compare(r[i], mathf.apply(a[i])) == 0, "at index #" + i + ", input = " + a[i] + ", actual = " + r[i] + ", expected = " + mathf.apply(a[i]));
 720             Assert.assertTrue(isWithin1Ulp(r[i], strictmathf.apply(a[i])), "at index #" + i + ", input = " + a[i] + ", actual = " + r[i] + ", expected (within 1 ulp) = " + strictmathf.apply(a[i]));
 721         }
 722     }
 723 
 724     static void assertArraysEqualsWithinOneUlp($type$[] r, $type$[] a, $type$[] b, FBinOp mathf, FBinOp strictmathf) {
 725         int i = 0;
 726         try {
 727             // Check that result is within 1 ulp of strict math or equivalent to math implementation.
 728             for (; i < a.length; i++) {
 729                 Assert.assertTrue($Type$.compare(r[i], mathf.apply(a[i], b[i])) == 0 ||
 730                                     isWithin1Ulp(r[i], strictmathf.apply(a[i], b[i])));
 731             }
 732         } catch (AssertionError e) {
 733             Assert.assertTrue($Type$.compare(r[i], mathf.apply(a[i], b[i])) == 0, "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", actual = " + r[i] + ", expected = " + mathf.apply(a[i], b[i]));
 734             Assert.assertTrue(isWithin1Ulp(r[i], strictmathf.apply(a[i], b[i])), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", actual = " + r[i] + ", expected (within 1 ulp) = " + strictmathf.apply(a[i], b[i]));
 735         }
 736     }
 737 
 738     static void assertBroadcastArraysEqualsWithinOneUlp($type$[] r, $type$[] a, $type$[] b,
 739                                                         FBinOp mathf, FBinOp strictmathf) {
 740         int i = 0;
 741         try {
 742             // Check that result is within 1 ulp of strict math or equivalent to math implementation.
 743             for (; i < a.length; i++) {
 744                 Assert.assertTrue($Type$.compare(r[i],
 745                                   mathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])) == 0 ||
 746                                   isWithin1Ulp(r[i],
 747                                   strictmathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])));
 748             }
 749         } catch (AssertionError e) {
 750             Assert.assertTrue($Type$.compare(r[i],
 751                               mathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])) == 0,
 752                               "at index #" + i + ", input1 = " + a[i] + ", input2 = " +
 753                               b[(i / SPECIES.length()) * SPECIES.length()] + ", actual = " + r[i] +
 754                               ", expected = " + mathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]));
 755             Assert.assertTrue(isWithin1Ulp(r[i],
 756                               strictmathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])),
 757                              "at index #" + i + ", input1 = " + a[i] + ", input2 = " +
 758                              b[(i / SPECIES.length()) * SPECIES.length()] + ", actual = " + r[i] +
 759                              ", expected (within 1 ulp) = " + strictmathf.apply(a[i],
 760                              b[(i / SPECIES.length()) * SPECIES.length()]));
 761         }
 762     }
 763 #end[FP]
 764 
 765     interface FBinArrayOp {
 766         $type$ apply($type$[] a, int b);
 767     }
 768 
 769     static void assertArraysEquals($type$[] r, $type$[] a, FBinArrayOp f) {
 770         int i = 0;
 771         try {
 772             for (; i < a.length; i++) {
 773                 Assert.assertEquals(r[i], f.apply(a, i));
 774             }
 775         } catch (AssertionError e) {
 776             Assert.assertEquals(r[i], f.apply(a,i), "at index #" + i);
 777         }
 778     }
 779 
 780     interface FGatherScatterOp {
 781         $type$[] apply($type$[] a, int ix, int[] b, int iy);
 782     }
 783 
 784     static void assertArraysEquals($type$[] r, $type$[] a, int[] b, FGatherScatterOp f) {
 785         int i = 0;
 786         try {
 787             for (; i < a.length; i += SPECIES.length()) {
 788                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 789                   f.apply(a, i, b, i));
 790             }
 791         } catch (AssertionError e) {
 792             $type$[] ref = f.apply(a, i, b, i);
 793             $type$[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 794             Assert.assertEquals(res, ref,
 795               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 796               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 797               + ", b: "
 798               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 799               + " at index #" + i);
 800         }
 801     }
 802 
 803     interface FGatherMaskedOp {
 804         $type$[] apply($type$[] a, int ix, boolean[] mask, int[] b, int iy);
 805     }
 806 
 807     interface FScatterMaskedOp {
 808         $type$[] apply($type$[] r, $type$[] a, int ix, boolean[] mask, int[] b, int iy);
 809     }
 810 
 811     static void assertArraysEquals($type$[] r, $type$[] a, int[] b, boolean[] mask, FGatherMaskedOp f) {
 812         int i = 0;
 813         try {
 814             for (; i < a.length; i += SPECIES.length()) {
 815                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 816                   f.apply(a, i, mask, b, i));
 817             }
 818         } catch (AssertionError e) {
 819             $type$[] ref = f.apply(a, i, mask, b, i);
 820             $type$[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 821             Assert.assertEquals(res, ref,
 822               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 823               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 824               + ", b: "
 825               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 826               + ", mask: "
 827               + Arrays.toString(mask)
 828               + " at index #" + i);
 829         }
 830     }
 831 
 832     static void assertArraysEquals($type$[] r, $type$[] a, int[] b, boolean[] mask, FScatterMaskedOp f) {
 833         int i = 0;
 834         try {
 835             for (; i < a.length; i += SPECIES.length()) {
 836                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 837                   f.apply(r, a, i, mask, b, i));
 838             }
 839         } catch (AssertionError e) {
 840             $type$[] ref = f.apply(r, a, i, mask, b, i);
 841             $type$[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 842             Assert.assertEquals(res, ref,
 843               "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
 844               + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
 845               + ", b: "
 846               + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
 847               + ", r: "
 848               + Arrays.toString(Arrays.copyOfRange(r, i, i+SPECIES.length()))
 849               + ", mask: "
 850               + Arrays.toString(mask)
 851               + " at index #" + i);
 852         }
 853     }
 854 
 855     interface FLaneOp {
 856         $type$[] apply($type$[] a, int origin, int idx);
 857     }
 858 
 859     static void assertArraysEquals($type$[] r, $type$[] a, int origin, FLaneOp f) {
 860         int i = 0;
 861         try {
 862             for (; i < a.length; i += SPECIES.length()) {
 863                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 864                   f.apply(a, origin, i));
 865             }
 866         } catch (AssertionError e) {
 867             $type$[] ref = f.apply(a, origin, i);
 868             $type$[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 869             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 870               + ", res: " + Arrays.toString(res)
 871               + "), at index #" + i);
 872         }
 873     }
 874 
 875     interface FLaneBop {
 876         $type$[] apply($type$[] a, $type$[] b, int origin, int idx);
 877     }
 878 
 879     static void assertArraysEquals($type$[] r, $type$[] a, $type$[] b, int origin, FLaneBop f) {
 880         int i = 0;
 881         try {
 882             for (; i < a.length; i += SPECIES.length()) {
 883                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 884                   f.apply(a, b, origin, i));
 885             }
 886         } catch (AssertionError e) {
 887             $type$[] ref = f.apply(a, b, origin, i);
 888             $type$[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 889             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 890               + ", res: " + Arrays.toString(res)
 891               + "), at index #" + i
 892               + ", at origin #" + origin);
 893         }
 894     }
 895 
 896     interface FLaneMaskedBop {
 897         $type$[] apply($type$[] a, $type$[] b, int origin, boolean[] mask, int idx);
 898     }
 899 
 900     static void assertArraysEquals($type$[] r, $type$[] a, $type$[] b, int origin, boolean[] mask, FLaneMaskedBop f) {
 901         int i = 0;
 902         try {
 903             for (; i < a.length; i += SPECIES.length()) {
 904                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 905                   f.apply(a, b, origin, mask, i));
 906             }
 907         } catch (AssertionError e) {
 908             $type$[] ref = f.apply(a, b, origin, mask, i);
 909             $type$[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 910             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 911               + ", res: " + Arrays.toString(res)
 912               + "), at index #" + i
 913               + ", at origin #" + origin);
 914         }
 915     }
 916 
 917     interface FLanePartBop {
 918         $type$[] apply($type$[] a, $type$[] b, int origin, int part, int idx);
 919     }
 920 
 921     static void assertArraysEquals($type$[] r, $type$[] a, $type$[] b, int origin, int part, FLanePartBop f) {
 922         int i = 0;
 923         try {
 924             for (; i < a.length; i += SPECIES.length()) {
 925                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 926                   f.apply(a, b, origin, part, i));
 927             }
 928         } catch (AssertionError e) {
 929             $type$[] ref = f.apply(a, b, origin, part, i);
 930             $type$[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 931             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 932               + ", res: " + Arrays.toString(res)
 933               + "), at index #" + i
 934               + ", at origin #" + origin
 935               + ", with part #" + part);
 936         }
 937     }
 938 
 939     interface FLanePartMaskedBop {
 940         $type$[] apply($type$[] a, $type$[] b, int origin, int part, boolean[] mask, int idx);
 941     }
 942 
 943     static void assertArraysEquals($type$[] r, $type$[] a, $type$[] b, int origin, int part, boolean[] mask, FLanePartMaskedBop f) {
 944         int i = 0;
 945         try {
 946             for (; i < a.length; i += SPECIES.length()) {
 947                 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
 948                   f.apply(a, b, origin, part, mask, i));
 949             }
 950         } catch (AssertionError e) {
 951             $type$[] ref = f.apply(a, b, origin, part, mask, i);
 952             $type$[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
 953             Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
 954               + ", res: " + Arrays.toString(res)
 955               + "), at index #" + i
 956               + ", at origin #" + origin
 957               + ", with part #" + part);
 958         }
 959     }
 960 
 961 #if[!Int]
 962 #if[!byteOrShort]
 963     static int intCornerCaseValue(int i) {
 964         switch(i % 5) {
 965             case 0:
 966                 return Integer.MAX_VALUE;
 967             case 1:
 968                 return Integer.MIN_VALUE;
 969             case 2:
 970                 return Integer.MIN_VALUE;
 971             case 3:
 972                 return Integer.MAX_VALUE;
 973             default:
 974                 return (int)0;
 975         }
 976     }
 977 
 978     static final List<IntFunction<$type$[]>> INT_$TYPE$_GENERATORS = List.of(
 979             withToString("$type$[-i * 5]", (int s) -> {
 980                 return fill(s * BUFFER_REPS,
 981                             i -> ($type$)(-i * 5));
 982             }),
 983             withToString("$type$[i * 5]", (int s) -> {
 984                 return fill(s * BUFFER_REPS,
 985                             i -> ($type$)(i * 5));
 986             }),
 987             withToString("$type$[i + 1]", (int s) -> {
 988                 return fill(s * BUFFER_REPS,
 989                             i -> ((($type$)(i + 1) == 0) ? 1 : ($type$)(i + 1)));
 990             }),
 991             withToString("$type$[intCornerCaseValue(i)]", (int s) -> {
 992                 return fill(s * BUFFER_REPS,
 993                             i -> ($type$)intCornerCaseValue(i));
 994             })
 995     );
 996 #end[!byteOrShort]
 997 #end[!Int]
 998 
 999     static void assertArraysEquals(int[] r, $type$[] a, int offs) {
1000         int i = 0;
1001         try {
1002             for (; i < r.length; i++) {
1003                 Assert.assertEquals(r[i], (int)(a[i+offs]));
1004             }
1005         } catch (AssertionError e) {
1006             Assert.assertEquals(r[i], (int)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
1007         }
1008     }
1009 
1010 #if[!Long]
1011 #if[FP]
1012     static long longCornerCaseValue(int i) {
1013         switch(i % 5) {
1014             case 0:
1015                 return Long.MAX_VALUE;
1016             case 1:
1017                 return Long.MIN_VALUE;
1018             case 2:
1019                 return Long.MIN_VALUE;
1020             case 3:
1021                 return Long.MAX_VALUE;
1022             default:
1023                 return (long)0;
1024         }
1025     }
1026 
1027     static final List<IntFunction<$type$[]>> LONG_$TYPE$_GENERATORS = List.of(
1028             withToString("$type$[-i * 5]", (int s) -> {
1029                 return fill(s * BUFFER_REPS,
1030                             i -> ($type$)(-i * 5));
1031             }),
1032             withToString("$type$[i * 5]", (int s) -> {
1033                 return fill(s * BUFFER_REPS,
1034                             i -> ($type$)(i * 5));
1035             }),
1036             withToString("$type$[i + 1]", (int s) -> {
1037                 return fill(s * BUFFER_REPS,
1038                             i -> ((($type$)(i + 1) == 0) ? 1 : ($type$)(i + 1)));
1039             }),
1040             withToString("$type$[cornerCaseValue(i)]", (int s) -> {
1041                 return fill(s * BUFFER_REPS,
1042                             i -> ($type$)longCornerCaseValue(i));
1043             })
1044     );
1045 #end[FP]
1046 #end[!Long]
1047 
1048 #if[byte]
1049     static void assertArraysEquals($type$[] r, $type$[] a, int offs) {
1050         int i = 0;
1051         try {
1052             for (; i < r.length; i++) {
1053                 Assert.assertEquals(r[i], (long)(a[i+offs]));
1054             }
1055         } catch (AssertionError e) {
1056             Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
1057         }
1058     }
1059 #end[byte]
1060 
1061     static void assertArraysEquals(long[] r, $type$[] a, int offs) {
1062         int i = 0;
1063         try {
1064             for (; i < r.length; i++) {
1065                 Assert.assertEquals(r[i], (long)(a[i+offs]));
1066             }
1067         } catch (AssertionError e) {
1068             Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
1069         }
1070     }
1071 
1072 #if[!Double]
1073     static void assertArraysEquals(double[] r, $type$[] a, int offs) {
1074         int i = 0;
1075         try {
1076             for (; i < r.length; i++) {
1077                 Assert.assertEquals(r[i], (double)(a[i+offs]));
1078             }
1079         } catch (AssertionError e) {
1080             Assert.assertEquals(r[i], (double)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
1081         }
1082     }
1083 #end[!Double]
1084 
1085 
1086     static $bitstype$ bits($type$ e) {
1087         return {#if[FP]? $Type$.$type$To$Bitstype$Bits(e): e};
1088     }
1089 
1090     static final List<IntFunction<$type$[]>> $TYPE$_GENERATORS = List.of(
1091             withToString("$type$[-i * 5]", (int s) -> {
1092                 return fill(s * BUFFER_REPS,
1093                             i -> ($type$)(-i * 5));
1094             }),
1095             withToString("$type$[i * 5]", (int s) -> {
1096                 return fill(s * BUFFER_REPS,
1097                             i -> ($type$)(i * 5));
1098             }),
1099             withToString("$type$[i + 1]", (int s) -> {
1100                 return fill(s * BUFFER_REPS,
1101                             i -> ((($type$)(i + 1) == 0) ? 1 : ($type$)(i + 1)));
1102             }),
1103             withToString("$type$[cornerCaseValue(i)]", (int s) -> {
1104                 return fill(s * BUFFER_REPS,
1105                             i -> cornerCaseValue(i));
1106             })
1107     );
1108 
1109     // Create combinations of pairs
1110     // @@@ Might be sensitive to order e.g. div by 0
1111     static final List<List<IntFunction<$type$[]>>> $TYPE$_GENERATOR_PAIRS =
1112         Stream.of($TYPE$_GENERATORS.get(0)).
1113                 flatMap(fa -> $TYPE$_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
1114                 collect(Collectors.toList());
1115 
1116     @DataProvider
1117     public Object[][] boolUnaryOpProvider() {
1118         return BOOL_ARRAY_GENERATORS.stream().
1119                 map(f -> new Object[]{f}).
1120                 toArray(Object[][]::new);
1121     }
1122 
1123     static final List<List<IntFunction<$type$[]>>> $TYPE$_GENERATOR_TRIPLES =
1124         $TYPE$_GENERATOR_PAIRS.stream().
1125                 flatMap(pair -> $TYPE$_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))).
1126                 collect(Collectors.toList());
1127 
1128     @DataProvider
1129     public Object[][] $type$BinaryOpProvider() {
1130         return $TYPE$_GENERATOR_PAIRS.stream().map(List::toArray).
1131                 toArray(Object[][]::new);
1132     }
1133 
1134     @DataProvider
1135     public Object[][] $type$IndexedOpProvider() {
1136         return $TYPE$_GENERATOR_PAIRS.stream().map(List::toArray).
1137                 toArray(Object[][]::new);
1138     }
1139 
1140     @DataProvider
1141     public Object[][] $type$BinaryOpMaskProvider() {
1142         return BOOLEAN_MASK_GENERATORS.stream().
1143                 flatMap(fm -> $TYPE$_GENERATOR_PAIRS.stream().map(lfa -> {
1144                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1145                 })).
1146                 toArray(Object[][]::new);
1147     }
1148 
1149     @DataProvider
1150     public Object[][] $type$TernaryOpProvider() {
1151         return $TYPE$_GENERATOR_TRIPLES.stream().map(List::toArray).
1152                 toArray(Object[][]::new);
1153     }
1154 
1155     @DataProvider
1156     public Object[][] $type$TernaryOpMaskProvider() {
1157         return BOOLEAN_MASK_GENERATORS.stream().
1158                 flatMap(fm -> $TYPE$_GENERATOR_TRIPLES.stream().map(lfa -> {
1159                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1160                 })).
1161                 toArray(Object[][]::new);
1162     }
1163 
1164     @DataProvider
1165     public Object[][] $type$UnaryOpProvider() {
1166         return $TYPE$_GENERATORS.stream().
1167                 map(f -> new Object[]{f}).
1168                 toArray(Object[][]::new);
1169     }
1170 
1171     @DataProvider
1172     public Object[][] $type$UnaryOpMaskProvider() {
1173         return BOOLEAN_MASK_GENERATORS.stream().
1174                 flatMap(fm -> $TYPE$_GENERATORS.stream().map(fa -> {
1175                     return new Object[] {fa, fm};
1176                 })).
1177                 toArray(Object[][]::new);
1178     }
1179 
1180 #if[!Int]
1181 #if[!byteOrShort]
1182     @DataProvider
1183     public Object[][] $type$toIntUnaryOpProvider() {
1184         return INT_$TYPE$_GENERATORS.stream().
1185                 map(f -> new Object[]{f}).
1186                 toArray(Object[][]::new);
1187     }
1188 #end[!byteOrShort]
1189 #end[!Int]
1190 
1191 #if[FP]
1192     @DataProvider
1193     public Object[][] $type$toLongUnaryOpProvider() {
1194         return LONG_$TYPE$_GENERATORS.stream().
1195                 map(f -> new Object[]{f}).
1196                 toArray(Object[][]::new);
1197     }
1198 #end[FP]
1199 
1200     @DataProvider
1201     public Object[][] maskProvider() {
1202         return BOOLEAN_MASK_GENERATORS.stream().
1203                 map(f -> new Object[]{f}).
1204                 toArray(Object[][]::new);
1205     }
1206 
1207     @DataProvider
1208     public Object[][] maskCompareOpProvider() {
1209         return BOOLEAN_MASK_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
1210                 toArray(Object[][]::new);
1211     }
1212 
1213     @DataProvider
1214     public Object[][] shuffleProvider() {
1215         return INT_SHUFFLE_GENERATORS.stream().
1216                 map(f -> new Object[]{f}).
1217                 toArray(Object[][]::new);
1218     }
1219 
1220     @DataProvider
1221     public Object[][] shuffleCompareOpProvider() {
1222         return INT_SHUFFLE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
1223                 toArray(Object[][]::new);
1224     }
1225 
1226     @DataProvider
1227     public Object[][] $type$UnaryOpShuffleProvider() {
1228         return INT_SHUFFLE_GENERATORS.stream().
1229                 flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
1230                     return new Object[] {fa, fs};
1231                 })).
1232                 toArray(Object[][]::new);
1233     }
1234 
1235     @DataProvider
1236     public Object[][] $type$UnaryOpShuffleMaskProvider() {
1237         return BOOLEAN_MASK_GENERATORS.stream().
1238                 flatMap(fm -> INT_SHUFFLE_GENERATORS.stream().
1239                     flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
1240                         return new Object[] {fa, fs, fm};
1241                 }))).
1242                 toArray(Object[][]::new);
1243     }
1244 
1245 #if[!Int]
1246     static final List<BiFunction<Integer,Integer,$type$[]>> $TYPE$_SHUFFLE_GENERATORS = List.of(
1247             withToStringBi("shuffle[random]", (Integer l, Integer m) -> {
1248                 $type$[] a = new $type$[l];
1249 #if[ByteMax]
1250                 int upper = Math.min(Byte.MAX_VALUE + 1, m);
1251 #else[ByteMax]
1252                 int upper = m;
1253 #end[ByteMax]
1254                 for (int i = 0; i < 1; i++) {
1255                     a[i] = ($type$)RAND.nextInt(upper);
1256                 }
1257                 return a;
1258             })
1259     );
1260 
1261     @DataProvider
1262     public Object[][] $type$UnaryOpSelectFromProvider() {
1263         return $TYPE$_SHUFFLE_GENERATORS.stream().
1264                 flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
1265                     return new Object[] {fa, fs};
1266                 })).
1267                 toArray(Object[][]::new);
1268     }
1269 
1270     @DataProvider
1271     public Object[][] $type$UnaryOpSelectFromMaskProvider() {
1272         return BOOLEAN_MASK_GENERATORS.stream().
1273                 flatMap(fm -> $TYPE$_SHUFFLE_GENERATORS.stream().
1274                     flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
1275                         return new Object[] {fa, fs, fm};
1276                 }))).
1277                 toArray(Object[][]::new);
1278     }
1279 
1280 #end[!Int]
1281 
1282     static final List<IntFunction<$type$[]>> $TYPE$_COMPARE_GENERATORS = List.of(
1283             withToString("$type$[i]", (int s) -> {
1284                 return fill(s * BUFFER_REPS,
1285                             i -> ($type$)i);
1286             }),
1287             withToString("$type$[i - length / 2]", (int s) -> {
1288                 return fill(s * BUFFER_REPS,
1289                             i -> ($type$)(i - (s * BUFFER_REPS / 2)));
1290             }),
1291             withToString("$type$[i + 1]", (int s) -> {
1292                 return fill(s * BUFFER_REPS,
1293                             i -> ($type$)(i + 1));
1294             }),
1295             withToString("$type$[i - 2]", (int s) -> {
1296                 return fill(s * BUFFER_REPS,
1297                             i -> ($type$)(i - 2));
1298             }),
1299             withToString("$type$[zigZag(i)]", (int s) -> {
1300                 return fill(s * BUFFER_REPS,
1301                             i -> i%3 == 0 ? ($type$)i : (i%3 == 1 ? ($type$)(i + 1) : ($type$)(i - 2)));
1302             }),
1303             withToString("$type$[cornerCaseValue(i)]", (int s) -> {
1304                 return fill(s * BUFFER_REPS,
1305                             i -> cornerCaseValue(i));
1306             })
1307     );
1308 
1309     static final List<List<IntFunction<$type$[]>>> $TYPE$_TEST_GENERATOR_ARGS =
1310         $TYPE$_COMPARE_GENERATORS.stream().
1311                 map(fa -> List.of(fa)).
1312                 collect(Collectors.toList());
1313 
1314     @DataProvider
1315     public Object[][] $type$TestOpProvider() {
1316         return $TYPE$_TEST_GENERATOR_ARGS.stream().map(List::toArray).
1317                 toArray(Object[][]::new);
1318     }
1319 
1320     @DataProvider
1321     public Object[][] $type$TestOpMaskProvider() {
1322         return BOOLEAN_MASK_GENERATORS.stream().
1323                 flatMap(fm -> $TYPE$_TEST_GENERATOR_ARGS.stream().map(lfa -> {
1324                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1325                 })).
1326                 toArray(Object[][]::new);
1327     }
1328 
1329     static final List<List<IntFunction<$type$[]>>> $TYPE$_COMPARE_GENERATOR_PAIRS =
1330         $TYPE$_COMPARE_GENERATORS.stream().
1331                 flatMap(fa -> $TYPE$_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))).
1332                 collect(Collectors.toList());
1333 
1334     @DataProvider
1335     public Object[][] $type$CompareOpProvider() {
1336         return $TYPE$_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
1337                 toArray(Object[][]::new);
1338     }
1339 
1340     @DataProvider
1341     public Object[][] $type$CompareOpMaskProvider() {
1342         return BOOLEAN_MASK_GENERATORS.stream().
1343                 flatMap(fm -> $TYPE$_COMPARE_GENERATOR_PAIRS.stream().map(lfa -> {
1344                     return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1345                 })).
1346                 toArray(Object[][]::new);
1347     }
1348 
1349     interface To$Type$F {
1350         $type$ apply(int i);
1351     }
1352 
1353     static $type$[] fill(int s , To$Type$F f) {
1354         return fill(new $type$[s], f);
1355     }
1356 
1357     static $type$[] fill($type$[] a, To$Type$F f) {
1358         for (int i = 0; i < a.length; i++) {
1359             a[i] = f.apply(i);
1360         }
1361         return a;
1362     }
1363 
1364     static $type$ cornerCaseValue(int i) {
1365 #if[FP]
1366         switch(i % 7) {
1367             case 0:
1368                 return $Wideboxtype$.MAX_VALUE;
1369             case 1:
1370                 return $Wideboxtype$.MIN_VALUE;
1371             case 2:
1372                 return $Wideboxtype$.NEGATIVE_INFINITY;
1373             case 3:
1374                 return $Wideboxtype$.POSITIVE_INFINITY;
1375             case 4:
1376                 return $Wideboxtype$.NaN;
1377             case 5:
1378                 return ($type$)0.0;
1379             default:
1380                 return ($type$)-0.0;
1381         }
1382 #else[FP]
1383         switch(i % 5) {
1384             case 0:
1385                 return $Wideboxtype$.MAX_VALUE;
1386             case 1:
1387                 return $Wideboxtype$.MIN_VALUE;
1388             case 2:
1389                 return $Wideboxtype$.MIN_VALUE;
1390             case 3:
1391                 return $Wideboxtype$.MAX_VALUE;
1392             default:
1393                 return ($type$)0;
1394         }
1395 #end[FP]
1396     }
1397 
1398     static $type$ get($type$[] a, int i) {
1399         return ($type$) a[i];
1400     }
1401 
1402     static final IntFunction<$type$[]> fr = (vl) -> {
1403         int length = BUFFER_REPS * vl;
1404         return new $type$[length];
1405     };
1406 
1407     static final IntFunction<boolean[]> fmr = (vl) -> {
1408         int length = BUFFER_REPS * vl;
1409         return new boolean[length];
1410     };
1411 
1412 #if[!Long]
1413     static final IntFunction<long[]> lfr = (vl) -> {
1414         int length = BUFFER_REPS * vl;
1415         return new long[length];
1416     };
1417 #end[!Long]
1418 
1419 #if[BITWISE]
1420     static void replaceZero($type$[] a, $type$ v) {
1421         for (int i = 0; i < a.length; i++) {
1422             if (a[i] == 0) {
1423                 a[i] = v;
1424             }
1425         }
1426     }
1427 
1428     static void replaceZero($type$[] a, boolean[] mask, $type$ v) {
1429         for (int i = 0; i < a.length; i++) {
1430             if (mask[i % mask.length] && a[i] == 0) {
1431                 a[i] = v;
1432             }
1433         }
1434     }
1435 
1436     static $type$ ROL_scalar($type$ a, $type$ b) {
1437 #if[intOrLong]
1438         return $Wideboxtype$.rotateLeft(a, ((int)b));
1439 #else[intOrLong]
1440 #if[short]
1441         return (short)(((((short)a) & 0xFFFF) << (b & 15)) | ((((short)a) & 0xFFFF) >>> (16 - (b & 15))));
1442 #else[short]
1443         return (byte)(((((byte)a) & 0xFF) << (b & 7)) | ((((byte)a) & 0xFF) >>> (8 - (b & 7))));
1444 #end[short]
1445 #end[intOrLong]
1446     }
1447 
1448     static $type$ ROR_scalar($type$ a, $type$ b) {
1449 #if[intOrLong]
1450         return $Wideboxtype$.rotateRight(a, ((int)b));
1451 #else[intOrLong]
1452 #if[short]
1453         return (short)(((((short)a) & 0xFFFF) >>> (b & 15)) | ((((short)a) & 0xFFFF) << (16 - (b & 15))));
1454 #else[short]
1455         return (byte)(((((byte)a) & 0xFF) >>> (b & 7)) | ((((byte)a) & 0xFF) << (8 - (b & 7))));
1456 #end[short]
1457 #end[intOrLong]
1458     }
1459 #end[BITWISE]
1460 
1461     static boolean eq($type$ a, $type$ b) {
1462         return a == b;
1463     }
1464 
1465     static boolean neq($type$ a, $type$ b) {
1466         return a != b;
1467     }
1468 
1469     static boolean lt($type$ a, $type$ b) {
1470         return a < b;
1471     }
1472 
1473     static boolean le($type$ a, $type$ b) {
1474         return a <= b;
1475     }
1476 
1477     static boolean gt($type$ a, $type$ b) {
1478         return a > b;
1479     }
1480 
1481     static boolean ge($type$ a, $type$ b) {
1482         return a >= b;
1483     }
1484 
1485 #if[!FP]
1486     static boolean ult($type$ a, $type$ b) {
1487         return $Boxtype$.compareUnsigned(a, b) < 0;
1488     }
1489 
1490     static boolean ule($type$ a, $type$ b) {
1491         return $Boxtype$.compareUnsigned(a, b) <= 0;
1492     }
1493 
1494     static boolean ugt($type$ a, $type$ b) {
1495         return $Boxtype$.compareUnsigned(a, b) > 0;
1496     }
1497 
1498     static boolean uge($type$ a, $type$ b) {
1499         return $Boxtype$.compareUnsigned(a, b) >= 0;
1500     }
1501 #end[!FP]
1502 
1503     @Test
1504     static void smokeTest1() {
1505         $abstractvectortype$ three = $abstractvectortype$.broadcast(SPECIES, (byte)-3);
1506         $abstractvectortype$ three2 = ($abstractvectortype$) SPECIES.broadcast(-3);
1507         assert(three.eq(three2).allTrue());
1508         $abstractvectortype$ three3 = three2.broadcast(1).broadcast(-3);
1509         assert(three.eq(three3).allTrue());
1510         int scale = 2;
1511         Class<?> ETYPE = $type$.class;
1512         if (ETYPE == double.class || ETYPE == long.class)
1513             scale = 1000000;
1514         else if (ETYPE == byte.class && SPECIES.length() >= 64)
1515             scale = 1;
1516         $abstractvectortype$ higher = three.addIndex(scale);
1517         VectorMask<$Boxtype$> m = three.compare(VectorOperators.LE, higher);
1518         assert(m.allTrue());
1519         m = higher.min(($type$)-1).test(VectorOperators.IS_NEGATIVE);
1520         assert(m.allTrue());
1521 #if[FP]
1522         m = higher.test(VectorOperators.IS_FINITE);
1523         assert(m.allTrue());
1524 #end[FP]
1525         $type$ max = higher.reduceLanes(VectorOperators.MAX);
1526         assert(max == -3 + scale * (SPECIES.length()-1));
1527     }
1528 
1529     private static $type$[]
1530     bothToArray($abstractvectortype$ a, $abstractvectortype$ b) {
1531         $type$[] r = new $type$[a.length() + b.length()];
1532         a.intoArray(r, 0);
1533         b.intoArray(r, a.length());
1534         return r;
1535     }
1536 
1537     @Test
1538     static void smokeTest2() {
1539         // Do some zipping and shuffling.
1540         $abstractvectortype$ io = ($abstractvectortype$) SPECIES.broadcast(0).addIndex(1);
1541         $abstractvectortype$ io2 = ($abstractvectortype$) VectorShuffle.iota(SPECIES,0,1,false).toVector();
1542         Assert.assertEquals(io, io2);
1543         $abstractvectortype$ a = io.add(($type$)1); //[1,2]
1544         $abstractvectortype$ b = a.neg();  //[-1,-2]
1545         $type$[] abValues = bothToArray(a,b); //[1,2,-1,-2]
1546         VectorShuffle<$Boxtype$> zip0 = VectorShuffle.makeZip(SPECIES, 0);
1547         VectorShuffle<$Boxtype$> zip1 = VectorShuffle.makeZip(SPECIES, 1);
1548         $abstractvectortype$ zab0 = a.rearrange(zip0,b); //[1,-1]
1549         $abstractvectortype$ zab1 = a.rearrange(zip1,b); //[2,-2]
1550         $type$[] zabValues = bothToArray(zab0, zab1); //[1,-1,2,-2]
1551         // manually zip
1552         $type$[] manual = new $type$[zabValues.length];
1553         for (int i = 0; i < manual.length; i += 2) {
1554             manual[i+0] = abValues[i/2];
1555             manual[i+1] = abValues[a.length() + i/2];
1556         }
1557         Assert.assertEquals(Arrays.toString(zabValues), Arrays.toString(manual));
1558         VectorShuffle<$Boxtype$> unz0 = VectorShuffle.makeUnzip(SPECIES, 0);
1559         VectorShuffle<$Boxtype$> unz1 = VectorShuffle.makeUnzip(SPECIES, 1);
1560         $abstractvectortype$ uab0 = zab0.rearrange(unz0,zab1);
1561         $abstractvectortype$ uab1 = zab0.rearrange(unz1,zab1);
1562         $type$[] abValues1 = bothToArray(uab0, uab1);
1563         Assert.assertEquals(Arrays.toString(abValues), Arrays.toString(abValues1));
1564     }
1565 
1566     static void iotaShuffle() {
1567         $abstractvectortype$ io = ($abstractvectortype$) SPECIES.broadcast(0).addIndex(1);
1568         $abstractvectortype$ io2 = ($abstractvectortype$) VectorShuffle.iota(SPECIES, 0 , 1, false).toVector();
1569         Assert.assertEquals(io, io2);
1570     }
1571 
1572     @Test
1573     // Test all shuffle related operations.
1574     static void shuffleTest() {
1575         // To test backend instructions, make sure that C2 is used.
1576         for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) {
1577             iotaShuffle();
1578         }
1579     }
1580 
1581     @Test
1582     void viewAsIntegeralLanesTest() {
1583 #if[FP]
1584         Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes();
1585         VectorSpecies<?> asIntegralSpecies = asIntegral.species();
1586         Assert.assertNotEquals(asIntegralSpecies.elementType(), SPECIES.elementType());
1587         Assert.assertEquals(asIntegralSpecies.vectorShape(), SPECIES.vectorShape());
1588         Assert.assertEquals(asIntegralSpecies.length(), SPECIES.length());
1589         Assert.assertEquals(asIntegral.viewAsFloatingLanes().species(), SPECIES);
1590 #else[FP]
1591         Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes();
1592         Assert.assertEquals(asIntegral.species(), SPECIES);
1593 #end[FP]
1594     }
1595 
1596 #if[FP]
1597     @Test
1598     void viewAsFloatingLanesTest() {
1599         Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes();
1600         Assert.assertEquals(asFloating.species(), SPECIES);
1601     }
1602 #else[FP]
1603 #if[byteOrShort]
1604     @Test(expectedExceptions = UnsupportedOperationException.class)
1605     void viewAsFloatingLanesTest() {
1606         SPECIES.zero().viewAsFloatingLanes();
1607     }
1608 #else[byteOrShort]
1609     @Test
1610     void viewAsFloatingLanesTest() {
1611         Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes();
1612         VectorSpecies<?> asFloatingSpecies = asFloating.species();
1613         Assert.assertNotEquals(asFloatingSpecies.elementType(), SPECIES.elementType());
1614         Assert.assertEquals(asFloatingSpecies.vectorShape(), SPECIES.vectorShape());
1615         Assert.assertEquals(asFloatingSpecies.length(), SPECIES.length());
1616         Assert.assertEquals(asFloating.viewAsIntegralLanes().species(), SPECIES);
1617     }
1618 #end[byteOrShort]
1619 #end[FP]
1620 
1621 #if[BITWISE]
1622     @Test
1623     // Test div by 0.
1624     static void bitwiseDivByZeroSmokeTest() {
1625         try {
1626             $abstractvectortype$ a = ($abstractvectortype$) SPECIES.broadcast(0).addIndex(1);
1627             $abstractvectortype$ b = ($abstractvectortype$) SPECIES.broadcast(0);
1628             a.div(b);
1629             Assert.fail();
1630         } catch (ArithmeticException e) {
1631         }
1632 
1633         try {
1634             $abstractvectortype$ a = ($abstractvectortype$) SPECIES.broadcast(0).addIndex(1);
1635             $abstractvectortype$ b = ($abstractvectortype$) SPECIES.broadcast(0);
1636             VectorMask<$Boxtype$> m = a.lt(($type$) 1);
1637             a.div(b, m);
1638             Assert.fail();
1639         } catch (ArithmeticException e) {
1640         }
1641     }
1642 #end[BITWISE]