< prev index next >

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

Print this page




 146 
 147     @Override
 148     float rOp(float v, FBinOp f) {
 149         float[] vec = getElements();
 150         for (int i = 0; i < length(); i++) {
 151             v = f.apply(i, v, vec[i]);
 152         }
 153         return v;
 154     }
 155 
 156     @Override
 157     @ForceInline
 158     public <F> Vector<F> cast(VectorSpecies<F> s) {
 159         Objects.requireNonNull(s);
 160         if (s.length() != LENGTH)
 161             throw new IllegalArgumentException("Vector length this species length differ");
 162 
 163         return VectorIntrinsics.cast(
 164             Float128Vector.class,
 165             float.class, LENGTH,
 166             s.boxType(),
 167             s.elementType(), LENGTH,
 168             this, s,
 169             (species, vector) -> vector.castDefault(species)
 170         );
 171     }
 172 
 173     @SuppressWarnings("unchecked")
 174     @ForceInline
 175     private <F> Vector<F> castDefault(VectorSpecies<F> s) {
 176         int limit = s.length();
 177 
 178         Class<?> stype = s.elementType();
 179         if (stype == byte.class) {
 180             byte[] a = new byte[limit];
 181             for (int i = 0; i < limit; i++) {
 182                 a[i] = (byte) this.lane(i);
 183             }
 184             return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
 185         } else if (stype == short.class) {
 186             short[] a = new short[limit];


 284                 (species, vector) -> vector.defaultReinterpret(species)
 285             );
 286         } else if (stype == double.class) {
 287             return VectorIntrinsics.reinterpret(
 288                 Float128Vector.class,
 289                 float.class, LENGTH,
 290                 Double128Vector.class,
 291                 double.class, Double128Vector.LENGTH,
 292                 this, s,
 293                 (species, vector) -> vector.defaultReinterpret(species)
 294             );
 295         } else {
 296             throw new UnsupportedOperationException("Bad lane type for casting.");
 297         }
 298     }
 299 
 300     @Override
 301     @ForceInline
 302     public FloatVector reshape(VectorSpecies<Float> s) {
 303         Objects.requireNonNull(s);
 304         if (s.bitSize() == 64 && (s.boxType() == Float64Vector.class)) {
 305             return VectorIntrinsics.reinterpret(
 306                 Float128Vector.class,
 307                 float.class, LENGTH,
 308                 Float64Vector.class,
 309                 float.class, Float64Vector.LENGTH,
 310                 this, s,
 311                 (species, vector) -> (FloatVector) vector.defaultReinterpret(species)
 312             );
 313         } else if (s.bitSize() == 128 && (s.boxType() == Float128Vector.class)) {
 314             return VectorIntrinsics.reinterpret(
 315                 Float128Vector.class,
 316                 float.class, LENGTH,
 317                 Float128Vector.class,
 318                 float.class, Float128Vector.LENGTH,
 319                 this, s,
 320                 (species, vector) -> (FloatVector) vector.defaultReinterpret(species)
 321             );
 322         } else if (s.bitSize() == 256 && (s.boxType() == Float256Vector.class)) {
 323             return VectorIntrinsics.reinterpret(
 324                 Float128Vector.class,
 325                 float.class, LENGTH,
 326                 Float256Vector.class,
 327                 float.class, Float256Vector.LENGTH,
 328                 this, s,
 329                 (species, vector) -> (FloatVector) vector.defaultReinterpret(species)
 330             );
 331         } else if (s.bitSize() == 512 && (s.boxType() == Float512Vector.class)) {
 332             return VectorIntrinsics.reinterpret(
 333                 Float128Vector.class,
 334                 float.class, LENGTH,
 335                 Float512Vector.class,
 336                 float.class, Float512Vector.LENGTH,
 337                 this, s,
 338                 (species, vector) -> (FloatVector) vector.defaultReinterpret(species)
 339             );
 340         } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
 341                 && (s.bitSize() % 128 == 0) && (s.boxType() == FloatMaxVector.class)) {
 342             return VectorIntrinsics.reinterpret(
 343                 Float128Vector.class,
 344                 float.class, LENGTH,
 345                 FloatMaxVector.class,
 346                 float.class, FloatMaxVector.LENGTH,
 347                 this, s,
 348                 (species, vector) -> (FloatVector) vector.defaultReinterpret(species)
 349             );
 350         } else {
 351             throw new InternalError("Unimplemented size");
 352         }
 353     }
 354 
 355     // Binary operations with scalars
 356 
 357     @Override
 358     @ForceInline
 359     public FloatVector add(float o) {
 360         return add((Float128Vector)FloatVector.broadcast(SPECIES, o));
 361     }


1150 
1151     @Override
1152     void forEach(VectorMask<Float> o, FUnCon f) {
1153         boolean[] mbits = ((Float128Mask)o).getBits();
1154         forEach((i, a) -> {
1155             if (mbits[i]) { f.apply(i, a); }
1156         });
1157     }
1158 
1159     Int128Vector toBits() {
1160         float[] vec = getElements();
1161         int[] res = new int[this.species().length()];
1162         for(int i = 0; i < this.species().length(); i++){
1163             res[i] = Float.floatToIntBits(vec[i]);
1164         }
1165         return new Int128Vector(res);
1166     }
1167 
1168 
1169     @Override
1170     public Float128Vector rotateEL(int j) {
1171         float[] vec = getElements();
1172         float[] res = new float[length()];
1173         for (int i = 0; i < length(); i++){
1174             res[(j + i) % length()] = vec[i];
1175         }
1176         return new Float128Vector(res);
1177     }
1178 
1179     @Override
1180     public Float128Vector rotateER(int j) {
1181         float[] vec = getElements();
1182         float[] res = new float[length()];
1183         for (int i = 0; i < length(); i++){
1184             int z = i - j;
1185             if(j < 0) {
1186                 res[length() + z] = vec[i];
1187             } else {
1188                 res[z] = vec[i];
1189             }
1190         }
1191         return new Float128Vector(res);
1192     }
1193 
1194     @Override
1195     public Float128Vector shiftEL(int j) {
1196         float[] vec = getElements();
1197         float[] res = new float[length()];
1198         for (int i = 0; i < length() - j; i++) {
1199             res[i] = vec[i + j];
1200         }
1201         return new Float128Vector(res);
1202     }
1203 
1204     @Override
1205     public Float128Vector shiftER(int j) {
1206         float[] vec = getElements();
1207         float[] res = new float[length()];
1208         for (int i = 0; i < length() - j; i++){
1209             res[i + j] = vec[i];
1210         }
1211         return new Float128Vector(res);
1212     }
1213 
1214     @Override
1215     @ForceInline
1216     public Float128Vector rearrange(Vector<Float> v,
1217                                   VectorShuffle<Float> s, VectorMask<Float> m) {
1218         return this.rearrange(s).blend(v.rearrange(s), m);
1219     }
1220 
1221     @Override
1222     @ForceInline
1223     public Float128Vector rearrange(VectorShuffle<Float> o1) {
1224         Objects.requireNonNull(o1);
1225         Float128Shuffle s =  (Float128Shuffle)o1;




 146 
 147     @Override
 148     float rOp(float v, FBinOp f) {
 149         float[] vec = getElements();
 150         for (int i = 0; i < length(); i++) {
 151             v = f.apply(i, v, vec[i]);
 152         }
 153         return v;
 154     }
 155 
 156     @Override
 157     @ForceInline
 158     public <F> Vector<F> cast(VectorSpecies<F> s) {
 159         Objects.requireNonNull(s);
 160         if (s.length() != LENGTH)
 161             throw new IllegalArgumentException("Vector length this species length differ");
 162 
 163         return VectorIntrinsics.cast(
 164             Float128Vector.class,
 165             float.class, LENGTH,
 166             s.vectorType(),
 167             s.elementType(), LENGTH,
 168             this, s,
 169             (species, vector) -> vector.castDefault(species)
 170         );
 171     }
 172 
 173     @SuppressWarnings("unchecked")
 174     @ForceInline
 175     private <F> Vector<F> castDefault(VectorSpecies<F> s) {
 176         int limit = s.length();
 177 
 178         Class<?> stype = s.elementType();
 179         if (stype == byte.class) {
 180             byte[] a = new byte[limit];
 181             for (int i = 0; i < limit; i++) {
 182                 a[i] = (byte) this.lane(i);
 183             }
 184             return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
 185         } else if (stype == short.class) {
 186             short[] a = new short[limit];


 284                 (species, vector) -> vector.defaultReinterpret(species)
 285             );
 286         } else if (stype == double.class) {
 287             return VectorIntrinsics.reinterpret(
 288                 Float128Vector.class,
 289                 float.class, LENGTH,
 290                 Double128Vector.class,
 291                 double.class, Double128Vector.LENGTH,
 292                 this, s,
 293                 (species, vector) -> vector.defaultReinterpret(species)
 294             );
 295         } else {
 296             throw new UnsupportedOperationException("Bad lane type for casting.");
 297         }
 298     }
 299 
 300     @Override
 301     @ForceInline
 302     public FloatVector reshape(VectorSpecies<Float> s) {
 303         Objects.requireNonNull(s);
 304         if (s.bitSize() == 64 && (s.vectorType() == Float64Vector.class)) {
 305             return VectorIntrinsics.reinterpret(
 306                 Float128Vector.class,
 307                 float.class, LENGTH,
 308                 Float64Vector.class,
 309                 float.class, Float64Vector.LENGTH,
 310                 this, s,
 311                 (species, vector) -> (FloatVector) vector.defaultReinterpret(species)
 312             );
 313         } else if (s.bitSize() == 128 && (s.vectorType() == Float128Vector.class)) {
 314             return VectorIntrinsics.reinterpret(
 315                 Float128Vector.class,
 316                 float.class, LENGTH,
 317                 Float128Vector.class,
 318                 float.class, Float128Vector.LENGTH,
 319                 this, s,
 320                 (species, vector) -> (FloatVector) vector.defaultReinterpret(species)
 321             );
 322         } else if (s.bitSize() == 256 && (s.vectorType() == Float256Vector.class)) {
 323             return VectorIntrinsics.reinterpret(
 324                 Float128Vector.class,
 325                 float.class, LENGTH,
 326                 Float256Vector.class,
 327                 float.class, Float256Vector.LENGTH,
 328                 this, s,
 329                 (species, vector) -> (FloatVector) vector.defaultReinterpret(species)
 330             );
 331         } else if (s.bitSize() == 512 && (s.vectorType() == Float512Vector.class)) {
 332             return VectorIntrinsics.reinterpret(
 333                 Float128Vector.class,
 334                 float.class, LENGTH,
 335                 Float512Vector.class,
 336                 float.class, Float512Vector.LENGTH,
 337                 this, s,
 338                 (species, vector) -> (FloatVector) vector.defaultReinterpret(species)
 339             );
 340         } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
 341                 && (s.bitSize() % 128 == 0) && (s.vectorType() == FloatMaxVector.class)) {
 342             return VectorIntrinsics.reinterpret(
 343                 Float128Vector.class,
 344                 float.class, LENGTH,
 345                 FloatMaxVector.class,
 346                 float.class, FloatMaxVector.LENGTH,
 347                 this, s,
 348                 (species, vector) -> (FloatVector) vector.defaultReinterpret(species)
 349             );
 350         } else {
 351             throw new InternalError("Unimplemented size");
 352         }
 353     }
 354 
 355     // Binary operations with scalars
 356 
 357     @Override
 358     @ForceInline
 359     public FloatVector add(float o) {
 360         return add((Float128Vector)FloatVector.broadcast(SPECIES, o));
 361     }


1150 
1151     @Override
1152     void forEach(VectorMask<Float> o, FUnCon f) {
1153         boolean[] mbits = ((Float128Mask)o).getBits();
1154         forEach((i, a) -> {
1155             if (mbits[i]) { f.apply(i, a); }
1156         });
1157     }
1158 
1159     Int128Vector toBits() {
1160         float[] vec = getElements();
1161         int[] res = new int[this.species().length()];
1162         for(int i = 0; i < this.species().length(); i++){
1163             res[i] = Float.floatToIntBits(vec[i]);
1164         }
1165         return new Int128Vector(res);
1166     }
1167 
1168 
1169     @Override
1170     public Float128Vector rotateLanesLeft(int j) {
1171         float[] vec = getElements();
1172         float[] res = new float[length()];
1173         for (int i = 0; i < length(); i++){
1174             res[(j + i) % length()] = vec[i];
1175         }
1176         return new Float128Vector(res);
1177     }
1178 
1179     @Override
1180     public Float128Vector rotateLanesRight(int j) {
1181         float[] vec = getElements();
1182         float[] res = new float[length()];
1183         for (int i = 0; i < length(); i++){
1184             int z = i - j;
1185             if(j < 0) {
1186                 res[length() + z] = vec[i];
1187             } else {
1188                 res[z] = vec[i];
1189             }
1190         }
1191         return new Float128Vector(res);
1192     }
1193 
1194     @Override
1195     public Float128Vector shiftLanesLeft(int j) {
1196         float[] vec = getElements();
1197         float[] res = new float[length()];
1198         for (int i = 0; i < length() - j; i++) {
1199             res[i] = vec[i + j];
1200         }
1201         return new Float128Vector(res);
1202     }
1203 
1204     @Override
1205     public Float128Vector shiftLanesRight(int j) {
1206         float[] vec = getElements();
1207         float[] res = new float[length()];
1208         for (int i = 0; i < length() - j; i++){
1209             res[i + j] = vec[i];
1210         }
1211         return new Float128Vector(res);
1212     }
1213 
1214     @Override
1215     @ForceInline
1216     public Float128Vector rearrange(Vector<Float> v,
1217                                   VectorShuffle<Float> s, VectorMask<Float> m) {
1218         return this.rearrange(s).blend(v.rearrange(s), m);
1219     }
1220 
1221     @Override
1222     @ForceInline
1223     public Float128Vector rearrange(VectorShuffle<Float> o1) {
1224         Objects.requireNonNull(o1);
1225         Float128Shuffle s =  (Float128Shuffle)o1;


< prev index next >