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.LongBuffer;
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 LongMaxVector extends LongVector {
41 private static final Species<Long> SPECIES = LongVector.SPECIES_MAX;
42
43 static final LongMaxVector ZERO = new LongMaxVector();
44
45 static final int LENGTH = SPECIES.length();
46
47 // Index vector species
48 private static final IntVector.IntSpecies INDEX_SPECIES;
49
50 static {
51 int bitSize = Vector.bitSizeForVectorLength(int.class, LENGTH);
52 INDEX_SPECIES = (IntVector.IntSpecies) IntVector.species(Shape.forBitSize(bitSize));
53 }
54
55 private final long[] vec; // Don't access directly, use getElements() instead.
56
57 private long[] getElements() {
58 return VectorIntrinsics.maybeRebox(this).vec;
59 }
60
61 LongMaxVector() {
62 vec = new long[SPECIES.length()];
63 }
64
65 LongMaxVector(long[] v) {
66 vec = v;
67 }
68
69 @Override
70 public int length() { return LENGTH; }
71
72 // Unary operator
73
74 @Override
75 LongMaxVector uOp(FUnOp f) {
76 long[] vec = getElements();
77 long[] res = new long[length()];
78 for (int i = 0; i < length(); i++) {
79 res[i] = f.apply(i, vec[i]);
80 }
81 return new LongMaxVector(res);
82 }
83
84 @Override
85 LongMaxVector uOp(Mask<Long> o, FUnOp f) {
86 long[] vec = getElements();
87 long[] res = new long[length()];
88 boolean[] mbits = ((LongMaxMask)o).getBits();
89 for (int i = 0; i < length(); i++) {
90 res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
91 }
92 return new LongMaxVector(res);
93 }
94
95 // Binary operator
96
97 @Override
98 LongMaxVector bOp(Vector<Long> o, FBinOp f) {
99 long[] res = new long[length()];
100 long[] vec1 = this.getElements();
101 long[] vec2 = ((LongMaxVector)o).getElements();
102 for (int i = 0; i < length(); i++) {
103 res[i] = f.apply(i, vec1[i], vec2[i]);
104 }
105 return new LongMaxVector(res);
106 }
107
108 @Override
109 LongMaxVector bOp(Vector<Long> o1, Mask<Long> o2, FBinOp f) {
110 long[] res = new long[length()];
111 long[] vec1 = this.getElements();
112 long[] vec2 = ((LongMaxVector)o1).getElements();
113 boolean[] mbits = ((LongMaxMask)o2).getBits();
114 for (int i = 0; i < length(); i++) {
115 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
116 }
117 return new LongMaxVector(res);
118 }
119
120 // Trinary operator
121
122 @Override
123 LongMaxVector tOp(Vector<Long> o1, Vector<Long> o2, FTriOp f) {
124 long[] res = new long[length()];
125 long[] vec1 = this.getElements();
126 long[] vec2 = ((LongMaxVector)o1).getElements();
127 long[] vec3 = ((LongMaxVector)o2).getElements();
128 for (int i = 0; i < length(); i++) {
129 res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
130 }
131 return new LongMaxVector(res);
132 }
133
134 @Override
135 LongMaxVector tOp(Vector<Long> o1, Vector<Long> o2, Mask<Long> o3, FTriOp f) {
136 long[] res = new long[length()];
137 long[] vec1 = getElements();
138 long[] vec2 = ((LongMaxVector)o1).getElements();
139 long[] vec3 = ((LongMaxVector)o2).getElements();
140 boolean[] mbits = ((LongMaxMask)o3).getBits();
141 for (int i = 0; i < length(); i++) {
142 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
143 }
144 return new LongMaxVector(res);
145 }
146
147 @Override
148 long rOp(long v, FBinOp f) {
149 long[] vec = getElements();
150 for (int i = 0; i < length(); i++) {
151 v = f.apply(i, v, vec[i]);
152 }
153 return v;
154 }
155
156 @Override
157 @ForceInline
158 public <F> Vector<F> cast(Species<F> s) {
159 Objects.requireNonNull(s);
160 if (s.length() != LENGTH)
161 throw new IllegalArgumentException("Vector length this species length differ");
162
163 return VectorIntrinsics.cast(
164 LongMaxVector.class,
165 long.class, LENGTH,
166 s.boxType(),
167 s.elementType(), LENGTH,
168 this, s,
169 (species, vector) -> vector.castDefault(species)
170 );
171 }
172
173 @SuppressWarnings("unchecked")
174 @ForceInline
175 private <F> Vector<F> castDefault(Species<F> s) {
176 int limit = s.length();
177
178 Class<?> stype = s.elementType();
179 if (stype == byte.class) {
180 byte[] a = new byte[limit];
181 for (int i = 0; i < limit; i++) {
182 a[i] = (byte) this.get(i);
183 }
184 return (Vector) ByteVector.fromArray((Species<Byte>) s, a, 0);
185 } else if (stype == short.class) {
186 short[] a = new short[limit];
187 for (int i = 0; i < limit; i++) {
188 a[i] = (short) this.get(i);
189 }
190 return (Vector) ShortVector.fromArray((Species<Short>) s, a, 0);
191 } else if (stype == int.class) {
192 int[] a = new int[limit];
193 for (int i = 0; i < limit; i++) {
194 a[i] = (int) this.get(i);
195 }
196 return (Vector) IntVector.fromArray((Species<Integer>) s, a, 0);
197 } else if (stype == long.class) {
198 long[] a = new long[limit];
199 for (int i = 0; i < limit; i++) {
200 a[i] = (long) this.get(i);
201 }
202 return (Vector) LongVector.fromArray((Species<Long>) s, a, 0);
203 } else if (stype == float.class) {
204 float[] a = new float[limit];
205 for (int i = 0; i < limit; i++) {
206 a[i] = (float) this.get(i);
207 }
208 return (Vector) FloatVector.fromArray((Species<Float>) s, a, 0);
209 } else if (stype == double.class) {
210 double[] a = new double[limit];
211 for (int i = 0; i < limit; i++) {
212 a[i] = (double) this.get(i);
213 }
214 return (Vector) DoubleVector.fromArray((Species<Double>) s, a, 0);
215 } else {
216 throw new UnsupportedOperationException("Bad lane type for casting.");
217 }
218 }
219
220 @Override
221 @ForceInline
222 @SuppressWarnings("unchecked")
223 public <F> Vector<F> reinterpret(Species<F> s) {
224 Objects.requireNonNull(s);
225
226 if(s.elementType().equals(long.class)) {
227 return (Vector<F>) reshape((Species<Long>)s);
228 }
229 if(s.bitSize() == bitSize()) {
230 return reinterpretType(s);
231 }
232
233 return defaultReinterpret(s);
234 }
235
236 @ForceInline
237 private <F> Vector<F> reinterpretType(Species<F> s) {
238 Objects.requireNonNull(s);
239
240 Class<?> stype = s.elementType();
241 if (stype == byte.class) {
242 return VectorIntrinsics.reinterpret(
243 LongMaxVector.class,
244 long.class, LENGTH,
245 ByteMaxVector.class,
246 byte.class, ByteMaxVector.LENGTH,
247 this, s,
248 (species, vector) -> vector.defaultReinterpret(species)
249 );
250 } else if (stype == short.class) {
251 return VectorIntrinsics.reinterpret(
252 LongMaxVector.class,
253 long.class, LENGTH,
254 ShortMaxVector.class,
255 short.class, ShortMaxVector.LENGTH,
256 this, s,
257 (species, vector) -> vector.defaultReinterpret(species)
282 float.class, FloatMaxVector.LENGTH,
283 this, s,
284 (species, vector) -> vector.defaultReinterpret(species)
285 );
286 } else if (stype == double.class) {
287 return VectorIntrinsics.reinterpret(
288 LongMaxVector.class,
289 long.class, LENGTH,
290 DoubleMaxVector.class,
291 double.class, DoubleMaxVector.LENGTH,
292 this, s,
293 (species, vector) -> vector.defaultReinterpret(species)
294 );
295 } else {
296 throw new UnsupportedOperationException("Bad lane type for casting.");
297 }
298 }
299
300 @Override
301 @ForceInline
302 public LongVector reshape(Species<Long> s) {
303 Objects.requireNonNull(s);
304 if (s.bitSize() == 64 && (s.boxType() == Long64Vector.class)) {
305 return VectorIntrinsics.reinterpret(
306 LongMaxVector.class,
307 long.class, LENGTH,
308 Long64Vector.class,
309 long.class, Long64Vector.LENGTH,
310 this, s,
311 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
312 );
313 } else if (s.bitSize() == 128 && (s.boxType() == Long128Vector.class)) {
314 return VectorIntrinsics.reinterpret(
315 LongMaxVector.class,
316 long.class, LENGTH,
317 Long128Vector.class,
318 long.class, Long128Vector.LENGTH,
319 this, s,
320 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
321 );
322 } else if (s.bitSize() == 256 && (s.boxType() == Long256Vector.class)) {
345 LongMaxVector.class,
346 long.class, LongMaxVector.LENGTH,
347 this, s,
348 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
349 );
350 } else {
351 throw new InternalError("Unimplemented size");
352 }
353 }
354
355 // Binary operations with scalars
356
357 @Override
358 @ForceInline
359 public LongVector add(long o) {
360 return add((LongMaxVector)LongVector.broadcast(SPECIES, o));
361 }
362
363 @Override
364 @ForceInline
365 public LongVector add(long o, Mask<Long> m) {
366 return add((LongMaxVector)LongVector.broadcast(SPECIES, o), m);
367 }
368
369 @Override
370 @ForceInline
371 public LongVector sub(long o) {
372 return sub((LongMaxVector)LongVector.broadcast(SPECIES, o));
373 }
374
375 @Override
376 @ForceInline
377 public LongVector sub(long o, Mask<Long> m) {
378 return sub((LongMaxVector)LongVector.broadcast(SPECIES, o), m);
379 }
380
381 @Override
382 @ForceInline
383 public LongVector mul(long o) {
384 return mul((LongMaxVector)LongVector.broadcast(SPECIES, o));
385 }
386
387 @Override
388 @ForceInline
389 public LongVector mul(long o, Mask<Long> m) {
390 return mul((LongMaxVector)LongVector.broadcast(SPECIES, o), m);
391 }
392
393 @Override
394 @ForceInline
395 public LongVector min(long o) {
396 return min((LongMaxVector)LongVector.broadcast(SPECIES, o));
397 }
398
399 @Override
400 @ForceInline
401 public LongVector max(long o) {
402 return max((LongMaxVector)LongVector.broadcast(SPECIES, o));
403 }
404
405 @Override
406 @ForceInline
407 public Mask<Long> equal(long o) {
408 return equal((LongMaxVector)LongVector.broadcast(SPECIES, o));
409 }
410
411 @Override
412 @ForceInline
413 public Mask<Long> notEqual(long o) {
414 return notEqual((LongMaxVector)LongVector.broadcast(SPECIES, o));
415 }
416
417 @Override
418 @ForceInline
419 public Mask<Long> lessThan(long o) {
420 return lessThan((LongMaxVector)LongVector.broadcast(SPECIES, o));
421 }
422
423 @Override
424 @ForceInline
425 public Mask<Long> lessThanEq(long o) {
426 return lessThanEq((LongMaxVector)LongVector.broadcast(SPECIES, o));
427 }
428
429 @Override
430 @ForceInline
431 public Mask<Long> greaterThan(long o) {
432 return greaterThan((LongMaxVector)LongVector.broadcast(SPECIES, o));
433 }
434
435 @Override
436 @ForceInline
437 public Mask<Long> greaterThanEq(long o) {
438 return greaterThanEq((LongMaxVector)LongVector.broadcast(SPECIES, o));
439 }
440
441 @Override
442 @ForceInline
443 public LongVector blend(long o, Mask<Long> m) {
444 return blend((LongMaxVector)LongVector.broadcast(SPECIES, o), m);
445 }
446
447
448 @Override
449 @ForceInline
450 public LongVector and(long o) {
451 return and((LongMaxVector)LongVector.broadcast(SPECIES, o));
452 }
453
454 @Override
455 @ForceInline
456 public LongVector and(long o, Mask<Long> m) {
457 return and((LongMaxVector)LongVector.broadcast(SPECIES, o), m);
458 }
459
460 @Override
461 @ForceInline
462 public LongVector or(long o) {
463 return or((LongMaxVector)LongVector.broadcast(SPECIES, o));
464 }
465
466 @Override
467 @ForceInline
468 public LongVector or(long o, Mask<Long> m) {
469 return or((LongMaxVector)LongVector.broadcast(SPECIES, o), m);
470 }
471
472 @Override
473 @ForceInline
474 public LongVector xor(long o) {
475 return xor((LongMaxVector)LongVector.broadcast(SPECIES, o));
476 }
477
478 @Override
479 @ForceInline
480 public LongVector xor(long o, Mask<Long> m) {
481 return xor((LongMaxVector)LongVector.broadcast(SPECIES, o), m);
482 }
483
484 @Override
485 @ForceInline
486 public LongMaxVector neg() {
487 return (LongMaxVector)zero(SPECIES).sub(this);
488 }
489
490 // Unary operations
491
492 @ForceInline
493 @Override
494 public LongMaxVector neg(Mask<Long> m) {
495 return blend(neg(), m);
496 }
497
498 @Override
499 @ForceInline
500 public LongMaxVector abs() {
501 return VectorIntrinsics.unaryOp(
502 VECTOR_OP_ABS, LongMaxVector.class, long.class, LENGTH,
503 this,
504 v1 -> v1.uOp((i, a) -> (long) Math.abs(a)));
505 }
506
507 @ForceInline
508 @Override
509 public LongMaxVector abs(Mask<Long> m) {
510 return blend(abs(), m);
511 }
512
513
514 @Override
515 @ForceInline
516 public LongMaxVector not() {
517 return VectorIntrinsics.unaryOp(
518 VECTOR_OP_NOT, LongMaxVector.class, long.class, LENGTH,
519 this,
520 v1 -> v1.uOp((i, a) -> (long) ~a));
521 }
522
523 @ForceInline
524 @Override
525 public LongMaxVector not(Mask<Long> m) {
526 return blend(not(), m);
527 }
528 // Binary operations
529
530 @Override
531 @ForceInline
532 public LongMaxVector add(Vector<Long> o) {
533 Objects.requireNonNull(o);
534 LongMaxVector v = (LongMaxVector)o;
535 return VectorIntrinsics.binaryOp(
536 VECTOR_OP_ADD, LongMaxVector.class, long.class, LENGTH,
537 this, v,
538 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a + b)));
539 }
540
541 @Override
542 @ForceInline
543 public LongMaxVector add(Vector<Long> v, Mask<Long> m) {
544 return blend(add(v), m);
545 }
546
547 @Override
548 @ForceInline
549 public LongMaxVector sub(Vector<Long> o) {
550 Objects.requireNonNull(o);
551 LongMaxVector v = (LongMaxVector)o;
552 return VectorIntrinsics.binaryOp(
553 VECTOR_OP_SUB, LongMaxVector.class, long.class, LENGTH,
554 this, v,
555 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a - b)));
556 }
557
558 @Override
559 @ForceInline
560 public LongMaxVector sub(Vector<Long> v, Mask<Long> m) {
561 return blend(sub(v), m);
562 }
563
564 @Override
565 @ForceInline
566 public LongMaxVector mul(Vector<Long> o) {
567 Objects.requireNonNull(o);
568 LongMaxVector v = (LongMaxVector)o;
569 return VectorIntrinsics.binaryOp(
570 VECTOR_OP_MUL, LongMaxVector.class, long.class, LENGTH,
571 this, v,
572 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a * b)));
573 }
574
575 @Override
576 @ForceInline
577 public LongMaxVector mul(Vector<Long> v, Mask<Long> m) {
578 return blend(mul(v), m);
579 }
580
581 @Override
582 @ForceInline
583 public LongMaxVector min(Vector<Long> o) {
584 Objects.requireNonNull(o);
585 LongMaxVector v = (LongMaxVector)o;
586 return (LongMaxVector) VectorIntrinsics.binaryOp(
587 VECTOR_OP_MIN, LongMaxVector.class, long.class, LENGTH,
588 this, v,
589 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long) Math.min(a, b)));
590 }
591
592 @Override
593 @ForceInline
594 public LongMaxVector min(Vector<Long> v, Mask<Long> m) {
595 return blend(min(v), m);
596 }
597
598 @Override
599 @ForceInline
600 public LongMaxVector max(Vector<Long> o) {
601 Objects.requireNonNull(o);
602 LongMaxVector v = (LongMaxVector)o;
603 return VectorIntrinsics.binaryOp(
604 VECTOR_OP_MAX, LongMaxVector.class, long.class, LENGTH,
605 this, v,
606 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long) Math.max(a, b)));
607 }
608
609 @Override
610 @ForceInline
611 public LongMaxVector max(Vector<Long> v, Mask<Long> m) {
612 return blend(max(v), m);
613 }
614
615 @Override
616 @ForceInline
617 public LongMaxVector and(Vector<Long> o) {
618 Objects.requireNonNull(o);
619 LongMaxVector v = (LongMaxVector)o;
620 return VectorIntrinsics.binaryOp(
621 VECTOR_OP_AND, LongMaxVector.class, long.class, LENGTH,
622 this, v,
623 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a & b)));
624 }
625
626 @Override
627 @ForceInline
628 public LongMaxVector or(Vector<Long> o) {
629 Objects.requireNonNull(o);
630 LongMaxVector v = (LongMaxVector)o;
631 return VectorIntrinsics.binaryOp(
632 VECTOR_OP_OR, LongMaxVector.class, long.class, LENGTH,
633 this, v,
634 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a | b)));
635 }
636
637 @Override
638 @ForceInline
639 public LongMaxVector xor(Vector<Long> o) {
640 Objects.requireNonNull(o);
641 LongMaxVector v = (LongMaxVector)o;
642 return VectorIntrinsics.binaryOp(
643 VECTOR_OP_XOR, LongMaxVector.class, long.class, LENGTH,
644 this, v,
645 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a ^ b)));
646 }
647
648 @Override
649 @ForceInline
650 public LongMaxVector and(Vector<Long> v, Mask<Long> m) {
651 return blend(and(v), m);
652 }
653
654 @Override
655 @ForceInline
656 public LongMaxVector or(Vector<Long> v, Mask<Long> m) {
657 return blend(or(v), m);
658 }
659
660 @Override
661 @ForceInline
662 public LongMaxVector xor(Vector<Long> v, Mask<Long> m) {
663 return blend(xor(v), m);
664 }
665
666 @Override
667 @ForceInline
668 public LongMaxVector shiftL(int s) {
669 return VectorIntrinsics.broadcastInt(
670 VECTOR_OP_LSHIFT, LongMaxVector.class, long.class, LENGTH,
671 this, s,
672 (v, i) -> v.uOp((__, a) -> (long) (a << i)));
673 }
674
675 @Override
676 @ForceInline
677 public LongMaxVector shiftL(int s, Mask<Long> m) {
678 return blend(shiftL(s), m);
679 }
680
681 @Override
682 @ForceInline
683 public LongMaxVector shiftR(int s) {
684 return VectorIntrinsics.broadcastInt(
685 VECTOR_OP_URSHIFT, LongMaxVector.class, long.class, LENGTH,
686 this, s,
687 (v, i) -> v.uOp((__, a) -> (long) (a >>> i)));
688 }
689
690 @Override
691 @ForceInline
692 public LongMaxVector shiftR(int s, Mask<Long> m) {
693 return blend(shiftR(s), m);
694 }
695
696 @Override
697 @ForceInline
698 public LongMaxVector aShiftR(int s) {
699 return VectorIntrinsics.broadcastInt(
700 VECTOR_OP_RSHIFT, LongMaxVector.class, long.class, LENGTH,
701 this, s,
702 (v, i) -> v.uOp((__, a) -> (long) (a >> i)));
703 }
704
705 @Override
706 @ForceInline
707 public LongMaxVector aShiftR(int s, Mask<Long> m) {
708 return blend(aShiftR(s), m);
709 }
710
711 @Override
712 @ForceInline
713 public LongMaxVector shiftL(Vector<Long> s) {
714 LongMaxVector shiftv = (LongMaxVector)s;
715 // As per shift specification for Java, mask the shift count.
716 shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
717 return VectorIntrinsics.binaryOp(
718 VECTOR_OP_LSHIFT, LongMaxVector.class, long.class, LENGTH,
719 this, shiftv,
720 (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a << b)));
721 }
722
723 @Override
724 @ForceInline
725 public LongMaxVector shiftR(Vector<Long> s) {
726 LongMaxVector shiftv = (LongMaxVector)s;
727 // As per shift specification for Java, mask the shift count.
751 @Override
752 @ForceInline
753 public long addAll() {
754 return (long) VectorIntrinsics.reductionCoerced(
755 VECTOR_OP_ADD, LongMaxVector.class, long.class, LENGTH,
756 this,
757 v -> (long) v.rOp((long) 0, (i, a, b) -> (long) (a + b)));
758 }
759
760 @Override
761 @ForceInline
762 public long andAll() {
763 return (long) VectorIntrinsics.reductionCoerced(
764 VECTOR_OP_AND, LongMaxVector.class, long.class, LENGTH,
765 this,
766 v -> (long) v.rOp((long) -1, (i, a, b) -> (long) (a & b)));
767 }
768
769 @Override
770 @ForceInline
771 public long andAll(Mask<Long> m) {
772 return blend((LongMaxVector)LongVector.broadcast(SPECIES, (long) -1), m).andAll();
773 }
774
775 @Override
776 @ForceInline
777 public long minAll() {
778 return (long) VectorIntrinsics.reductionCoerced(
779 VECTOR_OP_MIN, LongMaxVector.class, long.class, LENGTH,
780 this,
781 v -> (long) v.rOp(Long.MAX_VALUE , (i, a, b) -> (long) Math.min(a, b)));
782 }
783
784 @Override
785 @ForceInline
786 public long maxAll() {
787 return (long) VectorIntrinsics.reductionCoerced(
788 VECTOR_OP_MAX, LongMaxVector.class, long.class, LENGTH,
789 this,
790 v -> (long) v.rOp(Long.MIN_VALUE , (i, a, b) -> (long) Math.max(a, b)));
791 }
793 @Override
794 @ForceInline
795 public long mulAll() {
796 return (long) VectorIntrinsics.reductionCoerced(
797 VECTOR_OP_MUL, LongMaxVector.class, long.class, LENGTH,
798 this,
799 v -> (long) v.rOp((long) 1, (i, a, b) -> (long) (a * b)));
800 }
801
802 @Override
803 @ForceInline
804 public long orAll() {
805 return (long) VectorIntrinsics.reductionCoerced(
806 VECTOR_OP_OR, LongMaxVector.class, long.class, LENGTH,
807 this,
808 v -> (long) v.rOp((long) 0, (i, a, b) -> (long) (a | b)));
809 }
810
811 @Override
812 @ForceInline
813 public long orAll(Mask<Long> m) {
814 return blend((LongMaxVector)LongVector.broadcast(SPECIES, (long) 0), m).orAll();
815 }
816
817 @Override
818 @ForceInline
819 public long xorAll() {
820 return (long) VectorIntrinsics.reductionCoerced(
821 VECTOR_OP_XOR, LongMaxVector.class, long.class, LENGTH,
822 this,
823 v -> (long) v.rOp((long) 0, (i, a, b) -> (long) (a ^ b)));
824 }
825
826 @Override
827 @ForceInline
828 public long xorAll(Mask<Long> m) {
829 return blend((LongMaxVector)LongVector.broadcast(SPECIES, (long) 0), m).xorAll();
830 }
831
832
833 @Override
834 @ForceInline
835 public long addAll(Mask<Long> m) {
836 return blend((LongMaxVector)LongVector.broadcast(SPECIES, (long) 0), m).addAll();
837 }
838
839
840 @Override
841 @ForceInline
842 public long mulAll(Mask<Long> m) {
843 return blend((LongMaxVector)LongVector.broadcast(SPECIES, (long) 1), m).mulAll();
844 }
845
846 @Override
847 @ForceInline
848 public long minAll(Mask<Long> m) {
849 return blend((LongMaxVector)LongVector.broadcast(SPECIES, Long.MAX_VALUE), m).minAll();
850 }
851
852 @Override
853 @ForceInline
854 public long maxAll(Mask<Long> m) {
855 return blend((LongMaxVector)LongVector.broadcast(SPECIES, Long.MIN_VALUE), m).maxAll();
856 }
857
858 @Override
859 @ForceInline
860 public Shuffle<Long> toShuffle() {
861 long[] a = toArray();
862 int[] sa = new int[a.length];
863 for (int i = 0; i < a.length; i++) {
864 sa[i] = (int) a[i];
865 }
866 return LongVector.shuffleFromArray(SPECIES, sa, 0);
867 }
868
869 // Memory operations
870
871 private static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_LONG_INDEX_SCALE);
872 private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
873
874 @Override
875 @ForceInline
876 public void intoArray(long[] a, int ix) {
877 Objects.requireNonNull(a);
878 ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
879 VectorIntrinsics.store(LongMaxVector.class, long.class, LENGTH,
880 a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_LONG_BASE_OFFSET,
881 this,
882 a, ix,
883 (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
884 }
885
886 @Override
887 @ForceInline
888 public final void intoArray(long[] a, int ax, Mask<Long> m) {
889 LongVector oldVal = LongVector.fromArray(SPECIES, a, ax);
890 LongVector newVal = oldVal.blend(this, m);
891 newVal.intoArray(a, ax);
892 }
893 @Override
894 @ForceInline
895 public void intoArray(long[] a, int ix, int[] b, int iy) {
896 Objects.requireNonNull(a);
897 Objects.requireNonNull(b);
898
899 // Index vector: vix[0:n] = i -> ix + indexMap[iy + i]
900 IntVector vix = IntVector.fromArray(INDEX_SPECIES, b, iy).add(ix);
901
902 vix = VectorIntrinsics.checkIndex(vix, a.length);
903
904 VectorIntrinsics.storeWithMap(LongMaxVector.class, long.class, LENGTH, vix.getClass(),
905 a, Unsafe.ARRAY_LONG_BASE_OFFSET, vix,
906 this,
907 a, ix, b, iy,
908 (arr, idx, v, indexMap, idy) -> v.forEach((i, e) -> arr[idx+indexMap[idy+i]] = e));
909 }
910
911 @Override
912 @ForceInline
913 public final void intoArray(long[] a, int ax, Mask<Long> m, int[] b, int iy) {
914 // @@@ This can result in out of bounds errors for unset mask lanes
915 LongVector oldVal = LongVector.fromArray(SPECIES, a, ax, b, iy);
916 LongVector newVal = oldVal.blend(this, m);
917 newVal.intoArray(a, ax, b, iy);
918 }
919
920 @Override
921 @ForceInline
922 public void intoByteArray(byte[] a, int ix) {
923 Objects.requireNonNull(a);
924 ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
925 VectorIntrinsics.store(LongMaxVector.class, long.class, LENGTH,
926 a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
927 this,
928 a, ix,
929 (c, idx, v) -> {
930 ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
931 LongBuffer tb = bbc.asLongBuffer();
932 v.forEach((i, e) -> tb.put(e));
933 });
934 }
935
936 @Override
937 @ForceInline
938 public final void intoByteArray(byte[] a, int ix, Mask<Long> m) {
939 LongMaxVector oldVal = (LongMaxVector) LongVector.fromByteArray(SPECIES, a, ix);
940 LongMaxVector newVal = oldVal.blend(this, m);
941 newVal.intoByteArray(a, ix);
942 }
943
944 @Override
945 @ForceInline
946 public void intoByteBuffer(ByteBuffer bb, int ix) {
947 if (bb.order() != ByteOrder.nativeOrder()) {
948 throw new IllegalArgumentException();
949 }
950 if (bb.isReadOnly()) {
951 throw new ReadOnlyBufferException();
952 }
953 ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
954 VectorIntrinsics.store(LongMaxVector.class, long.class, LENGTH,
955 U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
956 this,
957 bb, ix,
958 (c, idx, v) -> {
959 ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
960 LongBuffer tb = bbc.asLongBuffer();
961 v.forEach((i, e) -> tb.put(e));
962 });
963 }
964
965 @Override
966 @ForceInline
967 public void intoByteBuffer(ByteBuffer bb, int ix, Mask<Long> m) {
968 LongMaxVector oldVal = (LongMaxVector) LongVector.fromByteBuffer(SPECIES, bb, ix);
969 LongMaxVector newVal = oldVal.blend(this, m);
970 newVal.intoByteBuffer(bb, ix);
971 }
972
973 //
974
975 @Override
976 public String toString() {
977 return Arrays.toString(getElements());
978 }
979
980 @Override
981 public boolean equals(Object o) {
982 if (this == o) return true;
983 if (o == null || this.getClass() != o.getClass()) return false;
984
985 LongMaxVector that = (LongMaxVector) o;
986 return this.equal(that).allTrue();
987 }
1072 Objects.requireNonNull(o);
1073 LongMaxVector v = (LongMaxVector)o;
1074
1075 return VectorIntrinsics.compare(
1076 BT_ge, LongMaxVector.class, LongMaxMask.class, long.class, LENGTH,
1077 this, v,
1078 (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1079 }
1080
1081 // Foreach
1082
1083 @Override
1084 void forEach(FUnCon f) {
1085 long[] vec = getElements();
1086 for (int i = 0; i < length(); i++) {
1087 f.apply(i, vec[i]);
1088 }
1089 }
1090
1091 @Override
1092 void forEach(Mask<Long> o, FUnCon f) {
1093 boolean[] mbits = ((LongMaxMask)o).getBits();
1094 forEach((i, a) -> {
1095 if (mbits[i]) { f.apply(i, a); }
1096 });
1097 }
1098
1099
1100 DoubleMaxVector toFP() {
1101 long[] vec = getElements();
1102 double[] res = new double[this.species().length()];
1103 for(int i = 0; i < this.species().length(); i++){
1104 res[i] = Double.longBitsToDouble(vec[i]);
1105 }
1106 return new DoubleMaxVector(res);
1107 }
1108
1109 @Override
1110 public LongMaxVector rotateEL(int j) {
1111 long[] vec = getElements();
1112 long[] res = new long[length()];
1137 long[] res = new long[length()];
1138 for (int i = 0; i < length() - j; i++) {
1139 res[i] = vec[i + j];
1140 }
1141 return new LongMaxVector(res);
1142 }
1143
1144 @Override
1145 public LongMaxVector shiftER(int j) {
1146 long[] vec = getElements();
1147 long[] res = new long[length()];
1148 for (int i = 0; i < length() - j; i++){
1149 res[i + j] = vec[i];
1150 }
1151 return new LongMaxVector(res);
1152 }
1153
1154 @Override
1155 @ForceInline
1156 public LongMaxVector rearrange(Vector<Long> v,
1157 Shuffle<Long> s, Mask<Long> m) {
1158 return this.rearrange(s).blend(v.rearrange(s), m);
1159 }
1160
1161 @Override
1162 @ForceInline
1163 public LongMaxVector rearrange(Shuffle<Long> o1) {
1164 Objects.requireNonNull(o1);
1165 LongMaxShuffle s = (LongMaxShuffle)o1;
1166
1167 return VectorIntrinsics.rearrangeOp(
1168 LongMaxVector.class, LongMaxShuffle.class, long.class, LENGTH,
1169 this, s,
1170 (v1, s_) -> v1.uOp((i, a) -> {
1171 int ei = s_.getElement(i);
1172 return v1.get(ei);
1173 }));
1174 }
1175
1176 @Override
1177 @ForceInline
1178 public LongMaxVector blend(Vector<Long> o1, Mask<Long> o2) {
1179 Objects.requireNonNull(o1);
1180 Objects.requireNonNull(o2);
1181 LongMaxVector v = (LongMaxVector)o1;
1182 LongMaxMask m = (LongMaxMask)o2;
1183
1184 return VectorIntrinsics.blend(
1185 LongMaxVector.class, LongMaxMask.class, long.class, LENGTH,
1186 this, v, m,
1187 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1188 }
1189
1190 // Accessors
1191
1192 @Override
1193 public long get(int i) {
1194 if (i < 0 || i >= LENGTH) {
1195 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1196 }
1197 return (long) VectorIntrinsics.extract(
1198 LongMaxVector.class, long.class, LENGTH,
1242 boolean[] bits = new boolean[species().length()];
1243 Arrays.fill(bits, val);
1244 this.bits = bits;
1245 }
1246
1247 boolean[] getBits() {
1248 return VectorIntrinsics.maybeRebox(this).bits;
1249 }
1250
1251 @Override
1252 LongMaxMask uOp(MUnOp f) {
1253 boolean[] res = new boolean[species().length()];
1254 boolean[] bits = getBits();
1255 for (int i = 0; i < species().length(); i++) {
1256 res[i] = f.apply(i, bits[i]);
1257 }
1258 return new LongMaxMask(res);
1259 }
1260
1261 @Override
1262 LongMaxMask bOp(Mask<Long> o, MBinOp f) {
1263 boolean[] res = new boolean[species().length()];
1264 boolean[] bits = getBits();
1265 boolean[] mbits = ((LongMaxMask)o).getBits();
1266 for (int i = 0; i < species().length(); i++) {
1267 res[i] = f.apply(i, bits[i], mbits[i]);
1268 }
1269 return new LongMaxMask(res);
1270 }
1271
1272 @Override
1273 public Species<Long> species() {
1274 return SPECIES;
1275 }
1276
1277 @Override
1278 public LongMaxVector toVector() {
1279 long[] res = new long[species().length()];
1280 boolean[] bits = getBits();
1281 for (int i = 0; i < species().length(); i++) {
1282 // -1 will result in the most significant bit being set in
1283 // addition to some or all other bits
1284 res[i] = (long) (bits[i] ? -1 : 0);
1285 }
1286 return new LongMaxVector(res);
1287 }
1288
1289 @Override
1290 @ForceInline
1291 @SuppressWarnings("unchecked")
1292 public <E> Mask<E> cast(Species<E> species) {
1293 if (length() != species.length())
1294 throw new IllegalArgumentException("Mask length and species length differ");
1295 Class<?> stype = species.elementType();
1296 boolean [] maskArray = toArray();
1297 if (stype == byte.class) {
1298 return (Mask <E>) new ByteMaxVector.ByteMaxMask(maskArray);
1299 } else if (stype == short.class) {
1300 return (Mask <E>) new ShortMaxVector.ShortMaxMask(maskArray);
1301 } else if (stype == int.class) {
1302 return (Mask <E>) new IntMaxVector.IntMaxMask(maskArray);
1303 } else if (stype == long.class) {
1304 return (Mask <E>) new LongMaxVector.LongMaxMask(maskArray);
1305 } else if (stype == float.class) {
1306 return (Mask <E>) new FloatMaxVector.FloatMaxMask(maskArray);
1307 } else if (stype == double.class) {
1308 return (Mask <E>) new DoubleMaxVector.DoubleMaxMask(maskArray);
1309 } else {
1310 throw new UnsupportedOperationException("Bad lane type for casting.");
1311 }
1312 }
1313
1314 // Unary operations
1315
1316 @Override
1317 @ForceInline
1318 public LongMaxMask not() {
1319 return (LongMaxMask) VectorIntrinsics.unaryOp(
1320 VECTOR_OP_NOT, LongMaxMask.class, long.class, LENGTH,
1321 this,
1322 (m1) -> m1.uOp((i, a) -> !a));
1323 }
1324
1325 // Binary operations
1326
1327 @Override
1328 @ForceInline
1329 public LongMaxMask and(Mask<Long> o) {
1330 Objects.requireNonNull(o);
1331 LongMaxMask m = (LongMaxMask)o;
1332 return VectorIntrinsics.binaryOp(VECTOR_OP_AND, LongMaxMask.class, long.class, LENGTH,
1333 this, m,
1334 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1335 }
1336
1337 @Override
1338 @ForceInline
1339 public LongMaxMask or(Mask<Long> o) {
1340 Objects.requireNonNull(o);
1341 LongMaxMask m = (LongMaxMask)o;
1342 return VectorIntrinsics.binaryOp(VECTOR_OP_OR, LongMaxMask.class, long.class, LENGTH,
1343 this, m,
1344 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1345 }
1346
1347 // Reductions
1348
1349 @Override
1350 @ForceInline
1351 public boolean anyTrue() {
1352 return VectorIntrinsics.test(BT_ne, LongMaxMask.class, long.class, LENGTH,
1353 this, this,
1354 (m, __) -> anyTrueHelper(((LongMaxMask)m).getBits()));
1355 }
1356
1357 @Override
1358 @ForceInline
1359 public boolean allTrue() {
1360 return VectorIntrinsics.test(BT_overflow, LongMaxMask.class, long.class, LENGTH,
1361 this, LongVector.maskAllTrue(species()),
1362 (m, __) -> allTrueHelper(((LongMaxMask)m).getBits()));
1363 }
1364 }
1365
1366 // Shuffle
1367
1368 static final class LongMaxShuffle extends AbstractShuffle<Long> {
1369 LongMaxShuffle(byte[] reorder) {
1370 super(reorder);
1371 }
1372
1373 public LongMaxShuffle(int[] reorder) {
1374 super(reorder);
1375 }
1376
1377 public LongMaxShuffle(int[] reorder, int i) {
1378 super(reorder, i);
1379 }
1380
1381 public LongMaxShuffle(IntUnaryOperator f) {
1382 super(f);
1383 }
1384
1385 @Override
1386 public Species<Long> species() {
1387 return SPECIES;
1388 }
1389
1390 @Override
1391 public LongVector toVector() {
1392 long[] va = new long[SPECIES.length()];
1393 for (int i = 0; i < va.length; i++) {
1394 va[i] = (long) getElement(i);
1395 }
1396 return LongVector.fromArray(SPECIES, va, 0);
1397 }
1398
1399 @Override
1400 @ForceInline
1401 @SuppressWarnings("unchecked")
1402 public <F> Shuffle<F> cast(Species<F> species) {
1403 if (length() != species.length())
1404 throw new IllegalArgumentException("Shuffle length and species length differ");
1405 Class<?> stype = species.elementType();
1406 int [] shuffleArray = toArray();
1407 if (stype == byte.class) {
1408 return (Shuffle<F>) new ByteMaxVector.ByteMaxShuffle(shuffleArray);
1409 } else if (stype == short.class) {
1410 return (Shuffle<F>) new ShortMaxVector.ShortMaxShuffle(shuffleArray);
1411 } else if (stype == int.class) {
1412 return (Shuffle<F>) new IntMaxVector.IntMaxShuffle(shuffleArray);
1413 } else if (stype == long.class) {
1414 return (Shuffle<F>) new LongMaxVector.LongMaxShuffle(shuffleArray);
1415 } else if (stype == float.class) {
1416 return (Shuffle<F>) new FloatMaxVector.FloatMaxShuffle(shuffleArray);
1417 } else if (stype == double.class) {
1418 return (Shuffle<F>) new DoubleMaxVector.DoubleMaxShuffle(shuffleArray);
1419 } else {
1420 throw new UnsupportedOperationException("Bad lane type for casting.");
1421 }
1422 }
1423
1424 @Override
1425 public LongMaxShuffle rearrange(Vector.Shuffle<Long> o) {
1426 LongMaxShuffle s = (LongMaxShuffle) o;
1427 byte[] r = new byte[reorder.length];
1428 for (int i = 0; i < reorder.length; i++) {
1429 r[i] = reorder[s.reorder[i]];
1430 }
1431 return new LongMaxShuffle(r);
1432 }
1433 }
1434
1435 // Species
1436
1437 @Override
1438 public Species<Long> species() {
1439 return SPECIES;
1440 }
1441 }
|
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.LongBuffer;
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 LongMaxVector extends LongVector {
41 private static final VectorSpecies<Long> SPECIES = LongVector.SPECIES_MAX;
42
43 static final LongMaxVector ZERO = new LongMaxVector();
44
45 static final int LENGTH = SPECIES.length();
46
47 // Index vector species
48 private static final IntVector.IntSpecies INDEX_SPECIES;
49
50 static {
51 int bitSize = Vector.bitSizeForVectorLength(int.class, LENGTH);
52 INDEX_SPECIES = (IntVector.IntSpecies) IntVector.species(VectorShape.forBitSize(bitSize));
53 }
54
55 private final long[] vec; // Don't access directly, use getElements() instead.
56
57 private long[] getElements() {
58 return VectorIntrinsics.maybeRebox(this).vec;
59 }
60
61 LongMaxVector() {
62 vec = new long[SPECIES.length()];
63 }
64
65 LongMaxVector(long[] v) {
66 vec = v;
67 }
68
69 @Override
70 public int length() { return LENGTH; }
71
72 // Unary operator
73
74 @Override
75 LongMaxVector uOp(FUnOp f) {
76 long[] vec = getElements();
77 long[] res = new long[length()];
78 for (int i = 0; i < length(); i++) {
79 res[i] = f.apply(i, vec[i]);
80 }
81 return new LongMaxVector(res);
82 }
83
84 @Override
85 LongMaxVector uOp(VectorMask<Long> o, FUnOp f) {
86 long[] vec = getElements();
87 long[] res = new long[length()];
88 boolean[] mbits = ((LongMaxMask)o).getBits();
89 for (int i = 0; i < length(); i++) {
90 res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
91 }
92 return new LongMaxVector(res);
93 }
94
95 // Binary operator
96
97 @Override
98 LongMaxVector bOp(Vector<Long> o, FBinOp f) {
99 long[] res = new long[length()];
100 long[] vec1 = this.getElements();
101 long[] vec2 = ((LongMaxVector)o).getElements();
102 for (int i = 0; i < length(); i++) {
103 res[i] = f.apply(i, vec1[i], vec2[i]);
104 }
105 return new LongMaxVector(res);
106 }
107
108 @Override
109 LongMaxVector bOp(Vector<Long> o1, VectorMask<Long> o2, FBinOp f) {
110 long[] res = new long[length()];
111 long[] vec1 = this.getElements();
112 long[] vec2 = ((LongMaxVector)o1).getElements();
113 boolean[] mbits = ((LongMaxMask)o2).getBits();
114 for (int i = 0; i < length(); i++) {
115 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
116 }
117 return new LongMaxVector(res);
118 }
119
120 // Trinary operator
121
122 @Override
123 LongMaxVector tOp(Vector<Long> o1, Vector<Long> o2, FTriOp f) {
124 long[] res = new long[length()];
125 long[] vec1 = this.getElements();
126 long[] vec2 = ((LongMaxVector)o1).getElements();
127 long[] vec3 = ((LongMaxVector)o2).getElements();
128 for (int i = 0; i < length(); i++) {
129 res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
130 }
131 return new LongMaxVector(res);
132 }
133
134 @Override
135 LongMaxVector tOp(Vector<Long> o1, Vector<Long> o2, VectorMask<Long> o3, FTriOp f) {
136 long[] res = new long[length()];
137 long[] vec1 = getElements();
138 long[] vec2 = ((LongMaxVector)o1).getElements();
139 long[] vec3 = ((LongMaxVector)o2).getElements();
140 boolean[] mbits = ((LongMaxMask)o3).getBits();
141 for (int i = 0; i < length(); i++) {
142 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
143 }
144 return new LongMaxVector(res);
145 }
146
147 @Override
148 long rOp(long v, FBinOp f) {
149 long[] vec = getElements();
150 for (int i = 0; i < length(); i++) {
151 v = f.apply(i, v, vec[i]);
152 }
153 return v;
154 }
155
156 @Override
157 @ForceInline
158 public <F> Vector<F> cast(VectorSpecies<F> s) {
159 Objects.requireNonNull(s);
160 if (s.length() != LENGTH)
161 throw new IllegalArgumentException("Vector length this species length differ");
162
163 return VectorIntrinsics.cast(
164 LongMaxVector.class,
165 long.class, LENGTH,
166 s.boxType(),
167 s.elementType(), LENGTH,
168 this, s,
169 (species, vector) -> vector.castDefault(species)
170 );
171 }
172
173 @SuppressWarnings("unchecked")
174 @ForceInline
175 private <F> Vector<F> castDefault(VectorSpecies<F> s) {
176 int limit = s.length();
177
178 Class<?> stype = s.elementType();
179 if (stype == byte.class) {
180 byte[] a = new byte[limit];
181 for (int i = 0; i < limit; i++) {
182 a[i] = (byte) this.get(i);
183 }
184 return (Vector) ByteVector.fromArray((VectorSpecies<Byte>) s, a, 0);
185 } else if (stype == short.class) {
186 short[] a = new short[limit];
187 for (int i = 0; i < limit; i++) {
188 a[i] = (short) this.get(i);
189 }
190 return (Vector) ShortVector.fromArray((VectorSpecies<Short>) s, a, 0);
191 } else if (stype == int.class) {
192 int[] a = new int[limit];
193 for (int i = 0; i < limit; i++) {
194 a[i] = (int) this.get(i);
195 }
196 return (Vector) IntVector.fromArray((VectorSpecies<Integer>) s, a, 0);
197 } else if (stype == long.class) {
198 long[] a = new long[limit];
199 for (int i = 0; i < limit; i++) {
200 a[i] = (long) this.get(i);
201 }
202 return (Vector) LongVector.fromArray((VectorSpecies<Long>) s, a, 0);
203 } else if (stype == float.class) {
204 float[] a = new float[limit];
205 for (int i = 0; i < limit; i++) {
206 a[i] = (float) this.get(i);
207 }
208 return (Vector) FloatVector.fromArray((VectorSpecies<Float>) s, a, 0);
209 } else if (stype == double.class) {
210 double[] a = new double[limit];
211 for (int i = 0; i < limit; i++) {
212 a[i] = (double) this.get(i);
213 }
214 return (Vector) DoubleVector.fromArray((VectorSpecies<Double>) s, a, 0);
215 } else {
216 throw new UnsupportedOperationException("Bad lane type for casting.");
217 }
218 }
219
220 @Override
221 @ForceInline
222 @SuppressWarnings("unchecked")
223 public <F> Vector<F> reinterpret(VectorSpecies<F> s) {
224 Objects.requireNonNull(s);
225
226 if(s.elementType().equals(long.class)) {
227 return (Vector<F>) reshape((VectorSpecies<Long>)s);
228 }
229 if(s.bitSize() == bitSize()) {
230 return reinterpretType(s);
231 }
232
233 return defaultReinterpret(s);
234 }
235
236 @ForceInline
237 private <F> Vector<F> reinterpretType(VectorSpecies<F> s) {
238 Objects.requireNonNull(s);
239
240 Class<?> stype = s.elementType();
241 if (stype == byte.class) {
242 return VectorIntrinsics.reinterpret(
243 LongMaxVector.class,
244 long.class, LENGTH,
245 ByteMaxVector.class,
246 byte.class, ByteMaxVector.LENGTH,
247 this, s,
248 (species, vector) -> vector.defaultReinterpret(species)
249 );
250 } else if (stype == short.class) {
251 return VectorIntrinsics.reinterpret(
252 LongMaxVector.class,
253 long.class, LENGTH,
254 ShortMaxVector.class,
255 short.class, ShortMaxVector.LENGTH,
256 this, s,
257 (species, vector) -> vector.defaultReinterpret(species)
282 float.class, FloatMaxVector.LENGTH,
283 this, s,
284 (species, vector) -> vector.defaultReinterpret(species)
285 );
286 } else if (stype == double.class) {
287 return VectorIntrinsics.reinterpret(
288 LongMaxVector.class,
289 long.class, LENGTH,
290 DoubleMaxVector.class,
291 double.class, DoubleMaxVector.LENGTH,
292 this, s,
293 (species, vector) -> vector.defaultReinterpret(species)
294 );
295 } else {
296 throw new UnsupportedOperationException("Bad lane type for casting.");
297 }
298 }
299
300 @Override
301 @ForceInline
302 public LongVector reshape(VectorSpecies<Long> s) {
303 Objects.requireNonNull(s);
304 if (s.bitSize() == 64 && (s.boxType() == Long64Vector.class)) {
305 return VectorIntrinsics.reinterpret(
306 LongMaxVector.class,
307 long.class, LENGTH,
308 Long64Vector.class,
309 long.class, Long64Vector.LENGTH,
310 this, s,
311 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
312 );
313 } else if (s.bitSize() == 128 && (s.boxType() == Long128Vector.class)) {
314 return VectorIntrinsics.reinterpret(
315 LongMaxVector.class,
316 long.class, LENGTH,
317 Long128Vector.class,
318 long.class, Long128Vector.LENGTH,
319 this, s,
320 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
321 );
322 } else if (s.bitSize() == 256 && (s.boxType() == Long256Vector.class)) {
345 LongMaxVector.class,
346 long.class, LongMaxVector.LENGTH,
347 this, s,
348 (species, vector) -> (LongVector) vector.defaultReinterpret(species)
349 );
350 } else {
351 throw new InternalError("Unimplemented size");
352 }
353 }
354
355 // Binary operations with scalars
356
357 @Override
358 @ForceInline
359 public LongVector add(long o) {
360 return add((LongMaxVector)LongVector.broadcast(SPECIES, o));
361 }
362
363 @Override
364 @ForceInline
365 public LongVector add(long o, VectorMask<Long> m) {
366 return add((LongMaxVector)LongVector.broadcast(SPECIES, o), m);
367 }
368
369 @Override
370 @ForceInline
371 public LongVector sub(long o) {
372 return sub((LongMaxVector)LongVector.broadcast(SPECIES, o));
373 }
374
375 @Override
376 @ForceInline
377 public LongVector sub(long o, VectorMask<Long> m) {
378 return sub((LongMaxVector)LongVector.broadcast(SPECIES, o), m);
379 }
380
381 @Override
382 @ForceInline
383 public LongVector mul(long o) {
384 return mul((LongMaxVector)LongVector.broadcast(SPECIES, o));
385 }
386
387 @Override
388 @ForceInline
389 public LongVector mul(long o, VectorMask<Long> m) {
390 return mul((LongMaxVector)LongVector.broadcast(SPECIES, o), m);
391 }
392
393 @Override
394 @ForceInline
395 public LongVector min(long o) {
396 return min((LongMaxVector)LongVector.broadcast(SPECIES, o));
397 }
398
399 @Override
400 @ForceInline
401 public LongVector max(long o) {
402 return max((LongMaxVector)LongVector.broadcast(SPECIES, o));
403 }
404
405 @Override
406 @ForceInline
407 public VectorMask<Long> equal(long o) {
408 return equal((LongMaxVector)LongVector.broadcast(SPECIES, o));
409 }
410
411 @Override
412 @ForceInline
413 public VectorMask<Long> notEqual(long o) {
414 return notEqual((LongMaxVector)LongVector.broadcast(SPECIES, o));
415 }
416
417 @Override
418 @ForceInline
419 public VectorMask<Long> lessThan(long o) {
420 return lessThan((LongMaxVector)LongVector.broadcast(SPECIES, o));
421 }
422
423 @Override
424 @ForceInline
425 public VectorMask<Long> lessThanEq(long o) {
426 return lessThanEq((LongMaxVector)LongVector.broadcast(SPECIES, o));
427 }
428
429 @Override
430 @ForceInline
431 public VectorMask<Long> greaterThan(long o) {
432 return greaterThan((LongMaxVector)LongVector.broadcast(SPECIES, o));
433 }
434
435 @Override
436 @ForceInline
437 public VectorMask<Long> greaterThanEq(long o) {
438 return greaterThanEq((LongMaxVector)LongVector.broadcast(SPECIES, o));
439 }
440
441 @Override
442 @ForceInline
443 public LongVector blend(long o, VectorMask<Long> m) {
444 return blend((LongMaxVector)LongVector.broadcast(SPECIES, o), m);
445 }
446
447
448 @Override
449 @ForceInline
450 public LongVector and(long o) {
451 return and((LongMaxVector)LongVector.broadcast(SPECIES, o));
452 }
453
454 @Override
455 @ForceInline
456 public LongVector and(long o, VectorMask<Long> m) {
457 return and((LongMaxVector)LongVector.broadcast(SPECIES, o), m);
458 }
459
460 @Override
461 @ForceInline
462 public LongVector or(long o) {
463 return or((LongMaxVector)LongVector.broadcast(SPECIES, o));
464 }
465
466 @Override
467 @ForceInline
468 public LongVector or(long o, VectorMask<Long> m) {
469 return or((LongMaxVector)LongVector.broadcast(SPECIES, o), m);
470 }
471
472 @Override
473 @ForceInline
474 public LongVector xor(long o) {
475 return xor((LongMaxVector)LongVector.broadcast(SPECIES, o));
476 }
477
478 @Override
479 @ForceInline
480 public LongVector xor(long o, VectorMask<Long> m) {
481 return xor((LongMaxVector)LongVector.broadcast(SPECIES, o), m);
482 }
483
484 @Override
485 @ForceInline
486 public LongMaxVector neg() {
487 return (LongMaxVector)zero(SPECIES).sub(this);
488 }
489
490 // Unary operations
491
492 @ForceInline
493 @Override
494 public LongMaxVector neg(VectorMask<Long> m) {
495 return blend(neg(), m);
496 }
497
498 @Override
499 @ForceInline
500 public LongMaxVector abs() {
501 return VectorIntrinsics.unaryOp(
502 VECTOR_OP_ABS, LongMaxVector.class, long.class, LENGTH,
503 this,
504 v1 -> v1.uOp((i, a) -> (long) Math.abs(a)));
505 }
506
507 @ForceInline
508 @Override
509 public LongMaxVector abs(VectorMask<Long> m) {
510 return blend(abs(), m);
511 }
512
513
514 @Override
515 @ForceInline
516 public LongMaxVector not() {
517 return VectorIntrinsics.unaryOp(
518 VECTOR_OP_NOT, LongMaxVector.class, long.class, LENGTH,
519 this,
520 v1 -> v1.uOp((i, a) -> (long) ~a));
521 }
522
523 @ForceInline
524 @Override
525 public LongMaxVector not(VectorMask<Long> m) {
526 return blend(not(), m);
527 }
528 // Binary operations
529
530 @Override
531 @ForceInline
532 public LongMaxVector add(Vector<Long> o) {
533 Objects.requireNonNull(o);
534 LongMaxVector v = (LongMaxVector)o;
535 return VectorIntrinsics.binaryOp(
536 VECTOR_OP_ADD, LongMaxVector.class, long.class, LENGTH,
537 this, v,
538 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a + b)));
539 }
540
541 @Override
542 @ForceInline
543 public LongMaxVector add(Vector<Long> v, VectorMask<Long> m) {
544 return blend(add(v), m);
545 }
546
547 @Override
548 @ForceInline
549 public LongMaxVector sub(Vector<Long> o) {
550 Objects.requireNonNull(o);
551 LongMaxVector v = (LongMaxVector)o;
552 return VectorIntrinsics.binaryOp(
553 VECTOR_OP_SUB, LongMaxVector.class, long.class, LENGTH,
554 this, v,
555 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a - b)));
556 }
557
558 @Override
559 @ForceInline
560 public LongMaxVector sub(Vector<Long> v, VectorMask<Long> m) {
561 return blend(sub(v), m);
562 }
563
564 @Override
565 @ForceInline
566 public LongMaxVector mul(Vector<Long> o) {
567 Objects.requireNonNull(o);
568 LongMaxVector v = (LongMaxVector)o;
569 return VectorIntrinsics.binaryOp(
570 VECTOR_OP_MUL, LongMaxVector.class, long.class, LENGTH,
571 this, v,
572 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a * b)));
573 }
574
575 @Override
576 @ForceInline
577 public LongMaxVector mul(Vector<Long> v, VectorMask<Long> m) {
578 return blend(mul(v), m);
579 }
580
581 @Override
582 @ForceInline
583 public LongMaxVector min(Vector<Long> o) {
584 Objects.requireNonNull(o);
585 LongMaxVector v = (LongMaxVector)o;
586 return (LongMaxVector) VectorIntrinsics.binaryOp(
587 VECTOR_OP_MIN, LongMaxVector.class, long.class, LENGTH,
588 this, v,
589 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long) Math.min(a, b)));
590 }
591
592 @Override
593 @ForceInline
594 public LongMaxVector min(Vector<Long> v, VectorMask<Long> m) {
595 return blend(min(v), m);
596 }
597
598 @Override
599 @ForceInline
600 public LongMaxVector max(Vector<Long> o) {
601 Objects.requireNonNull(o);
602 LongMaxVector v = (LongMaxVector)o;
603 return VectorIntrinsics.binaryOp(
604 VECTOR_OP_MAX, LongMaxVector.class, long.class, LENGTH,
605 this, v,
606 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long) Math.max(a, b)));
607 }
608
609 @Override
610 @ForceInline
611 public LongMaxVector max(Vector<Long> v, VectorMask<Long> m) {
612 return blend(max(v), m);
613 }
614
615 @Override
616 @ForceInline
617 public LongMaxVector and(Vector<Long> o) {
618 Objects.requireNonNull(o);
619 LongMaxVector v = (LongMaxVector)o;
620 return VectorIntrinsics.binaryOp(
621 VECTOR_OP_AND, LongMaxVector.class, long.class, LENGTH,
622 this, v,
623 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a & b)));
624 }
625
626 @Override
627 @ForceInline
628 public LongMaxVector or(Vector<Long> o) {
629 Objects.requireNonNull(o);
630 LongMaxVector v = (LongMaxVector)o;
631 return VectorIntrinsics.binaryOp(
632 VECTOR_OP_OR, LongMaxVector.class, long.class, LENGTH,
633 this, v,
634 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a | b)));
635 }
636
637 @Override
638 @ForceInline
639 public LongMaxVector xor(Vector<Long> o) {
640 Objects.requireNonNull(o);
641 LongMaxVector v = (LongMaxVector)o;
642 return VectorIntrinsics.binaryOp(
643 VECTOR_OP_XOR, LongMaxVector.class, long.class, LENGTH,
644 this, v,
645 (v1, v2) -> v1.bOp(v2, (i, a, b) -> (long)(a ^ b)));
646 }
647
648 @Override
649 @ForceInline
650 public LongMaxVector and(Vector<Long> v, VectorMask<Long> m) {
651 return blend(and(v), m);
652 }
653
654 @Override
655 @ForceInline
656 public LongMaxVector or(Vector<Long> v, VectorMask<Long> m) {
657 return blend(or(v), m);
658 }
659
660 @Override
661 @ForceInline
662 public LongMaxVector xor(Vector<Long> v, VectorMask<Long> m) {
663 return blend(xor(v), m);
664 }
665
666 @Override
667 @ForceInline
668 public LongMaxVector shiftL(int s) {
669 return VectorIntrinsics.broadcastInt(
670 VECTOR_OP_LSHIFT, LongMaxVector.class, long.class, LENGTH,
671 this, s,
672 (v, i) -> v.uOp((__, a) -> (long) (a << i)));
673 }
674
675 @Override
676 @ForceInline
677 public LongMaxVector shiftL(int s, VectorMask<Long> m) {
678 return blend(shiftL(s), m);
679 }
680
681 @Override
682 @ForceInline
683 public LongMaxVector shiftR(int s) {
684 return VectorIntrinsics.broadcastInt(
685 VECTOR_OP_URSHIFT, LongMaxVector.class, long.class, LENGTH,
686 this, s,
687 (v, i) -> v.uOp((__, a) -> (long) (a >>> i)));
688 }
689
690 @Override
691 @ForceInline
692 public LongMaxVector shiftR(int s, VectorMask<Long> m) {
693 return blend(shiftR(s), m);
694 }
695
696 @Override
697 @ForceInline
698 public LongMaxVector aShiftR(int s) {
699 return VectorIntrinsics.broadcastInt(
700 VECTOR_OP_RSHIFT, LongMaxVector.class, long.class, LENGTH,
701 this, s,
702 (v, i) -> v.uOp((__, a) -> (long) (a >> i)));
703 }
704
705 @Override
706 @ForceInline
707 public LongMaxVector aShiftR(int s, VectorMask<Long> m) {
708 return blend(aShiftR(s), m);
709 }
710
711 @Override
712 @ForceInline
713 public LongMaxVector shiftL(Vector<Long> s) {
714 LongMaxVector shiftv = (LongMaxVector)s;
715 // As per shift specification for Java, mask the shift count.
716 shiftv = shiftv.and(LongVector.broadcast(SPECIES, 0x3f));
717 return VectorIntrinsics.binaryOp(
718 VECTOR_OP_LSHIFT, LongMaxVector.class, long.class, LENGTH,
719 this, shiftv,
720 (v1, v2) -> v1.bOp(v2,(i,a, b) -> (long) (a << b)));
721 }
722
723 @Override
724 @ForceInline
725 public LongMaxVector shiftR(Vector<Long> s) {
726 LongMaxVector shiftv = (LongMaxVector)s;
727 // As per shift specification for Java, mask the shift count.
751 @Override
752 @ForceInline
753 public long addAll() {
754 return (long) VectorIntrinsics.reductionCoerced(
755 VECTOR_OP_ADD, LongMaxVector.class, long.class, LENGTH,
756 this,
757 v -> (long) v.rOp((long) 0, (i, a, b) -> (long) (a + b)));
758 }
759
760 @Override
761 @ForceInline
762 public long andAll() {
763 return (long) VectorIntrinsics.reductionCoerced(
764 VECTOR_OP_AND, LongMaxVector.class, long.class, LENGTH,
765 this,
766 v -> (long) v.rOp((long) -1, (i, a, b) -> (long) (a & b)));
767 }
768
769 @Override
770 @ForceInline
771 public long andAll(VectorMask<Long> m) {
772 return blend((LongMaxVector)LongVector.broadcast(SPECIES, (long) -1), m).andAll();
773 }
774
775 @Override
776 @ForceInline
777 public long minAll() {
778 return (long) VectorIntrinsics.reductionCoerced(
779 VECTOR_OP_MIN, LongMaxVector.class, long.class, LENGTH,
780 this,
781 v -> (long) v.rOp(Long.MAX_VALUE , (i, a, b) -> (long) Math.min(a, b)));
782 }
783
784 @Override
785 @ForceInline
786 public long maxAll() {
787 return (long) VectorIntrinsics.reductionCoerced(
788 VECTOR_OP_MAX, LongMaxVector.class, long.class, LENGTH,
789 this,
790 v -> (long) v.rOp(Long.MIN_VALUE , (i, a, b) -> (long) Math.max(a, b)));
791 }
793 @Override
794 @ForceInline
795 public long mulAll() {
796 return (long) VectorIntrinsics.reductionCoerced(
797 VECTOR_OP_MUL, LongMaxVector.class, long.class, LENGTH,
798 this,
799 v -> (long) v.rOp((long) 1, (i, a, b) -> (long) (a * b)));
800 }
801
802 @Override
803 @ForceInline
804 public long orAll() {
805 return (long) VectorIntrinsics.reductionCoerced(
806 VECTOR_OP_OR, LongMaxVector.class, long.class, LENGTH,
807 this,
808 v -> (long) v.rOp((long) 0, (i, a, b) -> (long) (a | b)));
809 }
810
811 @Override
812 @ForceInline
813 public long orAll(VectorMask<Long> m) {
814 return blend((LongMaxVector)LongVector.broadcast(SPECIES, (long) 0), m).orAll();
815 }
816
817 @Override
818 @ForceInline
819 public long xorAll() {
820 return (long) VectorIntrinsics.reductionCoerced(
821 VECTOR_OP_XOR, LongMaxVector.class, long.class, LENGTH,
822 this,
823 v -> (long) v.rOp((long) 0, (i, a, b) -> (long) (a ^ b)));
824 }
825
826 @Override
827 @ForceInline
828 public long xorAll(VectorMask<Long> m) {
829 return blend((LongMaxVector)LongVector.broadcast(SPECIES, (long) 0), m).xorAll();
830 }
831
832
833 @Override
834 @ForceInline
835 public long addAll(VectorMask<Long> m) {
836 return blend((LongMaxVector)LongVector.broadcast(SPECIES, (long) 0), m).addAll();
837 }
838
839
840 @Override
841 @ForceInline
842 public long mulAll(VectorMask<Long> m) {
843 return blend((LongMaxVector)LongVector.broadcast(SPECIES, (long) 1), m).mulAll();
844 }
845
846 @Override
847 @ForceInline
848 public long minAll(VectorMask<Long> m) {
849 return blend((LongMaxVector)LongVector.broadcast(SPECIES, Long.MAX_VALUE), m).minAll();
850 }
851
852 @Override
853 @ForceInline
854 public long maxAll(VectorMask<Long> m) {
855 return blend((LongMaxVector)LongVector.broadcast(SPECIES, Long.MIN_VALUE), m).maxAll();
856 }
857
858 @Override
859 @ForceInline
860 public VectorShuffle<Long> toShuffle() {
861 long[] a = toArray();
862 int[] sa = new int[a.length];
863 for (int i = 0; i < a.length; i++) {
864 sa[i] = (int) a[i];
865 }
866 return VectorShuffle.fromArray(SPECIES, sa, 0);
867 }
868
869 // Memory operations
870
871 private static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_LONG_INDEX_SCALE);
872 private static final int BOOLEAN_ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BOOLEAN_INDEX_SCALE);
873
874 @Override
875 @ForceInline
876 public void intoArray(long[] a, int ix) {
877 Objects.requireNonNull(a);
878 ix = VectorIntrinsics.checkIndex(ix, a.length, LENGTH);
879 VectorIntrinsics.store(LongMaxVector.class, long.class, LENGTH,
880 a, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_LONG_BASE_OFFSET,
881 this,
882 a, ix,
883 (arr, idx, v) -> v.forEach((i, e) -> arr[idx + i] = e));
884 }
885
886 @Override
887 @ForceInline
888 public final void intoArray(long[] a, int ax, VectorMask<Long> m) {
889 LongVector oldVal = LongVector.fromArray(SPECIES, a, ax);
890 LongVector newVal = oldVal.blend(this, m);
891 newVal.intoArray(a, ax);
892 }
893 @Override
894 @ForceInline
895 public void intoArray(long[] a, int ix, int[] b, int iy) {
896 Objects.requireNonNull(a);
897 Objects.requireNonNull(b);
898
899 // Index vector: vix[0:n] = i -> ix + indexMap[iy + i]
900 IntVector vix = IntVector.fromArray(INDEX_SPECIES, b, iy).add(ix);
901
902 vix = VectorIntrinsics.checkIndex(vix, a.length);
903
904 VectorIntrinsics.storeWithMap(LongMaxVector.class, long.class, LENGTH, vix.getClass(),
905 a, Unsafe.ARRAY_LONG_BASE_OFFSET, vix,
906 this,
907 a, ix, b, iy,
908 (arr, idx, v, indexMap, idy) -> v.forEach((i, e) -> arr[idx+indexMap[idy+i]] = e));
909 }
910
911 @Override
912 @ForceInline
913 public final void intoArray(long[] a, int ax, VectorMask<Long> m, int[] b, int iy) {
914 // @@@ This can result in out of bounds errors for unset mask lanes
915 LongVector oldVal = LongVector.fromArray(SPECIES, a, ax, b, iy);
916 LongVector newVal = oldVal.blend(this, m);
917 newVal.intoArray(a, ax, b, iy);
918 }
919
920 @Override
921 @ForceInline
922 public void intoByteArray(byte[] a, int ix) {
923 Objects.requireNonNull(a);
924 ix = VectorIntrinsics.checkIndex(ix, a.length, bitSize() / Byte.SIZE);
925 VectorIntrinsics.store(LongMaxVector.class, long.class, LENGTH,
926 a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET,
927 this,
928 a, ix,
929 (c, idx, v) -> {
930 ByteBuffer bbc = ByteBuffer.wrap(c, idx, c.length - idx).order(ByteOrder.nativeOrder());
931 LongBuffer tb = bbc.asLongBuffer();
932 v.forEach((i, e) -> tb.put(e));
933 });
934 }
935
936 @Override
937 @ForceInline
938 public final void intoByteArray(byte[] a, int ix, VectorMask<Long> m) {
939 LongMaxVector oldVal = (LongMaxVector) LongVector.fromByteArray(SPECIES, a, ix);
940 LongMaxVector newVal = oldVal.blend(this, m);
941 newVal.intoByteArray(a, ix);
942 }
943
944 @Override
945 @ForceInline
946 public void intoByteBuffer(ByteBuffer bb, int ix) {
947 if (bb.order() != ByteOrder.nativeOrder()) {
948 throw new IllegalArgumentException();
949 }
950 if (bb.isReadOnly()) {
951 throw new ReadOnlyBufferException();
952 }
953 ix = VectorIntrinsics.checkIndex(ix, bb.limit(), bitSize() / Byte.SIZE);
954 VectorIntrinsics.store(LongMaxVector.class, long.class, LENGTH,
955 U.getReference(bb, BYTE_BUFFER_HB), ix + U.getLong(bb, BUFFER_ADDRESS),
956 this,
957 bb, ix,
958 (c, idx, v) -> {
959 ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder());
960 LongBuffer tb = bbc.asLongBuffer();
961 v.forEach((i, e) -> tb.put(e));
962 });
963 }
964
965 @Override
966 @ForceInline
967 public void intoByteBuffer(ByteBuffer bb, int ix, VectorMask<Long> m) {
968 LongMaxVector oldVal = (LongMaxVector) LongVector.fromByteBuffer(SPECIES, bb, ix);
969 LongMaxVector newVal = oldVal.blend(this, m);
970 newVal.intoByteBuffer(bb, ix);
971 }
972
973 //
974
975 @Override
976 public String toString() {
977 return Arrays.toString(getElements());
978 }
979
980 @Override
981 public boolean equals(Object o) {
982 if (this == o) return true;
983 if (o == null || this.getClass() != o.getClass()) return false;
984
985 LongMaxVector that = (LongMaxVector) o;
986 return this.equal(that).allTrue();
987 }
1072 Objects.requireNonNull(o);
1073 LongMaxVector v = (LongMaxVector)o;
1074
1075 return VectorIntrinsics.compare(
1076 BT_ge, LongMaxVector.class, LongMaxMask.class, long.class, LENGTH,
1077 this, v,
1078 (v1, v2) -> v1.bTest(v2, (i, a, b) -> a >= b));
1079 }
1080
1081 // Foreach
1082
1083 @Override
1084 void forEach(FUnCon f) {
1085 long[] vec = getElements();
1086 for (int i = 0; i < length(); i++) {
1087 f.apply(i, vec[i]);
1088 }
1089 }
1090
1091 @Override
1092 void forEach(VectorMask<Long> o, FUnCon f) {
1093 boolean[] mbits = ((LongMaxMask)o).getBits();
1094 forEach((i, a) -> {
1095 if (mbits[i]) { f.apply(i, a); }
1096 });
1097 }
1098
1099
1100 DoubleMaxVector toFP() {
1101 long[] vec = getElements();
1102 double[] res = new double[this.species().length()];
1103 for(int i = 0; i < this.species().length(); i++){
1104 res[i] = Double.longBitsToDouble(vec[i]);
1105 }
1106 return new DoubleMaxVector(res);
1107 }
1108
1109 @Override
1110 public LongMaxVector rotateEL(int j) {
1111 long[] vec = getElements();
1112 long[] res = new long[length()];
1137 long[] res = new long[length()];
1138 for (int i = 0; i < length() - j; i++) {
1139 res[i] = vec[i + j];
1140 }
1141 return new LongMaxVector(res);
1142 }
1143
1144 @Override
1145 public LongMaxVector shiftER(int j) {
1146 long[] vec = getElements();
1147 long[] res = new long[length()];
1148 for (int i = 0; i < length() - j; i++){
1149 res[i + j] = vec[i];
1150 }
1151 return new LongMaxVector(res);
1152 }
1153
1154 @Override
1155 @ForceInline
1156 public LongMaxVector rearrange(Vector<Long> v,
1157 VectorShuffle<Long> s, VectorMask<Long> m) {
1158 return this.rearrange(s).blend(v.rearrange(s), m);
1159 }
1160
1161 @Override
1162 @ForceInline
1163 public LongMaxVector rearrange(VectorShuffle<Long> o1) {
1164 Objects.requireNonNull(o1);
1165 LongMaxShuffle s = (LongMaxShuffle)o1;
1166
1167 return VectorIntrinsics.rearrangeOp(
1168 LongMaxVector.class, LongMaxShuffle.class, long.class, LENGTH,
1169 this, s,
1170 (v1, s_) -> v1.uOp((i, a) -> {
1171 int ei = s_.getElement(i);
1172 return v1.get(ei);
1173 }));
1174 }
1175
1176 @Override
1177 @ForceInline
1178 public LongMaxVector blend(Vector<Long> o1, VectorMask<Long> o2) {
1179 Objects.requireNonNull(o1);
1180 Objects.requireNonNull(o2);
1181 LongMaxVector v = (LongMaxVector)o1;
1182 LongMaxMask m = (LongMaxMask)o2;
1183
1184 return VectorIntrinsics.blend(
1185 LongMaxVector.class, LongMaxMask.class, long.class, LENGTH,
1186 this, v, m,
1187 (v1, v2, m_) -> v1.bOp(v2, (i, a, b) -> m_.getElement(i) ? b : a));
1188 }
1189
1190 // Accessors
1191
1192 @Override
1193 public long get(int i) {
1194 if (i < 0 || i >= LENGTH) {
1195 throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + LENGTH);
1196 }
1197 return (long) VectorIntrinsics.extract(
1198 LongMaxVector.class, long.class, LENGTH,
1242 boolean[] bits = new boolean[species().length()];
1243 Arrays.fill(bits, val);
1244 this.bits = bits;
1245 }
1246
1247 boolean[] getBits() {
1248 return VectorIntrinsics.maybeRebox(this).bits;
1249 }
1250
1251 @Override
1252 LongMaxMask uOp(MUnOp f) {
1253 boolean[] res = new boolean[species().length()];
1254 boolean[] bits = getBits();
1255 for (int i = 0; i < species().length(); i++) {
1256 res[i] = f.apply(i, bits[i]);
1257 }
1258 return new LongMaxMask(res);
1259 }
1260
1261 @Override
1262 LongMaxMask bOp(VectorMask<Long> o, MBinOp f) {
1263 boolean[] res = new boolean[species().length()];
1264 boolean[] bits = getBits();
1265 boolean[] mbits = ((LongMaxMask)o).getBits();
1266 for (int i = 0; i < species().length(); i++) {
1267 res[i] = f.apply(i, bits[i], mbits[i]);
1268 }
1269 return new LongMaxMask(res);
1270 }
1271
1272 @Override
1273 public VectorSpecies<Long> species() {
1274 return SPECIES;
1275 }
1276
1277 @Override
1278 public LongMaxVector toVector() {
1279 long[] res = new long[species().length()];
1280 boolean[] bits = getBits();
1281 for (int i = 0; i < species().length(); i++) {
1282 // -1 will result in the most significant bit being set in
1283 // addition to some or all other bits
1284 res[i] = (long) (bits[i] ? -1 : 0);
1285 }
1286 return new LongMaxVector(res);
1287 }
1288
1289 @Override
1290 @ForceInline
1291 @SuppressWarnings("unchecked")
1292 public <E> VectorMask<E> cast(VectorSpecies<E> species) {
1293 if (length() != species.length())
1294 throw new IllegalArgumentException("VectorMask length and species length differ");
1295 Class<?> stype = species.elementType();
1296 boolean [] maskArray = toArray();
1297 if (stype == byte.class) {
1298 return (VectorMask <E>) new ByteMaxVector.ByteMaxMask(maskArray);
1299 } else if (stype == short.class) {
1300 return (VectorMask <E>) new ShortMaxVector.ShortMaxMask(maskArray);
1301 } else if (stype == int.class) {
1302 return (VectorMask <E>) new IntMaxVector.IntMaxMask(maskArray);
1303 } else if (stype == long.class) {
1304 return (VectorMask <E>) new LongMaxVector.LongMaxMask(maskArray);
1305 } else if (stype == float.class) {
1306 return (VectorMask <E>) new FloatMaxVector.FloatMaxMask(maskArray);
1307 } else if (stype == double.class) {
1308 return (VectorMask <E>) new DoubleMaxVector.DoubleMaxMask(maskArray);
1309 } else {
1310 throw new UnsupportedOperationException("Bad lane type for casting.");
1311 }
1312 }
1313
1314 // Unary operations
1315
1316 @Override
1317 @ForceInline
1318 public LongMaxMask not() {
1319 return (LongMaxMask) VectorIntrinsics.unaryOp(
1320 VECTOR_OP_NOT, LongMaxMask.class, long.class, LENGTH,
1321 this,
1322 (m1) -> m1.uOp((i, a) -> !a));
1323 }
1324
1325 // Binary operations
1326
1327 @Override
1328 @ForceInline
1329 public LongMaxMask and(VectorMask<Long> o) {
1330 Objects.requireNonNull(o);
1331 LongMaxMask m = (LongMaxMask)o;
1332 return VectorIntrinsics.binaryOp(VECTOR_OP_AND, LongMaxMask.class, long.class, LENGTH,
1333 this, m,
1334 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
1335 }
1336
1337 @Override
1338 @ForceInline
1339 public LongMaxMask or(VectorMask<Long> o) {
1340 Objects.requireNonNull(o);
1341 LongMaxMask m = (LongMaxMask)o;
1342 return VectorIntrinsics.binaryOp(VECTOR_OP_OR, LongMaxMask.class, long.class, LENGTH,
1343 this, m,
1344 (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
1345 }
1346
1347 // Reductions
1348
1349 @Override
1350 @ForceInline
1351 public boolean anyTrue() {
1352 return VectorIntrinsics.test(BT_ne, LongMaxMask.class, long.class, LENGTH,
1353 this, this,
1354 (m, __) -> anyTrueHelper(((LongMaxMask)m).getBits()));
1355 }
1356
1357 @Override
1358 @ForceInline
1359 public boolean allTrue() {
1360 return VectorIntrinsics.test(BT_overflow, LongMaxMask.class, long.class, LENGTH,
1361 this, VectorMask.maskAllTrue(species()),
1362 (m, __) -> allTrueHelper(((LongMaxMask)m).getBits()));
1363 }
1364 }
1365
1366 // Shuffle
1367
1368 static final class LongMaxShuffle extends AbstractShuffle<Long> {
1369 LongMaxShuffle(byte[] reorder) {
1370 super(reorder);
1371 }
1372
1373 public LongMaxShuffle(int[] reorder) {
1374 super(reorder);
1375 }
1376
1377 public LongMaxShuffle(int[] reorder, int i) {
1378 super(reorder, i);
1379 }
1380
1381 public LongMaxShuffle(IntUnaryOperator f) {
1382 super(f);
1383 }
1384
1385 @Override
1386 public VectorSpecies<Long> species() {
1387 return SPECIES;
1388 }
1389
1390 @Override
1391 public LongVector toVector() {
1392 long[] va = new long[SPECIES.length()];
1393 for (int i = 0; i < va.length; i++) {
1394 va[i] = (long) getElement(i);
1395 }
1396 return LongVector.fromArray(SPECIES, va, 0);
1397 }
1398
1399 @Override
1400 @ForceInline
1401 @SuppressWarnings("unchecked")
1402 public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
1403 if (length() != species.length())
1404 throw new IllegalArgumentException("Shuffle length and species length differ");
1405 Class<?> stype = species.elementType();
1406 int [] shuffleArray = toArray();
1407 if (stype == byte.class) {
1408 return (VectorShuffle<F>) new ByteMaxVector.ByteMaxShuffle(shuffleArray);
1409 } else if (stype == short.class) {
1410 return (VectorShuffle<F>) new ShortMaxVector.ShortMaxShuffle(shuffleArray);
1411 } else if (stype == int.class) {
1412 return (VectorShuffle<F>) new IntMaxVector.IntMaxShuffle(shuffleArray);
1413 } else if (stype == long.class) {
1414 return (VectorShuffle<F>) new LongMaxVector.LongMaxShuffle(shuffleArray);
1415 } else if (stype == float.class) {
1416 return (VectorShuffle<F>) new FloatMaxVector.FloatMaxShuffle(shuffleArray);
1417 } else if (stype == double.class) {
1418 return (VectorShuffle<F>) new DoubleMaxVector.DoubleMaxShuffle(shuffleArray);
1419 } else {
1420 throw new UnsupportedOperationException("Bad lane type for casting.");
1421 }
1422 }
1423
1424 @Override
1425 public LongMaxShuffle rearrange(VectorShuffle<Long> o) {
1426 LongMaxShuffle s = (LongMaxShuffle) o;
1427 byte[] r = new byte[reorder.length];
1428 for (int i = 0; i < reorder.length; i++) {
1429 r[i] = reorder[s.reorder[i]];
1430 }
1431 return new LongMaxShuffle(r);
1432 }
1433 }
1434
1435 // VectorSpecies
1436
1437 @Override
1438 public VectorSpecies<Long> species() {
1439 return SPECIES;
1440 }
1441 }
|