21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have
23 * questions.
24 */
25 package jdk.incubator.vector;
26
27 import java.nio.ByteBuffer;
28 import java.nio.ByteOrder;
29 import java.nio.ShortBuffer;
30 import java.nio.ReadOnlyBufferException;
31 import java.util.Arrays;
32 import java.util.Objects;
33 import java.util.function.IntUnaryOperator;
34
35 import jdk.internal.misc.Unsafe;
36 import jdk.internal.vm.annotation.ForceInline;
37 import static jdk.incubator.vector.VectorIntrinsics.*;
38
39 @SuppressWarnings("cast")
40 final class Short64Vector extends ShortVector {
41 private static final Species<Short> SPECIES = ShortVector.SPECIES_64;
42
43 static final Short64Vector ZERO = new Short64Vector();
44
45 static final int LENGTH = SPECIES.length();
46
47 private final short[] vec; // Don't access directly, use getElements() instead.
48
49 private short[] getElements() {
50 return VectorIntrinsics.maybeRebox(this).vec;
51 }
52
53 Short64Vector() {
54 vec = new short[SPECIES.length()];
55 }
56
57 Short64Vector(short[] v) {
58 vec = v;
59 }
60
61 @Override
62 public int length() { return LENGTH; }
63
64 // Unary operator
65
66 @Override
67 Short64Vector uOp(FUnOp f) {
68 short[] vec = getElements();
69 short[] res = new short[length()];
70 for (int i = 0; i < length(); i++) {
71 res[i] = f.apply(i, vec[i]);
72 }
73 return new Short64Vector(res);
74 }
75
76 @Override
77 Short64Vector uOp(Mask<Short> o, FUnOp f) {
78 short[] vec = getElements();
79 short[] res = new short[length()];
80 boolean[] mbits = ((Short64Mask)o).getBits();
81 for (int i = 0; i < length(); i++) {
82 res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
83 }
84 return new Short64Vector(res);
85 }
86
87 // Binary operator
88
89 @Override
90 Short64Vector bOp(Vector<Short> o, FBinOp f) {
91 short[] res = new short[length()];
92 short[] vec1 = this.getElements();
93 short[] vec2 = ((Short64Vector)o).getElements();
94 for (int i = 0; i < length(); i++) {
95 res[i] = f.apply(i, vec1[i], vec2[i]);
96 }
97 return new Short64Vector(res);
98 }
99
100 @Override
101 Short64Vector bOp(Vector<Short> o1, Mask<Short> o2, FBinOp f) {
102 short[] res = new short[length()];
103 short[] vec1 = this.getElements();
104 short[] vec2 = ((Short64Vector)o1).getElements();
105 boolean[] mbits = ((Short64Mask)o2).getBits();
106 for (int i = 0; i < length(); i++) {
107 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
108 }
109 return new Short64Vector(res);
110 }
111
112 // Trinary operator
113
114 @Override
115 Short64Vector tOp(Vector<Short> o1, Vector<Short> o2, FTriOp f) {
116 short[] res = new short[length()];
117 short[] vec1 = this.getElements();
118 short[] vec2 = ((Short64Vector)o1).getElements();
119 short[] vec3 = ((Short64Vector)o2).getElements();
120 for (int i = 0; i < length(); i++) {
121 res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
122 }
123 return new Short64Vector(res);
124 }
125
126 @Override
127 Short64Vector tOp(Vector<Short> o1, Vector<Short> o2, Mask<Short> o3, FTriOp f) {
128 short[] res = new short[length()];
129 short[] vec1 = getElements();
130 short[] vec2 = ((Short64Vector)o1).getElements();
131 short[] vec3 = ((Short64Vector)o2).getElements();
132 boolean[] mbits = ((Short64Mask)o3).getBits();
133 for (int i = 0; i < length(); i++) {
134 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
135 }
136 return new Short64Vector(res);
137 }
138
139 @Override
140 short rOp(short v, FBinOp f) {
141 short[] vec = getElements();
142 for (int i = 0; i < length(); i++) {
143 v = f.apply(i, v, vec[i]);
144 }
145 return v;
146 }
147
148 @Override
149 @ForceInline
150 public <F> Vector<F> cast(Species<F> s) {
151 Objects.requireNonNull(s);
152 if (s.length() != LENGTH)
153 throw new IllegalArgumentException("Vector length this species length differ");
154
155 return VectorIntrinsics.cast(
156 Short64Vector.class,
157 short.class, LENGTH,
158 s.boxType(),
159 s.elementType(), LENGTH,
160 this, s,
161 (species, vector) -> vector.castDefault(species)
162 );
163 }
164
165 @SuppressWarnings("unchecked")
166 @ForceInline
167 private <F> Vector<F> castDefault(Species<F> s) {
168 int limit = s.length();
169
170 Class<?> stype = s.elementType();
171 if (stype == byte.class) {
172 byte[] a = new byte[limit];
173 for (int i = 0; i < limit; i++) {
174 a[i] = (byte) this.get(i);
175 }
176 return (Vector) ByteVector.fromArray((Species<Byte>) s, a, 0);
177 } else if (stype == short.class) {
178 short[] a = new short[limit];
179 for (int i = 0; i < limit; i++) {
180 a[i] = (short) this.get(i);
181 }
182 return (Vector) ShortVector.fromArray((Species<Short>) s, a, 0);
183 } else if (stype == int.class) {
184 int[] a = new int[limit];
185 for (int i = 0; i < limit; i++) {
186 a[i] = (int) this.get(i);
187 }
188 return (Vector) IntVector.fromArray((Species<Integer>) s, a, 0);
189 } else if (stype == long.class) {
190 long[] a = new long[limit];
191 for (int i = 0; i < limit; i++) {
192 a[i] = (long) this.get(i);
193 }
194 return (Vector) LongVector.fromArray((Species<Long>) s, a, 0);
195 } else if (stype == float.class) {
196 float[] a = new float[limit];
197 for (int i = 0; i < limit; i++) {
198 a[i] = (float) this.get(i);
199 }
200 return (Vector) FloatVector.fromArray((Species<Float>) s, a, 0);
201 } else if (stype == double.class) {
202 double[] a = new double[limit];
203 for (int i = 0; i < limit; i++) {
204 a[i] = (double) this.get(i);
205 }
206 return (Vector) DoubleVector.fromArray((Species<Double>) s, a, 0);
207 } else {
208 throw new UnsupportedOperationException("Bad lane type for casting.");
209 }
210 }
211
212 @Override
213 @ForceInline
214 @SuppressWarnings("unchecked")
215 public <F> Vector<F> reinterpret(Species<F> s) {
216 Objects.requireNonNull(s);
217
218 if(s.elementType().equals(short.class)) {
219 return (Vector<F>) reshape((Species<Short>)s);
220 }
221 if(s.bitSize() == bitSize()) {
222 return reinterpretType(s);
223 }
224
225 return defaultReinterpret(s);
226 }
227
228 @ForceInline
229 private <F> Vector<F> reinterpretType(Species<F> s) {
230 Objects.requireNonNull(s);
231
232 Class<?> stype = s.elementType();
233 if (stype == byte.class) {
234 return VectorIntrinsics.reinterpret(
235 Short64Vector.class,
236 short.class, LENGTH,
237 Byte64Vector.class,
238 byte.class, Byte64Vector.LENGTH,
239 this, s,
240 (species, vector) -> vector.defaultReinterpret(species)
241 );
242 } else if (stype == short.class) {
243 return VectorIntrinsics.reinterpret(
244 Short64Vector.class,
245 short.class, LENGTH,
246 Short64Vector.class,
247 short.class, Short64Vector.LENGTH,
248 this, s,
249 (species, vector) -> vector.defaultReinterpret(species)
274 float.class, Float64Vector.LENGTH,
275 this, s,
276 (species, vector) -> vector.defaultReinterpret(species)
277 );
278 } else if (stype == double.class) {
279 return VectorIntrinsics.reinterpret(
280 Short64Vector.class,
281 short.class, LENGTH,
282 Double64Vector.class,
283 double.class, Double64Vector.LENGTH,
284 this, s,
285 (species, vector) -> vector.defaultReinterpret(species)
286 );
287 } else {
288 throw new UnsupportedOperationException("Bad lane type for casting.");
289 }
290 }
291
292 @Override
293 @ForceInline
294 public ShortVector reshape(Species<Short> s) {
295 Objects.requireNonNull(s);
296 if (s.bitSize() == 64 && (s.boxType() == Short64Vector.class)) {
297 return VectorIntrinsics.reinterpret(
298 Short64Vector.class,
299 short.class, LENGTH,
300 Short64Vector.class,
301 short.class, Short64Vector.LENGTH,
302 this, s,
303 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
304 );
305 } else if (s.bitSize() == 128 && (s.boxType() == Short128Vector.class)) {
306 return VectorIntrinsics.reinterpret(
307 Short64Vector.class,
308 short.class, LENGTH,
309 Short128Vector.class,
310 short.class, Short128Vector.LENGTH,
311 this, s,
312 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
313 );
314 } else if (s.bitSize() == 256 && (s.boxType() == Short256Vector.class)) {
337 ShortMaxVector.class,
338 short.class, ShortMaxVector.LENGTH,
339 this, s,
340 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
341 );
342 } else {
343 throw new InternalError("Unimplemented size");
344 }
345 }
346
347 // Binary operations with scalars
348
349 @Override
350 @ForceInline
351 public ShortVector add(short o) {
352 return add((Short64Vector)ShortVector.broadcast(SPECIES, o));
353 }
354
355 @Override
356 @ForceInline
357 public ShortVector add(short o, Mask<Short> m) {
358 return add((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
359 }
360
361 @Override
362 @ForceInline
363 public ShortVector sub(short o) {
364 return sub((Short64Vector)ShortVector.broadcast(SPECIES, o));
365 }
366
367 @Override
368 @ForceInline
369 public ShortVector sub(short o, Mask<Short> m) {
370 return sub((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
371 }
372
373 @Override
374 @ForceInline
375 public ShortVector mul(short o) {
376 return mul((Short64Vector)ShortVector.broadcast(SPECIES, o));
377 }
378
379 @Override
380 @ForceInline
381 public ShortVector mul(short o, Mask<Short> m) {
382 return mul((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
383 }
384
385 @Override
386 @ForceInline
387 public ShortVector min(short o) {
388 return min((Short64Vector)ShortVector.broadcast(SPECIES, o));
389 }
390
391 @Override
392 @ForceInline
393 public ShortVector max(short o) {
394 return max((Short64Vector)ShortVector.broadcast(SPECIES, o));
395 }
396
397 @Override
398 @ForceInline
399 public Mask<Short> equal(short o) {
400 return equal((Short64Vector)ShortVector.broadcast(SPECIES, o));
401 }
402
403 @Override
404 @ForceInline
405 public Mask<Short> notEqual(short o) {
406 return notEqual((Short64Vector)ShortVector.broadcast(SPECIES, o));
407 }
408
409 @Override
410 @ForceInline
411 public Mask<Short> lessThan(short o) {
412 return lessThan((Short64Vector)ShortVector.broadcast(SPECIES, o));
413 }
414
415 @Override
416 @ForceInline
417 public Mask<Short> lessThanEq(short o) {
418 return lessThanEq((Short64Vector)ShortVector.broadcast(SPECIES, o));
419 }
420
421 @Override
422 @ForceInline
423 public Mask<Short> greaterThan(short o) {
424 return greaterThan((Short64Vector)ShortVector.broadcast(SPECIES, o));
425 }
426
427 @Override
428 @ForceInline
429 public Mask<Short> greaterThanEq(short o) {
430 return greaterThanEq((Short64Vector)ShortVector.broadcast(SPECIES, o));
431 }
432
433 @Override
434 @ForceInline
435 public ShortVector blend(short o, Mask<Short> m) {
436 return blend((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
437 }
438
439
440 @Override
441 @ForceInline
442 public ShortVector and(short o) {
443 return and((Short64Vector)ShortVector.broadcast(SPECIES, o));
444 }
445
446 @Override
447 @ForceInline
448 public ShortVector and(short o, Mask<Short> m) {
449 return and((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
450 }
451
452 @Override
453 @ForceInline
454 public ShortVector or(short o) {
455 return or((Short64Vector)ShortVector.broadcast(SPECIES, o));
456 }
457
458 @Override
459 @ForceInline
460 public ShortVector or(short o, Mask<Short> m) {
461 return or((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
462 }
463
464 @Override
465 @ForceInline
466 public ShortVector xor(short o) {
467 return xor((Short64Vector)ShortVector.broadcast(SPECIES, o));
468 }
469
470 @Override
471 @ForceInline
472 public ShortVector xor(short o, Mask<Short> m) {
473 return xor((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
474 }
475
476 @Override
477 @ForceInline
478 public Short64Vector neg() {
479 return (Short64Vector)zero(SPECIES).sub(this);
480 }
481
482 // Unary operations
483
484 @ForceInline
485 @Override
486 public Short64Vector neg(Mask<Short> m) {
487 return blend(neg(), m);
488 }
489
490 @Override
491 @ForceInline
492 public Short64Vector abs() {
493 return VectorIntrinsics.unaryOp(
494 VECTOR_OP_ABS, Short64Vector.class, short.class, LENGTH,
495 this,
496 v1 -> v1.uOp((i, a) -> (short) Math.abs(a)));
497 }
498
499 @ForceInline
500 @Override
501 public Short64Vector abs(Mask<Short> m) {
502 return blend(abs(), m);
503 }
504
505
506 @Override
507 @ForceInline
508 public Short64Vector not() {
509 return VectorIntrinsics.unaryOp(
510 VECTOR_OP_NOT, Short64Vector.class, short.class, LENGTH,
511 this,
512 v1 -> v1.uOp((i, a) -> (short) ~a));
513 }
514
515 @ForceInline
516 @Override
517 public Short64Vector not(Mask<Short> m) {
518 return blend(not(), m);
519 }
520 // Binary operations
521
522 @Override
523 @ForceInline
524 public Short64Vector add(Vector<Short> o) {
525 Objects.requireNonNull(o);
526 Short64Vector v = (Short64Vector)o;
527 return VectorIntrinsics.binaryOp(
528 VECTOR_OP_ADD, Short64Vector.class, short.class, LENGTH,
529 this, v,
530 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a + b)));
531 }
532
533 @Override
534 @ForceInline
535 public Short64Vector add(Vector<Short> v, Mask<Short> m) {
536 return blend(add(v), m);
537 }
538
539 @Override
540 @ForceInline
541 public Short64Vector sub(Vector<Short> o) {
542 Objects.requireNonNull(o);
543 Short64Vector v = (Short64Vector)o;
544 return VectorIntrinsics.binaryOp(
545 VECTOR_OP_SUB, Short64Vector.class, short.class, LENGTH,
546 this, v,
547 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a - b)));
548 }
549
550 @Override
551 @ForceInline
552 public Short64Vector sub(Vector<Short> v, Mask<Short> m) {
553 return blend(sub(v), m);
554 }
555
556 @Override
557 @ForceInline
558 public Short64Vector mul(Vector<Short> o) {
559 Objects.requireNonNull(o);
560 Short64Vector v = (Short64Vector)o;
561 return VectorIntrinsics.binaryOp(
562 VECTOR_OP_MUL, Short64Vector.class, short.class, LENGTH,
563 this, v,
564 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a * b)));
565 }
566
567 @Override
568 @ForceInline
569 public Short64Vector mul(Vector<Short> v, Mask<Short> m) {
570 return blend(mul(v), m);
571 }
572
573 @Override
574 @ForceInline
575 public Short64Vector min(Vector<Short> o) {
576 Objects.requireNonNull(o);
577 Short64Vector v = (Short64Vector)o;
578 return (Short64Vector) VectorIntrinsics.binaryOp(
579 VECTOR_OP_MIN, Short64Vector.class, short.class, LENGTH,
580 this, v,
581 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short) Math.min(a, b)));
582 }
583
584 @Override
585 @ForceInline
586 public Short64Vector min(Vector<Short> v, Mask<Short> m) {
587 return blend(min(v), m);
588 }
589
590 @Override
591 @ForceInline
592 public Short64Vector max(Vector<Short> o) {
593 Objects.requireNonNull(o);
594 Short64Vector v = (Short64Vector)o;
595 return VectorIntrinsics.binaryOp(
596 VECTOR_OP_MAX, Short64Vector.class, short.class, LENGTH,
597 this, v,
598 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short) Math.max(a, b)));
599 }
600
601 @Override
602 @ForceInline
603 public Short64Vector max(Vector<Short> v, Mask<Short> m) {
604 return blend(max(v), m);
605 }
606
607 @Override
608 @ForceInline
609 public Short64Vector and(Vector<Short> o) {
610 Objects.requireNonNull(o);
611 Short64Vector v = (Short64Vector)o;
612 return VectorIntrinsics.binaryOp(
613 VECTOR_OP_AND, Short64Vector.class, short.class, LENGTH,
614 this, v,
615 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a & b)));
616 }
617
618 @Override
619 @ForceInline
620 public Short64Vector or(Vector<Short> o) {
621 Objects.requireNonNull(o);
622 Short64Vector v = (Short64Vector)o;
623 return VectorIntrinsics.binaryOp(
624 VECTOR_OP_OR, Short64Vector.class, short.class, LENGTH,
625 this, v,
626 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a | b)));
627 }
628
629 @Override
630 @ForceInline
631 public Short64Vector xor(Vector<Short> o) {
632 Objects.requireNonNull(o);
633 Short64Vector v = (Short64Vector)o;
634 return VectorIntrinsics.binaryOp(
635 VECTOR_OP_XOR, Short64Vector.class, short.class, LENGTH,
636 this, v,
637 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a ^ b)));
638 }
639
640 @Override
641 @ForceInline
642 public Short64Vector and(Vector<Short> v, Mask<Short> m) {
643 return blend(and(v), m);
644 }
645
646 @Override
647 @ForceInline
648 public Short64Vector or(Vector<Short> v, Mask<Short> m) {
649 return blend(or(v), m);
650 }
651
652 @Override
653 @ForceInline
654 public Short64Vector xor(Vector<Short> v, Mask<Short> m) {
655 return blend(xor(v), m);
656 }
657
658 @Override
659 @ForceInline
660 public Short64Vector shiftL(int s) {
661 return VectorIntrinsics.broadcastInt(
662 VECTOR_OP_LSHIFT, Short64Vector.class, short.class, LENGTH,
663 this, s,
664 (v, i) -> v.uOp((__, a) -> (short) (a << (i & 15))));
665 }
666
667 @Override
668 @ForceInline
669 public Short64Vector shiftL(int s, Mask<Short> m) {
670 return blend(shiftL(s), m);
671 }
672
673 @Override
674 @ForceInline
675 public Short64Vector shiftR(int s) {
676 return VectorIntrinsics.broadcastInt(
677 VECTOR_OP_URSHIFT, Short64Vector.class, short.class, LENGTH,
678 this, s,
679 (v, i) -> v.uOp((__, a) -> (short) ((a & 0xFFFF) >>> (i & 15))));
680 }
681
682 @Override
683 @ForceInline
684 public Short64Vector shiftR(int s, Mask<Short> m) {
685 return blend(shiftR(s), m);
686 }
687
688 @Override
689 @ForceInline
690 public Short64Vector aShiftR(int s) {
691 return VectorIntrinsics.broadcastInt(
692 VECTOR_OP_RSHIFT, Short64Vector.class, short.class, LENGTH,
693 this, s,
694 (v, i) -> v.uOp((__, a) -> (short) (a >> (i & 15))));
695 }
696
697 @Override
698 @ForceInline
699 public Short64Vector aShiftR(int s, Mask<Short> m) {
700 return blend(aShiftR(s), m);
701 }
702 // Ternary operations
703
704
705 // Type specific horizontal reductions
706
707 @Override
708 @ForceInline
709 public short addAll() {
710 return (short) VectorIntrinsics.reductionCoerced(
711 VECTOR_OP_ADD, Short64Vector.class, short.class, LENGTH,
712 this,
713 v -> (long) v.rOp((short) 0, (i, a, b) -> (short) (a + b)));
714 }
715
716 @Override
717 @ForceInline
718 public short andAll() {
719 return (short) VectorIntrinsics.reductionCoerced(
720 VECTOR_OP_AND, Short64Vector.class, short.class, LENGTH,
721 this,
722 v -> (long) v.rOp((short) -1, (i, a, b) -> (short) (a & b)));
723 }
724
725 @Override
726 @ForceInline
727 public short andAll(Mask<Short> m) {
728 return blend((Short64Vector)ShortVector.broadcast(SPECIES, (short) -1), m).andAll();
729 }
730
731 @Override
732 @ForceInline
733 public short minAll() {
734 return (short) VectorIntrinsics.reductionCoerced(
735 VECTOR_OP_MIN, Short64Vector.class, short.class, LENGTH,
736 this,
737 v -> (long) v.rOp(Short.MAX_VALUE , (i, a, b) -> (short) Math.min(a, b)));
738 }
739
740 @Override
741 @ForceInline
742 public short maxAll() {
743 return (short) VectorIntrinsics.reductionCoerced(
744 VECTOR_OP_MAX, Short64Vector.class, short.class, LENGTH,
745 this,
746 v -> (long) v.rOp(Short.MIN_VALUE , (i, a, b) -> (short) Math.max(a, b)));
747 }
749 @Override
750 @ForceInline
751 public short mulAll() {
752 return (short) VectorIntrinsics.reductionCoerced(
753 VECTOR_OP_MUL, Short64Vector.class, short.class, LENGTH,
754 this,
755 v -> (long) v.rOp((short) 1, (i, a, b) -> (short) (a * b)));
756 }
757
758 @Override
759 @ForceInline
760 public short orAll() {
761 return (short) VectorIntrinsics.reductionCoerced(
762 VECTOR_OP_OR, Short64Vector.class, short.class, LENGTH,
763 this,
764 v -> (long) v.rOp((short) 0, (i, a, b) -> (short) (a | b)));
765 }
766
767 @Override
768 @ForceInline
769 public short orAll(Mask<Short> m) {
770 return blend((Short64Vector)ShortVector.broadcast(SPECIES, (short) 0), m).orAll();
771 }
772
773 @Override
774 @ForceInline
775 public short xorAll() {
776 return (short) VectorIntrinsics.reductionCoerced(
777 VECTOR_OP_XOR, Short64Vector.class, short.class, LENGTH,
778 this,
779 v -> (long) v.rOp((short) 0, (i, a, b) -> (short) (a ^ b)));
780 }
781
782 @Override
783 @ForceInline
784 public short xorAll(Mask<Short> m) {
785 return blend((Short64Vector)ShortVector.broadcast(SPECIES, (short) 0), m).xorAll();
786 }
787
788
789 @Override
790 @ForceInline
791 public short addAll(Mask<Short> m) {
792 return blend((Short64Vector)ShortVector.broadcast(SPECIES, (short) 0), m).addAll();
793 }
794
795
796 @Override
797 @ForceInline
798 public short mulAll(Mask<Short> m) {
799 return blend((Short64Vector)ShortVector.broadcast(SPECIES, (short) 1), m).mulAll();
800 }
801
802 @Override
803 @ForceInline
804 public short minAll(Mask<Short> m) {
805 return blend((Short64Vector)ShortVector.broadcast(SPECIES, Short.MAX_VALUE), m).minAll();
806 }
807
808 @Override
809 @ForceInline
810 public short maxAll(Mask<Short> m) {
811 return blend((Short64Vector)ShortVector.broadcast(SPECIES, Short.MIN_VALUE), m).maxAll();
812 }
813
814 @Override
815 @ForceInline
816 public Shuffle<Short> toShuffle() {
817 short[] a = toArray();
818 int[] sa = new int[a.length];
819 for (int i = 0; i < a.length; i++) {
820 sa[i] = (int) a[i];
821 }
822 return ShortVector.shuffleFromArray(SPECIES, sa, 0);
823 }
824
825 // Memory operations
826
827 private static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_SHORT_INDEX_SCALE);
828 private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
829
830 @Override
831 @ForceInline
832 public void intoArray(short[] a, int ix) {
833 Objects.requireNonNull(a);
834 ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
835 VectorIntrinsics.store(Short64Vector.class, short.class, LENGTH,
836 a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_SHORT_BASE_OFFSET,
837 this,
838 a, ix,
839 (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
840 }
841
842 @Override
843 @ForceInline
844 public final void intoArray(short[] a, int ax, Mask<Short> m) {
845 ShortVector oldVal = ShortVector.fromArray(SPECIES, a, ax);
846 ShortVector newVal = oldVal.blend(this, m);
847 newVal.intoArray(a, ax);
848 }
849
850 @Override
851 @ForceInline
852 public void intoByteArray(byte[] a, int ix) {
853 Objects.requireNonNull(a);
854 ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
855 VectorIntrinsics.store(Short64Vector.class, short.class, LENGTH,
856 a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
857 this,
858 a, ix,
859 (c, idx, v) -> {
860 ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
861 ShortBuffer tb = bbc.asShortBuffer();
862 v.forEach((i, e) -> tb.put(e));
863 });
864 }
865
866 @Override
867 @ForceInline
868 public final void intoByteArray(byte[] a, int ix, Mask<Short> m) {
869 Short64Vector oldVal = (Short64Vector) ShortVector.fromByteArray(SPECIES, a, ix);
870 Short64Vector newVal = oldVal.blend(this, m);
871 newVal.intoByteArray(a, ix);
872 }
873
874 @Override
875 @ForceInline
876 public void intoByteBuffer(ByteBuffer bb, int ix) {
877 if (bb.order() != ByteOrder.nativeOrder()) {
878 throw new IllegalArgumentException();
879 }
880 if (bb.isReadOnly()) {
881 throw new ReadOnlyBufferException();
882 }
883 ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
884 VectorIntrinsics.store(Short64Vector.class, short.class, LENGTH,
885 U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
886 this,
887 bb, ix,
888 (c, idx, v) -> {
889 ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
890 ShortBuffer tb = bbc.asShortBuffer();
891 v.forEach((i, e) -> tb.put(e));
892 });
893 }
894
895 @Override
896 @ForceInline
897 public void intoByteBuffer(ByteBuffer bb, int ix, Mask<Short> m) {
898 Short64Vector oldVal = (Short64Vector) ShortVector.fromByteBuffer(SPECIES, bb, ix);
899 Short64Vector newVal = oldVal.blend(this, m);
900 newVal.intoByteBuffer(bb, ix);
901 }
902
903 //
904
905 @Override
906 public String toString() {
907 return Arrays.toString(getElements());
908 }
909
910 @Override
911 public boolean equals(Object o) {
912 if (this == o) return true;
913 if (o == null || this.getClass() != o.getClass()) return false;
914
915 Short64Vector that = (Short64Vector) o;
916 return this.equal(that).allTrue();
917 }
1002 Objects.requireNonNull(o);
1003 Short64Vector v = (Short64Vector)o;
1004
1005 return VectorIntrinsics.compare(
1006 BT_ge, Short64Vector.class, Short64Mask.class, short.class, LENGTH,
1007 this, v,
1008 (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1009 }
1010
1011 // Foreach
1012
1013 @Override
1014 void forEach(FUnCon f) {
1015 short[] vec = getElements();
1016 for (int i = 0; i < length(); i++) {
1017 f.apply(i, vec[i]);
1018 }
1019 }
1020
1021 @Override
1022 void forEach(Mask<Short> o, FUnCon f) {
1023 boolean[] mbits = ((Short64Mask)o).getBits();
1024 forEach((i, a) -> {
1025 if (mbits[i]) { f.apply(i, a); }
1026 });
1027 }
1028
1029
1030
1031 @Override
1032 public Short64Vector rotateEL(int j) {
1033 short[] vec = getElements();
1034 short[] res = new short[length()];
1035 for (int i = 0; i < length(); i++){
1036 res[(j + i) % length()] = vec[i];
1037 }
1038 return new Short64Vector(res);
1039 }
1040
1041 @Override
1042 public Short64Vector rotateER(int j) {
1059 short[] res = new short[length()];
1060 for (int i = 0; i < length() - j; i++) {
1061 res[i] = vec[i + j];
1062 }
1063 return new Short64Vector(res);
1064 }
1065
1066 @Override
1067 public Short64Vector shiftER(int j) {
1068 short[] vec = getElements();
1069 short[] res = new short[length()];
1070 for (int i = 0; i < length() - j; i++){
1071 res[i + j] = vec[i];
1072 }
1073 return new Short64Vector(res);
1074 }
1075
1076 @Override
1077 @ForceInline
1078 public Short64Vector rearrange(Vector<Short> v,
1079 Shuffle<Short> s, Mask<Short> m) {
1080 return this.rearrange(s).blend(v.rearrange(s), m);
1081 }
1082
1083 @Override
1084 @ForceInline
1085 public Short64Vector rearrange(Shuffle<Short> o1) {
1086 Objects.requireNonNull(o1);
1087 Short64Shuffle s = (Short64Shuffle)o1;
1088
1089 return VectorIntrinsics.rearrangeOp(
1090 Short64Vector.class, Short64Shuffle.class, short.class, LENGTH,
1091 this, s,
1092 (v1, s_) -> v1.uOp((i, a) -> {
1093 int ei = s_.getElement(i);
1094 return v1.get(ei);
1095 }));
1096 }
1097
1098 @Override
1099 @ForceInline
1100 public Short64Vector blend(Vector<Short> o1, Mask<Short> o2) {
1101 Objects.requireNonNull(o1);
1102 Objects.requireNonNull(o2);
1103 Short64Vector v = (Short64Vector)o1;
1104 Short64Mask m = (Short64Mask)o2;
1105
1106 return VectorIntrinsics.blend(
1107 Short64Vector.class, Short64Mask.class, short.class, LENGTH,
1108 this, v, m,
1109 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1110 }
1111
1112 // Accessors
1113
1114 @Override
1115 public short get(int i) {
1116 if (i < 0 || i >= LENGTH) {
1117 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1118 }
1119 return (short) VectorIntrinsics.extract(
1120 Short64Vector.class, short.class, LENGTH,
1164 boolean[] bits = new boolean[species().length()];
1165 Arrays.fill(bits, val);
1166 this.bits = bits;
1167 }
1168
1169 boolean[] getBits() {
1170 return VectorIntrinsics.maybeRebox(this).bits;
1171 }
1172
1173 @Override
1174 Short64Mask uOp(MUnOp f) {
1175 boolean[] res = new boolean[species().length()];
1176 boolean[] bits = getBits();
1177 for (int i = 0; i < species().length(); i++) {
1178 res[i] = f.apply(i, bits[i]);
1179 }
1180 return new Short64Mask(res);
1181 }
1182
1183 @Override
1184 Short64Mask bOp(Mask<Short> o, MBinOp f) {
1185 boolean[] res = new boolean[species().length()];
1186 boolean[] bits = getBits();
1187 boolean[] mbits = ((Short64Mask)o).getBits();
1188 for (int i = 0; i < species().length(); i++) {
1189 res[i] = f.apply(i, bits[i], mbits[i]);
1190 }
1191 return new Short64Mask(res);
1192 }
1193
1194 @Override
1195 public Species<Short> species() {
1196 return SPECIES;
1197 }
1198
1199 @Override
1200 public Short64Vector toVector() {
1201 short[] res = new short[species().length()];
1202 boolean[] bits = getBits();
1203 for (int i = 0; i < species().length(); i++) {
1204 // -1 will result in the most significant bit being set in
1205 // addition to some or all other bits
1206 res[i] = (short) (bits[i] ? -1 : 0);
1207 }
1208 return new Short64Vector(res);
1209 }
1210
1211 @Override
1212 @ForceInline
1213 @SuppressWarnings("unchecked")
1214 public <E> Mask<E> cast(Species<E> species) {
1215 if (length() != species.length())
1216 throw new IllegalArgumentException("Mask length and species length differ");
1217 Class<?> stype = species.elementType();
1218 boolean [] maskArray = toArray();
1219 if (stype == byte.class) {
1220 return (Mask <E>) new Byte64Vector.Byte64Mask(maskArray);
1221 } else if (stype == short.class) {
1222 return (Mask <E>) new Short64Vector.Short64Mask(maskArray);
1223 } else if (stype == int.class) {
1224 return (Mask <E>) new Int64Vector.Int64Mask(maskArray);
1225 } else if (stype == long.class) {
1226 return (Mask <E>) new Long64Vector.Long64Mask(maskArray);
1227 } else if (stype == float.class) {
1228 return (Mask <E>) new Float64Vector.Float64Mask(maskArray);
1229 } else if (stype == double.class) {
1230 return (Mask <E>) new Double64Vector.Double64Mask(maskArray);
1231 } else {
1232 throw new UnsupportedOperationException("Bad lane type for casting.");
1233 }
1234 }
1235
1236 // Unary operations
1237
1238 @Override
1239 @ForceInline
1240 public Short64Mask not() {
1241 return (Short64Mask) VectorIntrinsics.unaryOp(
1242 VECTOR_OP_NOT, Short64Mask.class, short.class, LENGTH,
1243 this,
1244 (m1) -> m1.uOp((i, a) -> !a));
1245 }
1246
1247 // Binary operations
1248
1249 @Override
1250 @ForceInline
1251 public Short64Mask and(Mask<Short> o) {
1252 Objects.requireNonNull(o);
1253 Short64Mask m = (Short64Mask)o;
1254 return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Short64Mask.class, short.class, LENGTH,
1255 this, m,
1256 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1257 }
1258
1259 @Override
1260 @ForceInline
1261 public Short64Mask or(Mask<Short> o) {
1262 Objects.requireNonNull(o);
1263 Short64Mask m = (Short64Mask)o;
1264 return VectorIntrinsics.binaryOp(VECTOR_OP_OR, Short64Mask.class, short.class, LENGTH,
1265 this, m,
1266 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1267 }
1268
1269 // Reductions
1270
1271 @Override
1272 @ForceInline
1273 public boolean anyTrue() {
1274 return VectorIntrinsics.test(BT_ne, Short64Mask.class, short.class, LENGTH,
1275 this, this,
1276 (m, __) -> anyTrueHelper(((Short64Mask)m).getBits()));
1277 }
1278
1279 @Override
1280 @ForceInline
1281 public boolean allTrue() {
1282 return VectorIntrinsics.test(BT_overflow, Short64Mask.class, short.class, LENGTH,
1283 this, ShortVector.maskAllTrue(species()),
1284 (m, __) -> allTrueHelper(((Short64Mask)m).getBits()));
1285 }
1286 }
1287
1288 // Shuffle
1289
1290 static final class Short64Shuffle extends AbstractShuffle<Short> {
1291 Short64Shuffle(byte[] reorder) {
1292 super(reorder);
1293 }
1294
1295 public Short64Shuffle(int[] reorder) {
1296 super(reorder);
1297 }
1298
1299 public Short64Shuffle(int[] reorder, int i) {
1300 super(reorder, i);
1301 }
1302
1303 public Short64Shuffle(IntUnaryOperator f) {
1304 super(f);
1305 }
1306
1307 @Override
1308 public Species<Short> species() {
1309 return SPECIES;
1310 }
1311
1312 @Override
1313 public ShortVector toVector() {
1314 short[] va = new short[SPECIES.length()];
1315 for (int i = 0; i < va.length; i++) {
1316 va[i] = (short) getElement(i);
1317 }
1318 return ShortVector.fromArray(SPECIES, va, 0);
1319 }
1320
1321 @Override
1322 @ForceInline
1323 @SuppressWarnings("unchecked")
1324 public <F> Shuffle<F> cast(Species<F> species) {
1325 if (length() != species.length())
1326 throw new IllegalArgumentException("Shuffle length and species length differ");
1327 Class<?> stype = species.elementType();
1328 int [] shuffleArray = toArray();
1329 if (stype == byte.class) {
1330 return (Shuffle<F>) new Byte64Vector.Byte64Shuffle(shuffleArray);
1331 } else if (stype == short.class) {
1332 return (Shuffle<F>) new Short64Vector.Short64Shuffle(shuffleArray);
1333 } else if (stype == int.class) {
1334 return (Shuffle<F>) new Int64Vector.Int64Shuffle(shuffleArray);
1335 } else if (stype == long.class) {
1336 return (Shuffle<F>) new Long64Vector.Long64Shuffle(shuffleArray);
1337 } else if (stype == float.class) {
1338 return (Shuffle<F>) new Float64Vector.Float64Shuffle(shuffleArray);
1339 } else if (stype == double.class) {
1340 return (Shuffle<F>) new Double64Vector.Double64Shuffle(shuffleArray);
1341 } else {
1342 throw new UnsupportedOperationException("Bad lane type for casting.");
1343 }
1344 }
1345
1346 @Override
1347 public Short64Shuffle rearrange(Vector.Shuffle<Short> o) {
1348 Short64Shuffle s = (Short64Shuffle) o;
1349 byte[] r = new byte[reorder.length];
1350 for (int i = 0; i < reorder.length; i++) {
1351 r[i] = reorder[s.reorder[i]];
1352 }
1353 return new Short64Shuffle(r);
1354 }
1355 }
1356
1357 // Species
1358
1359 @Override
1360 public Species<Short> species() {
1361 return SPECIES;
1362 }
1363 }
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have
23 * questions.
24 */
25 package jdk.incubator.vector;
26
27 import java.nio.ByteBuffer;
28 import java.nio.ByteOrder;
29 import java.nio.ShortBuffer;
30 import java.nio.ReadOnlyBufferException;
31 import java.util.Arrays;
32 import java.util.Objects;
33 import java.util.function.IntUnaryOperator;
34
35 import jdk.internal.misc.Unsafe;
36 import jdk.internal.vm.annotation.ForceInline;
37 import static jdk.incubator.vector.VectorIntrinsics.*;
38
39 @SuppressWarnings("cast")
40 final class Short64Vector extends ShortVector {
41 private static final VectorSpecies<Short> SPECIES = ShortVector.SPECIES_64;
42
43 static final Short64Vector ZERO = new Short64Vector();
44
45 static final int LENGTH = SPECIES.length();
46
47 private final short[] vec; // Don't access directly, use getElements() instead.
48
49 private short[] getElements() {
50 return VectorIntrinsics.maybeRebox(this).vec;
51 }
52
53 Short64Vector() {
54 vec = new short[SPECIES.length()];
55 }
56
57 Short64Vector(short[] v) {
58 vec = v;
59 }
60
61 @Override
62 public int length() { return LENGTH; }
63
64 // Unary operator
65
66 @Override
67 Short64Vector uOp(FUnOp f) {
68 short[] vec = getElements();
69 short[] res = new short[length()];
70 for (int i = 0; i < length(); i++) {
71 res[i] = f.apply(i, vec[i]);
72 }
73 return new Short64Vector(res);
74 }
75
76 @Override
77 Short64Vector uOp(VectorMask<Short> o, FUnOp f) {
78 short[] vec = getElements();
79 short[] res = new short[length()];
80 boolean[] mbits = ((Short64Mask)o).getBits();
81 for (int i = 0; i < length(); i++) {
82 res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
83 }
84 return new Short64Vector(res);
85 }
86
87 // Binary operator
88
89 @Override
90 Short64Vector bOp(Vector<Short> o, FBinOp f) {
91 short[] res = new short[length()];
92 short[] vec1 = this.getElements();
93 short[] vec2 = ((Short64Vector)o).getElements();
94 for (int i = 0; i < length(); i++) {
95 res[i] = f.apply(i, vec1[i], vec2[i]);
96 }
97 return new Short64Vector(res);
98 }
99
100 @Override
101 Short64Vector bOp(Vector<Short> o1, VectorMask<Short> o2, FBinOp f) {
102 short[] res = new short[length()];
103 short[] vec1 = this.getElements();
104 short[] vec2 = ((Short64Vector)o1).getElements();
105 boolean[] mbits = ((Short64Mask)o2).getBits();
106 for (int i = 0; i < length(); i++) {
107 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
108 }
109 return new Short64Vector(res);
110 }
111
112 // Trinary operator
113
114 @Override
115 Short64Vector tOp(Vector<Short> o1, Vector<Short> o2, FTriOp f) {
116 short[] res = new short[length()];
117 short[] vec1 = this.getElements();
118 short[] vec2 = ((Short64Vector)o1).getElements();
119 short[] vec3 = ((Short64Vector)o2).getElements();
120 for (int i = 0; i < length(); i++) {
121 res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
122 }
123 return new Short64Vector(res);
124 }
125
126 @Override
127 Short64Vector tOp(Vector<Short> o1, Vector<Short> o2, VectorMask<Short> o3, FTriOp f) {
128 short[] res = new short[length()];
129 short[] vec1 = getElements();
130 short[] vec2 = ((Short64Vector)o1).getElements();
131 short[] vec3 = ((Short64Vector)o2).getElements();
132 boolean[] mbits = ((Short64Mask)o3).getBits();
133 for (int i = 0; i < length(); i++) {
134 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
135 }
136 return new Short64Vector(res);
137 }
138
139 @Override
140 short rOp(short v, FBinOp f) {
141 short[] vec = getElements();
142 for (int i = 0; i < length(); i++) {
143 v = f.apply(i, v, vec[i]);
144 }
145 return v;
146 }
147
148 @Override
149 @ForceInline
150 public <F> Vector<F> cast(VectorSpecies<F> s) {
151 Objects.requireNonNull(s);
152 if (s.length() != LENGTH)
153 throw new IllegalArgumentException("Vector length this species length differ");
154
155 return VectorIntrinsics.cast(
156 Short64Vector.class,
157 short.class, LENGTH,
158 s.boxType(),
159 s.elementType(), LENGTH,
160 this, s,
161 (species, vector) -> vector.castDefault(species)
162 );
163 }
164
165 @SuppressWarnings("unchecked")
166 @ForceInline
167 private <F> Vector<F> castDefault(VectorSpecies<F> s) {
168 int limit = s.length();
169
170 Class<?> stype = s.elementType();
171 if (stype == byte.class) {
172 byte[] a = new byte[limit];
173 for (int i = 0; i < limit; i++) {
174 a[i] = (byte) this.get(i);
175 }
176 return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
177 } else if (stype == short.class) {
178 short[] a = new short[limit];
179 for (int i = 0; i < limit; i++) {
180 a[i] = (short) this.get(i);
181 }
182 return (Vector) ShortVector.fromArray((VectorSpecies<Short>) s, a, 0);
183 } else if (stype == int.class) {
184 int[] a = new int[limit];
185 for (int i = 0; i < limit; i++) {
186 a[i] = (int) this.get(i);
187 }
188 return (Vector) IntVector.fromArray((VectorSpecies<Integer>) s, a, 0);
189 } else if (stype == long.class) {
190 long[] a = new long[limit];
191 for (int i = 0; i < limit; i++) {
192 a[i] = (long) this.get(i);
193 }
194 return (Vector) LongVector.fromArray((VectorSpecies<Long>) s, a, 0);
195 } else if (stype == float.class) {
196 float[] a = new float[limit];
197 for (int i = 0; i < limit; i++) {
198 a[i] = (float) this.get(i);
199 }
200 return (Vector) FloatVector.fromArray((VectorSpecies<Float>) s, a, 0);
201 } else if (stype == double.class) {
202 double[] a = new double[limit];
203 for (int i = 0; i < limit; i++) {
204 a[i] = (double) this.get(i);
205 }
206 return (Vector) DoubleVector.fromArray((VectorSpecies<Double>) s, a, 0);
207 } else {
208 throw new UnsupportedOperationException("Bad lane type for casting.");
209 }
210 }
211
212 @Override
213 @ForceInline
214 @SuppressWarnings("unchecked")
215 public <F> Vector<F> reinterpret(VectorSpecies<F> s) {
216 Objects.requireNonNull(s);
217
218 if(s.elementType().equals(short.class)) {
219 return (Vector<F>) reshape((VectorSpecies<Short>)s);
220 }
221 if(s.bitSize() == bitSize()) {
222 return reinterpretType(s);
223 }
224
225 return defaultReinterpret(s);
226 }
227
228 @ForceInline
229 private <F> Vector<F> reinterpretType(VectorSpecies<F> s) {
230 Objects.requireNonNull(s);
231
232 Class<?> stype = s.elementType();
233 if (stype == byte.class) {
234 return VectorIntrinsics.reinterpret(
235 Short64Vector.class,
236 short.class, LENGTH,
237 Byte64Vector.class,
238 byte.class, Byte64Vector.LENGTH,
239 this, s,
240 (species, vector) -> vector.defaultReinterpret(species)
241 );
242 } else if (stype == short.class) {
243 return VectorIntrinsics.reinterpret(
244 Short64Vector.class,
245 short.class, LENGTH,
246 Short64Vector.class,
247 short.class, Short64Vector.LENGTH,
248 this, s,
249 (species, vector) -> vector.defaultReinterpret(species)
274 float.class, Float64Vector.LENGTH,
275 this, s,
276 (species, vector) -> vector.defaultReinterpret(species)
277 );
278 } else if (stype == double.class) {
279 return VectorIntrinsics.reinterpret(
280 Short64Vector.class,
281 short.class, LENGTH,
282 Double64Vector.class,
283 double.class, Double64Vector.LENGTH,
284 this, s,
285 (species, vector) -> vector.defaultReinterpret(species)
286 );
287 } else {
288 throw new UnsupportedOperationException("Bad lane type for casting.");
289 }
290 }
291
292 @Override
293 @ForceInline
294 public ShortVector reshape(VectorSpecies<Short> s) {
295 Objects.requireNonNull(s);
296 if (s.bitSize() == 64 && (s.boxType() == Short64Vector.class)) {
297 return VectorIntrinsics.reinterpret(
298 Short64Vector.class,
299 short.class, LENGTH,
300 Short64Vector.class,
301 short.class, Short64Vector.LENGTH,
302 this, s,
303 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
304 );
305 } else if (s.bitSize() == 128 && (s.boxType() == Short128Vector.class)) {
306 return VectorIntrinsics.reinterpret(
307 Short64Vector.class,
308 short.class, LENGTH,
309 Short128Vector.class,
310 short.class, Short128Vector.LENGTH,
311 this, s,
312 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
313 );
314 } else if (s.bitSize() == 256 && (s.boxType() == Short256Vector.class)) {
337 ShortMaxVector.class,
338 short.class, ShortMaxVector.LENGTH,
339 this, s,
340 (species, vector) -> (ShortVector) vector.defaultReinterpret(species)
341 );
342 } else {
343 throw new InternalError("Unimplemented size");
344 }
345 }
346
347 // Binary operations with scalars
348
349 @Override
350 @ForceInline
351 public ShortVector add(short o) {
352 return add((Short64Vector)ShortVector.broadcast(SPECIES, o));
353 }
354
355 @Override
356 @ForceInline
357 public ShortVector add(short o, VectorMask<Short> m) {
358 return add((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
359 }
360
361 @Override
362 @ForceInline
363 public ShortVector sub(short o) {
364 return sub((Short64Vector)ShortVector.broadcast(SPECIES, o));
365 }
366
367 @Override
368 @ForceInline
369 public ShortVector sub(short o, VectorMask<Short> m) {
370 return sub((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
371 }
372
373 @Override
374 @ForceInline
375 public ShortVector mul(short o) {
376 return mul((Short64Vector)ShortVector.broadcast(SPECIES, o));
377 }
378
379 @Override
380 @ForceInline
381 public ShortVector mul(short o, VectorMask<Short> m) {
382 return mul((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
383 }
384
385 @Override
386 @ForceInline
387 public ShortVector min(short o) {
388 return min((Short64Vector)ShortVector.broadcast(SPECIES, o));
389 }
390
391 @Override
392 @ForceInline
393 public ShortVector max(short o) {
394 return max((Short64Vector)ShortVector.broadcast(SPECIES, o));
395 }
396
397 @Override
398 @ForceInline
399 public VectorMask<Short> equal(short o) {
400 return equal((Short64Vector)ShortVector.broadcast(SPECIES, o));
401 }
402
403 @Override
404 @ForceInline
405 public VectorMask<Short> notEqual(short o) {
406 return notEqual((Short64Vector)ShortVector.broadcast(SPECIES, o));
407 }
408
409 @Override
410 @ForceInline
411 public VectorMask<Short> lessThan(short o) {
412 return lessThan((Short64Vector)ShortVector.broadcast(SPECIES, o));
413 }
414
415 @Override
416 @ForceInline
417 public VectorMask<Short> lessThanEq(short o) {
418 return lessThanEq((Short64Vector)ShortVector.broadcast(SPECIES, o));
419 }
420
421 @Override
422 @ForceInline
423 public VectorMask<Short> greaterThan(short o) {
424 return greaterThan((Short64Vector)ShortVector.broadcast(SPECIES, o));
425 }
426
427 @Override
428 @ForceInline
429 public VectorMask<Short> greaterThanEq(short o) {
430 return greaterThanEq((Short64Vector)ShortVector.broadcast(SPECIES, o));
431 }
432
433 @Override
434 @ForceInline
435 public ShortVector blend(short o, VectorMask<Short> m) {
436 return blend((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
437 }
438
439
440 @Override
441 @ForceInline
442 public ShortVector and(short o) {
443 return and((Short64Vector)ShortVector.broadcast(SPECIES, o));
444 }
445
446 @Override
447 @ForceInline
448 public ShortVector and(short o, VectorMask<Short> m) {
449 return and((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
450 }
451
452 @Override
453 @ForceInline
454 public ShortVector or(short o) {
455 return or((Short64Vector)ShortVector.broadcast(SPECIES, o));
456 }
457
458 @Override
459 @ForceInline
460 public ShortVector or(short o, VectorMask<Short> m) {
461 return or((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
462 }
463
464 @Override
465 @ForceInline
466 public ShortVector xor(short o) {
467 return xor((Short64Vector)ShortVector.broadcast(SPECIES, o));
468 }
469
470 @Override
471 @ForceInline
472 public ShortVector xor(short o, VectorMask<Short> m) {
473 return xor((Short64Vector)ShortVector.broadcast(SPECIES, o), m);
474 }
475
476 @Override
477 @ForceInline
478 public Short64Vector neg() {
479 return (Short64Vector)zero(SPECIES).sub(this);
480 }
481
482 // Unary operations
483
484 @ForceInline
485 @Override
486 public Short64Vector neg(VectorMask<Short> m) {
487 return blend(neg(), m);
488 }
489
490 @Override
491 @ForceInline
492 public Short64Vector abs() {
493 return VectorIntrinsics.unaryOp(
494 VECTOR_OP_ABS, Short64Vector.class, short.class, LENGTH,
495 this,
496 v1 -> v1.uOp((i, a) -> (short) Math.abs(a)));
497 }
498
499 @ForceInline
500 @Override
501 public Short64Vector abs(VectorMask<Short> m) {
502 return blend(abs(), m);
503 }
504
505
506 @Override
507 @ForceInline
508 public Short64Vector not() {
509 return VectorIntrinsics.unaryOp(
510 VECTOR_OP_NOT, Short64Vector.class, short.class, LENGTH,
511 this,
512 v1 -> v1.uOp((i, a) -> (short) ~a));
513 }
514
515 @ForceInline
516 @Override
517 public Short64Vector not(VectorMask<Short> m) {
518 return blend(not(), m);
519 }
520 // Binary operations
521
522 @Override
523 @ForceInline
524 public Short64Vector add(Vector<Short> o) {
525 Objects.requireNonNull(o);
526 Short64Vector v = (Short64Vector)o;
527 return VectorIntrinsics.binaryOp(
528 VECTOR_OP_ADD, Short64Vector.class, short.class, LENGTH,
529 this, v,
530 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a + b)));
531 }
532
533 @Override
534 @ForceInline
535 public Short64Vector add(Vector<Short> v, VectorMask<Short> m) {
536 return blend(add(v), m);
537 }
538
539 @Override
540 @ForceInline
541 public Short64Vector sub(Vector<Short> o) {
542 Objects.requireNonNull(o);
543 Short64Vector v = (Short64Vector)o;
544 return VectorIntrinsics.binaryOp(
545 VECTOR_OP_SUB, Short64Vector.class, short.class, LENGTH,
546 this, v,
547 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a - b)));
548 }
549
550 @Override
551 @ForceInline
552 public Short64Vector sub(Vector<Short> v, VectorMask<Short> m) {
553 return blend(sub(v), m);
554 }
555
556 @Override
557 @ForceInline
558 public Short64Vector mul(Vector<Short> o) {
559 Objects.requireNonNull(o);
560 Short64Vector v = (Short64Vector)o;
561 return VectorIntrinsics.binaryOp(
562 VECTOR_OP_MUL, Short64Vector.class, short.class, LENGTH,
563 this, v,
564 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a * b)));
565 }
566
567 @Override
568 @ForceInline
569 public Short64Vector mul(Vector<Short> v, VectorMask<Short> m) {
570 return blend(mul(v), m);
571 }
572
573 @Override
574 @ForceInline
575 public Short64Vector min(Vector<Short> o) {
576 Objects.requireNonNull(o);
577 Short64Vector v = (Short64Vector)o;
578 return (Short64Vector) VectorIntrinsics.binaryOp(
579 VECTOR_OP_MIN, Short64Vector.class, short.class, LENGTH,
580 this, v,
581 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short) Math.min(a, b)));
582 }
583
584 @Override
585 @ForceInline
586 public Short64Vector min(Vector<Short> v, VectorMask<Short> m) {
587 return blend(min(v), m);
588 }
589
590 @Override
591 @ForceInline
592 public Short64Vector max(Vector<Short> o) {
593 Objects.requireNonNull(o);
594 Short64Vector v = (Short64Vector)o;
595 return VectorIntrinsics.binaryOp(
596 VECTOR_OP_MAX, Short64Vector.class, short.class, LENGTH,
597 this, v,
598 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short) Math.max(a, b)));
599 }
600
601 @Override
602 @ForceInline
603 public Short64Vector max(Vector<Short> v, VectorMask<Short> m) {
604 return blend(max(v), m);
605 }
606
607 @Override
608 @ForceInline
609 public Short64Vector and(Vector<Short> o) {
610 Objects.requireNonNull(o);
611 Short64Vector v = (Short64Vector)o;
612 return VectorIntrinsics.binaryOp(
613 VECTOR_OP_AND, Short64Vector.class, short.class, LENGTH,
614 this, v,
615 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a & b)));
616 }
617
618 @Override
619 @ForceInline
620 public Short64Vector or(Vector<Short> o) {
621 Objects.requireNonNull(o);
622 Short64Vector v = (Short64Vector)o;
623 return VectorIntrinsics.binaryOp(
624 VECTOR_OP_OR, Short64Vector.class, short.class, LENGTH,
625 this, v,
626 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a | b)));
627 }
628
629 @Override
630 @ForceInline
631 public Short64Vector xor(Vector<Short> o) {
632 Objects.requireNonNull(o);
633 Short64Vector v = (Short64Vector)o;
634 return VectorIntrinsics.binaryOp(
635 VECTOR_OP_XOR, Short64Vector.class, short.class, LENGTH,
636 this, v,
637 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (short)(a ^ b)));
638 }
639
640 @Override
641 @ForceInline
642 public Short64Vector and(Vector<Short> v, VectorMask<Short> m) {
643 return blend(and(v), m);
644 }
645
646 @Override
647 @ForceInline
648 public Short64Vector or(Vector<Short> v, VectorMask<Short> m) {
649 return blend(or(v), m);
650 }
651
652 @Override
653 @ForceInline
654 public Short64Vector xor(Vector<Short> v, VectorMask<Short> m) {
655 return blend(xor(v), m);
656 }
657
658 @Override
659 @ForceInline
660 public Short64Vector shiftL(int s) {
661 return VectorIntrinsics.broadcastInt(
662 VECTOR_OP_LSHIFT, Short64Vector.class, short.class, LENGTH,
663 this, s,
664 (v, i) -> v.uOp((__, a) -> (short) (a << (i & 15))));
665 }
666
667 @Override
668 @ForceInline
669 public Short64Vector shiftL(int s, VectorMask<Short> m) {
670 return blend(shiftL(s), m);
671 }
672
673 @Override
674 @ForceInline
675 public Short64Vector shiftR(int s) {
676 return VectorIntrinsics.broadcastInt(
677 VECTOR_OP_URSHIFT, Short64Vector.class, short.class, LENGTH,
678 this, s,
679 (v, i) -> v.uOp((__, a) -> (short) ((a & 0xFFFF) >>> (i & 15))));
680 }
681
682 @Override
683 @ForceInline
684 public Short64Vector shiftR(int s, VectorMask<Short> m) {
685 return blend(shiftR(s), m);
686 }
687
688 @Override
689 @ForceInline
690 public Short64Vector aShiftR(int s) {
691 return VectorIntrinsics.broadcastInt(
692 VECTOR_OP_RSHIFT, Short64Vector.class, short.class, LENGTH,
693 this, s,
694 (v, i) -> v.uOp((__, a) -> (short) (a >> (i & 15))));
695 }
696
697 @Override
698 @ForceInline
699 public Short64Vector aShiftR(int s, VectorMask<Short> m) {
700 return blend(aShiftR(s), m);
701 }
702 // Ternary operations
703
704
705 // Type specific horizontal reductions
706
707 @Override
708 @ForceInline
709 public short addAll() {
710 return (short) VectorIntrinsics.reductionCoerced(
711 VECTOR_OP_ADD, Short64Vector.class, short.class, LENGTH,
712 this,
713 v -> (long) v.rOp((short) 0, (i, a, b) -> (short) (a + b)));
714 }
715
716 @Override
717 @ForceInline
718 public short andAll() {
719 return (short) VectorIntrinsics.reductionCoerced(
720 VECTOR_OP_AND, Short64Vector.class, short.class, LENGTH,
721 this,
722 v -> (long) v.rOp((short) -1, (i, a, b) -> (short) (a & b)));
723 }
724
725 @Override
726 @ForceInline
727 public short andAll(VectorMask<Short> m) {
728 return blend((Short64Vector)ShortVector.broadcast(SPECIES, (short) -1), m).andAll();
729 }
730
731 @Override
732 @ForceInline
733 public short minAll() {
734 return (short) VectorIntrinsics.reductionCoerced(
735 VECTOR_OP_MIN, Short64Vector.class, short.class, LENGTH,
736 this,
737 v -> (long) v.rOp(Short.MAX_VALUE , (i, a, b) -> (short) Math.min(a, b)));
738 }
739
740 @Override
741 @ForceInline
742 public short maxAll() {
743 return (short) VectorIntrinsics.reductionCoerced(
744 VECTOR_OP_MAX, Short64Vector.class, short.class, LENGTH,
745 this,
746 v -> (long) v.rOp(Short.MIN_VALUE , (i, a, b) -> (short) Math.max(a, b)));
747 }
749 @Override
750 @ForceInline
751 public short mulAll() {
752 return (short) VectorIntrinsics.reductionCoerced(
753 VECTOR_OP_MUL, Short64Vector.class, short.class, LENGTH,
754 this,
755 v -> (long) v.rOp((short) 1, (i, a, b) -> (short) (a * b)));
756 }
757
758 @Override
759 @ForceInline
760 public short orAll() {
761 return (short) VectorIntrinsics.reductionCoerced(
762 VECTOR_OP_OR, Short64Vector.class, short.class, LENGTH,
763 this,
764 v -> (long) v.rOp((short) 0, (i, a, b) -> (short) (a | b)));
765 }
766
767 @Override
768 @ForceInline
769 public short orAll(VectorMask<Short> m) {
770 return blend((Short64Vector)ShortVector.broadcast(SPECIES, (short) 0), m).orAll();
771 }
772
773 @Override
774 @ForceInline
775 public short xorAll() {
776 return (short) VectorIntrinsics.reductionCoerced(
777 VECTOR_OP_XOR, Short64Vector.class, short.class, LENGTH,
778 this,
779 v -> (long) v.rOp((short) 0, (i, a, b) -> (short) (a ^ b)));
780 }
781
782 @Override
783 @ForceInline
784 public short xorAll(VectorMask<Short> m) {
785 return blend((Short64Vector)ShortVector.broadcast(SPECIES, (short) 0), m).xorAll();
786 }
787
788
789 @Override
790 @ForceInline
791 public short addAll(VectorMask<Short> m) {
792 return blend((Short64Vector)ShortVector.broadcast(SPECIES, (short) 0), m).addAll();
793 }
794
795
796 @Override
797 @ForceInline
798 public short mulAll(VectorMask<Short> m) {
799 return blend((Short64Vector)ShortVector.broadcast(SPECIES, (short) 1), m).mulAll();
800 }
801
802 @Override
803 @ForceInline
804 public short minAll(VectorMask<Short> m) {
805 return blend((Short64Vector)ShortVector.broadcast(SPECIES, Short.MAX_VALUE), m).minAll();
806 }
807
808 @Override
809 @ForceInline
810 public short maxAll(VectorMask<Short> m) {
811 return blend((Short64Vector)ShortVector.broadcast(SPECIES, Short.MIN_VALUE), m).maxAll();
812 }
813
814 @Override
815 @ForceInline
816 public VectorShuffle<Short> toShuffle() {
817 short[] a = toArray();
818 int[] sa = new int[a.length];
819 for (int i = 0; i < a.length; i++) {
820 sa[i] = (int) a[i];
821 }
822 return VectorShuffle.fromArray(SPECIES, sa, 0);
823 }
824
825 // Memory operations
826
827 private static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_SHORT_INDEX_SCALE);
828 private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
829
830 @Override
831 @ForceInline
832 public void intoArray(short[] a, int ix) {
833 Objects.requireNonNull(a);
834 ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
835 VectorIntrinsics.store(Short64Vector.class, short.class, LENGTH,
836 a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_SHORT_BASE_OFFSET,
837 this,
838 a, ix,
839 (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
840 }
841
842 @Override
843 @ForceInline
844 public final void intoArray(short[] a, int ax, VectorMask<Short> m) {
845 ShortVector oldVal = ShortVector.fromArray(SPECIES, a, ax);
846 ShortVector newVal = oldVal.blend(this, m);
847 newVal.intoArray(a, ax);
848 }
849
850 @Override
851 @ForceInline
852 public void intoByteArray(byte[] a, int ix) {
853 Objects.requireNonNull(a);
854 ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
855 VectorIntrinsics.store(Short64Vector.class, short.class, LENGTH,
856 a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
857 this,
858 a, ix,
859 (c, idx, v) -> {
860 ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
861 ShortBuffer tb = bbc.asShortBuffer();
862 v.forEach((i, e) -> tb.put(e));
863 });
864 }
865
866 @Override
867 @ForceInline
868 public final void intoByteArray(byte[] a, int ix, VectorMask<Short> m) {
869 Short64Vector oldVal = (Short64Vector) ShortVector.fromByteArray(SPECIES, a, ix);
870 Short64Vector newVal = oldVal.blend(this, m);
871 newVal.intoByteArray(a, ix);
872 }
873
874 @Override
875 @ForceInline
876 public void intoByteBuffer(ByteBuffer bb, int ix) {
877 if (bb.order() != ByteOrder.nativeOrder()) {
878 throw new IllegalArgumentException();
879 }
880 if (bb.isReadOnly()) {
881 throw new ReadOnlyBufferException();
882 }
883 ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
884 VectorIntrinsics.store(Short64Vector.class, short.class, LENGTH,
885 U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
886 this,
887 bb, ix,
888 (c, idx, v) -> {
889 ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
890 ShortBuffer tb = bbc.asShortBuffer();
891 v.forEach((i, e) -> tb.put(e));
892 });
893 }
894
895 @Override
896 @ForceInline
897 public void intoByteBuffer(ByteBuffer bb, int ix, VectorMask<Short> m) {
898 Short64Vector oldVal = (Short64Vector) ShortVector.fromByteBuffer(SPECIES, bb, ix);
899 Short64Vector newVal = oldVal.blend(this, m);
900 newVal.intoByteBuffer(bb, ix);
901 }
902
903 //
904
905 @Override
906 public String toString() {
907 return Arrays.toString(getElements());
908 }
909
910 @Override
911 public boolean equals(Object o) {
912 if (this == o) return true;
913 if (o == null || this.getClass() != o.getClass()) return false;
914
915 Short64Vector that = (Short64Vector) o;
916 return this.equal(that).allTrue();
917 }
1002 Objects.requireNonNull(o);
1003 Short64Vector v = (Short64Vector)o;
1004
1005 return VectorIntrinsics.compare(
1006 BT_ge, Short64Vector.class, Short64Mask.class, short.class, LENGTH,
1007 this, v,
1008 (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1009 }
1010
1011 // Foreach
1012
1013 @Override
1014 void forEach(FUnCon f) {
1015 short[] vec = getElements();
1016 for (int i = 0; i < length(); i++) {
1017 f.apply(i, vec[i]);
1018 }
1019 }
1020
1021 @Override
1022 void forEach(VectorMask<Short> o, FUnCon f) {
1023 boolean[] mbits = ((Short64Mask)o).getBits();
1024 forEach((i, a) -> {
1025 if (mbits[i]) { f.apply(i, a); }
1026 });
1027 }
1028
1029
1030
1031 @Override
1032 public Short64Vector rotateEL(int j) {
1033 short[] vec = getElements();
1034 short[] res = new short[length()];
1035 for (int i = 0; i < length(); i++){
1036 res[(j + i) % length()] = vec[i];
1037 }
1038 return new Short64Vector(res);
1039 }
1040
1041 @Override
1042 public Short64Vector rotateER(int j) {
1059 short[] res = new short[length()];
1060 for (int i = 0; i < length() - j; i++) {
1061 res[i] = vec[i + j];
1062 }
1063 return new Short64Vector(res);
1064 }
1065
1066 @Override
1067 public Short64Vector shiftER(int j) {
1068 short[] vec = getElements();
1069 short[] res = new short[length()];
1070 for (int i = 0; i < length() - j; i++){
1071 res[i + j] = vec[i];
1072 }
1073 return new Short64Vector(res);
1074 }
1075
1076 @Override
1077 @ForceInline
1078 public Short64Vector rearrange(Vector<Short> v,
1079 VectorShuffle<Short> s, VectorMask<Short> m) {
1080 return this.rearrange(s).blend(v.rearrange(s), m);
1081 }
1082
1083 @Override
1084 @ForceInline
1085 public Short64Vector rearrange(VectorShuffle<Short> o1) {
1086 Objects.requireNonNull(o1);
1087 Short64Shuffle s = (Short64Shuffle)o1;
1088
1089 return VectorIntrinsics.rearrangeOp(
1090 Short64Vector.class, Short64Shuffle.class, short.class, LENGTH,
1091 this, s,
1092 (v1, s_) -> v1.uOp((i, a) -> {
1093 int ei = s_.getElement(i);
1094 return v1.get(ei);
1095 }));
1096 }
1097
1098 @Override
1099 @ForceInline
1100 public Short64Vector blend(Vector<Short> o1, VectorMask<Short> o2) {
1101 Objects.requireNonNull(o1);
1102 Objects.requireNonNull(o2);
1103 Short64Vector v = (Short64Vector)o1;
1104 Short64Mask m = (Short64Mask)o2;
1105
1106 return VectorIntrinsics.blend(
1107 Short64Vector.class, Short64Mask.class, short.class, LENGTH,
1108 this, v, m,
1109 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1110 }
1111
1112 // Accessors
1113
1114 @Override
1115 public short get(int i) {
1116 if (i < 0 || i >= LENGTH) {
1117 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1118 }
1119 return (short) VectorIntrinsics.extract(
1120 Short64Vector.class, short.class, LENGTH,
1164 boolean[] bits = new boolean[species().length()];
1165 Arrays.fill(bits, val);
1166 this.bits = bits;
1167 }
1168
1169 boolean[] getBits() {
1170 return VectorIntrinsics.maybeRebox(this).bits;
1171 }
1172
1173 @Override
1174 Short64Mask uOp(MUnOp f) {
1175 boolean[] res = new boolean[species().length()];
1176 boolean[] bits = getBits();
1177 for (int i = 0; i < species().length(); i++) {
1178 res[i] = f.apply(i, bits[i]);
1179 }
1180 return new Short64Mask(res);
1181 }
1182
1183 @Override
1184 Short64Mask bOp(VectorMask<Short> o, MBinOp f) {
1185 boolean[] res = new boolean[species().length()];
1186 boolean[] bits = getBits();
1187 boolean[] mbits = ((Short64Mask)o).getBits();
1188 for (int i = 0; i < species().length(); i++) {
1189 res[i] = f.apply(i, bits[i], mbits[i]);
1190 }
1191 return new Short64Mask(res);
1192 }
1193
1194 @Override
1195 public VectorSpecies<Short> species() {
1196 return SPECIES;
1197 }
1198
1199 @Override
1200 public Short64Vector toVector() {
1201 short[] res = new short[species().length()];
1202 boolean[] bits = getBits();
1203 for (int i = 0; i < species().length(); i++) {
1204 // -1 will result in the most significant bit being set in
1205 // addition to some or all other bits
1206 res[i] = (short) (bits[i] ? -1 : 0);
1207 }
1208 return new Short64Vector(res);
1209 }
1210
1211 @Override
1212 @ForceInline
1213 @SuppressWarnings("unchecked")
1214 public <E> VectorMask<E> cast(VectorSpecies<E> species) {
1215 if (length() != species.length())
1216 throw new IllegalArgumentException("VectorMask length and species length differ");
1217 Class<?> stype = species.elementType();
1218 boolean [] maskArray = toArray();
1219 if (stype == byte.class) {
1220 return (VectorMask <E>) new Byte64Vector.Byte64Mask(maskArray);
1221 } else if (stype == short.class) {
1222 return (VectorMask <E>) new Short64Vector.Short64Mask(maskArray);
1223 } else if (stype == int.class) {
1224 return (VectorMask <E>) new Int64Vector.Int64Mask(maskArray);
1225 } else if (stype == long.class) {
1226 return (VectorMask <E>) new Long64Vector.Long64Mask(maskArray);
1227 } else if (stype == float.class) {
1228 return (VectorMask <E>) new Float64Vector.Float64Mask(maskArray);
1229 } else if (stype == double.class) {
1230 return (VectorMask <E>) new Double64Vector.Double64Mask(maskArray);
1231 } else {
1232 throw new UnsupportedOperationException("Bad lane type for casting.");
1233 }
1234 }
1235
1236 // Unary operations
1237
1238 @Override
1239 @ForceInline
1240 public Short64Mask not() {
1241 return (Short64Mask) VectorIntrinsics.unaryOp(
1242 VECTOR_OP_NOT, Short64Mask.class, short.class, LENGTH,
1243 this,
1244 (m1) -> m1.uOp((i, a) -> !a));
1245 }
1246
1247 // Binary operations
1248
1249 @Override
1250 @ForceInline
1251 public Short64Mask and(VectorMask<Short> o) {
1252 Objects.requireNonNull(o);
1253 Short64Mask m = (Short64Mask)o;
1254 return VectorIntrinsics.binaryOp(VECTOR_OP_AND, Short64Mask.class, short.class, LENGTH,
1255 this, m,
1256 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1257 }
1258
1259 @Override
1260 @ForceInline
1261 public Short64Mask or(VectorMask<Short> o) {
1262 Objects.requireNonNull(o);
1263 Short64Mask m = (Short64Mask)o;
1264 return VectorIntrinsics.binaryOp(VECTOR_OP_OR, Short64Mask.class, short.class, LENGTH,
1265 this, m,
1266 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1267 }
1268
1269 // Reductions
1270
1271 @Override
1272 @ForceInline
1273 public boolean anyTrue() {
1274 return VectorIntrinsics.test(BT_ne, Short64Mask.class, short.class, LENGTH,
1275 this, this,
1276 (m, __) -> anyTrueHelper(((Short64Mask)m).getBits()));
1277 }
1278
1279 @Override
1280 @ForceInline
1281 public boolean allTrue() {
1282 return VectorIntrinsics.test(BT_overflow, Short64Mask.class, short.class, LENGTH,
1283 this, VectorMask.maskAllTrue(species()),
1284 (m, __) -> allTrueHelper(((Short64Mask)m).getBits()));
1285 }
1286 }
1287
1288 // Shuffle
1289
1290 static final class Short64Shuffle extends AbstractShuffle<Short> {
1291 Short64Shuffle(byte[] reorder) {
1292 super(reorder);
1293 }
1294
1295 public Short64Shuffle(int[] reorder) {
1296 super(reorder);
1297 }
1298
1299 public Short64Shuffle(int[] reorder, int i) {
1300 super(reorder, i);
1301 }
1302
1303 public Short64Shuffle(IntUnaryOperator f) {
1304 super(f);
1305 }
1306
1307 @Override
1308 public VectorSpecies<Short> species() {
1309 return SPECIES;
1310 }
1311
1312 @Override
1313 public ShortVector toVector() {
1314 short[] va = new short[SPECIES.length()];
1315 for (int i = 0; i < va.length; i++) {
1316 va[i] = (short) getElement(i);
1317 }
1318 return ShortVector.fromArray(SPECIES, va, 0);
1319 }
1320
1321 @Override
1322 @ForceInline
1323 @SuppressWarnings("unchecked")
1324 public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
1325 if (length() != species.length())
1326 throw new IllegalArgumentException("Shuffle length and species length differ");
1327 Class<?> stype = species.elementType();
1328 int [] shuffleArray = toArray();
1329 if (stype == byte.class) {
1330 return (VectorShuffle<F>) new Byte64Vector.Byte64Shuffle(shuffleArray);
1331 } else if (stype == short.class) {
1332 return (VectorShuffle<F>) new Short64Vector.Short64Shuffle(shuffleArray);
1333 } else if (stype == int.class) {
1334 return (VectorShuffle<F>) new Int64Vector.Int64Shuffle(shuffleArray);
1335 } else if (stype == long.class) {
1336 return (VectorShuffle<F>) new Long64Vector.Long64Shuffle(shuffleArray);
1337 } else if (stype == float.class) {
1338 return (VectorShuffle<F>) new Float64Vector.Float64Shuffle(shuffleArray);
1339 } else if (stype == double.class) {
1340 return (VectorShuffle<F>) new Double64Vector.Double64Shuffle(shuffleArray);
1341 } else {
1342 throw new UnsupportedOperationException("Bad lane type for casting.");
1343 }
1344 }
1345
1346 @Override
1347 public Short64Shuffle rearrange(VectorShuffle<Short> o) {
1348 Short64Shuffle s = (Short64Shuffle) o;
1349 byte[] r = new byte[reorder.length];
1350 for (int i = 0; i < reorder.length; i++) {
1351 r[i] = reorder[s.reorder[i]];
1352 }
1353 return new Short64Shuffle(r);
1354 }
1355 }
1356
1357 // VectorSpecies
1358
1359 @Override
1360 public VectorSpecies<Short> species() {
1361 return SPECIES;
1362 }
1363 }
|