< prev index next >

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

Print this page
rev 49509 : [vector] Intrinsic support for resize


 727     public Int64Vector blend(Vector<Integer, Shapes.S64Bit> o1, Mask<Integer, Shapes.S64Bit> o2) {
 728         Objects.requireNonNull(o1);
 729         Objects.requireNonNull(o2);
 730         Int64Vector v = (Int64Vector)o1;
 731         Int64Mask   m = (Int64Mask)o2;
 732 
 733         return (Int64Vector) VectorIntrinsics.blend(
 734             Int64Vector.class, Int64Mask.class, int.class, LENGTH,
 735             this, v, m,
 736             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
 737     }
 738 
 739     @Override
 740     @ForceInline
 741     @SuppressWarnings("unchecked")
 742     public <F> Vector<F, Shapes.S64Bit> rebracket(Species<F, Shapes.S64Bit> species) {
 743         Objects.requireNonNull(species);
 744         // TODO: check proper element type
 745         // TODO: update to pass the two species as an arguments and ideally
 746         // push down intrinsic call into species implementation
 747         return VectorIntrinsics.rebracket(
 748             Int64Vector.class, int.class, LENGTH,
 749             species.elementType(), this,
 750             (v, t) -> species.reshape(v)
 751         );
 752     }
 753 
 754     // Accessors
 755 
 756     @Override
 757     public int get(int i) {
 758         int[] vec = getElements();
 759         return vec[i];
 760     }
 761 
 762     @Override
 763     public Int64Vector with(int i, int e) {
 764         int[] res = vec.clone();
 765         res[i] = e;
 766         return new Int64Vector(res);
 767     }
 768 
 769     // Mask


 818         public Int64Species species() {
 819             return SPECIES;
 820         }
 821 
 822         @Override
 823         public Int64Vector toVector() {
 824             int[] res = new int[species().length()];
 825             boolean[] bits = getBits();
 826             for (int i = 0; i < species().length(); i++) {
 827                 res[i] = (int) (bits[i] ? -1 : 0);
 828             }
 829             return new Int64Vector(res);
 830         }
 831 
 832         @Override
 833         @ForceInline
 834         @SuppressWarnings("unchecked")
 835         public <Z> Mask<Z, Shapes.S64Bit> rebracket(Species<Z, Shapes.S64Bit> species) {
 836             Objects.requireNonNull(species);
 837             // TODO: check proper element type
 838             return VectorIntrinsics.rebracket(
 839                 Int64Mask.class, int.class, LENGTH,
 840                 species.elementType(), this,
 841                 (m, t) -> m.reshape(species)
 842             );
 843         }
 844 
 845         // Unary operations
 846 
 847         //Mask<E, S> not();
 848 
 849         // Binary operations
 850 
 851         @Override
 852         @ForceInline
 853         public Int64Mask and(Mask<Integer,Shapes.S64Bit> o) {
 854             Objects.requireNonNull(o);
 855             Int64Mask m = (Int64Mask)o;
 856             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Int64Mask.class, int.class, LENGTH,
 857                                              this, m,
 858                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
 859         }
 860 


 917     public Int64Species species() {
 918         return SPECIES;
 919     }
 920 
 921     static final class Int64Species extends IntSpecies<Shapes.S64Bit> {
 922         static final int BIT_SIZE = Shapes.S_64_BIT.bitSize();
 923 
 924         static final int LENGTH = BIT_SIZE / Integer.SIZE;
 925 
 926         @Override
 927         public String toString() {
 928            StringBuilder sb = new StringBuilder("Shape[");
 929            sb.append(bitSize()).append(" bits, ");
 930            sb.append(length()).append(" ").append(int.class.getSimpleName()).append("s x ");
 931            sb.append(elementSize()).append(" bits");
 932            sb.append("]");
 933            return sb.toString();
 934         }
 935 
 936         @Override

 937         public int bitSize() {
 938             return BIT_SIZE;
 939         }
 940 
 941         @Override

 942         public int length() {
 943             return LENGTH;
 944         }
 945 
 946         @Override

 947         public Class<Integer> elementType() {
 948             return Integer.class;
 949         }
 950 
 951         @Override

 952         public int elementSize() {
 953             return Integer.SIZE;
 954         }
 955 
 956         @Override

 957         public Shapes.S64Bit shape() {
 958             return Shapes.S_64_BIT;
 959         }
 960 
 961         @Override
 962         Int64Vector op(FOp f) {
 963             int[] res = new int[length()];
 964             for (int i = 0; i < length(); i++) {
 965                 res[i] = f.apply(i);
 966             }
 967             return new Int64Vector(res);
 968         }
 969 
 970         @Override
 971         Int64Vector op(Mask<Integer, Shapes.S64Bit> o, FOp f) {
 972             int[] res = new int[length()];
 973             boolean[] mbits = ((Int64Mask)o).getBits();
 974             for (int i = 0; i < length(); i++) {
 975                 if (mbits[i]) {
 976                     res[i] = f.apply(i);


1031         public Int64Mask maskAllFalse() {
1032             return VectorIntrinsics.broadcastCoerced(Int64Mask.class, int.class, LENGTH,
1033                                                      0,
1034                                                      (z -> Int64Mask.FALSE_MASK));
1035         }
1036 
1037         @Override
1038         @ForceInline
1039         public Int64Vector fromArray(int[] a, int ix) {
1040             Objects.requireNonNull(a);
1041             ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
1042             return (Int64Vector) VectorIntrinsics.load(Int64Vector.class, int.class, LENGTH,
1043                                                         a, ix,
1044                                                         (arr, idx) -> super.fromArray((int[]) arr, idx));
1045         }
1046 
1047         @Override
1048         @ForceInline
1049         public Int64Vector fromArray(int[] a, int ax, Mask<Integer, Shapes.S64Bit> m) {
1050             return zero().blend(fromArray(a, ax), m); // TODO: use better default impl: op(m, i -> a[ax + i]);






































1051         }
1052     }
1053 }


 727     public Int64Vector blend(Vector<Integer, Shapes.S64Bit> o1, Mask<Integer, Shapes.S64Bit> o2) {
 728         Objects.requireNonNull(o1);
 729         Objects.requireNonNull(o2);
 730         Int64Vector v = (Int64Vector)o1;
 731         Int64Mask   m = (Int64Mask)o2;
 732 
 733         return (Int64Vector) VectorIntrinsics.blend(
 734             Int64Vector.class, Int64Mask.class, int.class, LENGTH,
 735             this, v, m,
 736             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
 737     }
 738 
 739     @Override
 740     @ForceInline
 741     @SuppressWarnings("unchecked")
 742     public <F> Vector<F, Shapes.S64Bit> rebracket(Species<F, Shapes.S64Bit> species) {
 743         Objects.requireNonNull(species);
 744         // TODO: check proper element type
 745         // TODO: update to pass the two species as an arguments and ideally
 746         // push down intrinsic call into species implementation
 747         return VectorIntrinsics.reinterpret(
 748             Int64Vector.class, int.class, LENGTH,
 749             species.elementType(), species.length(), this,
 750             (v, t) -> species.reshape(v)
 751         );
 752     }
 753 
 754     // Accessors
 755 
 756     @Override
 757     public int get(int i) {
 758         int[] vec = getElements();
 759         return vec[i];
 760     }
 761 
 762     @Override
 763     public Int64Vector with(int i, int e) {
 764         int[] res = vec.clone();
 765         res[i] = e;
 766         return new Int64Vector(res);
 767     }
 768 
 769     // Mask


 818         public Int64Species species() {
 819             return SPECIES;
 820         }
 821 
 822         @Override
 823         public Int64Vector toVector() {
 824             int[] res = new int[species().length()];
 825             boolean[] bits = getBits();
 826             for (int i = 0; i < species().length(); i++) {
 827                 res[i] = (int) (bits[i] ? -1 : 0);
 828             }
 829             return new Int64Vector(res);
 830         }
 831 
 832         @Override
 833         @ForceInline
 834         @SuppressWarnings("unchecked")
 835         public <Z> Mask<Z, Shapes.S64Bit> rebracket(Species<Z, Shapes.S64Bit> species) {
 836             Objects.requireNonNull(species);
 837             // TODO: check proper element type
 838             return VectorIntrinsics.reinterpret(
 839                 Int64Mask.class, int.class, LENGTH,
 840                 species.elementType(), species.length(), this,
 841                 (m, t) -> m.reshape(species)
 842             );
 843         }
 844 
 845         // Unary operations
 846 
 847         //Mask<E, S> not();
 848 
 849         // Binary operations
 850 
 851         @Override
 852         @ForceInline
 853         public Int64Mask and(Mask<Integer,Shapes.S64Bit> o) {
 854             Objects.requireNonNull(o);
 855             Int64Mask m = (Int64Mask)o;
 856             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Int64Mask.class, int.class, LENGTH,
 857                                              this, m,
 858                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
 859         }
 860 


 917     public Int64Species species() {
 918         return SPECIES;
 919     }
 920 
 921     static final class Int64Species extends IntSpecies<Shapes.S64Bit> {
 922         static final int BIT_SIZE = Shapes.S_64_BIT.bitSize();
 923 
 924         static final int LENGTH = BIT_SIZE / Integer.SIZE;
 925 
 926         @Override
 927         public String toString() {
 928            StringBuilder sb = new StringBuilder("Shape[");
 929            sb.append(bitSize()).append(" bits, ");
 930            sb.append(length()).append(" ").append(int.class.getSimpleName()).append("s x ");
 931            sb.append(elementSize()).append(" bits");
 932            sb.append("]");
 933            return sb.toString();
 934         }
 935 
 936         @Override
 937         @ForceInline
 938         public int bitSize() {
 939             return BIT_SIZE;
 940         }
 941 
 942         @Override
 943         @ForceInline
 944         public int length() {
 945             return LENGTH;
 946         }
 947 
 948         @Override
 949         @ForceInline
 950         public Class<Integer> elementType() {
 951             return Integer.class;
 952         }
 953 
 954         @Override
 955         @ForceInline
 956         public int elementSize() {
 957             return Integer.SIZE;
 958         }
 959 
 960         @Override
 961         @ForceInline
 962         public Shapes.S64Bit shape() {
 963             return Shapes.S_64_BIT;
 964         }
 965 
 966         @Override
 967         Int64Vector op(FOp f) {
 968             int[] res = new int[length()];
 969             for (int i = 0; i < length(); i++) {
 970                 res[i] = f.apply(i);
 971             }
 972             return new Int64Vector(res);
 973         }
 974 
 975         @Override
 976         Int64Vector op(Mask<Integer, Shapes.S64Bit> o, FOp f) {
 977             int[] res = new int[length()];
 978             boolean[] mbits = ((Int64Mask)o).getBits();
 979             for (int i = 0; i < length(); i++) {
 980                 if (mbits[i]) {
 981                     res[i] = f.apply(i);


1036         public Int64Mask maskAllFalse() {
1037             return VectorIntrinsics.broadcastCoerced(Int64Mask.class, int.class, LENGTH,
1038                                                      0,
1039                                                      (z -> Int64Mask.FALSE_MASK));
1040         }
1041 
1042         @Override
1043         @ForceInline
1044         public Int64Vector fromArray(int[] a, int ix) {
1045             Objects.requireNonNull(a);
1046             ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
1047             return (Int64Vector) VectorIntrinsics.load(Int64Vector.class, int.class, LENGTH,
1048                                                         a, ix,
1049                                                         (arr, idx) -> super.fromArray((int[]) arr, idx));
1050         }
1051 
1052         @Override
1053         @ForceInline
1054         public Int64Vector fromArray(int[] a, int ax, Mask<Integer, Shapes.S64Bit> m) {
1055             return zero().blend(fromArray(a, ax), m); // TODO: use better default impl: op(m, i -> a[ax + i]);
1056         }
1057 
1058         @Override
1059         @ForceInline
1060         @SuppressWarnings("unchecked")
1061         public <T extends Shape> Int64Vector resize(Vector<Integer, T> o) {
1062             Objects.requireNonNull(o);
1063             if (o.bitSize() == 64) {
1064                 Int64Vector so = (Int64Vector)o;
1065                 return VectorIntrinsics.reinterpret(
1066                     Int64Vector.class, int.class, so.length(),
1067                     Integer.class, LENGTH, so,
1068                     (v, t) -> (Int64Vector)reshape(v)
1069                 );
1070             } else if (o.bitSize() == 128) {
1071                 Int128Vector so = (Int128Vector)o;
1072                 return VectorIntrinsics.reinterpret(
1073                     Int128Vector.class, int.class, so.length(),
1074                     Integer.class, LENGTH, so,
1075                     (v, t) -> (Int64Vector)reshape(v)
1076                 );
1077             } else if (o.bitSize() == 256) {
1078                 Int256Vector so = (Int256Vector)o;
1079                 return VectorIntrinsics.reinterpret(
1080                     Int256Vector.class, int.class, so.length(),
1081                     Integer.class, LENGTH, so,
1082                     (v, t) -> (Int64Vector)reshape(v)
1083                 );
1084             } else if (o.bitSize() == 512) {
1085                 Int512Vector so = (Int512Vector)o;
1086                 return VectorIntrinsics.reinterpret(
1087                     Int512Vector.class, int.class, so.length(),
1088                     Integer.class, LENGTH, so,
1089                     (v, t) -> (Int64Vector)reshape(v)
1090                 );
1091             } else {
1092                 throw new InternalError("Unimplemented size");
1093             }
1094         }
1095     }
1096 }
< prev index next >