< prev index next >

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

Print this page




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


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


 640     @Override
 641     @ForceInline
 642     public Short128Vector and(Vector<Short> v, VectorMask<Short> m) {
 643         return blend(and(v), m);
 644     }
 645 
 646     @Override
 647     @ForceInline
 648     public Short128Vector or(Vector<Short> v, VectorMask<Short> m) {
 649         return blend(or(v), m);
 650     }
 651 
 652     @Override
 653     @ForceInline
 654     public Short128Vector xor(Vector<Short> v, VectorMask<Short> m) {
 655         return blend(xor(v), m);
 656     }
 657 
 658     @Override
 659     @ForceInline
 660     public Short128Vector shiftL(int s) {
 661         return VectorIntrinsics.broadcastInt(
 662             VECTOR_OP_LSHIFT, Short128Vector.class, short.class, LENGTH,
 663             this, s,
 664             (v, i) -> v.uOp((__, a) -> (short) (a << (i & 15))));
 665     }
 666 
 667     @Override
 668     @ForceInline
 669     public Short128Vector shiftL(int s, VectorMask<Short> m) {
 670         return blend(shiftL(s), m);
 671     }
 672 
 673     @Override
 674     @ForceInline
 675     public Short128Vector shiftR(int s) {









 676         return VectorIntrinsics.broadcastInt(
 677             VECTOR_OP_URSHIFT, Short128Vector.class, short.class, LENGTH,
 678             this, s,
 679             (v, i) -> v.uOp((__, a) -> (short) ((a & 0xFFFF) >>> (i & 15))));






 680     }
 681 
 682     @Override
 683     @ForceInline
 684     public Short128Vector shiftR(int s, VectorMask<Short> m) {
 685         return blend(shiftR(s), m);



 686     }
 687 
 688     @Override
 689     @ForceInline
 690     public Short128Vector aShiftR(int s) {
 691         return VectorIntrinsics.broadcastInt(
 692             VECTOR_OP_RSHIFT, Short128Vector.class, short.class, LENGTH,
 693             this, s,
 694             (v, i) -> v.uOp((__, a) -> (short) (a >> (i & 15))));






 695     }
 696 
 697     @Override
 698     @ForceInline
 699     public Short128Vector aShiftR(int s, VectorMask<Short> m) {
 700         return blend(aShiftR(s), m);



 701     }
 702     // Ternary operations
 703 
 704 
 705     // Type specific horizontal reductions
 706 
 707     @Override
 708     @ForceInline
 709     public short addAll() {
 710         return (short) VectorIntrinsics.reductionCoerced(
 711             VECTOR_OP_ADD, Short128Vector.class, short.class, LENGTH,
 712             this,
 713             v -> (long) v.rOp((short) 0, (i, a, b) -> (short) (a + b)));
 714     }
 715 
 716     @Override
 717     @ForceInline
 718     public short andAll() {
 719         return (short) VectorIntrinsics.reductionCoerced(
 720             VECTOR_OP_AND, Short128Vector.class, short.class, LENGTH,


1012 
1013     @Override
1014     void forEach(FUnCon f) {
1015         short[] vec = getElements();
1016         for (int i = 0; i < length(); i++) {
1017             f.apply(i, vec[i]);
1018         }
1019     }
1020 
1021     @Override
1022     void forEach(VectorMask<Short> o, FUnCon f) {
1023         boolean[] mbits = ((Short128Mask)o).getBits();
1024         forEach((i, a) -> {
1025             if (mbits[i]) { f.apply(i, a); }
1026         });
1027     }
1028 
1029 
1030 
1031     @Override
1032     public Short128Vector rotateEL(int j) {
1033         short[] vec = getElements();
1034         short[] res = new short[length()];
1035         for (int i = 0; i < length(); i++){
1036             res[(j + i) % length()] = vec[i];
1037         }
1038         return new Short128Vector(res);
1039     }
1040 
1041     @Override
1042     public Short128Vector rotateER(int j) {
1043         short[] vec = getElements();
1044         short[] res = new short[length()];
1045         for (int i = 0; i < length(); i++){
1046             int z = i - j;
1047             if(j < 0) {
1048                 res[length() + z] = vec[i];
1049             } else {
1050                 res[z] = vec[i];
1051             }
1052         }
1053         return new Short128Vector(res);
1054     }
1055 
1056     @Override
1057     public Short128Vector shiftEL(int j) {
1058         short[] vec = getElements();
1059         short[] res = new short[length()];
1060         for (int i = 0; i < length() - j; i++) {
1061             res[i] = vec[i + j];
1062         }
1063         return new Short128Vector(res);
1064     }
1065 
1066     @Override
1067     public Short128Vector shiftER(int j) {
1068         short[] vec = getElements();
1069         short[] res = new short[length()];
1070         for (int i = 0; i < length() - j; i++){
1071             res[i + j] = vec[i];
1072         }
1073         return new Short128Vector(res);
1074     }
1075 
1076     @Override
1077     @ForceInline
1078     public Short128Vector rearrange(Vector<Short> v,
1079                                   VectorShuffle<Short> s, VectorMask<Short> m) {
1080         return this.rearrange(s).blend(v.rearrange(s), m);
1081     }
1082 
1083     @Override
1084     @ForceInline
1085     public Short128Vector rearrange(VectorShuffle<Short> o1) {
1086         Objects.requireNonNull(o1);
1087         Short128Shuffle s =  (Short128Shuffle)o1;




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


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


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


1039 
1040     @Override
1041     void forEach(FUnCon f) {
1042         short[] vec = getElements();
1043         for (int i = 0; i < length(); i++) {
1044             f.apply(i, vec[i]);
1045         }
1046     }
1047 
1048     @Override
1049     void forEach(VectorMask<Short> o, FUnCon f) {
1050         boolean[] mbits = ((Short128Mask)o).getBits();
1051         forEach((i, a) -> {
1052             if (mbits[i]) { f.apply(i, a); }
1053         });
1054     }
1055 
1056 
1057 
1058     @Override
1059     public Short128Vector rotateLanesLeft(int j) {
1060         short[] vec = getElements();
1061         short[] res = new short[length()];
1062         for (int i = 0; i < length(); i++){
1063             res[(j + i) % length()] = vec[i];
1064         }
1065         return new Short128Vector(res);
1066     }
1067 
1068     @Override
1069     public Short128Vector rotateLanesRight(int j) {
1070         short[] vec = getElements();
1071         short[] res = new short[length()];
1072         for (int i = 0; i < length(); i++){
1073             int z = i - j;
1074             if(j < 0) {
1075                 res[length() + z] = vec[i];
1076             } else {
1077                 res[z] = vec[i];
1078             }
1079         }
1080         return new Short128Vector(res);
1081     }
1082 
1083     @Override
1084     public Short128Vector shiftLanesLeft(int j) {
1085         short[] vec = getElements();
1086         short[] res = new short[length()];
1087         for (int i = 0; i < length() - j; i++) {
1088             res[i] = vec[i + j];
1089         }
1090         return new Short128Vector(res);
1091     }
1092 
1093     @Override
1094     public Short128Vector shiftLanesRight(int j) {
1095         short[] vec = getElements();
1096         short[] res = new short[length()];
1097         for (int i = 0; i < length() - j; i++){
1098             res[i + j] = vec[i];
1099         }
1100         return new Short128Vector(res);
1101     }
1102 
1103     @Override
1104     @ForceInline
1105     public Short128Vector rearrange(Vector<Short> v,
1106                                   VectorShuffle<Short> s, VectorMask<Short> m) {
1107         return this.rearrange(s).blend(v.rearrange(s), m);
1108     }
1109 
1110     @Override
1111     @ForceInline
1112     public Short128Vector rearrange(VectorShuffle<Short> o1) {
1113         Objects.requireNonNull(o1);
1114         Short128Shuffle s =  (Short128Shuffle)o1;


< prev index next >