41
42 /**
43 * A specialized {@link Vector} representing an ordered immutable sequence of
44 * {@code $type$} values.
45 */
46 @SuppressWarnings("cast")
47 public abstract class $abstractvectortype$ extends Vector<$Boxtype$> {
48
49 $abstractvectortype$() {}
50
51 private static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_$TYPE$_INDEX_SCALE);
52
53 // Unary operator
54
55 interface FUnOp {
56 $type$ apply(int i, $type$ a);
57 }
58
59 abstract $abstractvectortype$ uOp(FUnOp f);
60
61 abstract $abstractvectortype$ uOp(Mask<$Boxtype$> m, FUnOp f);
62
63 // Binary operator
64
65 interface FBinOp {
66 $type$ apply(int i, $type$ a, $type$ b);
67 }
68
69 abstract $abstractvectortype$ bOp(Vector<$Boxtype$> v, FBinOp f);
70
71 abstract $abstractvectortype$ bOp(Vector<$Boxtype$> v, Mask<$Boxtype$> m, FBinOp f);
72
73 // Trinary operator
74
75 interface FTriOp {
76 $type$ apply(int i, $type$ a, $type$ b, $type$ c);
77 }
78
79 abstract $abstractvectortype$ tOp(Vector<$Boxtype$> v1, Vector<$Boxtype$> v2, FTriOp f);
80
81 abstract $abstractvectortype$ tOp(Vector<$Boxtype$> v1, Vector<$Boxtype$> v2, Mask<$Boxtype$> m, FTriOp f);
82
83 // Reduction operator
84
85 abstract $type$ rOp($type$ v, FBinOp f);
86
87 // Binary test
88
89 interface FBinTest {
90 boolean apply(int i, $type$ a, $type$ b);
91 }
92
93 abstract Mask<$Boxtype$> bTest(Vector<$Boxtype$> v, FBinTest f);
94
95 // Foreach
96
97 interface FUnCon {
98 void apply(int i, $type$ a);
99 }
100
101 abstract void forEach(FUnCon f);
102
103 abstract void forEach(Mask<$Boxtype$> m, FUnCon f);
104
105 // Static factories
106
107 /**
108 * Returns a vector where all lane elements are set to the default
109 * primitive value.
110 *
111 * @param species species of desired vector
112 * @return a zero vector of given species
113 */
114 @ForceInline
115 @SuppressWarnings("unchecked")
116 public static $abstractvectortype$ zero(Species<$Boxtype$> species) {
117 #if[FP]
118 return VectorIntrinsics.broadcastCoerced((Class<$Type$Vector>) species.boxType(), $type$.class, species.length(),
119 $Type$.$type$To$Bitstype$Bits(0.0f), species,
120 ((bits, s) -> (($Type$Species)s).op(i -> $Type$.$bitstype$BitsTo$Type$(($bitstype$)bits))));
121 #else[FP]
122 return VectorIntrinsics.broadcastCoerced((Class<$Type$Vector>) species.boxType(), $type$.class, species.length(),
123 0, species,
124 ((bits, s) -> (($Type$Species)s).op(i -> ($type$)bits)));
125 #end[FP]
126 }
127
128 /**
129 * Loads a vector from a byte array starting at an offset.
130 * <p>
131 * Bytes are composed into primitive lane elements according to the
132 * native byte order of the underlying platform
133 * <p>
134 * This method behaves as if it returns the result of calling the
135 * byte buffer, offset, and mask accepting
136 * {@link #fromByteBuffer(Species<$Boxtype$>, ByteBuffer, int, Mask) method} as follows:
137 * <pre>{@code
138 * return this.fromByteBuffer(ByteBuffer.wrap(a), i, this.maskAllTrue());
139 * }</pre>
140 *
141 * @param species species of desired vector
142 * @param a the byte array
143 * @param ix the offset into the array
144 * @return a vector loaded from a byte array
145 * @throws IndexOutOfBoundsException if {@code i < 0} or
146 * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)}
147 */
148 @ForceInline
149 @SuppressWarnings("unchecked")
150 public static $abstractvectortype$ fromByteArray(Species<$Boxtype$> species, byte[] a, int ix) {
151 Objects.requireNonNull(a);
152 ix = VectorIntrinsics.checkIndex(ix, a.length, species.bitSize() / Byte.SIZE);
153 return VectorIntrinsics.load((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(),
154 a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
155 a, ix, species,
156 (c, idx, s) -> {
157 ByteBuffer bbc = ByteBuffer.wrap(c, idx, a.length - idx).order(ByteOrder.nativeOrder());
158 $Type$Buffer tb = bbc{#if[byte]?;:.as$Type$Buffer();}
159 return (($Type$Species)s).op(i -> tb.get());
160 });
161 }
162
163 /**
164 * Loads a vector from a byte array starting at an offset and using a
165 * mask.
166 * <p>
167 * Bytes are composed into primitive lane elements according to the
168 * native byte order of the underlying platform.
169 * <p>
170 * This method behaves as if it returns the result of calling the
171 * byte buffer, offset, and mask accepting
172 * {@link #fromByteBuffer(Species<$Boxtype$>, ByteBuffer, int, Mask) method} as follows:
173 * <pre>{@code
174 * return this.fromByteBuffer(ByteBuffer.wrap(a), i, m);
175 * }</pre>
176 *
177 * @param species species of desired vector
178 * @param a the byte array
179 * @param ix the offset into the array
180 * @param m the mask
181 * @return a vector loaded from a byte array
182 * @throws IndexOutOfBoundsException if {@code i < 0} or
183 * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)}
184 * @throws IndexOutOfBoundsException if the offset is {@code < 0},
185 * or {@code > a.length},
186 * for any vector lane index {@code N} where the mask at lane {@code N}
187 * is set
188 * {@code i >= a.length - (N * this.elementSize() / Byte.SIZE)}
189 */
190 @ForceInline
191 public static $abstractvectortype$ fromByteArray(Species<$Boxtype$> species, byte[] a, int ix, Mask<$Boxtype$> m) {
192 return zero(species).blend(fromByteArray(species, a, ix), m);
193 }
194
195 /**
196 * Loads a vector from an array starting at offset.
197 * <p>
198 * For each vector lane, where {@code N} is the vector lane index, the
199 * array element at index {@code i + N} is placed into the
200 * resulting vector at lane index {@code N}.
201 *
202 * @param species species of desired vector
203 * @param a the array
204 * @param i the offset into the array
205 * @return the vector loaded from an array
206 * @throws IndexOutOfBoundsException if {@code i < 0}, or
207 * {@code i > a.length - this.length()}
208 */
209 @ForceInline
210 @SuppressWarnings("unchecked")
211 public static $abstractvectortype$ fromArray(Species<$Boxtype$> species, $type$[] a, int i){
212 Objects.requireNonNull(a);
213 i = VectorIntrinsics.checkIndex(i, a.length, species.length());
214 return VectorIntrinsics.load((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(),
215 a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_$TYPE$_BASE_OFFSET,
216 a, i, species,
217 (c, idx, s) -> (($Type$Species)s).op(n -> c[idx + n]));
218 }
219
220
221 /**
222 * Loads a vector from an array starting at offset and using a mask.
223 * <p>
224 * For each vector lane, where {@code N} is the vector lane index,
225 * if the mask lane at index {@code N} is set then the array element at
226 * index {@code i + N} is placed into the resulting vector at lane index
227 * {@code N}, otherwise the default element value is placed into the
228 * resulting vector at lane index {@code N}.
229 *
230 * @param species species of desired vector
231 * @param a the array
232 * @param i the offset into the array
233 * @param m the mask
234 * @return the vector loaded from an array
235 * @throws IndexOutOfBoundsException if {@code i < 0}, or
236 * for any vector lane index {@code N} where the mask at lane {@code N}
237 * is set {@code i > a.length - N}
238 */
239 @ForceInline
240 public static $abstractvectortype$ fromArray(Species<$Boxtype$> species, $type$[] a, int i, Mask<$Boxtype$> m) {
241 return zero(species).blend(fromArray(species, a, i), m);
242 }
243
244 /**
245 * Loads a vector from an array using indexes obtained from an index
246 * map.
247 * <p>
248 * For each vector lane, where {@code N} is the vector lane index, the
249 * array element at index {@code i + indexMap[j + N]} is placed into the
250 * resulting vector at lane index {@code N}.
251 *
252 * @param species species of desired vector
253 * @param a the array
254 * @param i the offset into the array, may be negative if relative
255 * indexes in the index map compensate to produce a value within the
256 * array bounds
257 * @param indexMap the index map
258 * @param j the offset into the index map
259 * @return the vector loaded from an array
260 * @throws IndexOutOfBoundsException if {@code j < 0}, or
261 * {@code j > indexMap.length - this.length()},
262 * or for any vector lane index {@code N} the result of
263 * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length}
264 */
265 #if[byteOrShort]
266 public static $abstractvectortype$ fromArray(Species<$Boxtype$> species, $type$[] a, int i, int[] indexMap, int j) {
267 return (($Type$Species)species).op(n -> a[i + indexMap[j + n]]);
268 }
269 #else[byteOrShort]
270 @ForceInline
271 @SuppressWarnings("unchecked")
272 public static $abstractvectortype$ fromArray(Species<$Boxtype$> species, $type$[] a, int i, int[] indexMap, int j) {
273 Objects.requireNonNull(a);
274 Objects.requireNonNull(indexMap);
275
276 #if[longOrDouble]
277 if (species.length() == 1) {
278 return $abstractvectortype$.fromArray(species, a, i + indexMap[j]);
279 }
280 #end[longOrDouble]
281
282 // Index vector: vix[0:n] = k -> i + indexMap[j + k]
283 IntVector vix = IntVector.fromArray(IntVector.species(species.indexShape()), indexMap, j).add(i);
284
285 vix = VectorIntrinsics.checkIndex(vix, a.length);
286
287 return VectorIntrinsics.loadWithMap((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(),
288 IntVector.species(species.indexShape()).boxType(), a, Unsafe.ARRAY_$TYPE$_BASE_OFFSET, vix,
289 a, i, indexMap, j, species,
290 ($type$[] c, int idx, int[] iMap, int idy, Species<$Boxtype$> s) ->
291 (($Type$Species)s).op(n -> c[idx + iMap[idy+n]]));
292 }
293
294 #end[byteOrShort]
295 /**
296 * Loads a vector from an array using indexes obtained from an index
297 * map and using a mask.
298 * <p>
299 * For each vector lane, where {@code N} is the vector lane index,
300 * if the mask lane at index {@code N} is set then the array element at
301 * index {@code i + indexMap[j + N]} is placed into the resulting vector
302 * at lane index {@code N}.
303 *
304 * @param species species of desired vector
305 * @param a the array
306 * @param i the offset into the array, may be negative if relative
307 * indexes in the index map compensate to produce a value within the
308 * array bounds
309 * @param m the mask
310 * @param indexMap the index map
311 * @param j the offset into the index map
312 * @return the vector loaded from an array
313 * @throws IndexOutOfBoundsException if {@code j < 0}, or
314 * {@code j > indexMap.length - this.length()},
315 * or for any vector lane index {@code N} where the mask at lane
316 * {@code N} is set the result of {@code i + indexMap[j + N]} is
317 * {@code < 0} or {@code >= a.length}
318 */
319 #if[byteOrShort]
320 public static $abstractvectortype$ fromArray(Species<$Boxtype$> species, $type$[] a, int i, Mask<$Boxtype$> m, int[] indexMap, int j) {
321 return (($Type$Species)species).op(m, n -> a[i + indexMap[j + n]]);
322 }
323 #else[byteOrShort]
324 @ForceInline
325 @SuppressWarnings("unchecked")
326 public static $abstractvectortype$ fromArray(Species<$Boxtype$> species, $type$[] a, int i, Mask<$Boxtype$> m, int[] indexMap, int j) {
327 // @@@ This can result in out of bounds errors for unset mask lanes
328 return zero(species).blend(fromArray(species, a, i, indexMap, j), m);
329 }
330
331 #end[byteOrShort]
332
333 /**
334 * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
335 * offset into the byte buffer.
336 * <p>
337 * Bytes are composed into primitive lane elements according to the
338 * native byte order of the underlying platform.
339 * <p>
340 * This method behaves as if it returns the result of calling the
341 * byte buffer, offset, and mask accepting
342 * {@link #fromByteBuffer(Species<$Boxtype$>, ByteBuffer, int, Mask)} method} as follows:
343 * <pre>{@code
344 * return this.fromByteBuffer(b, i, this.maskAllTrue())
345 * }</pre>
346 *
347 * @param species species of desired vector
348 * @param bb the byte buffer
349 * @param ix the offset into the byte buffer
350 * @return a vector loaded from a byte buffer
351 * @throws IndexOutOfBoundsException if the offset is {@code < 0},
352 * or {@code > b.limit()},
353 * or if there are fewer than
354 * {@code this.length() * this.elementSize() / Byte.SIZE} bytes
355 * remaining in the byte buffer from the given offset
356 */
357 @ForceInline
358 @SuppressWarnings("unchecked")
359 public static $abstractvectortype$ fromByteBuffer(Species<$Boxtype$> species, ByteBuffer bb, int ix) {
360 if (bb.order() != ByteOrder.nativeOrder()) {
361 throw new IllegalArgumentException();
362 }
363 ix = VectorIntrinsics.checkIndex(ix, bb.limit(), species.bitSize() / Byte.SIZE);
364 return VectorIntrinsics.load((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(),
365 U.getReference(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + ix,
366 bb, ix, species,
367 (c, idx, s) -> {
368 ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
369 $Type$Buffer tb = bbc{#if[byte]?;:.as$Type$Buffer();}
370 return (($Type$Species)s).op(i -> tb.get());
371 });
372 }
373
374 /**
375 * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
376 * offset into the byte buffer and using a mask.
377 * <p>
378 * This method behaves as if the byte buffer is viewed as a primitive
379 * {@link java.nio.Buffer buffer} for the primitive element type,
391 * e[] es = new e[this.length()];
392 * for (int n = 0; n < t.length; n++) {
393 * if (m.isSet(n))
394 * es[n] = eb.get(n);
395 * }
396 * Vector<E> r = ((ESpecies<S>)this).fromArray(es, 0, m);
397 * }</pre>
398 *
399 * @param species species of desired vector
400 * @param bb the byte buffer
401 * @param ix the offset into the byte buffer
402 * @param m the mask
403 * @return a vector loaded from a byte buffer
404 * @throws IndexOutOfBoundsException if the offset is {@code < 0},
405 * or {@code > b.limit()},
406 * for any vector lane index {@code N} where the mask at lane {@code N}
407 * is set
408 * {@code i >= b.limit() - (N * this.elementSize() / Byte.SIZE)}
409 */
410 @ForceInline
411 public static $abstractvectortype$ fromByteBuffer(Species<$Boxtype$> species, ByteBuffer bb, int ix, Mask<$Boxtype$> m) {
412 return zero(species).blend(fromByteBuffer(species, bb, ix), m);
413 }
414
415 /**
416 * Returns a vector where all lane elements are set to the primitive
417 * value {@code e}.
418 *
419 * @param s species of the desired vector
420 * @param e the value
421 * @return a vector of vector where all lane elements are set to
422 * the primitive value {@code e}
423 */
424 #if[FP]
425 @ForceInline
426 @SuppressWarnings("unchecked")
427 public static $abstractvectortype$ broadcast(Species<$Boxtype$> s, $type$ e) {
428 return VectorIntrinsics.broadcastCoerced(
429 (Class<$abstractvectortype$>) s.boxType(), $type$.class, s.length(),
430 $Type$.$type$To$Bitstype$Bits(e), s,
431 ((bits, sp) -> (($Type$Species)sp).op(i -> $Type$.$bitstype$BitsTo$Type$(($bitstype$)bits))));
432 }
433 #else[FP]
434 @ForceInline
435 @SuppressWarnings("unchecked")
436 public static $abstractvectortype$ broadcast(Species<$Boxtype$> s, $type$ e) {
437 return VectorIntrinsics.broadcastCoerced(
438 (Class<$abstractvectortype$>) s.boxType(), $type$.class, s.length(),
439 e, s,
440 ((bits, sp) -> (($Type$Species)sp).op(i -> ($type$)bits)));
441 }
442 #end[FP]
443
444 /**
445 * Returns a vector where each lane element is set to a given
446 * primitive value.
447 * <p>
448 * For each vector lane, where {@code N} is the vector lane index, the
449 * the primitive value at index {@code N} is placed into the resulting
450 * vector at lane index {@code N}.
451 *
452 * @param s species of the desired vector
453 * @param es the given primitive values
454 * @return a vector where each lane element is set to a given primitive
455 * value
456 * @throws IndexOutOfBoundsException if {@code es.length < this.length()}
457 */
458 @ForceInline
459 @SuppressWarnings("unchecked")
460 public static $abstractvectortype$ scalars(Species<$Boxtype$> s, $type$... es) {
461 Objects.requireNonNull(es);
462 int ix = VectorIntrinsics.checkIndex(0, es.length, s.length());
463 return VectorIntrinsics.load((Class<$abstractvectortype$>) s.boxType(), $type$.class, s.length(),
464 es, Unsafe.ARRAY_$TYPE$_BASE_OFFSET,
465 es, ix, s,
466 (c, idx, sp) -> (($Type$Species)sp).op(n -> c[idx + n]));
467 }
468
469 /**
470 * Returns a vector where the first lane element is set to the primtive
471 * value {@code e}, all other lane elements are set to the default
472 * value.
473 *
474 * @param s species of the desired vector
475 * @param e the value
476 * @return a vector where the first lane element is set to the primitive
477 * value {@code e}
478 */
479 @ForceInline
480 public static final $abstractvectortype$ single(Species<$Boxtype$> s, $type$ e) {
481 return zero(s).with(0, e);
482 }
483
484 /**
485 * Returns a vector where each lane element is set to a randomly
486 * generated primitive value.
487 *
488 * The semantics are equivalent to calling
489 #if[byteOrShort]
490 * ($type$){@link ThreadLocalRandom#nextInt()}
491 #else[byteOrShort]
492 * {@link ThreadLocalRandom#next$Type$()}
493 #end[byteOrShort]
494 *
495 * @param s species of the desired vector
496 * @return a vector where each lane elements is set to a randomly
497 * generated primitive value
498 */
499 #if[intOrLong]
500 public static $abstractvectortype$ random(Species<$Boxtype$> s) {
501 ThreadLocalRandom r = ThreadLocalRandom.current();
502 return (($Type$Species)s).op(i -> r.next$Type$());
503 }
504 #else[intOrLong]
505 #if[FP]
506 public static $abstractvectortype$ random(Species<$Boxtype$> s) {
507 ThreadLocalRandom r = ThreadLocalRandom.current();
508 return (($Type$Species)s).op(i -> r.next$Type$());
509 }
510 #else[FP]
511 public static $abstractvectortype$ random(Species<$Boxtype$> s) {
512 ThreadLocalRandom r = ThreadLocalRandom.current();
513 return (($Type$Species)s).op(i -> ($type$) r.nextInt());
514 }
515 #end[FP]
516 #end[intOrLong]
517
518 /**
519 * Returns a mask where each lane is set or unset according to given
520 * {@code boolean} values
521 * <p>
522 * For each mask lane, where {@code N} is the mask lane index,
523 * if the given {@code boolean} value at index {@code N} is {@code true}
524 * then the mask lane at index {@code N} is set, otherwise it is unset.
525 *
526 * @param species mask species
527 * @param bits the given {@code boolean} values
528 * @return a mask where each lane is set or unset according to the given {@code boolean} value
529 * @throws IndexOutOfBoundsException if {@code bits.length < species.length()}
530 */
531 @ForceInline
532 public static Mask<$Boxtype$> maskFromValues(Species<$Boxtype$> species, boolean... bits) {
533 if (species.boxType() == $Type$MaxVector.class)
534 return new $Type$MaxVector.$Type$MaxMask(bits);
535 switch (species.bitSize()) {
536 case 64: return new $Type$64Vector.$Type$64Mask(bits);
537 case 128: return new $Type$128Vector.$Type$128Mask(bits);
538 case 256: return new $Type$256Vector.$Type$256Mask(bits);
539 case 512: return new $Type$512Vector.$Type$512Mask(bits);
540 default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
541 }
542 }
543
544 // @@@ This is a bad implementation -- makes lambdas capturing -- fix this
545 static Mask<$Boxtype$> trueMask(Species<$Boxtype$> species) {
546 if (species.boxType() == $Type$MaxVector.class)
547 return $Type$MaxVector.$Type$MaxMask.TRUE_MASK;
548 switch (species.bitSize()) {
549 case 64: return $Type$64Vector.$Type$64Mask.TRUE_MASK;
550 case 128: return $Type$128Vector.$Type$128Mask.TRUE_MASK;
551 case 256: return $Type$256Vector.$Type$256Mask.TRUE_MASK;
552 case 512: return $Type$512Vector.$Type$512Mask.TRUE_MASK;
553 default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
554 }
555 }
556
557 static Mask<$Boxtype$> falseMask(Species<$Boxtype$> species) {
558 if (species.boxType() == $Type$MaxVector.class)
559 return $Type$MaxVector.$Type$MaxMask.FALSE_MASK;
560 switch (species.bitSize()) {
561 case 64: return $Type$64Vector.$Type$64Mask.FALSE_MASK;
562 case 128: return $Type$128Vector.$Type$128Mask.FALSE_MASK;
563 case 256: return $Type$256Vector.$Type$256Mask.FALSE_MASK;
564 case 512: return $Type$512Vector.$Type$512Mask.FALSE_MASK;
565 default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
566 }
567 }
568
569 /**
570 * Loads a mask from a {@code boolean} array starting at an offset.
571 * <p>
572 * For each mask lane, where {@code N} is the mask lane index,
573 * if the array element at index {@code ix + N} is {@code true} then the
574 * mask lane at index {@code N} is set, otherwise it is unset.
575 *
576 * @param species mask species
577 * @param bits the {@code boolean} array
578 * @param ix the offset into the array
579 * @return the mask loaded from a {@code boolean} array
580 * @throws IndexOutOfBoundsException if {@code ix < 0}, or
581 * {@code ix > bits.length - species.length()}
582 */
583 @ForceInline
584 @SuppressWarnings("unchecked")
585 public static Mask<$Boxtype$> maskFromArray(Species<$Boxtype$> species, boolean[] bits, int ix) {
586 Objects.requireNonNull(bits);
587 ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length());
588 return VectorIntrinsics.load((Class<Mask<$Boxtype$>>) species.maskType(), $bitstype$.class, species.length(),
589 bits, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET,
590 bits, ix, species,
591 (c, idx, s) -> (Mask<$Boxtype$>) (($Type$Species)s).opm(n -> c[idx + n]));
592 }
593
594 /**
595 * Returns a mask where all lanes are set.
596 *
597 * @param species mask species
598 * @return a mask where all lanes are set
599 */
600 @ForceInline
601 @SuppressWarnings("unchecked")
602 public static Mask<$Boxtype$> maskAllTrue(Species<$Boxtype$> species) {
603 return VectorIntrinsics.broadcastCoerced((Class<Mask<$Boxtype$>>) species.maskType(), $bitstype$.class, species.length(),
604 ($bitstype$)-1, species,
605 ((z, s) -> trueMask(s)));
606 }
607
608 /**
609 * Returns a mask where all lanes are unset.
610 *
611 * @param species mask species
612 * @return a mask where all lanes are unset
613 */
614 @ForceInline
615 @SuppressWarnings("unchecked")
616 public static Mask<$Boxtype$> maskAllFalse(Species<$Boxtype$> species) {
617 return VectorIntrinsics.broadcastCoerced((Class<Mask<$Boxtype$>>) species.maskType(), $bitstype$.class, species.length(),
618 0, species,
619 ((z, s) -> falseMask(s)));
620 }
621
622 /**
623 * Returns a shuffle of mapped indexes where each lane element is
624 * the result of applying a mapping function to the corresponding lane
625 * index.
626 * <p>
627 * Care should be taken to ensure Shuffle values produced from this
628 * method are consumed as constants to ensure optimal generation of
629 * code. For example, values held in static final fields or values
630 * held in loop constant local variables.
631 * <p>
632 * This method behaves as if a shuffle is created from an array of
633 * mapped indexes as follows:
634 * <pre>{@code
635 * int[] a = new int[species.length()];
636 * for (int i = 0; i < a.length; i++) {
637 * a[i] = f.applyAsInt(i);
638 * }
639 * return this.shuffleFromValues(a);
640 * }</pre>
641 *
642 * @param species shuffle species
643 * @param f the lane index mapping function
644 * @return a shuffle of mapped indexes
645 */
646 @ForceInline
647 public static Shuffle<$Boxtype$> shuffle(Species<$Boxtype$> species, IntUnaryOperator f) {
648 if (species.boxType() == $Type$MaxVector.class)
649 return new $Type$MaxVector.$Type$MaxShuffle(f);
650 switch (species.bitSize()) {
651 case 64: return new $Type$64Vector.$Type$64Shuffle(f);
652 case 128: return new $Type$128Vector.$Type$128Shuffle(f);
653 case 256: return new $Type$256Vector.$Type$256Shuffle(f);
654 case 512: return new $Type$512Vector.$Type$512Shuffle(f);
655 default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
656 }
657 }
658
659 /**
660 * Returns a shuffle where each lane element is the value of its
661 * corresponding lane index.
662 * <p>
663 * This method behaves as if a shuffle is created from an identity
664 * index mapping function as follows:
665 * <pre>{@code
666 * return this.shuffle(i -> i);
667 * }</pre>
668 *
669 * @param species shuffle species
670 * @return a shuffle of lane indexes
671 */
672 @ForceInline
673 public static Shuffle<$Boxtype$> shuffleIota(Species<$Boxtype$> species) {
674 if (species.boxType() == $Type$MaxVector.class)
675 return new $Type$MaxVector.$Type$MaxShuffle(AbstractShuffle.IDENTITY);
676 switch (species.bitSize()) {
677 case 64: return new $Type$64Vector.$Type$64Shuffle(AbstractShuffle.IDENTITY);
678 case 128: return new $Type$128Vector.$Type$128Shuffle(AbstractShuffle.IDENTITY);
679 case 256: return new $Type$256Vector.$Type$256Shuffle(AbstractShuffle.IDENTITY);
680 case 512: return new $Type$512Vector.$Type$512Shuffle(AbstractShuffle.IDENTITY);
681 default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
682 }
683 }
684
685 /**
686 * Returns a shuffle where each lane element is set to a given
687 * {@code int} value logically AND'ed by the species length minus one.
688 * <p>
689 * For each shuffle lane, where {@code N} is the shuffle lane index, the
690 * the {@code int} value at index {@code N} logically AND'ed by
691 * {@code species.length() - 1} is placed into the resulting shuffle at
692 * lane index {@code N}.
693 *
694 * @param species shuffle species
695 * @param ixs the given {@code int} values
696 * @return a shuffle where each lane element is set to a given
697 * {@code int} value
698 * @throws IndexOutOfBoundsException if the number of int values is
699 * {@code < species.length()}
700 */
701 @ForceInline
702 public static Shuffle<$Boxtype$> shuffleFromValues(Species<$Boxtype$> species, int... ixs) {
703 if (species.boxType() == $Type$MaxVector.class)
704 return new $Type$MaxVector.$Type$MaxShuffle(ixs);
705 switch (species.bitSize()) {
706 case 64: return new $Type$64Vector.$Type$64Shuffle(ixs);
707 case 128: return new $Type$128Vector.$Type$128Shuffle(ixs);
708 case 256: return new $Type$256Vector.$Type$256Shuffle(ixs);
709 case 512: return new $Type$512Vector.$Type$512Shuffle(ixs);
710 default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
711 }
712 }
713
714 /**
715 * Loads a shuffle from an {@code int} array starting at an offset.
716 * <p>
717 * For each shuffle lane, where {@code N} is the shuffle lane index, the
718 * array element at index {@code i + N} logically AND'ed by
719 * {@code species.length() - 1} is placed into the resulting shuffle at lane
720 * index {@code N}.
721 *
722 * @param species shuffle species
723 * @param ixs the {@code int} array
724 * @param i the offset into the array
725 * @return a shuffle loaded from the {@code int} array
726 * @throws IndexOutOfBoundsException if {@code i < 0}, or
727 * {@code i > a.length - species.length()}
728 */
729 @ForceInline
730 public static Shuffle<$Boxtype$> shuffleFromArray(Species<$Boxtype$> species, int[] ixs, int i) {
731 if (species.boxType() == $Type$MaxVector.class)
732 return new $Type$MaxVector.$Type$MaxShuffle(ixs, i);
733 switch (species.bitSize()) {
734 case 64: return new $Type$64Vector.$Type$64Shuffle(ixs, i);
735 case 128: return new $Type$128Vector.$Type$128Shuffle(ixs, i);
736 case 256: return new $Type$256Vector.$Type$256Shuffle(ixs, i);
737 case 512: return new $Type$512Vector.$Type$512Shuffle(ixs, i);
738 default: throw new IllegalArgumentException(Integer.toString(species.bitSize()));
739 }
740 }
741
742 // Ops
743
744 @Override
745 public abstract $abstractvectortype$ add(Vector<$Boxtype$> v);
746
747 /**
748 * Adds this vector to the broadcast of an input scalar.
749 * <p>
750 * This is a vector binary operation where the primitive addition operation
751 * ({@code +}) is applied to lane elements.
752 *
753 * @param s the input scalar
754 * @return the result of adding this vector to the broadcast of an input
755 * scalar
756 */
757 public abstract $abstractvectortype$ add($type$ s);
758
759 @Override
760 public abstract $abstractvectortype$ add(Vector<$Boxtype$> v, Mask<$Boxtype$> m);
761
762 /**
763 * Adds this vector to broadcast of an input scalar,
764 * selecting lane elements controlled by a mask.
765 * <p>
766 * This is a vector binary operation where the primitive addition operation
767 * ({@code +}) is applied to lane elements.
768 *
769 * @param s the input scalar
770 * @param m the mask controlling lane selection
771 * @return the result of adding this vector to the broadcast of an input
772 * scalar
773 */
774 public abstract $abstractvectortype$ add($type$ s, Mask<$Boxtype$> m);
775
776 @Override
777 public abstract $abstractvectortype$ sub(Vector<$Boxtype$> v);
778
779 /**
780 * Subtracts the broadcast of an input scalar from this vector.
781 * <p>
782 * This is a vector binary operation where the primitive subtraction
783 * operation ({@code -}) is applied to lane elements.
784 *
785 * @param s the input scalar
786 * @return the result of subtracting the broadcast of an input
787 * scalar from this vector
788 */
789 public abstract $abstractvectortype$ sub($type$ s);
790
791 @Override
792 public abstract $abstractvectortype$ sub(Vector<$Boxtype$> v, Mask<$Boxtype$> m);
793
794 /**
795 * Subtracts the broadcast of an input scalar from this vector, selecting
796 * lane elements controlled by a mask.
797 * <p>
798 * This is a vector binary operation where the primitive subtraction
799 * operation ({@code -}) is applied to lane elements.
800 *
801 * @param s the input scalar
802 * @param m the mask controlling lane selection
803 * @return the result of subtracting the broadcast of an input
804 * scalar from this vector
805 */
806 public abstract $abstractvectortype$ sub($type$ s, Mask<$Boxtype$> m);
807
808 @Override
809 public abstract $abstractvectortype$ mul(Vector<$Boxtype$> v);
810
811 /**
812 * Multiplies this vector with the broadcast of an input scalar.
813 * <p>
814 * This is a vector binary operation where the primitive multiplication
815 * operation ({@code *}) is applied to lane elements.
816 *
817 * @param s the input scalar
818 * @return the result of multiplying this vector with the broadcast of an
819 * input scalar
820 */
821 public abstract $abstractvectortype$ mul($type$ s);
822
823 @Override
824 public abstract $abstractvectortype$ mul(Vector<$Boxtype$> v, Mask<$Boxtype$> m);
825
826 /**
827 * Multiplies this vector with the broadcast of an input scalar, selecting
828 * lane elements controlled by a mask.
829 * <p>
830 * This is a vector binary operation where the primitive multiplication
831 * operation ({@code *}) is applied to lane elements.
832 *
833 * @param s the input scalar
834 * @param m the mask controlling lane selection
835 * @return the result of multiplying this vector with the broadcast of an
836 * input scalar
837 */
838 public abstract $abstractvectortype$ mul($type$ s, Mask<$Boxtype$> m);
839
840 @Override
841 public abstract $abstractvectortype$ neg();
842
843 @Override
844 public abstract $abstractvectortype$ neg(Mask<$Boxtype$> m);
845
846 @Override
847 public abstract $abstractvectortype$ abs();
848
849 @Override
850 public abstract $abstractvectortype$ abs(Mask<$Boxtype$> m);
851
852 @Override
853 public abstract $abstractvectortype$ min(Vector<$Boxtype$> v);
854
855 @Override
856 public abstract $abstractvectortype$ min(Vector<$Boxtype$> v, Mask<$Boxtype$> m);
857
858 /**
859 * Returns the minimum of this vector and the broadcast of an input scalar.
860 * <p>
861 * This is a vector binary operation where the operation
862 * {@code (a, b) -> Math.min(a, b)} is applied to lane elements.
863 *
864 * @param s the input scalar
865 * @return the minimum of this vector and the broadcast of an input scalar
866 */
867 public abstract $abstractvectortype$ min($type$ s);
868
869 @Override
870 public abstract $abstractvectortype$ max(Vector<$Boxtype$> v);
871
872 @Override
873 public abstract $abstractvectortype$ max(Vector<$Boxtype$> v, Mask<$Boxtype$> m);
874
875 /**
876 * Returns the maximum of this vector and the broadcast of an input scalar.
877 * <p>
878 * This is a vector binary operation where the operation
879 * {@code (a, b) -> Math.max(a, b)} is applied to lane elements.
880 *
881 * @param s the input scalar
882 * @return the maximum of this vector and the broadcast of an input scalar
883 */
884 public abstract $abstractvectortype$ max($type$ s);
885
886 @Override
887 public abstract Mask<$Boxtype$> equal(Vector<$Boxtype$> v);
888
889 /**
890 * Tests if this vector is equal to the broadcast of an input scalar.
891 * <p>
892 * This is a vector binary test operation where the primitive equals
893 * operation ({@code ==}) is applied to lane elements.
894 *
895 * @param s the input scalar
896 * @return the result mask of testing if this vector is equal to the
897 * broadcast of an input scalar
898 */
899 public abstract Mask<$Boxtype$> equal($type$ s);
900
901 @Override
902 public abstract Mask<$Boxtype$> notEqual(Vector<$Boxtype$> v);
903
904 /**
905 * Tests if this vector is not equal to the broadcast of an input scalar.
906 * <p>
907 * This is a vector binary test operation where the primitive not equals
908 * operation ({@code !=}) is applied to lane elements.
909 *
910 * @param s the input scalar
911 * @return the result mask of testing if this vector is not equal to the
912 * broadcast of an input scalar
913 */
914 public abstract Mask<$Boxtype$> notEqual($type$ s);
915
916 @Override
917 public abstract Mask<$Boxtype$> lessThan(Vector<$Boxtype$> v);
918
919 /**
920 * Tests if this vector is less than the broadcast of an input scalar.
921 * <p>
922 * This is a vector binary test operation where the primitive less than
923 * operation ({@code <}) is applied to lane elements.
924 *
925 * @param s the input scalar
926 * @return the mask result of testing if this vector is less than the
927 * broadcast of an input scalar
928 */
929 public abstract Mask<$Boxtype$> lessThan($type$ s);
930
931 @Override
932 public abstract Mask<$Boxtype$> lessThanEq(Vector<$Boxtype$> v);
933
934 /**
935 * Tests if this vector is less or equal to the broadcast of an input scalar.
936 * <p>
937 * This is a vector binary test operation where the primitive less than
938 * or equal to operation ({@code <=}) is applied to lane elements.
939 *
940 * @param s the input scalar
941 * @return the mask result of testing if this vector is less than or equal
942 * to the broadcast of an input scalar
943 */
944 public abstract Mask<$Boxtype$> lessThanEq($type$ s);
945
946 @Override
947 public abstract Mask<$Boxtype$> greaterThan(Vector<$Boxtype$> v);
948
949 /**
950 * Tests if this vector is greater than the broadcast of an input scalar.
951 * <p>
952 * This is a vector binary test operation where the primitive greater than
953 * operation ({@code >}) is applied to lane elements.
954 *
955 * @param s the input scalar
956 * @return the mask result of testing if this vector is greater than the
957 * broadcast of an input scalar
958 */
959 public abstract Mask<$Boxtype$> greaterThan($type$ s);
960
961 @Override
962 public abstract Mask<$Boxtype$> greaterThanEq(Vector<$Boxtype$> v);
963
964 /**
965 * Tests if this vector is greater than or equal to the broadcast of an
966 * input scalar.
967 * <p>
968 * This is a vector binary test operation where the primitive greater than
969 * or equal to operation ({@code >=}) is applied to lane elements.
970 *
971 * @param s the input scalar
972 * @return the mask result of testing if this vector is greater than or
973 * equal to the broadcast of an input scalar
974 */
975 public abstract Mask<$Boxtype$> greaterThanEq($type$ s);
976
977 @Override
978 public abstract $abstractvectortype$ blend(Vector<$Boxtype$> v, Mask<$Boxtype$> m);
979
980 /**
981 * Blends the lane elements of this vector with those of the broadcast of an
982 * input scalar, selecting lanes controlled by a mask.
983 * <p>
984 * For each lane of the mask, at lane index {@code N}, if the mask lane
985 * is set then the lane element at {@code N} from the input vector is
986 * selected and placed into the resulting vector at {@code N},
987 * otherwise the the lane element at {@code N} from this input vector is
988 * selected and placed into the resulting vector at {@code N}.
989 *
990 * @param s the input scalar
991 * @param m the mask controlling lane selection
992 * @return the result of blending the lane elements of this vector with
993 * those of the broadcast of an input scalar
994 */
995 public abstract $abstractvectortype$ blend($type$ s, Mask<$Boxtype$> m);
996
997 @Override
998 public abstract $abstractvectortype$ rearrange(Vector<$Boxtype$> v,
999 Shuffle<$Boxtype$> s, Mask<$Boxtype$> m);
1000
1001 @Override
1002 public abstract $abstractvectortype$ rearrange(Shuffle<$Boxtype$> m);
1003
1004 @Override
1005 public abstract $abstractvectortype$ reshape(Species<$Boxtype$> s);
1006
1007 @Override
1008 public abstract $abstractvectortype$ rotateEL(int i);
1009
1010 @Override
1011 public abstract $abstractvectortype$ rotateER(int i);
1012
1013 @Override
1014 public abstract $abstractvectortype$ shiftEL(int i);
1015
1016 @Override
1017 public abstract $abstractvectortype$ shiftER(int i);
1018
1019 #if[FP]
1020 /**
1021 * Divides this vector by an input vector.
1022 * <p>
1023 * This is a vector binary operation where the primitive division
1024 * operation ({@code /}) is applied to lane elements.
1025 *
1034 * This is a vector binary operation where the primitive division
1035 * operation ({@code /}) is applied to lane elements.
1036 *
1037 * @param s the input scalar
1038 * @return the result of dividing this vector by the broadcast of an input
1039 * scalar
1040 */
1041 public abstract $abstractvectortype$ div($type$ s);
1042
1043 /**
1044 * Divides this vector by an input vector, selecting lane elements
1045 * controlled by a mask.
1046 * <p>
1047 * This is a vector binary operation where the primitive division
1048 * operation ({@code /}) is applied to lane elements.
1049 *
1050 * @param v the input vector
1051 * @param m the mask controlling lane selection
1052 * @return the result of dividing this vector by the input vector
1053 */
1054 public abstract $abstractvectortype$ div(Vector<$Boxtype$> v, Mask<$Boxtype$> m);
1055
1056 /**
1057 * Divides this vector by the broadcast of an input scalar, selecting lane
1058 * elements controlled by a mask.
1059 * <p>
1060 * This is a vector binary operation where the primitive division
1061 * operation ({@code /}) is applied to lane elements.
1062 *
1063 * @param s the input scalar
1064 * @param m the mask controlling lane selection
1065 * @return the result of dividing this vector by the broadcast of an input
1066 * scalar
1067 */
1068 public abstract $abstractvectortype$ div($type$ s, Mask<$Boxtype$> m);
1069
1070 /**
1071 * Calculates the square root of this vector.
1072 * <p>
1073 * This is a vector unary operation where the {@link Math#sqrt} operation
1074 * is applied to lane elements.
1075 *
1076 * @return the square root of this vector
1077 */
1078 public abstract $abstractvectortype$ sqrt();
1079
1080 /**
1081 * Calculates the square root of this vector, selecting lane elements
1082 * controlled by a mask.
1083 * <p>
1084 * This is a vector unary operation where the {@link Math#sqrt} operation
1085 * is applied to lane elements.
1086 *
1087 * @param m the mask controlling lane selection
1088 * @return the square root of this vector
1089 */
1090 public $abstractvectortype$ sqrt(Mask<$Boxtype$> m) {
1091 return uOp(m, (i, a) -> ($type$) Math.sqrt((double) a));
1092 }
1093
1094 /**
1095 * Calculates the trigonometric tangent of this vector.
1096 * <p>
1097 * This is a vector unary operation with same semantic definition as
1098 * {@link Math#tan} operation applied to lane elements.
1099 * The implementation is not required to return same
1100 * results as {@link Math#tan}, but adheres to rounding, monotonicity,
1101 * and special case semantics as defined in the {@link Math#tan}
1102 * specifications. The computed result will be within 1 ulp of the
1103 * exact result.
1104 *
1105 * @return the tangent of this vector
1106 */
1107 public $abstractvectortype$ tan() {
1108 return uOp((i, a) -> ($type$) Math.tan((double) a));
1109 }
1110
1111 /**
1112 * Calculates the trigonometric tangent of this vector, selecting lane
1113 * elements controlled by a mask.
1114 * <p>
1115 * Semantics for rounding, monotonicity, and special cases are
1116 * described in {@link $abstractvectortype$#tan}
1117 *
1118 * @param m the mask controlling lane selection
1119 * @return the tangent of this vector
1120 */
1121 public $abstractvectortype$ tan(Mask<$Boxtype$> m) {
1122 return uOp(m, (i, a) -> ($type$) Math.tan((double) a));
1123 }
1124
1125 /**
1126 * Calculates the hyperbolic tangent of this vector.
1127 * <p>
1128 * This is a vector unary operation with same semantic definition as
1129 * {@link Math#tanh} operation applied to lane elements.
1130 * The implementation is not required to return same
1131 * results as {@link Math#tanh}, but adheres to rounding, monotonicity,
1132 * and special case semantics as defined in the {@link Math#tanh}
1133 * specifications. The computed result will be within 2.5 ulps of the
1134 * exact result.
1135 *
1136 * @return the hyperbolic tangent of this vector
1137 */
1138 public $abstractvectortype$ tanh() {
1139 return uOp((i, a) -> ($type$) Math.tanh((double) a));
1140 }
1141
1142 /**
1143 * Calculates the hyperbolic tangent of this vector, selecting lane elements
1144 * controlled by a mask.
1145 * <p>
1146 * Semantics for rounding, monotonicity, and special cases are
1147 * described in {@link $abstractvectortype$#tanh}
1148 *
1149 * @param m the mask controlling lane selection
1150 * @return the hyperbolic tangent of this vector
1151 */
1152 public $abstractvectortype$ tanh(Mask<$Boxtype$> m) {
1153 return uOp(m, (i, a) -> ($type$) Math.tanh((double) a));
1154 }
1155
1156 /**
1157 * Calculates the trigonometric sine of this vector.
1158 * <p>
1159 * This is a vector unary operation with same semantic definition as
1160 * {@link Math#sin} operation applied to lane elements.
1161 * The implementation is not required to return same
1162 * results as {@link Math#sin}, but adheres to rounding, monotonicity,
1163 * and special case semantics as defined in the {@link Math#sin}
1164 * specifications. The computed result will be within 1 ulp of the
1165 * exact result.
1166 *
1167 * @return the sine of this vector
1168 */
1169 public $abstractvectortype$ sin() {
1170 return uOp((i, a) -> ($type$) Math.sin((double) a));
1171 }
1172
1173 /**
1174 * Calculates the trigonometric sine of this vector, selecting lane elements
1175 * controlled by a mask.
1176 * <p>
1177 * Semantics for rounding, monotonicity, and special cases are
1178 * described in {@link $abstractvectortype$#sin}
1179 *
1180 * @param m the mask controlling lane selection
1181 * @return the sine of this vector
1182 */
1183 public $abstractvectortype$ sin(Mask<$Boxtype$> m) {
1184 return uOp(m, (i, a) -> ($type$) Math.sin((double) a));
1185 }
1186
1187 /**
1188 * Calculates the hyperbolic sine of this vector.
1189 * <p>
1190 * This is a vector unary operation with same semantic definition as
1191 * {@link Math#sinh} operation applied to lane elements.
1192 * The implementation is not required to return same
1193 * results as {@link Math#sinh}, but adheres to rounding, monotonicity,
1194 * and special case semantics as defined in the {@link Math#sinh}
1195 * specifications. The computed result will be within 2.5 ulps of the
1196 * exact result.
1197 *
1198 * @return the hyperbolic sine of this vector
1199 */
1200 public $abstractvectortype$ sinh() {
1201 return uOp((i, a) -> ($type$) Math.sinh((double) a));
1202 }
1203
1204 /**
1205 * Calculates the hyperbolic sine of this vector, selecting lane elements
1206 * controlled by a mask.
1207 * <p>
1208 * Semantics for rounding, monotonicity, and special cases are
1209 * described in {@link $abstractvectortype$#sinh}
1210 *
1211 * @param m the mask controlling lane selection
1212 * @return the hyperbolic sine of this vector
1213 */
1214 public $abstractvectortype$ sinh(Mask<$Boxtype$> m) {
1215 return uOp(m, (i, a) -> ($type$) Math.sinh((double) a));
1216 }
1217
1218 /**
1219 * Calculates the trigonometric cosine of this vector.
1220 * <p>
1221 * This is a vector unary operation with same semantic definition as
1222 * {@link Math#cos} operation applied to lane elements.
1223 * The implementation is not required to return same
1224 * results as {@link Math#cos}, but adheres to rounding, monotonicity,
1225 * and special case semantics as defined in the {@link Math#cos}
1226 * specifications. The computed result will be within 1 ulp of the
1227 * exact result.
1228 *
1229 * @return the cosine of this vector
1230 */
1231 public $abstractvectortype$ cos() {
1232 return uOp((i, a) -> ($type$) Math.cos((double) a));
1233 }
1234
1235 /**
1236 * Calculates the trigonometric cosine of this vector, selecting lane
1237 * elements controlled by a mask.
1238 * <p>
1239 * Semantics for rounding, monotonicity, and special cases are
1240 * described in {@link $abstractvectortype$#cos}
1241 *
1242 * @param m the mask controlling lane selection
1243 * @return the cosine of this vector
1244 */
1245 public $abstractvectortype$ cos(Mask<$Boxtype$> m) {
1246 return uOp(m, (i, a) -> ($type$) Math.cos((double) a));
1247 }
1248
1249 /**
1250 * Calculates the hyperbolic cosine of this vector.
1251 * <p>
1252 * This is a vector unary operation with same semantic definition as
1253 * {@link Math#cosh} operation applied to lane elements.
1254 * The implementation is not required to return same
1255 * results as {@link Math#cosh}, but adheres to rounding, monotonicity,
1256 * and special case semantics as defined in the {@link Math#cosh}
1257 * specifications. The computed result will be within 2.5 ulps of the
1258 * exact result.
1259 *
1260 * @return the hyperbolic cosine of this vector
1261 */
1262 public $abstractvectortype$ cosh() {
1263 return uOp((i, a) -> ($type$) Math.cosh((double) a));
1264 }
1265
1266 /**
1267 * Calculates the hyperbolic cosine of this vector, selecting lane elements
1268 * controlled by a mask.
1269 * <p>
1270 * Semantics for rounding, monotonicity, and special cases are
1271 * described in {@link $abstractvectortype$#cosh}
1272 *
1273 * @param m the mask controlling lane selection
1274 * @return the hyperbolic cosine of this vector
1275 */
1276 public $abstractvectortype$ cosh(Mask<$Boxtype$> m) {
1277 return uOp(m, (i, a) -> ($type$) Math.cosh((double) a));
1278 }
1279
1280 /**
1281 * Calculates the arc sine of this vector.
1282 * <p>
1283 * This is a vector unary operation with same semantic definition as
1284 * {@link Math#asin} operation applied to lane elements.
1285 * The implementation is not required to return same
1286 * results as {@link Math#asin}, but adheres to rounding, monotonicity,
1287 * and special case semantics as defined in the {@link Math#asin}
1288 * specifications. The computed result will be within 1 ulp of the
1289 * exact result.
1290 *
1291 * @return the arc sine of this vector
1292 */
1293 public $abstractvectortype$ asin() {
1294 return uOp((i, a) -> ($type$) Math.asin((double) a));
1295 }
1296
1297 /**
1298 * Calculates the arc sine of this vector, selecting lane elements
1299 * controlled by a mask.
1300 * <p>
1301 * Semantics for rounding, monotonicity, and special cases are
1302 * described in {@link $abstractvectortype$#asin}
1303 *
1304 * @param m the mask controlling lane selection
1305 * @return the arc sine of this vector
1306 */
1307 public $abstractvectortype$ asin(Mask<$Boxtype$> m) {
1308 return uOp(m, (i, a) -> ($type$) Math.asin((double) a));
1309 }
1310
1311 /**
1312 * Calculates the arc cosine of this vector.
1313 * <p>
1314 * This is a vector unary operation with same semantic definition as
1315 * {@link Math#acos} operation applied to lane elements.
1316 * The implementation is not required to return same
1317 * results as {@link Math#acos}, but adheres to rounding, monotonicity,
1318 * and special case semantics as defined in the {@link Math#acos}
1319 * specifications. The computed result will be within 1 ulp of the
1320 * exact result.
1321 *
1322 * @return the arc cosine of this vector
1323 */
1324 public $abstractvectortype$ acos() {
1325 return uOp((i, a) -> ($type$) Math.acos((double) a));
1326 }
1327
1328 /**
1329 * Calculates the arc cosine of this vector, selecting lane elements
1330 * controlled by a mask.
1331 * <p>
1332 * Semantics for rounding, monotonicity, and special cases are
1333 * described in {@link $abstractvectortype$#acos}
1334 *
1335 * @param m the mask controlling lane selection
1336 * @return the arc cosine of this vector
1337 */
1338 public $abstractvectortype$ acos(Mask<$Boxtype$> m) {
1339 return uOp(m, (i, a) -> ($type$) Math.acos((double) a));
1340 }
1341
1342 /**
1343 * Calculates the arc tangent of this vector.
1344 * <p>
1345 * This is a vector unary operation with same semantic definition as
1346 * {@link Math#atan} operation applied to lane elements.
1347 * The implementation is not required to return same
1348 * results as {@link Math#atan}, but adheres to rounding, monotonicity,
1349 * and special case semantics as defined in the {@link Math#atan}
1350 * specifications. The computed result will be within 1 ulp of the
1351 * exact result.
1352 *
1353 * @return the arc tangent of this vector
1354 */
1355 public $abstractvectortype$ atan() {
1356 return uOp((i, a) -> ($type$) Math.atan((double) a));
1357 }
1358
1359 /**
1360 * Calculates the arc tangent of this vector, selecting lane elements
1361 * controlled by a mask.
1362 * <p>
1363 * Semantics for rounding, monotonicity, and special cases are
1364 * described in {@link $abstractvectortype$#atan}
1365 *
1366 * @param m the mask controlling lane selection
1367 * @return the arc tangent of this vector
1368 */
1369 public $abstractvectortype$ atan(Mask<$Boxtype$> m) {
1370 return uOp(m, (i, a) -> ($type$) Math.atan((double) a));
1371 }
1372
1373 /**
1374 * Calculates the arc tangent of this vector divided by an input vector.
1375 * <p>
1376 * This is a vector binary operation with same semantic definition as
1377 * {@link Math#atan2} operation applied to lane elements.
1378 * The implementation is not required to return same
1379 * results as {@link Math#atan2}, but adheres to rounding, monotonicity,
1380 * and special case semantics as defined in the {@link Math#atan2}
1381 * specifications. The computed result will be within 2 ulps of the
1382 * exact result.
1383 *
1384 * @param v the input vector
1385 * @return the arc tangent of this vector divided by the input vector
1386 */
1387 public $abstractvectortype$ atan2(Vector<$Boxtype$> v) {
1388 return bOp(v, (i, a, b) -> ($type$) Math.atan2((double) a, (double) b));
1389 }
1399 * and special case semantics as defined in the {@link Math#atan2}
1400 * specifications. The computed result will be within 1 ulp of the
1401 * exact result.
1402 *
1403 * @param s the input scalar
1404 * @return the arc tangent of this vector over the input vector
1405 */
1406 public abstract $abstractvectortype$ atan2($type$ s);
1407
1408 /**
1409 * Calculates the arc tangent of this vector divided by an input vector,
1410 * selecting lane elements controlled by a mask.
1411 * <p>
1412 * Semantics for rounding, monotonicity, and special cases are
1413 * described in {@link $abstractvectortype$#atan2}
1414 *
1415 * @param v the input vector
1416 * @param m the mask controlling lane selection
1417 * @return the arc tangent of this vector divided by the input vector
1418 */
1419 public $abstractvectortype$ atan2(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
1420 return bOp(v, m, (i, a, b) -> ($type$) Math.atan2((double) a, (double) b));
1421 }
1422
1423 /**
1424 * Calculates the arc tangent of this vector divided by the broadcast of an
1425 * an input scalar, selecting lane elements controlled by a mask.
1426 * <p>
1427 * Semantics for rounding, monotonicity, and special cases are
1428 * described in {@link $abstractvectortype$#atan2}
1429 *
1430 * @param s the input scalar
1431 * @param m the mask controlling lane selection
1432 * @return the arc tangent of this vector over the input vector
1433 */
1434 public abstract $abstractvectortype$ atan2($type$ s, Mask<$Boxtype$> m);
1435
1436 /**
1437 * Calculates the cube root of this vector.
1438 * <p>
1439 * This is a vector unary operation with same semantic definition as
1440 * {@link Math#cbrt} operation applied to lane elements.
1441 * The implementation is not required to return same
1442 * results as {@link Math#cbrt}, but adheres to rounding, monotonicity,
1443 * and special case semantics as defined in the {@link Math#cbrt}
1444 * specifications. The computed result will be within 1 ulp of the
1445 * exact result.
1446 *
1447 * @return the cube root of this vector
1448 */
1449 public $abstractvectortype$ cbrt() {
1450 return uOp((i, a) -> ($type$) Math.cbrt((double) a));
1451 }
1452
1453 /**
1454 * Calculates the cube root of this vector, selecting lane elements
1455 * controlled by a mask.
1456 * <p>
1457 * Semantics for rounding, monotonicity, and special cases are
1458 * described in {@link $abstractvectortype$#cbrt}
1459 *
1460 * @param m the mask controlling lane selection
1461 * @return the cube root of this vector
1462 */
1463 public $abstractvectortype$ cbrt(Mask<$Boxtype$> m) {
1464 return uOp(m, (i, a) -> ($type$) Math.cbrt((double) a));
1465 }
1466
1467 /**
1468 * Calculates the natural logarithm of this vector.
1469 * <p>
1470 * This is a vector unary operation with same semantic definition as
1471 * {@link Math#log} operation applied to lane elements.
1472 * The implementation is not required to return same
1473 * results as {@link Math#log}, but adheres to rounding, monotonicity,
1474 * and special case semantics as defined in the {@link Math#log}
1475 * specifications. The computed result will be within 1 ulp of the
1476 * exact result.
1477 *
1478 * @return the natural logarithm of this vector
1479 */
1480 public $abstractvectortype$ log() {
1481 return uOp((i, a) -> ($type$) Math.log((double) a));
1482 }
1483
1484 /**
1485 * Calculates the natural logarithm of this vector, selecting lane elements
1486 * controlled by a mask.
1487 * <p>
1488 * Semantics for rounding, monotonicity, and special cases are
1489 * described in {@link $abstractvectortype$#log}
1490 *
1491 * @param m the mask controlling lane selection
1492 * @return the natural logarithm of this vector
1493 */
1494 public $abstractvectortype$ log(Mask<$Boxtype$> m) {
1495 return uOp(m, (i, a) -> ($type$) Math.log((double) a));
1496 }
1497
1498 /**
1499 * Calculates the base 10 logarithm of this vector.
1500 * <p>
1501 * This is a vector unary operation with same semantic definition as
1502 * {@link Math#log10} operation applied to lane elements.
1503 * The implementation is not required to return same
1504 * results as {@link Math#log10}, but adheres to rounding, monotonicity,
1505 * and special case semantics as defined in the {@link Math#log10}
1506 * specifications. The computed result will be within 1 ulp of the
1507 * exact result.
1508 *
1509 * @return the base 10 logarithm of this vector
1510 */
1511 public $abstractvectortype$ log10() {
1512 return uOp((i, a) -> ($type$) Math.log10((double) a));
1513 }
1514
1515 /**
1516 * Calculates the base 10 logarithm of this vector, selecting lane elements
1517 * controlled by a mask.
1518 * <p>
1519 * Semantics for rounding, monotonicity, and special cases are
1520 * described in {@link $abstractvectortype$#log10}
1521 *
1522 * @param m the mask controlling lane selection
1523 * @return the base 10 logarithm of this vector
1524 */
1525 public $abstractvectortype$ log10(Mask<$Boxtype$> m) {
1526 return uOp(m, (i, a) -> ($type$) Math.log10((double) a));
1527 }
1528
1529 /**
1530 * Calculates the natural logarithm of the sum of this vector and the
1531 * broadcast of {@code 1}.
1532 * <p>
1533 * This is a vector unary operation with same semantic definition as
1534 * {@link Math#log1p} operation applied to lane elements.
1535 * The implementation is not required to return same
1536 * results as {@link Math#log1p}, but adheres to rounding, monotonicity,
1537 * and special case semantics as defined in the {@link Math#log1p}
1538 * specifications. The computed result will be within 1 ulp of the
1539 * exact result.
1540 *
1541 * @return the natural logarithm of the sum of this vector and the broadcast
1542 * of {@code 1}
1543 */
1544 public $abstractvectortype$ log1p() {
1545 return uOp((i, a) -> ($type$) Math.log1p((double) a));
1546 }
1547
1548 /**
1549 * Calculates the natural logarithm of the sum of this vector and the
1550 * broadcast of {@code 1}, selecting lane elements controlled by a mask.
1551 * <p>
1552 * Semantics for rounding, monotonicity, and special cases are
1553 * described in {@link $abstractvectortype$#log1p}
1554 *
1555 * @param m the mask controlling lane selection
1556 * @return the natural logarithm of the sum of this vector and the broadcast
1557 * of {@code 1}
1558 */
1559 public $abstractvectortype$ log1p(Mask<$Boxtype$> m) {
1560 return uOp(m, (i, a) -> ($type$) Math.log1p((double) a));
1561 }
1562
1563 /**
1564 * Calculates this vector raised to the power of an input vector.
1565 * <p>
1566 * This is a vector binary operation with same semantic definition as
1567 * {@link Math#pow} operation applied to lane elements.
1568 * The implementation is not required to return same
1569 * results as {@link Math#pow}, but adheres to rounding, monotonicity,
1570 * and special case semantics as defined in the {@link Math#pow}
1571 * specifications. The computed result will be within 1 ulp of the
1572 * exact result.
1573 *
1574 * @param v the input vector
1575 * @return this vector raised to the power of an input vector
1576 */
1577 public $abstractvectortype$ pow(Vector<$Boxtype$> v) {
1578 return bOp(v, (i, a, b) -> ($type$) Math.pow((double) a, (double) b));
1579 }
1590 * specifications. The computed result will be within 1 ulp of the
1591 * exact result.
1592 *
1593 * @param s the input scalar
1594 * @return this vector raised to the power of the broadcast of an input
1595 * scalar.
1596 */
1597 public abstract $abstractvectortype$ pow($type$ s);
1598
1599 /**
1600 * Calculates this vector raised to the power of an input vector, selecting
1601 * lane elements controlled by a mask.
1602 * <p>
1603 * Semantics for rounding, monotonicity, and special cases are
1604 * described in {@link $abstractvectortype$#pow}
1605 *
1606 * @param v the input vector
1607 * @param m the mask controlling lane selection
1608 * @return this vector raised to the power of an input vector
1609 */
1610 public $abstractvectortype$ pow(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
1611 return bOp(v, m, (i, a, b) -> ($type$) Math.pow((double) a, (double) b));
1612 }
1613
1614 /**
1615 * Calculates this vector raised to the power of the broadcast of an input
1616 * scalar, selecting lane elements controlled by a mask.
1617 * <p>
1618 * Semantics for rounding, monotonicity, and special cases are
1619 * described in {@link $abstractvectortype$#pow}
1620 *
1621 * @param s the input scalar
1622 * @param m the mask controlling lane selection
1623 * @return this vector raised to the power of the broadcast of an input
1624 * scalar.
1625 */
1626 public abstract $abstractvectortype$ pow($type$ s, Mask<$Boxtype$> m);
1627
1628 /**
1629 * Calculates the broadcast of Euler's number {@code e} raised to the power
1630 * of this vector.
1631 * <p>
1632 * This is a vector unary operation with same semantic definition as
1633 * {@link Math#exp} operation applied to lane elements.
1634 * The implementation is not required to return same
1635 * results as {@link Math#exp}, but adheres to rounding, monotonicity,
1636 * and special case semantics as defined in the {@link Math#exp}
1637 * specifications. The computed result will be within 1 ulp of the
1638 * exact result.
1639 *
1640 * @return the broadcast of Euler's number {@code e} raised to the power of
1641 * this vector
1642 */
1643 public $abstractvectortype$ exp() {
1644 return uOp((i, a) -> ($type$) Math.exp((double) a));
1645 }
1646
1647 /**
1648 * Calculates the broadcast of Euler's number {@code e} raised to the power
1649 * of this vector, selecting lane elements controlled by a mask.
1650 * <p>
1651 * Semantics for rounding, monotonicity, and special cases are
1652 * described in {@link $abstractvectortype$#exp}
1653 *
1654 * @param m the mask controlling lane selection
1655 * @return the broadcast of Euler's number {@code e} raised to the power of
1656 * this vector
1657 */
1658 public $abstractvectortype$ exp(Mask<$Boxtype$> m) {
1659 return uOp(m, (i, a) -> ($type$) Math.exp((double) a));
1660 }
1661
1662 /**
1663 * Calculates the broadcast of Euler's number {@code e} raised to the power
1664 * of this vector minus the broadcast of {@code -1}.
1665 * More specifically as if the following (ignoring any differences in
1666 * numerical accuracy):
1667 * <pre>{@code
1668 * this.exp().sub(this.species().broadcast(1))
1669 * }</pre>
1670 * <p>
1671 * This is a vector unary operation with same semantic definition as
1672 * {@link Math#expm1} operation applied to lane elements.
1673 * The implementation is not required to return same
1674 * results as {@link Math#expm1}, but adheres to rounding, monotonicity,
1675 * and special case semantics as defined in the {@link Math#expm1}
1676 * specifications. The computed result will be within 1 ulp of the
1677 * exact result.
1678 *
1683 return uOp((i, a) -> ($type$) Math.expm1((double) a));
1684 }
1685
1686 /**
1687 * Calculates the broadcast of Euler's number {@code e} raised to the power
1688 * of this vector minus the broadcast of {@code -1}, selecting lane elements
1689 * controlled by a mask
1690 * More specifically as if the following (ignoring any differences in
1691 * numerical accuracy):
1692 * <pre>{@code
1693 * this.exp(m).sub(this.species().broadcast(1), m)
1694 * }</pre>
1695 * <p>
1696 * Semantics for rounding, monotonicity, and special cases are
1697 * described in {@link $abstractvectortype$#expm1}
1698 *
1699 * @param m the mask controlling lane selection
1700 * @return the broadcast of Euler's number {@code e} raised to the power of
1701 * this vector minus the broadcast of {@code -1}
1702 */
1703 public $abstractvectortype$ expm1(Mask<$Boxtype$> m) {
1704 return uOp(m, (i, a) -> ($type$) Math.expm1((double) a));
1705 }
1706
1707 /**
1708 * Calculates the product of this vector and a first input vector summed
1709 * with a second input vector.
1710 * More specifically as if the following (ignoring any differences in
1711 * numerical accuracy):
1712 * <pre>{@code
1713 * this.mul(v1).add(v2)
1714 * }</pre>
1715 * <p>
1716 * This is a vector ternary operation where the {@link Math#fma} operation
1717 * is applied to lane elements.
1718 *
1719 * @param v1 the first input vector
1720 * @param v2 the second input vector
1721 * @return the product of this vector and the first input vector summed with
1722 * the second input vector
1723 */
1742 public abstract $abstractvectortype$ fma($type$ s1, $type$ s2);
1743
1744 /**
1745 * Calculates the product of this vector and a first input vector summed
1746 * with a second input vector, selecting lane elements controlled by a mask.
1747 * More specifically as if the following (ignoring any differences in
1748 * numerical accuracy):
1749 * <pre>{@code
1750 * this.mul(v1, m).add(v2, m)
1751 * }</pre>
1752 * <p>
1753 * This is a vector ternary operation where the {@link Math#fma} operation
1754 * is applied to lane elements.
1755 *
1756 * @param v1 the first input vector
1757 * @param v2 the second input vector
1758 * @param m the mask controlling lane selection
1759 * @return the product of this vector and the first input vector summed with
1760 * the second input vector
1761 */
1762 public $abstractvectortype$ fma(Vector<$Boxtype$> v1, Vector<$Boxtype$> v2, Mask<$Boxtype$> m) {
1763 return tOp(v1, v2, m, (i, a, b, c) -> Math.fma(a, b, c));
1764 }
1765
1766 /**
1767 * Calculates the product of this vector and the broadcast of a first input
1768 * scalar summed with the broadcast of a second input scalar, selecting lane
1769 * elements controlled by a mask
1770 * More specifically as if the following:
1771 * <pre>{@code
1772 * this.fma(this.species().broadcast(s1), this.species().broadcast(s2), m)
1773 * }</pre>
1774 * <p>
1775 * This is a vector ternary operation where the {@link Math#fma} operation
1776 * is applied to lane elements.
1777 *
1778 * @param s1 the first input scalar
1779 * @param s2 the second input scalar
1780 * @param m the mask controlling lane selection
1781 * @return the product of this vector and the broadcast of a first input
1782 * scalar summed with the broadcast of a second input scalar
1783 */
1784 public abstract $abstractvectortype$ fma($type$ s1, $type$ s2, Mask<$Boxtype$> m);
1785
1786 /**
1787 * Calculates square root of the sum of the squares of this vector and an
1788 * input vector.
1789 * More specifically as if the following (ignoring any differences in
1790 * numerical accuracy):
1791 * <pre>{@code
1792 * this.mul(this).add(v.mul(v)).sqrt()
1793 * }</pre>
1794 * <p>
1795 * This is a vector binary operation with same semantic definition as
1796 * {@link Math#hypot} operation applied to lane elements.
1797 * The implementation is not required to return same
1798 * results as {@link Math#hypot}, but adheres to rounding, monotonicity,
1799 * and special case semantics as defined in the {@link Math#hypot}
1800 * specifications. The computed result will be within 1 ulp of the
1801 * exact result.
1802 *
1803 * @param v the input vector
1804 * @return square root of the sum of the squares of this vector and an input
1831 */
1832 public abstract $abstractvectortype$ hypot($type$ s);
1833
1834 /**
1835 * Calculates square root of the sum of the squares of this vector and an
1836 * input vector, selecting lane elements controlled by a mask.
1837 * More specifically as if the following (ignoring any differences in
1838 * numerical accuracy):
1839 * <pre>{@code
1840 * this.mul(this, m).add(v.mul(v), m).sqrt(m)
1841 * }</pre>
1842 * <p>
1843 * Semantics for rounding, monotonicity, and special cases are
1844 * described in {@link $abstractvectortype$#hypot}
1845 *
1846 * @param v the input vector
1847 * @param m the mask controlling lane selection
1848 * @return square root of the sum of the squares of this vector and an input
1849 * vector
1850 */
1851 public $abstractvectortype$ hypot(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
1852 return bOp(v, m, (i, a, b) -> ($type$) Math.hypot((double) a, (double) b));
1853 }
1854
1855 /**
1856 * Calculates square root of the sum of the squares of this vector and the
1857 * broadcast of an input scalar, selecting lane elements controlled by a
1858 * mask.
1859 * More specifically as if the following (ignoring any differences in
1860 * numerical accuracy):
1861 * <pre>{@code
1862 * this.mul(this, m).add(this.species().broadcast(v * v), m).sqrt(m)
1863 * }</pre>
1864 * <p>
1865 * Semantics for rounding, monotonicity, and special cases are
1866 * described in {@link $abstractvectortype$#hypot}
1867 *
1868 * @param s the input scalar
1869 * @param m the mask controlling lane selection
1870 * @return square root of the sum of the squares of this vector and the
1871 * broadcast of an input scalar
1872 */
1873 public abstract $abstractvectortype$ hypot($type$ s, Mask<$Boxtype$> m);
1874 #end[FP]
1875
1876 #if[BITWISE]
1877
1878 /**
1879 * Bitwise ANDs this vector with an input vector.
1880 * <p>
1881 * This is a vector binary operation where the primitive bitwise AND
1882 * operation ({@code &}) is applied to lane elements.
1883 *
1884 * @param v the input vector
1885 * @return the bitwise AND of this vector with the input vector
1886 */
1887 public abstract $abstractvectortype$ and(Vector<$Boxtype$> v);
1888
1889 /**
1890 * Bitwise ANDs this vector with the broadcast of an input scalar.
1891 * <p>
1892 * This is a vector binary operation where the primitive bitwise AND
1893 * operation ({@code &}) is applied to lane elements.
1894 *
1895 * @param s the input scalar
1896 * @return the bitwise AND of this vector with the broadcast of an input
1897 * scalar
1898 */
1899 public abstract $abstractvectortype$ and($type$ s);
1900
1901 /**
1902 * Bitwise ANDs this vector with an input vector, selecting lane elements
1903 * controlled by a mask.
1904 * <p>
1905 * This is a vector binary operation where the primitive bitwise AND
1906 * operation ({@code &}) is applied to lane elements.
1907 *
1908 * @param v the input vector
1909 * @param m the mask controlling lane selection
1910 * @return the bitwise AND of this vector with the input vector
1911 */
1912 public abstract $abstractvectortype$ and(Vector<$Boxtype$> v, Mask<$Boxtype$> m);
1913
1914 /**
1915 * Bitwise ANDs this vector with the broadcast of an input scalar, selecting
1916 * lane elements controlled by a mask.
1917 * <p>
1918 * This is a vector binary operation where the primitive bitwise AND
1919 * operation ({@code &}) is applied to lane elements.
1920 *
1921 * @param s the input scalar
1922 * @param m the mask controlling lane selection
1923 * @return the bitwise AND of this vector with the broadcast of an input
1924 * scalar
1925 */
1926 public abstract $abstractvectortype$ and($type$ s, Mask<$Boxtype$> m);
1927
1928 /**
1929 * Bitwise ORs this vector with an input vector.
1930 * <p>
1931 * This is a vector binary operation where the primitive bitwise OR
1932 * operation ({@code |}) is applied to lane elements.
1933 *
1934 * @param v the input vector
1935 * @return the bitwise OR of this vector with the input vector
1936 */
1937 public abstract $abstractvectortype$ or(Vector<$Boxtype$> v);
1938
1939 /**
1940 * Bitwise ORs this vector with the broadcast of an input scalar.
1941 * <p>
1942 * This is a vector binary operation where the primitive bitwise OR
1943 * operation ({@code |}) is applied to lane elements.
1944 *
1945 * @param s the input scalar
1946 * @return the bitwise OR of this vector with the broadcast of an input
1947 * scalar
1948 */
1949 public abstract $abstractvectortype$ or($type$ s);
1950
1951 /**
1952 * Bitwise ORs this vector with an input vector, selecting lane elements
1953 * controlled by a mask.
1954 * <p>
1955 * This is a vector binary operation where the primitive bitwise OR
1956 * operation ({@code |}) is applied to lane elements.
1957 *
1958 * @param v the input vector
1959 * @param m the mask controlling lane selection
1960 * @return the bitwise OR of this vector with the input vector
1961 */
1962 public abstract $abstractvectortype$ or(Vector<$Boxtype$> v, Mask<$Boxtype$> m);
1963
1964 /**
1965 * Bitwise ORs this vector with the broadcast of an input scalar, selecting
1966 * lane elements controlled by a mask.
1967 * <p>
1968 * This is a vector binary operation where the primitive bitwise OR
1969 * operation ({@code |}) is applied to lane elements.
1970 *
1971 * @param s the input scalar
1972 * @param m the mask controlling lane selection
1973 * @return the bitwise OR of this vector with the broadcast of an input
1974 * scalar
1975 */
1976 public abstract $abstractvectortype$ or($type$ s, Mask<$Boxtype$> m);
1977
1978 /**
1979 * Bitwise XORs this vector with an input vector.
1980 * <p>
1981 * This is a vector binary operation where the primitive bitwise XOR
1982 * operation ({@code ^}) is applied to lane elements.
1983 *
1984 * @param v the input vector
1985 * @return the bitwise XOR of this vector with the input vector
1986 */
1987 public abstract $abstractvectortype$ xor(Vector<$Boxtype$> v);
1988
1989 /**
1990 * Bitwise XORs this vector with the broadcast of an input scalar.
1991 * <p>
1992 * This is a vector binary operation where the primitive bitwise XOR
1993 * operation ({@code ^}) is applied to lane elements.
1994 *
1995 * @param s the input scalar
1996 * @return the bitwise XOR of this vector with the broadcast of an input
1997 * scalar
1998 */
1999 public abstract $abstractvectortype$ xor($type$ s);
2000
2001 /**
2002 * Bitwise XORs this vector with an input vector, selecting lane elements
2003 * controlled by a mask.
2004 * <p>
2005 * This is a vector binary operation where the primitive bitwise XOR
2006 * operation ({@code ^}) is applied to lane elements.
2007 *
2008 * @param v the input vector
2009 * @param m the mask controlling lane selection
2010 * @return the bitwise XOR of this vector with the input vector
2011 */
2012 public abstract $abstractvectortype$ xor(Vector<$Boxtype$> v, Mask<$Boxtype$> m);
2013
2014 /**
2015 * Bitwise XORs this vector with the broadcast of an input scalar, selecting
2016 * lane elements controlled by a mask.
2017 * <p>
2018 * This is a vector binary operation where the primitive bitwise XOR
2019 * operation ({@code ^}) is applied to lane elements.
2020 *
2021 * @param s the input scalar
2022 * @param m the mask controlling lane selection
2023 * @return the bitwise XOR of this vector with the broadcast of an input
2024 * scalar
2025 */
2026 public abstract $abstractvectortype$ xor($type$ s, Mask<$Boxtype$> m);
2027
2028 /**
2029 * Bitwise NOTs this vector.
2030 * <p>
2031 * This is a vector unary operation where the primitive bitwise NOT
2032 * operation ({@code ~}) is applied to lane elements.
2033 *
2034 * @return the bitwise NOT of this vector
2035 */
2036 public abstract $abstractvectortype$ not();
2037
2038 /**
2039 * Bitwise NOTs this vector, selecting lane elements controlled by a mask.
2040 * <p>
2041 * This is a vector unary operation where the primitive bitwise NOT
2042 * operation ({@code ~}) is applied to lane elements.
2043 *
2044 * @param m the mask controlling lane selection
2045 * @return the bitwise NOT of this vector
2046 */
2047 public abstract $abstractvectortype$ not(Mask<$Boxtype$> m);
2048
2049 #if[byte]
2050 /**
2051 * Logically left shifts this vector by the broadcast of an input scalar.
2052 * <p>
2053 * This is a vector binary operation where the primitive logical left shift
2054 * operation ({@code <<}) is applied to lane elements to left shift the
2055 * element by shift value as specified by the input scalar. Only the 3
2056 * lowest-order bits of shift value are used. It is as if the shift value
2057 * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0x7.
2058 * The shift distance actually used is therefore always in the range 0 to 7, inclusive.
2059 *
2060 * @param s the input scalar; the number of the bits to left shift
2061 * @return the result of logically left shifting left this vector by the
2062 * broadcast of an input scalar
2063 */
2064 #end[byte]
2065 #if[short]
2066 /**
2067 * Logically left shifts this vector by the broadcast of an input scalar.
2125 * @param s the input scalar; the number of the bits to left shift
2126 * @param m the mask controlling lane selection
2127 * @return the result of logically left shifting left this vector by the
2128 * broadcast of an input scalar
2129 */
2130 #end[short]
2131 #if[intOrLong]
2132 /**
2133 * Logically left shifts this vector by the broadcast of an input scalar,
2134 * selecting lane elements controlled by a mask.
2135 * <p>
2136 * This is a vector binary operation where the primitive logical left shift
2137 * operation ({@code <<}) is applied to lane elements.
2138 *
2139 * @param s the input scalar; the number of the bits to left shift
2140 * @param m the mask controlling lane selection
2141 * @return the result of logically left shifting this vector by the
2142 * broadcast of an input scalar
2143 */
2144 #end[intOrLong]
2145 public abstract $abstractvectortype$ shiftL(int s, Mask<$Boxtype$> m);
2146
2147 #if[intOrLong]
2148 /**
2149 * Logically left shifts this vector by an input vector.
2150 * <p>
2151 * This is a vector binary operation where the primitive logical left shift
2152 * operation ({@code <<}) is applied to lane elements.
2153 *
2154 * @param v the input vector
2155 * @return the result of logically left shifting this vector by the input
2156 * vector
2157 */
2158 public abstract $abstractvectortype$ shiftL(Vector<$Boxtype$> v);
2159
2160 /**
2161 * Logically left shifts this vector by an input vector, selecting lane
2162 * elements controlled by a mask.
2163 * <p>
2164 * This is a vector binary operation where the primitive logical left shift
2165 * operation ({@code <<}) is applied to lane elements.
2166 *
2167 * @param v the input vector
2168 * @param m the mask controlling lane selection
2169 * @return the result of logically left shifting this vector by the input
2170 * vector
2171 */
2172 public $abstractvectortype$ shiftL(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
2173 return bOp(v, m, (i, a, b) -> ($type$) (a << b));
2174 }
2175 #end[intOrLong]
2176
2177 // logical, or unsigned, shift right
2178
2179 #if[byte]
2180 /**
2181 * Logically right shifts (or unsigned right shifts) this vector by the
2182 * broadcast of an input scalar.
2183 * <p>
2184 * This is a vector binary operation where the primitive logical right shift
2185 * operation ({@code >>>}) is applied to lane elements to logically right shift the
2186 * element by shift value as specified by the input scalar. Only the 3
2187 * lowest-order bits of shift value are used. It is as if the shift value
2188 * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0x7.
2189 * The shift distance actually used is therefore always in the range 0 to 7, inclusive.
2190 *
2191 * @param s the input scalar; the number of the bits to right shift
2192 * @return the result of logically right shifting this vector by the
2261 * @param m the mask controlling lane selection
2262 * @return the result of logically right shifting this vector by the
2263 * broadcast of an input scalar
2264 */
2265 #end[short]
2266 #if[intOrLong]
2267 /**
2268 * Logically right shifts (or unsigned right shifts) this vector by the
2269 * broadcast of an input scalar, selecting lane elements controlled by a
2270 * mask.
2271 * <p>
2272 * This is a vector binary operation where the primitive logical right shift
2273 * operation ({@code >>>}) is applied to lane elements.
2274 *
2275 * @param s the input scalar; the number of the bits to right shift
2276 * @param m the mask controlling lane selection
2277 * @return the result of logically right shifting this vector by the
2278 * broadcast of an input scalar
2279 */
2280 #end[intOrLong]
2281 public abstract $abstractvectortype$ shiftR(int s, Mask<$Boxtype$> m);
2282
2283 #if[intOrLong]
2284 /**
2285 * Logically right shifts (or unsigned right shifts) this vector by an
2286 * input vector.
2287 * <p>
2288 * This is a vector binary operation where the primitive logical right shift
2289 * operation ({@code >>>}) is applied to lane elements.
2290 *
2291 * @param v the input vector
2292 * @return the result of logically right shifting this vector by the
2293 * input vector
2294 */
2295 public abstract $abstractvectortype$ shiftR(Vector<$Boxtype$> v);
2296
2297 /**
2298 * Logically right shifts (or unsigned right shifts) this vector by an
2299 * input vector, selecting lane elements controlled by a mask.
2300 * <p>
2301 * This is a vector binary operation where the primitive logical right shift
2302 * operation ({@code >>>}) is applied to lane elements.
2303 *
2304 * @param v the input vector
2305 * @param m the mask controlling lane selection
2306 * @return the result of logically right shifting this vector by the
2307 * input vector
2308 */
2309 public $abstractvectortype$ shiftR(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
2310 return bOp(v, m, (i, a, b) -> ($type$) (a >>> b));
2311 }
2312 #end[intOrLong]
2313
2314 #if[byte]
2315 /**
2316 * Arithmetically right shifts (or signed right shifts) this vector by the
2317 * broadcast of an input scalar.
2318 * <p>
2319 * This is a vector binary operation where the primitive arithmetic right
2320 * shift operation ({@code >>}) is applied to lane elements to arithmetically
2321 * right shift the element by shift value as specified by the input scalar.
2322 * Only the 3 lowest-order bits of shift value are used. It is as if the shift
2323 * value were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0x7.
2324 * The shift distance actually used is therefore always in the range 0 to 7, inclusive.
2325 *
2326 * @param s the input scalar; the number of the bits to right shift
2327 * @return the result of arithmetically right shifting this vector by the
2328 * broadcast of an input scalar
2329 */
2396 * @param m the mask controlling lane selection
2397 * @return the result of arithmetically right shifting this vector by the
2398 * broadcast of an input scalar
2399 */
2400 #end[short]
2401 #if[intOrLong]
2402 /**
2403 * Arithmetically right shifts (or signed right shifts) this vector by the
2404 * broadcast of an input scalar, selecting lane elements controlled by a
2405 * mask.
2406 * <p>
2407 * This is a vector binary operation where the primitive arithmetic right
2408 * shift operation ({@code >>}) is applied to lane elements.
2409 *
2410 * @param s the input scalar; the number of the bits to right shift
2411 * @param m the mask controlling lane selection
2412 * @return the result of arithmetically right shifting this vector by the
2413 * broadcast of an input scalar
2414 */
2415 #end[intOrLong]
2416 public abstract $abstractvectortype$ aShiftR(int s, Mask<$Boxtype$> m);
2417
2418 #if[intOrLong]
2419 /**
2420 * Arithmetically right shifts (or signed right shifts) this vector by an
2421 * input vector.
2422 * <p>
2423 * This is a vector binary operation where the primitive arithmetic right
2424 * shift operation ({@code >>}) is applied to lane elements.
2425 *
2426 * @param v the input vector
2427 * @return the result of arithmetically right shifting this vector by the
2428 * input vector
2429 */
2430 public abstract $abstractvectortype$ aShiftR(Vector<$Boxtype$> v);
2431
2432 /**
2433 * Arithmetically right shifts (or signed right shifts) this vector by an
2434 * input vector, selecting lane elements controlled by a mask.
2435 * <p>
2436 * This is a vector binary operation where the primitive arithmetic right
2437 * shift operation ({@code >>}) is applied to lane elements.
2438 *
2439 * @param v the input vector
2440 * @param m the mask controlling lane selection
2441 * @return the result of arithmetically right shifting this vector by the
2442 * input vector
2443 */
2444 public $abstractvectortype$ aShiftR(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
2445 return bOp(v, m, (i, a, b) -> ($type$) (a >> b));
2446 }
2447
2448 /**
2449 * Rotates left this vector by the broadcast of an input scalar.
2450 * <p>
2451 * This is a vector binary operation where the operation
2452 * {@link $Wideboxtype$#rotateLeft} is applied to lane elements and where
2453 * lane elements of this vector apply to the first argument, and lane
2454 * elements of the broadcast vector apply to the second argument (the
2455 * rotation distance).
2456 *
2457 * @param s the input scalar; the number of the bits to rotate left
2458 * @return the result of rotating left this vector by the broadcast of an
2459 * input scalar
2460 */
2461 @ForceInline
2462 public final $abstractvectortype$ rotateL(int s) {
2463 return shiftL(s).or(shiftR(-s));
2464 }
2465
2466 /**
2467 * Rotates left this vector by the broadcast of an input scalar, selecting
2468 * lane elements controlled by a mask.
2469 * <p>
2470 * This is a vector binary operation where the operation
2471 * {@link $Wideboxtype$#rotateLeft} is applied to lane elements and where
2472 * lane elements of this vector apply to the first argument, and lane
2473 * elements of the broadcast vector apply to the second argument (the
2474 * rotation distance).
2475 *
2476 * @param s the input scalar; the number of the bits to rotate left
2477 * @param m the mask controlling lane selection
2478 * @return the result of rotating left this vector by the broadcast of an
2479 * input scalar
2480 */
2481 @ForceInline
2482 public final $abstractvectortype$ rotateL(int s, Mask<$Boxtype$> m) {
2483 return shiftL(s, m).or(shiftR(-s, m), m);
2484 }
2485
2486 /**
2487 * Rotates right this vector by the broadcast of an input scalar.
2488 * <p>
2489 * This is a vector binary operation where the operation
2490 * {@link $Wideboxtype$#rotateRight} is applied to lane elements and where
2491 * lane elements of this vector apply to the first argument, and lane
2492 * elements of the broadcast vector apply to the second argument (the
2493 * rotation distance).
2494 *
2495 * @param s the input scalar; the number of the bits to rotate right
2496 * @return the result of rotating right this vector by the broadcast of an
2497 * input scalar
2498 */
2499 @ForceInline
2500 public final $abstractvectortype$ rotateR(int s) {
2501 return shiftR(s).or(shiftL(-s));
2502 }
2503
2504 /**
2505 * Rotates right this vector by the broadcast of an input scalar, selecting
2506 * lane elements controlled by a mask.
2507 * <p>
2508 * This is a vector binary operation where the operation
2509 * {@link $Wideboxtype$#rotateRight} is applied to lane elements and where
2510 * lane elements of this vector apply to the first argument, and lane
2511 * elements of the broadcast vector apply to the second argument (the
2512 * rotation distance).
2513 *
2514 * @param s the input scalar; the number of the bits to rotate right
2515 * @param m the mask controlling lane selection
2516 * @return the result of rotating right this vector by the broadcast of an
2517 * input scalar
2518 */
2519 @ForceInline
2520 public final $abstractvectortype$ rotateR(int s, Mask<$Boxtype$> m) {
2521 return shiftR(s, m).or(shiftL(-s, m), m);
2522 }
2523 #end[intOrLong]
2524 #end[BITWISE]
2525
2526 @Override
2527 public abstract void intoByteArray(byte[] a, int ix);
2528
2529 @Override
2530 public abstract void intoByteArray(byte[] a, int ix, Mask<$Boxtype$> m);
2531
2532 @Override
2533 public abstract void intoByteBuffer(ByteBuffer bb, int ix);
2534
2535 @Override
2536 public abstract void intoByteBuffer(ByteBuffer bb, int ix, Mask<$Boxtype$> m);
2537
2538
2539 // Type specific horizontal reductions
2540 /**
2541 * Adds all lane elements of this vector.
2542 * <p>
2543 #if[FP]
2544 * This is a vector reduction operation where the addition
2545 * operation ({@code +}) is applied to lane elements,
2546 * and the identity value is {@code 0.0}.
2547 *
2548 * <p>The value of a floating-point sum is a function both of the input values as well
2549 * as the order of addition operations. The order of addition operations of this method
2550 * is intentionally not defined to allow for JVM to generate optimal machine
2551 * code for the underlying platform at runtime. If the platform supports a vector
2552 * instruction to add all values in the vector, or if there is some other efficient machine
2553 * code sequence, then the JVM has the option of generating this machine code. Otherwise,
2554 * the default implementation of adding vectors sequentially from left to right is used.
2555 * For this reason, the output of this method may vary for the same input values.
2556 #else[FP]
2572 * operation ({@code +}) is applied to lane elements,
2573 * and the identity value is {@code 0.0}.
2574 *
2575 * <p>The value of a floating-point sum is a function both of the input values as well
2576 * as the order of addition operations. The order of addition operations of this method
2577 * is intentionally not defined to allow for JVM to generate optimal machine
2578 * code for the underlying platform at runtime. If the platform supports a vector
2579 * instruction to add all values in the vector, or if there is some other efficient machine
2580 * code sequence, then the JVM has the option of generating this machine code. Otherwise,
2581 * the default implementation of adding vectors sequentially from left to right is used.
2582 * For this reason, the output of this method may vary on the same input values.
2583 #else[FP]
2584 * This is an associative vector reduction operation where the addition
2585 * operation ({@code +}) is applied to lane elements,
2586 * and the identity value is {@code 0}.
2587 #end[FP]
2588 *
2589 * @param m the mask controlling lane selection
2590 * @return the addition of the selected lane elements of this vector
2591 */
2592 public abstract $type$ addAll(Mask<$Boxtype$> m);
2593
2594 /**
2595 * Multiplies all lane elements of this vector.
2596 * <p>
2597 #if[FP]
2598 * This is a vector reduction operation where the
2599 * multiplication operation ({@code *}) is applied to lane elements,
2600 * and the identity value is {@code 1.0}.
2601 *
2602 * <p>The order of multiplication operations of this method
2603 * is intentionally not defined to allow for JVM to generate optimal machine
2604 * code for the underlying platform at runtime. If the platform supports a vector
2605 * instruction to multiply all values in the vector, or if there is some other efficient machine
2606 * code sequence, then the JVM has the option of generating this machine code. Otherwise,
2607 * the default implementation of multiplying vectors sequentially from left to right is used.
2608 * For this reason, the output of this method may vary on the same input values.
2609 #else[FP]
2610 * This is an associative vector reduction operation where the
2611 * multiplication operation ({@code *}) is applied to lane elements,
2612 * and the identity value is {@code 1}.
2624 * This is a vector reduction operation where the
2625 * multiplication operation ({@code *}) is applied to lane elements,
2626 * and the identity value is {@code 1.0}.
2627 *
2628 * <p>The order of multiplication operations of this method
2629 * is intentionally not defined to allow for JVM to generate optimal machine
2630 * code for the underlying platform at runtime. If the platform supports a vector
2631 * instruction to multiply all values in the vector, or if there is some other efficient machine
2632 * code sequence, then the JVM has the option of generating this machine code. Otherwise,
2633 * the default implementation of multiplying vectors sequentially from left to right is used.
2634 * For this reason, the output of this method may vary on the same input values.
2635 #else[FP]
2636 * This is an associative vector reduction operation where the
2637 * multiplication operation ({@code *}) is applied to lane elements,
2638 * and the identity value is {@code 1}.
2639 #end[FP]
2640 *
2641 * @param m the mask controlling lane selection
2642 * @return the multiplication of all the lane elements of this vector
2643 */
2644 public abstract $type$ mulAll(Mask<$Boxtype$> m);
2645
2646 /**
2647 * Returns the minimum lane element of this vector.
2648 * <p>
2649 * This is an associative vector reduction operation where the operation
2650 * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
2651 * and the identity value is
2652 #if[FP]
2653 * {@link $Boxtype$#POSITIVE_INFINITY}.
2654 #else[FP]
2655 * {@link $Boxtype$#MAX_VALUE}.
2656 #end[FP]
2657 *
2658 * @return the minimum lane element of this vector
2659 */
2660 public abstract $type$ minAll();
2661
2662 /**
2663 * Returns the minimum lane element of this vector, selecting lane elements
2664 * controlled by a mask.
2665 * <p>
2666 * This is an associative vector reduction operation where the operation
2667 * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
2668 * and the identity value is
2669 #if[FP]
2670 * {@link $Boxtype$#POSITIVE_INFINITY}.
2671 #else[FP]
2672 * {@link $Boxtype$#MAX_VALUE}.
2673 #end[FP]
2674 *
2675 * @param m the mask controlling lane selection
2676 * @return the minimum lane element of this vector
2677 */
2678 public abstract $type$ minAll(Mask<$Boxtype$> m);
2679
2680 /**
2681 * Returns the maximum lane element of this vector.
2682 * <p>
2683 * This is an associative vector reduction operation where the operation
2684 * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
2685 * and the identity value is
2686 #if[FP]
2687 * {@link $Boxtype$#NEGATIVE_INFINITY}.
2688 #else[FP]
2689 * {@link $Boxtype$#MIN_VALUE}.
2690 #end[FP]
2691 *
2692 * @return the maximum lane element of this vector
2693 */
2694 public abstract $type$ maxAll();
2695
2696 /**
2697 * Returns the maximum lane element of this vector, selecting lane elements
2698 * controlled by a mask.
2699 * <p>
2700 * This is an associative vector reduction operation where the operation
2701 * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
2702 * and the identity value is
2703 #if[FP]
2704 * {@link $Boxtype$#NEGATIVE_INFINITY}.
2705 #else[FP]
2706 * {@link $Boxtype$#MIN_VALUE}.
2707 #end[FP]
2708 *
2709 * @param m the mask controlling lane selection
2710 * @return the maximum lane element of this vector
2711 */
2712 public abstract $type$ maxAll(Mask<$Boxtype$> m);
2713
2714 #if[BITWISE]
2715 /**
2716 * Logically ORs all lane elements of this vector.
2717 * <p>
2718 * This is an associative vector reduction operation where the logical OR
2719 * operation ({@code |}) is applied to lane elements,
2720 * and the identity value is {@code 0}.
2721 *
2722 * @return the logical OR all the lane elements of this vector
2723 */
2724 public abstract $type$ orAll();
2725
2726 /**
2727 * Logically ORs all lane elements of this vector, selecting lane elements
2728 * controlled by a mask.
2729 * <p>
2730 * This is an associative vector reduction operation where the logical OR
2731 * operation ({@code |}) is applied to lane elements,
2732 * and the identity value is {@code 0}.
2733 *
2734 * @param m the mask controlling lane selection
2735 * @return the logical OR all the lane elements of this vector
2736 */
2737 public abstract $type$ orAll(Mask<$Boxtype$> m);
2738
2739 /**
2740 * Logically ANDs all lane elements of this vector.
2741 * <p>
2742 * This is an associative vector reduction operation where the logical AND
2743 * operation ({@code |}) is applied to lane elements,
2744 * and the identity value is {@code -1}.
2745 *
2746 * @return the logical AND all the lane elements of this vector
2747 */
2748 public abstract $type$ andAll();
2749
2750 /**
2751 * Logically ANDs all lane elements of this vector, selecting lane elements
2752 * controlled by a mask.
2753 * <p>
2754 * This is an associative vector reduction operation where the logical AND
2755 * operation ({@code |}) is applied to lane elements,
2756 * and the identity value is {@code -1}.
2757 *
2758 * @param m the mask controlling lane selection
2759 * @return the logical AND all the lane elements of this vector
2760 */
2761 public abstract $type$ andAll(Mask<$Boxtype$> m);
2762
2763 /**
2764 * Logically XORs all lane elements of this vector.
2765 * <p>
2766 * This is an associative vector reduction operation where the logical XOR
2767 * operation ({@code ^}) is applied to lane elements,
2768 * and the identity value is {@code 0}.
2769 *
2770 * @return the logical XOR all the lane elements of this vector
2771 */
2772 public abstract $type$ xorAll();
2773
2774 /**
2775 * Logically XORs all lane elements of this vector, selecting lane elements
2776 * controlled by a mask.
2777 * <p>
2778 * This is an associative vector reduction operation where the logical XOR
2779 * operation ({@code ^}) is applied to lane elements,
2780 * and the identity value is {@code 0}.
2781 *
2782 * @param m the mask controlling lane selection
2783 * @return the logical XOR all the lane elements of this vector
2784 */
2785 public abstract $type$ xorAll(Mask<$Boxtype$> m);
2786 #end[BITWISE]
2787
2788 // Type specific accessors
2789
2790 /**
2791 * Gets the lane element at lane index {@code i}
2792 *
2793 * @param i the lane index
2794 * @return the lane element at lane index {@code i}
2795 * @throws IllegalArgumentException if the index is is out of range
2796 * ({@code < 0 || >= length()})
2797 */
2798 public abstract $type$ get(int i);
2799
2800 /**
2801 * Replaces the lane element of this vector at lane index {@code i} with
2802 * value {@code e}.
2803 * <p>
2804 * This is a cross-lane operation and behaves as if it returns the result
2805 * of blending this vector with an input vector that is the result of
2848 * @param i the offset into the array
2849 * @throws IndexOutOfBoundsException if {@code i < 0}, or
2850 * {@code i > a.length - this.length()}
2851 */
2852 public abstract void intoArray($type$[] a, int i);
2853
2854 /**
2855 * Stores this vector into an array starting at offset and using a mask.
2856 * <p>
2857 * For each vector lane, where {@code N} is the vector lane index,
2858 * if the mask lane at index {@code N} is set then the lane element at
2859 * index {@code N} is stored into the array index {@code i + N}.
2860 *
2861 * @param a the array
2862 * @param i the offset into the array
2863 * @param m the mask
2864 * @throws IndexOutOfBoundsException if {@code i < 0}, or
2865 * for any vector lane index {@code N} where the mask at lane {@code N}
2866 * is set {@code i >= a.length - N}
2867 */
2868 public abstract void intoArray($type$[] a, int i, Mask<$Boxtype$> m);
2869
2870 /**
2871 * Stores this vector into an array using indexes obtained from an index
2872 * map.
2873 * <p>
2874 * For each vector lane, where {@code N} is the vector lane index, the
2875 * lane element at index {@code N} is stored into the array at index
2876 * {@code i + indexMap[j + N]}.
2877 *
2878 * @param a the array
2879 * @param i the offset into the array, may be negative if relative
2880 * indexes in the index map compensate to produce a value within the
2881 * array bounds
2882 * @param indexMap the index map
2883 * @param j the offset into the index map
2884 * @throws IndexOutOfBoundsException if {@code j < 0}, or
2885 * {@code j > indexMap.length - this.length()},
2886 * or for any vector lane index {@code N} the result of
2887 * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length}
2888 */
2900 * <p>
2901 * For each vector lane, where {@code N} is the vector lane index,
2902 * if the mask lane at index {@code N} is set then the lane element at
2903 * index {@code N} is stored into the array at index
2904 * {@code i + indexMap[j + N]}.
2905 *
2906 * @param a the array
2907 * @param i the offset into the array, may be negative if relative
2908 * indexes in the index map compensate to produce a value within the
2909 * array bounds
2910 * @param m the mask
2911 * @param indexMap the index map
2912 * @param j the offset into the index map
2913 * @throws IndexOutOfBoundsException if {@code j < 0}, or
2914 * {@code j > indexMap.length - this.length()},
2915 * or for any vector lane index {@code N} where the mask at lane
2916 * {@code N} is set the result of {@code i + indexMap[j + N]} is
2917 * {@code < 0} or {@code >= a.length}
2918 */
2919 #if[byteOrShort]
2920 public void intoArray($type$[] a, int i, Mask<$Boxtype$> m, int[] indexMap, int j) {
2921 forEach(m, (n, e) -> a[i + indexMap[j + n]] = e);
2922 }
2923 #else[byteOrShort]
2924 public abstract void intoArray($type$[] a, int i, Mask<$Boxtype$> m, int[] indexMap, int j);
2925 #end[byteOrShort]
2926 // Species
2927
2928 @Override
2929 public abstract Species<$Boxtype$> species();
2930
2931 /**
2932 * Class representing {@link $abstractvectortype$}'s of the same {@link Vector.Shape Shape}.
2933 */
2934 static final class $Type$Species extends Vector.AbstractSpecies<$Boxtype$> {
2935 final Function<$type$[], $Type$Vector> vectorFactory;
2936 final Function<boolean[], Vector.Mask<$Boxtype$>> maskFactory;
2937
2938 private $Type$Species(Vector.Shape shape,
2939 Class<?> boxType,
2940 Class<?> maskType,
2941 Function<$type$[], $Type$Vector> vectorFactory,
2942 Function<boolean[], Vector.Mask<$Boxtype$>> maskFactory) {
2943 super(shape, $type$.class, $Boxtype$.SIZE, boxType, maskType);
2944 this.vectorFactory = vectorFactory;
2945 this.maskFactory = maskFactory;
2946 }
2947
2948 interface FOp {
2949 $type$ apply(int i);
2950 }
2951
2952 interface FOpm {
2953 boolean apply(int i);
2954 }
2955
2956 $Type$Vector op(FOp f) {
2957 $type$[] res = new $type$[length()];
2958 for (int i = 0; i < length(); i++) {
2959 res[i] = f.apply(i);
2960 }
2961 return vectorFactory.apply(res);
2962 }
2963
2964 $Type$Vector op(Vector.Mask<$Boxtype$> o, FOp f) {
2965 $type$[] res = new $type$[length()];
2966 boolean[] mbits = ((AbstractMask<$Boxtype$>)o).getBits();
2967 for (int i = 0; i < length(); i++) {
2968 if (mbits[i]) {
2969 res[i] = f.apply(i);
2970 }
2971 }
2972 return vectorFactory.apply(res);
2973 }
2974
2975 Vector.Mask<$Boxtype$> opm(IntVector.IntSpecies.FOpm f) {
2976 boolean[] res = new boolean[length()];
2977 for (int i = 0; i < length(); i++) {
2978 res[i] = (boolean)f.apply(i);
2979 }
2980 return maskFactory.apply(res);
2981 }
2982 }
2983
2984 /**
2985 * Finds the preferred species for an element type of {@code $type$}.
2986 * <p>
2987 * A preferred species is a species chosen by the platform that has a
2988 * shape of maximal bit size. A preferred species for different element
2989 * types will have the same shape, and therefore vectors, masks, and
2990 * shuffles created from such species will be shape compatible.
2991 *
2992 * @return the preferred species for an element type of {@code $type$}
2993 */
2994 private static $Type$Species preferredSpecies() {
2995 return ($Type$Species) Species.ofPreferred($type$.class);
2996 }
2997
2998 /**
2999 * Finds a species for an element type of {@code $type$} and shape.
3000 *
3001 * @param s the shape
3002 * @return a species for an element type of {@code $type$} and shape
3003 * @throws IllegalArgumentException if no such species exists for the shape
3004 */
3005 static $Type$Species species(Vector.Shape s) {
3006 Objects.requireNonNull(s);
3007 switch (s) {
3008 case S_64_BIT: return ($Type$Species) SPECIES_64;
3009 case S_128_BIT: return ($Type$Species) SPECIES_128;
3010 case S_256_BIT: return ($Type$Species) SPECIES_256;
3011 case S_512_BIT: return ($Type$Species) SPECIES_512;
3012 case S_Max_BIT: return ($Type$Species) SPECIES_MAX;
3013 default: throw new IllegalArgumentException("Bad shape: " + s);
3014 }
3015 }
3016
3017 /** Species representing {@link $Type$Vector}s of {@link Vector.Shape#S_64_BIT Shape.S_64_BIT}. */
3018 public static final Species<$Boxtype$> SPECIES_64 = new $Type$Species(Shape.S_64_BIT, $Type$64Vector.class, $Type$64Vector.$Type$64Mask.class,
3019 $Type$64Vector::new, $Type$64Vector.$Type$64Mask::new);
3020
3021 /** Species representing {@link $Type$Vector}s of {@link Vector.Shape#S_128_BIT Shape.S_128_BIT}. */
3022 public static final Species<$Boxtype$> SPECIES_128 = new $Type$Species(Shape.S_128_BIT, $Type$128Vector.class, $Type$128Vector.$Type$128Mask.class,
3023 $Type$128Vector::new, $Type$128Vector.$Type$128Mask::new);
3024
3025 /** Species representing {@link $Type$Vector}s of {@link Vector.Shape#S_256_BIT Shape.S_256_BIT}. */
3026 public static final Species<$Boxtype$> SPECIES_256 = new $Type$Species(Shape.S_256_BIT, $Type$256Vector.class, $Type$256Vector.$Type$256Mask.class,
3027 $Type$256Vector::new, $Type$256Vector.$Type$256Mask::new);
3028
3029 /** Species representing {@link $Type$Vector}s of {@link Vector.Shape#S_512_BIT Shape.S_512_BIT}. */
3030 public static final Species<$Boxtype$> SPECIES_512 = new $Type$Species(Shape.S_512_BIT, $Type$512Vector.class, $Type$512Vector.$Type$512Mask.class,
3031 $Type$512Vector::new, $Type$512Vector.$Type$512Mask::new);
3032
3033 /** Species representing {@link $Type$Vector}s of {@link Vector.Shape#S_Max_BIT Shape.S_Max_BIT}. */
3034 public static final Species<$Boxtype$> SPECIES_MAX = new $Type$Species(Shape.S_Max_BIT, $Type$MaxVector.class, $Type$MaxVector.$Type$MaxMask.class,
3035 $Type$MaxVector::new, $Type$MaxVector.$Type$MaxMask::new);
3036
3037 /**
3038 * Preferred species for {@link $Type$Vector}s.
3039 * A preferred species is a species of maximal bit size for the platform.
3040 */
3041 public static final Species<$Boxtype$> SPECIES_PREFERRED = (Species<$Boxtype$>) preferredSpecies();
3042 }
|
41
42 /**
43 * A specialized {@link Vector} representing an ordered immutable sequence of
44 * {@code $type$} values.
45 */
46 @SuppressWarnings("cast")
47 public abstract class $abstractvectortype$ extends Vector<$Boxtype$> {
48
49 $abstractvectortype$() {}
50
51 private static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_$TYPE$_INDEX_SCALE);
52
53 // Unary operator
54
55 interface FUnOp {
56 $type$ apply(int i, $type$ a);
57 }
58
59 abstract $abstractvectortype$ uOp(FUnOp f);
60
61 abstract $abstractvectortype$ uOp(VectorMask<$Boxtype$> m, FUnOp f);
62
63 // Binary operator
64
65 interface FBinOp {
66 $type$ apply(int i, $type$ a, $type$ b);
67 }
68
69 abstract $abstractvectortype$ bOp(Vector<$Boxtype$> v, FBinOp f);
70
71 abstract $abstractvectortype$ bOp(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m, FBinOp f);
72
73 // Trinary operator
74
75 interface FTriOp {
76 $type$ apply(int i, $type$ a, $type$ b, $type$ c);
77 }
78
79 abstract $abstractvectortype$ tOp(Vector<$Boxtype$> v1, Vector<$Boxtype$> v2, FTriOp f);
80
81 abstract $abstractvectortype$ tOp(Vector<$Boxtype$> v1, Vector<$Boxtype$> v2, VectorMask<$Boxtype$> m, FTriOp f);
82
83 // Reduction operator
84
85 abstract $type$ rOp($type$ v, FBinOp f);
86
87 // Binary test
88
89 interface FBinTest {
90 boolean apply(int i, $type$ a, $type$ b);
91 }
92
93 abstract VectorMask<$Boxtype$> bTest(Vector<$Boxtype$> v, FBinTest f);
94
95 // Foreach
96
97 interface FUnCon {
98 void apply(int i, $type$ a);
99 }
100
101 abstract void forEach(FUnCon f);
102
103 abstract void forEach(VectorMask<$Boxtype$> m, FUnCon f);
104
105 // Static factories
106
107 /**
108 * Returns a vector where all lane elements are set to the default
109 * primitive value.
110 *
111 * @param species species of desired vector
112 * @return a zero vector of given species
113 */
114 @ForceInline
115 @SuppressWarnings("unchecked")
116 public static $abstractvectortype$ zero(VectorSpecies<$Boxtype$> species) {
117 #if[FP]
118 return VectorIntrinsics.broadcastCoerced((Class<$Type$Vector>) species.boxType(), $type$.class, species.length(),
119 $Type$.$type$To$Bitstype$Bits(0.0f), species,
120 ((bits, s) -> (($Type$Species)s).op(i -> $Type$.$bitstype$BitsTo$Type$(($bitstype$)bits))));
121 #else[FP]
122 return VectorIntrinsics.broadcastCoerced((Class<$Type$Vector>) species.boxType(), $type$.class, species.length(),
123 0, species,
124 ((bits, s) -> (($Type$Species)s).op(i -> ($type$)bits)));
125 #end[FP]
126 }
127
128 /**
129 * Loads a vector from a byte array starting at an offset.
130 * <p>
131 * Bytes are composed into primitive lane elements according to the
132 * native byte order of the underlying platform
133 * <p>
134 * This method behaves as if it returns the result of calling the
135 * byte buffer, offset, and mask accepting
136 * {@link #fromByteBuffer(VectorSpecies<$Boxtype$>, ByteBuffer, int, VectorMask) method} as follows:
137 * <pre>{@code
138 * return this.fromByteBuffer(ByteBuffer.wrap(a), i, this.maskAllTrue());
139 * }</pre>
140 *
141 * @param species species of desired vector
142 * @param a the byte array
143 * @param ix the offset into the array
144 * @return a vector loaded from a byte array
145 * @throws IndexOutOfBoundsException if {@code i < 0} or
146 * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)}
147 */
148 @ForceInline
149 @SuppressWarnings("unchecked")
150 public static $abstractvectortype$ fromByteArray(VectorSpecies<$Boxtype$> species, byte[] a, int ix) {
151 Objects.requireNonNull(a);
152 ix = VectorIntrinsics.checkIndex(ix, a.length, species.bitSize() / Byte.SIZE);
153 return VectorIntrinsics.load((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(),
154 a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
155 a, ix, species,
156 (c, idx, s) -> {
157 ByteBuffer bbc = ByteBuffer.wrap(c, idx, a.length - idx).order(ByteOrder.nativeOrder());
158 $Type$Buffer tb = bbc{#if[byte]?;:.as$Type$Buffer();}
159 return (($Type$Species)s).op(i -> tb.get());
160 });
161 }
162
163 /**
164 * Loads a vector from a byte array starting at an offset and using a
165 * mask.
166 * <p>
167 * Bytes are composed into primitive lane elements according to the
168 * native byte order of the underlying platform.
169 * <p>
170 * This method behaves as if it returns the result of calling the
171 * byte buffer, offset, and mask accepting
172 * {@link #fromByteBuffer(VectorSpecies<$Boxtype$>, ByteBuffer, int, VectorMask) method} as follows:
173 * <pre>{@code
174 * return this.fromByteBuffer(ByteBuffer.wrap(a), i, m);
175 * }</pre>
176 *
177 * @param species species of desired vector
178 * @param a the byte array
179 * @param ix the offset into the array
180 * @param m the mask
181 * @return a vector loaded from a byte array
182 * @throws IndexOutOfBoundsException if {@code i < 0} or
183 * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)}
184 * @throws IndexOutOfBoundsException if the offset is {@code < 0},
185 * or {@code > a.length},
186 * for any vector lane index {@code N} where the mask at lane {@code N}
187 * is set
188 * {@code i >= a.length - (N * this.elementSize() / Byte.SIZE)}
189 */
190 @ForceInline
191 public static $abstractvectortype$ fromByteArray(VectorSpecies<$Boxtype$> species, byte[] a, int ix, VectorMask<$Boxtype$> m) {
192 return zero(species).blend(fromByteArray(species, a, ix), m);
193 }
194
195 /**
196 * Loads a vector from an array starting at offset.
197 * <p>
198 * For each vector lane, where {@code N} is the vector lane index, the
199 * array element at index {@code i + N} is placed into the
200 * resulting vector at lane index {@code N}.
201 *
202 * @param species species of desired vector
203 * @param a the array
204 * @param i the offset into the array
205 * @return the vector loaded from an array
206 * @throws IndexOutOfBoundsException if {@code i < 0}, or
207 * {@code i > a.length - this.length()}
208 */
209 @ForceInline
210 @SuppressWarnings("unchecked")
211 public static $abstractvectortype$ fromArray(VectorSpecies<$Boxtype$> species, $type$[] a, int i){
212 Objects.requireNonNull(a);
213 i = VectorIntrinsics.checkIndex(i, a.length, species.length());
214 return VectorIntrinsics.load((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(),
215 a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_$TYPE$_BASE_OFFSET,
216 a, i, species,
217 (c, idx, s) -> (($Type$Species)s).op(n -> c[idx + n]));
218 }
219
220
221 /**
222 * Loads a vector from an array starting at offset and using a mask.
223 * <p>
224 * For each vector lane, where {@code N} is the vector lane index,
225 * if the mask lane at index {@code N} is set then the array element at
226 * index {@code i + N} is placed into the resulting vector at lane index
227 * {@code N}, otherwise the default element value is placed into the
228 * resulting vector at lane index {@code N}.
229 *
230 * @param species species of desired vector
231 * @param a the array
232 * @param i the offset into the array
233 * @param m the mask
234 * @return the vector loaded from an array
235 * @throws IndexOutOfBoundsException if {@code i < 0}, or
236 * for any vector lane index {@code N} where the mask at lane {@code N}
237 * is set {@code i > a.length - N}
238 */
239 @ForceInline
240 public static $abstractvectortype$ fromArray(VectorSpecies<$Boxtype$> species, $type$[] a, int i, VectorMask<$Boxtype$> m) {
241 return zero(species).blend(fromArray(species, a, i), m);
242 }
243
244 /**
245 * Loads a vector from an array using indexes obtained from an index
246 * map.
247 * <p>
248 * For each vector lane, where {@code N} is the vector lane index, the
249 * array element at index {@code i + indexMap[j + N]} is placed into the
250 * resulting vector at lane index {@code N}.
251 *
252 * @param species species of desired vector
253 * @param a the array
254 * @param i the offset into the array, may be negative if relative
255 * indexes in the index map compensate to produce a value within the
256 * array bounds
257 * @param indexMap the index map
258 * @param j the offset into the index map
259 * @return the vector loaded from an array
260 * @throws IndexOutOfBoundsException if {@code j < 0}, or
261 * {@code j > indexMap.length - this.length()},
262 * or for any vector lane index {@code N} the result of
263 * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length}
264 */
265 #if[byteOrShort]
266 public static $abstractvectortype$ fromArray(VectorSpecies<$Boxtype$> species, $type$[] a, int i, int[] indexMap, int j) {
267 return (($Type$Species)species).op(n -> a[i + indexMap[j + n]]);
268 }
269 #else[byteOrShort]
270 @ForceInline
271 @SuppressWarnings("unchecked")
272 public static $abstractvectortype$ fromArray(VectorSpecies<$Boxtype$> species, $type$[] a, int i, int[] indexMap, int j) {
273 Objects.requireNonNull(a);
274 Objects.requireNonNull(indexMap);
275
276 #if[longOrDouble]
277 if (species.length() == 1) {
278 return $abstractvectortype$.fromArray(species, a, i + indexMap[j]);
279 }
280 #end[longOrDouble]
281
282 // Index vector: vix[0:n] = k -> i + indexMap[j + k]
283 IntVector vix = IntVector.fromArray(IntVector.species(species.indexShape()), indexMap, j).add(i);
284
285 vix = VectorIntrinsics.checkIndex(vix, a.length);
286
287 return VectorIntrinsics.loadWithMap((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(),
288 IntVector.species(species.indexShape()).boxType(), a, Unsafe.ARRAY_$TYPE$_BASE_OFFSET, vix,
289 a, i, indexMap, j, species,
290 ($type$[] c, int idx, int[] iMap, int idy, VectorSpecies<$Boxtype$> s) ->
291 (($Type$Species)s).op(n -> c[idx + iMap[idy+n]]));
292 }
293
294 #end[byteOrShort]
295 /**
296 * Loads a vector from an array using indexes obtained from an index
297 * map and using a mask.
298 * <p>
299 * For each vector lane, where {@code N} is the vector lane index,
300 * if the mask lane at index {@code N} is set then the array element at
301 * index {@code i + indexMap[j + N]} is placed into the resulting vector
302 * at lane index {@code N}.
303 *
304 * @param species species of desired vector
305 * @param a the array
306 * @param i the offset into the array, may be negative if relative
307 * indexes in the index map compensate to produce a value within the
308 * array bounds
309 * @param m the mask
310 * @param indexMap the index map
311 * @param j the offset into the index map
312 * @return the vector loaded from an array
313 * @throws IndexOutOfBoundsException if {@code j < 0}, or
314 * {@code j > indexMap.length - this.length()},
315 * or for any vector lane index {@code N} where the mask at lane
316 * {@code N} is set the result of {@code i + indexMap[j + N]} is
317 * {@code < 0} or {@code >= a.length}
318 */
319 #if[byteOrShort]
320 public static $abstractvectortype$ fromArray(VectorSpecies<$Boxtype$> species, $type$[] a, int i, VectorMask<$Boxtype$> m, int[] indexMap, int j) {
321 return (($Type$Species)species).op(m, n -> a[i + indexMap[j + n]]);
322 }
323 #else[byteOrShort]
324 @ForceInline
325 @SuppressWarnings("unchecked")
326 public static $abstractvectortype$ fromArray(VectorSpecies<$Boxtype$> species, $type$[] a, int i, VectorMask<$Boxtype$> m, int[] indexMap, int j) {
327 // @@@ This can result in out of bounds errors for unset mask lanes
328 return zero(species).blend(fromArray(species, a, i, indexMap, j), m);
329 }
330
331 #end[byteOrShort]
332
333 /**
334 * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
335 * offset into the byte buffer.
336 * <p>
337 * Bytes are composed into primitive lane elements according to the
338 * native byte order of the underlying platform.
339 * <p>
340 * This method behaves as if it returns the result of calling the
341 * byte buffer, offset, and mask accepting
342 * {@link #fromByteBuffer(VectorSpecies<$Boxtype$>, ByteBuffer, int, VectorMask)} method} as follows:
343 * <pre>{@code
344 * return this.fromByteBuffer(b, i, this.maskAllTrue())
345 * }</pre>
346 *
347 * @param species species of desired vector
348 * @param bb the byte buffer
349 * @param ix the offset into the byte buffer
350 * @return a vector loaded from a byte buffer
351 * @throws IndexOutOfBoundsException if the offset is {@code < 0},
352 * or {@code > b.limit()},
353 * or if there are fewer than
354 * {@code this.length() * this.elementSize() / Byte.SIZE} bytes
355 * remaining in the byte buffer from the given offset
356 */
357 @ForceInline
358 @SuppressWarnings("unchecked")
359 public static $abstractvectortype$ fromByteBuffer(VectorSpecies<$Boxtype$> species, ByteBuffer bb, int ix) {
360 if (bb.order() != ByteOrder.nativeOrder()) {
361 throw new IllegalArgumentException();
362 }
363 ix = VectorIntrinsics.checkIndex(ix, bb.limit(), species.bitSize() / Byte.SIZE);
364 return VectorIntrinsics.load((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(),
365 U.getReference(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + ix,
366 bb, ix, species,
367 (c, idx, s) -> {
368 ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
369 $Type$Buffer tb = bbc{#if[byte]?;:.as$Type$Buffer();}
370 return (($Type$Species)s).op(i -> tb.get());
371 });
372 }
373
374 /**
375 * Loads a vector from a {@link ByteBuffer byte buffer} starting at an
376 * offset into the byte buffer and using a mask.
377 * <p>
378 * This method behaves as if the byte buffer is viewed as a primitive
379 * {@link java.nio.Buffer buffer} for the primitive element type,
391 * e[] es = new e[this.length()];
392 * for (int n = 0; n < t.length; n++) {
393 * if (m.isSet(n))
394 * es[n] = eb.get(n);
395 * }
396 * Vector<E> r = ((ESpecies<S>)this).fromArray(es, 0, m);
397 * }</pre>
398 *
399 * @param species species of desired vector
400 * @param bb the byte buffer
401 * @param ix the offset into the byte buffer
402 * @param m the mask
403 * @return a vector loaded from a byte buffer
404 * @throws IndexOutOfBoundsException if the offset is {@code < 0},
405 * or {@code > b.limit()},
406 * for any vector lane index {@code N} where the mask at lane {@code N}
407 * is set
408 * {@code i >= b.limit() - (N * this.elementSize() / Byte.SIZE)}
409 */
410 @ForceInline
411 public static $abstractvectortype$ fromByteBuffer(VectorSpecies<$Boxtype$> species, ByteBuffer bb, int ix, VectorMask<$Boxtype$> m) {
412 return zero(species).blend(fromByteBuffer(species, bb, ix), m);
413 }
414
415 /**
416 * Returns a vector where all lane elements are set to the primitive
417 * value {@code e}.
418 *
419 * @param s species of the desired vector
420 * @param e the value
421 * @return a vector of vector where all lane elements are set to
422 * the primitive value {@code e}
423 */
424 #if[FP]
425 @ForceInline
426 @SuppressWarnings("unchecked")
427 public static $abstractvectortype$ broadcast(VectorSpecies<$Boxtype$> s, $type$ e) {
428 return VectorIntrinsics.broadcastCoerced(
429 (Class<$abstractvectortype$>) s.boxType(), $type$.class, s.length(),
430 $Type$.$type$To$Bitstype$Bits(e), s,
431 ((bits, sp) -> (($Type$Species)sp).op(i -> $Type$.$bitstype$BitsTo$Type$(($bitstype$)bits))));
432 }
433 #else[FP]
434 @ForceInline
435 @SuppressWarnings("unchecked")
436 public static $abstractvectortype$ broadcast(VectorSpecies<$Boxtype$> s, $type$ e) {
437 return VectorIntrinsics.broadcastCoerced(
438 (Class<$abstractvectortype$>) s.boxType(), $type$.class, s.length(),
439 e, s,
440 ((bits, sp) -> (($Type$Species)sp).op(i -> ($type$)bits)));
441 }
442 #end[FP]
443
444 /**
445 * Returns a vector where each lane element is set to a given
446 * primitive value.
447 * <p>
448 * For each vector lane, where {@code N} is the vector lane index, the
449 * the primitive value at index {@code N} is placed into the resulting
450 * vector at lane index {@code N}.
451 *
452 * @param s species of the desired vector
453 * @param es the given primitive values
454 * @return a vector where each lane element is set to a given primitive
455 * value
456 * @throws IndexOutOfBoundsException if {@code es.length < this.length()}
457 */
458 @ForceInline
459 @SuppressWarnings("unchecked")
460 public static $abstractvectortype$ scalars(VectorSpecies<$Boxtype$> s, $type$... es) {
461 Objects.requireNonNull(es);
462 int ix = VectorIntrinsics.checkIndex(0, es.length, s.length());
463 return VectorIntrinsics.load((Class<$abstractvectortype$>) s.boxType(), $type$.class, s.length(),
464 es, Unsafe.ARRAY_$TYPE$_BASE_OFFSET,
465 es, ix, s,
466 (c, idx, sp) -> (($Type$Species)sp).op(n -> c[idx + n]));
467 }
468
469 /**
470 * Returns a vector where the first lane element is set to the primtive
471 * value {@code e}, all other lane elements are set to the default
472 * value.
473 *
474 * @param s species of the desired vector
475 * @param e the value
476 * @return a vector where the first lane element is set to the primitive
477 * value {@code e}
478 */
479 @ForceInline
480 public static final $abstractvectortype$ single(VectorSpecies<$Boxtype$> s, $type$ e) {
481 return zero(s).with(0, e);
482 }
483
484 /**
485 * Returns a vector where each lane element is set to a randomly
486 * generated primitive value.
487 *
488 * The semantics are equivalent to calling
489 #if[byteOrShort]
490 * ($type$){@link ThreadLocalRandom#nextInt()}
491 #else[byteOrShort]
492 * {@link ThreadLocalRandom#next$Type$()}
493 #end[byteOrShort]
494 *
495 * @param s species of the desired vector
496 * @return a vector where each lane elements is set to a randomly
497 * generated primitive value
498 */
499 #if[intOrLong]
500 public static $abstractvectortype$ random(VectorSpecies<$Boxtype$> s) {
501 ThreadLocalRandom r = ThreadLocalRandom.current();
502 return (($Type$Species)s).op(i -> r.next$Type$());
503 }
504 #else[intOrLong]
505 #if[FP]
506 public static $abstractvectortype$ random(VectorSpecies<$Boxtype$> s) {
507 ThreadLocalRandom r = ThreadLocalRandom.current();
508 return (($Type$Species)s).op(i -> r.next$Type$());
509 }
510 #else[FP]
511 public static $abstractvectortype$ random(VectorSpecies<$Boxtype$> s) {
512 ThreadLocalRandom r = ThreadLocalRandom.current();
513 return (($Type$Species)s).op(i -> ($type$) r.nextInt());
514 }
515 #end[FP]
516 #end[intOrLong]
517
518 // Ops
519
520 @Override
521 public abstract $abstractvectortype$ add(Vector<$Boxtype$> v);
522
523 /**
524 * Adds this vector to the broadcast of an input scalar.
525 * <p>
526 * This is a vector binary operation where the primitive addition operation
527 * ({@code +}) is applied to lane elements.
528 *
529 * @param s the input scalar
530 * @return the result of adding this vector to the broadcast of an input
531 * scalar
532 */
533 public abstract $abstractvectortype$ add($type$ s);
534
535 @Override
536 public abstract $abstractvectortype$ add(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m);
537
538 /**
539 * Adds this vector to broadcast of an input scalar,
540 * selecting lane elements controlled by a mask.
541 * <p>
542 * This is a vector binary operation where the primitive addition operation
543 * ({@code +}) is applied to lane elements.
544 *
545 * @param s the input scalar
546 * @param m the mask controlling lane selection
547 * @return the result of adding this vector to the broadcast of an input
548 * scalar
549 */
550 public abstract $abstractvectortype$ add($type$ s, VectorMask<$Boxtype$> m);
551
552 @Override
553 public abstract $abstractvectortype$ sub(Vector<$Boxtype$> v);
554
555 /**
556 * Subtracts the broadcast of an input scalar from this vector.
557 * <p>
558 * This is a vector binary operation where the primitive subtraction
559 * operation ({@code -}) is applied to lane elements.
560 *
561 * @param s the input scalar
562 * @return the result of subtracting the broadcast of an input
563 * scalar from this vector
564 */
565 public abstract $abstractvectortype$ sub($type$ s);
566
567 @Override
568 public abstract $abstractvectortype$ sub(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m);
569
570 /**
571 * Subtracts the broadcast of an input scalar from this vector, selecting
572 * lane elements controlled by a mask.
573 * <p>
574 * This is a vector binary operation where the primitive subtraction
575 * operation ({@code -}) is applied to lane elements.
576 *
577 * @param s the input scalar
578 * @param m the mask controlling lane selection
579 * @return the result of subtracting the broadcast of an input
580 * scalar from this vector
581 */
582 public abstract $abstractvectortype$ sub($type$ s, VectorMask<$Boxtype$> m);
583
584 @Override
585 public abstract $abstractvectortype$ mul(Vector<$Boxtype$> v);
586
587 /**
588 * Multiplies this vector with the broadcast of an input scalar.
589 * <p>
590 * This is a vector binary operation where the primitive multiplication
591 * operation ({@code *}) is applied to lane elements.
592 *
593 * @param s the input scalar
594 * @return the result of multiplying this vector with the broadcast of an
595 * input scalar
596 */
597 public abstract $abstractvectortype$ mul($type$ s);
598
599 @Override
600 public abstract $abstractvectortype$ mul(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m);
601
602 /**
603 * Multiplies this vector with the broadcast of an input scalar, selecting
604 * lane elements controlled by a mask.
605 * <p>
606 * This is a vector binary operation where the primitive multiplication
607 * operation ({@code *}) is applied to lane elements.
608 *
609 * @param s the input scalar
610 * @param m the mask controlling lane selection
611 * @return the result of multiplying this vector with the broadcast of an
612 * input scalar
613 */
614 public abstract $abstractvectortype$ mul($type$ s, VectorMask<$Boxtype$> m);
615
616 @Override
617 public abstract $abstractvectortype$ neg();
618
619 @Override
620 public abstract $abstractvectortype$ neg(VectorMask<$Boxtype$> m);
621
622 @Override
623 public abstract $abstractvectortype$ abs();
624
625 @Override
626 public abstract $abstractvectortype$ abs(VectorMask<$Boxtype$> m);
627
628 @Override
629 public abstract $abstractvectortype$ min(Vector<$Boxtype$> v);
630
631 @Override
632 public abstract $abstractvectortype$ min(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m);
633
634 /**
635 * Returns the minimum of this vector and the broadcast of an input scalar.
636 * <p>
637 * This is a vector binary operation where the operation
638 * {@code (a, b) -> Math.min(a, b)} is applied to lane elements.
639 *
640 * @param s the input scalar
641 * @return the minimum of this vector and the broadcast of an input scalar
642 */
643 public abstract $abstractvectortype$ min($type$ s);
644
645 @Override
646 public abstract $abstractvectortype$ max(Vector<$Boxtype$> v);
647
648 @Override
649 public abstract $abstractvectortype$ max(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m);
650
651 /**
652 * Returns the maximum of this vector and the broadcast of an input scalar.
653 * <p>
654 * This is a vector binary operation where the operation
655 * {@code (a, b) -> Math.max(a, b)} is applied to lane elements.
656 *
657 * @param s the input scalar
658 * @return the maximum of this vector and the broadcast of an input scalar
659 */
660 public abstract $abstractvectortype$ max($type$ s);
661
662 @Override
663 public abstract VectorMask<$Boxtype$> equal(Vector<$Boxtype$> v);
664
665 /**
666 * Tests if this vector is equal to the broadcast of an input scalar.
667 * <p>
668 * This is a vector binary test operation where the primitive equals
669 * operation ({@code ==}) is applied to lane elements.
670 *
671 * @param s the input scalar
672 * @return the result mask of testing if this vector is equal to the
673 * broadcast of an input scalar
674 */
675 public abstract VectorMask<$Boxtype$> equal($type$ s);
676
677 @Override
678 public abstract VectorMask<$Boxtype$> notEqual(Vector<$Boxtype$> v);
679
680 /**
681 * Tests if this vector is not equal to the broadcast of an input scalar.
682 * <p>
683 * This is a vector binary test operation where the primitive not equals
684 * operation ({@code !=}) is applied to lane elements.
685 *
686 * @param s the input scalar
687 * @return the result mask of testing if this vector is not equal to the
688 * broadcast of an input scalar
689 */
690 public abstract VectorMask<$Boxtype$> notEqual($type$ s);
691
692 @Override
693 public abstract VectorMask<$Boxtype$> lessThan(Vector<$Boxtype$> v);
694
695 /**
696 * Tests if this vector is less than the broadcast of an input scalar.
697 * <p>
698 * This is a vector binary test operation where the primitive less than
699 * operation ({@code <}) is applied to lane elements.
700 *
701 * @param s the input scalar
702 * @return the mask result of testing if this vector is less than the
703 * broadcast of an input scalar
704 */
705 public abstract VectorMask<$Boxtype$> lessThan($type$ s);
706
707 @Override
708 public abstract VectorMask<$Boxtype$> lessThanEq(Vector<$Boxtype$> v);
709
710 /**
711 * Tests if this vector is less or equal to the broadcast of an input scalar.
712 * <p>
713 * This is a vector binary test operation where the primitive less than
714 * or equal to operation ({@code <=}) is applied to lane elements.
715 *
716 * @param s the input scalar
717 * @return the mask result of testing if this vector is less than or equal
718 * to the broadcast of an input scalar
719 */
720 public abstract VectorMask<$Boxtype$> lessThanEq($type$ s);
721
722 @Override
723 public abstract VectorMask<$Boxtype$> greaterThan(Vector<$Boxtype$> v);
724
725 /**
726 * Tests if this vector is greater than the broadcast of an input scalar.
727 * <p>
728 * This is a vector binary test operation where the primitive greater than
729 * operation ({@code >}) is applied to lane elements.
730 *
731 * @param s the input scalar
732 * @return the mask result of testing if this vector is greater than the
733 * broadcast of an input scalar
734 */
735 public abstract VectorMask<$Boxtype$> greaterThan($type$ s);
736
737 @Override
738 public abstract VectorMask<$Boxtype$> greaterThanEq(Vector<$Boxtype$> v);
739
740 /**
741 * Tests if this vector is greater than or equal to the broadcast of an
742 * input scalar.
743 * <p>
744 * This is a vector binary test operation where the primitive greater than
745 * or equal to operation ({@code >=}) is applied to lane elements.
746 *
747 * @param s the input scalar
748 * @return the mask result of testing if this vector is greater than or
749 * equal to the broadcast of an input scalar
750 */
751 public abstract VectorMask<$Boxtype$> greaterThanEq($type$ s);
752
753 @Override
754 public abstract $abstractvectortype$ blend(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m);
755
756 /**
757 * Blends the lane elements of this vector with those of the broadcast of an
758 * input scalar, selecting lanes controlled by a mask.
759 * <p>
760 * For each lane of the mask, at lane index {@code N}, if the mask lane
761 * is set then the lane element at {@code N} from the input vector is
762 * selected and placed into the resulting vector at {@code N},
763 * otherwise the the lane element at {@code N} from this input vector is
764 * selected and placed into the resulting vector at {@code N}.
765 *
766 * @param s the input scalar
767 * @param m the mask controlling lane selection
768 * @return the result of blending the lane elements of this vector with
769 * those of the broadcast of an input scalar
770 */
771 public abstract $abstractvectortype$ blend($type$ s, VectorMask<$Boxtype$> m);
772
773 @Override
774 public abstract $abstractvectortype$ rearrange(Vector<$Boxtype$> v,
775 VectorShuffle<$Boxtype$> s, VectorMask<$Boxtype$> m);
776
777 @Override
778 public abstract $abstractvectortype$ rearrange(VectorShuffle<$Boxtype$> m);
779
780 @Override
781 public abstract $abstractvectortype$ reshape(VectorSpecies<$Boxtype$> s);
782
783 @Override
784 public abstract $abstractvectortype$ rotateEL(int i);
785
786 @Override
787 public abstract $abstractvectortype$ rotateER(int i);
788
789 @Override
790 public abstract $abstractvectortype$ shiftEL(int i);
791
792 @Override
793 public abstract $abstractvectortype$ shiftER(int i);
794
795 #if[FP]
796 /**
797 * Divides this vector by an input vector.
798 * <p>
799 * This is a vector binary operation where the primitive division
800 * operation ({@code /}) is applied to lane elements.
801 *
810 * This is a vector binary operation where the primitive division
811 * operation ({@code /}) is applied to lane elements.
812 *
813 * @param s the input scalar
814 * @return the result of dividing this vector by the broadcast of an input
815 * scalar
816 */
817 public abstract $abstractvectortype$ div($type$ s);
818
819 /**
820 * Divides this vector by an input vector, selecting lane elements
821 * controlled by a mask.
822 * <p>
823 * This is a vector binary operation where the primitive division
824 * operation ({@code /}) is applied to lane elements.
825 *
826 * @param v the input vector
827 * @param m the mask controlling lane selection
828 * @return the result of dividing this vector by the input vector
829 */
830 public abstract $abstractvectortype$ div(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m);
831
832 /**
833 * Divides this vector by the broadcast of an input scalar, selecting lane
834 * elements controlled by a mask.
835 * <p>
836 * This is a vector binary operation where the primitive division
837 * operation ({@code /}) is applied to lane elements.
838 *
839 * @param s the input scalar
840 * @param m the mask controlling lane selection
841 * @return the result of dividing this vector by the broadcast of an input
842 * scalar
843 */
844 public abstract $abstractvectortype$ div($type$ s, VectorMask<$Boxtype$> m);
845
846 /**
847 * Calculates the square root of this vector.
848 * <p>
849 * This is a vector unary operation where the {@link Math#sqrt} operation
850 * is applied to lane elements.
851 *
852 * @return the square root of this vector
853 */
854 public abstract $abstractvectortype$ sqrt();
855
856 /**
857 * Calculates the square root of this vector, selecting lane elements
858 * controlled by a mask.
859 * <p>
860 * This is a vector unary operation where the {@link Math#sqrt} operation
861 * is applied to lane elements.
862 *
863 * @param m the mask controlling lane selection
864 * @return the square root of this vector
865 */
866 public $abstractvectortype$ sqrt(VectorMask<$Boxtype$> m) {
867 return uOp(m, (i, a) -> ($type$) Math.sqrt((double) a));
868 }
869
870 /**
871 * Calculates the trigonometric tangent of this vector.
872 * <p>
873 * This is a vector unary operation with same semantic definition as
874 * {@link Math#tan} operation applied to lane elements.
875 * The implementation is not required to return same
876 * results as {@link Math#tan}, but adheres to rounding, monotonicity,
877 * and special case semantics as defined in the {@link Math#tan}
878 * specifications. The computed result will be within 1 ulp of the
879 * exact result.
880 *
881 * @return the tangent of this vector
882 */
883 public $abstractvectortype$ tan() {
884 return uOp((i, a) -> ($type$) Math.tan((double) a));
885 }
886
887 /**
888 * Calculates the trigonometric tangent of this vector, selecting lane
889 * elements controlled by a mask.
890 * <p>
891 * Semantics for rounding, monotonicity, and special cases are
892 * described in {@link $abstractvectortype$#tan}
893 *
894 * @param m the mask controlling lane selection
895 * @return the tangent of this vector
896 */
897 public $abstractvectortype$ tan(VectorMask<$Boxtype$> m) {
898 return uOp(m, (i, a) -> ($type$) Math.tan((double) a));
899 }
900
901 /**
902 * Calculates the hyperbolic tangent of this vector.
903 * <p>
904 * This is a vector unary operation with same semantic definition as
905 * {@link Math#tanh} operation applied to lane elements.
906 * The implementation is not required to return same
907 * results as {@link Math#tanh}, but adheres to rounding, monotonicity,
908 * and special case semantics as defined in the {@link Math#tanh}
909 * specifications. The computed result will be within 2.5 ulps of the
910 * exact result.
911 *
912 * @return the hyperbolic tangent of this vector
913 */
914 public $abstractvectortype$ tanh() {
915 return uOp((i, a) -> ($type$) Math.tanh((double) a));
916 }
917
918 /**
919 * Calculates the hyperbolic tangent of this vector, selecting lane elements
920 * controlled by a mask.
921 * <p>
922 * Semantics for rounding, monotonicity, and special cases are
923 * described in {@link $abstractvectortype$#tanh}
924 *
925 * @param m the mask controlling lane selection
926 * @return the hyperbolic tangent of this vector
927 */
928 public $abstractvectortype$ tanh(VectorMask<$Boxtype$> m) {
929 return uOp(m, (i, a) -> ($type$) Math.tanh((double) a));
930 }
931
932 /**
933 * Calculates the trigonometric sine of this vector.
934 * <p>
935 * This is a vector unary operation with same semantic definition as
936 * {@link Math#sin} operation applied to lane elements.
937 * The implementation is not required to return same
938 * results as {@link Math#sin}, but adheres to rounding, monotonicity,
939 * and special case semantics as defined in the {@link Math#sin}
940 * specifications. The computed result will be within 1 ulp of the
941 * exact result.
942 *
943 * @return the sine of this vector
944 */
945 public $abstractvectortype$ sin() {
946 return uOp((i, a) -> ($type$) Math.sin((double) a));
947 }
948
949 /**
950 * Calculates the trigonometric sine of this vector, selecting lane elements
951 * controlled by a mask.
952 * <p>
953 * Semantics for rounding, monotonicity, and special cases are
954 * described in {@link $abstractvectortype$#sin}
955 *
956 * @param m the mask controlling lane selection
957 * @return the sine of this vector
958 */
959 public $abstractvectortype$ sin(VectorMask<$Boxtype$> m) {
960 return uOp(m, (i, a) -> ($type$) Math.sin((double) a));
961 }
962
963 /**
964 * Calculates the hyperbolic sine of this vector.
965 * <p>
966 * This is a vector unary operation with same semantic definition as
967 * {@link Math#sinh} operation applied to lane elements.
968 * The implementation is not required to return same
969 * results as {@link Math#sinh}, but adheres to rounding, monotonicity,
970 * and special case semantics as defined in the {@link Math#sinh}
971 * specifications. The computed result will be within 2.5 ulps of the
972 * exact result.
973 *
974 * @return the hyperbolic sine of this vector
975 */
976 public $abstractvectortype$ sinh() {
977 return uOp((i, a) -> ($type$) Math.sinh((double) a));
978 }
979
980 /**
981 * Calculates the hyperbolic sine of this vector, selecting lane elements
982 * controlled by a mask.
983 * <p>
984 * Semantics for rounding, monotonicity, and special cases are
985 * described in {@link $abstractvectortype$#sinh}
986 *
987 * @param m the mask controlling lane selection
988 * @return the hyperbolic sine of this vector
989 */
990 public $abstractvectortype$ sinh(VectorMask<$Boxtype$> m) {
991 return uOp(m, (i, a) -> ($type$) Math.sinh((double) a));
992 }
993
994 /**
995 * Calculates the trigonometric cosine of this vector.
996 * <p>
997 * This is a vector unary operation with same semantic definition as
998 * {@link Math#cos} operation applied to lane elements.
999 * The implementation is not required to return same
1000 * results as {@link Math#cos}, but adheres to rounding, monotonicity,
1001 * and special case semantics as defined in the {@link Math#cos}
1002 * specifications. The computed result will be within 1 ulp of the
1003 * exact result.
1004 *
1005 * @return the cosine of this vector
1006 */
1007 public $abstractvectortype$ cos() {
1008 return uOp((i, a) -> ($type$) Math.cos((double) a));
1009 }
1010
1011 /**
1012 * Calculates the trigonometric cosine of this vector, selecting lane
1013 * elements controlled by a mask.
1014 * <p>
1015 * Semantics for rounding, monotonicity, and special cases are
1016 * described in {@link $abstractvectortype$#cos}
1017 *
1018 * @param m the mask controlling lane selection
1019 * @return the cosine of this vector
1020 */
1021 public $abstractvectortype$ cos(VectorMask<$Boxtype$> m) {
1022 return uOp(m, (i, a) -> ($type$) Math.cos((double) a));
1023 }
1024
1025 /**
1026 * Calculates the hyperbolic cosine of this vector.
1027 * <p>
1028 * This is a vector unary operation with same semantic definition as
1029 * {@link Math#cosh} operation applied to lane elements.
1030 * The implementation is not required to return same
1031 * results as {@link Math#cosh}, but adheres to rounding, monotonicity,
1032 * and special case semantics as defined in the {@link Math#cosh}
1033 * specifications. The computed result will be within 2.5 ulps of the
1034 * exact result.
1035 *
1036 * @return the hyperbolic cosine of this vector
1037 */
1038 public $abstractvectortype$ cosh() {
1039 return uOp((i, a) -> ($type$) Math.cosh((double) a));
1040 }
1041
1042 /**
1043 * Calculates the hyperbolic cosine of this vector, selecting lane elements
1044 * controlled by a mask.
1045 * <p>
1046 * Semantics for rounding, monotonicity, and special cases are
1047 * described in {@link $abstractvectortype$#cosh}
1048 *
1049 * @param m the mask controlling lane selection
1050 * @return the hyperbolic cosine of this vector
1051 */
1052 public $abstractvectortype$ cosh(VectorMask<$Boxtype$> m) {
1053 return uOp(m, (i, a) -> ($type$) Math.cosh((double) a));
1054 }
1055
1056 /**
1057 * Calculates the arc sine of this vector.
1058 * <p>
1059 * This is a vector unary operation with same semantic definition as
1060 * {@link Math#asin} operation applied to lane elements.
1061 * The implementation is not required to return same
1062 * results as {@link Math#asin}, but adheres to rounding, monotonicity,
1063 * and special case semantics as defined in the {@link Math#asin}
1064 * specifications. The computed result will be within 1 ulp of the
1065 * exact result.
1066 *
1067 * @return the arc sine of this vector
1068 */
1069 public $abstractvectortype$ asin() {
1070 return uOp((i, a) -> ($type$) Math.asin((double) a));
1071 }
1072
1073 /**
1074 * Calculates the arc sine of this vector, selecting lane elements
1075 * controlled by a mask.
1076 * <p>
1077 * Semantics for rounding, monotonicity, and special cases are
1078 * described in {@link $abstractvectortype$#asin}
1079 *
1080 * @param m the mask controlling lane selection
1081 * @return the arc sine of this vector
1082 */
1083 public $abstractvectortype$ asin(VectorMask<$Boxtype$> m) {
1084 return uOp(m, (i, a) -> ($type$) Math.asin((double) a));
1085 }
1086
1087 /**
1088 * Calculates the arc cosine of this vector.
1089 * <p>
1090 * This is a vector unary operation with same semantic definition as
1091 * {@link Math#acos} operation applied to lane elements.
1092 * The implementation is not required to return same
1093 * results as {@link Math#acos}, but adheres to rounding, monotonicity,
1094 * and special case semantics as defined in the {@link Math#acos}
1095 * specifications. The computed result will be within 1 ulp of the
1096 * exact result.
1097 *
1098 * @return the arc cosine of this vector
1099 */
1100 public $abstractvectortype$ acos() {
1101 return uOp((i, a) -> ($type$) Math.acos((double) a));
1102 }
1103
1104 /**
1105 * Calculates the arc cosine of this vector, selecting lane elements
1106 * controlled by a mask.
1107 * <p>
1108 * Semantics for rounding, monotonicity, and special cases are
1109 * described in {@link $abstractvectortype$#acos}
1110 *
1111 * @param m the mask controlling lane selection
1112 * @return the arc cosine of this vector
1113 */
1114 public $abstractvectortype$ acos(VectorMask<$Boxtype$> m) {
1115 return uOp(m, (i, a) -> ($type$) Math.acos((double) a));
1116 }
1117
1118 /**
1119 * Calculates the arc tangent of this vector.
1120 * <p>
1121 * This is a vector unary operation with same semantic definition as
1122 * {@link Math#atan} operation applied to lane elements.
1123 * The implementation is not required to return same
1124 * results as {@link Math#atan}, but adheres to rounding, monotonicity,
1125 * and special case semantics as defined in the {@link Math#atan}
1126 * specifications. The computed result will be within 1 ulp of the
1127 * exact result.
1128 *
1129 * @return the arc tangent of this vector
1130 */
1131 public $abstractvectortype$ atan() {
1132 return uOp((i, a) -> ($type$) Math.atan((double) a));
1133 }
1134
1135 /**
1136 * Calculates the arc tangent of this vector, selecting lane elements
1137 * controlled by a mask.
1138 * <p>
1139 * Semantics for rounding, monotonicity, and special cases are
1140 * described in {@link $abstractvectortype$#atan}
1141 *
1142 * @param m the mask controlling lane selection
1143 * @return the arc tangent of this vector
1144 */
1145 public $abstractvectortype$ atan(VectorMask<$Boxtype$> m) {
1146 return uOp(m, (i, a) -> ($type$) Math.atan((double) a));
1147 }
1148
1149 /**
1150 * Calculates the arc tangent of this vector divided by an input vector.
1151 * <p>
1152 * This is a vector binary operation with same semantic definition as
1153 * {@link Math#atan2} operation applied to lane elements.
1154 * The implementation is not required to return same
1155 * results as {@link Math#atan2}, but adheres to rounding, monotonicity,
1156 * and special case semantics as defined in the {@link Math#atan2}
1157 * specifications. The computed result will be within 2 ulps of the
1158 * exact result.
1159 *
1160 * @param v the input vector
1161 * @return the arc tangent of this vector divided by the input vector
1162 */
1163 public $abstractvectortype$ atan2(Vector<$Boxtype$> v) {
1164 return bOp(v, (i, a, b) -> ($type$) Math.atan2((double) a, (double) b));
1165 }
1175 * and special case semantics as defined in the {@link Math#atan2}
1176 * specifications. The computed result will be within 1 ulp of the
1177 * exact result.
1178 *
1179 * @param s the input scalar
1180 * @return the arc tangent of this vector over the input vector
1181 */
1182 public abstract $abstractvectortype$ atan2($type$ s);
1183
1184 /**
1185 * Calculates the arc tangent of this vector divided by an input vector,
1186 * selecting lane elements controlled by a mask.
1187 * <p>
1188 * Semantics for rounding, monotonicity, and special cases are
1189 * described in {@link $abstractvectortype$#atan2}
1190 *
1191 * @param v the input vector
1192 * @param m the mask controlling lane selection
1193 * @return the arc tangent of this vector divided by the input vector
1194 */
1195 public $abstractvectortype$ atan2(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
1196 return bOp(v, m, (i, a, b) -> ($type$) Math.atan2((double) a, (double) b));
1197 }
1198
1199 /**
1200 * Calculates the arc tangent of this vector divided by the broadcast of an
1201 * an input scalar, selecting lane elements controlled by a mask.
1202 * <p>
1203 * Semantics for rounding, monotonicity, and special cases are
1204 * described in {@link $abstractvectortype$#atan2}
1205 *
1206 * @param s the input scalar
1207 * @param m the mask controlling lane selection
1208 * @return the arc tangent of this vector over the input vector
1209 */
1210 public abstract $abstractvectortype$ atan2($type$ s, VectorMask<$Boxtype$> m);
1211
1212 /**
1213 * Calculates the cube root of this vector.
1214 * <p>
1215 * This is a vector unary operation with same semantic definition as
1216 * {@link Math#cbrt} operation applied to lane elements.
1217 * The implementation is not required to return same
1218 * results as {@link Math#cbrt}, but adheres to rounding, monotonicity,
1219 * and special case semantics as defined in the {@link Math#cbrt}
1220 * specifications. The computed result will be within 1 ulp of the
1221 * exact result.
1222 *
1223 * @return the cube root of this vector
1224 */
1225 public $abstractvectortype$ cbrt() {
1226 return uOp((i, a) -> ($type$) Math.cbrt((double) a));
1227 }
1228
1229 /**
1230 * Calculates the cube root of this vector, selecting lane elements
1231 * controlled by a mask.
1232 * <p>
1233 * Semantics for rounding, monotonicity, and special cases are
1234 * described in {@link $abstractvectortype$#cbrt}
1235 *
1236 * @param m the mask controlling lane selection
1237 * @return the cube root of this vector
1238 */
1239 public $abstractvectortype$ cbrt(VectorMask<$Boxtype$> m) {
1240 return uOp(m, (i, a) -> ($type$) Math.cbrt((double) a));
1241 }
1242
1243 /**
1244 * Calculates the natural logarithm of this vector.
1245 * <p>
1246 * This is a vector unary operation with same semantic definition as
1247 * {@link Math#log} operation applied to lane elements.
1248 * The implementation is not required to return same
1249 * results as {@link Math#log}, but adheres to rounding, monotonicity,
1250 * and special case semantics as defined in the {@link Math#log}
1251 * specifications. The computed result will be within 1 ulp of the
1252 * exact result.
1253 *
1254 * @return the natural logarithm of this vector
1255 */
1256 public $abstractvectortype$ log() {
1257 return uOp((i, a) -> ($type$) Math.log((double) a));
1258 }
1259
1260 /**
1261 * Calculates the natural logarithm of this vector, selecting lane elements
1262 * controlled by a mask.
1263 * <p>
1264 * Semantics for rounding, monotonicity, and special cases are
1265 * described in {@link $abstractvectortype$#log}
1266 *
1267 * @param m the mask controlling lane selection
1268 * @return the natural logarithm of this vector
1269 */
1270 public $abstractvectortype$ log(VectorMask<$Boxtype$> m) {
1271 return uOp(m, (i, a) -> ($type$) Math.log((double) a));
1272 }
1273
1274 /**
1275 * Calculates the base 10 logarithm of this vector.
1276 * <p>
1277 * This is a vector unary operation with same semantic definition as
1278 * {@link Math#log10} operation applied to lane elements.
1279 * The implementation is not required to return same
1280 * results as {@link Math#log10}, but adheres to rounding, monotonicity,
1281 * and special case semantics as defined in the {@link Math#log10}
1282 * specifications. The computed result will be within 1 ulp of the
1283 * exact result.
1284 *
1285 * @return the base 10 logarithm of this vector
1286 */
1287 public $abstractvectortype$ log10() {
1288 return uOp((i, a) -> ($type$) Math.log10((double) a));
1289 }
1290
1291 /**
1292 * Calculates the base 10 logarithm of this vector, selecting lane elements
1293 * controlled by a mask.
1294 * <p>
1295 * Semantics for rounding, monotonicity, and special cases are
1296 * described in {@link $abstractvectortype$#log10}
1297 *
1298 * @param m the mask controlling lane selection
1299 * @return the base 10 logarithm of this vector
1300 */
1301 public $abstractvectortype$ log10(VectorMask<$Boxtype$> m) {
1302 return uOp(m, (i, a) -> ($type$) Math.log10((double) a));
1303 }
1304
1305 /**
1306 * Calculates the natural logarithm of the sum of this vector and the
1307 * broadcast of {@code 1}.
1308 * <p>
1309 * This is a vector unary operation with same semantic definition as
1310 * {@link Math#log1p} operation applied to lane elements.
1311 * The implementation is not required to return same
1312 * results as {@link Math#log1p}, but adheres to rounding, monotonicity,
1313 * and special case semantics as defined in the {@link Math#log1p}
1314 * specifications. The computed result will be within 1 ulp of the
1315 * exact result.
1316 *
1317 * @return the natural logarithm of the sum of this vector and the broadcast
1318 * of {@code 1}
1319 */
1320 public $abstractvectortype$ log1p() {
1321 return uOp((i, a) -> ($type$) Math.log1p((double) a));
1322 }
1323
1324 /**
1325 * Calculates the natural logarithm of the sum of this vector and the
1326 * broadcast of {@code 1}, selecting lane elements controlled by a mask.
1327 * <p>
1328 * Semantics for rounding, monotonicity, and special cases are
1329 * described in {@link $abstractvectortype$#log1p}
1330 *
1331 * @param m the mask controlling lane selection
1332 * @return the natural logarithm of the sum of this vector and the broadcast
1333 * of {@code 1}
1334 */
1335 public $abstractvectortype$ log1p(VectorMask<$Boxtype$> m) {
1336 return uOp(m, (i, a) -> ($type$) Math.log1p((double) a));
1337 }
1338
1339 /**
1340 * Calculates this vector raised to the power of an input vector.
1341 * <p>
1342 * This is a vector binary operation with same semantic definition as
1343 * {@link Math#pow} operation applied to lane elements.
1344 * The implementation is not required to return same
1345 * results as {@link Math#pow}, but adheres to rounding, monotonicity,
1346 * and special case semantics as defined in the {@link Math#pow}
1347 * specifications. The computed result will be within 1 ulp of the
1348 * exact result.
1349 *
1350 * @param v the input vector
1351 * @return this vector raised to the power of an input vector
1352 */
1353 public $abstractvectortype$ pow(Vector<$Boxtype$> v) {
1354 return bOp(v, (i, a, b) -> ($type$) Math.pow((double) a, (double) b));
1355 }
1366 * specifications. The computed result will be within 1 ulp of the
1367 * exact result.
1368 *
1369 * @param s the input scalar
1370 * @return this vector raised to the power of the broadcast of an input
1371 * scalar.
1372 */
1373 public abstract $abstractvectortype$ pow($type$ s);
1374
1375 /**
1376 * Calculates this vector raised to the power of an input vector, selecting
1377 * lane elements controlled by a mask.
1378 * <p>
1379 * Semantics for rounding, monotonicity, and special cases are
1380 * described in {@link $abstractvectortype$#pow}
1381 *
1382 * @param v the input vector
1383 * @param m the mask controlling lane selection
1384 * @return this vector raised to the power of an input vector
1385 */
1386 public $abstractvectortype$ pow(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
1387 return bOp(v, m, (i, a, b) -> ($type$) Math.pow((double) a, (double) b));
1388 }
1389
1390 /**
1391 * Calculates this vector raised to the power of the broadcast of an input
1392 * scalar, selecting lane elements controlled by a mask.
1393 * <p>
1394 * Semantics for rounding, monotonicity, and special cases are
1395 * described in {@link $abstractvectortype$#pow}
1396 *
1397 * @param s the input scalar
1398 * @param m the mask controlling lane selection
1399 * @return this vector raised to the power of the broadcast of an input
1400 * scalar.
1401 */
1402 public abstract $abstractvectortype$ pow($type$ s, VectorMask<$Boxtype$> m);
1403
1404 /**
1405 * Calculates the broadcast of Euler's number {@code e} raised to the power
1406 * of this vector.
1407 * <p>
1408 * This is a vector unary operation with same semantic definition as
1409 * {@link Math#exp} operation applied to lane elements.
1410 * The implementation is not required to return same
1411 * results as {@link Math#exp}, but adheres to rounding, monotonicity,
1412 * and special case semantics as defined in the {@link Math#exp}
1413 * specifications. The computed result will be within 1 ulp of the
1414 * exact result.
1415 *
1416 * @return the broadcast of Euler's number {@code e} raised to the power of
1417 * this vector
1418 */
1419 public $abstractvectortype$ exp() {
1420 return uOp((i, a) -> ($type$) Math.exp((double) a));
1421 }
1422
1423 /**
1424 * Calculates the broadcast of Euler's number {@code e} raised to the power
1425 * of this vector, selecting lane elements controlled by a mask.
1426 * <p>
1427 * Semantics for rounding, monotonicity, and special cases are
1428 * described in {@link $abstractvectortype$#exp}
1429 *
1430 * @param m the mask controlling lane selection
1431 * @return the broadcast of Euler's number {@code e} raised to the power of
1432 * this vector
1433 */
1434 public $abstractvectortype$ exp(VectorMask<$Boxtype$> m) {
1435 return uOp(m, (i, a) -> ($type$) Math.exp((double) a));
1436 }
1437
1438 /**
1439 * Calculates the broadcast of Euler's number {@code e} raised to the power
1440 * of this vector minus the broadcast of {@code -1}.
1441 * More specifically as if the following (ignoring any differences in
1442 * numerical accuracy):
1443 * <pre>{@code
1444 * this.exp().sub(this.species().broadcast(1))
1445 * }</pre>
1446 * <p>
1447 * This is a vector unary operation with same semantic definition as
1448 * {@link Math#expm1} operation applied to lane elements.
1449 * The implementation is not required to return same
1450 * results as {@link Math#expm1}, but adheres to rounding, monotonicity,
1451 * and special case semantics as defined in the {@link Math#expm1}
1452 * specifications. The computed result will be within 1 ulp of the
1453 * exact result.
1454 *
1459 return uOp((i, a) -> ($type$) Math.expm1((double) a));
1460 }
1461
1462 /**
1463 * Calculates the broadcast of Euler's number {@code e} raised to the power
1464 * of this vector minus the broadcast of {@code -1}, selecting lane elements
1465 * controlled by a mask
1466 * More specifically as if the following (ignoring any differences in
1467 * numerical accuracy):
1468 * <pre>{@code
1469 * this.exp(m).sub(this.species().broadcast(1), m)
1470 * }</pre>
1471 * <p>
1472 * Semantics for rounding, monotonicity, and special cases are
1473 * described in {@link $abstractvectortype$#expm1}
1474 *
1475 * @param m the mask controlling lane selection
1476 * @return the broadcast of Euler's number {@code e} raised to the power of
1477 * this vector minus the broadcast of {@code -1}
1478 */
1479 public $abstractvectortype$ expm1(VectorMask<$Boxtype$> m) {
1480 return uOp(m, (i, a) -> ($type$) Math.expm1((double) a));
1481 }
1482
1483 /**
1484 * Calculates the product of this vector and a first input vector summed
1485 * with a second input vector.
1486 * More specifically as if the following (ignoring any differences in
1487 * numerical accuracy):
1488 * <pre>{@code
1489 * this.mul(v1).add(v2)
1490 * }</pre>
1491 * <p>
1492 * This is a vector ternary operation where the {@link Math#fma} operation
1493 * is applied to lane elements.
1494 *
1495 * @param v1 the first input vector
1496 * @param v2 the second input vector
1497 * @return the product of this vector and the first input vector summed with
1498 * the second input vector
1499 */
1518 public abstract $abstractvectortype$ fma($type$ s1, $type$ s2);
1519
1520 /**
1521 * Calculates the product of this vector and a first input vector summed
1522 * with a second input vector, selecting lane elements controlled by a mask.
1523 * More specifically as if the following (ignoring any differences in
1524 * numerical accuracy):
1525 * <pre>{@code
1526 * this.mul(v1, m).add(v2, m)
1527 * }</pre>
1528 * <p>
1529 * This is a vector ternary operation where the {@link Math#fma} operation
1530 * is applied to lane elements.
1531 *
1532 * @param v1 the first input vector
1533 * @param v2 the second input vector
1534 * @param m the mask controlling lane selection
1535 * @return the product of this vector and the first input vector summed with
1536 * the second input vector
1537 */
1538 public $abstractvectortype$ fma(Vector<$Boxtype$> v1, Vector<$Boxtype$> v2, VectorMask<$Boxtype$> m) {
1539 return tOp(v1, v2, m, (i, a, b, c) -> Math.fma(a, b, c));
1540 }
1541
1542 /**
1543 * Calculates the product of this vector and the broadcast of a first input
1544 * scalar summed with the broadcast of a second input scalar, selecting lane
1545 * elements controlled by a mask
1546 * More specifically as if the following:
1547 * <pre>{@code
1548 * this.fma(this.species().broadcast(s1), this.species().broadcast(s2), m)
1549 * }</pre>
1550 * <p>
1551 * This is a vector ternary operation where the {@link Math#fma} operation
1552 * is applied to lane elements.
1553 *
1554 * @param s1 the first input scalar
1555 * @param s2 the second input scalar
1556 * @param m the mask controlling lane selection
1557 * @return the product of this vector and the broadcast of a first input
1558 * scalar summed with the broadcast of a second input scalar
1559 */
1560 public abstract $abstractvectortype$ fma($type$ s1, $type$ s2, VectorMask<$Boxtype$> m);
1561
1562 /**
1563 * Calculates square root of the sum of the squares of this vector and an
1564 * input vector.
1565 * More specifically as if the following (ignoring any differences in
1566 * numerical accuracy):
1567 * <pre>{@code
1568 * this.mul(this).add(v.mul(v)).sqrt()
1569 * }</pre>
1570 * <p>
1571 * This is a vector binary operation with same semantic definition as
1572 * {@link Math#hypot} operation applied to lane elements.
1573 * The implementation is not required to return same
1574 * results as {@link Math#hypot}, but adheres to rounding, monotonicity,
1575 * and special case semantics as defined in the {@link Math#hypot}
1576 * specifications. The computed result will be within 1 ulp of the
1577 * exact result.
1578 *
1579 * @param v the input vector
1580 * @return square root of the sum of the squares of this vector and an input
1607 */
1608 public abstract $abstractvectortype$ hypot($type$ s);
1609
1610 /**
1611 * Calculates square root of the sum of the squares of this vector and an
1612 * input vector, selecting lane elements controlled by a mask.
1613 * More specifically as if the following (ignoring any differences in
1614 * numerical accuracy):
1615 * <pre>{@code
1616 * this.mul(this, m).add(v.mul(v), m).sqrt(m)
1617 * }</pre>
1618 * <p>
1619 * Semantics for rounding, monotonicity, and special cases are
1620 * described in {@link $abstractvectortype$#hypot}
1621 *
1622 * @param v the input vector
1623 * @param m the mask controlling lane selection
1624 * @return square root of the sum of the squares of this vector and an input
1625 * vector
1626 */
1627 public $abstractvectortype$ hypot(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
1628 return bOp(v, m, (i, a, b) -> ($type$) Math.hypot((double) a, (double) b));
1629 }
1630
1631 /**
1632 * Calculates square root of the sum of the squares of this vector and the
1633 * broadcast of an input scalar, selecting lane elements controlled by a
1634 * mask.
1635 * More specifically as if the following (ignoring any differences in
1636 * numerical accuracy):
1637 * <pre>{@code
1638 * this.mul(this, m).add(this.species().broadcast(v * v), m).sqrt(m)
1639 * }</pre>
1640 * <p>
1641 * Semantics for rounding, monotonicity, and special cases are
1642 * described in {@link $abstractvectortype$#hypot}
1643 *
1644 * @param s the input scalar
1645 * @param m the mask controlling lane selection
1646 * @return square root of the sum of the squares of this vector and the
1647 * broadcast of an input scalar
1648 */
1649 public abstract $abstractvectortype$ hypot($type$ s, VectorMask<$Boxtype$> m);
1650 #end[FP]
1651
1652 #if[BITWISE]
1653
1654 /**
1655 * Bitwise ANDs this vector with an input vector.
1656 * <p>
1657 * This is a vector binary operation where the primitive bitwise AND
1658 * operation ({@code &}) is applied to lane elements.
1659 *
1660 * @param v the input vector
1661 * @return the bitwise AND of this vector with the input vector
1662 */
1663 public abstract $abstractvectortype$ and(Vector<$Boxtype$> v);
1664
1665 /**
1666 * Bitwise ANDs this vector with the broadcast of an input scalar.
1667 * <p>
1668 * This is a vector binary operation where the primitive bitwise AND
1669 * operation ({@code &}) is applied to lane elements.
1670 *
1671 * @param s the input scalar
1672 * @return the bitwise AND of this vector with the broadcast of an input
1673 * scalar
1674 */
1675 public abstract $abstractvectortype$ and($type$ s);
1676
1677 /**
1678 * Bitwise ANDs this vector with an input vector, selecting lane elements
1679 * controlled by a mask.
1680 * <p>
1681 * This is a vector binary operation where the primitive bitwise AND
1682 * operation ({@code &}) is applied to lane elements.
1683 *
1684 * @param v the input vector
1685 * @param m the mask controlling lane selection
1686 * @return the bitwise AND of this vector with the input vector
1687 */
1688 public abstract $abstractvectortype$ and(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m);
1689
1690 /**
1691 * Bitwise ANDs this vector with the broadcast of an input scalar, selecting
1692 * lane elements controlled by a mask.
1693 * <p>
1694 * This is a vector binary operation where the primitive bitwise AND
1695 * operation ({@code &}) is applied to lane elements.
1696 *
1697 * @param s the input scalar
1698 * @param m the mask controlling lane selection
1699 * @return the bitwise AND of this vector with the broadcast of an input
1700 * scalar
1701 */
1702 public abstract $abstractvectortype$ and($type$ s, VectorMask<$Boxtype$> m);
1703
1704 /**
1705 * Bitwise ORs this vector with an input vector.
1706 * <p>
1707 * This is a vector binary operation where the primitive bitwise OR
1708 * operation ({@code |}) is applied to lane elements.
1709 *
1710 * @param v the input vector
1711 * @return the bitwise OR of this vector with the input vector
1712 */
1713 public abstract $abstractvectortype$ or(Vector<$Boxtype$> v);
1714
1715 /**
1716 * Bitwise ORs this vector with the broadcast of an input scalar.
1717 * <p>
1718 * This is a vector binary operation where the primitive bitwise OR
1719 * operation ({@code |}) is applied to lane elements.
1720 *
1721 * @param s the input scalar
1722 * @return the bitwise OR of this vector with the broadcast of an input
1723 * scalar
1724 */
1725 public abstract $abstractvectortype$ or($type$ s);
1726
1727 /**
1728 * Bitwise ORs this vector with an input vector, selecting lane elements
1729 * controlled by a mask.
1730 * <p>
1731 * This is a vector binary operation where the primitive bitwise OR
1732 * operation ({@code |}) is applied to lane elements.
1733 *
1734 * @param v the input vector
1735 * @param m the mask controlling lane selection
1736 * @return the bitwise OR of this vector with the input vector
1737 */
1738 public abstract $abstractvectortype$ or(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m);
1739
1740 /**
1741 * Bitwise ORs this vector with the broadcast of an input scalar, selecting
1742 * lane elements controlled by a mask.
1743 * <p>
1744 * This is a vector binary operation where the primitive bitwise OR
1745 * operation ({@code |}) is applied to lane elements.
1746 *
1747 * @param s the input scalar
1748 * @param m the mask controlling lane selection
1749 * @return the bitwise OR of this vector with the broadcast of an input
1750 * scalar
1751 */
1752 public abstract $abstractvectortype$ or($type$ s, VectorMask<$Boxtype$> m);
1753
1754 /**
1755 * Bitwise XORs this vector with an input vector.
1756 * <p>
1757 * This is a vector binary operation where the primitive bitwise XOR
1758 * operation ({@code ^}) is applied to lane elements.
1759 *
1760 * @param v the input vector
1761 * @return the bitwise XOR of this vector with the input vector
1762 */
1763 public abstract $abstractvectortype$ xor(Vector<$Boxtype$> v);
1764
1765 /**
1766 * Bitwise XORs this vector with the broadcast of an input scalar.
1767 * <p>
1768 * This is a vector binary operation where the primitive bitwise XOR
1769 * operation ({@code ^}) is applied to lane elements.
1770 *
1771 * @param s the input scalar
1772 * @return the bitwise XOR of this vector with the broadcast of an input
1773 * scalar
1774 */
1775 public abstract $abstractvectortype$ xor($type$ s);
1776
1777 /**
1778 * Bitwise XORs this vector with an input vector, selecting lane elements
1779 * controlled by a mask.
1780 * <p>
1781 * This is a vector binary operation where the primitive bitwise XOR
1782 * operation ({@code ^}) is applied to lane elements.
1783 *
1784 * @param v the input vector
1785 * @param m the mask controlling lane selection
1786 * @return the bitwise XOR of this vector with the input vector
1787 */
1788 public abstract $abstractvectortype$ xor(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m);
1789
1790 /**
1791 * Bitwise XORs this vector with the broadcast of an input scalar, selecting
1792 * lane elements controlled by a mask.
1793 * <p>
1794 * This is a vector binary operation where the primitive bitwise XOR
1795 * operation ({@code ^}) is applied to lane elements.
1796 *
1797 * @param s the input scalar
1798 * @param m the mask controlling lane selection
1799 * @return the bitwise XOR of this vector with the broadcast of an input
1800 * scalar
1801 */
1802 public abstract $abstractvectortype$ xor($type$ s, VectorMask<$Boxtype$> m);
1803
1804 /**
1805 * Bitwise NOTs this vector.
1806 * <p>
1807 * This is a vector unary operation where the primitive bitwise NOT
1808 * operation ({@code ~}) is applied to lane elements.
1809 *
1810 * @return the bitwise NOT of this vector
1811 */
1812 public abstract $abstractvectortype$ not();
1813
1814 /**
1815 * Bitwise NOTs this vector, selecting lane elements controlled by a mask.
1816 * <p>
1817 * This is a vector unary operation where the primitive bitwise NOT
1818 * operation ({@code ~}) is applied to lane elements.
1819 *
1820 * @param m the mask controlling lane selection
1821 * @return the bitwise NOT of this vector
1822 */
1823 public abstract $abstractvectortype$ not(VectorMask<$Boxtype$> m);
1824
1825 #if[byte]
1826 /**
1827 * Logically left shifts this vector by the broadcast of an input scalar.
1828 * <p>
1829 * This is a vector binary operation where the primitive logical left shift
1830 * operation ({@code <<}) is applied to lane elements to left shift the
1831 * element by shift value as specified by the input scalar. Only the 3
1832 * lowest-order bits of shift value are used. It is as if the shift value
1833 * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0x7.
1834 * The shift distance actually used is therefore always in the range 0 to 7, inclusive.
1835 *
1836 * @param s the input scalar; the number of the bits to left shift
1837 * @return the result of logically left shifting left this vector by the
1838 * broadcast of an input scalar
1839 */
1840 #end[byte]
1841 #if[short]
1842 /**
1843 * Logically left shifts this vector by the broadcast of an input scalar.
1901 * @param s the input scalar; the number of the bits to left shift
1902 * @param m the mask controlling lane selection
1903 * @return the result of logically left shifting left this vector by the
1904 * broadcast of an input scalar
1905 */
1906 #end[short]
1907 #if[intOrLong]
1908 /**
1909 * Logically left shifts this vector by the broadcast of an input scalar,
1910 * selecting lane elements controlled by a mask.
1911 * <p>
1912 * This is a vector binary operation where the primitive logical left shift
1913 * operation ({@code <<}) is applied to lane elements.
1914 *
1915 * @param s the input scalar; the number of the bits to left shift
1916 * @param m the mask controlling lane selection
1917 * @return the result of logically left shifting this vector by the
1918 * broadcast of an input scalar
1919 */
1920 #end[intOrLong]
1921 public abstract $abstractvectortype$ shiftL(int s, VectorMask<$Boxtype$> m);
1922
1923 #if[intOrLong]
1924 /**
1925 * Logically left shifts this vector by an input vector.
1926 * <p>
1927 * This is a vector binary operation where the primitive logical left shift
1928 * operation ({@code <<}) is applied to lane elements.
1929 *
1930 * @param v the input vector
1931 * @return the result of logically left shifting this vector by the input
1932 * vector
1933 */
1934 public abstract $abstractvectortype$ shiftL(Vector<$Boxtype$> v);
1935
1936 /**
1937 * Logically left shifts this vector by an input vector, selecting lane
1938 * elements controlled by a mask.
1939 * <p>
1940 * This is a vector binary operation where the primitive logical left shift
1941 * operation ({@code <<}) is applied to lane elements.
1942 *
1943 * @param v the input vector
1944 * @param m the mask controlling lane selection
1945 * @return the result of logically left shifting this vector by the input
1946 * vector
1947 */
1948 public $abstractvectortype$ shiftL(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
1949 return bOp(v, m, (i, a, b) -> ($type$) (a << b));
1950 }
1951 #end[intOrLong]
1952
1953 // logical, or unsigned, shift right
1954
1955 #if[byte]
1956 /**
1957 * Logically right shifts (or unsigned right shifts) this vector by the
1958 * broadcast of an input scalar.
1959 * <p>
1960 * This is a vector binary operation where the primitive logical right shift
1961 * operation ({@code >>>}) is applied to lane elements to logically right shift the
1962 * element by shift value as specified by the input scalar. Only the 3
1963 * lowest-order bits of shift value are used. It is as if the shift value
1964 * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0x7.
1965 * The shift distance actually used is therefore always in the range 0 to 7, inclusive.
1966 *
1967 * @param s the input scalar; the number of the bits to right shift
1968 * @return the result of logically right shifting this vector by the
2037 * @param m the mask controlling lane selection
2038 * @return the result of logically right shifting this vector by the
2039 * broadcast of an input scalar
2040 */
2041 #end[short]
2042 #if[intOrLong]
2043 /**
2044 * Logically right shifts (or unsigned right shifts) this vector by the
2045 * broadcast of an input scalar, selecting lane elements controlled by a
2046 * mask.
2047 * <p>
2048 * This is a vector binary operation where the primitive logical right shift
2049 * operation ({@code >>>}) is applied to lane elements.
2050 *
2051 * @param s the input scalar; the number of the bits to right shift
2052 * @param m the mask controlling lane selection
2053 * @return the result of logically right shifting this vector by the
2054 * broadcast of an input scalar
2055 */
2056 #end[intOrLong]
2057 public abstract $abstractvectortype$ shiftR(int s, VectorMask<$Boxtype$> m);
2058
2059 #if[intOrLong]
2060 /**
2061 * Logically right shifts (or unsigned right shifts) this vector by an
2062 * input vector.
2063 * <p>
2064 * This is a vector binary operation where the primitive logical right shift
2065 * operation ({@code >>>}) is applied to lane elements.
2066 *
2067 * @param v the input vector
2068 * @return the result of logically right shifting this vector by the
2069 * input vector
2070 */
2071 public abstract $abstractvectortype$ shiftR(Vector<$Boxtype$> v);
2072
2073 /**
2074 * Logically right shifts (or unsigned right shifts) this vector by an
2075 * input vector, selecting lane elements controlled by a mask.
2076 * <p>
2077 * This is a vector binary operation where the primitive logical right shift
2078 * operation ({@code >>>}) is applied to lane elements.
2079 *
2080 * @param v the input vector
2081 * @param m the mask controlling lane selection
2082 * @return the result of logically right shifting this vector by the
2083 * input vector
2084 */
2085 public $abstractvectortype$ shiftR(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
2086 return bOp(v, m, (i, a, b) -> ($type$) (a >>> b));
2087 }
2088 #end[intOrLong]
2089
2090 #if[byte]
2091 /**
2092 * Arithmetically right shifts (or signed right shifts) this vector by the
2093 * broadcast of an input scalar.
2094 * <p>
2095 * This is a vector binary operation where the primitive arithmetic right
2096 * shift operation ({@code >>}) is applied to lane elements to arithmetically
2097 * right shift the element by shift value as specified by the input scalar.
2098 * Only the 3 lowest-order bits of shift value are used. It is as if the shift
2099 * value were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0x7.
2100 * The shift distance actually used is therefore always in the range 0 to 7, inclusive.
2101 *
2102 * @param s the input scalar; the number of the bits to right shift
2103 * @return the result of arithmetically right shifting this vector by the
2104 * broadcast of an input scalar
2105 */
2172 * @param m the mask controlling lane selection
2173 * @return the result of arithmetically right shifting this vector by the
2174 * broadcast of an input scalar
2175 */
2176 #end[short]
2177 #if[intOrLong]
2178 /**
2179 * Arithmetically right shifts (or signed right shifts) this vector by the
2180 * broadcast of an input scalar, selecting lane elements controlled by a
2181 * mask.
2182 * <p>
2183 * This is a vector binary operation where the primitive arithmetic right
2184 * shift operation ({@code >>}) is applied to lane elements.
2185 *
2186 * @param s the input scalar; the number of the bits to right shift
2187 * @param m the mask controlling lane selection
2188 * @return the result of arithmetically right shifting this vector by the
2189 * broadcast of an input scalar
2190 */
2191 #end[intOrLong]
2192 public abstract $abstractvectortype$ aShiftR(int s, VectorMask<$Boxtype$> m);
2193
2194 #if[intOrLong]
2195 /**
2196 * Arithmetically right shifts (or signed right shifts) this vector by an
2197 * input vector.
2198 * <p>
2199 * This is a vector binary operation where the primitive arithmetic right
2200 * shift operation ({@code >>}) is applied to lane elements.
2201 *
2202 * @param v the input vector
2203 * @return the result of arithmetically right shifting this vector by the
2204 * input vector
2205 */
2206 public abstract $abstractvectortype$ aShiftR(Vector<$Boxtype$> v);
2207
2208 /**
2209 * Arithmetically right shifts (or signed right shifts) this vector by an
2210 * input vector, selecting lane elements controlled by a mask.
2211 * <p>
2212 * This is a vector binary operation where the primitive arithmetic right
2213 * shift operation ({@code >>}) is applied to lane elements.
2214 *
2215 * @param v the input vector
2216 * @param m the mask controlling lane selection
2217 * @return the result of arithmetically right shifting this vector by the
2218 * input vector
2219 */
2220 public $abstractvectortype$ aShiftR(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
2221 return bOp(v, m, (i, a, b) -> ($type$) (a >> b));
2222 }
2223
2224 /**
2225 * Rotates left this vector by the broadcast of an input scalar.
2226 * <p>
2227 * This is a vector binary operation where the operation
2228 * {@link $Wideboxtype$#rotateLeft} is applied to lane elements and where
2229 * lane elements of this vector apply to the first argument, and lane
2230 * elements of the broadcast vector apply to the second argument (the
2231 * rotation distance).
2232 *
2233 * @param s the input scalar; the number of the bits to rotate left
2234 * @return the result of rotating left this vector by the broadcast of an
2235 * input scalar
2236 */
2237 @ForceInline
2238 public final $abstractvectortype$ rotateL(int s) {
2239 return shiftL(s).or(shiftR(-s));
2240 }
2241
2242 /**
2243 * Rotates left this vector by the broadcast of an input scalar, selecting
2244 * lane elements controlled by a mask.
2245 * <p>
2246 * This is a vector binary operation where the operation
2247 * {@link $Wideboxtype$#rotateLeft} is applied to lane elements and where
2248 * lane elements of this vector apply to the first argument, and lane
2249 * elements of the broadcast vector apply to the second argument (the
2250 * rotation distance).
2251 *
2252 * @param s the input scalar; the number of the bits to rotate left
2253 * @param m the mask controlling lane selection
2254 * @return the result of rotating left this vector by the broadcast of an
2255 * input scalar
2256 */
2257 @ForceInline
2258 public final $abstractvectortype$ rotateL(int s, VectorMask<$Boxtype$> m) {
2259 return shiftL(s, m).or(shiftR(-s, m), m);
2260 }
2261
2262 /**
2263 * Rotates right this vector by the broadcast of an input scalar.
2264 * <p>
2265 * This is a vector binary operation where the operation
2266 * {@link $Wideboxtype$#rotateRight} is applied to lane elements and where
2267 * lane elements of this vector apply to the first argument, and lane
2268 * elements of the broadcast vector apply to the second argument (the
2269 * rotation distance).
2270 *
2271 * @param s the input scalar; the number of the bits to rotate right
2272 * @return the result of rotating right this vector by the broadcast of an
2273 * input scalar
2274 */
2275 @ForceInline
2276 public final $abstractvectortype$ rotateR(int s) {
2277 return shiftR(s).or(shiftL(-s));
2278 }
2279
2280 /**
2281 * Rotates right this vector by the broadcast of an input scalar, selecting
2282 * lane elements controlled by a mask.
2283 * <p>
2284 * This is a vector binary operation where the operation
2285 * {@link $Wideboxtype$#rotateRight} is applied to lane elements and where
2286 * lane elements of this vector apply to the first argument, and lane
2287 * elements of the broadcast vector apply to the second argument (the
2288 * rotation distance).
2289 *
2290 * @param s the input scalar; the number of the bits to rotate right
2291 * @param m the mask controlling lane selection
2292 * @return the result of rotating right this vector by the broadcast of an
2293 * input scalar
2294 */
2295 @ForceInline
2296 public final $abstractvectortype$ rotateR(int s, VectorMask<$Boxtype$> m) {
2297 return shiftR(s, m).or(shiftL(-s, m), m);
2298 }
2299 #end[intOrLong]
2300 #end[BITWISE]
2301
2302 @Override
2303 public abstract void intoByteArray(byte[] a, int ix);
2304
2305 @Override
2306 public abstract void intoByteArray(byte[] a, int ix, VectorMask<$Boxtype$> m);
2307
2308 @Override
2309 public abstract void intoByteBuffer(ByteBuffer bb, int ix);
2310
2311 @Override
2312 public abstract void intoByteBuffer(ByteBuffer bb, int ix, VectorMask<$Boxtype$> m);
2313
2314
2315 // Type specific horizontal reductions
2316 /**
2317 * Adds all lane elements of this vector.
2318 * <p>
2319 #if[FP]
2320 * This is a vector reduction operation where the addition
2321 * operation ({@code +}) is applied to lane elements,
2322 * and the identity value is {@code 0.0}.
2323 *
2324 * <p>The value of a floating-point sum is a function both of the input values as well
2325 * as the order of addition operations. The order of addition operations of this method
2326 * is intentionally not defined to allow for JVM to generate optimal machine
2327 * code for the underlying platform at runtime. If the platform supports a vector
2328 * instruction to add all values in the vector, or if there is some other efficient machine
2329 * code sequence, then the JVM has the option of generating this machine code. Otherwise,
2330 * the default implementation of adding vectors sequentially from left to right is used.
2331 * For this reason, the output of this method may vary for the same input values.
2332 #else[FP]
2348 * operation ({@code +}) is applied to lane elements,
2349 * and the identity value is {@code 0.0}.
2350 *
2351 * <p>The value of a floating-point sum is a function both of the input values as well
2352 * as the order of addition operations. The order of addition operations of this method
2353 * is intentionally not defined to allow for JVM to generate optimal machine
2354 * code for the underlying platform at runtime. If the platform supports a vector
2355 * instruction to add all values in the vector, or if there is some other efficient machine
2356 * code sequence, then the JVM has the option of generating this machine code. Otherwise,
2357 * the default implementation of adding vectors sequentially from left to right is used.
2358 * For this reason, the output of this method may vary on the same input values.
2359 #else[FP]
2360 * This is an associative vector reduction operation where the addition
2361 * operation ({@code +}) is applied to lane elements,
2362 * and the identity value is {@code 0}.
2363 #end[FP]
2364 *
2365 * @param m the mask controlling lane selection
2366 * @return the addition of the selected lane elements of this vector
2367 */
2368 public abstract $type$ addAll(VectorMask<$Boxtype$> m);
2369
2370 /**
2371 * Multiplies all lane elements of this vector.
2372 * <p>
2373 #if[FP]
2374 * This is a vector reduction operation where the
2375 * multiplication operation ({@code *}) is applied to lane elements,
2376 * and the identity value is {@code 1.0}.
2377 *
2378 * <p>The order of multiplication operations of this method
2379 * is intentionally not defined to allow for JVM to generate optimal machine
2380 * code for the underlying platform at runtime. If the platform supports a vector
2381 * instruction to multiply all values in the vector, or if there is some other efficient machine
2382 * code sequence, then the JVM has the option of generating this machine code. Otherwise,
2383 * the default implementation of multiplying vectors sequentially from left to right is used.
2384 * For this reason, the output of this method may vary on the same input values.
2385 #else[FP]
2386 * This is an associative vector reduction operation where the
2387 * multiplication operation ({@code *}) is applied to lane elements,
2388 * and the identity value is {@code 1}.
2400 * This is a vector reduction operation where the
2401 * multiplication operation ({@code *}) is applied to lane elements,
2402 * and the identity value is {@code 1.0}.
2403 *
2404 * <p>The order of multiplication operations of this method
2405 * is intentionally not defined to allow for JVM to generate optimal machine
2406 * code for the underlying platform at runtime. If the platform supports a vector
2407 * instruction to multiply all values in the vector, or if there is some other efficient machine
2408 * code sequence, then the JVM has the option of generating this machine code. Otherwise,
2409 * the default implementation of multiplying vectors sequentially from left to right is used.
2410 * For this reason, the output of this method may vary on the same input values.
2411 #else[FP]
2412 * This is an associative vector reduction operation where the
2413 * multiplication operation ({@code *}) is applied to lane elements,
2414 * and the identity value is {@code 1}.
2415 #end[FP]
2416 *
2417 * @param m the mask controlling lane selection
2418 * @return the multiplication of all the lane elements of this vector
2419 */
2420 public abstract $type$ mulAll(VectorMask<$Boxtype$> m);
2421
2422 /**
2423 * Returns the minimum lane element of this vector.
2424 * <p>
2425 * This is an associative vector reduction operation where the operation
2426 * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
2427 * and the identity value is
2428 #if[FP]
2429 * {@link $Boxtype$#POSITIVE_INFINITY}.
2430 #else[FP]
2431 * {@link $Boxtype$#MAX_VALUE}.
2432 #end[FP]
2433 *
2434 * @return the minimum lane element of this vector
2435 */
2436 public abstract $type$ minAll();
2437
2438 /**
2439 * Returns the minimum lane element of this vector, selecting lane elements
2440 * controlled by a mask.
2441 * <p>
2442 * This is an associative vector reduction operation where the operation
2443 * {@code (a, b) -> Math.min(a, b)} is applied to lane elements,
2444 * and the identity value is
2445 #if[FP]
2446 * {@link $Boxtype$#POSITIVE_INFINITY}.
2447 #else[FP]
2448 * {@link $Boxtype$#MAX_VALUE}.
2449 #end[FP]
2450 *
2451 * @param m the mask controlling lane selection
2452 * @return the minimum lane element of this vector
2453 */
2454 public abstract $type$ minAll(VectorMask<$Boxtype$> m);
2455
2456 /**
2457 * Returns the maximum lane element of this vector.
2458 * <p>
2459 * This is an associative vector reduction operation where the operation
2460 * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
2461 * and the identity value is
2462 #if[FP]
2463 * {@link $Boxtype$#NEGATIVE_INFINITY}.
2464 #else[FP]
2465 * {@link $Boxtype$#MIN_VALUE}.
2466 #end[FP]
2467 *
2468 * @return the maximum lane element of this vector
2469 */
2470 public abstract $type$ maxAll();
2471
2472 /**
2473 * Returns the maximum lane element of this vector, selecting lane elements
2474 * controlled by a mask.
2475 * <p>
2476 * This is an associative vector reduction operation where the operation
2477 * {@code (a, b) -> Math.max(a, b)} is applied to lane elements,
2478 * and the identity value is
2479 #if[FP]
2480 * {@link $Boxtype$#NEGATIVE_INFINITY}.
2481 #else[FP]
2482 * {@link $Boxtype$#MIN_VALUE}.
2483 #end[FP]
2484 *
2485 * @param m the mask controlling lane selection
2486 * @return the maximum lane element of this vector
2487 */
2488 public abstract $type$ maxAll(VectorMask<$Boxtype$> m);
2489
2490 #if[BITWISE]
2491 /**
2492 * Logically ORs all lane elements of this vector.
2493 * <p>
2494 * This is an associative vector reduction operation where the logical OR
2495 * operation ({@code |}) is applied to lane elements,
2496 * and the identity value is {@code 0}.
2497 *
2498 * @return the logical OR all the lane elements of this vector
2499 */
2500 public abstract $type$ orAll();
2501
2502 /**
2503 * Logically ORs all lane elements of this vector, selecting lane elements
2504 * controlled by a mask.
2505 * <p>
2506 * This is an associative vector reduction operation where the logical OR
2507 * operation ({@code |}) is applied to lane elements,
2508 * and the identity value is {@code 0}.
2509 *
2510 * @param m the mask controlling lane selection
2511 * @return the logical OR all the lane elements of this vector
2512 */
2513 public abstract $type$ orAll(VectorMask<$Boxtype$> m);
2514
2515 /**
2516 * Logically ANDs all lane elements of this vector.
2517 * <p>
2518 * This is an associative vector reduction operation where the logical AND
2519 * operation ({@code |}) is applied to lane elements,
2520 * and the identity value is {@code -1}.
2521 *
2522 * @return the logical AND all the lane elements of this vector
2523 */
2524 public abstract $type$ andAll();
2525
2526 /**
2527 * Logically ANDs all lane elements of this vector, selecting lane elements
2528 * controlled by a mask.
2529 * <p>
2530 * This is an associative vector reduction operation where the logical AND
2531 * operation ({@code |}) is applied to lane elements,
2532 * and the identity value is {@code -1}.
2533 *
2534 * @param m the mask controlling lane selection
2535 * @return the logical AND all the lane elements of this vector
2536 */
2537 public abstract $type$ andAll(VectorMask<$Boxtype$> m);
2538
2539 /**
2540 * Logically XORs all lane elements of this vector.
2541 * <p>
2542 * This is an associative vector reduction operation where the logical XOR
2543 * operation ({@code ^}) is applied to lane elements,
2544 * and the identity value is {@code 0}.
2545 *
2546 * @return the logical XOR all the lane elements of this vector
2547 */
2548 public abstract $type$ xorAll();
2549
2550 /**
2551 * Logically XORs all lane elements of this vector, selecting lane elements
2552 * controlled by a mask.
2553 * <p>
2554 * This is an associative vector reduction operation where the logical XOR
2555 * operation ({@code ^}) is applied to lane elements,
2556 * and the identity value is {@code 0}.
2557 *
2558 * @param m the mask controlling lane selection
2559 * @return the logical XOR all the lane elements of this vector
2560 */
2561 public abstract $type$ xorAll(VectorMask<$Boxtype$> m);
2562 #end[BITWISE]
2563
2564 // Type specific accessors
2565
2566 /**
2567 * Gets the lane element at lane index {@code i}
2568 *
2569 * @param i the lane index
2570 * @return the lane element at lane index {@code i}
2571 * @throws IllegalArgumentException if the index is is out of range
2572 * ({@code < 0 || >= length()})
2573 */
2574 public abstract $type$ get(int i);
2575
2576 /**
2577 * Replaces the lane element of this vector at lane index {@code i} with
2578 * value {@code e}.
2579 * <p>
2580 * This is a cross-lane operation and behaves as if it returns the result
2581 * of blending this vector with an input vector that is the result of
2624 * @param i the offset into the array
2625 * @throws IndexOutOfBoundsException if {@code i < 0}, or
2626 * {@code i > a.length - this.length()}
2627 */
2628 public abstract void intoArray($type$[] a, int i);
2629
2630 /**
2631 * Stores this vector into an array starting at offset and using a mask.
2632 * <p>
2633 * For each vector lane, where {@code N} is the vector lane index,
2634 * if the mask lane at index {@code N} is set then the lane element at
2635 * index {@code N} is stored into the array index {@code i + N}.
2636 *
2637 * @param a the array
2638 * @param i the offset into the array
2639 * @param m the mask
2640 * @throws IndexOutOfBoundsException if {@code i < 0}, or
2641 * for any vector lane index {@code N} where the mask at lane {@code N}
2642 * is set {@code i >= a.length - N}
2643 */
2644 public abstract void intoArray($type$[] a, int i, VectorMask<$Boxtype$> m);
2645
2646 /**
2647 * Stores this vector into an array using indexes obtained from an index
2648 * map.
2649 * <p>
2650 * For each vector lane, where {@code N} is the vector lane index, the
2651 * lane element at index {@code N} is stored into the array at index
2652 * {@code i + indexMap[j + N]}.
2653 *
2654 * @param a the array
2655 * @param i the offset into the array, may be negative if relative
2656 * indexes in the index map compensate to produce a value within the
2657 * array bounds
2658 * @param indexMap the index map
2659 * @param j the offset into the index map
2660 * @throws IndexOutOfBoundsException if {@code j < 0}, or
2661 * {@code j > indexMap.length - this.length()},
2662 * or for any vector lane index {@code N} the result of
2663 * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length}
2664 */
2676 * <p>
2677 * For each vector lane, where {@code N} is the vector lane index,
2678 * if the mask lane at index {@code N} is set then the lane element at
2679 * index {@code N} is stored into the array at index
2680 * {@code i + indexMap[j + N]}.
2681 *
2682 * @param a the array
2683 * @param i the offset into the array, may be negative if relative
2684 * indexes in the index map compensate to produce a value within the
2685 * array bounds
2686 * @param m the mask
2687 * @param indexMap the index map
2688 * @param j the offset into the index map
2689 * @throws IndexOutOfBoundsException if {@code j < 0}, or
2690 * {@code j > indexMap.length - this.length()},
2691 * or for any vector lane index {@code N} where the mask at lane
2692 * {@code N} is set the result of {@code i + indexMap[j + N]} is
2693 * {@code < 0} or {@code >= a.length}
2694 */
2695 #if[byteOrShort]
2696 public void intoArray($type$[] a, int i, VectorMask<$Boxtype$> m, int[] indexMap, int j) {
2697 forEach(m, (n, e) -> a[i + indexMap[j + n]] = e);
2698 }
2699 #else[byteOrShort]
2700 public abstract void intoArray($type$[] a, int i, VectorMask<$Boxtype$> m, int[] indexMap, int j);
2701 #end[byteOrShort]
2702 // Species
2703
2704 @Override
2705 public abstract VectorSpecies<$Boxtype$> species();
2706
2707 /**
2708 * Class representing {@link $abstractvectortype$}'s of the same {@link VectorShape VectorShape}.
2709 */
2710 static final class $Type$Species extends AbstractSpecies<$Boxtype$> {
2711 final Function<$type$[], $Type$Vector> vectorFactory;
2712
2713 private $Type$Species(VectorShape shape,
2714 Class<?> boxType,
2715 Class<?> maskType,
2716 Function<$type$[], $Type$Vector> vectorFactory,
2717 Function<boolean[], VectorMask<$Boxtype$>> maskFactory,
2718 Function<IntUnaryOperator, VectorShuffle<$Boxtype$>> shuffleFromArrayFactory,
2719 fShuffleFromArray<$Boxtype$> shuffleFromOpFactory) {
2720 super(shape, $type$.class, $Boxtype$.SIZE, boxType, maskType, maskFactory,
2721 shuffleFromArrayFactory, shuffleFromOpFactory);
2722 this.vectorFactory = vectorFactory;
2723 }
2724
2725 interface FOp {
2726 $type$ apply(int i);
2727 }
2728
2729 $Type$Vector op(FOp f) {
2730 $type$[] res = new $type$[length()];
2731 for (int i = 0; i < length(); i++) {
2732 res[i] = f.apply(i);
2733 }
2734 return vectorFactory.apply(res);
2735 }
2736
2737 $Type$Vector op(VectorMask<$Boxtype$> o, FOp f) {
2738 $type$[] res = new $type$[length()];
2739 boolean[] mbits = ((AbstractMask<$Boxtype$>)o).getBits();
2740 for (int i = 0; i < length(); i++) {
2741 if (mbits[i]) {
2742 res[i] = f.apply(i);
2743 }
2744 }
2745 return vectorFactory.apply(res);
2746 }
2747 }
2748
2749 /**
2750 * Finds the preferred species for an element type of {@code $type$}.
2751 * <p>
2752 * A preferred species is a species chosen by the platform that has a
2753 * shape of maximal bit size. A preferred species for different element
2754 * types will have the same shape, and therefore vectors, masks, and
2755 * shuffles created from such species will be shape compatible.
2756 *
2757 * @return the preferred species for an element type of {@code $type$}
2758 */
2759 private static $Type$Species preferredSpecies() {
2760 return ($Type$Species) VectorSpecies.ofPreferred($type$.class);
2761 }
2762
2763 /**
2764 * Finds a species for an element type of {@code $type$} and shape.
2765 *
2766 * @param s the shape
2767 * @return a species for an element type of {@code $type$} and shape
2768 * @throws IllegalArgumentException if no such species exists for the shape
2769 */
2770 static $Type$Species species(VectorShape s) {
2771 Objects.requireNonNull(s);
2772 switch (s) {
2773 case S_64_BIT: return ($Type$Species) SPECIES_64;
2774 case S_128_BIT: return ($Type$Species) SPECIES_128;
2775 case S_256_BIT: return ($Type$Species) SPECIES_256;
2776 case S_512_BIT: return ($Type$Species) SPECIES_512;
2777 case S_Max_BIT: return ($Type$Species) SPECIES_MAX;
2778 default: throw new IllegalArgumentException("Bad shape: " + s);
2779 }
2780 }
2781
2782 /** Species representing {@link $Type$Vector}s of {@link VectorShape#S_64_BIT VectorShape.S_64_BIT}. */
2783 public static final VectorSpecies<$Boxtype$> SPECIES_64 = new $Type$Species(VectorShape.S_64_BIT, $Type$64Vector.class, $Type$64Vector.$Type$64Mask.class,
2784 $Type$64Vector::new, $Type$64Vector.$Type$64Mask::new,
2785 $Type$64Vector.$Type$64Shuffle::new, $Type$64Vector.$Type$64Shuffle::new);
2786
2787 /** Species representing {@link $Type$Vector}s of {@link VectorShape#S_128_BIT VectorShape.S_128_BIT}. */
2788 public static final VectorSpecies<$Boxtype$> SPECIES_128 = new $Type$Species(VectorShape.S_128_BIT, $Type$128Vector.class, $Type$128Vector.$Type$128Mask.class,
2789 $Type$128Vector::new, $Type$128Vector.$Type$128Mask::new,
2790 $Type$128Vector.$Type$128Shuffle::new, $Type$128Vector.$Type$128Shuffle::new);
2791
2792 /** Species representing {@link $Type$Vector}s of {@link VectorShape#S_256_BIT VectorShape.S_256_BIT}. */
2793 public static final VectorSpecies<$Boxtype$> SPECIES_256 = new $Type$Species(VectorShape.S_256_BIT, $Type$256Vector.class, $Type$256Vector.$Type$256Mask.class,
2794 $Type$256Vector::new, $Type$256Vector.$Type$256Mask::new,
2795 $Type$256Vector.$Type$256Shuffle::new, $Type$256Vector.$Type$256Shuffle::new);
2796
2797 /** Species representing {@link $Type$Vector}s of {@link VectorShape#S_512_BIT VectorShape.S_512_BIT}. */
2798 public static final VectorSpecies<$Boxtype$> SPECIES_512 = new $Type$Species(VectorShape.S_512_BIT, $Type$512Vector.class, $Type$512Vector.$Type$512Mask.class,
2799 $Type$512Vector::new, $Type$512Vector.$Type$512Mask::new,
2800 $Type$512Vector.$Type$512Shuffle::new, $Type$512Vector.$Type$512Shuffle::new);
2801
2802 /** Species representing {@link $Type$Vector}s of {@link VectorShape#S_Max_BIT VectorShape.S_Max_BIT}. */
2803 public static final VectorSpecies<$Boxtype$> SPECIES_MAX = new $Type$Species(VectorShape.S_Max_BIT, $Type$MaxVector.class, $Type$MaxVector.$Type$MaxMask.class,
2804 $Type$MaxVector::new, $Type$MaxVector.$Type$MaxMask::new,
2805 $Type$MaxVector.$Type$MaxShuffle::new, $Type$MaxVector.$Type$MaxShuffle::new);
2806
2807 /**
2808 * Preferred species for {@link $Type$Vector}s.
2809 * A preferred species is a species of maximal bit size for the platform.
2810 */
2811 public static final VectorSpecies<$Boxtype$> SPECIES_PREFERRED = (VectorSpecies<$Boxtype$>) preferredSpecies();
2812 }
|