162
163 return VectorIntrinsics.cast(
164 Float128Vector.class,
165 float.class, LENGTH,
166 s.boxType(),
167 s.elementType(), LENGTH,
168 this, s,
169 (species, vector) -> vector.castDefault(species)
170 );
171 }
172
173 @SuppressWarnings("unchecked")
174 @ForceInline
175 private <F> Vector<F> castDefault(VectorSpecies<F> s) {
176 int limit = s.length();
177
178 Class<?> stype = s.elementType();
179 if (stype == byte.class) {
180 byte[] a = new byte[limit];
181 for (int i = 0; i < limit; i++) {
182 a[i] = (byte) this.get(i);
183 }
184 return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
185 } else if (stype == short.class) {
186 short[] a = new short[limit];
187 for (int i = 0; i < limit; i++) {
188 a[i] = (short) this.get(i);
189 }
190 return (Vector) ShortVector.fromArray((VectorSpecies<Short>) s, a, 0);
191 } else if (stype == int.class) {
192 int[] a = new int[limit];
193 for (int i = 0; i < limit; i++) {
194 a[i] = (int) this.get(i);
195 }
196 return (Vector) IntVector.fromArray((VectorSpecies<Integer>) s, a, 0);
197 } else if (stype == long.class) {
198 long[] a = new long[limit];
199 for (int i = 0; i < limit; i++) {
200 a[i] = (long) this.get(i);
201 }
202 return (Vector) LongVector.fromArray((VectorSpecies<Long>) s, a, 0);
203 } else if (stype == float.class) {
204 float[] a = new float[limit];
205 for (int i = 0; i < limit; i++) {
206 a[i] = (float) this.get(i);
207 }
208 return (Vector) FloatVector.fromArray((VectorSpecies<Float>) s, a, 0);
209 } else if (stype == double.class) {
210 double[] a = new double[limit];
211 for (int i = 0; i < limit; i++) {
212 a[i] = (double) this.get(i);
213 }
214 return (Vector) DoubleVector.fromArray((VectorSpecies<Double>) s, a, 0);
215 } else {
216 throw new UnsupportedOperationException("Bad lane type for casting.");
217 }
218 }
219
220 @Override
221 @ForceInline
222 @SuppressWarnings("unchecked")
223 public <F> Vector<F> reinterpret(VectorSpecies<F> s) {
224 Objects.requireNonNull(s);
225
226 if(s.elementType().equals(float.class)) {
227 return (Vector<F>) reshape((VectorSpecies<Float>)s);
228 }
229 if(s.bitSize() == bitSize()) {
230 return reinterpretType(s);
231 }
232
1211 return new Float128Vector(res);
1212 }
1213
1214 @Override
1215 @ForceInline
1216 public Float128Vector rearrange(Vector<Float> v,
1217 VectorShuffle<Float> s, VectorMask<Float> m) {
1218 return this.rearrange(s).blend(v.rearrange(s), m);
1219 }
1220
1221 @Override
1222 @ForceInline
1223 public Float128Vector rearrange(VectorShuffle<Float> o1) {
1224 Objects.requireNonNull(o1);
1225 Float128Shuffle s = (Float128Shuffle)o1;
1226
1227 return VectorIntrinsics.rearrangeOp(
1228 Float128Vector.class, Float128Shuffle.class, float.class, LENGTH,
1229 this, s,
1230 (v1, s_) -> v1.uOp((i, a) -> {
1231 int ei = s_.getElement(i);
1232 return v1.get(ei);
1233 }));
1234 }
1235
1236 @Override
1237 @ForceInline
1238 public Float128Vector blend(Vector<Float> o1, VectorMask<Float> o2) {
1239 Objects.requireNonNull(o1);
1240 Objects.requireNonNull(o2);
1241 Float128Vector v = (Float128Vector)o1;
1242 Float128Mask m = (Float128Mask)o2;
1243
1244 return VectorIntrinsics.blend(
1245 Float128Vector.class, Float128Mask.class, float.class, LENGTH,
1246 this, v, m,
1247 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1248 }
1249
1250 // Accessors
1251
1252 @Override
1253 public float get(int i) {
1254 if (i < 0 || i >= LENGTH) {
1255 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1256 }
1257 int bits = (int) VectorIntrinsics.extract(
1258 Float128Vector.class, float.class, LENGTH,
1259 this, i,
1260 (vec, ix) -> {
1261 float[] vecarr = vec.getElements();
1262 return (long)Float.floatToIntBits(vecarr[ix]);
1263 });
1264 return Float.intBitsToFloat(bits);
1265 }
1266
1267 @Override
1268 public Float128Vector with(int i, float e) {
1269 if (i < 0 || i >= LENGTH) {
1270 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1271 }
1272 return VectorIntrinsics.insert(
1273 Float128Vector.class, float.class, LENGTH,
1435 super(reorder);
1436 }
1437
1438 public Float128Shuffle(int[] reorder, int i) {
1439 super(reorder, i);
1440 }
1441
1442 public Float128Shuffle(IntUnaryOperator f) {
1443 super(f);
1444 }
1445
1446 @Override
1447 public VectorSpecies<Float> species() {
1448 return SPECIES;
1449 }
1450
1451 @Override
1452 public FloatVector toVector() {
1453 float[] va = new float[SPECIES.length()];
1454 for (int i = 0; i < va.length; i++) {
1455 va[i] = (float) getElement(i);
1456 }
1457 return FloatVector.fromArray(SPECIES, va, 0);
1458 }
1459
1460 @Override
1461 @ForceInline
1462 @SuppressWarnings("unchecked")
1463 public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
1464 if (length() != species.length())
1465 throw new IllegalArgumentException("Shuffle length and species length differ");
1466 Class<?> stype = species.elementType();
1467 int [] shuffleArray = toArray();
1468 if (stype == byte.class) {
1469 return (VectorShuffle<F>) new Byte128Vector.Byte128Shuffle(shuffleArray);
1470 } else if (stype == short.class) {
1471 return (VectorShuffle<F>) new Short128Vector.Short128Shuffle(shuffleArray);
1472 } else if (stype == int.class) {
1473 return (VectorShuffle<F>) new Int128Vector.Int128Shuffle(shuffleArray);
1474 } else if (stype == long.class) {
1475 return (VectorShuffle<F>) new Long128Vector.Long128Shuffle(shuffleArray);
|
162
163 return VectorIntrinsics.cast(
164 Float128Vector.class,
165 float.class, LENGTH,
166 s.boxType(),
167 s.elementType(), LENGTH,
168 this, s,
169 (species, vector) -> vector.castDefault(species)
170 );
171 }
172
173 @SuppressWarnings("unchecked")
174 @ForceInline
175 private <F> Vector<F> castDefault(VectorSpecies<F> s) {
176 int limit = s.length();
177
178 Class<?> stype = s.elementType();
179 if (stype == byte.class) {
180 byte[] a = new byte[limit];
181 for (int i = 0; i < limit; i++) {
182 a[i] = (byte) this.lane(i);
183 }
184 return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
185 } else if (stype == short.class) {
186 short[] a = new short[limit];
187 for (int i = 0; i < limit; i++) {
188 a[i] = (short) this.lane(i);
189 }
190 return (Vector) ShortVector.fromArray((VectorSpecies<Short>) s, a, 0);
191 } else if (stype == int.class) {
192 int[] a = new int[limit];
193 for (int i = 0; i < limit; i++) {
194 a[i] = (int) this.lane(i);
195 }
196 return (Vector) IntVector.fromArray((VectorSpecies<Integer>) s, a, 0);
197 } else if (stype == long.class) {
198 long[] a = new long[limit];
199 for (int i = 0; i < limit; i++) {
200 a[i] = (long) this.lane(i);
201 }
202 return (Vector) LongVector.fromArray((VectorSpecies<Long>) s, a, 0);
203 } else if (stype == float.class) {
204 float[] a = new float[limit];
205 for (int i = 0; i < limit; i++) {
206 a[i] = (float) this.lane(i);
207 }
208 return (Vector) FloatVector.fromArray((VectorSpecies<Float>) s, a, 0);
209 } else if (stype == double.class) {
210 double[] a = new double[limit];
211 for (int i = 0; i < limit; i++) {
212 a[i] = (double) this.lane(i);
213 }
214 return (Vector) DoubleVector.fromArray((VectorSpecies<Double>) s, a, 0);
215 } else {
216 throw new UnsupportedOperationException("Bad lane type for casting.");
217 }
218 }
219
220 @Override
221 @ForceInline
222 @SuppressWarnings("unchecked")
223 public <F> Vector<F> reinterpret(VectorSpecies<F> s) {
224 Objects.requireNonNull(s);
225
226 if(s.elementType().equals(float.class)) {
227 return (Vector<F>) reshape((VectorSpecies<Float>)s);
228 }
229 if(s.bitSize() == bitSize()) {
230 return reinterpretType(s);
231 }
232
1211 return new Float128Vector(res);
1212 }
1213
1214 @Override
1215 @ForceInline
1216 public Float128Vector rearrange(Vector<Float> v,
1217 VectorShuffle<Float> s, VectorMask<Float> m) {
1218 return this.rearrange(s).blend(v.rearrange(s), m);
1219 }
1220
1221 @Override
1222 @ForceInline
1223 public Float128Vector rearrange(VectorShuffle<Float> o1) {
1224 Objects.requireNonNull(o1);
1225 Float128Shuffle s = (Float128Shuffle)o1;
1226
1227 return VectorIntrinsics.rearrangeOp(
1228 Float128Vector.class, Float128Shuffle.class, float.class, LENGTH,
1229 this, s,
1230 (v1, s_) -> v1.uOp((i, a) -> {
1231 int ei = s_.lane(i);
1232 return v1.lane(ei);
1233 }));
1234 }
1235
1236 @Override
1237 @ForceInline
1238 public Float128Vector blend(Vector<Float> o1, VectorMask<Float> o2) {
1239 Objects.requireNonNull(o1);
1240 Objects.requireNonNull(o2);
1241 Float128Vector v = (Float128Vector)o1;
1242 Float128Mask m = (Float128Mask)o2;
1243
1244 return VectorIntrinsics.blend(
1245 Float128Vector.class, Float128Mask.class, float.class, LENGTH,
1246 this, v, m,
1247 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.lane(i) ? b : a));
1248 }
1249
1250 // Accessors
1251
1252 @Override
1253 public float lane(int i) {
1254 if (i < 0 || i >= LENGTH) {
1255 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1256 }
1257 int bits = (int) VectorIntrinsics.extract(
1258 Float128Vector.class, float.class, LENGTH,
1259 this, i,
1260 (vec, ix) -> {
1261 float[] vecarr = vec.getElements();
1262 return (long)Float.floatToIntBits(vecarr[ix]);
1263 });
1264 return Float.intBitsToFloat(bits);
1265 }
1266
1267 @Override
1268 public Float128Vector with(int i, float e) {
1269 if (i < 0 || i >= LENGTH) {
1270 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1271 }
1272 return VectorIntrinsics.insert(
1273 Float128Vector.class, float.class, LENGTH,
1435 super(reorder);
1436 }
1437
1438 public Float128Shuffle(int[] reorder, int i) {
1439 super(reorder, i);
1440 }
1441
1442 public Float128Shuffle(IntUnaryOperator f) {
1443 super(f);
1444 }
1445
1446 @Override
1447 public VectorSpecies<Float> species() {
1448 return SPECIES;
1449 }
1450
1451 @Override
1452 public FloatVector toVector() {
1453 float[] va = new float[SPECIES.length()];
1454 for (int i = 0; i < va.length; i++) {
1455 va[i] = (float) lane(i);
1456 }
1457 return FloatVector.fromArray(SPECIES, va, 0);
1458 }
1459
1460 @Override
1461 @ForceInline
1462 @SuppressWarnings("unchecked")
1463 public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
1464 if (length() != species.length())
1465 throw new IllegalArgumentException("Shuffle length and species length differ");
1466 Class<?> stype = species.elementType();
1467 int [] shuffleArray = toArray();
1468 if (stype == byte.class) {
1469 return (VectorShuffle<F>) new Byte128Vector.Byte128Shuffle(shuffleArray);
1470 } else if (stype == short.class) {
1471 return (VectorShuffle<F>) new Short128Vector.Short128Shuffle(shuffleArray);
1472 } else if (stype == int.class) {
1473 return (VectorShuffle<F>) new Int128Vector.Int128Shuffle(shuffleArray);
1474 } else if (stype == long.class) {
1475 return (VectorShuffle<F>) new Long128Vector.Long128Shuffle(shuffleArray);
|