23 * questions.
24 */
25 package jdk.incubator.vector;
26
27 import java.nio.ByteBuffer;
28 import java.nio.ByteOrder;
29 #if[!byte]
30 import java.nio.$Type$Buffer;
31 #end[!byte]
32 import java.nio.ReadOnlyBufferException;
33 import java.util.Arrays;
34 import java.util.Objects;
35 import java.util.function.IntUnaryOperator;
36
37 import jdk.internal.misc.Unsafe;
38 import jdk.internal.vm.annotation.ForceInline;
39 import static jdk.incubator.vector.VectorIntrinsics.*;
40
41 @SuppressWarnings("cast")
42 final class $vectortype$ extends $abstractvectortype$ {
43 private static final Species<$Boxtype$> SPECIES = $Type$Vector.SPECIES_$BITS$;
44
45 static final $vectortype$ ZERO = new $vectortype$();
46
47 static final int LENGTH = SPECIES.length();
48
49 #if[!byteOrShort]
50 // Index vector species
51 private static final IntVector.IntSpecies INDEX_SPECIES;
52
53 static {
54 #if[longOrDouble64]
55 INDEX_SPECIES = (IntVector.IntSpecies) IntVector.species(Shape.S_64_BIT);
56 #else[longOrDouble64]
57 int bitSize = Vector.bitSizeForVectorLength(int.class, LENGTH);
58 INDEX_SPECIES = (IntVector.IntSpecies) IntVector.species(Shape.forBitSize(bitSize));
59 #end[longOrDouble64]
60 }
61
62 #end[!byteOrShort]
63 private final $type$[] vec; // Don't access directly, use getElements() instead.
64
65 private $type$[] getElements() {
66 return VectorIntrinsics.maybeRebox(this).vec;
67 }
68
69 $vectortype$() {
70 vec = new $type$[SPECIES.length()];
71 }
72
73 $vectortype$($type$[] v) {
74 vec = v;
75 }
76
77 @Override
78 public int length() { return LENGTH; }
79
80 // Unary operator
81
82 @Override
83 $vectortype$ uOp(FUnOp f) {
84 $type$[] vec = getElements();
85 $type$[] res = new $type$[length()];
86 for (int i = 0; i < length(); i++) {
87 res[i] = f.apply(i, vec[i]);
88 }
89 return new $vectortype$(res);
90 }
91
92 @Override
93 $vectortype$ uOp(Mask<$Boxtype$> o, FUnOp f) {
94 $type$[] vec = getElements();
95 $type$[] res = new $type$[length()];
96 boolean[] mbits = (($masktype$)o).getBits();
97 for (int i = 0; i < length(); i++) {
98 res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
99 }
100 return new $vectortype$(res);
101 }
102
103 // Binary operator
104
105 @Override
106 $vectortype$ bOp(Vector<$Boxtype$> o, FBinOp f) {
107 $type$[] res = new $type$[length()];
108 $type$[] vec1 = this.getElements();
109 $type$[] vec2 = (($vectortype$)o).getElements();
110 for (int i = 0; i < length(); i++) {
111 res[i] = f.apply(i, vec1[i], vec2[i]);
112 }
113 return new $vectortype$(res);
114 }
115
116 @Override
117 $vectortype$ bOp(Vector<$Boxtype$> o1, Mask<$Boxtype$> o2, FBinOp f) {
118 $type$[] res = new $type$[length()];
119 $type$[] vec1 = this.getElements();
120 $type$[] vec2 = (($vectortype$)o1).getElements();
121 boolean[] mbits = (($masktype$)o2).getBits();
122 for (int i = 0; i < length(); i++) {
123 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
124 }
125 return new $vectortype$(res);
126 }
127
128 // Trinary operator
129
130 @Override
131 $vectortype$ tOp(Vector<$Boxtype$> o1, Vector<$Boxtype$> o2, FTriOp f) {
132 $type$[] res = new $type$[length()];
133 $type$[] vec1 = this.getElements();
134 $type$[] vec2 = (($vectortype$)o1).getElements();
135 $type$[] vec3 = (($vectortype$)o2).getElements();
136 for (int i = 0; i < length(); i++) {
137 res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
138 }
139 return new $vectortype$(res);
140 }
141
142 @Override
143 $vectortype$ tOp(Vector<$Boxtype$> o1, Vector<$Boxtype$> o2, Mask<$Boxtype$> o3, FTriOp f) {
144 $type$[] res = new $type$[length()];
145 $type$[] vec1 = getElements();
146 $type$[] vec2 = (($vectortype$)o1).getElements();
147 $type$[] vec3 = (($vectortype$)o2).getElements();
148 boolean[] mbits = (($masktype$)o3).getBits();
149 for (int i = 0; i < length(); i++) {
150 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
151 }
152 return new $vectortype$(res);
153 }
154
155 @Override
156 $type$ rOp($type$ v, FBinOp f) {
157 $type$[] vec = getElements();
158 for (int i = 0; i < length(); i++) {
159 v = f.apply(i, v, vec[i]);
160 }
161 return v;
162 }
163
164 @Override
165 @ForceInline
166 public <F> Vector<F> cast(Species<F> s) {
167 Objects.requireNonNull(s);
168 if (s.length() != LENGTH)
169 throw new IllegalArgumentException("Vector length this species length differ");
170
171 return VectorIntrinsics.cast(
172 $vectortype$.class,
173 $type$.class, LENGTH,
174 s.boxType(),
175 s.elementType(), LENGTH,
176 this, s,
177 (species, vector) -> vector.castDefault(species)
178 );
179 }
180
181 @SuppressWarnings("unchecked")
182 @ForceInline
183 private <F> Vector<F> castDefault(Species<F> s) {
184 int limit = s.length();
185
186 Class<?> stype = s.elementType();
187 if (stype == byte.class) {
188 byte[] a = new byte[limit];
189 for (int i = 0; i < limit; i++) {
190 a[i] = (byte) this.get(i);
191 }
192 return (Vector) ByteVector.fromArray((Species<Byte>) s, a, 0);
193 } else if (stype == short.class) {
194 short[] a = new short[limit];
195 for (int i = 0; i < limit; i++) {
196 a[i] = (short) this.get(i);
197 }
198 return (Vector) ShortVector.fromArray((Species<Short>) s, a, 0);
199 } else if (stype == int.class) {
200 int[] a = new int[limit];
201 for (int i = 0; i < limit; i++) {
202 a[i] = (int) this.get(i);
203 }
204 return (Vector) IntVector.fromArray((Species<Integer>) s, a, 0);
205 } else if (stype == long.class) {
206 long[] a = new long[limit];
207 for (int i = 0; i < limit; i++) {
208 a[i] = (long) this.get(i);
209 }
210 return (Vector) LongVector.fromArray((Species<Long>) s, a, 0);
211 } else if (stype == float.class) {
212 float[] a = new float[limit];
213 for (int i = 0; i < limit; i++) {
214 a[i] = (float) this.get(i);
215 }
216 return (Vector) FloatVector.fromArray((Species<Float>) s, a, 0);
217 } else if (stype == double.class) {
218 double[] a = new double[limit];
219 for (int i = 0; i < limit; i++) {
220 a[i] = (double) this.get(i);
221 }
222 return (Vector) DoubleVector.fromArray((Species<Double>) s, a, 0);
223 } else {
224 throw new UnsupportedOperationException("Bad lane type for casting.");
225 }
226 }
227
228 @Override
229 @ForceInline
230 @SuppressWarnings("unchecked")
231 public <F> Vector<F> reinterpret(Species<F> s) {
232 Objects.requireNonNull(s);
233
234 if(s.elementType().equals($type$.class)) {
235 return (Vector<F>) reshape((Species<$Boxtype$>)s);
236 }
237 if(s.bitSize() == bitSize()) {
238 return reinterpretType(s);
239 }
240
241 return defaultReinterpret(s);
242 }
243
244 @ForceInline
245 private <F> Vector<F> reinterpretType(Species<F> s) {
246 Objects.requireNonNull(s);
247
248 Class<?> stype = s.elementType();
249 if (stype == byte.class) {
250 return VectorIntrinsics.reinterpret(
251 $vectortype$.class,
252 $type$.class, LENGTH,
253 Byte$bits$Vector.class,
254 byte.class, Byte$bits$Vector.LENGTH,
255 this, s,
256 (species, vector) -> vector.defaultReinterpret(species)
257 );
258 } else if (stype == short.class) {
259 return VectorIntrinsics.reinterpret(
260 $vectortype$.class,
261 $type$.class, LENGTH,
262 Short$bits$Vector.class,
263 short.class, Short$bits$Vector.LENGTH,
264 this, s,
265 (species, vector) -> vector.defaultReinterpret(species)
290 float.class, Float$bits$Vector.LENGTH,
291 this, s,
292 (species, vector) -> vector.defaultReinterpret(species)
293 );
294 } else if (stype == double.class) {
295 return VectorIntrinsics.reinterpret(
296 $vectortype$.class,
297 $type$.class, LENGTH,
298 Double$bits$Vector.class,
299 double.class, Double$bits$Vector.LENGTH,
300 this, s,
301 (species, vector) -> vector.defaultReinterpret(species)
302 );
303 } else {
304 throw new UnsupportedOperationException("Bad lane type for casting.");
305 }
306 }
307
308 @Override
309 @ForceInline
310 public $abstractvectortype$ reshape(Species<$Boxtype$> s) {
311 Objects.requireNonNull(s);
312 if (s.bitSize() == 64 && (s.boxType() == $Type$64Vector.class)) {
313 return VectorIntrinsics.reinterpret(
314 $vectortype$.class,
315 $type$.class, LENGTH,
316 $Type$64Vector.class,
317 $type$.class, $Type$64Vector.LENGTH,
318 this, s,
319 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
320 );
321 } else if (s.bitSize() == 128 && (s.boxType() == $Type$128Vector.class)) {
322 return VectorIntrinsics.reinterpret(
323 $vectortype$.class,
324 $type$.class, LENGTH,
325 $Type$128Vector.class,
326 $type$.class, $Type$128Vector.LENGTH,
327 this, s,
328 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
329 );
330 } else if (s.bitSize() == 256 && (s.boxType() == $Type$256Vector.class)) {
353 $Type$MaxVector.class,
354 $type$.class, $Type$MaxVector.LENGTH,
355 this, s,
356 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
357 );
358 } else {
359 throw new InternalError("Unimplemented size");
360 }
361 }
362
363 // Binary operations with scalars
364
365 @Override
366 @ForceInline
367 public $abstractvectortype$ add($type$ o) {
368 return add(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
369 }
370
371 @Override
372 @ForceInline
373 public $abstractvectortype$ add($type$ o, Mask<$Boxtype$> m) {
374 return add(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
375 }
376
377 @Override
378 @ForceInline
379 public $abstractvectortype$ sub($type$ o) {
380 return sub(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
381 }
382
383 @Override
384 @ForceInline
385 public $abstractvectortype$ sub($type$ o, Mask<$Boxtype$> m) {
386 return sub(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
387 }
388
389 @Override
390 @ForceInline
391 public $abstractvectortype$ mul($type$ o) {
392 return mul(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
393 }
394
395 @Override
396 @ForceInline
397 public $abstractvectortype$ mul($type$ o, Mask<$Boxtype$> m) {
398 return mul(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
399 }
400
401 @Override
402 @ForceInline
403 public $abstractvectortype$ min($type$ o) {
404 return min(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
405 }
406
407 @Override
408 @ForceInline
409 public $abstractvectortype$ max($type$ o) {
410 return max(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
411 }
412
413 @Override
414 @ForceInline
415 public Mask<$Boxtype$> equal($type$ o) {
416 return equal(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
417 }
418
419 @Override
420 @ForceInline
421 public Mask<$Boxtype$> notEqual($type$ o) {
422 return notEqual(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
423 }
424
425 @Override
426 @ForceInline
427 public Mask<$Boxtype$> lessThan($type$ o) {
428 return lessThan(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
429 }
430
431 @Override
432 @ForceInline
433 public Mask<$Boxtype$> lessThanEq($type$ o) {
434 return lessThanEq(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
435 }
436
437 @Override
438 @ForceInline
439 public Mask<$Boxtype$> greaterThan($type$ o) {
440 return greaterThan(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
441 }
442
443 @Override
444 @ForceInline
445 public Mask<$Boxtype$> greaterThanEq($type$ o) {
446 return greaterThanEq(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
447 }
448
449 @Override
450 @ForceInline
451 public $abstractvectortype$ blend($type$ o, Mask<$Boxtype$> m) {
452 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
453 }
454
455 #if[FP]
456 @Override
457 @ForceInline
458 public $abstractvectortype$ div($type$ o) {
459 return div(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
460 }
461
462 @Override
463 @ForceInline
464 public $abstractvectortype$ div($type$ o, Mask<$Boxtype$> m) {
465 return div(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
466 }
467
468 @Override
469 @ForceInline
470 public $vectortype$ div(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
471 return blend(div(v), m);
472 }
473
474 @Override
475 @ForceInline
476 public $abstractvectortype$ atan2($type$ o) {
477 return atan2(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
478 }
479
480 @Override
481 @ForceInline
482 public $abstractvectortype$ atan2($type$ o, Mask<$Boxtype$> m) {
483 return atan2(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
484 }
485
486 @Override
487 @ForceInline
488 public $abstractvectortype$ pow($type$ o) {
489 return pow(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
490 }
491
492 @Override
493 @ForceInline
494 public $abstractvectortype$ pow($type$ o, Mask<$Boxtype$> m) {
495 return pow(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
496 }
497
498 @Override
499 @ForceInline
500 public $abstractvectortype$ fma($type$ o1, $type$ o2) {
501 return fma(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o1), ($vectortype$)$abstractvectortype$.broadcast(SPECIES, o2));
502 }
503
504 @Override
505 @ForceInline
506 public $abstractvectortype$ fma($type$ o1, $type$ o2, Mask<$Boxtype$> m) {
507 return fma(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o1), ($vectortype$)$abstractvectortype$.broadcast(SPECIES, o2), m);
508 }
509
510 @Override
511 @ForceInline
512 public $abstractvectortype$ hypot($type$ o) {
513 return hypot(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
514 }
515
516 @Override
517 @ForceInline
518 public $abstractvectortype$ hypot($type$ o, Mask<$Boxtype$> m) {
519 return hypot(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
520 }
521 #end[FP]
522
523 #if[BITWISE]
524 @Override
525 @ForceInline
526 public $abstractvectortype$ and($type$ o) {
527 return and(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
528 }
529
530 @Override
531 @ForceInline
532 public $abstractvectortype$ and($type$ o, Mask<$Boxtype$> m) {
533 return and(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
534 }
535
536 @Override
537 @ForceInline
538 public $abstractvectortype$ or($type$ o) {
539 return or(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
540 }
541
542 @Override
543 @ForceInline
544 public $abstractvectortype$ or($type$ o, Mask<$Boxtype$> m) {
545 return or(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
546 }
547
548 @Override
549 @ForceInline
550 public $abstractvectortype$ xor($type$ o) {
551 return xor(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
552 }
553
554 @Override
555 @ForceInline
556 public $abstractvectortype$ xor($type$ o, Mask<$Boxtype$> m) {
557 return xor(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
558 }
559
560 @Override
561 @ForceInline
562 public $vectortype$ neg() {
563 return ($vectortype$)zero(SPECIES).sub(this);
564 }
565 #end[BITWISE]
566
567 // Unary operations
568
569 @ForceInline
570 @Override
571 public $vectortype$ neg(Mask<$Boxtype$> m) {
572 return blend(neg(), m);
573 }
574
575 @Override
576 @ForceInline
577 public $vectortype$ abs() {
578 return VectorIntrinsics.unaryOp(
579 VECTOR_OP_ABS, $vectortype$.class, $type$.class, LENGTH,
580 this,
581 v1 -> v1.uOp((i, a) -> ($type$) Math.abs(a)));
582 }
583
584 @ForceInline
585 @Override
586 public $vectortype$ abs(Mask<$Boxtype$> m) {
587 return blend(abs(), m);
588 }
589
590 #if[FP]
591 @Override
592 @ForceInline
593 public $vectortype$ neg() {
594 return VectorIntrinsics.unaryOp(
595 VECTOR_OP_NEG, $vectortype$.class, $type$.class, LENGTH,
596 this,
597 v1 -> v1.uOp((i, a) -> ($type$) -a));
598 }
599
600 @Override
601 @ForceInline
602 public $vectortype$ div(Vector<$Boxtype$> o) {
603 Objects.requireNonNull(o);
604 $vectortype$ v = ($vectortype$)o;
605 return VectorIntrinsics.binaryOp(
606 VECTOR_OP_DIV, $vectortype$.class, $type$.class, LENGTH,
782 return ($vectortype$) VectorIntrinsics.binaryOp(
783 VECTOR_OP_ATAN2, $vectortype$.class, $type$.class, LENGTH,
784 this, v,
785 (v1, v2) -> (($vectortype$)v1).bOp(v2, (i, a, b) -> ($type$)(Math.atan2(a,b))));
786 }
787
788 #end[FP]
789
790 #if[BITWISE]
791 @Override
792 @ForceInline
793 public $vectortype$ not() {
794 return VectorIntrinsics.unaryOp(
795 VECTOR_OP_NOT, $vectortype$.class, $type$.class, LENGTH,
796 this,
797 v1 -> v1.uOp((i, a) -> ($type$) ~a));
798 }
799
800 @ForceInline
801 @Override
802 public $vectortype$ not(Mask<$Boxtype$> m) {
803 return blend(not(), m);
804 }
805 #end[BITWISE]
806 // Binary operations
807
808 @Override
809 @ForceInline
810 public $vectortype$ add(Vector<$Boxtype$> o) {
811 Objects.requireNonNull(o);
812 $vectortype$ v = ($vectortype$)o;
813 return VectorIntrinsics.binaryOp(
814 VECTOR_OP_ADD, $vectortype$.class, $type$.class, LENGTH,
815 this, v,
816 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$)(a + b)));
817 }
818
819 @Override
820 @ForceInline
821 public $vectortype$ add(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
822 return blend(add(v), m);
823 }
824
825 @Override
826 @ForceInline
827 public $vectortype$ sub(Vector<$Boxtype$> o) {
828 Objects.requireNonNull(o);
829 $vectortype$ v = ($vectortype$)o;
830 return VectorIntrinsics.binaryOp(
831 VECTOR_OP_SUB, $vectortype$.class, $type$.class, LENGTH,
832 this, v,
833 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$)(a - b)));
834 }
835
836 @Override
837 @ForceInline
838 public $vectortype$ sub(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
839 return blend(sub(v), m);
840 }
841
842 @Override
843 @ForceInline
844 public $vectortype$ mul(Vector<$Boxtype$> o) {
845 Objects.requireNonNull(o);
846 $vectortype$ v = ($vectortype$)o;
847 return VectorIntrinsics.binaryOp(
848 VECTOR_OP_MUL, $vectortype$.class, $type$.class, LENGTH,
849 this, v,
850 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$)(a * b)));
851 }
852
853 @Override
854 @ForceInline
855 public $vectortype$ mul(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
856 return blend(mul(v), m);
857 }
858
859 @Override
860 @ForceInline
861 public $vectortype$ min(Vector<$Boxtype$> o) {
862 Objects.requireNonNull(o);
863 $vectortype$ v = ($vectortype$)o;
864 return ($vectortype$) VectorIntrinsics.binaryOp(
865 VECTOR_OP_MIN, $vectortype$.class, $type$.class, LENGTH,
866 this, v,
867 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$) Math.min(a, b)));
868 }
869
870 @Override
871 @ForceInline
872 public $vectortype$ min(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
873 return blend(min(v), m);
874 }
875
876 @Override
877 @ForceInline
878 public $vectortype$ max(Vector<$Boxtype$> o) {
879 Objects.requireNonNull(o);
880 $vectortype$ v = ($vectortype$)o;
881 return VectorIntrinsics.binaryOp(
882 VECTOR_OP_MAX, $vectortype$.class, $type$.class, LENGTH,
883 this, v,
884 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$) Math.max(a, b)));
885 }
886
887 @Override
888 @ForceInline
889 public $vectortype$ max(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
890 return blend(max(v), m);
891 }
892
893 #if[BITWISE]
894 @Override
895 @ForceInline
896 public $vectortype$ and(Vector<$Boxtype$> o) {
897 Objects.requireNonNull(o);
898 $vectortype$ v = ($vectortype$)o;
899 return VectorIntrinsics.binaryOp(
900 VECTOR_OP_AND, $vectortype$.class, $type$.class, LENGTH,
901 this, v,
902 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$)(a & b)));
903 }
904
905 @Override
906 @ForceInline
907 public $vectortype$ or(Vector<$Boxtype$> o) {
908 Objects.requireNonNull(o);
909 $vectortype$ v = ($vectortype$)o;
910 return VectorIntrinsics.binaryOp(
911 VECTOR_OP_OR, $vectortype$.class, $type$.class, LENGTH,
912 this, v,
913 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$)(a | b)));
914 }
915
916 @Override
917 @ForceInline
918 public $vectortype$ xor(Vector<$Boxtype$> o) {
919 Objects.requireNonNull(o);
920 $vectortype$ v = ($vectortype$)o;
921 return VectorIntrinsics.binaryOp(
922 VECTOR_OP_XOR, $vectortype$.class, $type$.class, LENGTH,
923 this, v,
924 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$)(a ^ b)));
925 }
926
927 @Override
928 @ForceInline
929 public $vectortype$ and(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
930 return blend(and(v), m);
931 }
932
933 @Override
934 @ForceInline
935 public $vectortype$ or(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
936 return blend(or(v), m);
937 }
938
939 @Override
940 @ForceInline
941 public $vectortype$ xor(Vector<$Boxtype$> v, Mask<$Boxtype$> m) {
942 return blend(xor(v), m);
943 }
944 #end[BITWISE]
945
946 #if[byte]
947 @Override
948 @ForceInline
949 public $vectortype$ shiftL(int s) {
950 return VectorIntrinsics.broadcastInt(
951 VECTOR_OP_LSHIFT, $vectortype$.class, $type$.class, LENGTH,
952 this, s,
953 (v, i) -> v.uOp((__, a) -> ($type$) (a << (i & 7))));
954 }
955
956 @Override
957 @ForceInline
958 public $vectortype$ shiftL(int s, Mask<$Boxtype$> m) {
959 return blend(shiftL(s), m);
960 }
961
962 @Override
963 @ForceInline
964 public $vectortype$ shiftR(int s) {
965 return VectorIntrinsics.broadcastInt(
966 VECTOR_OP_URSHIFT, $vectortype$.class, $type$.class, LENGTH,
967 this, s,
968 (v, i) -> v.uOp((__, a) -> ($type$) ((a & 0xFF) >>> (i & 7))));
969 }
970
971 @Override
972 @ForceInline
973 public $vectortype$ shiftR(int s, Mask<$Boxtype$> m) {
974 return blend(shiftR(s), m);
975 }
976
977 @Override
978 @ForceInline
979 public $vectortype$ aShiftR(int s) {
980 return VectorIntrinsics.broadcastInt(
981 VECTOR_OP_RSHIFT, $vectortype$.class, $type$.class, LENGTH,
982 this, s,
983 (v, i) -> v.uOp((__, a) -> ($type$) (a >> (i & 7))));
984 }
985
986 @Override
987 @ForceInline
988 public $vectortype$ aShiftR(int s, Mask<$Boxtype$> m) {
989 return blend(aShiftR(s), m);
990 }
991 #end[byte]
992 #if[short]
993 @Override
994 @ForceInline
995 public $vectortype$ shiftL(int s) {
996 return VectorIntrinsics.broadcastInt(
997 VECTOR_OP_LSHIFT, $vectortype$.class, $type$.class, LENGTH,
998 this, s,
999 (v, i) -> v.uOp((__, a) -> ($type$) (a << (i & 15))));
1000 }
1001
1002 @Override
1003 @ForceInline
1004 public $vectortype$ shiftL(int s, Mask<$Boxtype$> m) {
1005 return blend(shiftL(s), m);
1006 }
1007
1008 @Override
1009 @ForceInline
1010 public $vectortype$ shiftR(int s) {
1011 return VectorIntrinsics.broadcastInt(
1012 VECTOR_OP_URSHIFT, $vectortype$.class, $type$.class, LENGTH,
1013 this, s,
1014 (v, i) -> v.uOp((__, a) -> ($type$) ((a & 0xFFFF) >>> (i & 15))));
1015 }
1016
1017 @Override
1018 @ForceInline
1019 public $vectortype$ shiftR(int s, Mask<$Boxtype$> m) {
1020 return blend(shiftR(s), m);
1021 }
1022
1023 @Override
1024 @ForceInline
1025 public $vectortype$ aShiftR(int s) {
1026 return VectorIntrinsics.broadcastInt(
1027 VECTOR_OP_RSHIFT, $vectortype$.class, $type$.class, LENGTH,
1028 this, s,
1029 (v, i) -> v.uOp((__, a) -> ($type$) (a >> (i & 15))));
1030 }
1031
1032 @Override
1033 @ForceInline
1034 public $vectortype$ aShiftR(int s, Mask<$Boxtype$> m) {
1035 return blend(aShiftR(s), m);
1036 }
1037 #end[short]
1038 #if[intOrLong]
1039 @Override
1040 @ForceInline
1041 public $vectortype$ shiftL(int s) {
1042 return VectorIntrinsics.broadcastInt(
1043 VECTOR_OP_LSHIFT, $vectortype$.class, $type$.class, LENGTH,
1044 this, s,
1045 (v, i) -> v.uOp((__, a) -> ($type$) (a << i)));
1046 }
1047
1048 @Override
1049 @ForceInline
1050 public $vectortype$ shiftL(int s, Mask<$Boxtype$> m) {
1051 return blend(shiftL(s), m);
1052 }
1053
1054 @Override
1055 @ForceInline
1056 public $vectortype$ shiftR(int s) {
1057 return VectorIntrinsics.broadcastInt(
1058 VECTOR_OP_URSHIFT, $vectortype$.class, $type$.class, LENGTH,
1059 this, s,
1060 (v, i) -> v.uOp((__, a) -> ($type$) (a >>> i)));
1061 }
1062
1063 @Override
1064 @ForceInline
1065 public $vectortype$ shiftR(int s, Mask<$Boxtype$> m) {
1066 return blend(shiftR(s), m);
1067 }
1068
1069 @Override
1070 @ForceInline
1071 public $vectortype$ aShiftR(int s) {
1072 return VectorIntrinsics.broadcastInt(
1073 VECTOR_OP_RSHIFT, $vectortype$.class, $type$.class, LENGTH,
1074 this, s,
1075 (v, i) -> v.uOp((__, a) -> ($type$) (a >> i)));
1076 }
1077
1078 @Override
1079 @ForceInline
1080 public $vectortype$ aShiftR(int s, Mask<$Boxtype$> m) {
1081 return blend(aShiftR(s), m);
1082 }
1083
1084 @Override
1085 @ForceInline
1086 public $vectortype$ shiftL(Vector<$Boxtype$> s) {
1087 $vectortype$ shiftv = ($vectortype$)s;
1088 // As per shift specification for Java, mask the shift count.
1089 shiftv = shiftv.and($abstractvectortype$.broadcast(SPECIES, {#if[int]?0x1f:0x3f}));
1090 return VectorIntrinsics.binaryOp(
1091 VECTOR_OP_LSHIFT, $vectortype$.class, $type$.class, LENGTH,
1092 this, shiftv,
1093 (v1, v2) -> v1.bOp(v2,(i,a, b) -> ($type$) (a << b)));
1094 }
1095
1096 @Override
1097 @ForceInline
1098 public $vectortype$ shiftR(Vector<$Boxtype$> s) {
1099 $vectortype$ shiftv = ($vectortype$)s;
1100 // As per shift specification for Java, mask the shift count.
1140 @Override
1141 @ForceInline
1142 public $type$ addAll() {
1143 return ($type$) VectorIntrinsics.reductionCoerced(
1144 VECTOR_OP_ADD, $vectortype$.class, $type$.class, LENGTH,
1145 this,
1146 v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a + b)));
1147 }
1148
1149 @Override
1150 @ForceInline
1151 public $type$ andAll() {
1152 return ($type$) VectorIntrinsics.reductionCoerced(
1153 VECTOR_OP_AND, $vectortype$.class, $type$.class, LENGTH,
1154 this,
1155 v -> (long) v.rOp(($type$) -1, (i, a, b) -> ($type$) (a & b)));
1156 }
1157
1158 @Override
1159 @ForceInline
1160 public $type$ andAll(Mask<$Boxtype$> m) {
1161 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) -1), m).andAll();
1162 }
1163
1164 @Override
1165 @ForceInline
1166 public $type$ minAll() {
1167 return ($type$) VectorIntrinsics.reductionCoerced(
1168 VECTOR_OP_MIN, $vectortype$.class, $type$.class, LENGTH,
1169 this,
1170 v -> (long) v.rOp($Boxtype$.MAX_VALUE , (i, a, b) -> ($type$) Math.min(a, b)));
1171 }
1172
1173 @Override
1174 @ForceInline
1175 public $type$ maxAll() {
1176 return ($type$) VectorIntrinsics.reductionCoerced(
1177 VECTOR_OP_MAX, $vectortype$.class, $type$.class, LENGTH,
1178 this,
1179 v -> (long) v.rOp($Boxtype$.MIN_VALUE , (i, a, b) -> ($type$) Math.max(a, b)));
1180 }
1182 @Override
1183 @ForceInline
1184 public $type$ mulAll() {
1185 return ($type$) VectorIntrinsics.reductionCoerced(
1186 VECTOR_OP_MUL, $vectortype$.class, $type$.class, LENGTH,
1187 this,
1188 v -> (long) v.rOp(($type$) 1, (i, a, b) -> ($type$) (a * b)));
1189 }
1190
1191 @Override
1192 @ForceInline
1193 public $type$ orAll() {
1194 return ($type$) VectorIntrinsics.reductionCoerced(
1195 VECTOR_OP_OR, $vectortype$.class, $type$.class, LENGTH,
1196 this,
1197 v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a | b)));
1198 }
1199
1200 @Override
1201 @ForceInline
1202 public $type$ orAll(Mask<$Boxtype$> m) {
1203 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) 0), m).orAll();
1204 }
1205
1206 @Override
1207 @ForceInline
1208 public $type$ xorAll() {
1209 return ($type$) VectorIntrinsics.reductionCoerced(
1210 VECTOR_OP_XOR, $vectortype$.class, $type$.class, LENGTH,
1211 this,
1212 v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a ^ b)));
1213 }
1214
1215 @Override
1216 @ForceInline
1217 public $type$ xorAll(Mask<$Boxtype$> m) {
1218 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) 0), m).xorAll();
1219 }
1220 #end[BITWISE]
1221
1222 #if[FP]
1223 @Override
1224 @ForceInline
1225 public $type$ addAll() {
1226 $bitstype$ bits = ($bitstype$) VectorIntrinsics.reductionCoerced(
1227 VECTOR_OP_ADD, $vectortype$.class, $type$.class, LENGTH,
1228 this,
1229 v -> {
1230 $type$ r = v.rOp(($type$) 0, (i, a, b) -> ($type$) (a + b));
1231 return (long)$Type$.$type$To$Bitstype$Bits(r);
1232 });
1233 return $Type$.$bitstype$BitsTo$Fptype$(bits);
1234 }
1235
1236 @Override
1237 @ForceInline
1259 return $Type$.$bitstype$BitsTo$Fptype$(bits);
1260 }
1261
1262 @Override
1263 @ForceInline
1264 public $type$ maxAll() {
1265 $bitstype$ bits = ($bitstype$) VectorIntrinsics.reductionCoerced(
1266 VECTOR_OP_MAX, $vectortype$.class, $type$.class, LENGTH,
1267 this,
1268 v -> {
1269 $type$ r = v.rOp($Boxtype$.NEGATIVE_INFINITY, (i, a, b) -> ($type$) Math.max(a, b));
1270 return (long)$Type$.$type$To$Bitstype$Bits(r);
1271 });
1272 return $Type$.$bitstype$BitsTo$Fptype$(bits);
1273 }
1274
1275 #end[FP]
1276
1277 @Override
1278 @ForceInline
1279 public $type$ addAll(Mask<$Boxtype$> m) {
1280 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) 0), m).addAll();
1281 }
1282
1283
1284 @Override
1285 @ForceInline
1286 public $type$ mulAll(Mask<$Boxtype$> m) {
1287 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) 1), m).mulAll();
1288 }
1289
1290 @Override
1291 @ForceInline
1292 public $type$ minAll(Mask<$Boxtype$> m) {
1293 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, $Boxtype$.MAX_VALUE), m).minAll();
1294 }
1295
1296 @Override
1297 @ForceInline
1298 public $type$ maxAll(Mask<$Boxtype$> m) {
1299 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, $Boxtype$.MIN_VALUE), m).maxAll();
1300 }
1301
1302 @Override
1303 @ForceInline
1304 public Shuffle<$Boxtype$> toShuffle() {
1305 $type$[] a = toArray();
1306 int[] sa = new int[a.length];
1307 for (int i = 0; i < a.length; i++) {
1308 sa[i] = (int) a[i];
1309 }
1310 return $abstractvectortype$.shuffleFromArray(SPECIES, sa, 0);
1311 }
1312
1313 // Memory operations
1314
1315 private static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_$TYPE$_INDEX_SCALE);
1316 private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
1317
1318 @Override
1319 @ForceInline
1320 public void intoArray($type$[] a, int ix) {
1321 Objects.requireNonNull(a);
1322 ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
1323 VectorIntrinsics.store($vectortype$.class, $type$.class, LENGTH,
1324 a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_$TYPE$_BASE_OFFSET,
1325 this,
1326 a, ix,
1327 (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
1328 }
1329
1330 @Override
1331 @ForceInline
1332 public final void intoArray($type$[] a, int ax, Mask<$Boxtype$> m) {
1333 $abstractvectortype$ oldVal = $abstractvectortype$.fromArray(SPECIES, a, ax);
1334 $abstractvectortype$ newVal = oldVal.blend(this, m);
1335 newVal.intoArray(a, ax);
1336 }
1337 #if[!byteOrShort]
1338 @Override
1339 @ForceInline
1340 public void intoArray($type$[] a, int ix, int[] b, int iy) {
1341 #if[longOrDouble64]
1342 this.intoArray(a, ix + b[iy]);
1343 #else[longOrDouble64]
1344 Objects.requireNonNull(a);
1345 Objects.requireNonNull(b);
1346
1347 // Index vector: vix[0:n] = i -> ix + indexMap[iy + i]
1348 IntVector vix = IntVector.fromArray(INDEX_SPECIES, b, iy).add(ix);
1349
1350 vix = VectorIntrinsics.checkIndex(vix, a.length);
1351
1352 VectorIntrinsics.storeWithMap($vectortype$.class, $type$.class, LENGTH, $vectorindextype$,
1353 a, Unsafe.ARRAY_$TYPE$_BASE_OFFSET, vix,
1354 this,
1355 a, ix, b, iy,
1356 (arr, idx, v, indexMap, idy) -> v.forEach((i, e) -> arr[idx+indexMap[idy+i]] = e));
1357 #end[longOrDouble64]
1358 }
1359
1360 @Override
1361 @ForceInline
1362 public final void intoArray($type$[] a, int ax, Mask<$Boxtype$> m, int[] b, int iy) {
1363 // @@@ This can result in out of bounds errors for unset mask lanes
1364 $abstractvectortype$ oldVal = $abstractvectortype$.fromArray(SPECIES, a, ax, b, iy);
1365 $abstractvectortype$ newVal = oldVal.blend(this, m);
1366 newVal.intoArray(a, ax, b, iy);
1367 }
1368 #end[!byteOrShort]
1369
1370 @Override
1371 @ForceInline
1372 public void intoByteArray(byte[] a, int ix) {
1373 Objects.requireNonNull(a);
1374 ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
1375 VectorIntrinsics.store($vectortype$.class, $type$.class, LENGTH,
1376 a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
1377 this,
1378 a, ix,
1379 (c, idx, v) -> {
1380 ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
1381 $Type$Buffer tb = bbc{#if[byte]?;:.as$Type$Buffer();}
1382 v.forEach((i, e) -> tb.put(e));
1383 });
1384 }
1385
1386 @Override
1387 @ForceInline
1388 public final void intoByteArray(byte[] a, int ix, Mask<$Boxtype$> m) {
1389 $vectortype$ oldVal = ($vectortype$) $abstractvectortype$.fromByteArray(SPECIES, a, ix);
1390 $vectortype$ newVal = oldVal.blend(this, m);
1391 newVal.intoByteArray(a, ix);
1392 }
1393
1394 @Override
1395 @ForceInline
1396 public void intoByteBuffer(ByteBuffer bb, int ix) {
1397 if (bb.order() != ByteOrder.nativeOrder()) {
1398 throw new IllegalArgumentException();
1399 }
1400 if (bb.isReadOnly()) {
1401 throw new ReadOnlyBufferException();
1402 }
1403 ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
1404 VectorIntrinsics.store($vectortype$.class, $type$.class, LENGTH,
1405 U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
1406 this,
1407 bb, ix,
1408 (c, idx, v) -> {
1409 ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
1410 $Type$Buffer tb = bbc{#if[byte]?;:.as$Type$Buffer();}
1411 v.forEach((i, e) -> tb.put(e));
1412 });
1413 }
1414
1415 @Override
1416 @ForceInline
1417 public void intoByteBuffer(ByteBuffer bb, int ix, Mask<$Boxtype$> m) {
1418 $vectortype$ oldVal = ($vectortype$) $abstractvectortype$.fromByteBuffer(SPECIES, bb, ix);
1419 $vectortype$ newVal = oldVal.blend(this, m);
1420 newVal.intoByteBuffer(bb, ix);
1421 }
1422
1423 //
1424
1425 @Override
1426 public String toString() {
1427 return Arrays.toString(getElements());
1428 }
1429
1430 @Override
1431 public boolean equals(Object o) {
1432 if (this == o) return true;
1433 if (o == null || this.getClass() != o.getClass()) return false;
1434
1435 $vectortype$ that = ($vectortype$) o;
1436 return this.equal(that).allTrue();
1437 }
1522 Objects.requireNonNull(o);
1523 $vectortype$ v = ($vectortype$)o;
1524
1525 return VectorIntrinsics.compare(
1526 BT_ge, $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
1527 this, v,
1528 (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1529 }
1530
1531 // Foreach
1532
1533 @Override
1534 void forEach(FUnCon f) {
1535 $type$[] vec = getElements();
1536 for (int i = 0; i < length(); i++) {
1537 f.apply(i, vec[i]);
1538 }
1539 }
1540
1541 @Override
1542 void forEach(Mask<$Boxtype$> o, FUnCon f) {
1543 boolean[] mbits = (($masktype$)o).getBits();
1544 forEach((i, a) -> {
1545 if (mbits[i]) { f.apply(i, a); }
1546 });
1547 }
1548
1549 #if[FP]
1550 $bitsvectortype$ toBits() {
1551 $type$[] vec = getElements();
1552 $bitstype$[] res = new $bitstype$[this.species().length()];
1553 for(int i = 0; i < this.species().length(); i++){
1554 res[i] = $Type$.$type$To$Bitstype$Bits(vec[i]);
1555 }
1556 return new $bitsvectortype$(res);
1557 }
1558 #end[FP]
1559
1560 #if[intOrLong]
1561 $fpvectortype$ toFP() {
1562 $type$[] vec = getElements();
1599 $type$[] res = new $type$[length()];
1600 for (int i = 0; i < length() - j; i++) {
1601 res[i] = vec[i + j];
1602 }
1603 return new $vectortype$(res);
1604 }
1605
1606 @Override
1607 public $vectortype$ shiftER(int j) {
1608 $type$[] vec = getElements();
1609 $type$[] res = new $type$[length()];
1610 for (int i = 0; i < length() - j; i++){
1611 res[i + j] = vec[i];
1612 }
1613 return new $vectortype$(res);
1614 }
1615
1616 @Override
1617 @ForceInline
1618 public $vectortype$ rearrange(Vector<$Boxtype$> v,
1619 Shuffle<$Boxtype$> s, Mask<$Boxtype$> m) {
1620 return this.rearrange(s).blend(v.rearrange(s), m);
1621 }
1622
1623 @Override
1624 @ForceInline
1625 public $vectortype$ rearrange(Shuffle<$Boxtype$> o1) {
1626 Objects.requireNonNull(o1);
1627 $shuffletype$ s = ($shuffletype$)o1;
1628
1629 return VectorIntrinsics.rearrangeOp(
1630 $vectortype$.class, $shuffletype$.class, $type$.class, LENGTH,
1631 this, s,
1632 (v1, s_) -> v1.uOp((i, a) -> {
1633 int ei = s_.getElement(i);
1634 return v1.get(ei);
1635 }));
1636 }
1637
1638 @Override
1639 @ForceInline
1640 public $vectortype$ blend(Vector<$Boxtype$> o1, Mask<$Boxtype$> o2) {
1641 Objects.requireNonNull(o1);
1642 Objects.requireNonNull(o2);
1643 $vectortype$ v = ($vectortype$)o1;
1644 $masktype$ m = ($masktype$)o2;
1645
1646 return VectorIntrinsics.blend(
1647 $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
1648 this, v, m,
1649 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1650 }
1651
1652 // Accessors
1653
1654 #if[FP]
1655 @Override
1656 public $type$ get(int i) {
1657 if (i < 0 || i >= LENGTH) {
1658 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1659 }
1660 $bitstype$ bits = ($bitstype$) VectorIntrinsics.extract(
1736 boolean[] bits = new boolean[species().length()];
1737 Arrays.fill(bits, val);
1738 this.bits = bits;
1739 }
1740
1741 boolean[] getBits() {
1742 return VectorIntrinsics.maybeRebox(this).bits;
1743 }
1744
1745 @Override
1746 $masktype$ uOp(MUnOp f) {
1747 boolean[] res = new boolean[species().length()];
1748 boolean[] bits = getBits();
1749 for (int i = 0; i < species().length(); i++) {
1750 res[i] = f.apply(i, bits[i]);
1751 }
1752 return new $masktype$(res);
1753 }
1754
1755 @Override
1756 $masktype$ bOp(Mask<$Boxtype$> o, MBinOp f) {
1757 boolean[] res = new boolean[species().length()];
1758 boolean[] bits = getBits();
1759 boolean[] mbits = (($masktype$)o).getBits();
1760 for (int i = 0; i < species().length(); i++) {
1761 res[i] = f.apply(i, bits[i], mbits[i]);
1762 }
1763 return new $masktype$(res);
1764 }
1765
1766 @Override
1767 public Species<$Boxtype$> species() {
1768 return SPECIES;
1769 }
1770
1771 @Override
1772 public $vectortype$ toVector() {
1773 $type$[] res = new $type$[species().length()];
1774 boolean[] bits = getBits();
1775 for (int i = 0; i < species().length(); i++) {
1776 // -1 will result in the most significant bit being set in
1777 // addition to some or all other bits
1778 res[i] = ($type$) (bits[i] ? -1 : 0);
1779 }
1780 return new $vectortype$(res);
1781 }
1782
1783 @Override
1784 @ForceInline
1785 @SuppressWarnings("unchecked")
1786 public <E> Mask<E> cast(Species<E> species) {
1787 if (length() != species.length())
1788 throw new IllegalArgumentException("Mask length and species length differ");
1789 Class<?> stype = species.elementType();
1790 boolean [] maskArray = toArray();
1791 if (stype == byte.class) {
1792 return (Mask <E>) new Byte$bits$Vector.Byte$bits$Mask(maskArray);
1793 } else if (stype == short.class) {
1794 return (Mask <E>) new Short$bits$Vector.Short$bits$Mask(maskArray);
1795 } else if (stype == int.class) {
1796 return (Mask <E>) new Int$bits$Vector.Int$bits$Mask(maskArray);
1797 } else if (stype == long.class) {
1798 return (Mask <E>) new Long$bits$Vector.Long$bits$Mask(maskArray);
1799 } else if (stype == float.class) {
1800 return (Mask <E>) new Float$bits$Vector.Float$bits$Mask(maskArray);
1801 } else if (stype == double.class) {
1802 return (Mask <E>) new Double$bits$Vector.Double$bits$Mask(maskArray);
1803 } else {
1804 throw new UnsupportedOperationException("Bad lane type for casting.");
1805 }
1806 }
1807
1808 // Unary operations
1809
1810 @Override
1811 @ForceInline
1812 public $masktype$ not() {
1813 return ($masktype$) VectorIntrinsics.unaryOp(
1814 VECTOR_OP_NOT, $masktype$.class, $bitstype$.class, LENGTH,
1815 this,
1816 (m1) -> m1.uOp((i, a) -> !a));
1817 }
1818
1819 // Binary operations
1820
1821 @Override
1822 @ForceInline
1823 public $masktype$ and(Mask<$Boxtype$> o) {
1824 Objects.requireNonNull(o);
1825 $masktype$ m = ($masktype$)o;
1826 return VectorIntrinsics.binaryOp(VECTOR_OP_AND, $masktype$.class, $bitstype$.class, LENGTH,
1827 this, m,
1828 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1829 }
1830
1831 @Override
1832 @ForceInline
1833 public $masktype$ or(Mask<$Boxtype$> o) {
1834 Objects.requireNonNull(o);
1835 $masktype$ m = ($masktype$)o;
1836 return VectorIntrinsics.binaryOp(VECTOR_OP_OR, $masktype$.class, $bitstype$.class, LENGTH,
1837 this, m,
1838 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1839 }
1840
1841 // Reductions
1842
1843 @Override
1844 @ForceInline
1845 public boolean anyTrue() {
1846 return VectorIntrinsics.test(BT_ne, $masktype$.class, $bitstype$.class, LENGTH,
1847 this, this,
1848 (m, __) -> anyTrueHelper((($masktype$)m).getBits()));
1849 }
1850
1851 @Override
1852 @ForceInline
1853 public boolean allTrue() {
1854 return VectorIntrinsics.test(BT_overflow, $masktype$.class, $bitstype$.class, LENGTH,
1855 this, $abstractvectortype$.maskAllTrue(species()),
1856 (m, __) -> allTrueHelper((($masktype$)m).getBits()));
1857 }
1858 }
1859
1860 // Shuffle
1861
1862 static final class $shuffletype$ extends AbstractShuffle<$Boxtype$> {
1863 $shuffletype$(byte[] reorder) {
1864 super(reorder);
1865 }
1866
1867 public $shuffletype$(int[] reorder) {
1868 super(reorder);
1869 }
1870
1871 public $shuffletype$(int[] reorder, int i) {
1872 super(reorder, i);
1873 }
1874
1875 public $shuffletype$(IntUnaryOperator f) {
1876 super(f);
1877 }
1878
1879 @Override
1880 public Species<$Boxtype$> species() {
1881 return SPECIES;
1882 }
1883
1884 @Override
1885 public $abstractvectortype$ toVector() {
1886 $type$[] va = new $type$[SPECIES.length()];
1887 for (int i = 0; i < va.length; i++) {
1888 va[i] = ($type$) getElement(i);
1889 }
1890 return $abstractvectortype$.fromArray(SPECIES, va, 0);
1891 }
1892
1893 @Override
1894 @ForceInline
1895 @SuppressWarnings("unchecked")
1896 public <F> Shuffle<F> cast(Species<F> species) {
1897 if (length() != species.length())
1898 throw new IllegalArgumentException("Shuffle length and species length differ");
1899 Class<?> stype = species.elementType();
1900 int [] shuffleArray = toArray();
1901 if (stype == byte.class) {
1902 return (Shuffle<F>) new Byte$bits$Vector.Byte$bits$Shuffle(shuffleArray);
1903 } else if (stype == short.class) {
1904 return (Shuffle<F>) new Short$bits$Vector.Short$bits$Shuffle(shuffleArray);
1905 } else if (stype == int.class) {
1906 return (Shuffle<F>) new Int$bits$Vector.Int$bits$Shuffle(shuffleArray);
1907 } else if (stype == long.class) {
1908 return (Shuffle<F>) new Long$bits$Vector.Long$bits$Shuffle(shuffleArray);
1909 } else if (stype == float.class) {
1910 return (Shuffle<F>) new Float$bits$Vector.Float$bits$Shuffle(shuffleArray);
1911 } else if (stype == double.class) {
1912 return (Shuffle<F>) new Double$bits$Vector.Double$bits$Shuffle(shuffleArray);
1913 } else {
1914 throw new UnsupportedOperationException("Bad lane type for casting.");
1915 }
1916 }
1917
1918 @Override
1919 public $shuffletype$ rearrange(Vector.Shuffle<$Boxtype$> o) {
1920 $shuffletype$ s = ($shuffletype$) o;
1921 byte[] r = new byte[reorder.length];
1922 for (int i = 0; i < reorder.length; i++) {
1923 r[i] = reorder[s.reorder[i]];
1924 }
1925 return new $shuffletype$(r);
1926 }
1927 }
1928
1929 // Species
1930
1931 @Override
1932 public Species<$Boxtype$> species() {
1933 return SPECIES;
1934 }
1935 }
|
23 * questions.
24 */
25 package jdk.incubator.vector;
26
27 import java.nio.ByteBuffer;
28 import java.nio.ByteOrder;
29 #if[!byte]
30 import java.nio.$Type$Buffer;
31 #end[!byte]
32 import java.nio.ReadOnlyBufferException;
33 import java.util.Arrays;
34 import java.util.Objects;
35 import java.util.function.IntUnaryOperator;
36
37 import jdk.internal.misc.Unsafe;
38 import jdk.internal.vm.annotation.ForceInline;
39 import static jdk.incubator.vector.VectorIntrinsics.*;
40
41 @SuppressWarnings("cast")
42 final class $vectortype$ extends $abstractvectortype$ {
43 private static final VectorSpecies<$Boxtype$> SPECIES = $Type$Vector.SPECIES_$BITS$;
44
45 static final $vectortype$ ZERO = new $vectortype$();
46
47 static final int LENGTH = SPECIES.length();
48
49 #if[!byteOrShort]
50 // Index vector species
51 private static final IntVector.IntSpecies INDEX_SPECIES;
52
53 static {
54 #if[longOrDouble64]
55 INDEX_SPECIES = (IntVector.IntSpecies) IntVector.species(VectorShape.S_64_BIT);
56 #else[longOrDouble64]
57 int bitSize = Vector.bitSizeForVectorLength(int.class, LENGTH);
58 INDEX_SPECIES = (IntVector.IntSpecies) IntVector.species(VectorShape.forBitSize(bitSize));
59 #end[longOrDouble64]
60 }
61
62 #end[!byteOrShort]
63 private final $type$[] vec; // Don't access directly, use getElements() instead.
64
65 private $type$[] getElements() {
66 return VectorIntrinsics.maybeRebox(this).vec;
67 }
68
69 $vectortype$() {
70 vec = new $type$[SPECIES.length()];
71 }
72
73 $vectortype$($type$[] v) {
74 vec = v;
75 }
76
77 @Override
78 public int length() { return LENGTH; }
79
80 // Unary operator
81
82 @Override
83 $vectortype$ uOp(FUnOp f) {
84 $type$[] vec = getElements();
85 $type$[] res = new $type$[length()];
86 for (int i = 0; i < length(); i++) {
87 res[i] = f.apply(i, vec[i]);
88 }
89 return new $vectortype$(res);
90 }
91
92 @Override
93 $vectortype$ uOp(VectorMask<$Boxtype$> o, FUnOp f) {
94 $type$[] vec = getElements();
95 $type$[] res = new $type$[length()];
96 boolean[] mbits = (($masktype$)o).getBits();
97 for (int i = 0; i < length(); i++) {
98 res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
99 }
100 return new $vectortype$(res);
101 }
102
103 // Binary operator
104
105 @Override
106 $vectortype$ bOp(Vector<$Boxtype$> o, FBinOp f) {
107 $type$[] res = new $type$[length()];
108 $type$[] vec1 = this.getElements();
109 $type$[] vec2 = (($vectortype$)o).getElements();
110 for (int i = 0; i < length(); i++) {
111 res[i] = f.apply(i, vec1[i], vec2[i]);
112 }
113 return new $vectortype$(res);
114 }
115
116 @Override
117 $vectortype$ bOp(Vector<$Boxtype$> o1, VectorMask<$Boxtype$> o2, FBinOp f) {
118 $type$[] res = new $type$[length()];
119 $type$[] vec1 = this.getElements();
120 $type$[] vec2 = (($vectortype$)o1).getElements();
121 boolean[] mbits = (($masktype$)o2).getBits();
122 for (int i = 0; i < length(); i++) {
123 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
124 }
125 return new $vectortype$(res);
126 }
127
128 // Trinary operator
129
130 @Override
131 $vectortype$ tOp(Vector<$Boxtype$> o1, Vector<$Boxtype$> o2, FTriOp f) {
132 $type$[] res = new $type$[length()];
133 $type$[] vec1 = this.getElements();
134 $type$[] vec2 = (($vectortype$)o1).getElements();
135 $type$[] vec3 = (($vectortype$)o2).getElements();
136 for (int i = 0; i < length(); i++) {
137 res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
138 }
139 return new $vectortype$(res);
140 }
141
142 @Override
143 $vectortype$ tOp(Vector<$Boxtype$> o1, Vector<$Boxtype$> o2, VectorMask<$Boxtype$> o3, FTriOp f) {
144 $type$[] res = new $type$[length()];
145 $type$[] vec1 = getElements();
146 $type$[] vec2 = (($vectortype$)o1).getElements();
147 $type$[] vec3 = (($vectortype$)o2).getElements();
148 boolean[] mbits = (($masktype$)o3).getBits();
149 for (int i = 0; i < length(); i++) {
150 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
151 }
152 return new $vectortype$(res);
153 }
154
155 @Override
156 $type$ rOp($type$ v, FBinOp f) {
157 $type$[] vec = getElements();
158 for (int i = 0; i < length(); i++) {
159 v = f.apply(i, v, vec[i]);
160 }
161 return v;
162 }
163
164 @Override
165 @ForceInline
166 public <F> Vector<F> cast(VectorSpecies<F> s) {
167 Objects.requireNonNull(s);
168 if (s.length() != LENGTH)
169 throw new IllegalArgumentException("Vector length this species length differ");
170
171 return VectorIntrinsics.cast(
172 $vectortype$.class,
173 $type$.class, LENGTH,
174 s.boxType(),
175 s.elementType(), LENGTH,
176 this, s,
177 (species, vector) -> vector.castDefault(species)
178 );
179 }
180
181 @SuppressWarnings("unchecked")
182 @ForceInline
183 private <F> Vector<F> castDefault(VectorSpecies<F> s) {
184 int limit = s.length();
185
186 Class<?> stype = s.elementType();
187 if (stype == byte.class) {
188 byte[] a = new byte[limit];
189 for (int i = 0; i < limit; i++) {
190 a[i] = (byte) this.get(i);
191 }
192 return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
193 } else if (stype == short.class) {
194 short[] a = new short[limit];
195 for (int i = 0; i < limit; i++) {
196 a[i] = (short) this.get(i);
197 }
198 return (Vector) ShortVector.fromArray((VectorSpecies<Short>) s, a, 0);
199 } else if (stype == int.class) {
200 int[] a = new int[limit];
201 for (int i = 0; i < limit; i++) {
202 a[i] = (int) this.get(i);
203 }
204 return (Vector) IntVector.fromArray((VectorSpecies<Integer>) s, a, 0);
205 } else if (stype == long.class) {
206 long[] a = new long[limit];
207 for (int i = 0; i < limit; i++) {
208 a[i] = (long) this.get(i);
209 }
210 return (Vector) LongVector.fromArray((VectorSpecies<Long>) s, a, 0);
211 } else if (stype == float.class) {
212 float[] a = new float[limit];
213 for (int i = 0; i < limit; i++) {
214 a[i] = (float) this.get(i);
215 }
216 return (Vector) FloatVector.fromArray((VectorSpecies<Float>) s, a, 0);
217 } else if (stype == double.class) {
218 double[] a = new double[limit];
219 for (int i = 0; i < limit; i++) {
220 a[i] = (double) this.get(i);
221 }
222 return (Vector) DoubleVector.fromArray((VectorSpecies<Double>) s, a, 0);
223 } else {
224 throw new UnsupportedOperationException("Bad lane type for casting.");
225 }
226 }
227
228 @Override
229 @ForceInline
230 @SuppressWarnings("unchecked")
231 public <F> Vector<F> reinterpret(VectorSpecies<F> s) {
232 Objects.requireNonNull(s);
233
234 if(s.elementType().equals($type$.class)) {
235 return (Vector<F>) reshape((VectorSpecies<$Boxtype$>)s);
236 }
237 if(s.bitSize() == bitSize()) {
238 return reinterpretType(s);
239 }
240
241 return defaultReinterpret(s);
242 }
243
244 @ForceInline
245 private <F> Vector<F> reinterpretType(VectorSpecies<F> s) {
246 Objects.requireNonNull(s);
247
248 Class<?> stype = s.elementType();
249 if (stype == byte.class) {
250 return VectorIntrinsics.reinterpret(
251 $vectortype$.class,
252 $type$.class, LENGTH,
253 Byte$bits$Vector.class,
254 byte.class, Byte$bits$Vector.LENGTH,
255 this, s,
256 (species, vector) -> vector.defaultReinterpret(species)
257 );
258 } else if (stype == short.class) {
259 return VectorIntrinsics.reinterpret(
260 $vectortype$.class,
261 $type$.class, LENGTH,
262 Short$bits$Vector.class,
263 short.class, Short$bits$Vector.LENGTH,
264 this, s,
265 (species, vector) -> vector.defaultReinterpret(species)
290 float.class, Float$bits$Vector.LENGTH,
291 this, s,
292 (species, vector) -> vector.defaultReinterpret(species)
293 );
294 } else if (stype == double.class) {
295 return VectorIntrinsics.reinterpret(
296 $vectortype$.class,
297 $type$.class, LENGTH,
298 Double$bits$Vector.class,
299 double.class, Double$bits$Vector.LENGTH,
300 this, s,
301 (species, vector) -> vector.defaultReinterpret(species)
302 );
303 } else {
304 throw new UnsupportedOperationException("Bad lane type for casting.");
305 }
306 }
307
308 @Override
309 @ForceInline
310 public $abstractvectortype$ reshape(VectorSpecies<$Boxtype$> s) {
311 Objects.requireNonNull(s);
312 if (s.bitSize() == 64 && (s.boxType() == $Type$64Vector.class)) {
313 return VectorIntrinsics.reinterpret(
314 $vectortype$.class,
315 $type$.class, LENGTH,
316 $Type$64Vector.class,
317 $type$.class, $Type$64Vector.LENGTH,
318 this, s,
319 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
320 );
321 } else if (s.bitSize() == 128 && (s.boxType() == $Type$128Vector.class)) {
322 return VectorIntrinsics.reinterpret(
323 $vectortype$.class,
324 $type$.class, LENGTH,
325 $Type$128Vector.class,
326 $type$.class, $Type$128Vector.LENGTH,
327 this, s,
328 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
329 );
330 } else if (s.bitSize() == 256 && (s.boxType() == $Type$256Vector.class)) {
353 $Type$MaxVector.class,
354 $type$.class, $Type$MaxVector.LENGTH,
355 this, s,
356 (species, vector) -> ($abstractvectortype$) vector.defaultReinterpret(species)
357 );
358 } else {
359 throw new InternalError("Unimplemented size");
360 }
361 }
362
363 // Binary operations with scalars
364
365 @Override
366 @ForceInline
367 public $abstractvectortype$ add($type$ o) {
368 return add(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
369 }
370
371 @Override
372 @ForceInline
373 public $abstractvectortype$ add($type$ o, VectorMask<$Boxtype$> m) {
374 return add(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
375 }
376
377 @Override
378 @ForceInline
379 public $abstractvectortype$ sub($type$ o) {
380 return sub(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
381 }
382
383 @Override
384 @ForceInline
385 public $abstractvectortype$ sub($type$ o, VectorMask<$Boxtype$> m) {
386 return sub(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
387 }
388
389 @Override
390 @ForceInline
391 public $abstractvectortype$ mul($type$ o) {
392 return mul(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
393 }
394
395 @Override
396 @ForceInline
397 public $abstractvectortype$ mul($type$ o, VectorMask<$Boxtype$> m) {
398 return mul(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
399 }
400
401 @Override
402 @ForceInline
403 public $abstractvectortype$ min($type$ o) {
404 return min(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
405 }
406
407 @Override
408 @ForceInline
409 public $abstractvectortype$ max($type$ o) {
410 return max(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
411 }
412
413 @Override
414 @ForceInline
415 public VectorMask<$Boxtype$> equal($type$ o) {
416 return equal(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
417 }
418
419 @Override
420 @ForceInline
421 public VectorMask<$Boxtype$> notEqual($type$ o) {
422 return notEqual(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
423 }
424
425 @Override
426 @ForceInline
427 public VectorMask<$Boxtype$> lessThan($type$ o) {
428 return lessThan(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
429 }
430
431 @Override
432 @ForceInline
433 public VectorMask<$Boxtype$> lessThanEq($type$ o) {
434 return lessThanEq(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
435 }
436
437 @Override
438 @ForceInline
439 public VectorMask<$Boxtype$> greaterThan($type$ o) {
440 return greaterThan(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
441 }
442
443 @Override
444 @ForceInline
445 public VectorMask<$Boxtype$> greaterThanEq($type$ o) {
446 return greaterThanEq(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
447 }
448
449 @Override
450 @ForceInline
451 public $abstractvectortype$ blend($type$ o, VectorMask<$Boxtype$> m) {
452 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
453 }
454
455 #if[FP]
456 @Override
457 @ForceInline
458 public $abstractvectortype$ div($type$ o) {
459 return div(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
460 }
461
462 @Override
463 @ForceInline
464 public $abstractvectortype$ div($type$ o, VectorMask<$Boxtype$> m) {
465 return div(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
466 }
467
468 @Override
469 @ForceInline
470 public $vectortype$ div(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
471 return blend(div(v), m);
472 }
473
474 @Override
475 @ForceInline
476 public $abstractvectortype$ atan2($type$ o) {
477 return atan2(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
478 }
479
480 @Override
481 @ForceInline
482 public $abstractvectortype$ atan2($type$ o, VectorMask<$Boxtype$> m) {
483 return atan2(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
484 }
485
486 @Override
487 @ForceInline
488 public $abstractvectortype$ pow($type$ o) {
489 return pow(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
490 }
491
492 @Override
493 @ForceInline
494 public $abstractvectortype$ pow($type$ o, VectorMask<$Boxtype$> m) {
495 return pow(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
496 }
497
498 @Override
499 @ForceInline
500 public $abstractvectortype$ fma($type$ o1, $type$ o2) {
501 return fma(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o1), ($vectortype$)$abstractvectortype$.broadcast(SPECIES, o2));
502 }
503
504 @Override
505 @ForceInline
506 public $abstractvectortype$ fma($type$ o1, $type$ o2, VectorMask<$Boxtype$> m) {
507 return fma(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o1), ($vectortype$)$abstractvectortype$.broadcast(SPECIES, o2), m);
508 }
509
510 @Override
511 @ForceInline
512 public $abstractvectortype$ hypot($type$ o) {
513 return hypot(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
514 }
515
516 @Override
517 @ForceInline
518 public $abstractvectortype$ hypot($type$ o, VectorMask<$Boxtype$> m) {
519 return hypot(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
520 }
521 #end[FP]
522
523 #if[BITWISE]
524 @Override
525 @ForceInline
526 public $abstractvectortype$ and($type$ o) {
527 return and(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
528 }
529
530 @Override
531 @ForceInline
532 public $abstractvectortype$ and($type$ o, VectorMask<$Boxtype$> m) {
533 return and(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
534 }
535
536 @Override
537 @ForceInline
538 public $abstractvectortype$ or($type$ o) {
539 return or(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
540 }
541
542 @Override
543 @ForceInline
544 public $abstractvectortype$ or($type$ o, VectorMask<$Boxtype$> m) {
545 return or(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
546 }
547
548 @Override
549 @ForceInline
550 public $abstractvectortype$ xor($type$ o) {
551 return xor(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o));
552 }
553
554 @Override
555 @ForceInline
556 public $abstractvectortype$ xor($type$ o, VectorMask<$Boxtype$> m) {
557 return xor(($vectortype$)$abstractvectortype$.broadcast(SPECIES, o), m);
558 }
559
560 @Override
561 @ForceInline
562 public $vectortype$ neg() {
563 return ($vectortype$)zero(SPECIES).sub(this);
564 }
565 #end[BITWISE]
566
567 // Unary operations
568
569 @ForceInline
570 @Override
571 public $vectortype$ neg(VectorMask<$Boxtype$> m) {
572 return blend(neg(), m);
573 }
574
575 @Override
576 @ForceInline
577 public $vectortype$ abs() {
578 return VectorIntrinsics.unaryOp(
579 VECTOR_OP_ABS, $vectortype$.class, $type$.class, LENGTH,
580 this,
581 v1 -> v1.uOp((i, a) -> ($type$) Math.abs(a)));
582 }
583
584 @ForceInline
585 @Override
586 public $vectortype$ abs(VectorMask<$Boxtype$> m) {
587 return blend(abs(), m);
588 }
589
590 #if[FP]
591 @Override
592 @ForceInline
593 public $vectortype$ neg() {
594 return VectorIntrinsics.unaryOp(
595 VECTOR_OP_NEG, $vectortype$.class, $type$.class, LENGTH,
596 this,
597 v1 -> v1.uOp((i, a) -> ($type$) -a));
598 }
599
600 @Override
601 @ForceInline
602 public $vectortype$ div(Vector<$Boxtype$> o) {
603 Objects.requireNonNull(o);
604 $vectortype$ v = ($vectortype$)o;
605 return VectorIntrinsics.binaryOp(
606 VECTOR_OP_DIV, $vectortype$.class, $type$.class, LENGTH,
782 return ($vectortype$) VectorIntrinsics.binaryOp(
783 VECTOR_OP_ATAN2, $vectortype$.class, $type$.class, LENGTH,
784 this, v,
785 (v1, v2) -> (($vectortype$)v1).bOp(v2, (i, a, b) -> ($type$)(Math.atan2(a,b))));
786 }
787
788 #end[FP]
789
790 #if[BITWISE]
791 @Override
792 @ForceInline
793 public $vectortype$ not() {
794 return VectorIntrinsics.unaryOp(
795 VECTOR_OP_NOT, $vectortype$.class, $type$.class, LENGTH,
796 this,
797 v1 -> v1.uOp((i, a) -> ($type$) ~a));
798 }
799
800 @ForceInline
801 @Override
802 public $vectortype$ not(VectorMask<$Boxtype$> m) {
803 return blend(not(), m);
804 }
805 #end[BITWISE]
806 // Binary operations
807
808 @Override
809 @ForceInline
810 public $vectortype$ add(Vector<$Boxtype$> o) {
811 Objects.requireNonNull(o);
812 $vectortype$ v = ($vectortype$)o;
813 return VectorIntrinsics.binaryOp(
814 VECTOR_OP_ADD, $vectortype$.class, $type$.class, LENGTH,
815 this, v,
816 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$)(a + b)));
817 }
818
819 @Override
820 @ForceInline
821 public $vectortype$ add(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
822 return blend(add(v), m);
823 }
824
825 @Override
826 @ForceInline
827 public $vectortype$ sub(Vector<$Boxtype$> o) {
828 Objects.requireNonNull(o);
829 $vectortype$ v = ($vectortype$)o;
830 return VectorIntrinsics.binaryOp(
831 VECTOR_OP_SUB, $vectortype$.class, $type$.class, LENGTH,
832 this, v,
833 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$)(a - b)));
834 }
835
836 @Override
837 @ForceInline
838 public $vectortype$ sub(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
839 return blend(sub(v), m);
840 }
841
842 @Override
843 @ForceInline
844 public $vectortype$ mul(Vector<$Boxtype$> o) {
845 Objects.requireNonNull(o);
846 $vectortype$ v = ($vectortype$)o;
847 return VectorIntrinsics.binaryOp(
848 VECTOR_OP_MUL, $vectortype$.class, $type$.class, LENGTH,
849 this, v,
850 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$)(a * b)));
851 }
852
853 @Override
854 @ForceInline
855 public $vectortype$ mul(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
856 return blend(mul(v), m);
857 }
858
859 @Override
860 @ForceInline
861 public $vectortype$ min(Vector<$Boxtype$> o) {
862 Objects.requireNonNull(o);
863 $vectortype$ v = ($vectortype$)o;
864 return ($vectortype$) VectorIntrinsics.binaryOp(
865 VECTOR_OP_MIN, $vectortype$.class, $type$.class, LENGTH,
866 this, v,
867 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$) Math.min(a, b)));
868 }
869
870 @Override
871 @ForceInline
872 public $vectortype$ min(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
873 return blend(min(v), m);
874 }
875
876 @Override
877 @ForceInline
878 public $vectortype$ max(Vector<$Boxtype$> o) {
879 Objects.requireNonNull(o);
880 $vectortype$ v = ($vectortype$)o;
881 return VectorIntrinsics.binaryOp(
882 VECTOR_OP_MAX, $vectortype$.class, $type$.class, LENGTH,
883 this, v,
884 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$) Math.max(a, b)));
885 }
886
887 @Override
888 @ForceInline
889 public $vectortype$ max(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
890 return blend(max(v), m);
891 }
892
893 #if[BITWISE]
894 @Override
895 @ForceInline
896 public $vectortype$ and(Vector<$Boxtype$> o) {
897 Objects.requireNonNull(o);
898 $vectortype$ v = ($vectortype$)o;
899 return VectorIntrinsics.binaryOp(
900 VECTOR_OP_AND, $vectortype$.class, $type$.class, LENGTH,
901 this, v,
902 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$)(a & b)));
903 }
904
905 @Override
906 @ForceInline
907 public $vectortype$ or(Vector<$Boxtype$> o) {
908 Objects.requireNonNull(o);
909 $vectortype$ v = ($vectortype$)o;
910 return VectorIntrinsics.binaryOp(
911 VECTOR_OP_OR, $vectortype$.class, $type$.class, LENGTH,
912 this, v,
913 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$)(a | b)));
914 }
915
916 @Override
917 @ForceInline
918 public $vectortype$ xor(Vector<$Boxtype$> o) {
919 Objects.requireNonNull(o);
920 $vectortype$ v = ($vectortype$)o;
921 return VectorIntrinsics.binaryOp(
922 VECTOR_OP_XOR, $vectortype$.class, $type$.class, LENGTH,
923 this, v,
924 (v1, v2) -> v1.bOp(v2, (i, a, b) -> ($type$)(a ^ b)));
925 }
926
927 @Override
928 @ForceInline
929 public $vectortype$ and(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
930 return blend(and(v), m);
931 }
932
933 @Override
934 @ForceInline
935 public $vectortype$ or(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
936 return blend(or(v), m);
937 }
938
939 @Override
940 @ForceInline
941 public $vectortype$ xor(Vector<$Boxtype$> v, VectorMask<$Boxtype$> m) {
942 return blend(xor(v), m);
943 }
944 #end[BITWISE]
945
946 #if[byte]
947 @Override
948 @ForceInline
949 public $vectortype$ shiftL(int s) {
950 return VectorIntrinsics.broadcastInt(
951 VECTOR_OP_LSHIFT, $vectortype$.class, $type$.class, LENGTH,
952 this, s,
953 (v, i) -> v.uOp((__, a) -> ($type$) (a << (i & 7))));
954 }
955
956 @Override
957 @ForceInline
958 public $vectortype$ shiftL(int s, VectorMask<$Boxtype$> m) {
959 return blend(shiftL(s), m);
960 }
961
962 @Override
963 @ForceInline
964 public $vectortype$ shiftR(int s) {
965 return VectorIntrinsics.broadcastInt(
966 VECTOR_OP_URSHIFT, $vectortype$.class, $type$.class, LENGTH,
967 this, s,
968 (v, i) -> v.uOp((__, a) -> ($type$) ((a & 0xFF) >>> (i & 7))));
969 }
970
971 @Override
972 @ForceInline
973 public $vectortype$ shiftR(int s, VectorMask<$Boxtype$> m) {
974 return blend(shiftR(s), m);
975 }
976
977 @Override
978 @ForceInline
979 public $vectortype$ aShiftR(int s) {
980 return VectorIntrinsics.broadcastInt(
981 VECTOR_OP_RSHIFT, $vectortype$.class, $type$.class, LENGTH,
982 this, s,
983 (v, i) -> v.uOp((__, a) -> ($type$) (a >> (i & 7))));
984 }
985
986 @Override
987 @ForceInline
988 public $vectortype$ aShiftR(int s, VectorMask<$Boxtype$> m) {
989 return blend(aShiftR(s), m);
990 }
991 #end[byte]
992 #if[short]
993 @Override
994 @ForceInline
995 public $vectortype$ shiftL(int s) {
996 return VectorIntrinsics.broadcastInt(
997 VECTOR_OP_LSHIFT, $vectortype$.class, $type$.class, LENGTH,
998 this, s,
999 (v, i) -> v.uOp((__, a) -> ($type$) (a << (i & 15))));
1000 }
1001
1002 @Override
1003 @ForceInline
1004 public $vectortype$ shiftL(int s, VectorMask<$Boxtype$> m) {
1005 return blend(shiftL(s), m);
1006 }
1007
1008 @Override
1009 @ForceInline
1010 public $vectortype$ shiftR(int s) {
1011 return VectorIntrinsics.broadcastInt(
1012 VECTOR_OP_URSHIFT, $vectortype$.class, $type$.class, LENGTH,
1013 this, s,
1014 (v, i) -> v.uOp((__, a) -> ($type$) ((a & 0xFFFF) >>> (i & 15))));
1015 }
1016
1017 @Override
1018 @ForceInline
1019 public $vectortype$ shiftR(int s, VectorMask<$Boxtype$> m) {
1020 return blend(shiftR(s), m);
1021 }
1022
1023 @Override
1024 @ForceInline
1025 public $vectortype$ aShiftR(int s) {
1026 return VectorIntrinsics.broadcastInt(
1027 VECTOR_OP_RSHIFT, $vectortype$.class, $type$.class, LENGTH,
1028 this, s,
1029 (v, i) -> v.uOp((__, a) -> ($type$) (a >> (i & 15))));
1030 }
1031
1032 @Override
1033 @ForceInline
1034 public $vectortype$ aShiftR(int s, VectorMask<$Boxtype$> m) {
1035 return blend(aShiftR(s), m);
1036 }
1037 #end[short]
1038 #if[intOrLong]
1039 @Override
1040 @ForceInline
1041 public $vectortype$ shiftL(int s) {
1042 return VectorIntrinsics.broadcastInt(
1043 VECTOR_OP_LSHIFT, $vectortype$.class, $type$.class, LENGTH,
1044 this, s,
1045 (v, i) -> v.uOp((__, a) -> ($type$) (a << i)));
1046 }
1047
1048 @Override
1049 @ForceInline
1050 public $vectortype$ shiftL(int s, VectorMask<$Boxtype$> m) {
1051 return blend(shiftL(s), m);
1052 }
1053
1054 @Override
1055 @ForceInline
1056 public $vectortype$ shiftR(int s) {
1057 return VectorIntrinsics.broadcastInt(
1058 VECTOR_OP_URSHIFT, $vectortype$.class, $type$.class, LENGTH,
1059 this, s,
1060 (v, i) -> v.uOp((__, a) -> ($type$) (a >>> i)));
1061 }
1062
1063 @Override
1064 @ForceInline
1065 public $vectortype$ shiftR(int s, VectorMask<$Boxtype$> m) {
1066 return blend(shiftR(s), m);
1067 }
1068
1069 @Override
1070 @ForceInline
1071 public $vectortype$ aShiftR(int s) {
1072 return VectorIntrinsics.broadcastInt(
1073 VECTOR_OP_RSHIFT, $vectortype$.class, $type$.class, LENGTH,
1074 this, s,
1075 (v, i) -> v.uOp((__, a) -> ($type$) (a >> i)));
1076 }
1077
1078 @Override
1079 @ForceInline
1080 public $vectortype$ aShiftR(int s, VectorMask<$Boxtype$> m) {
1081 return blend(aShiftR(s), m);
1082 }
1083
1084 @Override
1085 @ForceInline
1086 public $vectortype$ shiftL(Vector<$Boxtype$> s) {
1087 $vectortype$ shiftv = ($vectortype$)s;
1088 // As per shift specification for Java, mask the shift count.
1089 shiftv = shiftv.and($abstractvectortype$.broadcast(SPECIES, {#if[int]?0x1f:0x3f}));
1090 return VectorIntrinsics.binaryOp(
1091 VECTOR_OP_LSHIFT, $vectortype$.class, $type$.class, LENGTH,
1092 this, shiftv,
1093 (v1, v2) -> v1.bOp(v2,(i,a, b) -> ($type$) (a << b)));
1094 }
1095
1096 @Override
1097 @ForceInline
1098 public $vectortype$ shiftR(Vector<$Boxtype$> s) {
1099 $vectortype$ shiftv = ($vectortype$)s;
1100 // As per shift specification for Java, mask the shift count.
1140 @Override
1141 @ForceInline
1142 public $type$ addAll() {
1143 return ($type$) VectorIntrinsics.reductionCoerced(
1144 VECTOR_OP_ADD, $vectortype$.class, $type$.class, LENGTH,
1145 this,
1146 v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a + b)));
1147 }
1148
1149 @Override
1150 @ForceInline
1151 public $type$ andAll() {
1152 return ($type$) VectorIntrinsics.reductionCoerced(
1153 VECTOR_OP_AND, $vectortype$.class, $type$.class, LENGTH,
1154 this,
1155 v -> (long) v.rOp(($type$) -1, (i, a, b) -> ($type$) (a & b)));
1156 }
1157
1158 @Override
1159 @ForceInline
1160 public $type$ andAll(VectorMask<$Boxtype$> m) {
1161 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) -1), m).andAll();
1162 }
1163
1164 @Override
1165 @ForceInline
1166 public $type$ minAll() {
1167 return ($type$) VectorIntrinsics.reductionCoerced(
1168 VECTOR_OP_MIN, $vectortype$.class, $type$.class, LENGTH,
1169 this,
1170 v -> (long) v.rOp($Boxtype$.MAX_VALUE , (i, a, b) -> ($type$) Math.min(a, b)));
1171 }
1172
1173 @Override
1174 @ForceInline
1175 public $type$ maxAll() {
1176 return ($type$) VectorIntrinsics.reductionCoerced(
1177 VECTOR_OP_MAX, $vectortype$.class, $type$.class, LENGTH,
1178 this,
1179 v -> (long) v.rOp($Boxtype$.MIN_VALUE , (i, a, b) -> ($type$) Math.max(a, b)));
1180 }
1182 @Override
1183 @ForceInline
1184 public $type$ mulAll() {
1185 return ($type$) VectorIntrinsics.reductionCoerced(
1186 VECTOR_OP_MUL, $vectortype$.class, $type$.class, LENGTH,
1187 this,
1188 v -> (long) v.rOp(($type$) 1, (i, a, b) -> ($type$) (a * b)));
1189 }
1190
1191 @Override
1192 @ForceInline
1193 public $type$ orAll() {
1194 return ($type$) VectorIntrinsics.reductionCoerced(
1195 VECTOR_OP_OR, $vectortype$.class, $type$.class, LENGTH,
1196 this,
1197 v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a | b)));
1198 }
1199
1200 @Override
1201 @ForceInline
1202 public $type$ orAll(VectorMask<$Boxtype$> m) {
1203 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) 0), m).orAll();
1204 }
1205
1206 @Override
1207 @ForceInline
1208 public $type$ xorAll() {
1209 return ($type$) VectorIntrinsics.reductionCoerced(
1210 VECTOR_OP_XOR, $vectortype$.class, $type$.class, LENGTH,
1211 this,
1212 v -> (long) v.rOp(($type$) 0, (i, a, b) -> ($type$) (a ^ b)));
1213 }
1214
1215 @Override
1216 @ForceInline
1217 public $type$ xorAll(VectorMask<$Boxtype$> m) {
1218 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) 0), m).xorAll();
1219 }
1220 #end[BITWISE]
1221
1222 #if[FP]
1223 @Override
1224 @ForceInline
1225 public $type$ addAll() {
1226 $bitstype$ bits = ($bitstype$) VectorIntrinsics.reductionCoerced(
1227 VECTOR_OP_ADD, $vectortype$.class, $type$.class, LENGTH,
1228 this,
1229 v -> {
1230 $type$ r = v.rOp(($type$) 0, (i, a, b) -> ($type$) (a + b));
1231 return (long)$Type$.$type$To$Bitstype$Bits(r);
1232 });
1233 return $Type$.$bitstype$BitsTo$Fptype$(bits);
1234 }
1235
1236 @Override
1237 @ForceInline
1259 return $Type$.$bitstype$BitsTo$Fptype$(bits);
1260 }
1261
1262 @Override
1263 @ForceInline
1264 public $type$ maxAll() {
1265 $bitstype$ bits = ($bitstype$) VectorIntrinsics.reductionCoerced(
1266 VECTOR_OP_MAX, $vectortype$.class, $type$.class, LENGTH,
1267 this,
1268 v -> {
1269 $type$ r = v.rOp($Boxtype$.NEGATIVE_INFINITY, (i, a, b) -> ($type$) Math.max(a, b));
1270 return (long)$Type$.$type$To$Bitstype$Bits(r);
1271 });
1272 return $Type$.$bitstype$BitsTo$Fptype$(bits);
1273 }
1274
1275 #end[FP]
1276
1277 @Override
1278 @ForceInline
1279 public $type$ addAll(VectorMask<$Boxtype$> m) {
1280 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) 0), m).addAll();
1281 }
1282
1283
1284 @Override
1285 @ForceInline
1286 public $type$ mulAll(VectorMask<$Boxtype$> m) {
1287 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, ($type$) 1), m).mulAll();
1288 }
1289
1290 @Override
1291 @ForceInline
1292 public $type$ minAll(VectorMask<$Boxtype$> m) {
1293 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, $Boxtype$.MAX_VALUE), m).minAll();
1294 }
1295
1296 @Override
1297 @ForceInline
1298 public $type$ maxAll(VectorMask<$Boxtype$> m) {
1299 return blend(($vectortype$)$abstractvectortype$.broadcast(SPECIES, $Boxtype$.MIN_VALUE), m).maxAll();
1300 }
1301
1302 @Override
1303 @ForceInline
1304 public VectorShuffle<$Boxtype$> toShuffle() {
1305 $type$[] a = toArray();
1306 int[] sa = new int[a.length];
1307 for (int i = 0; i < a.length; i++) {
1308 sa[i] = (int) a[i];
1309 }
1310 return VectorShuffle.fromArray(SPECIES, sa, 0);
1311 }
1312
1313 // Memory operations
1314
1315 private static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_$TYPE$_INDEX_SCALE);
1316 private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
1317
1318 @Override
1319 @ForceInline
1320 public void intoArray($type$[] a, int ix) {
1321 Objects.requireNonNull(a);
1322 ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
1323 VectorIntrinsics.store($vectortype$.class, $type$.class, LENGTH,
1324 a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_$TYPE$_BASE_OFFSET,
1325 this,
1326 a, ix,
1327 (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
1328 }
1329
1330 @Override
1331 @ForceInline
1332 public final void intoArray($type$[] a, int ax, VectorMask<$Boxtype$> m) {
1333 $abstractvectortype$ oldVal = $abstractvectortype$.fromArray(SPECIES, a, ax);
1334 $abstractvectortype$ newVal = oldVal.blend(this, m);
1335 newVal.intoArray(a, ax);
1336 }
1337 #if[!byteOrShort]
1338 @Override
1339 @ForceInline
1340 public void intoArray($type$[] a, int ix, int[] b, int iy) {
1341 #if[longOrDouble64]
1342 this.intoArray(a, ix + b[iy]);
1343 #else[longOrDouble64]
1344 Objects.requireNonNull(a);
1345 Objects.requireNonNull(b);
1346
1347 // Index vector: vix[0:n] = i -> ix + indexMap[iy + i]
1348 IntVector vix = IntVector.fromArray(INDEX_SPECIES, b, iy).add(ix);
1349
1350 vix = VectorIntrinsics.checkIndex(vix, a.length);
1351
1352 VectorIntrinsics.storeWithMap($vectortype$.class, $type$.class, LENGTH, $vectorindextype$,
1353 a, Unsafe.ARRAY_$TYPE$_BASE_OFFSET, vix,
1354 this,
1355 a, ix, b, iy,
1356 (arr, idx, v, indexMap, idy) -> v.forEach((i, e) -> arr[idx+indexMap[idy+i]] = e));
1357 #end[longOrDouble64]
1358 }
1359
1360 @Override
1361 @ForceInline
1362 public final void intoArray($type$[] a, int ax, VectorMask<$Boxtype$> m, int[] b, int iy) {
1363 // @@@ This can result in out of bounds errors for unset mask lanes
1364 $abstractvectortype$ oldVal = $abstractvectortype$.fromArray(SPECIES, a, ax, b, iy);
1365 $abstractvectortype$ newVal = oldVal.blend(this, m);
1366 newVal.intoArray(a, ax, b, iy);
1367 }
1368 #end[!byteOrShort]
1369
1370 @Override
1371 @ForceInline
1372 public void intoByteArray(byte[] a, int ix) {
1373 Objects.requireNonNull(a);
1374 ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
1375 VectorIntrinsics.store($vectortype$.class, $type$.class, LENGTH,
1376 a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
1377 this,
1378 a, ix,
1379 (c, idx, v) -> {
1380 ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
1381 $Type$Buffer tb = bbc{#if[byte]?;:.as$Type$Buffer();}
1382 v.forEach((i, e) -> tb.put(e));
1383 });
1384 }
1385
1386 @Override
1387 @ForceInline
1388 public final void intoByteArray(byte[] a, int ix, VectorMask<$Boxtype$> m) {
1389 $vectortype$ oldVal = ($vectortype$) $abstractvectortype$.fromByteArray(SPECIES, a, ix);
1390 $vectortype$ newVal = oldVal.blend(this, m);
1391 newVal.intoByteArray(a, ix);
1392 }
1393
1394 @Override
1395 @ForceInline
1396 public void intoByteBuffer(ByteBuffer bb, int ix) {
1397 if (bb.order() != ByteOrder.nativeOrder()) {
1398 throw new IllegalArgumentException();
1399 }
1400 if (bb.isReadOnly()) {
1401 throw new ReadOnlyBufferException();
1402 }
1403 ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
1404 VectorIntrinsics.store($vectortype$.class, $type$.class, LENGTH,
1405 U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
1406 this,
1407 bb, ix,
1408 (c, idx, v) -> {
1409 ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
1410 $Type$Buffer tb = bbc{#if[byte]?;:.as$Type$Buffer();}
1411 v.forEach((i, e) -> tb.put(e));
1412 });
1413 }
1414
1415 @Override
1416 @ForceInline
1417 public void intoByteBuffer(ByteBuffer bb, int ix, VectorMask<$Boxtype$> m) {
1418 $vectortype$ oldVal = ($vectortype$) $abstractvectortype$.fromByteBuffer(SPECIES, bb, ix);
1419 $vectortype$ newVal = oldVal.blend(this, m);
1420 newVal.intoByteBuffer(bb, ix);
1421 }
1422
1423 //
1424
1425 @Override
1426 public String toString() {
1427 return Arrays.toString(getElements());
1428 }
1429
1430 @Override
1431 public boolean equals(Object o) {
1432 if (this == o) return true;
1433 if (o == null || this.getClass() != o.getClass()) return false;
1434
1435 $vectortype$ that = ($vectortype$) o;
1436 return this.equal(that).allTrue();
1437 }
1522 Objects.requireNonNull(o);
1523 $vectortype$ v = ($vectortype$)o;
1524
1525 return VectorIntrinsics.compare(
1526 BT_ge, $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
1527 this, v,
1528 (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1529 }
1530
1531 // Foreach
1532
1533 @Override
1534 void forEach(FUnCon f) {
1535 $type$[] vec = getElements();
1536 for (int i = 0; i < length(); i++) {
1537 f.apply(i, vec[i]);
1538 }
1539 }
1540
1541 @Override
1542 void forEach(VectorMask<$Boxtype$> o, FUnCon f) {
1543 boolean[] mbits = (($masktype$)o).getBits();
1544 forEach((i, a) -> {
1545 if (mbits[i]) { f.apply(i, a); }
1546 });
1547 }
1548
1549 #if[FP]
1550 $bitsvectortype$ toBits() {
1551 $type$[] vec = getElements();
1552 $bitstype$[] res = new $bitstype$[this.species().length()];
1553 for(int i = 0; i < this.species().length(); i++){
1554 res[i] = $Type$.$type$To$Bitstype$Bits(vec[i]);
1555 }
1556 return new $bitsvectortype$(res);
1557 }
1558 #end[FP]
1559
1560 #if[intOrLong]
1561 $fpvectortype$ toFP() {
1562 $type$[] vec = getElements();
1599 $type$[] res = new $type$[length()];
1600 for (int i = 0; i < length() - j; i++) {
1601 res[i] = vec[i + j];
1602 }
1603 return new $vectortype$(res);
1604 }
1605
1606 @Override
1607 public $vectortype$ shiftER(int j) {
1608 $type$[] vec = getElements();
1609 $type$[] res = new $type$[length()];
1610 for (int i = 0; i < length() - j; i++){
1611 res[i + j] = vec[i];
1612 }
1613 return new $vectortype$(res);
1614 }
1615
1616 @Override
1617 @ForceInline
1618 public $vectortype$ rearrange(Vector<$Boxtype$> v,
1619 VectorShuffle<$Boxtype$> s, VectorMask<$Boxtype$> m) {
1620 return this.rearrange(s).blend(v.rearrange(s), m);
1621 }
1622
1623 @Override
1624 @ForceInline
1625 public $vectortype$ rearrange(VectorShuffle<$Boxtype$> o1) {
1626 Objects.requireNonNull(o1);
1627 $shuffletype$ s = ($shuffletype$)o1;
1628
1629 return VectorIntrinsics.rearrangeOp(
1630 $vectortype$.class, $shuffletype$.class, $type$.class, LENGTH,
1631 this, s,
1632 (v1, s_) -> v1.uOp((i, a) -> {
1633 int ei = s_.getElement(i);
1634 return v1.get(ei);
1635 }));
1636 }
1637
1638 @Override
1639 @ForceInline
1640 public $vectortype$ blend(Vector<$Boxtype$> o1, VectorMask<$Boxtype$> o2) {
1641 Objects.requireNonNull(o1);
1642 Objects.requireNonNull(o2);
1643 $vectortype$ v = ($vectortype$)o1;
1644 $masktype$ m = ($masktype$)o2;
1645
1646 return VectorIntrinsics.blend(
1647 $vectortype$.class, $masktype$.class, $type$.class, LENGTH,
1648 this, v, m,
1649 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1650 }
1651
1652 // Accessors
1653
1654 #if[FP]
1655 @Override
1656 public $type$ get(int i) {
1657 if (i < 0 || i >= LENGTH) {
1658 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1659 }
1660 $bitstype$ bits = ($bitstype$) VectorIntrinsics.extract(
1736 boolean[] bits = new boolean[species().length()];
1737 Arrays.fill(bits, val);
1738 this.bits = bits;
1739 }
1740
1741 boolean[] getBits() {
1742 return VectorIntrinsics.maybeRebox(this).bits;
1743 }
1744
1745 @Override
1746 $masktype$ uOp(MUnOp f) {
1747 boolean[] res = new boolean[species().length()];
1748 boolean[] bits = getBits();
1749 for (int i = 0; i < species().length(); i++) {
1750 res[i] = f.apply(i, bits[i]);
1751 }
1752 return new $masktype$(res);
1753 }
1754
1755 @Override
1756 $masktype$ bOp(VectorMask<$Boxtype$> o, MBinOp f) {
1757 boolean[] res = new boolean[species().length()];
1758 boolean[] bits = getBits();
1759 boolean[] mbits = (($masktype$)o).getBits();
1760 for (int i = 0; i < species().length(); i++) {
1761 res[i] = f.apply(i, bits[i], mbits[i]);
1762 }
1763 return new $masktype$(res);
1764 }
1765
1766 @Override
1767 public VectorSpecies<$Boxtype$> species() {
1768 return SPECIES;
1769 }
1770
1771 @Override
1772 public $vectortype$ toVector() {
1773 $type$[] res = new $type$[species().length()];
1774 boolean[] bits = getBits();
1775 for (int i = 0; i < species().length(); i++) {
1776 // -1 will result in the most significant bit being set in
1777 // addition to some or all other bits
1778 res[i] = ($type$) (bits[i] ? -1 : 0);
1779 }
1780 return new $vectortype$(res);
1781 }
1782
1783 @Override
1784 @ForceInline
1785 @SuppressWarnings("unchecked")
1786 public <E> VectorMask<E> cast(VectorSpecies<E> species) {
1787 if (length() != species.length())
1788 throw new IllegalArgumentException("VectorMask length and species length differ");
1789 Class<?> stype = species.elementType();
1790 boolean [] maskArray = toArray();
1791 if (stype == byte.class) {
1792 return (VectorMask <E>) new Byte$bits$Vector.Byte$bits$Mask(maskArray);
1793 } else if (stype == short.class) {
1794 return (VectorMask <E>) new Short$bits$Vector.Short$bits$Mask(maskArray);
1795 } else if (stype == int.class) {
1796 return (VectorMask <E>) new Int$bits$Vector.Int$bits$Mask(maskArray);
1797 } else if (stype == long.class) {
1798 return (VectorMask <E>) new Long$bits$Vector.Long$bits$Mask(maskArray);
1799 } else if (stype == float.class) {
1800 return (VectorMask <E>) new Float$bits$Vector.Float$bits$Mask(maskArray);
1801 } else if (stype == double.class) {
1802 return (VectorMask <E>) new Double$bits$Vector.Double$bits$Mask(maskArray);
1803 } else {
1804 throw new UnsupportedOperationException("Bad lane type for casting.");
1805 }
1806 }
1807
1808 // Unary operations
1809
1810 @Override
1811 @ForceInline
1812 public $masktype$ not() {
1813 return ($masktype$) VectorIntrinsics.unaryOp(
1814 VECTOR_OP_NOT, $masktype$.class, $bitstype$.class, LENGTH,
1815 this,
1816 (m1) -> m1.uOp((i, a) -> !a));
1817 }
1818
1819 // Binary operations
1820
1821 @Override
1822 @ForceInline
1823 public $masktype$ and(VectorMask<$Boxtype$> o) {
1824 Objects.requireNonNull(o);
1825 $masktype$ m = ($masktype$)o;
1826 return VectorIntrinsics.binaryOp(VECTOR_OP_AND, $masktype$.class, $bitstype$.class, LENGTH,
1827 this, m,
1828 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1829 }
1830
1831 @Override
1832 @ForceInline
1833 public $masktype$ or(VectorMask<$Boxtype$> o) {
1834 Objects.requireNonNull(o);
1835 $masktype$ m = ($masktype$)o;
1836 return VectorIntrinsics.binaryOp(VECTOR_OP_OR, $masktype$.class, $bitstype$.class, LENGTH,
1837 this, m,
1838 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1839 }
1840
1841 // Reductions
1842
1843 @Override
1844 @ForceInline
1845 public boolean anyTrue() {
1846 return VectorIntrinsics.test(BT_ne, $masktype$.class, $bitstype$.class, LENGTH,
1847 this, this,
1848 (m, __) -> anyTrueHelper((($masktype$)m).getBits()));
1849 }
1850
1851 @Override
1852 @ForceInline
1853 public boolean allTrue() {
1854 return VectorIntrinsics.test(BT_overflow, $masktype$.class, $bitstype$.class, LENGTH,
1855 this, VectorMask.maskAllTrue(species()),
1856 (m, __) -> allTrueHelper((($masktype$)m).getBits()));
1857 }
1858 }
1859
1860 // Shuffle
1861
1862 static final class $shuffletype$ extends AbstractShuffle<$Boxtype$> {
1863 $shuffletype$(byte[] reorder) {
1864 super(reorder);
1865 }
1866
1867 public $shuffletype$(int[] reorder) {
1868 super(reorder);
1869 }
1870
1871 public $shuffletype$(int[] reorder, int i) {
1872 super(reorder, i);
1873 }
1874
1875 public $shuffletype$(IntUnaryOperator f) {
1876 super(f);
1877 }
1878
1879 @Override
1880 public VectorSpecies<$Boxtype$> species() {
1881 return SPECIES;
1882 }
1883
1884 @Override
1885 public $abstractvectortype$ toVector() {
1886 $type$[] va = new $type$[SPECIES.length()];
1887 for (int i = 0; i < va.length; i++) {
1888 va[i] = ($type$) getElement(i);
1889 }
1890 return $abstractvectortype$.fromArray(SPECIES, va, 0);
1891 }
1892
1893 @Override
1894 @ForceInline
1895 @SuppressWarnings("unchecked")
1896 public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
1897 if (length() != species.length())
1898 throw new IllegalArgumentException("Shuffle length and species length differ");
1899 Class<?> stype = species.elementType();
1900 int [] shuffleArray = toArray();
1901 if (stype == byte.class) {
1902 return (VectorShuffle<F>) new Byte$bits$Vector.Byte$bits$Shuffle(shuffleArray);
1903 } else if (stype == short.class) {
1904 return (VectorShuffle<F>) new Short$bits$Vector.Short$bits$Shuffle(shuffleArray);
1905 } else if (stype == int.class) {
1906 return (VectorShuffle<F>) new Int$bits$Vector.Int$bits$Shuffle(shuffleArray);
1907 } else if (stype == long.class) {
1908 return (VectorShuffle<F>) new Long$bits$Vector.Long$bits$Shuffle(shuffleArray);
1909 } else if (stype == float.class) {
1910 return (VectorShuffle<F>) new Float$bits$Vector.Float$bits$Shuffle(shuffleArray);
1911 } else if (stype == double.class) {
1912 return (VectorShuffle<F>) new Double$bits$Vector.Double$bits$Shuffle(shuffleArray);
1913 } else {
1914 throw new UnsupportedOperationException("Bad lane type for casting.");
1915 }
1916 }
1917
1918 @Override
1919 public $shuffletype$ rearrange(VectorShuffle<$Boxtype$> o) {
1920 $shuffletype$ s = ($shuffletype$) o;
1921 byte[] r = new byte[reorder.length];
1922 for (int i = 0; i < reorder.length; i++) {
1923 r[i] = reorder[s.reorder[i]];
1924 }
1925 return new $shuffletype$(r);
1926 }
1927 }
1928
1929 // VectorSpecies
1930
1931 @Override
1932 public VectorSpecies<$Boxtype$> species() {
1933 return SPECIES;
1934 }
1935 }
|