179 @ForceInline
180 public static FloatVector fromByteArray(FloatSpecies species, byte[] a, int ix, Mask<Float> m) {
181 return zero(species).blend(fromByteArray(species, a, ix), m);
182 }
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 i + 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 i the offset into the array
194 * @return the vector loaded from an array
195 * @throws IndexOutOfBoundsException if {@code i < 0}, or
196 * {@code i > a.length - this.length()}
197 */
198 @ForceInline
199 @SuppressWarnings("unchecked")
200 public static FloatVector fromArray(FloatSpecies species, float[] a, int i){
201 Objects.requireNonNull(a);
202 i = VectorIntrinsics.checkIndex(i, a.length, species.length());
203 return VectorIntrinsics.load((Class<FloatVector>) species.boxType(), float.class, species.length(),
204 a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_FLOAT_BASE_OFFSET,
205 a, i, 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 i + 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 i the offset into the array
222 * @param m the mask
223 * @return the vector loaded from an array
224 * @throws IndexOutOfBoundsException if {@code i < 0}, or
225 * for any vector lane index {@code N} where the mask at lane {@code N}
226 * is set {@code i > a.length - N}
227 */
228 @ForceInline
229 public static FloatVector fromArray(FloatSpecies species, float[] a, int i, Mask<Float> m) {
230 return zero(species).blend(fromArray(species, a, i), m);
231 }
232
233 /**
234 * Loads a vector from an array using indexes obtained from an index
235 * map.
236 * <p>
237 * For each vector lane, where {@code N} is the vector lane index, the
238 * array element at index {@code i + indexMap[j + N]} is placed into the
239 * resulting vector at lane index {@code N}.
240 *
241 * @param species species of desired vector
242 * @param a the array
243 * @param i the offset into the array, may be negative if relative
244 * indexes in the index map compensate to produce a value within the
245 * array bounds
246 * @param indexMap the index map
247 * @param j the offset into the index map
248 * @return the vector loaded from an array
249 * @throws IndexOutOfBoundsException if {@code j < 0}, or
250 * {@code j > indexMap.length - this.length()},
251 * or for any vector lane index {@code N} the result of
252 * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length}
253 */
254 @ForceInline
255 @SuppressWarnings("unchecked")
256 public static FloatVector fromArray(FloatSpecies species, float[] a, int i, int[] indexMap, int j) {
257 Objects.requireNonNull(a);
258 Objects.requireNonNull(indexMap);
259
260
261 // Index vector: vix[0:n] = k -> i + indexMap[j + i]
262 IntVector vix = IntVector.fromArray(species.indexSpecies(), indexMap, j).add(i);
263
264 vix = VectorIntrinsics.checkIndex(vix, a.length);
265
266 return VectorIntrinsics.loadWithMap((Class<FloatVector>) species.boxType(), float.class, species.length(),
267 species.indexSpecies().vectorType(), a, Unsafe.ARRAY_FLOAT_BASE_OFFSET, vix,
268 a, i, indexMap, j, species,
269 (c, idx, iMap, idy, s) -> ((FloatSpecies)s).op(n -> c[idx + iMap[idy+n]]));
270 }
271
272 /**
273 * Loads a vector from an array using indexes obtained from an index
274 * map and using a mask.
275 * <p>
276 * For each vector lane, where {@code N} is the vector lane index,
277 * if the mask lane at index {@code N} is set then the array element at
278 * index {@code i + indexMap[j + N]} is placed into the resulting vector
279 * at lane index {@code N}.
280 *
281 * @param species species of desired vector
282 * @param a the array
283 * @param i the offset into the array, may be negative if relative
284 * indexes in the index map compensate to produce a value within the
285 * array bounds
286 * @param m the mask
287 * @param indexMap the index map
288 * @param j the offset into the index map
289 * @return the vector loaded from an array
290 * @throws IndexOutOfBoundsException if {@code j < 0}, or
291 * {@code j > indexMap.length - this.length()},
292 * or for any vector lane index {@code N} where the mask at lane
293 * {@code N} is set the result of {@code i + indexMap[j + N]} is
294 * {@code < 0} or {@code >= a.length}
295 */
296 @ForceInline
297 @SuppressWarnings("unchecked")
298 public static FloatVector fromArray(FloatSpecies species, float[] a, int i, Mask<Float> m, int[] indexMap, int j) {
299 // @@@ This can result in out of bounds errors for unset mask lanes
300 return zero(species).blend(fromArray(species, a, i, indexMap, j), m);
301 }
302
303
304 /**
305 * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
306 * offset into the byte buffer.
307 * <p>
308 * Bytes are composed into primitive lane elements according to the
309 * native byte order of the underlying platform.
310 * <p>
311 * This method behaves as if it returns the result of calling the
312 * byte buffer, offset, and mask accepting
313 * {@link #fromByteBuffer(FloatSpecies, ByteBuffer, int, Mask)} method} as follows:
314 * <pre>{@code
315 * return this.fromByteBuffer(b, i, this.maskAllTrue())
316 * }</pre>
317 *
318 * @param species species of desired vector
319 * @param bb the byte buffer
320 * @param ix the offset into the byte buffer
|
179 @ForceInline
180 public static FloatVector fromByteArray(FloatSpecies species, byte[] a, int ix, Mask<Float> m) {
181 return zero(species).blend(fromByteArray(species, a, ix), m);
182 }
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 i + 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 i the offset into the array
194 * @return the vector loaded from an array
195 * @throws IndexOutOfBoundsException if {@code i < 0}, or
196 * {@code i > a.length - this.length()}
197 */
198 @ForceInline
199 public static FloatVector fromArray(FloatSpecies species, float[] a, int i) {
200 Objects.requireNonNull(a);
201 i = VectorIntrinsics.checkIndex(i, a.length, species.length());
202 return fromArrayWithoutCheck(species, a, i);
203 }
204
205 @ForceInline
206 @SuppressWarnings("unchecked")
207 static FloatVector fromArrayWithoutCheck(FloatSpecies species, float[] a, int i) {
208 return VectorIntrinsics.load((Class<FloatVector>) species.boxType(), float.class, species.length(),
209 a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_FLOAT_BASE_OFFSET,
210 a, i, species,
211 (c, idx, s) -> ((FloatSpecies)s).op(n -> c[idx + n]));
212 }
213
214 /**
215 * Loads a vector from an array starting at offset and using a mask.
216 * <p>
217 * For each vector lane, where {@code N} is the vector lane index,
218 * if the mask lane at index {@code N} is set then the array element at
219 * index {@code i + N} is placed into the resulting vector at lane index
220 * {@code N}, otherwise the default element value is placed into the
221 * resulting vector at lane index {@code N}.
222 *
223 * @param species species of desired vector
224 * @param a the array
225 * @param i the offset into the array
226 * @param m the mask
227 * @return the vector loaded from an array
228 * @throws IndexOutOfBoundsException if {@code i < 0}, or
229 * for any vector lane index {@code N} where the mask at lane {@code N}
230 * is set {@code i > a.length - N}
231 */
232 @ForceInline
233 public static FloatVector fromArray(FloatSpecies species, float[] a, int i, Mask<Float> m) {
234 Objects.requireNonNull(a);
235 if (i + species.length() <= a.length) {
236 return zero(species).blend(fromArrayWithoutCheck(species, a, i), m);
237 } else {
238 return species.op(m, n -> a[i + n]);
239 }
240 }
241
242 /**
243 * Loads a vector from an array using indexes obtained from an index
244 * map.
245 * <p>
246 * For each vector lane, where {@code N} is the vector lane index, the
247 * array element at index {@code i + indexMap[j + N]} is placed into the
248 * resulting vector at lane index {@code N}.
249 *
250 * @param species species of desired vector
251 * @param a the array
252 * @param i the offset into the array, may be negative if relative
253 * indexes in the index map compensate to produce a value within the
254 * array bounds
255 * @param indexMap the index map
256 * @param j the offset into the index map
257 * @return the vector loaded from an array
258 * @throws IndexOutOfBoundsException if {@code j < 0}, or
259 * {@code j > indexMap.length - this.length()},
260 * or for any vector lane index {@code N} the result of
261 * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length}
262 */
263 @ForceInline
264 public static FloatVector fromArray(FloatSpecies species, float[] a, int i, int[] indexMap, int j) {
265 Objects.requireNonNull(a);
266 Objects.requireNonNull(indexMap);
267
268 // Index vector: vix[0:n] = k -> i + indexMap[j + i]
269 IntVector vix = IntVector.fromArray(species.indexSpecies(), indexMap, j).add(i);
270
271 vix = VectorIntrinsics.checkIndex(vix, a.length);
272
273 return fromArrayWithoutCheck(species, a, i, indexMap, j, vix);
274 }
275
276 @ForceInline
277 @SuppressWarnings("unchecked")
278 static FloatVector fromArrayWithoutCheck(FloatSpecies species, float[] a, int i, int[] indexMap, int j, IntVector vix) {
279 return VectorIntrinsics.loadWithMap((Class<FloatVector>) species.boxType(), float.class, species.length(),
280 species.indexSpecies().vectorType(), a, Unsafe.ARRAY_FLOAT_BASE_OFFSET, vix,
281 a, i, indexMap, j, species,
282 (c, idx, iMap, idy, s) -> ((FloatSpecies)s).op(n -> c[idx + iMap[idy+n]]));
283 }
284
285 /**
286 * Loads a vector from an array using indexes obtained from an index
287 * map and using a mask.
288 * <p>
289 * For each vector lane, where {@code N} is the vector lane index,
290 * if the mask lane at index {@code N} is set then the array element at
291 * index {@code i + indexMap[j + N]} is placed into the resulting vector
292 * at lane index {@code N}.
293 *
294 * @param species species of desired vector
295 * @param a the array
296 * @param i the offset into the array, may be negative if relative
297 * indexes in the index map compensate to produce a value within the
298 * array bounds
299 * @param m the mask
300 * @param indexMap the index map
301 * @param j the offset into the index map
302 * @return the vector loaded from an array
303 * @throws IndexOutOfBoundsException if {@code j < 0}, or
304 * {@code j > indexMap.length - this.length()},
305 * or for any vector lane index {@code N} where the mask at lane
306 * {@code N} is set the result of {@code i + indexMap[j + N]} is
307 * {@code < 0} or {@code >= a.length}
308 */
309 @ForceInline
310 public static FloatVector fromArray(FloatSpecies species, float[] a, int i, Mask<Float> m, int[] indexMap, int j) {
311 Objects.requireNonNull(a);
312 Objects.requireNonNull(indexMap);
313
314 // Index vector: vix[0:n] = k -> i + indexMap[j + i]
315 IntVector vix = IntVector.fromArray(species.indexSpecies(), indexMap, j).add(i);
316
317 if (vix.lessThan(0).anyTrue() || vix.greaterThanEq(a.length).anyTrue()) {
318 return species.op(m, n -> a[i + indexMap[j+n]]);
319 } else {
320 return zero(species).blend(fromArrayWithoutCheck(species, a, i, indexMap, j, vix), m);
321 }
322 }
323
324
325 /**
326 * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
327 * offset into the byte buffer.
328 * <p>
329 * Bytes are composed into primitive lane elements according to the
330 * native byte order of the underlying platform.
331 * <p>
332 * This method behaves as if it returns the result of calling the
333 * byte buffer, offset, and mask accepting
334 * {@link #fromByteBuffer(FloatSpecies, ByteBuffer, int, Mask)} method} as follows:
335 * <pre>{@code
336 * return this.fromByteBuffer(b, i, this.maskAllTrue())
337 * }</pre>
338 *
339 * @param species species of desired vector
340 * @param bb the byte buffer
341 * @param ix the offset into the byte buffer
|