690 public Long128Vector blend(Vector<Long, Shapes.S128Bit> o1, Mask<Long, Shapes.S128Bit> o2) {
691 Objects.requireNonNull(o1);
692 Objects.requireNonNull(o2);
693 Long128Vector v = (Long128Vector)o1;
694 Long128Mask m = (Long128Mask)o2;
695
696 return (Long128Vector) VectorIntrinsics.blend(
697 Long128Vector.class, Long128Mask.class, long.class, LENGTH,
698 this, v, m,
699 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
700 }
701
702 @Override
703 @ForceInline
704 @SuppressWarnings("unchecked")
705 public <F> Vector<F, Shapes.S128Bit> rebracket(Species<F, Shapes.S128Bit> species) {
706 Objects.requireNonNull(species);
707 // TODO: check proper element type
708 // TODO: update to pass the two species as an arguments and ideally
709 // push down intrinsic call into species implementation
710 return VectorIntrinsics.rebracket(
711 Long128Vector.class, long.class, LENGTH,
712 species.elementType(), this,
713 (v, t) -> species.reshape(v)
714 );
715 }
716
717 // Accessors
718
719 @Override
720 public long get(int i) {
721 long[] vec = getElements();
722 return vec[i];
723 }
724
725 @Override
726 public Long128Vector with(int i, long e) {
727 long[] res = vec.clone();
728 res[i] = e;
729 return new Long128Vector(res);
730 }
731
732 // Mask
781 public Long128Species species() {
782 return SPECIES;
783 }
784
785 @Override
786 public Long128Vector toVector() {
787 long[] res = new long[species().length()];
788 boolean[] bits = getBits();
789 for (int i = 0; i < species().length(); i++) {
790 res[i] = (long) (bits[i] ? -1 : 0);
791 }
792 return new Long128Vector(res);
793 }
794
795 @Override
796 @ForceInline
797 @SuppressWarnings("unchecked")
798 public <Z> Mask<Z, Shapes.S128Bit> rebracket(Species<Z, Shapes.S128Bit> species) {
799 Objects.requireNonNull(species);
800 // TODO: check proper element type
801 return VectorIntrinsics.rebracket(
802 Long128Mask.class, long.class, LENGTH,
803 species.elementType(), this,
804 (m, t) -> m.reshape(species)
805 );
806 }
807
808 // Unary operations
809
810 //Mask<E, S> not();
811
812 // Binary operations
813
814 @Override
815 @ForceInline
816 public Long128Mask and(Mask<Long,Shapes.S128Bit> o) {
817 Objects.requireNonNull(o);
818 Long128Mask m = (Long128Mask)o;
819 return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Long128Mask.class, long.class, LENGTH,
820 this, m,
821 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
822 }
823
880 public Long128Species species() {
881 return SPECIES;
882 }
883
884 static final class Long128Species extends LongSpecies<Shapes.S128Bit> {
885 static final int BIT_SIZE = Shapes.S_128_BIT.bitSize();
886
887 static final int LENGTH = BIT_SIZE / Long.SIZE;
888
889 @Override
890 public String toString() {
891 StringBuilder sb = new StringBuilder("Shape[");
892 sb.append(bitSize()).append(" bits, ");
893 sb.append(length()).append(" ").append(long.class.getSimpleName()).append("s x ");
894 sb.append(elementSize()).append(" bits");
895 sb.append("]");
896 return sb.toString();
897 }
898
899 @Override
900 public int bitSize() {
901 return BIT_SIZE;
902 }
903
904 @Override
905 public int length() {
906 return LENGTH;
907 }
908
909 @Override
910 public Class<Long> elementType() {
911 return Long.class;
912 }
913
914 @Override
915 public int elementSize() {
916 return Long.SIZE;
917 }
918
919 @Override
920 public Shapes.S128Bit shape() {
921 return Shapes.S_128_BIT;
922 }
923
924 @Override
925 Long128Vector op(FOp f) {
926 long[] res = new long[length()];
927 for (int i = 0; i < length(); i++) {
928 res[i] = f.apply(i);
929 }
930 return new Long128Vector(res);
931 }
932
933 @Override
934 Long128Vector op(Mask<Long, Shapes.S128Bit> o, FOp f) {
935 long[] res = new long[length()];
936 boolean[] mbits = ((Long128Mask)o).getBits();
937 for (int i = 0; i < length(); i++) {
938 if (mbits[i]) {
939 res[i] = f.apply(i);
994 public Long128Mask maskAllFalse() {
995 return VectorIntrinsics.broadcastCoerced(Long128Mask.class, long.class, LENGTH,
996 0,
997 (z -> Long128Mask.FALSE_MASK));
998 }
999
1000 @Override
1001 @ForceInline
1002 public Long128Vector fromArray(long[] a, int ix) {
1003 Objects.requireNonNull(a);
1004 ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
1005 return (Long128Vector) VectorIntrinsics.load(Long128Vector.class, long.class, LENGTH,
1006 a, ix,
1007 (arr, idx) -> super.fromArray((long[]) arr, idx));
1008 }
1009
1010 @Override
1011 @ForceInline
1012 public Long128Vector fromArray(long[] a, int ax, Mask<Long, Shapes.S128Bit> m) {
1013 return zero().blend(fromArray(a, ax), m); // TODO: use better default impl: op(m, i -> a[ax + i]);
1014 }
1015 }
1016 }
|
690 public Long128Vector blend(Vector<Long, Shapes.S128Bit> o1, Mask<Long, Shapes.S128Bit> o2) {
691 Objects.requireNonNull(o1);
692 Objects.requireNonNull(o2);
693 Long128Vector v = (Long128Vector)o1;
694 Long128Mask m = (Long128Mask)o2;
695
696 return (Long128Vector) VectorIntrinsics.blend(
697 Long128Vector.class, Long128Mask.class, long.class, LENGTH,
698 this, v, m,
699 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
700 }
701
702 @Override
703 @ForceInline
704 @SuppressWarnings("unchecked")
705 public <F> Vector<F, Shapes.S128Bit> rebracket(Species<F, Shapes.S128Bit> species) {
706 Objects.requireNonNull(species);
707 // TODO: check proper element type
708 // TODO: update to pass the two species as an arguments and ideally
709 // push down intrinsic call into species implementation
710 return VectorIntrinsics.reinterpret(
711 Long128Vector.class, long.class, LENGTH,
712 species.elementType(), species.length(), this,
713 (v, t) -> species.reshape(v)
714 );
715 }
716
717 // Accessors
718
719 @Override
720 public long get(int i) {
721 long[] vec = getElements();
722 return vec[i];
723 }
724
725 @Override
726 public Long128Vector with(int i, long e) {
727 long[] res = vec.clone();
728 res[i] = e;
729 return new Long128Vector(res);
730 }
731
732 // Mask
781 public Long128Species species() {
782 return SPECIES;
783 }
784
785 @Override
786 public Long128Vector toVector() {
787 long[] res = new long[species().length()];
788 boolean[] bits = getBits();
789 for (int i = 0; i < species().length(); i++) {
790 res[i] = (long) (bits[i] ? -1 : 0);
791 }
792 return new Long128Vector(res);
793 }
794
795 @Override
796 @ForceInline
797 @SuppressWarnings("unchecked")
798 public <Z> Mask<Z, Shapes.S128Bit> rebracket(Species<Z, Shapes.S128Bit> species) {
799 Objects.requireNonNull(species);
800 // TODO: check proper element type
801 return VectorIntrinsics.reinterpret(
802 Long128Mask.class, long.class, LENGTH,
803 species.elementType(), species.length(), this,
804 (m, t) -> m.reshape(species)
805 );
806 }
807
808 // Unary operations
809
810 //Mask<E, S> not();
811
812 // Binary operations
813
814 @Override
815 @ForceInline
816 public Long128Mask and(Mask<Long,Shapes.S128Bit> o) {
817 Objects.requireNonNull(o);
818 Long128Mask m = (Long128Mask)o;
819 return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Long128Mask.class, long.class, LENGTH,
820 this, m,
821 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
822 }
823
880 public Long128Species species() {
881 return SPECIES;
882 }
883
884 static final class Long128Species extends LongSpecies<Shapes.S128Bit> {
885 static final int BIT_SIZE = Shapes.S_128_BIT.bitSize();
886
887 static final int LENGTH = BIT_SIZE / Long.SIZE;
888
889 @Override
890 public String toString() {
891 StringBuilder sb = new StringBuilder("Shape[");
892 sb.append(bitSize()).append(" bits, ");
893 sb.append(length()).append(" ").append(long.class.getSimpleName()).append("s x ");
894 sb.append(elementSize()).append(" bits");
895 sb.append("]");
896 return sb.toString();
897 }
898
899 @Override
900 @ForceInline
901 public int bitSize() {
902 return BIT_SIZE;
903 }
904
905 @Override
906 @ForceInline
907 public int length() {
908 return LENGTH;
909 }
910
911 @Override
912 @ForceInline
913 public Class<Long> elementType() {
914 return Long.class;
915 }
916
917 @Override
918 @ForceInline
919 public int elementSize() {
920 return Long.SIZE;
921 }
922
923 @Override
924 @ForceInline
925 public Shapes.S128Bit shape() {
926 return Shapes.S_128_BIT;
927 }
928
929 @Override
930 Long128Vector op(FOp f) {
931 long[] res = new long[length()];
932 for (int i = 0; i < length(); i++) {
933 res[i] = f.apply(i);
934 }
935 return new Long128Vector(res);
936 }
937
938 @Override
939 Long128Vector op(Mask<Long, Shapes.S128Bit> o, FOp f) {
940 long[] res = new long[length()];
941 boolean[] mbits = ((Long128Mask)o).getBits();
942 for (int i = 0; i < length(); i++) {
943 if (mbits[i]) {
944 res[i] = f.apply(i);
999 public Long128Mask maskAllFalse() {
1000 return VectorIntrinsics.broadcastCoerced(Long128Mask.class, long.class, LENGTH,
1001 0,
1002 (z -> Long128Mask.FALSE_MASK));
1003 }
1004
1005 @Override
1006 @ForceInline
1007 public Long128Vector fromArray(long[] a, int ix) {
1008 Objects.requireNonNull(a);
1009 ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
1010 return (Long128Vector) VectorIntrinsics.load(Long128Vector.class, long.class, LENGTH,
1011 a, ix,
1012 (arr, idx) -> super.fromArray((long[]) arr, idx));
1013 }
1014
1015 @Override
1016 @ForceInline
1017 public Long128Vector fromArray(long[] a, int ax, Mask<Long, Shapes.S128Bit> m) {
1018 return zero().blend(fromArray(a, ax), m); // TODO: use better default impl: op(m, i -> a[ax + i]);
1019 }
1020
1021 @Override
1022 @ForceInline
1023 @SuppressWarnings("unchecked")
1024 public <T extends Shape> Long128Vector resize(Vector<Long, T> o) {
1025 Objects.requireNonNull(o);
1026 if (o.bitSize() == 64) {
1027 Long64Vector so = (Long64Vector)o;
1028 return VectorIntrinsics.reinterpret(
1029 Long64Vector.class, long.class, so.length(),
1030 Long.class, LENGTH, so,
1031 (v, t) -> (Long128Vector)reshape(v)
1032 );
1033 } else if (o.bitSize() == 128) {
1034 Long128Vector so = (Long128Vector)o;
1035 return VectorIntrinsics.reinterpret(
1036 Long128Vector.class, long.class, so.length(),
1037 Long.class, LENGTH, so,
1038 (v, t) -> (Long128Vector)reshape(v)
1039 );
1040 } else if (o.bitSize() == 256) {
1041 Long256Vector so = (Long256Vector)o;
1042 return VectorIntrinsics.reinterpret(
1043 Long256Vector.class, long.class, so.length(),
1044 Long.class, LENGTH, so,
1045 (v, t) -> (Long128Vector)reshape(v)
1046 );
1047 } else if (o.bitSize() == 512) {
1048 Long512Vector so = (Long512Vector)o;
1049 return VectorIntrinsics.reinterpret(
1050 Long512Vector.class, long.class, so.length(),
1051 Long.class, LENGTH, so,
1052 (v, t) -> (Long128Vector)reshape(v)
1053 );
1054 } else {
1055 throw new InternalError("Unimplemented size");
1056 }
1057 }
1058 }
1059 }
|