< prev index next >

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short64Vector.java

Print this page
rev 54658 : refactored mask and shuffle creation methods, moved classes to top-level
rev 54660 : Javadoc changes


 154 
 155         return VectorIntrinsics.cast(
 156             Short64Vector.class,
 157             short.class, LENGTH,
 158             s.boxType(),
 159             s.elementType(), LENGTH,
 160             this, s,
 161             (species, vector) -> vector.castDefault(species)
 162         );
 163     }
 164 
 165     @SuppressWarnings("unchecked")
 166     @ForceInline
 167     private <F> Vector<F> castDefault(VectorSpecies<F> s) {
 168         int limit = s.length();
 169 
 170         Class<?> stype = s.elementType();
 171         if (stype == byte.class) {
 172             byte[] a = new byte[limit];
 173             for (int i = 0; i < limit; i++) {
 174                 a[i] = (byte) this.get(i);
 175             }
 176             return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
 177         } else if (stype == short.class) {
 178             short[] a = new short[limit];
 179             for (int i = 0; i < limit; i++) {
 180                 a[i] = (short) this.get(i);
 181             }
 182             return (Vector) ShortVector.fromArray((VectorSpecies<Short>) s, a, 0);
 183         } else if (stype == int.class) {
 184             int[] a = new int[limit];
 185             for (int i = 0; i < limit; i++) {
 186                 a[i] = (int) this.get(i);
 187             }
 188             return (Vector) IntVector.fromArray((VectorSpecies<Integer>) s, a, 0);
 189         } else if (stype == long.class) {
 190             long[] a = new long[limit];
 191             for (int i = 0; i < limit; i++) {
 192                 a[i] = (long) this.get(i);
 193             }
 194             return (Vector) LongVector.fromArray((VectorSpecies<Long>) s, a, 0);
 195         } else if (stype == float.class) {
 196             float[] a = new float[limit];
 197             for (int i = 0; i < limit; i++) {
 198                 a[i] = (float) this.get(i);
 199             }
 200             return (Vector) FloatVector.fromArray((VectorSpecies<Float>) s, a, 0);
 201         } else if (stype == double.class) {
 202             double[] a = new double[limit];
 203             for (int i = 0; i < limit; i++) {
 204                 a[i] = (double) this.get(i);
 205             }
 206             return (Vector) DoubleVector.fromArray((VectorSpecies<Double>) s, a, 0);
 207         } else {
 208             throw new UnsupportedOperationException("Bad lane type for casting.");
 209         }
 210     }
 211 
 212     @Override
 213     @ForceInline
 214     @SuppressWarnings("unchecked")
 215     public <F> Vector<F> reinterpret(VectorSpecies<F> s) {
 216         Objects.requireNonNull(s);
 217 
 218         if(s.elementType().equals(short.class)) {
 219             return (Vector<F>) reshape((VectorSpecies<Short>)s);
 220         }
 221         if(s.bitSize() == bitSize()) {
 222             return reinterpretType(s);
 223         }
 224 


1073         return new Short64Vector(res);
1074     }
1075 
1076     @Override
1077     @ForceInline
1078     public Short64Vector rearrange(Vector<Short> v,
1079                                   VectorShuffle<Short> s, VectorMask<Short> m) {
1080         return this.rearrange(s).blend(v.rearrange(s), m);
1081     }
1082 
1083     @Override
1084     @ForceInline
1085     public Short64Vector rearrange(VectorShuffle<Short> o1) {
1086         Objects.requireNonNull(o1);
1087         Short64Shuffle s =  (Short64Shuffle)o1;
1088 
1089         return VectorIntrinsics.rearrangeOp(
1090             Short64Vector.class, Short64Shuffle.class, short.class, LENGTH,
1091             this, s,
1092             (v1, s_) -> v1.uOp((i, a) -> {
1093                 int ei = s_.getElement(i);
1094                 return v1.get(ei);
1095             }));
1096     }
1097 
1098     @Override
1099     @ForceInline
1100     public Short64Vector blend(Vector<Short> o1, VectorMask<Short> o2) {
1101         Objects.requireNonNull(o1);
1102         Objects.requireNonNull(o2);
1103         Short64Vector v = (Short64Vector)o1;
1104         Short64Mask   m = (Short64Mask)o2;
1105 
1106         return VectorIntrinsics.blend(
1107             Short64Vector.class, Short64Mask.class, short.class, LENGTH,
1108             this, v, m,
1109             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1110     }
1111 
1112     // Accessors
1113 
1114     @Override
1115     public short get(int i) {
1116         if (i < 0 || i >= LENGTH) {
1117             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1118         }
1119         return (short) VectorIntrinsics.extract(
1120                                 Short64Vector.class, short.class, LENGTH,
1121                                 this, i,
1122                                 (vec, ix) -> {
1123                                     short[] vecarr = vec.getElements();
1124                                     return (long)vecarr[ix];
1125                                 });
1126     }
1127 
1128     @Override
1129     public Short64Vector with(int i, short e) {
1130         if (i < 0 || i >= LENGTH) {
1131             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1132         }
1133         return VectorIntrinsics.insert(
1134                                 Short64Vector.class, short.class, LENGTH,
1135                                 this, i, (long)e,


1296             super(reorder);
1297         }
1298 
1299         public Short64Shuffle(int[] reorder, int i) {
1300             super(reorder, i);
1301         }
1302 
1303         public Short64Shuffle(IntUnaryOperator f) {
1304             super(f);
1305         }
1306 
1307         @Override
1308         public VectorSpecies<Short> species() {
1309             return SPECIES;
1310         }
1311 
1312         @Override
1313         public ShortVector toVector() {
1314             short[] va = new short[SPECIES.length()];
1315             for (int i = 0; i < va.length; i++) {
1316               va[i] = (short) getElement(i);
1317             }
1318             return ShortVector.fromArray(SPECIES, va, 0);
1319         }
1320 
1321         @Override
1322         @ForceInline
1323         @SuppressWarnings("unchecked")
1324         public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
1325             if (length() != species.length())
1326                 throw new IllegalArgumentException("Shuffle length and species length differ");
1327             Class<?> stype = species.elementType();
1328             int [] shuffleArray = toArray();
1329             if (stype == byte.class) {
1330                 return (VectorShuffle<F>) new Byte64Vector.Byte64Shuffle(shuffleArray);
1331             } else if (stype == short.class) {
1332                 return (VectorShuffle<F>) new Short64Vector.Short64Shuffle(shuffleArray);
1333             } else if (stype == int.class) {
1334                 return (VectorShuffle<F>) new Int64Vector.Int64Shuffle(shuffleArray);
1335             } else if (stype == long.class) {
1336                 return (VectorShuffle<F>) new Long64Vector.Long64Shuffle(shuffleArray);




 154 
 155         return VectorIntrinsics.cast(
 156             Short64Vector.class,
 157             short.class, LENGTH,
 158             s.boxType(),
 159             s.elementType(), LENGTH,
 160             this, s,
 161             (species, vector) -> vector.castDefault(species)
 162         );
 163     }
 164 
 165     @SuppressWarnings("unchecked")
 166     @ForceInline
 167     private <F> Vector<F> castDefault(VectorSpecies<F> s) {
 168         int limit = s.length();
 169 
 170         Class<?> stype = s.elementType();
 171         if (stype == byte.class) {
 172             byte[] a = new byte[limit];
 173             for (int i = 0; i < limit; i++) {
 174                 a[i] = (byte) this.lane(i);
 175             }
 176             return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
 177         } else if (stype == short.class) {
 178             short[] a = new short[limit];
 179             for (int i = 0; i < limit; i++) {
 180                 a[i] = (short) this.lane(i);
 181             }
 182             return (Vector) ShortVector.fromArray((VectorSpecies<Short>) s, a, 0);
 183         } else if (stype == int.class) {
 184             int[] a = new int[limit];
 185             for (int i = 0; i < limit; i++) {
 186                 a[i] = (int) this.lane(i);
 187             }
 188             return (Vector) IntVector.fromArray((VectorSpecies<Integer>) s, a, 0);
 189         } else if (stype == long.class) {
 190             long[] a = new long[limit];
 191             for (int i = 0; i < limit; i++) {
 192                 a[i] = (long) this.lane(i);
 193             }
 194             return (Vector) LongVector.fromArray((VectorSpecies<Long>) s, a, 0);
 195         } else if (stype == float.class) {
 196             float[] a = new float[limit];
 197             for (int i = 0; i < limit; i++) {
 198                 a[i] = (float) this.lane(i);
 199             }
 200             return (Vector) FloatVector.fromArray((VectorSpecies<Float>) s, a, 0);
 201         } else if (stype == double.class) {
 202             double[] a = new double[limit];
 203             for (int i = 0; i < limit; i++) {
 204                 a[i] = (double) this.lane(i);
 205             }
 206             return (Vector) DoubleVector.fromArray((VectorSpecies<Double>) s, a, 0);
 207         } else {
 208             throw new UnsupportedOperationException("Bad lane type for casting.");
 209         }
 210     }
 211 
 212     @Override
 213     @ForceInline
 214     @SuppressWarnings("unchecked")
 215     public <F> Vector<F> reinterpret(VectorSpecies<F> s) {
 216         Objects.requireNonNull(s);
 217 
 218         if(s.elementType().equals(short.class)) {
 219             return (Vector<F>) reshape((VectorSpecies<Short>)s);
 220         }
 221         if(s.bitSize() == bitSize()) {
 222             return reinterpretType(s);
 223         }
 224 


1073         return new Short64Vector(res);
1074     }
1075 
1076     @Override
1077     @ForceInline
1078     public Short64Vector rearrange(Vector<Short> v,
1079                                   VectorShuffle<Short> s, VectorMask<Short> m) {
1080         return this.rearrange(s).blend(v.rearrange(s), m);
1081     }
1082 
1083     @Override
1084     @ForceInline
1085     public Short64Vector rearrange(VectorShuffle<Short> o1) {
1086         Objects.requireNonNull(o1);
1087         Short64Shuffle s =  (Short64Shuffle)o1;
1088 
1089         return VectorIntrinsics.rearrangeOp(
1090             Short64Vector.class, Short64Shuffle.class, short.class, LENGTH,
1091             this, s,
1092             (v1, s_) -> v1.uOp((i, a) -> {
1093                 int ei = s_.lane(i);
1094                 return v1.lane(ei);
1095             }));
1096     }
1097 
1098     @Override
1099     @ForceInline
1100     public Short64Vector blend(Vector<Short> o1, VectorMask<Short> o2) {
1101         Objects.requireNonNull(o1);
1102         Objects.requireNonNull(o2);
1103         Short64Vector v = (Short64Vector)o1;
1104         Short64Mask   m = (Short64Mask)o2;
1105 
1106         return VectorIntrinsics.blend(
1107             Short64Vector.class, Short64Mask.class, short.class, LENGTH,
1108             this, v, m,
1109             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.lane(i) ? b : a));
1110     }
1111 
1112     // Accessors
1113 
1114     @Override
1115     public short lane(int i) {
1116         if (i < 0 || i >= LENGTH) {
1117             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1118         }
1119         return (short) VectorIntrinsics.extract(
1120                                 Short64Vector.class, short.class, LENGTH,
1121                                 this, i,
1122                                 (vec, ix) -> {
1123                                     short[] vecarr = vec.getElements();
1124                                     return (long)vecarr[ix];
1125                                 });
1126     }
1127 
1128     @Override
1129     public Short64Vector with(int i, short e) {
1130         if (i < 0 || i >= LENGTH) {
1131             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1132         }
1133         return VectorIntrinsics.insert(
1134                                 Short64Vector.class, short.class, LENGTH,
1135                                 this, i, (long)e,


1296             super(reorder);
1297         }
1298 
1299         public Short64Shuffle(int[] reorder, int i) {
1300             super(reorder, i);
1301         }
1302 
1303         public Short64Shuffle(IntUnaryOperator f) {
1304             super(f);
1305         }
1306 
1307         @Override
1308         public VectorSpecies<Short> species() {
1309             return SPECIES;
1310         }
1311 
1312         @Override
1313         public ShortVector toVector() {
1314             short[] va = new short[SPECIES.length()];
1315             for (int i = 0; i < va.length; i++) {
1316               va[i] = (short) lane(i);
1317             }
1318             return ShortVector.fromArray(SPECIES, va, 0);
1319         }
1320 
1321         @Override
1322         @ForceInline
1323         @SuppressWarnings("unchecked")
1324         public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
1325             if (length() != species.length())
1326                 throw new IllegalArgumentException("Shuffle length and species length differ");
1327             Class<?> stype = species.elementType();
1328             int [] shuffleArray = toArray();
1329             if (stype == byte.class) {
1330                 return (VectorShuffle<F>) new Byte64Vector.Byte64Shuffle(shuffleArray);
1331             } else if (stype == short.class) {
1332                 return (VectorShuffle<F>) new Short64Vector.Short64Shuffle(shuffleArray);
1333             } else if (stype == int.class) {
1334                 return (VectorShuffle<F>) new Int64Vector.Int64Shuffle(shuffleArray);
1335             } else if (stype == long.class) {
1336                 return (VectorShuffle<F>) new Long64Vector.Long64Shuffle(shuffleArray);


< prev index next >