170
171 return VectorIntrinsics.cast(
172 $vectortype$.class,
173 $type$.class, LENGTH,
174 s.boxType(),
175 s.elementType(), LENGTH,
176 this, s,
177 (species, vector) -> vector.castDefault(species)
178 );
179 }
180
181 @SuppressWarnings("unchecked")
182 @ForceInline
183 private <F> Vector<F> castDefault(VectorSpecies<F> s) {
184 int limit = s.length();
185
186 Class<?> stype = s.elementType();
187 if (stype == byte.class) {
188 byte[] a = new byte[limit];
189 for (int i = 0; i < limit; i++) {
190 a[i] = (byte) this.get(i);
191 }
192 return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
193 } else if (stype == short.class) {
194 short[] a = new short[limit];
195 for (int i = 0; i < limit; i++) {
196 a[i] = (short) this.get(i);
197 }
198 return (Vector) ShortVector.fromArray((VectorSpecies<Short>) s, a, 0);
199 } else if (stype == int.class) {
200 int[] a = new int[limit];
201 for (int i = 0; i < limit; i++) {
202 a[i] = (int) this.get(i);
203 }
204 return (Vector) IntVector.fromArray((VectorSpecies<Integer>) s, a, 0);
205 } else if (stype == long.class) {
206 long[] a = new long[limit];
207 for (int i = 0; i < limit; i++) {
208 a[i] = (long) this.get(i);
209 }
210 return (Vector) LongVector.fromArray((VectorSpecies<Long>) s, a, 0);
211 } else if (stype == float.class) {
212 float[] a = new float[limit];
213 for (int i = 0; i < limit; i++) {
214 a[i] = (float) this.get(i);
215 }
216 return (Vector) FloatVector.fromArray((VectorSpecies<Float>) s, a, 0);
217 } else if (stype == double.class) {
218 double[] a = new double[limit];
219 for (int i = 0; i < limit; i++) {
220 a[i] = (double) this.get(i);
221 }
222 return (Vector) DoubleVector.fromArray((VectorSpecies<Double>) s, a, 0);
223 } else {
224 throw new UnsupportedOperationException("Bad lane type for casting.");
225 }
226 }
227
228 @Override
229 @ForceInline
230 @SuppressWarnings("unchecked")
231 public <F> Vector<F> reinterpret(VectorSpecies<F> s) {
232 Objects.requireNonNull(s);
233
234 if(s.elementType().equals($type$.class)) {
235 return (Vector<F>) reshape((VectorSpecies<$Boxtype$>)s);
236 }
237 if(s.bitSize() == bitSize()) {
238 return reinterpretType(s);
239 }
240
1613 return new $vectortype$(res);
1614 }
1615
1616 @Override
1617 @ForceInline
1618 public $vectortype$ rearrange(Vector<$Boxtype$> v,
1619 VectorShuffle<$Boxtype$> s, VectorMask<$Boxtype$> m) {
1620 return this.rearrange(s).blend(v.rearrange(s), m);
1621 }
1622
1623 @Override
1624 @ForceInline
1625 public $vectortype$ rearrange(VectorShuffle<$Boxtype$> o1) {
1626 Objects.requireNonNull(o1);
1627 $shuffletype$ s = ($shuffletype$)o1;
1628
1629 return VectorIntrinsics.rearrangeOp(
1630 $vectortype$.class, $shuffletype$.class, $type$.class, LENGTH,
1631 this, s,
1632 (v1, s_) -> v1.uOp((i, a) -> {
1633 int ei = s_.getElement(i);
1634 return v1.get(ei);
1635 }));
1636 }
1637
1638 @Override
1639 @ForceInline
1640 public $vectortype$ blend(Vector<$Boxtype$> o1, VectorMask<$Boxtype$> o2) {
1641 Objects.requireNonNull(o1);
1642 Objects.requireNonNull(o2);
1643 $vectortype$ v = ($vectortype$)o1;
1644 $masktype$ m = ($masktype$)o2;
1645
1646 return VectorIntrinsics.blend(
1647 $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
1648 this, v, m,
1649 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1650 }
1651
1652 // Accessors
1653
1654 #if[FP]
1655 @Override
1656 public $type$ get(int i) {
1657 if (i < 0 || i >= LENGTH) {
1658 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1659 }
1660 $bitstype$ bits = ($bitstype$) VectorIntrinsics.extract(
1661 $vectortype$.class, $type$.class, LENGTH,
1662 this, i,
1663 (vec, ix) -> {
1664 $type$[] vecarr = vec.getElements();
1665 return (long)$Type$.$type$To$Bitstype$Bits(vecarr[ix]);
1666 });
1667 return $Type$.$bitstype$BitsTo$Fptype$(bits);
1668 }
1669
1670 @Override
1671 public $vectortype$ with(int i, $type$ e) {
1672 if (i < 0 || i >= LENGTH) {
1673 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1674 }
1675 return VectorIntrinsics.insert(
1676 $vectortype$.class, $type$.class, LENGTH,
1677 this, i, (long)$Type$.$type$To$Bitstype$Bits(e),
1678 (v, ix, bits) -> {
1679 $type$[] res = v.getElements().clone();
1680 res[ix] = $Type$.$bitstype$BitsTo$Type$(($bitstype$)bits);
1681 return new $vectortype$(res);
1682 });
1683 }
1684 #else[FP]
1685 @Override
1686 public $type$ get(int i) {
1687 if (i < 0 || i >= LENGTH) {
1688 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1689 }
1690 return ($type$) VectorIntrinsics.extract(
1691 $vectortype$.class, $type$.class, LENGTH,
1692 this, i,
1693 (vec, ix) -> {
1694 $type$[] vecarr = vec.getElements();
1695 return (long)vecarr[ix];
1696 });
1697 }
1698
1699 @Override
1700 public $vectortype$ with(int i, $type$ e) {
1701 if (i < 0 || i >= LENGTH) {
1702 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1703 }
1704 return VectorIntrinsics.insert(
1705 $vectortype$.class, $type$.class, LENGTH,
1706 this, i, (long)e,
1868 super(reorder);
1869 }
1870
1871 public $shuffletype$(int[] reorder, int i) {
1872 super(reorder, i);
1873 }
1874
1875 public $shuffletype$(IntUnaryOperator f) {
1876 super(f);
1877 }
1878
1879 @Override
1880 public VectorSpecies<$Boxtype$> species() {
1881 return SPECIES;
1882 }
1883
1884 @Override
1885 public $abstractvectortype$ toVector() {
1886 $type$[] va = new $type$[SPECIES.length()];
1887 for (int i = 0; i < va.length; i++) {
1888 va[i] = ($type$) getElement(i);
1889 }
1890 return $abstractvectortype$.fromArray(SPECIES, va, 0);
1891 }
1892
1893 @Override
1894 @ForceInline
1895 @SuppressWarnings("unchecked")
1896 public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
1897 if (length() != species.length())
1898 throw new IllegalArgumentException("Shuffle length and species length differ");
1899 Class<?> stype = species.elementType();
1900 int [] shuffleArray = toArray();
1901 if (stype == byte.class) {
1902 return (VectorShuffle<F>) new Byte$bits$Vector.Byte$bits$Shuffle(shuffleArray);
1903 } else if (stype == short.class) {
1904 return (VectorShuffle<F>) new Short$bits$Vector.Short$bits$Shuffle(shuffleArray);
1905 } else if (stype == int.class) {
1906 return (VectorShuffle<F>) new Int$bits$Vector.Int$bits$Shuffle(shuffleArray);
1907 } else if (stype == long.class) {
1908 return (VectorShuffle<F>) new Long$bits$Vector.Long$bits$Shuffle(shuffleArray);
|
170
171 return VectorIntrinsics.cast(
172 $vectortype$.class,
173 $type$.class, LENGTH,
174 s.boxType(),
175 s.elementType(), LENGTH,
176 this, s,
177 (species, vector) -> vector.castDefault(species)
178 );
179 }
180
181 @SuppressWarnings("unchecked")
182 @ForceInline
183 private <F> Vector<F> castDefault(VectorSpecies<F> s) {
184 int limit = s.length();
185
186 Class<?> stype = s.elementType();
187 if (stype == byte.class) {
188 byte[] a = new byte[limit];
189 for (int i = 0; i < limit; i++) {
190 a[i] = (byte) this.lane(i);
191 }
192 return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
193 } else if (stype == short.class) {
194 short[] a = new short[limit];
195 for (int i = 0; i < limit; i++) {
196 a[i] = (short) this.lane(i);
197 }
198 return (Vector) ShortVector.fromArray((VectorSpecies<Short>) s, a, 0);
199 } else if (stype == int.class) {
200 int[] a = new int[limit];
201 for (int i = 0; i < limit; i++) {
202 a[i] = (int) this.lane(i);
203 }
204 return (Vector) IntVector.fromArray((VectorSpecies<Integer>) s, a, 0);
205 } else if (stype == long.class) {
206 long[] a = new long[limit];
207 for (int i = 0; i < limit; i++) {
208 a[i] = (long) this.lane(i);
209 }
210 return (Vector) LongVector.fromArray((VectorSpecies<Long>) s, a, 0);
211 } else if (stype == float.class) {
212 float[] a = new float[limit];
213 for (int i = 0; i < limit; i++) {
214 a[i] = (float) this.lane(i);
215 }
216 return (Vector) FloatVector.fromArray((VectorSpecies<Float>) s, a, 0);
217 } else if (stype == double.class) {
218 double[] a = new double[limit];
219 for (int i = 0; i < limit; i++) {
220 a[i] = (double) this.lane(i);
221 }
222 return (Vector) DoubleVector.fromArray((VectorSpecies<Double>) s, a, 0);
223 } else {
224 throw new UnsupportedOperationException("Bad lane type for casting.");
225 }
226 }
227
228 @Override
229 @ForceInline
230 @SuppressWarnings("unchecked")
231 public <F> Vector<F> reinterpret(VectorSpecies<F> s) {
232 Objects.requireNonNull(s);
233
234 if(s.elementType().equals($type$.class)) {
235 return (Vector<F>) reshape((VectorSpecies<$Boxtype$>)s);
236 }
237 if(s.bitSize() == bitSize()) {
238 return reinterpretType(s);
239 }
240
1613 return new $vectortype$(res);
1614 }
1615
1616 @Override
1617 @ForceInline
1618 public $vectortype$ rearrange(Vector<$Boxtype$> v,
1619 VectorShuffle<$Boxtype$> s, VectorMask<$Boxtype$> m) {
1620 return this.rearrange(s).blend(v.rearrange(s), m);
1621 }
1622
1623 @Override
1624 @ForceInline
1625 public $vectortype$ rearrange(VectorShuffle<$Boxtype$> o1) {
1626 Objects.requireNonNull(o1);
1627 $shuffletype$ s = ($shuffletype$)o1;
1628
1629 return VectorIntrinsics.rearrangeOp(
1630 $vectortype$.class, $shuffletype$.class, $type$.class, LENGTH,
1631 this, s,
1632 (v1, s_) -> v1.uOp((i, a) -> {
1633 int ei = s_.lane(i);
1634 return v1.lane(ei);
1635 }));
1636 }
1637
1638 @Override
1639 @ForceInline
1640 public $vectortype$ blend(Vector<$Boxtype$> o1, VectorMask<$Boxtype$> o2) {
1641 Objects.requireNonNull(o1);
1642 Objects.requireNonNull(o2);
1643 $vectortype$ v = ($vectortype$)o1;
1644 $masktype$ m = ($masktype$)o2;
1645
1646 return VectorIntrinsics.blend(
1647 $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
1648 this, v, m,
1649 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.lane(i) ? b : a));
1650 }
1651
1652 // Accessors
1653
1654 #if[FP]
1655 @Override
1656 public $type$ lane(int i) {
1657 if (i < 0 || i >= LENGTH) {
1658 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1659 }
1660 $bitstype$ bits = ($bitstype$) VectorIntrinsics.extract(
1661 $vectortype$.class, $type$.class, LENGTH,
1662 this, i,
1663 (vec, ix) -> {
1664 $type$[] vecarr = vec.getElements();
1665 return (long)$Type$.$type$To$Bitstype$Bits(vecarr[ix]);
1666 });
1667 return $Type$.$bitstype$BitsTo$Fptype$(bits);
1668 }
1669
1670 @Override
1671 public $vectortype$ with(int i, $type$ e) {
1672 if (i < 0 || i >= LENGTH) {
1673 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1674 }
1675 return VectorIntrinsics.insert(
1676 $vectortype$.class, $type$.class, LENGTH,
1677 this, i, (long)$Type$.$type$To$Bitstype$Bits(e),
1678 (v, ix, bits) -> {
1679 $type$[] res = v.getElements().clone();
1680 res[ix] = $Type$.$bitstype$BitsTo$Type$(($bitstype$)bits);
1681 return new $vectortype$(res);
1682 });
1683 }
1684 #else[FP]
1685 @Override
1686 public $type$ lane(int i) {
1687 if (i < 0 || i >= LENGTH) {
1688 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1689 }
1690 return ($type$) VectorIntrinsics.extract(
1691 $vectortype$.class, $type$.class, LENGTH,
1692 this, i,
1693 (vec, ix) -> {
1694 $type$[] vecarr = vec.getElements();
1695 return (long)vecarr[ix];
1696 });
1697 }
1698
1699 @Override
1700 public $vectortype$ with(int i, $type$ e) {
1701 if (i < 0 || i >= LENGTH) {
1702 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1703 }
1704 return VectorIntrinsics.insert(
1705 $vectortype$.class, $type$.class, LENGTH,
1706 this, i, (long)e,
1868 super(reorder);
1869 }
1870
1871 public $shuffletype$(int[] reorder, int i) {
1872 super(reorder, i);
1873 }
1874
1875 public $shuffletype$(IntUnaryOperator f) {
1876 super(f);
1877 }
1878
1879 @Override
1880 public VectorSpecies<$Boxtype$> species() {
1881 return SPECIES;
1882 }
1883
1884 @Override
1885 public $abstractvectortype$ toVector() {
1886 $type$[] va = new $type$[SPECIES.length()];
1887 for (int i = 0; i < va.length; i++) {
1888 va[i] = ($type$) lane(i);
1889 }
1890 return $abstractvectortype$.fromArray(SPECIES, va, 0);
1891 }
1892
1893 @Override
1894 @ForceInline
1895 @SuppressWarnings("unchecked")
1896 public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
1897 if (length() != species.length())
1898 throw new IllegalArgumentException("Shuffle length and species length differ");
1899 Class<?> stype = species.elementType();
1900 int [] shuffleArray = toArray();
1901 if (stype == byte.class) {
1902 return (VectorShuffle<F>) new Byte$bits$Vector.Byte$bits$Shuffle(shuffleArray);
1903 } else if (stype == short.class) {
1904 return (VectorShuffle<F>) new Short$bits$Vector.Short$bits$Shuffle(shuffleArray);
1905 } else if (stype == int.class) {
1906 return (VectorShuffle<F>) new Int$bits$Vector.Int$bits$Shuffle(shuffleArray);
1907 } else if (stype == long.class) {
1908 return (VectorShuffle<F>) new Long$bits$Vector.Long$bits$Shuffle(shuffleArray);
|