< prev index next >

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

Print this page




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


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


1137 
1138     @Override
1139     void forEach(VectorMask<Double> o, FUnCon f) {
1140         boolean[] mbits = ((Double64Mask)o).getBits();
1141         forEach((i, a) -> {
1142             if (mbits[i]) { f.apply(i, a); }
1143         });
1144     }
1145 
1146     Long64Vector toBits() {
1147         double[] vec = getElements();
1148         long[] res = new long[this.species().length()];
1149         for(int i = 0; i < this.species().length(); i++){
1150             res[i] = Double.doubleToLongBits(vec[i]);
1151         }
1152         return new Long64Vector(res);
1153     }
1154 
1155 
1156     @Override
1157     public Double64Vector rotateEL(int j) {
1158         double[] vec = getElements();
1159         double[] res = new double[length()];
1160         for (int i = 0; i < length(); i++){
1161             res[(j + i) % length()] = vec[i];
1162         }
1163         return new Double64Vector(res);
1164     }
1165 
1166     @Override
1167     public Double64Vector rotateER(int j) {
1168         double[] vec = getElements();
1169         double[] res = new double[length()];
1170         for (int i = 0; i < length(); i++){
1171             int z = i - j;
1172             if(j < 0) {
1173                 res[length() + z] = vec[i];
1174             } else {
1175                 res[z] = vec[i];
1176             }
1177         }
1178         return new Double64Vector(res);
1179     }
1180 
1181     @Override
1182     public Double64Vector shiftEL(int j) {
1183         double[] vec = getElements();
1184         double[] res = new double[length()];
1185         for (int i = 0; i < length() - j; i++) {
1186             res[i] = vec[i + j];
1187         }
1188         return new Double64Vector(res);
1189     }
1190 
1191     @Override
1192     public Double64Vector shiftER(int j) {
1193         double[] vec = getElements();
1194         double[] res = new double[length()];
1195         for (int i = 0; i < length() - j; i++){
1196             res[i + j] = vec[i];
1197         }
1198         return new Double64Vector(res);
1199     }
1200 
1201     @Override
1202     @ForceInline
1203     public Double64Vector rearrange(Vector<Double> v,
1204                                   VectorShuffle<Double> s, VectorMask<Double> m) {
1205         return this.rearrange(s).blend(v.rearrange(s), m);
1206     }
1207 
1208     @Override
1209     @ForceInline
1210     public Double64Vector rearrange(VectorShuffle<Double> o1) {
1211         Objects.requireNonNull(o1);
1212         Double64Shuffle s =  (Double64Shuffle)o1;




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


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


1137 
1138     @Override
1139     void forEach(VectorMask<Double> o, FUnCon f) {
1140         boolean[] mbits = ((Double64Mask)o).getBits();
1141         forEach((i, a) -> {
1142             if (mbits[i]) { f.apply(i, a); }
1143         });
1144     }
1145 
1146     Long64Vector toBits() {
1147         double[] vec = getElements();
1148         long[] res = new long[this.species().length()];
1149         for(int i = 0; i < this.species().length(); i++){
1150             res[i] = Double.doubleToLongBits(vec[i]);
1151         }
1152         return new Long64Vector(res);
1153     }
1154 
1155 
1156     @Override
1157     public Double64Vector rotateLanesLeft(int j) {
1158         double[] vec = getElements();
1159         double[] res = new double[length()];
1160         for (int i = 0; i < length(); i++){
1161             res[(j + i) % length()] = vec[i];
1162         }
1163         return new Double64Vector(res);
1164     }
1165 
1166     @Override
1167     public Double64Vector rotateLanesRight(int j) {
1168         double[] vec = getElements();
1169         double[] res = new double[length()];
1170         for (int i = 0; i < length(); i++){
1171             int z = i - j;
1172             if(j < 0) {
1173                 res[length() + z] = vec[i];
1174             } else {
1175                 res[z] = vec[i];
1176             }
1177         }
1178         return new Double64Vector(res);
1179     }
1180 
1181     @Override
1182     public Double64Vector shiftLanesLeft(int j) {
1183         double[] vec = getElements();
1184         double[] res = new double[length()];
1185         for (int i = 0; i < length() - j; i++) {
1186             res[i] = vec[i + j];
1187         }
1188         return new Double64Vector(res);
1189     }
1190 
1191     @Override
1192     public Double64Vector shiftLanesRight(int j) {
1193         double[] vec = getElements();
1194         double[] res = new double[length()];
1195         for (int i = 0; i < length() - j; i++){
1196             res[i + j] = vec[i];
1197         }
1198         return new Double64Vector(res);
1199     }
1200 
1201     @Override
1202     @ForceInline
1203     public Double64Vector rearrange(Vector<Double> v,
1204                                   VectorShuffle<Double> s, VectorMask<Double> m) {
1205         return this.rearrange(s).blend(v.rearrange(s), m);
1206     }
1207 
1208     @Override
1209     @ForceInline
1210     public Double64Vector rearrange(VectorShuffle<Double> o1) {
1211         Objects.requireNonNull(o1);
1212         Double64Shuffle s =  (Double64Shuffle)o1;


< prev index next >