< prev index next >

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

Print this page




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


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


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









 675         return VectorIntrinsics.broadcastInt(
 676             VECTOR_OP_URSHIFT, ByteMaxVector.class, byte.class, LENGTH,
 677             this, s,
 678             (v, i) -> v.uOp((__, a) -> (byte) ((a & 0xFF) >>> (i & 7))));
 679     }
 680 
 681     @Override
 682     @ForceInline
 683     public ByteMaxVector shiftR(int s, VectorMask<Byte> m) {
 684         return blend(shiftR(s), m);
 685     }
 686 
 687     @Override
 688     @ForceInline
 689     public ByteMaxVector aShiftR(int s) {









 690         return VectorIntrinsics.broadcastInt(
 691             VECTOR_OP_RSHIFT, ByteMaxVector.class, byte.class, LENGTH,
 692             this, s,
 693             (v, i) -> v.uOp((__, a) -> (byte) (a >> (i & 7))));






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



 700     }

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


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




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


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


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


1039 
1040     @Override
1041     void forEach(FUnCon f) {
1042         byte[] 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<Byte> o, FUnCon f) {
1050         boolean[] mbits = ((ByteMaxMask)o).getBits();
1051         forEach((i, a) -> {
1052             if (mbits[i]) { f.apply(i, a); }
1053         });
1054     }
1055 
1056 
1057 
1058     @Override
1059     public ByteMaxVector rotateLanesLeft(int j) {
1060         byte[] vec = getElements();
1061         byte[] res = new byte[length()];
1062         for (int i = 0; i < length(); i++){
1063             res[(j + i) % length()] = vec[i];
1064         }
1065         return new ByteMaxVector(res);
1066     }
1067 
1068     @Override
1069     public ByteMaxVector rotateLanesRight(int j) {
1070         byte[] vec = getElements();
1071         byte[] res = new byte[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 ByteMaxVector(res);
1081     }
1082 
1083     @Override
1084     public ByteMaxVector shiftLanesLeft(int j) {
1085         byte[] vec = getElements();
1086         byte[] res = new byte[length()];
1087         for (int i = 0; i < length() - j; i++) {
1088             res[i] = vec[i + j];
1089         }
1090         return new ByteMaxVector(res);
1091     }
1092 
1093     @Override
1094     public ByteMaxVector shiftLanesRight(int j) {
1095         byte[] vec = getElements();
1096         byte[] res = new byte[length()];
1097         for (int i = 0; i < length() - j; i++){
1098             res[i + j] = vec[i];
1099         }
1100         return new ByteMaxVector(res);
1101     }
1102 
1103     @Override
1104     @ForceInline
1105     public ByteMaxVector rearrange(Vector<Byte> v,
1106                                   VectorShuffle<Byte> s, VectorMask<Byte> m) {
1107         return this.rearrange(s).blend(v.rearrange(s), m);
1108     }
1109 
1110     @Override
1111     @ForceInline
1112     public ByteMaxVector rearrange(VectorShuffle<Byte> o1) {
1113         Objects.requireNonNull(o1);
1114         ByteMaxShuffle s =  (ByteMaxShuffle)o1;


< prev index next >