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