656 public Byte256Vector blend(Vector<Byte, Shapes.S256Bit> o1, Mask<Byte, Shapes.S256Bit> o2) {
657 Objects.requireNonNull(o1);
658 Objects.requireNonNull(o2);
659 Byte256Vector v = (Byte256Vector)o1;
660 Byte256Mask m = (Byte256Mask)o2;
661
662 return (Byte256Vector) VectorIntrinsics.blend(
663 Byte256Vector.class, Byte256Mask.class, byte.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 Byte256Vector.class, byte.class, LENGTH,
678 species.elementType(), this,
679 (v, t) -> species.reshape(v)
680 );
681 }
682
683 // Accessors
684
685 @Override
686 public byte get(int i) {
687 byte[] vec = getElements();
688 return vec[i];
689 }
690
691 @Override
692 public Byte256Vector with(int i, byte e) {
693 byte[] res = vec.clone();
694 res[i] = e;
695 return new Byte256Vector(res);
696 }
697
698 // Mask
747 public Byte256Species species() {
748 return SPECIES;
749 }
750
751 @Override
752 public Byte256Vector toVector() {
753 byte[] res = new byte[species().length()];
754 boolean[] bits = getBits();
755 for (int i = 0; i < species().length(); i++) {
756 res[i] = (byte) (bits[i] ? -1 : 0);
757 }
758 return new Byte256Vector(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 Byte256Mask.class, byte.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 Byte256Mask and(Mask<Byte,Shapes.S256Bit> o) {
783 Objects.requireNonNull(o);
784 Byte256Mask m = (Byte256Mask)o;
785 return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Byte256Mask.class, byte.class, LENGTH,
786 this, m,
787 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
788 }
789
846 public Byte256Species species() {
847 return SPECIES;
848 }
849
850 static final class Byte256Species extends ByteSpecies<Shapes.S256Bit> {
851 static final int BIT_SIZE = Shapes.S_256_BIT.bitSize();
852
853 static final int LENGTH = BIT_SIZE / Byte.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(byte.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<Byte> elementType() {
877 return Byte.class;
878 }
879
880 @Override
881 public int elementSize() {
882 return Byte.SIZE;
883 }
884
885 @Override
886 public Shapes.S256Bit shape() {
887 return Shapes.S_256_BIT;
888 }
889
890 @Override
891 Byte256Vector op(FOp f) {
892 byte[] res = new byte[length()];
893 for (int i = 0; i < length(); i++) {
894 res[i] = f.apply(i);
895 }
896 return new Byte256Vector(res);
897 }
898
899 @Override
900 Byte256Vector op(Mask<Byte, Shapes.S256Bit> o, FOp f) {
901 byte[] res = new byte[length()];
902 boolean[] mbits = ((Byte256Mask)o).getBits();
903 for (int i = 0; i < length(); i++) {
904 if (mbits[i]) {
905 res[i] = f.apply(i);
960 public Byte256Mask maskAllFalse() {
961 return VectorIntrinsics.broadcastCoerced(Byte256Mask.class, byte.class, LENGTH,
962 0,
963 (z -> Byte256Mask.FALSE_MASK));
964 }
965
966 @Override
967 @ForceInline
968 public Byte256Vector fromArray(byte[] a, int ix) {
969 Objects.requireNonNull(a);
970 ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
971 return (Byte256Vector) VectorIntrinsics.load(Byte256Vector.class, byte.class, LENGTH,
972 a, ix,
973 (arr, idx) -> super.fromArray((byte[]) arr, idx));
974 }
975
976 @Override
977 @ForceInline
978 public Byte256Vector fromArray(byte[] a, int ax, Mask<Byte, 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 Byte256Vector blend(Vector<Byte, Shapes.S256Bit> o1, Mask<Byte, Shapes.S256Bit> o2) {
657 Objects.requireNonNull(o1);
658 Objects.requireNonNull(o2);
659 Byte256Vector v = (Byte256Vector)o1;
660 Byte256Mask m = (Byte256Mask)o2;
661
662 return (Byte256Vector) VectorIntrinsics.blend(
663 Byte256Vector.class, Byte256Mask.class, byte.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 Byte256Vector.class, byte.class, LENGTH,
678 species.elementType(), species.length(), this,
679 (v, t) -> species.reshape(v)
680 );
681 }
682
683 // Accessors
684
685 @Override
686 public byte get(int i) {
687 byte[] vec = getElements();
688 return vec[i];
689 }
690
691 @Override
692 public Byte256Vector with(int i, byte e) {
693 byte[] res = vec.clone();
694 res[i] = e;
695 return new Byte256Vector(res);
696 }
697
698 // Mask
747 public Byte256Species species() {
748 return SPECIES;
749 }
750
751 @Override
752 public Byte256Vector toVector() {
753 byte[] res = new byte[species().length()];
754 boolean[] bits = getBits();
755 for (int i = 0; i < species().length(); i++) {
756 res[i] = (byte) (bits[i] ? -1 : 0);
757 }
758 return new Byte256Vector(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 Byte256Mask.class, byte.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 Byte256Mask and(Mask<Byte,Shapes.S256Bit> o) {
783 Objects.requireNonNull(o);
784 Byte256Mask m = (Byte256Mask)o;
785 return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Byte256Mask.class, byte.class, LENGTH,
786 this, m,
787 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
788 }
789
846 public Byte256Species species() {
847 return SPECIES;
848 }
849
850 static final class Byte256Species extends ByteSpecies<Shapes.S256Bit> {
851 static final int BIT_SIZE = Shapes.S_256_BIT.bitSize();
852
853 static final int LENGTH = BIT_SIZE / Byte.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(byte.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<Byte> elementType() {
880 return Byte.class;
881 }
882
883 @Override
884 @ForceInline
885 public int elementSize() {
886 return Byte.SIZE;
887 }
888
889 @Override
890 @ForceInline
891 public Shapes.S256Bit shape() {
892 return Shapes.S_256_BIT;
893 }
894
895 @Override
896 Byte256Vector op(FOp f) {
897 byte[] res = new byte[length()];
898 for (int i = 0; i < length(); i++) {
899 res[i] = f.apply(i);
900 }
901 return new Byte256Vector(res);
902 }
903
904 @Override
905 Byte256Vector op(Mask<Byte, Shapes.S256Bit> o, FOp f) {
906 byte[] res = new byte[length()];
907 boolean[] mbits = ((Byte256Mask)o).getBits();
908 for (int i = 0; i < length(); i++) {
909 if (mbits[i]) {
910 res[i] = f.apply(i);
965 public Byte256Mask maskAllFalse() {
966 return VectorIntrinsics.broadcastCoerced(Byte256Mask.class, byte.class, LENGTH,
967 0,
968 (z -> Byte256Mask.FALSE_MASK));
969 }
970
971 @Override
972 @ForceInline
973 public Byte256Vector fromArray(byte[] a, int ix) {
974 Objects.requireNonNull(a);
975 ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
976 return (Byte256Vector) VectorIntrinsics.load(Byte256Vector.class, byte.class, LENGTH,
977 a, ix,
978 (arr, idx) -> super.fromArray((byte[]) arr, idx));
979 }
980
981 @Override
982 @ForceInline
983 public Byte256Vector fromArray(byte[] a, int ax, Mask<Byte, 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> Byte256Vector resize(Vector<Byte, T> o) {
991 Objects.requireNonNull(o);
992 if (o.bitSize() == 64) {
993 Byte64Vector so = (Byte64Vector)o;
994 return VectorIntrinsics.reinterpret(
995 Byte64Vector.class, byte.class, so.length(),
996 Byte.class, LENGTH, so,
997 (v, t) -> (Byte256Vector)reshape(v)
998 );
999 } else if (o.bitSize() == 128) {
1000 Byte128Vector so = (Byte128Vector)o;
1001 return VectorIntrinsics.reinterpret(
1002 Byte128Vector.class, byte.class, so.length(),
1003 Byte.class, LENGTH, so,
1004 (v, t) -> (Byte256Vector)reshape(v)
1005 );
1006 } else if (o.bitSize() == 256) {
1007 Byte256Vector so = (Byte256Vector)o;
1008 return VectorIntrinsics.reinterpret(
1009 Byte256Vector.class, byte.class, so.length(),
1010 Byte.class, LENGTH, so,
1011 (v, t) -> (Byte256Vector)reshape(v)
1012 );
1013 } else if (o.bitSize() == 512) {
1014 Byte512Vector so = (Byte512Vector)o;
1015 return VectorIntrinsics.reinterpret(
1016 Byte512Vector.class, byte.class, so.length(),
1017 Byte.class, LENGTH, so,
1018 (v, t) -> (Byte256Vector)reshape(v)
1019 );
1020 } else {
1021 throw new InternalError("Unimplemented size");
1022 }
1023 }
1024 }
1025 }
|