< prev index next >

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

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


 656     public Short256Vector blend(Vector<Short, Shapes.S256Bit> o1, Mask<Short, Shapes.S256Bit> o2) {
 657         Objects.requireNonNull(o1);
 658         Objects.requireNonNull(o2);
 659         Short256Vector v = (Short256Vector)o1;
 660         Short256Mask   m = (Short256Mask)o2;
 661 
 662         return (Short256Vector) VectorIntrinsics.blend(
 663             Short256Vector.class, Short256Mask.class, short.class, LENGTH,
 664             this, v, m,
 665             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
 666     }
 667 
 668     @Override
 669     @ForceInline
 670     @SuppressWarnings("unchecked")
 671     public <F> Vector<F, Shapes.S256Bit> rebracket(Species<F, Shapes.S256Bit> species) {
 672         Objects.requireNonNull(species);
 673         // TODO: check proper element type
 674         // TODO: update to pass the two species as an arguments and ideally
 675         // push down intrinsic call into species implementation
 676         return VectorIntrinsics.rebracket(
 677             Short256Vector.class, short.class, LENGTH,
 678             species.elementType(), this,
 679             (v, t) -> species.reshape(v)
 680         );
 681     }
 682 
 683     // Accessors
 684 
 685     @Override
 686     public short get(int i) {
 687         short[] vec = getElements();
 688         return vec[i];
 689     }
 690 
 691     @Override
 692     public Short256Vector with(int i, short e) {
 693         short[] res = vec.clone();
 694         res[i] = e;
 695         return new Short256Vector(res);
 696     }
 697 
 698     // Mask


 747         public Short256Species species() {
 748             return SPECIES;
 749         }
 750 
 751         @Override
 752         public Short256Vector toVector() {
 753             short[] res = new short[species().length()];
 754             boolean[] bits = getBits();
 755             for (int i = 0; i < species().length(); i++) {
 756                 res[i] = (short) (bits[i] ? -1 : 0);
 757             }
 758             return new Short256Vector(res);
 759         }
 760 
 761         @Override
 762         @ForceInline
 763         @SuppressWarnings("unchecked")
 764         public <Z> Mask<Z, Shapes.S256Bit> rebracket(Species<Z, Shapes.S256Bit> species) {
 765             Objects.requireNonNull(species);
 766             // TODO: check proper element type
 767             return VectorIntrinsics.rebracket(
 768                 Short256Mask.class, short.class, LENGTH,
 769                 species.elementType(), this,
 770                 (m, t) -> m.reshape(species)
 771             );
 772         }
 773 
 774         // Unary operations
 775 
 776         //Mask<E, S> not();
 777 
 778         // Binary operations
 779 
 780         @Override
 781         @ForceInline
 782         public Short256Mask and(Mask<Short,Shapes.S256Bit> o) {
 783             Objects.requireNonNull(o);
 784             Short256Mask m = (Short256Mask)o;
 785             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Short256Mask.class, short.class, LENGTH,
 786                                              this, m,
 787                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
 788         }
 789 


 846     public Short256Species species() {
 847         return SPECIES;
 848     }
 849 
 850     static final class Short256Species extends ShortSpecies<Shapes.S256Bit> {
 851         static final int BIT_SIZE = Shapes.S_256_BIT.bitSize();
 852 
 853         static final int LENGTH = BIT_SIZE / Short.SIZE;
 854 
 855         @Override
 856         public String toString() {
 857            StringBuilder sb = new StringBuilder("Shape[");
 858            sb.append(bitSize()).append(" bits, ");
 859            sb.append(length()).append(" ").append(short.class.getSimpleName()).append("s x ");
 860            sb.append(elementSize()).append(" bits");
 861            sb.append("]");
 862            return sb.toString();
 863         }
 864 
 865         @Override

 866         public int bitSize() {
 867             return BIT_SIZE;
 868         }
 869 
 870         @Override

 871         public int length() {
 872             return LENGTH;
 873         }
 874 
 875         @Override

 876         public Class<Short> elementType() {
 877             return Short.class;
 878         }
 879 
 880         @Override

 881         public int elementSize() {
 882             return Short.SIZE;
 883         }
 884 
 885         @Override

 886         public Shapes.S256Bit shape() {
 887             return Shapes.S_256_BIT;
 888         }
 889 
 890         @Override
 891         Short256Vector op(FOp f) {
 892             short[] res = new short[length()];
 893             for (int i = 0; i < length(); i++) {
 894                 res[i] = f.apply(i);
 895             }
 896             return new Short256Vector(res);
 897         }
 898 
 899         @Override
 900         Short256Vector op(Mask<Short, Shapes.S256Bit> o, FOp f) {
 901             short[] res = new short[length()];
 902             boolean[] mbits = ((Short256Mask)o).getBits();
 903             for (int i = 0; i < length(); i++) {
 904                 if (mbits[i]) {
 905                     res[i] = f.apply(i);


 960         public Short256Mask maskAllFalse() {
 961             return VectorIntrinsics.broadcastCoerced(Short256Mask.class, short.class, LENGTH,
 962                                                      0,
 963                                                      (z -> Short256Mask.FALSE_MASK));
 964         }
 965 
 966         @Override
 967         @ForceInline
 968         public Short256Vector fromArray(short[] a, int ix) {
 969             Objects.requireNonNull(a);
 970             ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
 971             return (Short256Vector) VectorIntrinsics.load(Short256Vector.class, short.class, LENGTH,
 972                                                         a, ix,
 973                                                         (arr, idx) -> super.fromArray((short[]) arr, idx));
 974         }
 975 
 976         @Override
 977         @ForceInline
 978         public Short256Vector fromArray(short[] a, int ax, Mask<Short, Shapes.S256Bit> m) {
 979             return zero().blend(fromArray(a, ax), m); // TODO: use better default impl: op(m, i -> a[ax + i]);






































 980         }
 981     }
 982 }


 656     public Short256Vector blend(Vector<Short, Shapes.S256Bit> o1, Mask<Short, Shapes.S256Bit> o2) {
 657         Objects.requireNonNull(o1);
 658         Objects.requireNonNull(o2);
 659         Short256Vector v = (Short256Vector)o1;
 660         Short256Mask   m = (Short256Mask)o2;
 661 
 662         return (Short256Vector) VectorIntrinsics.blend(
 663             Short256Vector.class, Short256Mask.class, short.class, LENGTH,
 664             this, v, m,
 665             (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
 666     }
 667 
 668     @Override
 669     @ForceInline
 670     @SuppressWarnings("unchecked")
 671     public <F> Vector<F, Shapes.S256Bit> rebracket(Species<F, Shapes.S256Bit> species) {
 672         Objects.requireNonNull(species);
 673         // TODO: check proper element type
 674         // TODO: update to pass the two species as an arguments and ideally
 675         // push down intrinsic call into species implementation
 676         return VectorIntrinsics.reinterpret(
 677             Short256Vector.class, short.class, LENGTH,
 678             species.elementType(), species.length(), this,
 679             (v, t) -> species.reshape(v)
 680         );
 681     }
 682 
 683     // Accessors
 684 
 685     @Override
 686     public short get(int i) {
 687         short[] vec = getElements();
 688         return vec[i];
 689     }
 690 
 691     @Override
 692     public Short256Vector with(int i, short e) {
 693         short[] res = vec.clone();
 694         res[i] = e;
 695         return new Short256Vector(res);
 696     }
 697 
 698     // Mask


 747         public Short256Species species() {
 748             return SPECIES;
 749         }
 750 
 751         @Override
 752         public Short256Vector toVector() {
 753             short[] res = new short[species().length()];
 754             boolean[] bits = getBits();
 755             for (int i = 0; i < species().length(); i++) {
 756                 res[i] = (short) (bits[i] ? -1 : 0);
 757             }
 758             return new Short256Vector(res);
 759         }
 760 
 761         @Override
 762         @ForceInline
 763         @SuppressWarnings("unchecked")
 764         public <Z> Mask<Z, Shapes.S256Bit> rebracket(Species<Z, Shapes.S256Bit> species) {
 765             Objects.requireNonNull(species);
 766             // TODO: check proper element type
 767             return VectorIntrinsics.reinterpret(
 768                 Short256Mask.class, short.class, LENGTH,
 769                 species.elementType(), species.length(), this,
 770                 (m, t) -> m.reshape(species)
 771             );
 772         }
 773 
 774         // Unary operations
 775 
 776         //Mask<E, S> not();
 777 
 778         // Binary operations
 779 
 780         @Override
 781         @ForceInline
 782         public Short256Mask and(Mask<Short,Shapes.S256Bit> o) {
 783             Objects.requireNonNull(o);
 784             Short256Mask m = (Short256Mask)o;
 785             return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Short256Mask.class, short.class, LENGTH,
 786                                              this, m,
 787                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
 788         }
 789 


 846     public Short256Species species() {
 847         return SPECIES;
 848     }
 849 
 850     static final class Short256Species extends ShortSpecies<Shapes.S256Bit> {
 851         static final int BIT_SIZE = Shapes.S_256_BIT.bitSize();
 852 
 853         static final int LENGTH = BIT_SIZE / Short.SIZE;
 854 
 855         @Override
 856         public String toString() {
 857            StringBuilder sb = new StringBuilder("Shape[");
 858            sb.append(bitSize()).append(" bits, ");
 859            sb.append(length()).append(" ").append(short.class.getSimpleName()).append("s x ");
 860            sb.append(elementSize()).append(" bits");
 861            sb.append("]");
 862            return sb.toString();
 863         }
 864 
 865         @Override
 866         @ForceInline
 867         public int bitSize() {
 868             return BIT_SIZE;
 869         }
 870 
 871         @Override
 872         @ForceInline
 873         public int length() {
 874             return LENGTH;
 875         }
 876 
 877         @Override
 878         @ForceInline
 879         public Class<Short> elementType() {
 880             return Short.class;
 881         }
 882 
 883         @Override
 884         @ForceInline
 885         public int elementSize() {
 886             return Short.SIZE;
 887         }
 888 
 889         @Override
 890         @ForceInline
 891         public Shapes.S256Bit shape() {
 892             return Shapes.S_256_BIT;
 893         }
 894 
 895         @Override
 896         Short256Vector op(FOp f) {
 897             short[] res = new short[length()];
 898             for (int i = 0; i < length(); i++) {
 899                 res[i] = f.apply(i);
 900             }
 901             return new Short256Vector(res);
 902         }
 903 
 904         @Override
 905         Short256Vector op(Mask<Short, Shapes.S256Bit> o, FOp f) {
 906             short[] res = new short[length()];
 907             boolean[] mbits = ((Short256Mask)o).getBits();
 908             for (int i = 0; i < length(); i++) {
 909                 if (mbits[i]) {
 910                     res[i] = f.apply(i);


 965         public Short256Mask maskAllFalse() {
 966             return VectorIntrinsics.broadcastCoerced(Short256Mask.class, short.class, LENGTH,
 967                                                      0,
 968                                                      (z -> Short256Mask.FALSE_MASK));
 969         }
 970 
 971         @Override
 972         @ForceInline
 973         public Short256Vector fromArray(short[] a, int ix) {
 974             Objects.requireNonNull(a);
 975             ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
 976             return (Short256Vector) VectorIntrinsics.load(Short256Vector.class, short.class, LENGTH,
 977                                                         a, ix,
 978                                                         (arr, idx) -> super.fromArray((short[]) arr, idx));
 979         }
 980 
 981         @Override
 982         @ForceInline
 983         public Short256Vector fromArray(short[] a, int ax, Mask<Short, Shapes.S256Bit> m) {
 984             return zero().blend(fromArray(a, ax), m); // TODO: use better default impl: op(m, i -> a[ax + i]);
 985         }
 986 
 987         @Override
 988         @ForceInline
 989         @SuppressWarnings("unchecked")
 990         public <T extends Shape> Short256Vector resize(Vector<Short, T> o) {
 991             Objects.requireNonNull(o);
 992             if (o.bitSize() == 64) {
 993                 Short64Vector so = (Short64Vector)o;
 994                 return VectorIntrinsics.reinterpret(
 995                     Short64Vector.class, short.class, so.length(),
 996                     Short.class, LENGTH, so,
 997                     (v, t) -> (Short256Vector)reshape(v)
 998                 );
 999             } else if (o.bitSize() == 128) {
1000                 Short128Vector so = (Short128Vector)o;
1001                 return VectorIntrinsics.reinterpret(
1002                     Short128Vector.class, short.class, so.length(),
1003                     Short.class, LENGTH, so,
1004                     (v, t) -> (Short256Vector)reshape(v)
1005                 );
1006             } else if (o.bitSize() == 256) {
1007                 Short256Vector so = (Short256Vector)o;
1008                 return VectorIntrinsics.reinterpret(
1009                     Short256Vector.class, short.class, so.length(),
1010                     Short.class, LENGTH, so,
1011                     (v, t) -> (Short256Vector)reshape(v)
1012                 );
1013             } else if (o.bitSize() == 512) {
1014                 Short512Vector so = (Short512Vector)o;
1015                 return VectorIntrinsics.reinterpret(
1016                     Short512Vector.class, short.class, so.length(),
1017                     Short.class, LENGTH, so,
1018                     (v, t) -> (Short256Vector)reshape(v)
1019                 );
1020             } else {
1021                 throw new InternalError("Unimplemented size");
1022             }
1023         }
1024     }
1025 }
< prev index next >