882 public $vectortype$ blend(Vector<$Boxtype$, Shapes.$shape$> o1, Mask<$Boxtype$, Shapes.$shape$> o2) {
883 Objects.requireNonNull(o1);
884 Objects.requireNonNull(o2);
885 $vectortype$ v = ($vectortype$)o1;
886 $masktype$ m = ($masktype$)o2;
887
888 return ($vectortype$) VectorIntrinsics.blend(
889 $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
890 this, v, m,
891 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
892 }
893
894 @Override
895 @ForceInline
896 @SuppressWarnings("unchecked")
897 public <F> Vector<F, Shapes.$shape$> rebracket(Species<F, Shapes.$shape$> species) {
898 Objects.requireNonNull(species);
899 // TODO: check proper element type
900 // TODO: update to pass the two species as an arguments and ideally
901 // push down intrinsic call into species implementation
902 return VectorIntrinsics.rebracket(
903 $vectortype$.class, $type$.class, LENGTH,
904 species.elementType(), this,
905 (v, t) -> species.reshape(v)
906 );
907 }
908
909 // Accessors
910
911 @Override
912 public $type$ get(int i) {
913 $type$[] vec = getElements();
914 return vec[i];
915 }
916
917 @Override
918 public $vectortype$ with(int i, $type$ e) {
919 $type$[] res = vec.clone();
920 res[i] = e;
921 return new $vectortype$(res);
922 }
923
924 // Mask
973 public $Type$$bits$Species species() {
974 return SPECIES;
975 }
976
977 @Override
978 public $vectortype$ toVector() {
979 $type$[] res = new $type$[species().length()];
980 boolean[] bits = getBits();
981 for (int i = 0; i < species().length(); i++) {
982 res[i] = ($type$) (bits[i] ? -1 : 0);
983 }
984 return new $vectortype$(res);
985 }
986
987 @Override
988 @ForceInline
989 @SuppressWarnings("unchecked")
990 public <Z> Mask<Z, Shapes.$shape$> rebracket(Species<Z, Shapes.$shape$> species) {
991 Objects.requireNonNull(species);
992 // TODO: check proper element type
993 return VectorIntrinsics.rebracket(
994 $masktype$.class, $type$.class, LENGTH,
995 species.elementType(), this,
996 (m, t) -> m.reshape(species)
997 );
998 }
999
1000 // Unary operations
1001
1002 //Mask<E, S> not();
1003
1004 // Binary operations
1005
1006 @Override
1007 @ForceInline
1008 public $masktype$ and(Mask<$Boxtype$,Shapes.$shape$> o) {
1009 Objects.requireNonNull(o);
1010 $masktype$ m = ($masktype$)o;
1011 return VectorIntrinsics.binaryOp(VECTOR_OP_AND, $masktype$.class, $bitstype$.class, LENGTH,
1012 this, m,
1013 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1014 }
1015
1072 public $Type$$bits$Species species() {
1073 return SPECIES;
1074 }
1075
1076 static final class $Type$$bits$Species extends $Type$Species<Shapes.$shape$> {
1077 static final int BIT_SIZE = Shapes.$Shape$.bitSize();
1078
1079 static final int LENGTH = BIT_SIZE / $Boxtype$.SIZE;
1080
1081 @Override
1082 public String toString() {
1083 StringBuilder sb = new StringBuilder("Shape[");
1084 sb.append(bitSize()).append(" bits, ");
1085 sb.append(length()).append(" ").append($type$.class.getSimpleName()).append("s x ");
1086 sb.append(elementSize()).append(" bits");
1087 sb.append("]");
1088 return sb.toString();
1089 }
1090
1091 @Override
1092 public int bitSize() {
1093 return BIT_SIZE;
1094 }
1095
1096 @Override
1097 public int length() {
1098 return LENGTH;
1099 }
1100
1101 @Override
1102 public Class<$Boxtype$> elementType() {
1103 return $Boxtype$.class;
1104 }
1105
1106 @Override
1107 public int elementSize() {
1108 return $Boxtype$.SIZE;
1109 }
1110
1111 @Override
1112 public Shapes.$shape$ shape() {
1113 return Shapes.$Shape$;
1114 }
1115
1116 @Override
1117 $vectortype$ op(FOp f) {
1118 $type$[] res = new $type$[length()];
1119 for (int i = 0; i < length(); i++) {
1120 res[i] = f.apply(i);
1121 }
1122 return new $vectortype$(res);
1123 }
1124
1125 @Override
1126 $vectortype$ op(Mask<$Boxtype$, Shapes.$shape$> o, FOp f) {
1127 $type$[] res = new $type$[length()];
1128 boolean[] mbits = (($masktype$)o).getBits();
1129 for (int i = 0; i < length(); i++) {
1130 if (mbits[i]) {
1131 res[i] = f.apply(i);
1206 public $masktype$ maskAllFalse() {
1207 return VectorIntrinsics.broadcastCoerced($masktype$.class, $bitstype$.class, LENGTH,
1208 0,
1209 (z -> $masktype$.FALSE_MASK));
1210 }
1211
1212 @Override
1213 @ForceInline
1214 public $vectortype$ fromArray($type$[] a, int ix) {
1215 Objects.requireNonNull(a);
1216 ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
1217 return ($vectortype$) VectorIntrinsics.load($vectortype$.class, $type$.class, LENGTH,
1218 a, ix,
1219 (arr, idx) -> super.fromArray(($type$[]) arr, idx));
1220 }
1221
1222 @Override
1223 @ForceInline
1224 public $vectortype$ fromArray($type$[] a, int ax, Mask<$Boxtype$, Shapes.$shape$> m) {
1225 return zero().blend(fromArray(a, ax), m); // TODO: use better default impl: op(m, i -> a[ax + i]);
1226 }
1227 }
1228 }
|
882 public $vectortype$ blend(Vector<$Boxtype$, Shapes.$shape$> o1, Mask<$Boxtype$, Shapes.$shape$> o2) {
883 Objects.requireNonNull(o1);
884 Objects.requireNonNull(o2);
885 $vectortype$ v = ($vectortype$)o1;
886 $masktype$ m = ($masktype$)o2;
887
888 return ($vectortype$) VectorIntrinsics.blend(
889 $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
890 this, v, m,
891 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
892 }
893
894 @Override
895 @ForceInline
896 @SuppressWarnings("unchecked")
897 public <F> Vector<F, Shapes.$shape$> rebracket(Species<F, Shapes.$shape$> species) {
898 Objects.requireNonNull(species);
899 // TODO: check proper element type
900 // TODO: update to pass the two species as an arguments and ideally
901 // push down intrinsic call into species implementation
902 return VectorIntrinsics.reinterpret(
903 $vectortype$.class, $type$.class, LENGTH,
904 species.elementType(), species.length(), this,
905 (v, t) -> species.reshape(v)
906 );
907 }
908
909 // Accessors
910
911 @Override
912 public $type$ get(int i) {
913 $type$[] vec = getElements();
914 return vec[i];
915 }
916
917 @Override
918 public $vectortype$ with(int i, $type$ e) {
919 $type$[] res = vec.clone();
920 res[i] = e;
921 return new $vectortype$(res);
922 }
923
924 // Mask
973 public $Type$$bits$Species species() {
974 return SPECIES;
975 }
976
977 @Override
978 public $vectortype$ toVector() {
979 $type$[] res = new $type$[species().length()];
980 boolean[] bits = getBits();
981 for (int i = 0; i < species().length(); i++) {
982 res[i] = ($type$) (bits[i] ? -1 : 0);
983 }
984 return new $vectortype$(res);
985 }
986
987 @Override
988 @ForceInline
989 @SuppressWarnings("unchecked")
990 public <Z> Mask<Z, Shapes.$shape$> rebracket(Species<Z, Shapes.$shape$> species) {
991 Objects.requireNonNull(species);
992 // TODO: check proper element type
993 return VectorIntrinsics.reinterpret(
994 $masktype$.class, $type$.class, LENGTH,
995 species.elementType(), species.length(), this,
996 (m, t) -> m.reshape(species)
997 );
998 }
999
1000 // Unary operations
1001
1002 //Mask<E, S> not();
1003
1004 // Binary operations
1005
1006 @Override
1007 @ForceInline
1008 public $masktype$ and(Mask<$Boxtype$,Shapes.$shape$> o) {
1009 Objects.requireNonNull(o);
1010 $masktype$ m = ($masktype$)o;
1011 return VectorIntrinsics.binaryOp(VECTOR_OP_AND, $masktype$.class, $bitstype$.class, LENGTH,
1012 this, m,
1013 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1014 }
1015
1072 public $Type$$bits$Species species() {
1073 return SPECIES;
1074 }
1075
1076 static final class $Type$$bits$Species extends $Type$Species<Shapes.$shape$> {
1077 static final int BIT_SIZE = Shapes.$Shape$.bitSize();
1078
1079 static final int LENGTH = BIT_SIZE / $Boxtype$.SIZE;
1080
1081 @Override
1082 public String toString() {
1083 StringBuilder sb = new StringBuilder("Shape[");
1084 sb.append(bitSize()).append(" bits, ");
1085 sb.append(length()).append(" ").append($type$.class.getSimpleName()).append("s x ");
1086 sb.append(elementSize()).append(" bits");
1087 sb.append("]");
1088 return sb.toString();
1089 }
1090
1091 @Override
1092 @ForceInline
1093 public int bitSize() {
1094 return BIT_SIZE;
1095 }
1096
1097 @Override
1098 @ForceInline
1099 public int length() {
1100 return LENGTH;
1101 }
1102
1103 @Override
1104 @ForceInline
1105 public Class<$Boxtype$> elementType() {
1106 return $Boxtype$.class;
1107 }
1108
1109 @Override
1110 @ForceInline
1111 public int elementSize() {
1112 return $Boxtype$.SIZE;
1113 }
1114
1115 @Override
1116 @ForceInline
1117 public Shapes.$shape$ shape() {
1118 return Shapes.$Shape$;
1119 }
1120
1121 @Override
1122 $vectortype$ op(FOp f) {
1123 $type$[] res = new $type$[length()];
1124 for (int i = 0; i < length(); i++) {
1125 res[i] = f.apply(i);
1126 }
1127 return new $vectortype$(res);
1128 }
1129
1130 @Override
1131 $vectortype$ op(Mask<$Boxtype$, Shapes.$shape$> o, FOp f) {
1132 $type$[] res = new $type$[length()];
1133 boolean[] mbits = (($masktype$)o).getBits();
1134 for (int i = 0; i < length(); i++) {
1135 if (mbits[i]) {
1136 res[i] = f.apply(i);
1211 public $masktype$ maskAllFalse() {
1212 return VectorIntrinsics.broadcastCoerced($masktype$.class, $bitstype$.class, LENGTH,
1213 0,
1214 (z -> $masktype$.FALSE_MASK));
1215 }
1216
1217 @Override
1218 @ForceInline
1219 public $vectortype$ fromArray($type$[] a, int ix) {
1220 Objects.requireNonNull(a);
1221 ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
1222 return ($vectortype$) VectorIntrinsics.load($vectortype$.class, $type$.class, LENGTH,
1223 a, ix,
1224 (arr, idx) -> super.fromArray(($type$[]) arr, idx));
1225 }
1226
1227 @Override
1228 @ForceInline
1229 public $vectortype$ fromArray($type$[] a, int ax, Mask<$Boxtype$, Shapes.$shape$> m) {
1230 return zero().blend(fromArray(a, ax), m); // TODO: use better default impl: op(m, i -> a[ax + i]);
1231 }
1232
1233 @Override
1234 @ForceInline
1235 @SuppressWarnings("unchecked")
1236 public <T extends Shape> $vectortype$ resize(Vector<$Boxtype$, T> o) {
1237 Objects.requireNonNull(o);
1238 if (o.bitSize() == 64) {
1239 $Type$64Vector so = ($Type$64Vector)o;
1240 return VectorIntrinsics.reinterpret(
1241 $Type$64Vector.class, $type$.class, so.length(),
1242 $Boxtype$.class, LENGTH, so,
1243 (v, t) -> ($vectortype$)reshape(v)
1244 );
1245 } else if (o.bitSize() == 128) {
1246 $Type$128Vector so = ($Type$128Vector)o;
1247 return VectorIntrinsics.reinterpret(
1248 $Type$128Vector.class, $type$.class, so.length(),
1249 $Boxtype$.class, LENGTH, so,
1250 (v, t) -> ($vectortype$)reshape(v)
1251 );
1252 } else if (o.bitSize() == 256) {
1253 $Type$256Vector so = ($Type$256Vector)o;
1254 return VectorIntrinsics.reinterpret(
1255 $Type$256Vector.class, $type$.class, so.length(),
1256 $Boxtype$.class, LENGTH, so,
1257 (v, t) -> ($vectortype$)reshape(v)
1258 );
1259 } else if (o.bitSize() == 512) {
1260 $Type$512Vector so = ($Type$512Vector)o;
1261 return VectorIntrinsics.reinterpret(
1262 $Type$512Vector.class, $type$.class, so.length(),
1263 $Boxtype$.class, LENGTH, so,
1264 (v, t) -> ($vectortype$)reshape(v)
1265 );
1266 } else {
1267 throw new InternalError("Unimplemented size");
1268 }
1269 }
1270 }
1271 }
|