< prev index next >

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

Print this page




 145 
 146     @Override
 147     long rOp(long v, FBinOp f) {
 148         long[] 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             Long64Vector.class,
 164             long.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                 Long64Vector.class,
 288                 long.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 LongVector reshape(VectorSpecies<Long> s) {
 302         Objects.requireNonNull(s);
 303         if (s.bitSize() == 64 && (s.boxType() == Long64Vector.class)) {
 304             return VectorIntrinsics.reinterpret(
 305                 Long64Vector.class,
 306                 long.class, LENGTH,
 307                 Long64Vector.class,
 308                 long.class, Long64Vector.LENGTH,
 309                 this, s,
 310                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 311             );
 312         } else if (s.bitSize() == 128 && (s.boxType() == Long128Vector.class)) {
 313             return VectorIntrinsics.reinterpret(
 314                 Long64Vector.class,
 315                 long.class, LENGTH,
 316                 Long128Vector.class,
 317                 long.class, Long128Vector.LENGTH,
 318                 this, s,
 319                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 320             );
 321         } else if (s.bitSize() == 256 && (s.boxType() == Long256Vector.class)) {
 322             return VectorIntrinsics.reinterpret(
 323                 Long64Vector.class,
 324                 long.class, LENGTH,
 325                 Long256Vector.class,
 326                 long.class, Long256Vector.LENGTH,
 327                 this, s,
 328                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 329             );
 330         } else if (s.bitSize() == 512 && (s.boxType() == Long512Vector.class)) {
 331             return VectorIntrinsics.reinterpret(
 332                 Long64Vector.class,
 333                 long.class, LENGTH,
 334                 Long512Vector.class,
 335                 long.class, Long512Vector.LENGTH,
 336                 this, s,
 337                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 338             );
 339         } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
 340                 && (s.bitSize() % 128 == 0) && (s.boxType() == LongMaxVector.class)) {
 341             return VectorIntrinsics.reinterpret(
 342                 Long64Vector.class,
 343                 long.class, LENGTH,
 344                 LongMaxVector.class,
 345                 long.class, LongMaxVector.LENGTH,
 346                 this, s,
 347                 (species, vector) -> (LongVector) 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 LongVector add(long o) {
 359         return add((Long64Vector)LongVector.broadcast(SPECIES, o));
 360     }


 647     @Override
 648     @ForceInline
 649     public Long64Vector and(Vector<Long> v, VectorMask<Long> m) {
 650         return blend(and(v), m);
 651     }
 652 
 653     @Override
 654     @ForceInline
 655     public Long64Vector or(Vector<Long> v, VectorMask<Long> m) {
 656         return blend(or(v), m);
 657     }
 658 
 659     @Override
 660     @ForceInline
 661     public Long64Vector xor(Vector<Long> v, VectorMask<Long> m) {
 662         return blend(xor(v), m);
 663     }
 664 
 665     @Override
 666     @ForceInline
 667     public Long64Vector shiftL(int s) {
 668         return VectorIntrinsics.broadcastInt(
 669             VECTOR_OP_LSHIFT, Long64Vector.class, long.class, LENGTH,
 670             this, s,
 671             (v, i) -> v.uOp((__, a) -> (long) (a << i)));
 672     }
 673 
 674     @Override
 675     @ForceInline
 676     public Long64Vector shiftL(int s, VectorMask<Long> m) {
 677         return blend(shiftL(s), m);
 678     }
 679 
 680     @Override
 681     @ForceInline
 682     public Long64Vector shiftR(int s) {
 683         return VectorIntrinsics.broadcastInt(
 684             VECTOR_OP_URSHIFT, Long64Vector.class, long.class, LENGTH,
 685             this, s,
 686             (v, i) -> v.uOp((__, a) -> (long) (a >>> i)));
 687     }
 688 
 689     @Override
 690     @ForceInline
 691     public Long64Vector shiftR(int s, VectorMask<Long> m) {
 692         return blend(shiftR(s), m);
 693     }
 694 
 695     @Override
 696     @ForceInline
 697     public Long64Vector aShiftR(int s) {
 698         return VectorIntrinsics.broadcastInt(
 699             VECTOR_OP_RSHIFT, Long64Vector.class, long.class, LENGTH,
 700             this, s,
 701             (v, i) -> v.uOp((__, a) -> (long) (a >> i)));
 702     }
 703 
 704     @Override
 705     @ForceInline
 706     public Long64Vector aShiftR(int s, VectorMask<Long> m) {
 707         return blend(aShiftR(s), m);
 708     }
 709 
 710     @Override
 711     @ForceInline
 712     public Long64Vector shiftL(Vector<Long> s) {
 713         Long64Vector shiftv = (Long64Vector)s;
 714         // As per shift specification for Java, mask the shift count.
 715         shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
 716         return VectorIntrinsics.binaryOp(
 717             VECTOR_OP_LSHIFT, Long64Vector.class, long.class, LENGTH,
 718             this, shiftv,
 719             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a << b)));
 720     }
 721 
 722     @Override
 723     @ForceInline
 724     public Long64Vector shiftR(Vector<Long> s) {
 725         Long64Vector shiftv = (Long64Vector)s;
 726         // As per shift specification for Java, mask the shift count.
 727         shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
 728         return VectorIntrinsics.binaryOp(
 729             VECTOR_OP_URSHIFT, Long64Vector.class, long.class, LENGTH,
 730             this, shiftv,
 731             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a >>> b)));
 732     }
 733 
 734     @Override
 735     @ForceInline
 736     public Long64Vector aShiftR(Vector<Long> s) {
 737         Long64Vector shiftv = (Long64Vector)s;
 738         // As per shift specification for Java, mask the shift count.
 739         shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
 740         return VectorIntrinsics.binaryOp(
 741             VECTOR_OP_RSHIFT, Long64Vector.class, long.class, LENGTH,
 742             this, shiftv,
 743             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a >> b)));
 744     }
 745     // Ternary operations
 746 
 747 
 748     // Type specific horizontal reductions
 749 
 750     @Override
 751     @ForceInline
 752     public long addAll() {
 753         return (long) VectorIntrinsics.reductionCoerced(
 754             VECTOR_OP_ADD, Long64Vector.class, long.class, LENGTH,
 755             this,
 756             v -> (long) v.rOp((long) 0, (i, a, b) -> (long) (a + b)));


1077 
1078     @Override
1079     void forEach(VectorMask<Long> o, FUnCon f) {
1080         boolean[] mbits = ((Long64Mask)o).getBits();
1081         forEach((i, a) -> {
1082             if (mbits[i]) { f.apply(i, a); }
1083         });
1084     }
1085 
1086 
1087     Double64Vector toFP() {
1088         long[] vec = getElements();
1089         double[] res = new double[this.species().length()];
1090         for(int i = 0; i < this.species().length(); i++){
1091             res[i] = Double.longBitsToDouble(vec[i]);
1092         }
1093         return new Double64Vector(res);
1094     }
1095 
1096     @Override
1097     public Long64Vector rotateEL(int j) {
1098         long[] vec = getElements();
1099         long[] res = new long[length()];
1100         for (int i = 0; i < length(); i++){
1101             res[(j + i) % length()] = vec[i];
1102         }
1103         return new Long64Vector(res);
1104     }
1105 
1106     @Override
1107     public Long64Vector rotateER(int j) {
1108         long[] vec = getElements();
1109         long[] res = new long[length()];
1110         for (int i = 0; i < length(); i++){
1111             int z = i - j;
1112             if(j < 0) {
1113                 res[length() + z] = vec[i];
1114             } else {
1115                 res[z] = vec[i];
1116             }
1117         }
1118         return new Long64Vector(res);
1119     }
1120 
1121     @Override
1122     public Long64Vector shiftEL(int j) {
1123         long[] vec = getElements();
1124         long[] res = new long[length()];
1125         for (int i = 0; i < length() - j; i++) {
1126             res[i] = vec[i + j];
1127         }
1128         return new Long64Vector(res);
1129     }
1130 
1131     @Override
1132     public Long64Vector shiftER(int j) {
1133         long[] vec = getElements();
1134         long[] res = new long[length()];
1135         for (int i = 0; i < length() - j; i++){
1136             res[i + j] = vec[i];
1137         }
1138         return new Long64Vector(res);
1139     }
1140 
1141     @Override
1142     @ForceInline
1143     public Long64Vector rearrange(Vector<Long> v,
1144                                   VectorShuffle<Long> s, VectorMask<Long> m) {
1145         return this.rearrange(s).blend(v.rearrange(s), m);
1146     }
1147 
1148     @Override
1149     @ForceInline
1150     public Long64Vector rearrange(VectorShuffle<Long> o1) {
1151         Objects.requireNonNull(o1);
1152         Long64Shuffle s =  (Long64Shuffle)o1;




 145 
 146     @Override
 147     long rOp(long v, FBinOp f) {
 148         long[] 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             Long64Vector.class,
 164             long.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                 Long64Vector.class,
 288                 long.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 LongVector reshape(VectorSpecies<Long> s) {
 302         Objects.requireNonNull(s);
 303         if (s.bitSize() == 64 && (s.vectorType() == Long64Vector.class)) {
 304             return VectorIntrinsics.reinterpret(
 305                 Long64Vector.class,
 306                 long.class, LENGTH,
 307                 Long64Vector.class,
 308                 long.class, Long64Vector.LENGTH,
 309                 this, s,
 310                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 311             );
 312         } else if (s.bitSize() == 128 && (s.vectorType() == Long128Vector.class)) {
 313             return VectorIntrinsics.reinterpret(
 314                 Long64Vector.class,
 315                 long.class, LENGTH,
 316                 Long128Vector.class,
 317                 long.class, Long128Vector.LENGTH,
 318                 this, s,
 319                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 320             );
 321         } else if (s.bitSize() == 256 && (s.vectorType() == Long256Vector.class)) {
 322             return VectorIntrinsics.reinterpret(
 323                 Long64Vector.class,
 324                 long.class, LENGTH,
 325                 Long256Vector.class,
 326                 long.class, Long256Vector.LENGTH,
 327                 this, s,
 328                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 329             );
 330         } else if (s.bitSize() == 512 && (s.vectorType() == Long512Vector.class)) {
 331             return VectorIntrinsics.reinterpret(
 332                 Long64Vector.class,
 333                 long.class, LENGTH,
 334                 Long512Vector.class,
 335                 long.class, Long512Vector.LENGTH,
 336                 this, s,
 337                 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
 338             );
 339         } else if ((s.bitSize() > 0) && (s.bitSize() <= 2048)
 340                 && (s.bitSize() % 128 == 0) && (s.vectorType() == LongMaxVector.class)) {
 341             return VectorIntrinsics.reinterpret(
 342                 Long64Vector.class,
 343                 long.class, LENGTH,
 344                 LongMaxVector.class,
 345                 long.class, LongMaxVector.LENGTH,
 346                 this, s,
 347                 (species, vector) -> (LongVector) 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 LongVector add(long o) {
 359         return add((Long64Vector)LongVector.broadcast(SPECIES, o));
 360     }


 647     @Override
 648     @ForceInline
 649     public Long64Vector and(Vector<Long> v, VectorMask<Long> m) {
 650         return blend(and(v), m);
 651     }
 652 
 653     @Override
 654     @ForceInline
 655     public Long64Vector or(Vector<Long> v, VectorMask<Long> m) {
 656         return blend(or(v), m);
 657     }
 658 
 659     @Override
 660     @ForceInline
 661     public Long64Vector xor(Vector<Long> v, VectorMask<Long> m) {
 662         return blend(xor(v), m);
 663     }
 664 
 665     @Override
 666     @ForceInline
 667     public Long64Vector shiftLeft(int s) {
 668         return VectorIntrinsics.broadcastInt(
 669             VECTOR_OP_LSHIFT, Long64Vector.class, long.class, LENGTH,
 670             this, s,
 671             (v, i) -> v.uOp((__, a) -> (long) (a << i)));
 672     }
 673 
 674     @Override
 675     @ForceInline
 676     public Long64Vector shiftLeft(int s, VectorMask<Long> m) {
 677         return blend(shiftLeft(s), m);
 678     }
 679 
 680     @Override
 681     @ForceInline
 682     public Long64Vector shiftRight(int s) {
 683         return VectorIntrinsics.broadcastInt(
 684             VECTOR_OP_URSHIFT, Long64Vector.class, long.class, LENGTH,
 685             this, s,
 686             (v, i) -> v.uOp((__, a) -> (long) (a >>> i)));
 687     }
 688 
 689     @Override
 690     @ForceInline
 691     public Long64Vector shiftRight(int s, VectorMask<Long> m) {
 692         return blend(shiftRight(s), m);
 693     }
 694 
 695     @Override
 696     @ForceInline
 697     public Long64Vector shiftArithmeticRight(int s) {
 698         return VectorIntrinsics.broadcastInt(
 699             VECTOR_OP_RSHIFT, Long64Vector.class, long.class, LENGTH,
 700             this, s,
 701             (v, i) -> v.uOp((__, a) -> (long) (a >> i)));
 702     }
 703 
 704     @Override
 705     @ForceInline
 706     public Long64Vector shiftArithmeticRight(int s, VectorMask<Long> m) {
 707         return blend(shiftArithmeticRight(s), m);
 708     }
 709 
 710     @Override
 711     @ForceInline
 712     public Long64Vector shiftLeft(Vector<Long> s) {
 713         Long64Vector shiftv = (Long64Vector)s;
 714         // As per shift specification for Java, mask the shift count.
 715         shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
 716         return VectorIntrinsics.binaryOp(
 717             VECTOR_OP_LSHIFT, Long64Vector.class, long.class, LENGTH,
 718             this, shiftv,
 719             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a << b)));
 720     }
 721 
 722     @Override
 723     @ForceInline
 724     public Long64Vector shiftRight(Vector<Long> s) {
 725         Long64Vector shiftv = (Long64Vector)s;
 726         // As per shift specification for Java, mask the shift count.
 727         shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
 728         return VectorIntrinsics.binaryOp(
 729             VECTOR_OP_URSHIFT, Long64Vector.class, long.class, LENGTH,
 730             this, shiftv,
 731             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a >>> b)));
 732     }
 733 
 734     @Override
 735     @ForceInline
 736     public Long64Vector shiftArithmeticRight(Vector<Long> s) {
 737         Long64Vector shiftv = (Long64Vector)s;
 738         // As per shift specification for Java, mask the shift count.
 739         shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
 740         return VectorIntrinsics.binaryOp(
 741             VECTOR_OP_RSHIFT, Long64Vector.class, long.class, LENGTH,
 742             this, shiftv,
 743             (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a >> b)));
 744     }
 745     // Ternary operations
 746 
 747 
 748     // Type specific horizontal reductions
 749 
 750     @Override
 751     @ForceInline
 752     public long addAll() {
 753         return (long) VectorIntrinsics.reductionCoerced(
 754             VECTOR_OP_ADD, Long64Vector.class, long.class, LENGTH,
 755             this,
 756             v -> (long) v.rOp((long) 0, (i, a, b) -> (long) (a + b)));


1077 
1078     @Override
1079     void forEach(VectorMask<Long> o, FUnCon f) {
1080         boolean[] mbits = ((Long64Mask)o).getBits();
1081         forEach((i, a) -> {
1082             if (mbits[i]) { f.apply(i, a); }
1083         });
1084     }
1085 
1086 
1087     Double64Vector toFP() {
1088         long[] vec = getElements();
1089         double[] res = new double[this.species().length()];
1090         for(int i = 0; i < this.species().length(); i++){
1091             res[i] = Double.longBitsToDouble(vec[i]);
1092         }
1093         return new Double64Vector(res);
1094     }
1095 
1096     @Override
1097     public Long64Vector rotateLanesLeft(int j) {
1098         long[] vec = getElements();
1099         long[] res = new long[length()];
1100         for (int i = 0; i < length(); i++){
1101             res[(j + i) % length()] = vec[i];
1102         }
1103         return new Long64Vector(res);
1104     }
1105 
1106     @Override
1107     public Long64Vector rotateLanesRight(int j) {
1108         long[] vec = getElements();
1109         long[] res = new long[length()];
1110         for (int i = 0; i < length(); i++){
1111             int z = i - j;
1112             if(j < 0) {
1113                 res[length() + z] = vec[i];
1114             } else {
1115                 res[z] = vec[i];
1116             }
1117         }
1118         return new Long64Vector(res);
1119     }
1120 
1121     @Override
1122     public Long64Vector shiftLanesLeft(int j) {
1123         long[] vec = getElements();
1124         long[] res = new long[length()];
1125         for (int i = 0; i < length() - j; i++) {
1126             res[i] = vec[i + j];
1127         }
1128         return new Long64Vector(res);
1129     }
1130 
1131     @Override
1132     public Long64Vector shiftLanesRight(int j) {
1133         long[] vec = getElements();
1134         long[] res = new long[length()];
1135         for (int i = 0; i < length() - j; i++){
1136             res[i + j] = vec[i];
1137         }
1138         return new Long64Vector(res);
1139     }
1140 
1141     @Override
1142     @ForceInline
1143     public Long64Vector rearrange(Vector<Long> v,
1144                                   VectorShuffle<Long> s, VectorMask<Long> m) {
1145         return this.rearrange(s).blend(v.rearrange(s), m);
1146     }
1147 
1148     @Override
1149     @ForceInline
1150     public Long64Vector rearrange(VectorShuffle<Long> o1) {
1151         Objects.requireNonNull(o1);
1152         Long64Shuffle s =  (Long64Shuffle)o1;


< prev index next >