153
154 return VectorIntrinsics.cast(
155 Byte256Vector.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.get(i);
174 }
175 return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
176 } else if (stype == short.class) {
177 short[] a = new short[limit];
178 for (int i = 0; i < limit; i++) {
179 a[i] = (short) this.get(i);
180 }
181 return (Vector) ShortVector.fromArray((VectorSpecies<Short>) s, a, 0);
182 } else if (stype == int.class) {
183 int[] a = new int[limit];
184 for (int i = 0; i < limit; i++) {
185 a[i] = (int) this.get(i);
186 }
187 return (Vector) IntVector.fromArray((VectorSpecies<Integer>) s, a, 0);
188 } else if (stype == long.class) {
189 long[] a = new long[limit];
190 for (int i = 0; i < limit; i++) {
191 a[i] = (long) this.get(i);
192 }
193 return (Vector) LongVector.fromArray((VectorSpecies<Long>) s, a, 0);
194 } else if (stype == float.class) {
195 float[] a = new float[limit];
196 for (int i = 0; i < limit; i++) {
197 a[i] = (float) this.get(i);
198 }
199 return (Vector) FloatVector.fromArray((VectorSpecies<Float>) s, a, 0);
200 } else if (stype == double.class) {
201 double[] a = new double[limit];
202 for (int i = 0; i < limit; i++) {
203 a[i] = (double) this.get(i);
204 }
205 return (Vector) DoubleVector.fromArray((VectorSpecies<Double>) s, a, 0);
206 } else {
207 throw new UnsupportedOperationException("Bad lane type for casting.");
208 }
209 }
210
211 @Override
212 @ForceInline
213 @SuppressWarnings("unchecked")
214 public <F> Vector<F> reinterpret(VectorSpecies<F> s) {
215 Objects.requireNonNull(s);
216
217 if(s.elementType().equals(byte.class)) {
218 return (Vector<F>) reshape((VectorSpecies<Byte>)s);
219 }
220 if(s.bitSize() == bitSize()) {
221 return reinterpretType(s);
222 }
223
1072 return new Byte256Vector(res);
1073 }
1074
1075 @Override
1076 @ForceInline
1077 public Byte256Vector 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 Byte256Vector rearrange(VectorShuffle<Byte> o1) {
1085 Objects.requireNonNull(o1);
1086 Byte256Shuffle s = (Byte256Shuffle)o1;
1087
1088 return VectorIntrinsics.rearrangeOp(
1089 Byte256Vector.class, Byte256Shuffle.class, byte.class, LENGTH,
1090 this, s,
1091 (v1, s_) -> v1.uOp((i, a) -> {
1092 int ei = s_.getElement(i);
1093 return v1.get(ei);
1094 }));
1095 }
1096
1097 @Override
1098 @ForceInline
1099 public Byte256Vector blend(Vector<Byte> o1, VectorMask<Byte> o2) {
1100 Objects.requireNonNull(o1);
1101 Objects.requireNonNull(o2);
1102 Byte256Vector v = (Byte256Vector)o1;
1103 Byte256Mask m = (Byte256Mask)o2;
1104
1105 return VectorIntrinsics.blend(
1106 Byte256Vector.class, Byte256Mask.class, byte.class, LENGTH,
1107 this, v, m,
1108 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1109 }
1110
1111 // Accessors
1112
1113 @Override
1114 public byte get(int i) {
1115 if (i < 0 || i >= LENGTH) {
1116 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1117 }
1118 return (byte) VectorIntrinsics.extract(
1119 Byte256Vector.class, byte.class, LENGTH,
1120 this, i,
1121 (vec, ix) -> {
1122 byte[] vecarr = vec.getElements();
1123 return (long)vecarr[ix];
1124 });
1125 }
1126
1127 @Override
1128 public Byte256Vector with(int i, byte e) {
1129 if (i < 0 || i >= LENGTH) {
1130 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1131 }
1132 return VectorIntrinsics.insert(
1133 Byte256Vector.class, byte.class, LENGTH,
1134 this, i, (long)e,
1295 super(reorder);
1296 }
1297
1298 public Byte256Shuffle(int[] reorder, int i) {
1299 super(reorder, i);
1300 }
1301
1302 public Byte256Shuffle(IntUnaryOperator f) {
1303 super(f);
1304 }
1305
1306 @Override
1307 public VectorSpecies<Byte> species() {
1308 return SPECIES;
1309 }
1310
1311 @Override
1312 public ByteVector toVector() {
1313 byte[] va = new byte[SPECIES.length()];
1314 for (int i = 0; i < va.length; i++) {
1315 va[i] = (byte) getElement(i);
1316 }
1317 return ByteVector.fromArray(SPECIES, va, 0);
1318 }
1319
1320 @Override
1321 @ForceInline
1322 @SuppressWarnings("unchecked")
1323 public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
1324 if (length() != species.length())
1325 throw new IllegalArgumentException("Shuffle length and species length differ");
1326 Class<?> stype = species.elementType();
1327 int [] shuffleArray = toArray();
1328 if (stype == byte.class) {
1329 return (VectorShuffle<F>) new Byte256Vector.Byte256Shuffle(shuffleArray);
1330 } else if (stype == short.class) {
1331 return (VectorShuffle<F>) new Short256Vector.Short256Shuffle(shuffleArray);
1332 } else if (stype == int.class) {
1333 return (VectorShuffle<F>) new Int256Vector.Int256Shuffle(shuffleArray);
1334 } else if (stype == long.class) {
1335 return (VectorShuffle<F>) new Long256Vector.Long256Shuffle(shuffleArray);
|
153
154 return VectorIntrinsics.cast(
155 Byte256Vector.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];
178 for (int i = 0; i < limit; i++) {
179 a[i] = (short) this.lane(i);
180 }
181 return (Vector) ShortVector.fromArray((VectorSpecies<Short>) s, a, 0);
182 } else if (stype == int.class) {
183 int[] a = new int[limit];
184 for (int i = 0; i < limit; i++) {
185 a[i] = (int) this.lane(i);
186 }
187 return (Vector) IntVector.fromArray((VectorSpecies<Integer>) s, a, 0);
188 } else if (stype == long.class) {
189 long[] a = new long[limit];
190 for (int i = 0; i < limit; i++) {
191 a[i] = (long) this.lane(i);
192 }
193 return (Vector) LongVector.fromArray((VectorSpecies<Long>) s, a, 0);
194 } else if (stype == float.class) {
195 float[] a = new float[limit];
196 for (int i = 0; i < limit; i++) {
197 a[i] = (float) this.lane(i);
198 }
199 return (Vector) FloatVector.fromArray((VectorSpecies<Float>) s, a, 0);
200 } else if (stype == double.class) {
201 double[] a = new double[limit];
202 for (int i = 0; i < limit; i++) {
203 a[i] = (double) this.lane(i);
204 }
205 return (Vector) DoubleVector.fromArray((VectorSpecies<Double>) s, a, 0);
206 } else {
207 throw new UnsupportedOperationException("Bad lane type for casting.");
208 }
209 }
210
211 @Override
212 @ForceInline
213 @SuppressWarnings("unchecked")
214 public <F> Vector<F> reinterpret(VectorSpecies<F> s) {
215 Objects.requireNonNull(s);
216
217 if(s.elementType().equals(byte.class)) {
218 return (Vector<F>) reshape((VectorSpecies<Byte>)s);
219 }
220 if(s.bitSize() == bitSize()) {
221 return reinterpretType(s);
222 }
223
1072 return new Byte256Vector(res);
1073 }
1074
1075 @Override
1076 @ForceInline
1077 public Byte256Vector 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 Byte256Vector rearrange(VectorShuffle<Byte> o1) {
1085 Objects.requireNonNull(o1);
1086 Byte256Shuffle s = (Byte256Shuffle)o1;
1087
1088 return VectorIntrinsics.rearrangeOp(
1089 Byte256Vector.class, Byte256Shuffle.class, byte.class, LENGTH,
1090 this, s,
1091 (v1, s_) -> v1.uOp((i, a) -> {
1092 int ei = s_.lane(i);
1093 return v1.lane(ei);
1094 }));
1095 }
1096
1097 @Override
1098 @ForceInline
1099 public Byte256Vector blend(Vector<Byte> o1, VectorMask<Byte> o2) {
1100 Objects.requireNonNull(o1);
1101 Objects.requireNonNull(o2);
1102 Byte256Vector v = (Byte256Vector)o1;
1103 Byte256Mask m = (Byte256Mask)o2;
1104
1105 return VectorIntrinsics.blend(
1106 Byte256Vector.class, Byte256Mask.class, byte.class, LENGTH,
1107 this, v, m,
1108 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.lane(i) ? b : a));
1109 }
1110
1111 // Accessors
1112
1113 @Override
1114 public byte lane(int i) {
1115 if (i < 0 || i >= LENGTH) {
1116 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1117 }
1118 return (byte) VectorIntrinsics.extract(
1119 Byte256Vector.class, byte.class, LENGTH,
1120 this, i,
1121 (vec, ix) -> {
1122 byte[] vecarr = vec.getElements();
1123 return (long)vecarr[ix];
1124 });
1125 }
1126
1127 @Override
1128 public Byte256Vector with(int i, byte e) {
1129 if (i < 0 || i >= LENGTH) {
1130 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1131 }
1132 return VectorIntrinsics.insert(
1133 Byte256Vector.class, byte.class, LENGTH,
1134 this, i, (long)e,
1295 super(reorder);
1296 }
1297
1298 public Byte256Shuffle(int[] reorder, int i) {
1299 super(reorder, i);
1300 }
1301
1302 public Byte256Shuffle(IntUnaryOperator f) {
1303 super(f);
1304 }
1305
1306 @Override
1307 public VectorSpecies<Byte> species() {
1308 return SPECIES;
1309 }
1310
1311 @Override
1312 public ByteVector toVector() {
1313 byte[] va = new byte[SPECIES.length()];
1314 for (int i = 0; i < va.length; i++) {
1315 va[i] = (byte) lane(i);
1316 }
1317 return ByteVector.fromArray(SPECIES, va, 0);
1318 }
1319
1320 @Override
1321 @ForceInline
1322 @SuppressWarnings("unchecked")
1323 public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
1324 if (length() != species.length())
1325 throw new IllegalArgumentException("Shuffle length and species length differ");
1326 Class<?> stype = species.elementType();
1327 int [] shuffleArray = toArray();
1328 if (stype == byte.class) {
1329 return (VectorShuffle<F>) new Byte256Vector.Byte256Shuffle(shuffleArray);
1330 } else if (stype == short.class) {
1331 return (VectorShuffle<F>) new Short256Vector.Short256Shuffle(shuffleArray);
1332 } else if (stype == int.class) {
1333 return (VectorShuffle<F>) new Int256Vector.Int256Shuffle(shuffleArray);
1334 } else if (stype == long.class) {
1335 return (VectorShuffle<F>) new Long256Vector.Long256Shuffle(shuffleArray);
|