95 interface FUnCon {
96 void apply(int i, float a);
97 }
98
99 abstract void forEach(FUnCon f);
100
101 abstract void forEach(VectorMask<Float> m, FUnCon f);
102
103 // Static factories
104
105 /**
106 * Returns a vector where all lane elements are set to the default
107 * primitive value.
108 *
109 * @param species species of desired vector
110 * @return a zero vector of given species
111 */
112 @ForceInline
113 @SuppressWarnings("unchecked")
114 public static FloatVector zero(VectorSpecies<Float> species) {
115 return VectorIntrinsics.broadcastCoerced((Class<FloatVector>) species.boxType(), float.class, species.length(),
116 Float.floatToIntBits(0.0f), species,
117 ((bits, s) -> ((FloatSpecies)s).op(i -> Float.intBitsToFloat((int)bits))));
118 }
119
120 /**
121 * Loads a vector from a byte array starting at an offset.
122 * <p>
123 * Bytes are composed into primitive lane elements according to the
124 * native byte order of the underlying platform
125 * <p>
126 * This method behaves as if it returns the result of calling the
127 * byte buffer, offset, and mask accepting
128 * {@link #fromByteBuffer(VectorSpecies, ByteBuffer, int, VectorMask) method} as follows:
129 * <pre>{@code
130 * return fromByteBuffer(species, ByteBuffer.wrap(a), offset, VectorMask.allTrue());
131 * }</pre>
132 *
133 * @param species species of desired vector
134 * @param a the byte array
135 * @param offset the offset into the array
136 * @return a vector loaded from a byte array
137 * @throws IndexOutOfBoundsException if {@code i < 0} or
138 * {@code offset > a.length - (species.length() * species.elementSize() / Byte.SIZE)}
139 */
140 @ForceInline
141 @SuppressWarnings("unchecked")
142 public static FloatVector fromByteArray(VectorSpecies<Float> species, byte[] a, int offset) {
143 Objects.requireNonNull(a);
144 offset = VectorIntrinsics.checkIndex(offset, a.length, species.bitSize() / Byte.SIZE);
145 return VectorIntrinsics.load((Class<FloatVector>) species.boxType(), float.class, species.length(),
146 a, ((long) offset) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
147 a, offset, species,
148 (c, idx, s) -> {
149 ByteBuffer bbc = ByteBuffer.wrap(c, idx, a.length - idx).order(ByteOrder.nativeOrder());
150 FloatBuffer tb = bbc.asFloatBuffer();
151 return ((FloatSpecies)s).op(i -> tb.get());
152 });
153 }
154
155 /**
156 * Loads a vector from a byte array starting at an offset and using a
157 * mask.
158 * <p>
159 * Bytes are composed into primitive lane elements according to the
160 * native byte order of the underlying platform.
161 * <p>
162 * This method behaves as if it returns the result of calling the
163 * byte buffer, offset, and mask accepting
164 * {@link #fromByteBuffer(VectorSpecies, ByteBuffer, int, VectorMask) method} as follows:
165 * <pre>{@code
183
184 /**
185 * Loads a vector from an array starting at offset.
186 * <p>
187 * For each vector lane, where {@code N} is the vector lane index, the
188 * array element at index {@code offset + N} is placed into the
189 * resulting vector at lane index {@code N}.
190 *
191 * @param species species of desired vector
192 * @param a the array
193 * @param offset the offset into the array
194 * @return the vector loaded from an array
195 * @throws IndexOutOfBoundsException if {@code offset < 0}, or
196 * {@code offset > a.length - species.length()}
197 */
198 @ForceInline
199 @SuppressWarnings("unchecked")
200 public static FloatVector fromArray(VectorSpecies<Float> species, float[] a, int offset){
201 Objects.requireNonNull(a);
202 offset = VectorIntrinsics.checkIndex(offset, a.length, species.length());
203 return VectorIntrinsics.load((Class<FloatVector>) species.boxType(), float.class, species.length(),
204 a, (((long) offset) << ARRAY_SHIFT) + Unsafe.ARRAY_FLOAT_BASE_OFFSET,
205 a, offset, species,
206 (c, idx, s) -> ((FloatSpecies)s).op(n -> c[idx + n]));
207 }
208
209
210 /**
211 * Loads a vector from an array starting at offset and using a mask.
212 * <p>
213 * For each vector lane, where {@code N} is the vector lane index,
214 * if the mask lane at index {@code N} is set then the array element at
215 * index {@code offset + N} is placed into the resulting vector at lane index
216 * {@code N}, otherwise the default element value is placed into the
217 * resulting vector at lane index {@code N}.
218 *
219 * @param species species of desired vector
220 * @param a the array
221 * @param offset the offset into the array
222 * @param m the mask
223 * @return the vector loaded from an array
246 * @param indexMap the index map
247 * @param i_offset the offset into the index map
248 * @return the vector loaded from an array
249 * @throws IndexOutOfBoundsException if {@code i_offset < 0}, or
250 * {@code i_offset > indexMap.length - species.length()},
251 * or for any vector lane index {@code N} the result of
252 * {@code a_offset + indexMap[i_offset + N]} is {@code < 0} or {@code >= a.length}
253 */
254 @ForceInline
255 @SuppressWarnings("unchecked")
256 public static FloatVector fromArray(VectorSpecies<Float> species, float[] a, int a_offset, int[] indexMap, int i_offset) {
257 Objects.requireNonNull(a);
258 Objects.requireNonNull(indexMap);
259
260
261 // Index vector: vix[0:n] = k -> a_offset + indexMap[i_offset + k]
262 IntVector vix = IntVector.fromArray(IntVector.species(species.indexShape()), indexMap, i_offset).add(a_offset);
263
264 vix = VectorIntrinsics.checkIndex(vix, a.length);
265
266 return VectorIntrinsics.loadWithMap((Class<FloatVector>) species.boxType(), float.class, species.length(),
267 IntVector.species(species.indexShape()).boxType(), a, Unsafe.ARRAY_FLOAT_BASE_OFFSET, vix,
268 a, a_offset, indexMap, i_offset, species,
269 (float[] c, int idx, int[] iMap, int idy, VectorSpecies<Float> s) ->
270 ((FloatSpecies)s).op(n -> c[idx + iMap[idy+n]]));
271 }
272
273 /**
274 * Loads a vector from an array using indexes obtained from an index
275 * map and using a mask.
276 * <p>
277 * For each vector lane, where {@code N} is the vector lane index,
278 * if the mask lane at index {@code N} is set then the array element at
279 * index {@code a_offset + indexMap[i_offset + N]} is placed into the resulting vector
280 * at lane index {@code N}.
281 *
282 * @param species species of desired vector
283 * @param a the array
284 * @param a_offset the offset into the array, may be negative if relative
285 * indexes in the index map compensate to produce a value within the
286 * array bounds
287 * @param m the mask
316 * return fromByteBuffer(b, offset, VectorMask.allTrue())
317 * }</pre>
318 *
319 * @param species species of desired vector
320 * @param bb the byte buffer
321 * @param offset the offset into the byte buffer
322 * @return a vector loaded from a byte buffer
323 * @throws IndexOutOfBoundsException if the offset is {@code < 0},
324 * or {@code > b.limit()},
325 * or if there are fewer than
326 * {@code species.length() * species.elementSize() / Byte.SIZE} bytes
327 * remaining in the byte buffer from the given offset
328 */
329 @ForceInline
330 @SuppressWarnings("unchecked")
331 public static FloatVector fromByteBuffer(VectorSpecies<Float> species, ByteBuffer bb, int offset) {
332 if (bb.order() != ByteOrder.nativeOrder()) {
333 throw new IllegalArgumentException();
334 }
335 offset = VectorIntrinsics.checkIndex(offset, bb.limit(), species.bitSize() / Byte.SIZE);
336 return VectorIntrinsics.load((Class<FloatVector>) species.boxType(), float.class, species.length(),
337 U.getReference(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + offset,
338 bb, offset, species,
339 (c, idx, s) -> {
340 ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
341 FloatBuffer tb = bbc.asFloatBuffer();
342 return ((FloatSpecies)s).op(i -> tb.get());
343 });
344 }
345
346 /**
347 * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
348 * offset into the byte buffer and using a mask.
349 * <p>
350 * This method behaves as if the byte buffer is viewed as a primitive
351 * {@link java.nio.Buffer buffer} for the primitive element type,
352 * according to the native byte order of the underlying platform, and
353 * the returned vector is loaded with a mask from a primitive array
354 * obtained from the primitive buffer.
355 * The following pseudocode expresses the behaviour, where
356 * {@code EBuffer} is the primitive buffer type, {@code e} is the
380 * {@code offset >= b.limit() - (N * species.elementSize() / Byte.SIZE)}
381 */
382 @ForceInline
383 public static FloatVector fromByteBuffer(VectorSpecies<Float> species, ByteBuffer bb, int offset, VectorMask<Float> m) {
384 return zero(species).blend(fromByteBuffer(species, bb, offset), m);
385 }
386
387 /**
388 * Returns a vector where all lane elements are set to the primitive
389 * value {@code e}.
390 *
391 * @param species species of the desired vector
392 * @param e the value
393 * @return a vector of vector where all lane elements are set to
394 * the primitive value {@code e}
395 */
396 @ForceInline
397 @SuppressWarnings("unchecked")
398 public static FloatVector broadcast(VectorSpecies<Float> species, float e) {
399 return VectorIntrinsics.broadcastCoerced(
400 (Class<FloatVector>) species.boxType(), float.class, species.length(),
401 Float.floatToIntBits(e), species,
402 ((bits, sp) -> ((FloatSpecies)sp).op(i -> Float.intBitsToFloat((int)bits))));
403 }
404
405 /**
406 * Returns a vector where each lane element is set to given
407 * primitive values.
408 * <p>
409 * For each vector lane, where {@code N} is the vector lane index, the
410 * the primitive value at index {@code N} is placed into the resulting
411 * vector at lane index {@code N}.
412 *
413 * @param species species of the desired vector
414 * @param es the given primitive values
415 * @return a vector where each lane element is set to given primitive
416 * values
417 * @throws IndexOutOfBoundsException if {@code es.length < species.length()}
418 */
419 @ForceInline
420 @SuppressWarnings("unchecked")
421 public static FloatVector scalars(VectorSpecies<Float> species, float... es) {
422 Objects.requireNonNull(es);
423 int ix = VectorIntrinsics.checkIndex(0, es.length, species.length());
424 return VectorIntrinsics.load((Class<FloatVector>) species.boxType(), float.class, species.length(),
425 es, Unsafe.ARRAY_FLOAT_BASE_OFFSET,
426 es, ix, species,
427 (c, idx, sp) -> ((FloatSpecies)sp).op(n -> c[idx + n]));
428 }
429
430 /**
431 * Returns a vector where the first lane element is set to the primtive
432 * value {@code e}, all other lane elements are set to the default
433 * value.
434 *
435 * @param species species of the desired vector
436 * @param e the value
437 * @return a vector where the first lane element is set to the primitive
438 * value {@code e}
439 */
440 @ForceInline
441 public static final FloatVector single(VectorSpecies<Float> species, float e) {
442 return zero(species).with(0, e);
443 }
444
782 @Override
783 public abstract FloatVector rearrange(Vector<Float> v,
784 VectorShuffle<Float> s, VectorMask<Float> m);
785
786 /**
787 * {@inheritDoc}
788 */
789 @Override
790 public abstract FloatVector rearrange(VectorShuffle<Float> m);
791
792 /**
793 * {@inheritDoc}
794 */
795 @Override
796 public abstract FloatVector reshape(VectorSpecies<Float> s);
797
798 /**
799 * {@inheritDoc}
800 */
801 @Override
802 public abstract FloatVector rotateEL(int i);
803
804 /**
805 * {@inheritDoc}
806 */
807 @Override
808 public abstract FloatVector rotateER(int i);
809
810 /**
811 * {@inheritDoc}
812 */
813 @Override
814 public abstract FloatVector shiftEL(int i);
815
816 /**
817 * {@inheritDoc}
818 */
819 @Override
820 public abstract FloatVector shiftER(int i);
821
822 /**
823 * Divides this vector by an input vector.
824 * <p>
825 * This is a lane-wise binary operation which applies the primitive division
826 * operation ({@code /}) to each lane.
827 *
828 * @param v the input vector
829 * @return the result of dividing this vector by the input vector
830 */
831 public abstract FloatVector div(Vector<Float> v);
832
833 /**
834 * Divides this vector by the broadcast of an input scalar.
835 * <p>
836 * This is a lane-wise binary operation which applies the primitive division
837 * operation ({@code /}) to each lane.
838 *
839 * @param s the input scalar
840 * @return the result of dividing this vector by the broadcast of an input
1960 * or for any vector lane index {@code N} where the mask at lane
1961 * {@code N} is set the result of {@code a_offset + indexMap[i_offset + N]} is
1962 * {@code < 0} or {@code >= a.length}
1963 */
1964 public abstract void intoArray(float[] a, int a_offset, VectorMask<Float> m, int[] indexMap, int i_offset);
1965 // Species
1966
1967 /**
1968 * {@inheritDoc}
1969 */
1970 @Override
1971 public abstract VectorSpecies<Float> species();
1972
1973 /**
1974 * Class representing {@link FloatVector}'s of the same {@link VectorShape VectorShape}.
1975 */
1976 static final class FloatSpecies extends AbstractSpecies<Float> {
1977 final Function<float[], FloatVector> vectorFactory;
1978
1979 private FloatSpecies(VectorShape shape,
1980 Class<?> boxType,
1981 Class<?> maskType,
1982 Function<float[], FloatVector> vectorFactory,
1983 Function<boolean[], VectorMask<Float>> maskFactory,
1984 Function<IntUnaryOperator, VectorShuffle<Float>> shuffleFromArrayFactory,
1985 fShuffleFromArray<Float> shuffleFromOpFactory) {
1986 super(shape, float.class, Float.SIZE, boxType, maskType, maskFactory,
1987 shuffleFromArrayFactory, shuffleFromOpFactory);
1988 this.vectorFactory = vectorFactory;
1989 }
1990
1991 interface FOp {
1992 float apply(int i);
1993 }
1994
1995 FloatVector op(FOp f) {
1996 float[] res = new float[length()];
1997 for (int i = 0; i < length(); i++) {
1998 res[i] = f.apply(i);
1999 }
2000 return vectorFactory.apply(res);
2001 }
2002
2003 FloatVector op(VectorMask<Float> o, FOp f) {
2004 float[] res = new float[length()];
2005 boolean[] mbits = ((AbstractMask<Float>)o).getBits();
2006 for (int i = 0; i < length(); i++) {
|
95 interface FUnCon {
96 void apply(int i, float a);
97 }
98
99 abstract void forEach(FUnCon f);
100
101 abstract void forEach(VectorMask<Float> m, FUnCon f);
102
103 // Static factories
104
105 /**
106 * Returns a vector where all lane elements are set to the default
107 * primitive value.
108 *
109 * @param species species of desired vector
110 * @return a zero vector of given species
111 */
112 @ForceInline
113 @SuppressWarnings("unchecked")
114 public static FloatVector zero(VectorSpecies<Float> species) {
115 return VectorIntrinsics.broadcastCoerced((Class<FloatVector>) species.vectorType(), float.class, species.length(),
116 Float.floatToIntBits(0.0f), species,
117 ((bits, s) -> ((FloatSpecies)s).op(i -> Float.intBitsToFloat((int)bits))));
118 }
119
120 /**
121 * Loads a vector from a byte array starting at an offset.
122 * <p>
123 * Bytes are composed into primitive lane elements according to the
124 * native byte order of the underlying platform
125 * <p>
126 * This method behaves as if it returns the result of calling the
127 * byte buffer, offset, and mask accepting
128 * {@link #fromByteBuffer(VectorSpecies, ByteBuffer, int, VectorMask) method} as follows:
129 * <pre>{@code
130 * return fromByteBuffer(species, ByteBuffer.wrap(a), offset, VectorMask.allTrue());
131 * }</pre>
132 *
133 * @param species species of desired vector
134 * @param a the byte array
135 * @param offset the offset into the array
136 * @return a vector loaded from a byte array
137 * @throws IndexOutOfBoundsException if {@code i < 0} or
138 * {@code offset > a.length - (species.length() * species.elementSize() / Byte.SIZE)}
139 */
140 @ForceInline
141 @SuppressWarnings("unchecked")
142 public static FloatVector fromByteArray(VectorSpecies<Float> species, byte[] a, int offset) {
143 Objects.requireNonNull(a);
144 offset = VectorIntrinsics.checkIndex(offset, a.length, species.bitSize() / Byte.SIZE);
145 return VectorIntrinsics.load((Class<FloatVector>) species.vectorType(), float.class, species.length(),
146 a, ((long) offset) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
147 a, offset, species,
148 (c, idx, s) -> {
149 ByteBuffer bbc = ByteBuffer.wrap(c, idx, a.length - idx).order(ByteOrder.nativeOrder());
150 FloatBuffer tb = bbc.asFloatBuffer();
151 return ((FloatSpecies)s).op(i -> tb.get());
152 });
153 }
154
155 /**
156 * Loads a vector from a byte array starting at an offset and using a
157 * mask.
158 * <p>
159 * Bytes are composed into primitive lane elements according to the
160 * native byte order of the underlying platform.
161 * <p>
162 * This method behaves as if it returns the result of calling the
163 * byte buffer, offset, and mask accepting
164 * {@link #fromByteBuffer(VectorSpecies, ByteBuffer, int, VectorMask) method} as follows:
165 * <pre>{@code
183
184 /**
185 * Loads a vector from an array starting at offset.
186 * <p>
187 * For each vector lane, where {@code N} is the vector lane index, the
188 * array element at index {@code offset + N} is placed into the
189 * resulting vector at lane index {@code N}.
190 *
191 * @param species species of desired vector
192 * @param a the array
193 * @param offset the offset into the array
194 * @return the vector loaded from an array
195 * @throws IndexOutOfBoundsException if {@code offset < 0}, or
196 * {@code offset > a.length - species.length()}
197 */
198 @ForceInline
199 @SuppressWarnings("unchecked")
200 public static FloatVector fromArray(VectorSpecies<Float> species, float[] a, int offset){
201 Objects.requireNonNull(a);
202 offset = VectorIntrinsics.checkIndex(offset, a.length, species.length());
203 return VectorIntrinsics.load((Class<FloatVector>) species.vectorType(), float.class, species.length(),
204 a, (((long) offset) << ARRAY_SHIFT) + Unsafe.ARRAY_FLOAT_BASE_OFFSET,
205 a, offset, species,
206 (c, idx, s) -> ((FloatSpecies)s).op(n -> c[idx + n]));
207 }
208
209
210 /**
211 * Loads a vector from an array starting at offset and using a mask.
212 * <p>
213 * For each vector lane, where {@code N} is the vector lane index,
214 * if the mask lane at index {@code N} is set then the array element at
215 * index {@code offset + N} is placed into the resulting vector at lane index
216 * {@code N}, otherwise the default element value is placed into the
217 * resulting vector at lane index {@code N}.
218 *
219 * @param species species of desired vector
220 * @param a the array
221 * @param offset the offset into the array
222 * @param m the mask
223 * @return the vector loaded from an array
246 * @param indexMap the index map
247 * @param i_offset the offset into the index map
248 * @return the vector loaded from an array
249 * @throws IndexOutOfBoundsException if {@code i_offset < 0}, or
250 * {@code i_offset > indexMap.length - species.length()},
251 * or for any vector lane index {@code N} the result of
252 * {@code a_offset + indexMap[i_offset + N]} is {@code < 0} or {@code >= a.length}
253 */
254 @ForceInline
255 @SuppressWarnings("unchecked")
256 public static FloatVector fromArray(VectorSpecies<Float> species, float[] a, int a_offset, int[] indexMap, int i_offset) {
257 Objects.requireNonNull(a);
258 Objects.requireNonNull(indexMap);
259
260
261 // Index vector: vix[0:n] = k -> a_offset + indexMap[i_offset + k]
262 IntVector vix = IntVector.fromArray(IntVector.species(species.indexShape()), indexMap, i_offset).add(a_offset);
263
264 vix = VectorIntrinsics.checkIndex(vix, a.length);
265
266 return VectorIntrinsics.loadWithMap((Class<FloatVector>) species.vectorType(), float.class, species.length(),
267 IntVector.species(species.indexShape()).vectorType(), a, Unsafe.ARRAY_FLOAT_BASE_OFFSET, vix,
268 a, a_offset, indexMap, i_offset, species,
269 (float[] c, int idx, int[] iMap, int idy, VectorSpecies<Float> s) ->
270 ((FloatSpecies)s).op(n -> c[idx + iMap[idy+n]]));
271 }
272
273 /**
274 * Loads a vector from an array using indexes obtained from an index
275 * map and using a mask.
276 * <p>
277 * For each vector lane, where {@code N} is the vector lane index,
278 * if the mask lane at index {@code N} is set then the array element at
279 * index {@code a_offset + indexMap[i_offset + N]} is placed into the resulting vector
280 * at lane index {@code N}.
281 *
282 * @param species species of desired vector
283 * @param a the array
284 * @param a_offset the offset into the array, may be negative if relative
285 * indexes in the index map compensate to produce a value within the
286 * array bounds
287 * @param m the mask
316 * return fromByteBuffer(b, offset, VectorMask.allTrue())
317 * }</pre>
318 *
319 * @param species species of desired vector
320 * @param bb the byte buffer
321 * @param offset the offset into the byte buffer
322 * @return a vector loaded from a byte buffer
323 * @throws IndexOutOfBoundsException if the offset is {@code < 0},
324 * or {@code > b.limit()},
325 * or if there are fewer than
326 * {@code species.length() * species.elementSize() / Byte.SIZE} bytes
327 * remaining in the byte buffer from the given offset
328 */
329 @ForceInline
330 @SuppressWarnings("unchecked")
331 public static FloatVector fromByteBuffer(VectorSpecies<Float> species, ByteBuffer bb, int offset) {
332 if (bb.order() != ByteOrder.nativeOrder()) {
333 throw new IllegalArgumentException();
334 }
335 offset = VectorIntrinsics.checkIndex(offset, bb.limit(), species.bitSize() / Byte.SIZE);
336 return VectorIntrinsics.load((Class<FloatVector>) species.vectorType(), float.class, species.length(),
337 U.getReference(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + offset,
338 bb, offset, species,
339 (c, idx, s) -> {
340 ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
341 FloatBuffer tb = bbc.asFloatBuffer();
342 return ((FloatSpecies)s).op(i -> tb.get());
343 });
344 }
345
346 /**
347 * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
348 * offset into the byte buffer and using a mask.
349 * <p>
350 * This method behaves as if the byte buffer is viewed as a primitive
351 * {@link java.nio.Buffer buffer} for the primitive element type,
352 * according to the native byte order of the underlying platform, and
353 * the returned vector is loaded with a mask from a primitive array
354 * obtained from the primitive buffer.
355 * The following pseudocode expresses the behaviour, where
356 * {@code EBuffer} is the primitive buffer type, {@code e} is the
380 * {@code offset >= b.limit() - (N * species.elementSize() / Byte.SIZE)}
381 */
382 @ForceInline
383 public static FloatVector fromByteBuffer(VectorSpecies<Float> species, ByteBuffer bb, int offset, VectorMask<Float> m) {
384 return zero(species).blend(fromByteBuffer(species, bb, offset), m);
385 }
386
387 /**
388 * Returns a vector where all lane elements are set to the primitive
389 * value {@code e}.
390 *
391 * @param species species of the desired vector
392 * @param e the value
393 * @return a vector of vector where all lane elements are set to
394 * the primitive value {@code e}
395 */
396 @ForceInline
397 @SuppressWarnings("unchecked")
398 public static FloatVector broadcast(VectorSpecies<Float> species, float e) {
399 return VectorIntrinsics.broadcastCoerced(
400 (Class<FloatVector>) species.vectorType(), float.class, species.length(),
401 Float.floatToIntBits(e), species,
402 ((bits, sp) -> ((FloatSpecies)sp).op(i -> Float.intBitsToFloat((int)bits))));
403 }
404
405 /**
406 * Returns a vector where each lane element is set to given
407 * primitive values.
408 * <p>
409 * For each vector lane, where {@code N} is the vector lane index, the
410 * the primitive value at index {@code N} is placed into the resulting
411 * vector at lane index {@code N}.
412 *
413 * @param species species of the desired vector
414 * @param es the given primitive values
415 * @return a vector where each lane element is set to given primitive
416 * values
417 * @throws IndexOutOfBoundsException if {@code es.length < species.length()}
418 */
419 @ForceInline
420 @SuppressWarnings("unchecked")
421 public static FloatVector scalars(VectorSpecies<Float> species, float... es) {
422 Objects.requireNonNull(es);
423 int ix = VectorIntrinsics.checkIndex(0, es.length, species.length());
424 return VectorIntrinsics.load((Class<FloatVector>) species.vectorType(), float.class, species.length(),
425 es, Unsafe.ARRAY_FLOAT_BASE_OFFSET,
426 es, ix, species,
427 (c, idx, sp) -> ((FloatSpecies)sp).op(n -> c[idx + n]));
428 }
429
430 /**
431 * Returns a vector where the first lane element is set to the primtive
432 * value {@code e}, all other lane elements are set to the default
433 * value.
434 *
435 * @param species species of the desired vector
436 * @param e the value
437 * @return a vector where the first lane element is set to the primitive
438 * value {@code e}
439 */
440 @ForceInline
441 public static final FloatVector single(VectorSpecies<Float> species, float e) {
442 return zero(species).with(0, e);
443 }
444
782 @Override
783 public abstract FloatVector rearrange(Vector<Float> v,
784 VectorShuffle<Float> s, VectorMask<Float> m);
785
786 /**
787 * {@inheritDoc}
788 */
789 @Override
790 public abstract FloatVector rearrange(VectorShuffle<Float> m);
791
792 /**
793 * {@inheritDoc}
794 */
795 @Override
796 public abstract FloatVector reshape(VectorSpecies<Float> s);
797
798 /**
799 * {@inheritDoc}
800 */
801 @Override
802 public abstract FloatVector rotateLanesLeft(int i);
803
804 /**
805 * {@inheritDoc}
806 */
807 @Override
808 public abstract FloatVector rotateLanesRight(int i);
809
810 /**
811 * {@inheritDoc}
812 */
813 @Override
814 public abstract FloatVector shiftLanesLeft(int i);
815
816 /**
817 * {@inheritDoc}
818 */
819 @Override
820 public abstract FloatVector shiftLanesRight(int i);
821
822 /**
823 * Divides this vector by an input vector.
824 * <p>
825 * This is a lane-wise binary operation which applies the primitive division
826 * operation ({@code /}) to each lane.
827 *
828 * @param v the input vector
829 * @return the result of dividing this vector by the input vector
830 */
831 public abstract FloatVector div(Vector<Float> v);
832
833 /**
834 * Divides this vector by the broadcast of an input scalar.
835 * <p>
836 * This is a lane-wise binary operation which applies the primitive division
837 * operation ({@code /}) to each lane.
838 *
839 * @param s the input scalar
840 * @return the result of dividing this vector by the broadcast of an input
1960 * or for any vector lane index {@code N} where the mask at lane
1961 * {@code N} is set the result of {@code a_offset + indexMap[i_offset + N]} is
1962 * {@code < 0} or {@code >= a.length}
1963 */
1964 public abstract void intoArray(float[] a, int a_offset, VectorMask<Float> m, int[] indexMap, int i_offset);
1965 // Species
1966
1967 /**
1968 * {@inheritDoc}
1969 */
1970 @Override
1971 public abstract VectorSpecies<Float> species();
1972
1973 /**
1974 * Class representing {@link FloatVector}'s of the same {@link VectorShape VectorShape}.
1975 */
1976 static final class FloatSpecies extends AbstractSpecies<Float> {
1977 final Function<float[], FloatVector> vectorFactory;
1978
1979 private FloatSpecies(VectorShape shape,
1980 Class<?> vectorType,
1981 Class<?> maskType,
1982 Function<float[], FloatVector> vectorFactory,
1983 Function<boolean[], VectorMask<Float>> maskFactory,
1984 Function<IntUnaryOperator, VectorShuffle<Float>> shuffleFromArrayFactory,
1985 fShuffleFromArray<Float> shuffleFromOpFactory) {
1986 super(shape, float.class, Float.SIZE, vectorType, maskType, maskFactory,
1987 shuffleFromArrayFactory, shuffleFromOpFactory);
1988 this.vectorFactory = vectorFactory;
1989 }
1990
1991 interface FOp {
1992 float apply(int i);
1993 }
1994
1995 FloatVector op(FOp f) {
1996 float[] res = new float[length()];
1997 for (int i = 0; i < length(); i++) {
1998 res[i] = f.apply(i);
1999 }
2000 return vectorFactory.apply(res);
2001 }
2002
2003 FloatVector op(VectorMask<Float> o, FOp f) {
2004 float[] res = new float[length()];
2005 boolean[] mbits = ((AbstractMask<Float>)o).getBits();
2006 for (int i = 0; i < length(); i++) {
|