< prev index next >

test/jdk/jdk/incubator/vector/VectorReshapeTests.java

Print this page
rev 54658 : refactored mask and shuffle creation methods, moved classes to top-level
   1 import jdk.incubator.vector.*;
   2 import jdk.internal.vm.annotation.ForceInline;
   3 import org.testng.Assert;
   4 import org.testng.annotations.Test;
   5 import org.testng.annotations.DataProvider;
   6 
   7 import java.lang.invoke.MethodHandles;
   8 import java.lang.invoke.VarHandle;
   9 import java.util.Arrays;
  10 import java.util.List;
  11 import java.util.function.IntFunction;
  12 import jdk.incubator.vector.Vector.Shape;
  13 import jdk.incubator.vector.Vector.Species;
  14 
  15 /**
  16  * @test
  17  * @modules jdk.incubator.vector
  18  * @modules java.base/jdk.internal.vm.annotation
  19  * @run testng/othervm --add-opens jdk.incubator.vector/jdk.incubator.vector=ALL-UNNAMED
  20  *      VectorReshapeTests
  21  */
  22 
  23 @Test
  24 public class VectorReshapeTests {
  25     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  26     static final int NUM_ITER = 200 * INVOC_COUNT;
  27 
  28     static final Shape S_Max_BIT = getMaxBit();
  29 
  30     static final Species<Integer> ispec64 = IntVector.SPECIES_64;
  31     static final Species<Float> fspec64 = FloatVector.SPECIES_64;
  32     static final Species<Long> lspec64 = LongVector.SPECIES_64;
  33     static final Species<Double> dspec64 = DoubleVector.SPECIES_64;
  34     static final Species<Byte> bspec64 = ByteVector.SPECIES_64;
  35     static final Species<Short> sspec64 = ShortVector.SPECIES_64;
  36 
  37     static final Species<Integer> ispec128 = IntVector.SPECIES_128;
  38     static final Species<Float> fspec128 = FloatVector.SPECIES_128;
  39     static final Species<Long> lspec128 = LongVector.SPECIES_128;
  40     static final Species<Double> dspec128 = DoubleVector.SPECIES_128;
  41     static final Species<Byte> bspec128 = ByteVector.SPECIES_128;
  42     static final Species<Short> sspec128 = ShortVector.SPECIES_128;
  43 
  44     static final Species<Integer> ispec256 = IntVector.SPECIES_256;
  45     static final Species<Float> fspec256 = FloatVector.SPECIES_256;
  46     static final Species<Long> lspec256 = LongVector.SPECIES_256;
  47     static final Species<Double> dspec256 = DoubleVector.SPECIES_256;
  48     static final Species<Byte> bspec256 = ByteVector.SPECIES_256;
  49     static final Species<Short> sspec256 = ShortVector.SPECIES_256;
  50 
  51     static final Species<Integer> ispec512 = IntVector.SPECIES_512;
  52     static final Species<Float> fspec512 = FloatVector.SPECIES_512;
  53     static final Species<Long> lspec512 = LongVector.SPECIES_512;
  54     static final Species<Double> dspec512 = DoubleVector.SPECIES_512;
  55     static final Species<Byte> bspec512 = ByteVector.SPECIES_512;
  56     static final Species<Short> sspec512 = ShortVector.SPECIES_512;
  57 
  58     static final Species<Integer> ispecMax = IntVector.SPECIES_MAX;
  59     static final Species<Float> fspecMax = FloatVector.SPECIES_MAX;
  60     static final Species<Long> lspecMax = LongVector.SPECIES_MAX;
  61     static final Species<Double> dspecMax = DoubleVector.SPECIES_MAX;
  62     static final Species<Byte> bspecMax = ByteVector.SPECIES_MAX;
  63     static final Species<Short> sspecMax = ShortVector.SPECIES_MAX;
  64 
  65     static Shape getMaxBit() {
  66         return Shape.S_Max_BIT;
  67     }
  68 
  69     static <T> IntFunction<T> withToString(String s, IntFunction<T> f) {
  70         return new IntFunction<T>() {
  71             @Override
  72             public T apply(int v) {
  73                 return f.apply(v);
  74             }
  75 
  76             @Override
  77             public String toString() {
  78                 return s;
  79             }
  80         };
  81     }
  82 
  83     interface ToByteF {
  84         byte apply(int i);
  85     }
  86 


 261         return FLOAT_GENERATORS.stream().
 262                 map(f -> new Object[]{f}).
 263                 toArray(Object[][]::new);
 264     }
 265 
 266     static final List<IntFunction<double[]>> DOUBLE_GENERATORS = List.of(
 267             withToString("double(i)", (int s) -> {
 268                 return fill_double(s, i -> (double)i);
 269             })
 270     );
 271 
 272     @DataProvider
 273     public Object[][] doubleUnaryOpProvider() {
 274         return DOUBLE_GENERATORS.stream().
 275                 map(f -> new Object[]{f}).
 276                 toArray(Object[][]::new);
 277     }
 278 
 279     @ForceInline
 280     static <E>
 281     void testVectorReshape(Vector.Species<E> a, Vector.Species<E> b, byte[] input, byte[] output) {
 282         Vector<E> av;
 283         Class<?> stype = a.elementType();
 284         if (stype == byte.class) {
 285            av =  (Vector) ByteVector.fromByteArray((Species<Byte>)a, input, 0);
 286         } else if (stype == short.class) {
 287            av =  (Vector) ShortVector.fromByteArray((Species<Short>)a, input, 0);
 288         } else if (stype == int.class) {
 289            av =  (Vector) IntVector.fromByteArray((Species<Integer>)a, input, 0);
 290         } else if (stype == long.class) {
 291            av =  (Vector) LongVector.fromByteArray((Species<Long>)a, input, 0);
 292         } else if (stype == float.class) {
 293            av =  (Vector) FloatVector.fromByteArray((Species<Float>)a, input, 0);
 294         } else if (stype == double.class) {
 295            av =  (Vector) DoubleVector.fromByteArray((Species<Double>)a, input, 0);
 296         } else {
 297             throw new UnsupportedOperationException("Bad lane type");
 298         } 
 299         Vector<E> bv = av.reshape(b);
 300         bv.intoByteArray(output, 0);
 301 
 302         byte[] expected = Arrays.copyOf(input, output.length);
 303 
 304 
 305         Assert.assertEquals(expected, output);
 306     }
 307 
 308     @Test(dataProvider = "byteUnaryOpProvider")
 309     static void testReshapeByte(IntFunction<byte[]> fa) {
 310         byte[] bin64 = fa.apply(64/Byte.SIZE);
 311         byte[] bin128 = fa.apply(128/Byte.SIZE);
 312         byte[] bin256 = fa.apply(256/Byte.SIZE);
 313         byte[] bin512 = fa.apply(512/Byte.SIZE);
 314         byte[] binMax = fa.apply(S_Max_BIT.bitSize()/Byte.SIZE);
 315         byte[] bout64 = new byte[bin64.length];


 566             testVectorReshape(dspec256, dspec256, bin256, bout256);
 567             testVectorReshape(dspec256, dspec512, bin256, bout512);
 568             testVectorReshape(dspec256, dspecMax, bin256, boutMax);
 569 
 570             testVectorReshape(dspec512, dspec64, bin512, bout64);
 571             testVectorReshape(dspec512, dspec128, bin512, bout128);
 572             testVectorReshape(dspec512, dspec256, bin512, bout256);
 573             testVectorReshape(dspec512, dspec512, bin512, bout512);
 574             testVectorReshape(dspec512, dspecMax, bin512, boutMax);
 575 
 576             testVectorReshape(dspecMax, dspec64, binMax, bout64);
 577             testVectorReshape(dspecMax, dspec128, binMax, bout128);
 578             testVectorReshape(dspecMax, dspec256, binMax, bout256);
 579             testVectorReshape(dspecMax, dspec512, binMax, bout512);
 580             testVectorReshape(dspecMax, dspecMax, binMax, boutMax);
 581         }
 582     }
 583 
 584     @ForceInline
 585     static <E,F>
 586     void testVectorRebracket(Vector.Species<E> a, Vector.Species<F> b, byte[] input, byte[] output) {
 587         assert(input.length == output.length);
 588         Vector<E> av;
 589 
 590         Class<?> stype = a.elementType();
 591         if (stype == byte.class) {
 592            av =  (Vector) ByteVector.fromByteArray((Species<Byte>)a, input, 0);
 593         } else if (stype == short.class) {
 594            av =  (Vector) ShortVector.fromByteArray((Species<Short>)a, input, 0);
 595         } else if (stype == int.class) {
 596            av =  (Vector) IntVector.fromByteArray((Species<Integer>)a, input, 0);
 597         } else if (stype == long.class) {
 598            av =  (Vector) LongVector.fromByteArray((Species<Long>)a, input, 0);
 599         } else if (stype == float.class) {
 600            av =  (Vector) FloatVector.fromByteArray((Species<Float>)a, input, 0);
 601         } else if (stype == double.class) {
 602            av =  (Vector) DoubleVector.fromByteArray((Species<Double>)a, input, 0);
 603         } else {
 604             throw new UnsupportedOperationException("Bad lane type");
 605         } 
 606         Vector<F> bv = av.reinterpret(b);
 607         bv.intoByteArray(output, 0);
 608 
 609         Assert.assertEquals(input, output);
 610     }
 611 
 612     @Test(dataProvider = "byteUnaryOpProvider")
 613     static void testRebracket64(IntFunction<byte[]> fa) {
 614         byte[] barr = fa.apply(64/Byte.SIZE);
 615         byte[] bout = new byte[barr.length];
 616         for (int i = 0; i < NUM_ITER; i++) {
 617             testVectorRebracket(bspec64, bspec64, barr, bout);
 618             testVectorRebracket(bspec64, sspec64, barr, bout);
 619             testVectorRebracket(bspec64, ispec64, barr, bout);
 620             testVectorRebracket(bspec64, lspec64, barr, bout);
 621             testVectorRebracket(bspec64, fspec64, barr, bout);
 622             testVectorRebracket(bspec64, dspec64, barr, bout);


 839             testVectorRebracket(lspecMax, dspecMax, barr, bout);
 840 
 841             testVectorRebracket(fspecMax, bspecMax, barr, bout);
 842             testVectorRebracket(fspecMax, sspecMax, barr, bout);
 843             testVectorRebracket(fspecMax, ispecMax, barr, bout);
 844             testVectorRebracket(fspecMax, lspecMax, barr, bout);
 845             testVectorRebracket(fspecMax, fspecMax, barr, bout);
 846             testVectorRebracket(fspecMax, dspecMax, barr, bout);
 847 
 848             testVectorRebracket(dspecMax, bspecMax, barr, bout);
 849             testVectorRebracket(dspecMax, sspecMax, barr, bout);
 850             testVectorRebracket(dspecMax, ispecMax, barr, bout);
 851             testVectorRebracket(dspecMax, lspecMax, barr, bout);
 852             testVectorRebracket(dspecMax, fspecMax, barr, bout);
 853             testVectorRebracket(dspecMax, dspecMax, barr, bout);
 854         }
 855     }
 856 
 857     @ForceInline
 858     static 
 859     void testVectorCastByteToFloat(Species<Byte> a, Species<Float> b, byte[] input, float[] output) {
 860         assert(input.length == a.length());
 861         assert(output.length == b.length());
 862 
 863         ByteVector av = ByteVector.fromArray(a, input, 0);
 864         FloatVector bv = (FloatVector) av.cast(b);
 865         bv.intoArray(output, 0);
 866 
 867         for (int i = 0; i < Math.min(input.length, output.length); i++) {
 868             Assert.assertEquals(output[i], (float)input[i]);
 869         }
 870         for(int i = input.length; i < output.length; i++) {
 871             Assert.assertEquals(output[i], (float)0);
 872         }
 873     }
 874 
 875     @ForceInline
 876     static 
 877     void testVectorCastByteToFloatFail(Species<Byte> a, Species<Float> b, byte[] input) {
 878         assert(input.length == a.length());
 879 
 880         ByteVector av = ByteVector.fromArray(a, input, 0);
 881         try {
 882             av.cast(b);
 883             Assert.fail(String.format(
 884                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
 885                     a, b));
 886         } catch (IllegalArgumentException e) {
 887         }
 888     }
 889 
 890     @ForceInline
 891     static 
 892     void testVectorCastShortToFloat(Species<Short> a, Species<Float> b, short[] input, float[] output) {
 893         assert(input.length == a.length());
 894         assert(output.length == b.length());
 895 
 896         ShortVector av = ShortVector.fromArray(a, input, 0);
 897         FloatVector bv = (FloatVector) av.cast(b);
 898         bv.intoArray(output, 0);
 899 
 900         for (int i = 0; i < Math.min(input.length, output.length); i++) {
 901             Assert.assertEquals(output[i], (float)input[i]);
 902         }
 903         for(int i = input.length; i < output.length; i++) {
 904             Assert.assertEquals(output[i], (float)0);
 905         }
 906     }
 907 
 908     @ForceInline
 909     static 
 910     void testVectorCastShortToFloatFail(Species<Short> a, Species<Float> b, short[] input) {
 911         assert(input.length == a.length());
 912 
 913         ShortVector av = ShortVector.fromArray(a, input, 0);
 914         try {
 915             av.cast(b);
 916             Assert.fail(String.format(
 917                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
 918                     a, b));
 919         } catch (IllegalArgumentException e) {
 920         }
 921     }
 922 
 923     @ForceInline
 924     static 
 925     void testVectorCastIntToFloat(Species<Integer> a, Species<Float> b, int[] input, float[] output) {
 926         assert(input.length == a.length());
 927         assert(output.length == b.length());
 928 
 929         IntVector av = IntVector.fromArray(a, input, 0);
 930         FloatVector bv = (FloatVector) av.cast(b);
 931         bv.intoArray(output, 0);
 932 
 933         for (int i = 0; i < Math.min(input.length, output.length); i++) {
 934             Assert.assertEquals(output[i], (float)input[i]);
 935         }
 936         for(int i = input.length; i < output.length; i++) {
 937             Assert.assertEquals(output[i], (float)0);
 938         }
 939     }
 940 
 941     @ForceInline
 942     static 
 943     void testVectorCastIntToFloatFail(Species<Integer> a, Species<Float> b, int[] input) {
 944         assert(input.length == a.length());
 945 
 946         IntVector av = IntVector.fromArray(a, input, 0);
 947         try {
 948             av.cast(b);
 949             Assert.fail(String.format(
 950                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
 951                     a, b));
 952         } catch (IllegalArgumentException e) {
 953         }
 954     }
 955 
 956     @ForceInline
 957     static 
 958     void testVectorCastLongToFloat(Species<Long> a, Species<Float> b, long[] input, float[] output) {
 959         assert(input.length == a.length());
 960         assert(output.length == b.length());
 961 
 962         LongVector av = LongVector.fromArray(a, input, 0);
 963         FloatVector bv = (FloatVector) av.cast(b);
 964         bv.intoArray(output, 0);
 965 
 966         for (int i = 0; i < Math.min(input.length, output.length); i++) {
 967             Assert.assertEquals(output[i], (float)input[i]);
 968         }
 969         for(int i = input.length; i < output.length; i++) {
 970             Assert.assertEquals(output[i], (float)0);
 971         }
 972     }
 973 
 974     @ForceInline
 975     static 
 976     void testVectorCastLongToFloatFail(Species<Long> a, Species<Float> b, long[] input) {
 977         assert(input.length == a.length());
 978 
 979         LongVector av = LongVector.fromArray(a, input, 0);
 980         try {
 981             av.cast(b);
 982             Assert.fail(String.format(
 983                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
 984                     a, b));
 985         } catch (IllegalArgumentException e) {
 986         }
 987     }
 988 
 989     @ForceInline
 990     static 
 991     void testVectorCastFloatToFloat(Species<Float> a, Species<Float> b, float[] input, float[] output) {
 992         assert(input.length == a.length());
 993         assert(output.length == b.length());
 994 
 995         FloatVector av = FloatVector.fromArray(a, input, 0);
 996         FloatVector bv = (FloatVector) av.cast(b);
 997         bv.intoArray(output, 0);
 998 
 999         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1000             Assert.assertEquals(output[i], (float)input[i]);
1001         }
1002         for(int i = input.length; i < output.length; i++) {
1003             Assert.assertEquals(output[i], (float)0);
1004         }
1005     }
1006 
1007     @ForceInline
1008     static 
1009     void testVectorCastFloatToFloatFail(Species<Float> a, Species<Float> b, float[] input) {
1010         assert(input.length == a.length());
1011 
1012         FloatVector av = FloatVector.fromArray(a, input, 0);
1013         try {
1014             av.cast(b);
1015             Assert.fail(String.format(
1016                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1017                     a, b));
1018         } catch (IllegalArgumentException e) {
1019         }
1020     }
1021 
1022     @ForceInline
1023     static 
1024     void testVectorCastDoubleToFloat(Species<Double> a, Species<Float> b, double[] input, float[] output) {
1025         assert(input.length == a.length());
1026         assert(output.length == b.length());
1027 
1028         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1029         FloatVector bv = (FloatVector) av.cast(b);
1030         bv.intoArray(output, 0);
1031 
1032         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1033             Assert.assertEquals(output[i], (float)input[i]);
1034         }
1035         for(int i = input.length; i < output.length; i++) {
1036             Assert.assertEquals(output[i], (float)0);
1037         }
1038     }
1039 
1040     @ForceInline
1041     static 
1042     void testVectorCastDoubleToFloatFail(Species<Double> a, Species<Float> b, double[] input) {
1043         assert(input.length == a.length());
1044 
1045         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1046         try {
1047             av.cast(b);
1048             Assert.fail(String.format(
1049                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1050                     a, b));
1051         } catch (IllegalArgumentException e) {
1052         }
1053     }
1054 
1055     @ForceInline
1056     static 
1057     void testVectorCastByteToByte(Species<Byte> a, Species<Byte> b, byte[] input, byte[] output) {
1058         assert(input.length == a.length());
1059         assert(output.length == b.length());
1060 
1061         ByteVector av = ByteVector.fromArray(a, input, 0);
1062         ByteVector bv = (ByteVector) av.cast(b);
1063         bv.intoArray(output, 0);
1064 
1065         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1066             Assert.assertEquals(output[i], (byte)input[i]);
1067         }
1068         for(int i = input.length; i < output.length; i++) {
1069             Assert.assertEquals(output[i], (byte)0);
1070         }
1071     }
1072 
1073     @ForceInline
1074     static 
1075     void testVectorCastByteToByteFail(Species<Byte> a, Species<Byte> b, byte[] input) {
1076         assert(input.length == a.length());
1077 
1078         ByteVector av = ByteVector.fromArray(a, input, 0);
1079         try {
1080             av.cast(b);
1081             Assert.fail(String.format(
1082                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1083                     a, b));
1084         } catch (IllegalArgumentException e) {
1085         }
1086     }
1087 
1088     @ForceInline
1089     static 
1090     void testVectorCastShortToByte(Species<Short> a, Species<Byte> b, short[] input, byte[] output) {
1091         assert(input.length == a.length());
1092         assert(output.length == b.length());
1093 
1094         ShortVector av = ShortVector.fromArray(a, input, 0);
1095         ByteVector bv = (ByteVector) av.cast(b);
1096         bv.intoArray(output, 0);
1097 
1098         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1099             Assert.assertEquals(output[i], (byte)input[i]);
1100         }
1101         for(int i = input.length; i < output.length; i++) {
1102             Assert.assertEquals(output[i], (byte)0);
1103         }
1104     }
1105 
1106     @ForceInline
1107     static 
1108     void testVectorCastShortToByteFail(Species<Short> a, Species<Byte> b, short[] input) {
1109         assert(input.length == a.length());
1110 
1111         ShortVector av = ShortVector.fromArray(a, input, 0);
1112         try {
1113             av.cast(b);
1114             Assert.fail(String.format(
1115                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1116                     a, b));
1117         } catch (IllegalArgumentException e) {
1118         }
1119     }
1120 
1121     @ForceInline
1122     static 
1123     void testVectorCastIntToByte(Species<Integer> a, Species<Byte> b, int[] input, byte[] output) {
1124         assert(input.length == a.length());
1125         assert(output.length == b.length());
1126 
1127         IntVector av = IntVector.fromArray(a, input, 0);
1128         ByteVector bv = (ByteVector) av.cast(b);
1129         bv.intoArray(output, 0);
1130 
1131         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1132             Assert.assertEquals(output[i], (byte)input[i]);
1133         }
1134         for(int i = input.length; i < output.length; i++) {
1135             Assert.assertEquals(output[i], (byte)0);
1136         }
1137     }
1138 
1139     @ForceInline
1140     static 
1141     void testVectorCastIntToByteFail(Species<Integer> a, Species<Byte> b, int[] input) {
1142         assert(input.length == a.length());
1143 
1144         IntVector av = IntVector.fromArray(a, input, 0);
1145         try {
1146             av.cast(b);
1147             Assert.fail(String.format(
1148                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1149                     a, b));
1150         } catch (IllegalArgumentException e) {
1151         }
1152     }
1153 
1154     @ForceInline
1155     static 
1156     void testVectorCastLongToByte(Species<Long> a, Species<Byte> b, long[] input, byte[] output) {
1157         assert(input.length == a.length());
1158         assert(output.length == b.length());
1159 
1160         LongVector av = LongVector.fromArray(a, input, 0);
1161         ByteVector bv = (ByteVector) av.cast(b);
1162         bv.intoArray(output, 0);
1163 
1164         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1165             Assert.assertEquals(output[i], (byte)input[i]);
1166         }
1167         for(int i = input.length; i < output.length; i++) {
1168             Assert.assertEquals(output[i], (byte)0);
1169         }
1170     }
1171 
1172     @ForceInline
1173     static 
1174     void testVectorCastLongToByteFail(Species<Long> a, Species<Byte> b, long[] input) {
1175         assert(input.length == a.length());
1176 
1177         LongVector av = LongVector.fromArray(a, input, 0);
1178         try {
1179             av.cast(b);
1180             Assert.fail(String.format(
1181                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1182                     a, b));
1183         } catch (IllegalArgumentException e) {
1184         }
1185     }
1186 
1187     @ForceInline
1188     static 
1189     void testVectorCastFloatToByte(Species<Float> a, Species<Byte> b, float[] input, byte[] output) {
1190         assert(input.length == a.length());
1191         assert(output.length == b.length());
1192 
1193         FloatVector av = FloatVector.fromArray(a, input, 0);
1194         ByteVector bv = (ByteVector) av.cast(b);
1195         bv.intoArray(output, 0);
1196 
1197         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1198             Assert.assertEquals(output[i], (byte)input[i]);
1199         }
1200         for(int i = input.length; i < output.length; i++) {
1201             Assert.assertEquals(output[i], (byte)0);
1202         }
1203     }
1204 
1205     @ForceInline
1206     static 
1207     void testVectorCastFloatToByteFail(Species<Float> a, Species<Byte> b, float[] input) {
1208         assert(input.length == a.length());
1209 
1210         FloatVector av = FloatVector.fromArray(a, input, 0);
1211         try {
1212             av.cast(b);
1213             Assert.fail(String.format(
1214                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1215                     a, b));
1216         } catch (IllegalArgumentException e) {
1217         }
1218     }
1219 
1220     @ForceInline
1221     static 
1222     void testVectorCastDoubleToByte(Species<Double> a, Species<Byte> b, double[] input, byte[] output) {
1223         assert(input.length == a.length());
1224         assert(output.length == b.length());
1225 
1226         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1227         ByteVector bv = (ByteVector) av.cast(b);
1228         bv.intoArray(output, 0);
1229 
1230         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1231             Assert.assertEquals(output[i], (byte)input[i]);
1232         }
1233         for(int i = input.length; i < output.length; i++) {
1234             Assert.assertEquals(output[i], (byte)0);
1235         }
1236     }
1237 
1238     @ForceInline
1239     static 
1240     void testVectorCastDoubleToByteFail(Species<Double> a, Species<Byte> b, double[] input) {
1241         assert(input.length == a.length());
1242 
1243         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1244         try {
1245             av.cast(b);
1246             Assert.fail(String.format(
1247                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1248                     a, b));
1249         } catch (IllegalArgumentException e) {
1250         }
1251     }
1252 
1253     @ForceInline
1254     static 
1255     void testVectorCastByteToShort(Species<Byte> a, Species<Short> b, byte[] input, short[] output) {
1256         assert(input.length == a.length());
1257         assert(output.length == b.length());
1258 
1259         ByteVector av = ByteVector.fromArray(a, input, 0);
1260         ShortVector bv = (ShortVector) av.cast(b);
1261         bv.intoArray(output, 0);
1262 
1263         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1264             Assert.assertEquals(output[i], (short)input[i]);
1265         }
1266         for(int i = input.length; i < output.length; i++) {
1267             Assert.assertEquals(output[i], (short)0);
1268         }
1269     }
1270 
1271     @ForceInline
1272     static 
1273     void testVectorCastByteToShortFail(Species<Byte> a, Species<Short> b, byte[] input) {
1274         assert(input.length == a.length());
1275 
1276         ByteVector av = ByteVector.fromArray(a, input, 0);
1277         try {
1278             av.cast(b);
1279             Assert.fail(String.format(
1280                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1281                     a, b));
1282         } catch (IllegalArgumentException e) {
1283         }
1284     }
1285 
1286     @ForceInline
1287     static 
1288     void testVectorCastShortToShort(Species<Short> a, Species<Short> b, short[] input, short[] output) {
1289         assert(input.length == a.length());
1290         assert(output.length == b.length());
1291 
1292         ShortVector av = ShortVector.fromArray(a, input, 0);
1293         ShortVector bv = (ShortVector) av.cast(b);
1294         bv.intoArray(output, 0);
1295 
1296         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1297             Assert.assertEquals(output[i], (short)input[i]);
1298         }
1299         for(int i = input.length; i < output.length; i++) {
1300             Assert.assertEquals(output[i], (short)0);
1301         }
1302     }
1303 
1304     @ForceInline
1305     static 
1306     void testVectorCastShortToShortFail(Species<Short> a, Species<Short> b, short[] input) {
1307         assert(input.length == a.length());
1308 
1309         ShortVector av = ShortVector.fromArray(a, input, 0);
1310         try {
1311             av.cast(b);
1312             Assert.fail(String.format(
1313                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1314                     a, b));
1315         } catch (IllegalArgumentException e) {
1316         }
1317     }
1318 
1319     @ForceInline
1320     static 
1321     void testVectorCastIntToShort(Species<Integer> a, Species<Short> b, int[] input, short[] output) {
1322         assert(input.length == a.length());
1323         assert(output.length == b.length());
1324 
1325         IntVector av = IntVector.fromArray(a, input, 0);
1326         ShortVector bv = (ShortVector) av.cast(b);
1327         bv.intoArray(output, 0);
1328 
1329         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1330             Assert.assertEquals(output[i], (short)input[i]);
1331         }
1332         for(int i = input.length; i < output.length; i++) {
1333             Assert.assertEquals(output[i], (short)0);
1334         }
1335     }
1336 
1337     @ForceInline
1338     static 
1339     void testVectorCastIntToShortFail(Species<Integer> a, Species<Short> b, int[] input) {
1340         assert(input.length == a.length());
1341 
1342         IntVector av = IntVector.fromArray(a, input, 0);
1343         try {
1344             av.cast(b);
1345             Assert.fail(String.format(
1346                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1347                     a, b));
1348         } catch (IllegalArgumentException e) {
1349         }
1350     }
1351 
1352     @ForceInline
1353     static 
1354     void testVectorCastLongToShort(Species<Long> a, Species<Short> b, long[] input, short[] output) {
1355         assert(input.length == a.length());
1356         assert(output.length == b.length());
1357 
1358         LongVector av = LongVector.fromArray(a, input, 0);
1359         ShortVector bv = (ShortVector) av.cast(b);
1360         bv.intoArray(output, 0);
1361 
1362         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1363             Assert.assertEquals(output[i], (short)input[i]);
1364         }
1365         for(int i = input.length; i < output.length; i++) {
1366             Assert.assertEquals(output[i], (short)0);
1367         }
1368     }
1369 
1370     @ForceInline
1371     static 
1372     void testVectorCastLongToShortFail(Species<Long> a, Species<Short> b, long[] input) {
1373         assert(input.length == a.length());
1374 
1375         LongVector av = LongVector.fromArray(a, input, 0);
1376         try {
1377             av.cast(b);
1378             Assert.fail(String.format(
1379                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1380                     a, b));
1381         } catch (IllegalArgumentException e) {
1382         }
1383     }
1384 
1385     @ForceInline
1386     static 
1387     void testVectorCastFloatToShort(Species<Float> a, Species<Short> b, float[] input, short[] output) {
1388         assert(input.length == a.length());
1389         assert(output.length == b.length());
1390 
1391         FloatVector av = FloatVector.fromArray(a, input, 0);
1392         ShortVector bv = (ShortVector) av.cast(b);
1393         bv.intoArray(output, 0);
1394 
1395         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1396             Assert.assertEquals(output[i], (short)input[i]);
1397         }
1398         for(int i = input.length; i < output.length; i++) {
1399             Assert.assertEquals(output[i], (short)0);
1400         }
1401     }
1402 
1403     @ForceInline
1404     static 
1405     void testVectorCastFloatToShortFail(Species<Float> a, Species<Short> b, float[] input) {
1406         assert(input.length == a.length());
1407 
1408         FloatVector av = FloatVector.fromArray(a, input, 0);
1409         try {
1410             av.cast(b);
1411             Assert.fail(String.format(
1412                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1413                     a, b));
1414         } catch (IllegalArgumentException e) {
1415         }
1416     }
1417 
1418     @ForceInline
1419     static 
1420     void testVectorCastDoubleToShort(Species<Double> a, Species<Short> b, double[] input, short[] output) {
1421         assert(input.length == a.length());
1422         assert(output.length == b.length());
1423 
1424         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1425         ShortVector bv = (ShortVector) av.cast(b);
1426         bv.intoArray(output, 0);
1427 
1428         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1429             Assert.assertEquals(output[i], (short)input[i]);
1430         }
1431         for(int i = input.length; i < output.length; i++) {
1432             Assert.assertEquals(output[i], (short)0);
1433         }
1434     }
1435 
1436     @ForceInline
1437     static 
1438     void testVectorCastDoubleToShortFail(Species<Double> a, Species<Short> b, double[] input) {
1439         assert(input.length == a.length());
1440 
1441         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1442         try {
1443             av.cast(b);
1444             Assert.fail(String.format(
1445                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1446                     a, b));
1447         } catch (IllegalArgumentException e) {
1448         }
1449     }
1450 
1451     @ForceInline
1452     static 
1453     void testVectorCastByteToInt(Species<Byte> a, Species<Integer> b, byte[] input, int[] output) {
1454         assert(input.length == a.length());
1455         assert(output.length == b.length());
1456 
1457         ByteVector av = ByteVector.fromArray(a, input, 0);
1458         IntVector bv = (IntVector) av.cast(b);
1459         bv.intoArray(output, 0);
1460 
1461         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1462             Assert.assertEquals(output[i], (int)input[i]);
1463         }
1464         for(int i = input.length; i < output.length; i++) {
1465             Assert.assertEquals(output[i], (int)0);
1466         }
1467     }
1468 
1469     @ForceInline
1470     static 
1471     void testVectorCastByteToIntFail(Species<Byte> a, Species<Integer> b, byte[] input) {
1472         assert(input.length == a.length());
1473 
1474         ByteVector av = ByteVector.fromArray(a, input, 0);
1475         try {
1476             av.cast(b);
1477             Assert.fail(String.format(
1478                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1479                     a, b));
1480         } catch (IllegalArgumentException e) {
1481         }
1482     }
1483 
1484     @ForceInline
1485     static 
1486     void testVectorCastShortToInt(Species<Short> a, Species<Integer> b, short[] input, int[] output) {
1487         assert(input.length == a.length());
1488         assert(output.length == b.length());
1489 
1490         ShortVector av = ShortVector.fromArray(a, input, 0);
1491         IntVector bv = (IntVector) av.cast(b);
1492         bv.intoArray(output, 0);
1493 
1494         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1495             Assert.assertEquals(output[i], (int)input[i]);
1496         }
1497         for(int i = input.length; i < output.length; i++) {
1498             Assert.assertEquals(output[i], (int)0);
1499         }
1500     }
1501 
1502     @ForceInline
1503     static 
1504     void testVectorCastShortToIntFail(Species<Short> a, Species<Integer> b, short[] input) {
1505         assert(input.length == a.length());
1506 
1507         ShortVector av = ShortVector.fromArray(a, input, 0);
1508         try {
1509             av.cast(b);
1510             Assert.fail(String.format(
1511                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1512                     a, b));
1513         } catch (IllegalArgumentException e) {
1514         }
1515     }
1516 
1517     @ForceInline
1518     static 
1519     void testVectorCastIntToInt(Species<Integer> a, Species<Integer> b, int[] input, int[] output) {
1520         assert(input.length == a.length());
1521         assert(output.length == b.length());
1522 
1523         IntVector av = IntVector.fromArray(a, input, 0);
1524         IntVector bv = (IntVector) av.cast(b);
1525         bv.intoArray(output, 0);
1526 
1527         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1528             Assert.assertEquals(output[i], (int)input[i]);
1529         }
1530         for(int i = input.length; i < output.length; i++) {
1531             Assert.assertEquals(output[i], (int)0);
1532         }
1533     }
1534 
1535     @ForceInline
1536     static 
1537     void testVectorCastIntToIntFail(Species<Integer> a, Species<Integer> b, int[] input) {
1538         assert(input.length == a.length());
1539 
1540         IntVector av = IntVector.fromArray(a, input, 0);
1541         try {
1542             av.cast(b);
1543             Assert.fail(String.format(
1544                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1545                     a, b));
1546         } catch (IllegalArgumentException e) {
1547         }
1548     }
1549 
1550     @ForceInline
1551     static 
1552     void testVectorCastLongToInt(Species<Long> a, Species<Integer> b, long[] input, int[] output) {
1553         assert(input.length == a.length());
1554         assert(output.length == b.length());
1555 
1556         LongVector av = LongVector.fromArray(a, input, 0);
1557         IntVector bv = (IntVector) av.cast(b);
1558         bv.intoArray(output, 0);
1559 
1560         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1561             Assert.assertEquals(output[i], (int)input[i]);
1562         }
1563         for(int i = input.length; i < output.length; i++) {
1564             Assert.assertEquals(output[i], (int)0);
1565         }
1566     }
1567 
1568     @ForceInline
1569     static 
1570     void testVectorCastLongToIntFail(Species<Long> a, Species<Integer> b, long[] input) {
1571         assert(input.length == a.length());
1572 
1573         LongVector av = LongVector.fromArray(a, input, 0);
1574         try {
1575             av.cast(b);
1576             Assert.fail(String.format(
1577                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1578                     a, b));
1579         } catch (IllegalArgumentException e) {
1580         }
1581     }
1582 
1583     @ForceInline
1584     static 
1585     void testVectorCastFloatToInt(Species<Float> a, Species<Integer> b, float[] input, int[] output) {
1586         assert(input.length == a.length());
1587         assert(output.length == b.length());
1588 
1589         FloatVector av = FloatVector.fromArray(a, input, 0);
1590         IntVector bv = (IntVector) av.cast(b);
1591         bv.intoArray(output, 0);
1592 
1593         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1594             Assert.assertEquals(output[i], (int)input[i]);
1595         }
1596         for(int i = input.length; i < output.length; i++) {
1597             Assert.assertEquals(output[i], (int)0);
1598         }
1599     }
1600 
1601     @ForceInline
1602     static 
1603     void testVectorCastFloatToIntFail(Species<Float> a, Species<Integer> b, float[] input) {
1604         assert(input.length == a.length());
1605 
1606         FloatVector av = FloatVector.fromArray(a, input, 0);
1607         try {
1608             av.cast(b);
1609             Assert.fail(String.format(
1610                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1611                     a, b));
1612         } catch (IllegalArgumentException e) {
1613         }
1614     }
1615 
1616     @ForceInline
1617     static 
1618     void testVectorCastDoubleToInt(Species<Double> a, Species<Integer> b, double[] input, int[] output) {
1619         assert(input.length == a.length());
1620         assert(output.length == b.length());
1621 
1622         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1623         IntVector bv = (IntVector) av.cast(b);
1624         bv.intoArray(output, 0);
1625 
1626         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1627             Assert.assertEquals(output[i], (int)input[i]);
1628         }
1629         for(int i = input.length; i < output.length; i++) {
1630             Assert.assertEquals(output[i], (int)0);
1631         }
1632     }
1633 
1634     @ForceInline
1635     static 
1636     void testVectorCastDoubleToIntFail(Species<Double> a, Species<Integer> b, double[] input) {
1637         assert(input.length == a.length());
1638 
1639         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1640         try {
1641             av.cast(b);
1642             Assert.fail(String.format(
1643                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1644                     a, b));
1645         } catch (IllegalArgumentException e) {
1646         }
1647     }
1648 
1649     @ForceInline
1650     static 
1651     void testVectorCastByteToLong(Species<Byte> a, Species<Long> b, byte[] input, long[] output) {
1652         assert(input.length == a.length());
1653         assert(output.length == b.length());
1654 
1655         ByteVector av = ByteVector.fromArray(a, input, 0);
1656         LongVector bv = (LongVector) av.cast(b);
1657         bv.intoArray(output, 0);
1658 
1659         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1660             Assert.assertEquals(output[i], (long)input[i]);
1661         }
1662         for(int i = input.length; i < output.length; i++) {
1663             Assert.assertEquals(output[i], (long)0);
1664         }
1665     }
1666 
1667     @ForceInline
1668     static 
1669     void testVectorCastByteToLongFail(Species<Byte> a, Species<Long> b, byte[] input) {
1670         assert(input.length == a.length());
1671 
1672         ByteVector av = ByteVector.fromArray(a, input, 0);
1673         try {
1674             av.cast(b);
1675             Assert.fail(String.format(
1676                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1677                     a, b));
1678         } catch (IllegalArgumentException e) {
1679         }
1680     }
1681 
1682     @ForceInline
1683     static 
1684     void testVectorCastShortToLong(Species<Short> a, Species<Long> b, short[] input, long[] output) {
1685         assert(input.length == a.length());
1686         assert(output.length == b.length());
1687 
1688         ShortVector av = ShortVector.fromArray(a, input, 0);
1689         LongVector bv = (LongVector) av.cast(b);
1690         bv.intoArray(output, 0);
1691 
1692         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1693             Assert.assertEquals(output[i], (long)input[i]);
1694         }
1695         for(int i = input.length; i < output.length; i++) {
1696             Assert.assertEquals(output[i], (long)0);
1697         }
1698     }
1699 
1700     @ForceInline
1701     static 
1702     void testVectorCastShortToLongFail(Species<Short> a, Species<Long> b, short[] input) {
1703         assert(input.length == a.length());
1704 
1705         ShortVector av = ShortVector.fromArray(a, input, 0);
1706         try {
1707             av.cast(b);
1708             Assert.fail(String.format(
1709                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1710                     a, b));
1711         } catch (IllegalArgumentException e) {
1712         }
1713     }
1714 
1715     @ForceInline
1716     static 
1717     void testVectorCastIntToLong(Species<Integer> a, Species<Long> b, int[] input, long[] output) {
1718         assert(input.length == a.length());
1719         assert(output.length == b.length());
1720 
1721         IntVector av = IntVector.fromArray(a, input, 0);
1722         LongVector bv = (LongVector) av.cast(b);
1723         bv.intoArray(output, 0);
1724 
1725         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1726             Assert.assertEquals(output[i], (long)input[i]);
1727         }
1728         for(int i = input.length; i < output.length; i++) {
1729             Assert.assertEquals(output[i], (long)0);
1730         }
1731     }
1732 
1733     @ForceInline
1734     static 
1735     void testVectorCastIntToLongFail(Species<Integer> a, Species<Long> b, int[] input) {
1736         assert(input.length == a.length());
1737 
1738         IntVector av = IntVector.fromArray(a, input, 0);
1739         try {
1740             av.cast(b);
1741             Assert.fail(String.format(
1742                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1743                     a, b));
1744         } catch (IllegalArgumentException e) {
1745         }
1746     }
1747 
1748     @ForceInline
1749     static 
1750     void testVectorCastLongToLong(Species<Long> a, Species<Long> b, long[] input, long[] output) {
1751         assert(input.length == a.length());
1752         assert(output.length == b.length());
1753 
1754         LongVector av = LongVector.fromArray(a, input, 0);
1755         LongVector bv = (LongVector) av.cast(b);
1756         bv.intoArray(output, 0);
1757 
1758         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1759             Assert.assertEquals(output[i], (long)input[i]);
1760         }
1761         for(int i = input.length; i < output.length; i++) {
1762             Assert.assertEquals(output[i], (long)0);
1763         }
1764     }
1765 
1766     @ForceInline
1767     static 
1768     void testVectorCastLongToLongFail(Species<Long> a, Species<Long> b, long[] input) {
1769         assert(input.length == a.length());
1770 
1771         LongVector av = LongVector.fromArray(a, input, 0);
1772         try {
1773             av.cast(b);
1774             Assert.fail(String.format(
1775                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1776                     a, b));
1777         } catch (IllegalArgumentException e) {
1778         }
1779     }
1780 
1781     @ForceInline
1782     static 
1783     void testVectorCastFloatToLong(Species<Float> a, Species<Long> b, float[] input, long[] output) {
1784         assert(input.length == a.length());
1785         assert(output.length == b.length());
1786 
1787         FloatVector av = FloatVector.fromArray(a, input, 0);
1788         LongVector bv = (LongVector) av.cast(b);
1789         bv.intoArray(output, 0);
1790 
1791         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1792             Assert.assertEquals(output[i], (long)input[i]);
1793         }
1794         for(int i = input.length; i < output.length; i++) {
1795             Assert.assertEquals(output[i], (long)0);
1796         }
1797     }
1798 
1799     @ForceInline
1800     static 
1801     void testVectorCastFloatToLongFail(Species<Float> a, Species<Long> b, float[] input) {
1802         assert(input.length == a.length());
1803 
1804         FloatVector av = FloatVector.fromArray(a, input, 0);
1805         try {
1806             av.cast(b);
1807             Assert.fail(String.format(
1808                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1809                     a, b));
1810         } catch (IllegalArgumentException e) {
1811         }
1812     }
1813 
1814     @ForceInline
1815     static 
1816     void testVectorCastDoubleToLong(Species<Double> a, Species<Long> b, double[] input, long[] output) {
1817         assert(input.length == a.length());
1818         assert(output.length == b.length());
1819 
1820         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1821         LongVector bv = (LongVector) av.cast(b);
1822         bv.intoArray(output, 0);
1823 
1824         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1825             Assert.assertEquals(output[i], (long)input[i]);
1826         }
1827         for(int i = input.length; i < output.length; i++) {
1828             Assert.assertEquals(output[i], (long)0);
1829         }
1830     }
1831 
1832     @ForceInline
1833     static 
1834     void testVectorCastDoubleToLongFail(Species<Double> a, Species<Long> b, double[] input) {
1835         assert(input.length == a.length());
1836 
1837         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1838         try {
1839             av.cast(b);
1840             Assert.fail(String.format(
1841                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1842                     a, b));
1843         } catch (IllegalArgumentException e) {
1844         }
1845     }
1846 
1847     @ForceInline
1848     static 
1849     void testVectorCastByteToDouble(Species<Byte> a, Species<Double> b, byte[] input, double[] output) {
1850         assert(input.length == a.length());
1851         assert(output.length == b.length());
1852 
1853         ByteVector av = ByteVector.fromArray(a, input, 0);
1854         DoubleVector bv = (DoubleVector) av.cast(b);
1855         bv.intoArray(output, 0);
1856 
1857         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1858             Assert.assertEquals(output[i], (double)input[i]);
1859         }
1860         for(int i = input.length; i < output.length; i++) {
1861             Assert.assertEquals(output[i], (double)0);
1862         }
1863     }
1864 
1865     @ForceInline
1866     static 
1867     void testVectorCastByteToDoubleFail(Species<Byte> a, Species<Double> b, byte[] input) {
1868         assert(input.length == a.length());
1869 
1870         ByteVector av = ByteVector.fromArray(a, input, 0);
1871         try {
1872             av.cast(b);
1873             Assert.fail(String.format(
1874                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1875                     a, b));
1876         } catch (IllegalArgumentException e) {
1877         }
1878     }
1879 
1880     @ForceInline
1881     static 
1882     void testVectorCastShortToDouble(Species<Short> a, Species<Double> b, short[] input, double[] output) {
1883         assert(input.length == a.length());
1884         assert(output.length == b.length());
1885 
1886         ShortVector av = ShortVector.fromArray(a, input, 0);
1887         DoubleVector bv = (DoubleVector) av.cast(b);
1888         bv.intoArray(output, 0);
1889 
1890         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1891             Assert.assertEquals(output[i], (double)input[i]);
1892         }
1893         for(int i = input.length; i < output.length; i++) {
1894             Assert.assertEquals(output[i], (double)0);
1895         }
1896     }
1897 
1898     @ForceInline
1899     static 
1900     void testVectorCastShortToDoubleFail(Species<Short> a, Species<Double> b, short[] input) {
1901         assert(input.length == a.length());
1902 
1903         ShortVector av = ShortVector.fromArray(a, input, 0);
1904         try {
1905             av.cast(b);
1906             Assert.fail(String.format(
1907                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1908                     a, b));
1909         } catch (IllegalArgumentException e) {
1910         }
1911     }
1912 
1913     @ForceInline
1914     static 
1915     void testVectorCastIntToDouble(Species<Integer> a, Species<Double> b, int[] input, double[] output) {
1916         assert(input.length == a.length());
1917         assert(output.length == b.length());
1918 
1919         IntVector av = IntVector.fromArray(a, input, 0);
1920         DoubleVector bv = (DoubleVector) av.cast(b);
1921         bv.intoArray(output, 0);
1922 
1923         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1924             Assert.assertEquals(output[i], (double)input[i]);
1925         }
1926         for(int i = input.length; i < output.length; i++) {
1927             Assert.assertEquals(output[i], (double)0);
1928         }
1929     }
1930 
1931     @ForceInline
1932     static 
1933     void testVectorCastIntToDoubleFail(Species<Integer> a, Species<Double> b, int[] input) {
1934         assert(input.length == a.length());
1935 
1936         IntVector av = IntVector.fromArray(a, input, 0);
1937         try {
1938             av.cast(b);
1939             Assert.fail(String.format(
1940                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1941                     a, b));
1942         } catch (IllegalArgumentException e) {
1943         }
1944     }
1945 
1946     @ForceInline
1947     static 
1948     void testVectorCastLongToDouble(Species<Long> a, Species<Double> b, long[] input, double[] output) {
1949         assert(input.length == a.length());
1950         assert(output.length == b.length());
1951 
1952         LongVector av = LongVector.fromArray(a, input, 0);
1953         DoubleVector bv = (DoubleVector) av.cast(b);
1954         bv.intoArray(output, 0);
1955 
1956         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1957             Assert.assertEquals(output[i], (double)input[i]);
1958         }
1959         for(int i = input.length; i < output.length; i++) {
1960             Assert.assertEquals(output[i], (double)0);
1961         }
1962     }
1963 
1964     @ForceInline
1965     static 
1966     void testVectorCastLongToDoubleFail(Species<Long> a, Species<Double> b, long[] input) {
1967         assert(input.length == a.length());
1968 
1969         LongVector av = LongVector.fromArray(a, input, 0);
1970         try {
1971             av.cast(b);
1972             Assert.fail(String.format(
1973                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1974                     a, b));
1975         } catch (IllegalArgumentException e) {
1976         }
1977     }
1978 
1979     @ForceInline
1980     static 
1981     void testVectorCastFloatToDouble(Species<Float> a, Species<Double> b, float[] input, double[] output) {
1982         assert(input.length == a.length());
1983         assert(output.length == b.length());
1984 
1985         FloatVector av = FloatVector.fromArray(a, input, 0);
1986         DoubleVector bv = (DoubleVector) av.cast(b);
1987         bv.intoArray(output, 0);
1988 
1989         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1990             Assert.assertEquals(output[i], (double)input[i]);
1991         }
1992         for(int i = input.length; i < output.length; i++) {
1993             Assert.assertEquals(output[i], (double)0);
1994         }
1995     }
1996 
1997     @ForceInline
1998     static 
1999     void testVectorCastFloatToDoubleFail(Species<Float> a, Species<Double> b, float[] input) {
2000         assert(input.length == a.length());
2001 
2002         FloatVector av = FloatVector.fromArray(a, input, 0);
2003         try {
2004             av.cast(b);
2005             Assert.fail(String.format(
2006                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
2007                     a, b));
2008         } catch (IllegalArgumentException e) {
2009         }
2010     }
2011 
2012     @ForceInline
2013     static 
2014     void testVectorCastDoubleToDouble(Species<Double> a, Species<Double> b, double[] input, double[] output) {
2015         assert(input.length == a.length());
2016         assert(output.length == b.length());
2017 
2018         DoubleVector av = DoubleVector.fromArray(a, input, 0);
2019         DoubleVector bv = (DoubleVector) av.cast(b);
2020         bv.intoArray(output, 0);
2021 
2022         for (int i = 0; i < Math.min(input.length, output.length); i++) {
2023             Assert.assertEquals(output[i], (double)input[i]);
2024         }
2025         for(int i = input.length; i < output.length; i++) {
2026             Assert.assertEquals(output[i], (double)0);
2027         }
2028     }
2029 
2030     @ForceInline
2031     static 
2032     void testVectorCastDoubleToDoubleFail(Species<Double> a, Species<Double> b, double[] input) {
2033         assert(input.length == a.length());
2034 
2035         DoubleVector av = DoubleVector.fromArray(a, input, 0);
2036         try {
2037             av.cast(b);
2038             Assert.fail(String.format(
2039                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
2040                     a, b));
2041         } catch (IllegalArgumentException e) {
2042         }
2043     }
2044 
2045     @Test(dataProvider = "byteUnaryOpProvider")
2046     static void testCastFromByte(IntFunction<byte[]> fa) {
2047         byte[] bin64 = fa.apply(bspec64.length());
2048         byte[] bin128 = fa.apply(bspec128.length());
2049         byte[] bin256 = fa.apply(bspec256.length());
2050         byte[] bin512 = fa.apply(bspec512.length());
2051 
2052         byte[] bout64 = new byte[bspec64.length()];


3040 
3041             testVectorCastDoubleToDoubleFail(dspec64, dspec128, din64);
3042             testVectorCastDoubleToDoubleFail(dspec64, dspec256, din64);
3043             testVectorCastDoubleToDoubleFail(dspec64, dspec512, din64);
3044 
3045             testVectorCastDoubleToDoubleFail(dspec128, dspec64, din128);
3046             testVectorCastDoubleToDoubleFail(dspec128, dspec256, din128);
3047             testVectorCastDoubleToDoubleFail(dspec128, dspec512, din128);
3048 
3049             testVectorCastDoubleToDoubleFail(dspec256, dspec64, din256);
3050             testVectorCastDoubleToDoubleFail(dspec256, dspec128, din256);
3051             testVectorCastDoubleToDoubleFail(dspec256, dspec512, din256);
3052 
3053             testVectorCastDoubleToDoubleFail(dspec512, dspec64, din512);
3054             testVectorCastDoubleToDoubleFail(dspec512, dspec128, din512);
3055             testVectorCastDoubleToDoubleFail(dspec512, dspec256, din512);
3056         }
3057     }
3058 
3059     static 
3060     void testVectorCastByteMaxToByte(Species<Byte> a, Species<Byte> b,
3061                                           byte[] input, byte[] output) {
3062         if (S_Max_BIT.bitSize() == b.length() * Byte.SIZE) {
3063             testVectorCastByteToByte(a, b, input, output);
3064         } else {
3065             testVectorCastByteToByteFail(a, b, input);
3066         }
3067     }
3068 
3069     static 
3070     void testVectorCastByteMaxToShort(Species<Byte> a, Species<Short> b,
3071                                            byte[] input, short[] output) {
3072         if (S_Max_BIT.bitSize() == b.length() * Byte.SIZE) {
3073             testVectorCastByteToShort(a, b, input, output);
3074         } else {
3075             testVectorCastByteToShortFail(a, b, input);
3076         }
3077     }
3078 
3079     static 
3080     void testVectorCastByteMaxToInt(Species<Byte> a, Species<Integer> b,
3081                                          byte[] input, int[] output) {
3082         if (S_Max_BIT.bitSize() == b.length() * Byte.SIZE) {
3083             testVectorCastByteToInt(a, b, input, output);
3084         } else {
3085             testVectorCastByteToIntFail(a, b, input);
3086         }
3087     }
3088 
3089     static 
3090     void testVectorCastByteMaxToLong(Species<Byte> a, Species<Long> b,
3091                                           byte[] input, long[] output) {
3092         if (S_Max_BIT.bitSize() == b.length() * Byte.SIZE) {
3093             testVectorCastByteToLong(a, b, input, output);
3094         } else {
3095             testVectorCastByteToLongFail(a, b, input);
3096         }
3097     }
3098 
3099     static 
3100     void testVectorCastByteMaxToFloat(Species<Byte> a, Species<Float> b,
3101                                            byte[] input, float[] output) {
3102         if (S_Max_BIT.bitSize() == b.length() * Byte.SIZE) {
3103             testVectorCastByteToFloat(a, b, input, output);
3104         } else {
3105             testVectorCastByteToFloatFail(a, b, input);
3106         }
3107     }
3108 
3109     static 
3110     void testVectorCastByteMaxToDouble(Species<Byte> a, Species<Double> b,
3111                                             byte[] input, double[] output) {
3112         if (S_Max_BIT.bitSize() == b.length() * Byte.SIZE) {
3113             testVectorCastByteToDouble(a, b, input, output);
3114         } else {
3115             testVectorCastByteToDoubleFail(a, b, input);
3116         }
3117     }
3118 
3119     static 
3120     void testVectorCastShortMaxToByte(Species<Short> a, Species<Byte> b,
3121                                            short[] input, byte[] output) {
3122         if (S_Max_BIT.bitSize() == b.length() * Short.SIZE) {
3123             testVectorCastShortToByte(a, b, input, output);
3124         } else {
3125             testVectorCastShortToByteFail(a, b, input);
3126         }
3127     }
3128 
3129     static 
3130     void testVectorCastShortMaxToShort(Species<Short> a, Species<Short> b,
3131                                             short[] input, short[] output) {
3132         if (S_Max_BIT.bitSize() == b.length() * Short.SIZE) {
3133             testVectorCastShortToShort(a, b, input, output);
3134         } else {
3135             testVectorCastShortToShortFail(a, b, input);
3136         }
3137     }
3138 
3139     static 
3140     void testVectorCastShortMaxToInt(Species<Short> a, Species<Integer> b,
3141                                           short[] input, int[] output) {
3142         if (S_Max_BIT.bitSize() == b.length() * Short.SIZE) {
3143             testVectorCastShortToInt(a, b, input, output);
3144         } else {
3145             testVectorCastShortToIntFail(a, b, input);
3146         }
3147     }
3148 
3149     static 
3150     void testVectorCastShortMaxToLong(Species<Short> a, Species<Long> b,
3151                                            short[] input, long[] output) {
3152         if (S_Max_BIT.bitSize() == b.length() * Short.SIZE) {
3153             testVectorCastShortToLong(a, b, input, output);
3154         } else {
3155             testVectorCastShortToLongFail(a, b, input);
3156         }
3157     }
3158 
3159     static 
3160     void testVectorCastShortMaxToFloat(Species<Short> a, Species<Float> b,
3161                                             short[] input, float[] output) {
3162         if (S_Max_BIT.bitSize() == b.length() * Short.SIZE) {
3163             testVectorCastShortToFloat(a, b, input, output);
3164         } else {
3165             testVectorCastShortToFloatFail(a, b, input);
3166         }
3167     }
3168 
3169     static 
3170     void testVectorCastShortMaxToDouble(Species<Short> a, Species<Double> b,
3171                                              short[] input, double[] output) {
3172         if (S_Max_BIT.bitSize() == b.length() * Short.SIZE) {
3173             testVectorCastShortToDouble(a, b, input, output);
3174         } else {
3175             testVectorCastShortToDoubleFail(a, b, input);
3176         }
3177     }
3178 
3179     static 
3180     void testVectorCastIntMaxToByte(Species<Integer> a, Species<Byte> b,
3181                                          int[] input, byte[] output) {
3182         if (S_Max_BIT.bitSize() == b.length() * Integer.SIZE) {
3183             testVectorCastIntToByte(a, b, input, output);
3184         } else {
3185             testVectorCastIntToByteFail(a, b, input);
3186         }
3187     }
3188 
3189     static 
3190     void testVectorCastIntMaxToShort(Species<Integer> a, Species<Short> b,
3191                                           int[] input, short[] output) {
3192         if (S_Max_BIT.bitSize() == b.length() * Integer.SIZE) {
3193             testVectorCastIntToShort(a, b, input, output);
3194         } else {
3195             testVectorCastIntToShortFail(a, b, input);
3196         }
3197     }
3198 
3199     static 
3200     void testVectorCastIntMaxToInt(Species<Integer> a, Species<Integer> b,
3201                                         int[] input, int[] output) {
3202         if (S_Max_BIT.bitSize() == b.length() * Integer.SIZE) {
3203             testVectorCastIntToInt(a, b, input, output);
3204         } else {
3205             testVectorCastIntToIntFail(a, b, input);
3206         }
3207     }
3208 
3209     static 
3210     void testVectorCastIntMaxToLong(Species<Integer> a, Species<Long> b,
3211                                          int[] input, long[] output) {
3212         if (S_Max_BIT.bitSize() == b.length() * Integer.SIZE) {
3213             testVectorCastIntToLong(a, b, input, output);
3214         } else {
3215             testVectorCastIntToLongFail(a, b, input);
3216         }
3217     }
3218 
3219     static 
3220     void testVectorCastIntMaxToFloat(Species<Integer> a, Species<Float> b,
3221                                           int[] input, float[] output) {
3222         if (S_Max_BIT.bitSize() == b.length() * Integer.SIZE) {
3223             testVectorCastIntToFloat(a, b, input, output);
3224         } else {
3225             testVectorCastIntToFloatFail(a, b, input);
3226         }
3227     }
3228 
3229     static 
3230     void testVectorCastIntMaxToDouble(Species<Integer> a, Species<Double> b,
3231                                            int[] input, double[] output) {
3232         if (S_Max_BIT.bitSize() == b.length() * Integer.SIZE) {
3233             testVectorCastIntToDouble(a, b, input, output);
3234         } else {
3235             testVectorCastIntToDoubleFail(a, b, input);
3236         }
3237     }
3238 
3239     static 
3240     void testVectorCastLongMaxToByte(Species<Long> a, Species<Byte> b,
3241                                           long[] input, byte[] output) {
3242         if (S_Max_BIT.bitSize() == b.length() * Long.SIZE) {
3243             testVectorCastLongToByte(a, b, input, output);
3244         } else {
3245             testVectorCastLongToByteFail(a, b, input);
3246         }
3247     }
3248 
3249     static 
3250     void testVectorCastLongMaxToShort(Species<Long> a, Species<Short> b,
3251                                            long[] input, short[] output) {
3252         if (S_Max_BIT.bitSize() == b.length() * Long.SIZE) {
3253             testVectorCastLongToShort(a, b, input, output);
3254         } else {
3255             testVectorCastLongToShortFail(a, b, input);
3256         }
3257     }
3258 
3259     static 
3260     void testVectorCastLongMaxToInt(Species<Long> a, Species<Integer> b,
3261                                          long[] input, int[] output) {
3262         if (S_Max_BIT.bitSize() == b.length() * Long.SIZE) {
3263             testVectorCastLongToInt(a, b, input, output);
3264         } else {
3265             testVectorCastLongToIntFail(a, b, input);
3266         }
3267     }
3268 
3269     static 
3270     void testVectorCastLongMaxToLong(Species<Long> a, Species<Long> b,
3271                                           long[] input, long[] output) {
3272         if (S_Max_BIT.bitSize() == b.length() * Long.SIZE) {
3273             testVectorCastLongToLong(a, b, input, output);
3274         } else {
3275             testVectorCastLongToLongFail(a, b, input);
3276         }
3277     }
3278 
3279     static 
3280     void testVectorCastLongMaxToFloat(Species<Long> a, Species<Float> b,
3281                                            long[] input, float[] output) {
3282         if (S_Max_BIT.bitSize() == b.length() * Long.SIZE) {
3283             testVectorCastLongToFloat(a, b, input, output);
3284         } else {
3285             testVectorCastLongToFloatFail(a, b, input);
3286         }
3287     }
3288 
3289     static 
3290     void testVectorCastLongMaxToDouble(Species<Long> a, Species<Double> b,
3291                                             long[] input, double[] output) {
3292         if (S_Max_BIT.bitSize() == b.length() * Long.SIZE) {
3293             testVectorCastLongToDouble(a, b, input, output);
3294         } else {
3295             testVectorCastLongToDoubleFail(a, b, input);
3296         }
3297     }
3298 
3299     static 
3300     void testVectorCastFloatMaxToByte(Species<Float> a, Species<Byte> b,
3301                                            float[] input, byte[] output) {
3302         if (S_Max_BIT.bitSize() == b.length() * Float.SIZE) {
3303             testVectorCastFloatToByte(a, b, input, output);
3304         } else {
3305             testVectorCastFloatToByteFail(a, b, input);
3306         }
3307     }
3308 
3309     static 
3310     void testVectorCastFloatMaxToShort(Species<Float> a, Species<Short> b,
3311                                             float[] input, short[] output) {
3312         if (S_Max_BIT.bitSize() == b.length() * Float.SIZE) {
3313             testVectorCastFloatToShort(a, b, input, output);
3314         } else {
3315             testVectorCastFloatToShortFail(a, b, input);
3316         }
3317     }
3318 
3319     static 
3320     void testVectorCastFloatMaxToInt(Species<Float> a, Species<Integer> b,
3321                                           float[] input, int[] output) {
3322         if (S_Max_BIT.bitSize() == b.length() * Float.SIZE) {
3323             testVectorCastFloatToInt(a, b, input, output);
3324         } else {
3325             testVectorCastFloatToIntFail(a, b, input);
3326         }
3327     }
3328 
3329     static 
3330     void testVectorCastFloatMaxToLong(Species<Float> a, Species<Long> b,
3331                                            float[] input, long[] output) {
3332         if (S_Max_BIT.bitSize() == b.length() * Float.SIZE) {
3333             testVectorCastFloatToLong(a, b, input, output);
3334         } else {
3335             testVectorCastFloatToLongFail(a, b, input);
3336         }
3337     }
3338 
3339     static 
3340     void testVectorCastFloatMaxToFloat(Species<Float> a, Species<Float> b,
3341                                             float[] input, float[] output) {
3342         if (S_Max_BIT.bitSize() == b.length() * Float.SIZE) {
3343             testVectorCastFloatToFloat(a, b, input, output);
3344         } else {
3345             testVectorCastFloatToFloatFail(a, b, input);
3346         }
3347     }
3348 
3349     static 
3350     void testVectorCastFloatMaxToDouble(Species<Float> a, Species<Double> b,
3351                                              float[] input, double[] output) {
3352         if (S_Max_BIT.bitSize() == b.length() * Float.SIZE) {
3353             testVectorCastFloatToDouble(a, b, input, output);
3354         } else {
3355             testVectorCastFloatToDoubleFail(a, b, input);
3356         }
3357     }
3358 
3359     static 
3360     void testVectorCastDoubleMaxToByte(Species<Double> a, Species<Byte> b,
3361                                             double[] input, byte[] output) {
3362         if (S_Max_BIT.bitSize() == b.length() * Double.SIZE) {
3363             testVectorCastDoubleToByte(a, b, input, output);
3364         } else {
3365             testVectorCastDoubleToByteFail(a, b, input);
3366         }
3367     }
3368 
3369     static 
3370     void testVectorCastDoubleMaxToShort(Species<Double> a, Species<Short> b,
3371                                              double[] input, short[] output) {
3372         if (S_Max_BIT.bitSize() == b.length() * Double.SIZE) {
3373             testVectorCastDoubleToShort(a, b, input, output);
3374         } else {
3375             testVectorCastDoubleToShortFail(a, b, input);
3376         }
3377     }
3378 
3379     static 
3380     void testVectorCastDoubleMaxToInt(Species<Double> a, Species<Integer> b,
3381                                            double[] input, int[] output) {
3382         if (S_Max_BIT.bitSize() == b.length() * Double.SIZE) {
3383             testVectorCastDoubleToInt(a, b, input, output);
3384         } else {
3385             testVectorCastDoubleToIntFail(a, b, input);
3386         }
3387     }
3388 
3389     static 
3390     void testVectorCastDoubleMaxToLong(Species<Double> a, Species<Long> b,
3391                                             double[] input, long[] output) {
3392         if (S_Max_BIT.bitSize() == b.length() * Double.SIZE) {
3393             testVectorCastDoubleToLong(a, b, input, output);
3394         } else {
3395             testVectorCastDoubleToLongFail(a, b, input);
3396         }
3397     }
3398 
3399     static 
3400     void testVectorCastDoubleMaxToFloat(Species<Double> a, Species<Float> b,
3401                                              double[] input, float[] output) {
3402         if (S_Max_BIT.bitSize() == b.length() * Double.SIZE) {
3403             testVectorCastDoubleToFloat(a, b, input, output);
3404         } else {
3405             testVectorCastDoubleToFloatFail(a, b, input);
3406         }
3407     }
3408 
3409     static 
3410     void testVectorCastDoubleMaxToDouble(Species<Double> a, Species<Double> b,
3411                                               double[] input, double[] output) {
3412         if (S_Max_BIT.bitSize() == b.length() * Double.SIZE) {
3413             testVectorCastDoubleToDouble(a, b, input, output);
3414         } else {
3415             testVectorCastDoubleToDoubleFail(a, b, input);
3416         }
3417     }
3418 
3419     @Test(dataProvider = "byteUnaryOpProvider")
3420     static void testCastFromByteMax(IntFunction<byte[]> fa) {
3421         byte[] binMax = fa.apply(bspecMax.length());
3422 
3423         byte[] bout64 = new byte[bspec64.length()];
3424         byte[] bout128 = new byte[bspec128.length()];
3425         byte[] bout256 = new byte[bspec256.length()];
3426         byte[] bout512 = new byte[bspec512.length()];
3427         byte[] boutMax = new byte[bspecMax.length()];
3428 
3429         short[] sout64 = new short[sspec64.length()];
3430         short[] sout128 = new short[sspec128.length()];


   1 import jdk.incubator.vector.*;
   2 import jdk.internal.vm.annotation.ForceInline;
   3 import org.testng.Assert;
   4 import org.testng.annotations.Test;
   5 import org.testng.annotations.DataProvider;
   6 
   7 import java.lang.invoke.MethodHandles;
   8 import java.lang.invoke.VarHandle;
   9 import java.util.Arrays;
  10 import java.util.List;
  11 import java.util.function.IntFunction;
  12 import jdk.incubator.vector.VectorShape;
  13 import jdk.incubator.vector.VectorSpecies;
  14 
  15 /**
  16  * @test
  17  * @modules jdk.incubator.vector
  18  * @modules java.base/jdk.internal.vm.annotation
  19  * @run testng/othervm --add-opens jdk.incubator.vector/jdk.incubator.vector=ALL-UNNAMED
  20  *      VectorReshapeTests
  21  */
  22 
  23 @Test
  24 public class VectorReshapeTests {
  25     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  26     static final int NUM_ITER = 200 * INVOC_COUNT;
  27 
  28     static final VectorShape S_Max_BIT = getMaxBit();
  29 
  30     static final VectorSpecies<Integer> ispec64 = IntVector.SPECIES_64;
  31     static final VectorSpecies<Float> fspec64 = FloatVector.SPECIES_64;
  32     static final VectorSpecies<Long> lspec64 = LongVector.SPECIES_64;
  33     static final VectorSpecies<Double> dspec64 = DoubleVector.SPECIES_64;
  34     static final VectorSpecies<Byte> bspec64 = ByteVector.SPECIES_64;
  35     static final VectorSpecies<Short> sspec64 = ShortVector.SPECIES_64;
  36 
  37     static final VectorSpecies<Integer> ispec128 = IntVector.SPECIES_128;
  38     static final VectorSpecies<Float> fspec128 = FloatVector.SPECIES_128;
  39     static final VectorSpecies<Long> lspec128 = LongVector.SPECIES_128;
  40     static final VectorSpecies<Double> dspec128 = DoubleVector.SPECIES_128;
  41     static final VectorSpecies<Byte> bspec128 = ByteVector.SPECIES_128;
  42     static final VectorSpecies<Short> sspec128 = ShortVector.SPECIES_128;
  43 
  44     static final VectorSpecies<Integer> ispec256 = IntVector.SPECIES_256;
  45     static final VectorSpecies<Float> fspec256 = FloatVector.SPECIES_256;
  46     static final VectorSpecies<Long> lspec256 = LongVector.SPECIES_256;
  47     static final VectorSpecies<Double> dspec256 = DoubleVector.SPECIES_256;
  48     static final VectorSpecies<Byte> bspec256 = ByteVector.SPECIES_256;
  49     static final VectorSpecies<Short> sspec256 = ShortVector.SPECIES_256;
  50 
  51     static final VectorSpecies<Integer> ispec512 = IntVector.SPECIES_512;
  52     static final VectorSpecies<Float> fspec512 = FloatVector.SPECIES_512;
  53     static final VectorSpecies<Long> lspec512 = LongVector.SPECIES_512;
  54     static final VectorSpecies<Double> dspec512 = DoubleVector.SPECIES_512;
  55     static final VectorSpecies<Byte> bspec512 = ByteVector.SPECIES_512;
  56     static final VectorSpecies<Short> sspec512 = ShortVector.SPECIES_512;
  57 
  58     static final VectorSpecies<Integer> ispecMax = IntVector.SPECIES_MAX;
  59     static final VectorSpecies<Float> fspecMax = FloatVector.SPECIES_MAX;
  60     static final VectorSpecies<Long> lspecMax = LongVector.SPECIES_MAX;
  61     static final VectorSpecies<Double> dspecMax = DoubleVector.SPECIES_MAX;
  62     static final VectorSpecies<Byte> bspecMax = ByteVector.SPECIES_MAX;
  63     static final VectorSpecies<Short> sspecMax = ShortVector.SPECIES_MAX;
  64 
  65     static VectorShape getMaxBit() {
  66         return VectorShape.S_Max_BIT;
  67     }
  68 
  69     static <T> IntFunction<T> withToString(String s, IntFunction<T> f) {
  70         return new IntFunction<T>() {
  71             @Override
  72             public T apply(int v) {
  73                 return f.apply(v);
  74             }
  75 
  76             @Override
  77             public String toString() {
  78                 return s;
  79             }
  80         };
  81     }
  82 
  83     interface ToByteF {
  84         byte apply(int i);
  85     }
  86 


 261         return FLOAT_GENERATORS.stream().
 262                 map(f -> new Object[]{f}).
 263                 toArray(Object[][]::new);
 264     }
 265 
 266     static final List<IntFunction<double[]>> DOUBLE_GENERATORS = List.of(
 267             withToString("double(i)", (int s) -> {
 268                 return fill_double(s, i -> (double)i);
 269             })
 270     );
 271 
 272     @DataProvider
 273     public Object[][] doubleUnaryOpProvider() {
 274         return DOUBLE_GENERATORS.stream().
 275                 map(f -> new Object[]{f}).
 276                 toArray(Object[][]::new);
 277     }
 278 
 279     @ForceInline
 280     static <E>
 281     void testVectorReshape(VectorSpecies<E> a, VectorSpecies<E> b, byte[] input, byte[] output) {
 282         Vector<E> av;
 283         Class<?> stype = a.elementType();
 284         if (stype == byte.class) {
 285            av =  (Vector) ByteVector.fromByteArray((VectorSpecies<Byte>)a, input, 0);
 286         } else if (stype == short.class) {
 287            av =  (Vector) ShortVector.fromByteArray((VectorSpecies<Short>)a, input, 0);
 288         } else if (stype == int.class) {
 289            av =  (Vector) IntVector.fromByteArray((VectorSpecies<Integer>)a, input, 0);
 290         } else if (stype == long.class) {
 291            av =  (Vector) LongVector.fromByteArray((VectorSpecies<Long>)a, input, 0);
 292         } else if (stype == float.class) {
 293            av =  (Vector) FloatVector.fromByteArray((VectorSpecies<Float>)a, input, 0);
 294         } else if (stype == double.class) {
 295            av =  (Vector) DoubleVector.fromByteArray((VectorSpecies<Double>)a, input, 0);
 296         } else {
 297             throw new UnsupportedOperationException("Bad lane type");
 298         } 
 299         Vector<E> bv = av.reshape(b);
 300         bv.intoByteArray(output, 0);
 301 
 302         byte[] expected = Arrays.copyOf(input, output.length);
 303 
 304 
 305         Assert.assertEquals(expected, output);
 306     }
 307 
 308     @Test(dataProvider = "byteUnaryOpProvider")
 309     static void testReshapeByte(IntFunction<byte[]> fa) {
 310         byte[] bin64 = fa.apply(64/Byte.SIZE);
 311         byte[] bin128 = fa.apply(128/Byte.SIZE);
 312         byte[] bin256 = fa.apply(256/Byte.SIZE);
 313         byte[] bin512 = fa.apply(512/Byte.SIZE);
 314         byte[] binMax = fa.apply(S_Max_BIT.bitSize()/Byte.SIZE);
 315         byte[] bout64 = new byte[bin64.length];


 566             testVectorReshape(dspec256, dspec256, bin256, bout256);
 567             testVectorReshape(dspec256, dspec512, bin256, bout512);
 568             testVectorReshape(dspec256, dspecMax, bin256, boutMax);
 569 
 570             testVectorReshape(dspec512, dspec64, bin512, bout64);
 571             testVectorReshape(dspec512, dspec128, bin512, bout128);
 572             testVectorReshape(dspec512, dspec256, bin512, bout256);
 573             testVectorReshape(dspec512, dspec512, bin512, bout512);
 574             testVectorReshape(dspec512, dspecMax, bin512, boutMax);
 575 
 576             testVectorReshape(dspecMax, dspec64, binMax, bout64);
 577             testVectorReshape(dspecMax, dspec128, binMax, bout128);
 578             testVectorReshape(dspecMax, dspec256, binMax, bout256);
 579             testVectorReshape(dspecMax, dspec512, binMax, bout512);
 580             testVectorReshape(dspecMax, dspecMax, binMax, boutMax);
 581         }
 582     }
 583 
 584     @ForceInline
 585     static <E,F>
 586     void testVectorRebracket(VectorSpecies<E> a, VectorSpecies<F> b, byte[] input, byte[] output) {
 587         assert(input.length == output.length);
 588         Vector<E> av;
 589 
 590         Class<?> stype = a.elementType();
 591         if (stype == byte.class) {
 592            av =  (Vector) ByteVector.fromByteArray((VectorSpecies<Byte>)a, input, 0);
 593         } else if (stype == short.class) {
 594            av =  (Vector) ShortVector.fromByteArray((VectorSpecies<Short>)a, input, 0);
 595         } else if (stype == int.class) {
 596            av =  (Vector) IntVector.fromByteArray((VectorSpecies<Integer>)a, input, 0);
 597         } else if (stype == long.class) {
 598            av =  (Vector) LongVector.fromByteArray((VectorSpecies<Long>)a, input, 0);
 599         } else if (stype == float.class) {
 600            av =  (Vector) FloatVector.fromByteArray((VectorSpecies<Float>)a, input, 0);
 601         } else if (stype == double.class) {
 602            av =  (Vector) DoubleVector.fromByteArray((VectorSpecies<Double>)a, input, 0);
 603         } else {
 604             throw new UnsupportedOperationException("Bad lane type");
 605         } 
 606         Vector<F> bv = av.reinterpret(b);
 607         bv.intoByteArray(output, 0);
 608 
 609         Assert.assertEquals(input, output);
 610     }
 611 
 612     @Test(dataProvider = "byteUnaryOpProvider")
 613     static void testRebracket64(IntFunction<byte[]> fa) {
 614         byte[] barr = fa.apply(64/Byte.SIZE);
 615         byte[] bout = new byte[barr.length];
 616         for (int i = 0; i < NUM_ITER; i++) {
 617             testVectorRebracket(bspec64, bspec64, barr, bout);
 618             testVectorRebracket(bspec64, sspec64, barr, bout);
 619             testVectorRebracket(bspec64, ispec64, barr, bout);
 620             testVectorRebracket(bspec64, lspec64, barr, bout);
 621             testVectorRebracket(bspec64, fspec64, barr, bout);
 622             testVectorRebracket(bspec64, dspec64, barr, bout);


 839             testVectorRebracket(lspecMax, dspecMax, barr, bout);
 840 
 841             testVectorRebracket(fspecMax, bspecMax, barr, bout);
 842             testVectorRebracket(fspecMax, sspecMax, barr, bout);
 843             testVectorRebracket(fspecMax, ispecMax, barr, bout);
 844             testVectorRebracket(fspecMax, lspecMax, barr, bout);
 845             testVectorRebracket(fspecMax, fspecMax, barr, bout);
 846             testVectorRebracket(fspecMax, dspecMax, barr, bout);
 847 
 848             testVectorRebracket(dspecMax, bspecMax, barr, bout);
 849             testVectorRebracket(dspecMax, sspecMax, barr, bout);
 850             testVectorRebracket(dspecMax, ispecMax, barr, bout);
 851             testVectorRebracket(dspecMax, lspecMax, barr, bout);
 852             testVectorRebracket(dspecMax, fspecMax, barr, bout);
 853             testVectorRebracket(dspecMax, dspecMax, barr, bout);
 854         }
 855     }
 856 
 857     @ForceInline
 858     static 
 859     void testVectorCastByteToFloat(VectorSpecies<Byte> a, VectorSpecies<Float> b, byte[] input, float[] output) {
 860         assert(input.length == a.length());
 861         assert(output.length == b.length());
 862 
 863         ByteVector av = ByteVector.fromArray(a, input, 0);
 864         FloatVector bv = (FloatVector) av.cast(b);
 865         bv.intoArray(output, 0);
 866 
 867         for (int i = 0; i < Math.min(input.length, output.length); i++) {
 868             Assert.assertEquals(output[i], (float)input[i]);
 869         }
 870         for(int i = input.length; i < output.length; i++) {
 871             Assert.assertEquals(output[i], (float)0);
 872         }
 873     }
 874 
 875     @ForceInline
 876     static 
 877     void testVectorCastByteToFloatFail(VectorSpecies<Byte> a, VectorSpecies<Float> b, byte[] input) {
 878         assert(input.length == a.length());
 879 
 880         ByteVector av = ByteVector.fromArray(a, input, 0);
 881         try {
 882             av.cast(b);
 883             Assert.fail(String.format(
 884                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
 885                     a, b));
 886         } catch (IllegalArgumentException e) {
 887         }
 888     }
 889 
 890     @ForceInline
 891     static 
 892     void testVectorCastShortToFloat(VectorSpecies<Short> a, VectorSpecies<Float> b, short[] input, float[] output) {
 893         assert(input.length == a.length());
 894         assert(output.length == b.length());
 895 
 896         ShortVector av = ShortVector.fromArray(a, input, 0);
 897         FloatVector bv = (FloatVector) av.cast(b);
 898         bv.intoArray(output, 0);
 899 
 900         for (int i = 0; i < Math.min(input.length, output.length); i++) {
 901             Assert.assertEquals(output[i], (float)input[i]);
 902         }
 903         for(int i = input.length; i < output.length; i++) {
 904             Assert.assertEquals(output[i], (float)0);
 905         }
 906     }
 907 
 908     @ForceInline
 909     static 
 910     void testVectorCastShortToFloatFail(VectorSpecies<Short> a, VectorSpecies<Float> b, short[] input) {
 911         assert(input.length == a.length());
 912 
 913         ShortVector av = ShortVector.fromArray(a, input, 0);
 914         try {
 915             av.cast(b);
 916             Assert.fail(String.format(
 917                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
 918                     a, b));
 919         } catch (IllegalArgumentException e) {
 920         }
 921     }
 922 
 923     @ForceInline
 924     static 
 925     void testVectorCastIntToFloat(VectorSpecies<Integer> a, VectorSpecies<Float> b, int[] input, float[] output) {
 926         assert(input.length == a.length());
 927         assert(output.length == b.length());
 928 
 929         IntVector av = IntVector.fromArray(a, input, 0);
 930         FloatVector bv = (FloatVector) av.cast(b);
 931         bv.intoArray(output, 0);
 932 
 933         for (int i = 0; i < Math.min(input.length, output.length); i++) {
 934             Assert.assertEquals(output[i], (float)input[i]);
 935         }
 936         for(int i = input.length; i < output.length; i++) {
 937             Assert.assertEquals(output[i], (float)0);
 938         }
 939     }
 940 
 941     @ForceInline
 942     static 
 943     void testVectorCastIntToFloatFail(VectorSpecies<Integer> a, VectorSpecies<Float> b, int[] input) {
 944         assert(input.length == a.length());
 945 
 946         IntVector av = IntVector.fromArray(a, input, 0);
 947         try {
 948             av.cast(b);
 949             Assert.fail(String.format(
 950                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
 951                     a, b));
 952         } catch (IllegalArgumentException e) {
 953         }
 954     }
 955 
 956     @ForceInline
 957     static 
 958     void testVectorCastLongToFloat(VectorSpecies<Long> a, VectorSpecies<Float> b, long[] input, float[] output) {
 959         assert(input.length == a.length());
 960         assert(output.length == b.length());
 961 
 962         LongVector av = LongVector.fromArray(a, input, 0);
 963         FloatVector bv = (FloatVector) av.cast(b);
 964         bv.intoArray(output, 0);
 965 
 966         for (int i = 0; i < Math.min(input.length, output.length); i++) {
 967             Assert.assertEquals(output[i], (float)input[i]);
 968         }
 969         for(int i = input.length; i < output.length; i++) {
 970             Assert.assertEquals(output[i], (float)0);
 971         }
 972     }
 973 
 974     @ForceInline
 975     static 
 976     void testVectorCastLongToFloatFail(VectorSpecies<Long> a, VectorSpecies<Float> b, long[] input) {
 977         assert(input.length == a.length());
 978 
 979         LongVector av = LongVector.fromArray(a, input, 0);
 980         try {
 981             av.cast(b);
 982             Assert.fail(String.format(
 983                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
 984                     a, b));
 985         } catch (IllegalArgumentException e) {
 986         }
 987     }
 988 
 989     @ForceInline
 990     static 
 991     void testVectorCastFloatToFloat(VectorSpecies<Float> a, VectorSpecies<Float> b, float[] input, float[] output) {
 992         assert(input.length == a.length());
 993         assert(output.length == b.length());
 994 
 995         FloatVector av = FloatVector.fromArray(a, input, 0);
 996         FloatVector bv = (FloatVector) av.cast(b);
 997         bv.intoArray(output, 0);
 998 
 999         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1000             Assert.assertEquals(output[i], (float)input[i]);
1001         }
1002         for(int i = input.length; i < output.length; i++) {
1003             Assert.assertEquals(output[i], (float)0);
1004         }
1005     }
1006 
1007     @ForceInline
1008     static 
1009     void testVectorCastFloatToFloatFail(VectorSpecies<Float> a, VectorSpecies<Float> b, float[] input) {
1010         assert(input.length == a.length());
1011 
1012         FloatVector av = FloatVector.fromArray(a, input, 0);
1013         try {
1014             av.cast(b);
1015             Assert.fail(String.format(
1016                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1017                     a, b));
1018         } catch (IllegalArgumentException e) {
1019         }
1020     }
1021 
1022     @ForceInline
1023     static 
1024     void testVectorCastDoubleToFloat(VectorSpecies<Double> a, VectorSpecies<Float> b, double[] input, float[] output) {
1025         assert(input.length == a.length());
1026         assert(output.length == b.length());
1027 
1028         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1029         FloatVector bv = (FloatVector) av.cast(b);
1030         bv.intoArray(output, 0);
1031 
1032         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1033             Assert.assertEquals(output[i], (float)input[i]);
1034         }
1035         for(int i = input.length; i < output.length; i++) {
1036             Assert.assertEquals(output[i], (float)0);
1037         }
1038     }
1039 
1040     @ForceInline
1041     static 
1042     void testVectorCastDoubleToFloatFail(VectorSpecies<Double> a, VectorSpecies<Float> b, double[] input) {
1043         assert(input.length == a.length());
1044 
1045         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1046         try {
1047             av.cast(b);
1048             Assert.fail(String.format(
1049                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1050                     a, b));
1051         } catch (IllegalArgumentException e) {
1052         }
1053     }
1054 
1055     @ForceInline
1056     static 
1057     void testVectorCastByteToByte(VectorSpecies<Byte> a, VectorSpecies<Byte> b, byte[] input, byte[] output) {
1058         assert(input.length == a.length());
1059         assert(output.length == b.length());
1060 
1061         ByteVector av = ByteVector.fromArray(a, input, 0);
1062         ByteVector bv = (ByteVector) av.cast(b);
1063         bv.intoArray(output, 0);
1064 
1065         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1066             Assert.assertEquals(output[i], (byte)input[i]);
1067         }
1068         for(int i = input.length; i < output.length; i++) {
1069             Assert.assertEquals(output[i], (byte)0);
1070         }
1071     }
1072 
1073     @ForceInline
1074     static 
1075     void testVectorCastByteToByteFail(VectorSpecies<Byte> a, VectorSpecies<Byte> b, byte[] input) {
1076         assert(input.length == a.length());
1077 
1078         ByteVector av = ByteVector.fromArray(a, input, 0);
1079         try {
1080             av.cast(b);
1081             Assert.fail(String.format(
1082                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1083                     a, b));
1084         } catch (IllegalArgumentException e) {
1085         }
1086     }
1087 
1088     @ForceInline
1089     static 
1090     void testVectorCastShortToByte(VectorSpecies<Short> a, VectorSpecies<Byte> b, short[] input, byte[] output) {
1091         assert(input.length == a.length());
1092         assert(output.length == b.length());
1093 
1094         ShortVector av = ShortVector.fromArray(a, input, 0);
1095         ByteVector bv = (ByteVector) av.cast(b);
1096         bv.intoArray(output, 0);
1097 
1098         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1099             Assert.assertEquals(output[i], (byte)input[i]);
1100         }
1101         for(int i = input.length; i < output.length; i++) {
1102             Assert.assertEquals(output[i], (byte)0);
1103         }
1104     }
1105 
1106     @ForceInline
1107     static 
1108     void testVectorCastShortToByteFail(VectorSpecies<Short> a, VectorSpecies<Byte> b, short[] input) {
1109         assert(input.length == a.length());
1110 
1111         ShortVector av = ShortVector.fromArray(a, input, 0);
1112         try {
1113             av.cast(b);
1114             Assert.fail(String.format(
1115                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1116                     a, b));
1117         } catch (IllegalArgumentException e) {
1118         }
1119     }
1120 
1121     @ForceInline
1122     static 
1123     void testVectorCastIntToByte(VectorSpecies<Integer> a, VectorSpecies<Byte> b, int[] input, byte[] output) {
1124         assert(input.length == a.length());
1125         assert(output.length == b.length());
1126 
1127         IntVector av = IntVector.fromArray(a, input, 0);
1128         ByteVector bv = (ByteVector) av.cast(b);
1129         bv.intoArray(output, 0);
1130 
1131         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1132             Assert.assertEquals(output[i], (byte)input[i]);
1133         }
1134         for(int i = input.length; i < output.length; i++) {
1135             Assert.assertEquals(output[i], (byte)0);
1136         }
1137     }
1138 
1139     @ForceInline
1140     static 
1141     void testVectorCastIntToByteFail(VectorSpecies<Integer> a, VectorSpecies<Byte> b, int[] input) {
1142         assert(input.length == a.length());
1143 
1144         IntVector av = IntVector.fromArray(a, input, 0);
1145         try {
1146             av.cast(b);
1147             Assert.fail(String.format(
1148                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1149                     a, b));
1150         } catch (IllegalArgumentException e) {
1151         }
1152     }
1153 
1154     @ForceInline
1155     static 
1156     void testVectorCastLongToByte(VectorSpecies<Long> a, VectorSpecies<Byte> b, long[] input, byte[] output) {
1157         assert(input.length == a.length());
1158         assert(output.length == b.length());
1159 
1160         LongVector av = LongVector.fromArray(a, input, 0);
1161         ByteVector bv = (ByteVector) av.cast(b);
1162         bv.intoArray(output, 0);
1163 
1164         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1165             Assert.assertEquals(output[i], (byte)input[i]);
1166         }
1167         for(int i = input.length; i < output.length; i++) {
1168             Assert.assertEquals(output[i], (byte)0);
1169         }
1170     }
1171 
1172     @ForceInline
1173     static 
1174     void testVectorCastLongToByteFail(VectorSpecies<Long> a, VectorSpecies<Byte> b, long[] input) {
1175         assert(input.length == a.length());
1176 
1177         LongVector av = LongVector.fromArray(a, input, 0);
1178         try {
1179             av.cast(b);
1180             Assert.fail(String.format(
1181                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1182                     a, b));
1183         } catch (IllegalArgumentException e) {
1184         }
1185     }
1186 
1187     @ForceInline
1188     static 
1189     void testVectorCastFloatToByte(VectorSpecies<Float> a, VectorSpecies<Byte> b, float[] input, byte[] output) {
1190         assert(input.length == a.length());
1191         assert(output.length == b.length());
1192 
1193         FloatVector av = FloatVector.fromArray(a, input, 0);
1194         ByteVector bv = (ByteVector) av.cast(b);
1195         bv.intoArray(output, 0);
1196 
1197         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1198             Assert.assertEquals(output[i], (byte)input[i]);
1199         }
1200         for(int i = input.length; i < output.length; i++) {
1201             Assert.assertEquals(output[i], (byte)0);
1202         }
1203     }
1204 
1205     @ForceInline
1206     static 
1207     void testVectorCastFloatToByteFail(VectorSpecies<Float> a, VectorSpecies<Byte> b, float[] input) {
1208         assert(input.length == a.length());
1209 
1210         FloatVector av = FloatVector.fromArray(a, input, 0);
1211         try {
1212             av.cast(b);
1213             Assert.fail(String.format(
1214                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1215                     a, b));
1216         } catch (IllegalArgumentException e) {
1217         }
1218     }
1219 
1220     @ForceInline
1221     static 
1222     void testVectorCastDoubleToByte(VectorSpecies<Double> a, VectorSpecies<Byte> b, double[] input, byte[] output) {
1223         assert(input.length == a.length());
1224         assert(output.length == b.length());
1225 
1226         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1227         ByteVector bv = (ByteVector) av.cast(b);
1228         bv.intoArray(output, 0);
1229 
1230         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1231             Assert.assertEquals(output[i], (byte)input[i]);
1232         }
1233         for(int i = input.length; i < output.length; i++) {
1234             Assert.assertEquals(output[i], (byte)0);
1235         }
1236     }
1237 
1238     @ForceInline
1239     static 
1240     void testVectorCastDoubleToByteFail(VectorSpecies<Double> a, VectorSpecies<Byte> b, double[] input) {
1241         assert(input.length == a.length());
1242 
1243         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1244         try {
1245             av.cast(b);
1246             Assert.fail(String.format(
1247                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1248                     a, b));
1249         } catch (IllegalArgumentException e) {
1250         }
1251     }
1252 
1253     @ForceInline
1254     static 
1255     void testVectorCastByteToShort(VectorSpecies<Byte> a, VectorSpecies<Short> b, byte[] input, short[] output) {
1256         assert(input.length == a.length());
1257         assert(output.length == b.length());
1258 
1259         ByteVector av = ByteVector.fromArray(a, input, 0);
1260         ShortVector bv = (ShortVector) av.cast(b);
1261         bv.intoArray(output, 0);
1262 
1263         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1264             Assert.assertEquals(output[i], (short)input[i]);
1265         }
1266         for(int i = input.length; i < output.length; i++) {
1267             Assert.assertEquals(output[i], (short)0);
1268         }
1269     }
1270 
1271     @ForceInline
1272     static 
1273     void testVectorCastByteToShortFail(VectorSpecies<Byte> a, VectorSpecies<Short> b, byte[] input) {
1274         assert(input.length == a.length());
1275 
1276         ByteVector av = ByteVector.fromArray(a, input, 0);
1277         try {
1278             av.cast(b);
1279             Assert.fail(String.format(
1280                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1281                     a, b));
1282         } catch (IllegalArgumentException e) {
1283         }
1284     }
1285 
1286     @ForceInline
1287     static 
1288     void testVectorCastShortToShort(VectorSpecies<Short> a, VectorSpecies<Short> b, short[] input, short[] output) {
1289         assert(input.length == a.length());
1290         assert(output.length == b.length());
1291 
1292         ShortVector av = ShortVector.fromArray(a, input, 0);
1293         ShortVector bv = (ShortVector) av.cast(b);
1294         bv.intoArray(output, 0);
1295 
1296         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1297             Assert.assertEquals(output[i], (short)input[i]);
1298         }
1299         for(int i = input.length; i < output.length; i++) {
1300             Assert.assertEquals(output[i], (short)0);
1301         }
1302     }
1303 
1304     @ForceInline
1305     static 
1306     void testVectorCastShortToShortFail(VectorSpecies<Short> a, VectorSpecies<Short> b, short[] input) {
1307         assert(input.length == a.length());
1308 
1309         ShortVector av = ShortVector.fromArray(a, input, 0);
1310         try {
1311             av.cast(b);
1312             Assert.fail(String.format(
1313                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1314                     a, b));
1315         } catch (IllegalArgumentException e) {
1316         }
1317     }
1318 
1319     @ForceInline
1320     static 
1321     void testVectorCastIntToShort(VectorSpecies<Integer> a, VectorSpecies<Short> b, int[] input, short[] output) {
1322         assert(input.length == a.length());
1323         assert(output.length == b.length());
1324 
1325         IntVector av = IntVector.fromArray(a, input, 0);
1326         ShortVector bv = (ShortVector) av.cast(b);
1327         bv.intoArray(output, 0);
1328 
1329         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1330             Assert.assertEquals(output[i], (short)input[i]);
1331         }
1332         for(int i = input.length; i < output.length; i++) {
1333             Assert.assertEquals(output[i], (short)0);
1334         }
1335     }
1336 
1337     @ForceInline
1338     static 
1339     void testVectorCastIntToShortFail(VectorSpecies<Integer> a, VectorSpecies<Short> b, int[] input) {
1340         assert(input.length == a.length());
1341 
1342         IntVector av = IntVector.fromArray(a, input, 0);
1343         try {
1344             av.cast(b);
1345             Assert.fail(String.format(
1346                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1347                     a, b));
1348         } catch (IllegalArgumentException e) {
1349         }
1350     }
1351 
1352     @ForceInline
1353     static 
1354     void testVectorCastLongToShort(VectorSpecies<Long> a, VectorSpecies<Short> b, long[] input, short[] output) {
1355         assert(input.length == a.length());
1356         assert(output.length == b.length());
1357 
1358         LongVector av = LongVector.fromArray(a, input, 0);
1359         ShortVector bv = (ShortVector) av.cast(b);
1360         bv.intoArray(output, 0);
1361 
1362         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1363             Assert.assertEquals(output[i], (short)input[i]);
1364         }
1365         for(int i = input.length; i < output.length; i++) {
1366             Assert.assertEquals(output[i], (short)0);
1367         }
1368     }
1369 
1370     @ForceInline
1371     static 
1372     void testVectorCastLongToShortFail(VectorSpecies<Long> a, VectorSpecies<Short> b, long[] input) {
1373         assert(input.length == a.length());
1374 
1375         LongVector av = LongVector.fromArray(a, input, 0);
1376         try {
1377             av.cast(b);
1378             Assert.fail(String.format(
1379                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1380                     a, b));
1381         } catch (IllegalArgumentException e) {
1382         }
1383     }
1384 
1385     @ForceInline
1386     static 
1387     void testVectorCastFloatToShort(VectorSpecies<Float> a, VectorSpecies<Short> b, float[] input, short[] output) {
1388         assert(input.length == a.length());
1389         assert(output.length == b.length());
1390 
1391         FloatVector av = FloatVector.fromArray(a, input, 0);
1392         ShortVector bv = (ShortVector) av.cast(b);
1393         bv.intoArray(output, 0);
1394 
1395         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1396             Assert.assertEquals(output[i], (short)input[i]);
1397         }
1398         for(int i = input.length; i < output.length; i++) {
1399             Assert.assertEquals(output[i], (short)0);
1400         }
1401     }
1402 
1403     @ForceInline
1404     static 
1405     void testVectorCastFloatToShortFail(VectorSpecies<Float> a, VectorSpecies<Short> b, float[] input) {
1406         assert(input.length == a.length());
1407 
1408         FloatVector av = FloatVector.fromArray(a, input, 0);
1409         try {
1410             av.cast(b);
1411             Assert.fail(String.format(
1412                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1413                     a, b));
1414         } catch (IllegalArgumentException e) {
1415         }
1416     }
1417 
1418     @ForceInline
1419     static 
1420     void testVectorCastDoubleToShort(VectorSpecies<Double> a, VectorSpecies<Short> b, double[] input, short[] output) {
1421         assert(input.length == a.length());
1422         assert(output.length == b.length());
1423 
1424         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1425         ShortVector bv = (ShortVector) av.cast(b);
1426         bv.intoArray(output, 0);
1427 
1428         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1429             Assert.assertEquals(output[i], (short)input[i]);
1430         }
1431         for(int i = input.length; i < output.length; i++) {
1432             Assert.assertEquals(output[i], (short)0);
1433         }
1434     }
1435 
1436     @ForceInline
1437     static 
1438     void testVectorCastDoubleToShortFail(VectorSpecies<Double> a, VectorSpecies<Short> b, double[] input) {
1439         assert(input.length == a.length());
1440 
1441         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1442         try {
1443             av.cast(b);
1444             Assert.fail(String.format(
1445                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1446                     a, b));
1447         } catch (IllegalArgumentException e) {
1448         }
1449     }
1450 
1451     @ForceInline
1452     static 
1453     void testVectorCastByteToInt(VectorSpecies<Byte> a, VectorSpecies<Integer> b, byte[] input, int[] output) {
1454         assert(input.length == a.length());
1455         assert(output.length == b.length());
1456 
1457         ByteVector av = ByteVector.fromArray(a, input, 0);
1458         IntVector bv = (IntVector) av.cast(b);
1459         bv.intoArray(output, 0);
1460 
1461         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1462             Assert.assertEquals(output[i], (int)input[i]);
1463         }
1464         for(int i = input.length; i < output.length; i++) {
1465             Assert.assertEquals(output[i], (int)0);
1466         }
1467     }
1468 
1469     @ForceInline
1470     static 
1471     void testVectorCastByteToIntFail(VectorSpecies<Byte> a, VectorSpecies<Integer> b, byte[] input) {
1472         assert(input.length == a.length());
1473 
1474         ByteVector av = ByteVector.fromArray(a, input, 0);
1475         try {
1476             av.cast(b);
1477             Assert.fail(String.format(
1478                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1479                     a, b));
1480         } catch (IllegalArgumentException e) {
1481         }
1482     }
1483 
1484     @ForceInline
1485     static 
1486     void testVectorCastShortToInt(VectorSpecies<Short> a, VectorSpecies<Integer> b, short[] input, int[] output) {
1487         assert(input.length == a.length());
1488         assert(output.length == b.length());
1489 
1490         ShortVector av = ShortVector.fromArray(a, input, 0);
1491         IntVector bv = (IntVector) av.cast(b);
1492         bv.intoArray(output, 0);
1493 
1494         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1495             Assert.assertEquals(output[i], (int)input[i]);
1496         }
1497         for(int i = input.length; i < output.length; i++) {
1498             Assert.assertEquals(output[i], (int)0);
1499         }
1500     }
1501 
1502     @ForceInline
1503     static 
1504     void testVectorCastShortToIntFail(VectorSpecies<Short> a, VectorSpecies<Integer> b, short[] input) {
1505         assert(input.length == a.length());
1506 
1507         ShortVector av = ShortVector.fromArray(a, input, 0);
1508         try {
1509             av.cast(b);
1510             Assert.fail(String.format(
1511                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1512                     a, b));
1513         } catch (IllegalArgumentException e) {
1514         }
1515     }
1516 
1517     @ForceInline
1518     static 
1519     void testVectorCastIntToInt(VectorSpecies<Integer> a, VectorSpecies<Integer> b, int[] input, int[] output) {
1520         assert(input.length == a.length());
1521         assert(output.length == b.length());
1522 
1523         IntVector av = IntVector.fromArray(a, input, 0);
1524         IntVector bv = (IntVector) av.cast(b);
1525         bv.intoArray(output, 0);
1526 
1527         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1528             Assert.assertEquals(output[i], (int)input[i]);
1529         }
1530         for(int i = input.length; i < output.length; i++) {
1531             Assert.assertEquals(output[i], (int)0);
1532         }
1533     }
1534 
1535     @ForceInline
1536     static 
1537     void testVectorCastIntToIntFail(VectorSpecies<Integer> a, VectorSpecies<Integer> b, int[] input) {
1538         assert(input.length == a.length());
1539 
1540         IntVector av = IntVector.fromArray(a, input, 0);
1541         try {
1542             av.cast(b);
1543             Assert.fail(String.format(
1544                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1545                     a, b));
1546         } catch (IllegalArgumentException e) {
1547         }
1548     }
1549 
1550     @ForceInline
1551     static 
1552     void testVectorCastLongToInt(VectorSpecies<Long> a, VectorSpecies<Integer> b, long[] input, int[] output) {
1553         assert(input.length == a.length());
1554         assert(output.length == b.length());
1555 
1556         LongVector av = LongVector.fromArray(a, input, 0);
1557         IntVector bv = (IntVector) av.cast(b);
1558         bv.intoArray(output, 0);
1559 
1560         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1561             Assert.assertEquals(output[i], (int)input[i]);
1562         }
1563         for(int i = input.length; i < output.length; i++) {
1564             Assert.assertEquals(output[i], (int)0);
1565         }
1566     }
1567 
1568     @ForceInline
1569     static 
1570     void testVectorCastLongToIntFail(VectorSpecies<Long> a, VectorSpecies<Integer> b, long[] input) {
1571         assert(input.length == a.length());
1572 
1573         LongVector av = LongVector.fromArray(a, input, 0);
1574         try {
1575             av.cast(b);
1576             Assert.fail(String.format(
1577                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1578                     a, b));
1579         } catch (IllegalArgumentException e) {
1580         }
1581     }
1582 
1583     @ForceInline
1584     static 
1585     void testVectorCastFloatToInt(VectorSpecies<Float> a, VectorSpecies<Integer> b, float[] input, int[] output) {
1586         assert(input.length == a.length());
1587         assert(output.length == b.length());
1588 
1589         FloatVector av = FloatVector.fromArray(a, input, 0);
1590         IntVector bv = (IntVector) av.cast(b);
1591         bv.intoArray(output, 0);
1592 
1593         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1594             Assert.assertEquals(output[i], (int)input[i]);
1595         }
1596         for(int i = input.length; i < output.length; i++) {
1597             Assert.assertEquals(output[i], (int)0);
1598         }
1599     }
1600 
1601     @ForceInline
1602     static 
1603     void testVectorCastFloatToIntFail(VectorSpecies<Float> a, VectorSpecies<Integer> b, float[] input) {
1604         assert(input.length == a.length());
1605 
1606         FloatVector av = FloatVector.fromArray(a, input, 0);
1607         try {
1608             av.cast(b);
1609             Assert.fail(String.format(
1610                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1611                     a, b));
1612         } catch (IllegalArgumentException e) {
1613         }
1614     }
1615 
1616     @ForceInline
1617     static 
1618     void testVectorCastDoubleToInt(VectorSpecies<Double> a, VectorSpecies<Integer> b, double[] input, int[] output) {
1619         assert(input.length == a.length());
1620         assert(output.length == b.length());
1621 
1622         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1623         IntVector bv = (IntVector) av.cast(b);
1624         bv.intoArray(output, 0);
1625 
1626         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1627             Assert.assertEquals(output[i], (int)input[i]);
1628         }
1629         for(int i = input.length; i < output.length; i++) {
1630             Assert.assertEquals(output[i], (int)0);
1631         }
1632     }
1633 
1634     @ForceInline
1635     static 
1636     void testVectorCastDoubleToIntFail(VectorSpecies<Double> a, VectorSpecies<Integer> b, double[] input) {
1637         assert(input.length == a.length());
1638 
1639         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1640         try {
1641             av.cast(b);
1642             Assert.fail(String.format(
1643                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1644                     a, b));
1645         } catch (IllegalArgumentException e) {
1646         }
1647     }
1648 
1649     @ForceInline
1650     static 
1651     void testVectorCastByteToLong(VectorSpecies<Byte> a, VectorSpecies<Long> b, byte[] input, long[] output) {
1652         assert(input.length == a.length());
1653         assert(output.length == b.length());
1654 
1655         ByteVector av = ByteVector.fromArray(a, input, 0);
1656         LongVector bv = (LongVector) av.cast(b);
1657         bv.intoArray(output, 0);
1658 
1659         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1660             Assert.assertEquals(output[i], (long)input[i]);
1661         }
1662         for(int i = input.length; i < output.length; i++) {
1663             Assert.assertEquals(output[i], (long)0);
1664         }
1665     }
1666 
1667     @ForceInline
1668     static 
1669     void testVectorCastByteToLongFail(VectorSpecies<Byte> a, VectorSpecies<Long> b, byte[] input) {
1670         assert(input.length == a.length());
1671 
1672         ByteVector av = ByteVector.fromArray(a, input, 0);
1673         try {
1674             av.cast(b);
1675             Assert.fail(String.format(
1676                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1677                     a, b));
1678         } catch (IllegalArgumentException e) {
1679         }
1680     }
1681 
1682     @ForceInline
1683     static 
1684     void testVectorCastShortToLong(VectorSpecies<Short> a, VectorSpecies<Long> b, short[] input, long[] output) {
1685         assert(input.length == a.length());
1686         assert(output.length == b.length());
1687 
1688         ShortVector av = ShortVector.fromArray(a, input, 0);
1689         LongVector bv = (LongVector) av.cast(b);
1690         bv.intoArray(output, 0);
1691 
1692         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1693             Assert.assertEquals(output[i], (long)input[i]);
1694         }
1695         for(int i = input.length; i < output.length; i++) {
1696             Assert.assertEquals(output[i], (long)0);
1697         }
1698     }
1699 
1700     @ForceInline
1701     static 
1702     void testVectorCastShortToLongFail(VectorSpecies<Short> a, VectorSpecies<Long> b, short[] input) {
1703         assert(input.length == a.length());
1704 
1705         ShortVector av = ShortVector.fromArray(a, input, 0);
1706         try {
1707             av.cast(b);
1708             Assert.fail(String.format(
1709                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1710                     a, b));
1711         } catch (IllegalArgumentException e) {
1712         }
1713     }
1714 
1715     @ForceInline
1716     static 
1717     void testVectorCastIntToLong(VectorSpecies<Integer> a, VectorSpecies<Long> b, int[] input, long[] output) {
1718         assert(input.length == a.length());
1719         assert(output.length == b.length());
1720 
1721         IntVector av = IntVector.fromArray(a, input, 0);
1722         LongVector bv = (LongVector) av.cast(b);
1723         bv.intoArray(output, 0);
1724 
1725         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1726             Assert.assertEquals(output[i], (long)input[i]);
1727         }
1728         for(int i = input.length; i < output.length; i++) {
1729             Assert.assertEquals(output[i], (long)0);
1730         }
1731     }
1732 
1733     @ForceInline
1734     static 
1735     void testVectorCastIntToLongFail(VectorSpecies<Integer> a, VectorSpecies<Long> b, int[] input) {
1736         assert(input.length == a.length());
1737 
1738         IntVector av = IntVector.fromArray(a, input, 0);
1739         try {
1740             av.cast(b);
1741             Assert.fail(String.format(
1742                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1743                     a, b));
1744         } catch (IllegalArgumentException e) {
1745         }
1746     }
1747 
1748     @ForceInline
1749     static 
1750     void testVectorCastLongToLong(VectorSpecies<Long> a, VectorSpecies<Long> b, long[] input, long[] output) {
1751         assert(input.length == a.length());
1752         assert(output.length == b.length());
1753 
1754         LongVector av = LongVector.fromArray(a, input, 0);
1755         LongVector bv = (LongVector) av.cast(b);
1756         bv.intoArray(output, 0);
1757 
1758         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1759             Assert.assertEquals(output[i], (long)input[i]);
1760         }
1761         for(int i = input.length; i < output.length; i++) {
1762             Assert.assertEquals(output[i], (long)0);
1763         }
1764     }
1765 
1766     @ForceInline
1767     static 
1768     void testVectorCastLongToLongFail(VectorSpecies<Long> a, VectorSpecies<Long> b, long[] input) {
1769         assert(input.length == a.length());
1770 
1771         LongVector av = LongVector.fromArray(a, input, 0);
1772         try {
1773             av.cast(b);
1774             Assert.fail(String.format(
1775                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1776                     a, b));
1777         } catch (IllegalArgumentException e) {
1778         }
1779     }
1780 
1781     @ForceInline
1782     static 
1783     void testVectorCastFloatToLong(VectorSpecies<Float> a, VectorSpecies<Long> b, float[] input, long[] output) {
1784         assert(input.length == a.length());
1785         assert(output.length == b.length());
1786 
1787         FloatVector av = FloatVector.fromArray(a, input, 0);
1788         LongVector bv = (LongVector) av.cast(b);
1789         bv.intoArray(output, 0);
1790 
1791         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1792             Assert.assertEquals(output[i], (long)input[i]);
1793         }
1794         for(int i = input.length; i < output.length; i++) {
1795             Assert.assertEquals(output[i], (long)0);
1796         }
1797     }
1798 
1799     @ForceInline
1800     static 
1801     void testVectorCastFloatToLongFail(VectorSpecies<Float> a, VectorSpecies<Long> b, float[] input) {
1802         assert(input.length == a.length());
1803 
1804         FloatVector av = FloatVector.fromArray(a, input, 0);
1805         try {
1806             av.cast(b);
1807             Assert.fail(String.format(
1808                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1809                     a, b));
1810         } catch (IllegalArgumentException e) {
1811         }
1812     }
1813 
1814     @ForceInline
1815     static 
1816     void testVectorCastDoubleToLong(VectorSpecies<Double> a, VectorSpecies<Long> b, double[] input, long[] output) {
1817         assert(input.length == a.length());
1818         assert(output.length == b.length());
1819 
1820         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1821         LongVector bv = (LongVector) av.cast(b);
1822         bv.intoArray(output, 0);
1823 
1824         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1825             Assert.assertEquals(output[i], (long)input[i]);
1826         }
1827         for(int i = input.length; i < output.length; i++) {
1828             Assert.assertEquals(output[i], (long)0);
1829         }
1830     }
1831 
1832     @ForceInline
1833     static 
1834     void testVectorCastDoubleToLongFail(VectorSpecies<Double> a, VectorSpecies<Long> b, double[] input) {
1835         assert(input.length == a.length());
1836 
1837         DoubleVector av = DoubleVector.fromArray(a, input, 0);
1838         try {
1839             av.cast(b);
1840             Assert.fail(String.format(
1841                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1842                     a, b));
1843         } catch (IllegalArgumentException e) {
1844         }
1845     }
1846 
1847     @ForceInline
1848     static 
1849     void testVectorCastByteToDouble(VectorSpecies<Byte> a, VectorSpecies<Double> b, byte[] input, double[] output) {
1850         assert(input.length == a.length());
1851         assert(output.length == b.length());
1852 
1853         ByteVector av = ByteVector.fromArray(a, input, 0);
1854         DoubleVector bv = (DoubleVector) av.cast(b);
1855         bv.intoArray(output, 0);
1856 
1857         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1858             Assert.assertEquals(output[i], (double)input[i]);
1859         }
1860         for(int i = input.length; i < output.length; i++) {
1861             Assert.assertEquals(output[i], (double)0);
1862         }
1863     }
1864 
1865     @ForceInline
1866     static 
1867     void testVectorCastByteToDoubleFail(VectorSpecies<Byte> a, VectorSpecies<Double> b, byte[] input) {
1868         assert(input.length == a.length());
1869 
1870         ByteVector av = ByteVector.fromArray(a, input, 0);
1871         try {
1872             av.cast(b);
1873             Assert.fail(String.format(
1874                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1875                     a, b));
1876         } catch (IllegalArgumentException e) {
1877         }
1878     }
1879 
1880     @ForceInline
1881     static 
1882     void testVectorCastShortToDouble(VectorSpecies<Short> a, VectorSpecies<Double> b, short[] input, double[] output) {
1883         assert(input.length == a.length());
1884         assert(output.length == b.length());
1885 
1886         ShortVector av = ShortVector.fromArray(a, input, 0);
1887         DoubleVector bv = (DoubleVector) av.cast(b);
1888         bv.intoArray(output, 0);
1889 
1890         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1891             Assert.assertEquals(output[i], (double)input[i]);
1892         }
1893         for(int i = input.length; i < output.length; i++) {
1894             Assert.assertEquals(output[i], (double)0);
1895         }
1896     }
1897 
1898     @ForceInline
1899     static 
1900     void testVectorCastShortToDoubleFail(VectorSpecies<Short> a, VectorSpecies<Double> b, short[] input) {
1901         assert(input.length == a.length());
1902 
1903         ShortVector av = ShortVector.fromArray(a, input, 0);
1904         try {
1905             av.cast(b);
1906             Assert.fail(String.format(
1907                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1908                     a, b));
1909         } catch (IllegalArgumentException e) {
1910         }
1911     }
1912 
1913     @ForceInline
1914     static 
1915     void testVectorCastIntToDouble(VectorSpecies<Integer> a, VectorSpecies<Double> b, int[] input, double[] output) {
1916         assert(input.length == a.length());
1917         assert(output.length == b.length());
1918 
1919         IntVector av = IntVector.fromArray(a, input, 0);
1920         DoubleVector bv = (DoubleVector) av.cast(b);
1921         bv.intoArray(output, 0);
1922 
1923         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1924             Assert.assertEquals(output[i], (double)input[i]);
1925         }
1926         for(int i = input.length; i < output.length; i++) {
1927             Assert.assertEquals(output[i], (double)0);
1928         }
1929     }
1930 
1931     @ForceInline
1932     static 
1933     void testVectorCastIntToDoubleFail(VectorSpecies<Integer> a, VectorSpecies<Double> b, int[] input) {
1934         assert(input.length == a.length());
1935 
1936         IntVector av = IntVector.fromArray(a, input, 0);
1937         try {
1938             av.cast(b);
1939             Assert.fail(String.format(
1940                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1941                     a, b));
1942         } catch (IllegalArgumentException e) {
1943         }
1944     }
1945 
1946     @ForceInline
1947     static 
1948     void testVectorCastLongToDouble(VectorSpecies<Long> a, VectorSpecies<Double> b, long[] input, double[] output) {
1949         assert(input.length == a.length());
1950         assert(output.length == b.length());
1951 
1952         LongVector av = LongVector.fromArray(a, input, 0);
1953         DoubleVector bv = (DoubleVector) av.cast(b);
1954         bv.intoArray(output, 0);
1955 
1956         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1957             Assert.assertEquals(output[i], (double)input[i]);
1958         }
1959         for(int i = input.length; i < output.length; i++) {
1960             Assert.assertEquals(output[i], (double)0);
1961         }
1962     }
1963 
1964     @ForceInline
1965     static 
1966     void testVectorCastLongToDoubleFail(VectorSpecies<Long> a, VectorSpecies<Double> b, long[] input) {
1967         assert(input.length == a.length());
1968 
1969         LongVector av = LongVector.fromArray(a, input, 0);
1970         try {
1971             av.cast(b);
1972             Assert.fail(String.format(
1973                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
1974                     a, b));
1975         } catch (IllegalArgumentException e) {
1976         }
1977     }
1978 
1979     @ForceInline
1980     static 
1981     void testVectorCastFloatToDouble(VectorSpecies<Float> a, VectorSpecies<Double> b, float[] input, double[] output) {
1982         assert(input.length == a.length());
1983         assert(output.length == b.length());
1984 
1985         FloatVector av = FloatVector.fromArray(a, input, 0);
1986         DoubleVector bv = (DoubleVector) av.cast(b);
1987         bv.intoArray(output, 0);
1988 
1989         for (int i = 0; i < Math.min(input.length, output.length); i++) {
1990             Assert.assertEquals(output[i], (double)input[i]);
1991         }
1992         for(int i = input.length; i < output.length; i++) {
1993             Assert.assertEquals(output[i], (double)0);
1994         }
1995     }
1996 
1997     @ForceInline
1998     static 
1999     void testVectorCastFloatToDoubleFail(VectorSpecies<Float> a, VectorSpecies<Double> b, float[] input) {
2000         assert(input.length == a.length());
2001 
2002         FloatVector av = FloatVector.fromArray(a, input, 0);
2003         try {
2004             av.cast(b);
2005             Assert.fail(String.format(
2006                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
2007                     a, b));
2008         } catch (IllegalArgumentException e) {
2009         }
2010     }
2011 
2012     @ForceInline
2013     static 
2014     void testVectorCastDoubleToDouble(VectorSpecies<Double> a, VectorSpecies<Double> b, double[] input, double[] output) {
2015         assert(input.length == a.length());
2016         assert(output.length == b.length());
2017 
2018         DoubleVector av = DoubleVector.fromArray(a, input, 0);
2019         DoubleVector bv = (DoubleVector) av.cast(b);
2020         bv.intoArray(output, 0);
2021 
2022         for (int i = 0; i < Math.min(input.length, output.length); i++) {
2023             Assert.assertEquals(output[i], (double)input[i]);
2024         }
2025         for(int i = input.length; i < output.length; i++) {
2026             Assert.assertEquals(output[i], (double)0);
2027         }
2028     }
2029 
2030     @ForceInline
2031     static 
2032     void testVectorCastDoubleToDoubleFail(VectorSpecies<Double> a, VectorSpecies<Double> b, double[] input) {
2033         assert(input.length == a.length());
2034 
2035         DoubleVector av = DoubleVector.fromArray(a, input, 0);
2036         try {
2037             av.cast(b);
2038             Assert.fail(String.format(
2039                     "Cast failed to throw IllegalArgumentException for differing species lengths for %s and %s",
2040                     a, b));
2041         } catch (IllegalArgumentException e) {
2042         }
2043     }
2044 
2045     @Test(dataProvider = "byteUnaryOpProvider")
2046     static void testCastFromByte(IntFunction<byte[]> fa) {
2047         byte[] bin64 = fa.apply(bspec64.length());
2048         byte[] bin128 = fa.apply(bspec128.length());
2049         byte[] bin256 = fa.apply(bspec256.length());
2050         byte[] bin512 = fa.apply(bspec512.length());
2051 
2052         byte[] bout64 = new byte[bspec64.length()];


3040 
3041             testVectorCastDoubleToDoubleFail(dspec64, dspec128, din64);
3042             testVectorCastDoubleToDoubleFail(dspec64, dspec256, din64);
3043             testVectorCastDoubleToDoubleFail(dspec64, dspec512, din64);
3044 
3045             testVectorCastDoubleToDoubleFail(dspec128, dspec64, din128);
3046             testVectorCastDoubleToDoubleFail(dspec128, dspec256, din128);
3047             testVectorCastDoubleToDoubleFail(dspec128, dspec512, din128);
3048 
3049             testVectorCastDoubleToDoubleFail(dspec256, dspec64, din256);
3050             testVectorCastDoubleToDoubleFail(dspec256, dspec128, din256);
3051             testVectorCastDoubleToDoubleFail(dspec256, dspec512, din256);
3052 
3053             testVectorCastDoubleToDoubleFail(dspec512, dspec64, din512);
3054             testVectorCastDoubleToDoubleFail(dspec512, dspec128, din512);
3055             testVectorCastDoubleToDoubleFail(dspec512, dspec256, din512);
3056         }
3057     }
3058 
3059     static 
3060     void testVectorCastByteMaxToByte(VectorSpecies<Byte> a, VectorSpecies<Byte> b,
3061                                           byte[] input, byte[] output) {
3062         if (S_Max_BIT.bitSize() == b.length() * Byte.SIZE) {
3063             testVectorCastByteToByte(a, b, input, output);
3064         } else {
3065             testVectorCastByteToByteFail(a, b, input);
3066         }
3067     }
3068 
3069     static 
3070     void testVectorCastByteMaxToShort(VectorSpecies<Byte> a, VectorSpecies<Short> b,
3071                                            byte[] input, short[] output) {
3072         if (S_Max_BIT.bitSize() == b.length() * Byte.SIZE) {
3073             testVectorCastByteToShort(a, b, input, output);
3074         } else {
3075             testVectorCastByteToShortFail(a, b, input);
3076         }
3077     }
3078 
3079     static 
3080     void testVectorCastByteMaxToInt(VectorSpecies<Byte> a, VectorSpecies<Integer> b,
3081                                          byte[] input, int[] output) {
3082         if (S_Max_BIT.bitSize() == b.length() * Byte.SIZE) {
3083             testVectorCastByteToInt(a, b, input, output);
3084         } else {
3085             testVectorCastByteToIntFail(a, b, input);
3086         }
3087     }
3088 
3089     static 
3090     void testVectorCastByteMaxToLong(VectorSpecies<Byte> a, VectorSpecies<Long> b,
3091                                           byte[] input, long[] output) {
3092         if (S_Max_BIT.bitSize() == b.length() * Byte.SIZE) {
3093             testVectorCastByteToLong(a, b, input, output);
3094         } else {
3095             testVectorCastByteToLongFail(a, b, input);
3096         }
3097     }
3098 
3099     static 
3100     void testVectorCastByteMaxToFloat(VectorSpecies<Byte> a, VectorSpecies<Float> b,
3101                                            byte[] input, float[] output) {
3102         if (S_Max_BIT.bitSize() == b.length() * Byte.SIZE) {
3103             testVectorCastByteToFloat(a, b, input, output);
3104         } else {
3105             testVectorCastByteToFloatFail(a, b, input);
3106         }
3107     }
3108 
3109     static 
3110     void testVectorCastByteMaxToDouble(VectorSpecies<Byte> a, VectorSpecies<Double> b,
3111                                             byte[] input, double[] output) {
3112         if (S_Max_BIT.bitSize() == b.length() * Byte.SIZE) {
3113             testVectorCastByteToDouble(a, b, input, output);
3114         } else {
3115             testVectorCastByteToDoubleFail(a, b, input);
3116         }
3117     }
3118 
3119     static 
3120     void testVectorCastShortMaxToByte(VectorSpecies<Short> a, VectorSpecies<Byte> b,
3121                                            short[] input, byte[] output) {
3122         if (S_Max_BIT.bitSize() == b.length() * Short.SIZE) {
3123             testVectorCastShortToByte(a, b, input, output);
3124         } else {
3125             testVectorCastShortToByteFail(a, b, input);
3126         }
3127     }
3128 
3129     static 
3130     void testVectorCastShortMaxToShort(VectorSpecies<Short> a, VectorSpecies<Short> b,
3131                                             short[] input, short[] output) {
3132         if (S_Max_BIT.bitSize() == b.length() * Short.SIZE) {
3133             testVectorCastShortToShort(a, b, input, output);
3134         } else {
3135             testVectorCastShortToShortFail(a, b, input);
3136         }
3137     }
3138 
3139     static 
3140     void testVectorCastShortMaxToInt(VectorSpecies<Short> a, VectorSpecies<Integer> b,
3141                                           short[] input, int[] output) {
3142         if (S_Max_BIT.bitSize() == b.length() * Short.SIZE) {
3143             testVectorCastShortToInt(a, b, input, output);
3144         } else {
3145             testVectorCastShortToIntFail(a, b, input);
3146         }
3147     }
3148 
3149     static 
3150     void testVectorCastShortMaxToLong(VectorSpecies<Short> a, VectorSpecies<Long> b,
3151                                            short[] input, long[] output) {
3152         if (S_Max_BIT.bitSize() == b.length() * Short.SIZE) {
3153             testVectorCastShortToLong(a, b, input, output);
3154         } else {
3155             testVectorCastShortToLongFail(a, b, input);
3156         }
3157     }
3158 
3159     static 
3160     void testVectorCastShortMaxToFloat(VectorSpecies<Short> a, VectorSpecies<Float> b,
3161                                             short[] input, float[] output) {
3162         if (S_Max_BIT.bitSize() == b.length() * Short.SIZE) {
3163             testVectorCastShortToFloat(a, b, input, output);
3164         } else {
3165             testVectorCastShortToFloatFail(a, b, input);
3166         }
3167     }
3168 
3169     static 
3170     void testVectorCastShortMaxToDouble(VectorSpecies<Short> a, VectorSpecies<Double> b,
3171                                              short[] input, double[] output) {
3172         if (S_Max_BIT.bitSize() == b.length() * Short.SIZE) {
3173             testVectorCastShortToDouble(a, b, input, output);
3174         } else {
3175             testVectorCastShortToDoubleFail(a, b, input);
3176         }
3177     }
3178 
3179     static 
3180     void testVectorCastIntMaxToByte(VectorSpecies<Integer> a, VectorSpecies<Byte> b,
3181                                          int[] input, byte[] output) {
3182         if (S_Max_BIT.bitSize() == b.length() * Integer.SIZE) {
3183             testVectorCastIntToByte(a, b, input, output);
3184         } else {
3185             testVectorCastIntToByteFail(a, b, input);
3186         }
3187     }
3188 
3189     static 
3190     void testVectorCastIntMaxToShort(VectorSpecies<Integer> a, VectorSpecies<Short> b,
3191                                           int[] input, short[] output) {
3192         if (S_Max_BIT.bitSize() == b.length() * Integer.SIZE) {
3193             testVectorCastIntToShort(a, b, input, output);
3194         } else {
3195             testVectorCastIntToShortFail(a, b, input);
3196         }
3197     }
3198 
3199     static 
3200     void testVectorCastIntMaxToInt(VectorSpecies<Integer> a, VectorSpecies<Integer> b,
3201                                         int[] input, int[] output) {
3202         if (S_Max_BIT.bitSize() == b.length() * Integer.SIZE) {
3203             testVectorCastIntToInt(a, b, input, output);
3204         } else {
3205             testVectorCastIntToIntFail(a, b, input);
3206         }
3207     }
3208 
3209     static 
3210     void testVectorCastIntMaxToLong(VectorSpecies<Integer> a, VectorSpecies<Long> b,
3211                                          int[] input, long[] output) {
3212         if (S_Max_BIT.bitSize() == b.length() * Integer.SIZE) {
3213             testVectorCastIntToLong(a, b, input, output);
3214         } else {
3215             testVectorCastIntToLongFail(a, b, input);
3216         }
3217     }
3218 
3219     static 
3220     void testVectorCastIntMaxToFloat(VectorSpecies<Integer> a, VectorSpecies<Float> b,
3221                                           int[] input, float[] output) {
3222         if (S_Max_BIT.bitSize() == b.length() * Integer.SIZE) {
3223             testVectorCastIntToFloat(a, b, input, output);
3224         } else {
3225             testVectorCastIntToFloatFail(a, b, input);
3226         }
3227     }
3228 
3229     static 
3230     void testVectorCastIntMaxToDouble(VectorSpecies<Integer> a, VectorSpecies<Double> b,
3231                                            int[] input, double[] output) {
3232         if (S_Max_BIT.bitSize() == b.length() * Integer.SIZE) {
3233             testVectorCastIntToDouble(a, b, input, output);
3234         } else {
3235             testVectorCastIntToDoubleFail(a, b, input);
3236         }
3237     }
3238 
3239     static 
3240     void testVectorCastLongMaxToByte(VectorSpecies<Long> a, VectorSpecies<Byte> b,
3241                                           long[] input, byte[] output) {
3242         if (S_Max_BIT.bitSize() == b.length() * Long.SIZE) {
3243             testVectorCastLongToByte(a, b, input, output);
3244         } else {
3245             testVectorCastLongToByteFail(a, b, input);
3246         }
3247     }
3248 
3249     static 
3250     void testVectorCastLongMaxToShort(VectorSpecies<Long> a, VectorSpecies<Short> b,
3251                                            long[] input, short[] output) {
3252         if (S_Max_BIT.bitSize() == b.length() * Long.SIZE) {
3253             testVectorCastLongToShort(a, b, input, output);
3254         } else {
3255             testVectorCastLongToShortFail(a, b, input);
3256         }
3257     }
3258 
3259     static 
3260     void testVectorCastLongMaxToInt(VectorSpecies<Long> a, VectorSpecies<Integer> b,
3261                                          long[] input, int[] output) {
3262         if (S_Max_BIT.bitSize() == b.length() * Long.SIZE) {
3263             testVectorCastLongToInt(a, b, input, output);
3264         } else {
3265             testVectorCastLongToIntFail(a, b, input);
3266         }
3267     }
3268 
3269     static 
3270     void testVectorCastLongMaxToLong(VectorSpecies<Long> a, VectorSpecies<Long> b,
3271                                           long[] input, long[] output) {
3272         if (S_Max_BIT.bitSize() == b.length() * Long.SIZE) {
3273             testVectorCastLongToLong(a, b, input, output);
3274         } else {
3275             testVectorCastLongToLongFail(a, b, input);
3276         }
3277     }
3278 
3279     static 
3280     void testVectorCastLongMaxToFloat(VectorSpecies<Long> a, VectorSpecies<Float> b,
3281                                            long[] input, float[] output) {
3282         if (S_Max_BIT.bitSize() == b.length() * Long.SIZE) {
3283             testVectorCastLongToFloat(a, b, input, output);
3284         } else {
3285             testVectorCastLongToFloatFail(a, b, input);
3286         }
3287     }
3288 
3289     static 
3290     void testVectorCastLongMaxToDouble(VectorSpecies<Long> a, VectorSpecies<Double> b,
3291                                             long[] input, double[] output) {
3292         if (S_Max_BIT.bitSize() == b.length() * Long.SIZE) {
3293             testVectorCastLongToDouble(a, b, input, output);
3294         } else {
3295             testVectorCastLongToDoubleFail(a, b, input);
3296         }
3297     }
3298 
3299     static 
3300     void testVectorCastFloatMaxToByte(VectorSpecies<Float> a, VectorSpecies<Byte> b,
3301                                            float[] input, byte[] output) {
3302         if (S_Max_BIT.bitSize() == b.length() * Float.SIZE) {
3303             testVectorCastFloatToByte(a, b, input, output);
3304         } else {
3305             testVectorCastFloatToByteFail(a, b, input);
3306         }
3307     }
3308 
3309     static 
3310     void testVectorCastFloatMaxToShort(VectorSpecies<Float> a, VectorSpecies<Short> b,
3311                                             float[] input, short[] output) {
3312         if (S_Max_BIT.bitSize() == b.length() * Float.SIZE) {
3313             testVectorCastFloatToShort(a, b, input, output);
3314         } else {
3315             testVectorCastFloatToShortFail(a, b, input);
3316         }
3317     }
3318 
3319     static 
3320     void testVectorCastFloatMaxToInt(VectorSpecies<Float> a, VectorSpecies<Integer> b,
3321                                           float[] input, int[] output) {
3322         if (S_Max_BIT.bitSize() == b.length() * Float.SIZE) {
3323             testVectorCastFloatToInt(a, b, input, output);
3324         } else {
3325             testVectorCastFloatToIntFail(a, b, input);
3326         }
3327     }
3328 
3329     static 
3330     void testVectorCastFloatMaxToLong(VectorSpecies<Float> a, VectorSpecies<Long> b,
3331                                            float[] input, long[] output) {
3332         if (S_Max_BIT.bitSize() == b.length() * Float.SIZE) {
3333             testVectorCastFloatToLong(a, b, input, output);
3334         } else {
3335             testVectorCastFloatToLongFail(a, b, input);
3336         }
3337     }
3338 
3339     static 
3340     void testVectorCastFloatMaxToFloat(VectorSpecies<Float> a, VectorSpecies<Float> b,
3341                                             float[] input, float[] output) {
3342         if (S_Max_BIT.bitSize() == b.length() * Float.SIZE) {
3343             testVectorCastFloatToFloat(a, b, input, output);
3344         } else {
3345             testVectorCastFloatToFloatFail(a, b, input);
3346         }
3347     }
3348 
3349     static 
3350     void testVectorCastFloatMaxToDouble(VectorSpecies<Float> a, VectorSpecies<Double> b,
3351                                              float[] input, double[] output) {
3352         if (S_Max_BIT.bitSize() == b.length() * Float.SIZE) {
3353             testVectorCastFloatToDouble(a, b, input, output);
3354         } else {
3355             testVectorCastFloatToDoubleFail(a, b, input);
3356         }
3357     }
3358 
3359     static 
3360     void testVectorCastDoubleMaxToByte(VectorSpecies<Double> a, VectorSpecies<Byte> b,
3361                                             double[] input, byte[] output) {
3362         if (S_Max_BIT.bitSize() == b.length() * Double.SIZE) {
3363             testVectorCastDoubleToByte(a, b, input, output);
3364         } else {
3365             testVectorCastDoubleToByteFail(a, b, input);
3366         }
3367     }
3368 
3369     static 
3370     void testVectorCastDoubleMaxToShort(VectorSpecies<Double> a, VectorSpecies<Short> b,
3371                                              double[] input, short[] output) {
3372         if (S_Max_BIT.bitSize() == b.length() * Double.SIZE) {
3373             testVectorCastDoubleToShort(a, b, input, output);
3374         } else {
3375             testVectorCastDoubleToShortFail(a, b, input);
3376         }
3377     }
3378 
3379     static 
3380     void testVectorCastDoubleMaxToInt(VectorSpecies<Double> a, VectorSpecies<Integer> b,
3381                                            double[] input, int[] output) {
3382         if (S_Max_BIT.bitSize() == b.length() * Double.SIZE) {
3383             testVectorCastDoubleToInt(a, b, input, output);
3384         } else {
3385             testVectorCastDoubleToIntFail(a, b, input);
3386         }
3387     }
3388 
3389     static 
3390     void testVectorCastDoubleMaxToLong(VectorSpecies<Double> a, VectorSpecies<Long> b,
3391                                             double[] input, long[] output) {
3392         if (S_Max_BIT.bitSize() == b.length() * Double.SIZE) {
3393             testVectorCastDoubleToLong(a, b, input, output);
3394         } else {
3395             testVectorCastDoubleToLongFail(a, b, input);
3396         }
3397     }
3398 
3399     static 
3400     void testVectorCastDoubleMaxToFloat(VectorSpecies<Double> a, VectorSpecies<Float> b,
3401                                              double[] input, float[] output) {
3402         if (S_Max_BIT.bitSize() == b.length() * Double.SIZE) {
3403             testVectorCastDoubleToFloat(a, b, input, output);
3404         } else {
3405             testVectorCastDoubleToFloatFail(a, b, input);
3406         }
3407     }
3408 
3409     static 
3410     void testVectorCastDoubleMaxToDouble(VectorSpecies<Double> a, VectorSpecies<Double> b,
3411                                               double[] input, double[] output) {
3412         if (S_Max_BIT.bitSize() == b.length() * Double.SIZE) {
3413             testVectorCastDoubleToDouble(a, b, input, output);
3414         } else {
3415             testVectorCastDoubleToDoubleFail(a, b, input);
3416         }
3417     }
3418 
3419     @Test(dataProvider = "byteUnaryOpProvider")
3420     static void testCastFromByteMax(IntFunction<byte[]> fa) {
3421         byte[] binMax = fa.apply(bspecMax.length());
3422 
3423         byte[] bout64 = new byte[bspec64.length()];
3424         byte[] bout128 = new byte[bspec128.length()];
3425         byte[] bout256 = new byte[bspec256.length()];
3426         byte[] bout512 = new byte[bspec512.length()];
3427         byte[] boutMax = new byte[bspecMax.length()];
3428 
3429         short[] sout64 = new short[sspec64.length()];
3430         short[] sout128 = new short[sspec128.length()];


< prev index next >