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